Skip to content

Commit

Permalink
Updates and GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jlelse committed Jan 2, 2024
1 parent d0e1530 commit 4e99941
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 557 deletions.
21 changes: 0 additions & 21 deletions .drone.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .gitea/workflows/build.yaml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Master workflow

on:
push:
branches: [ master ]

jobs:
docker:
name: Build Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
- name: Login to Gitea container registry
uses: docker/login-action@v3
with:
registry: git.jlel.se
username: nologin
password: ${{ secrets.GITEA_TOKEN }}
- name: Test
uses: docker/build-push-action@v5
with:
push: false
target: test
tags: test
- name: Build image
uses: docker/build-push-action@v5
with:
push: true
target: base
tags: git.jlel.se/jlelse/goshort:latest
provenance: false
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
FROM golang:1.20-alpine3.17 as build
FROM golang:1.21-alpine3.19 as buildbase

WORKDIR /app
ENV CGO_ENABLED=0
ADD *.go go.mod go.sum /app/
ADD templates/ /app/templates/
RUN go test -cover ./...

FROM buildbase AS build

RUN go build -ldflags '-w -s' -o goshort

FROM alpine:3.17
FROM build AS test

RUN go test -timeout 300s -failfast -cover ./...

FROM alpine:3.19 AS base

WORKDIR /app
VOLUME /app/config
VOLUME /app/data
Expand Down
27 changes: 19 additions & 8 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,29 @@ func (a *app) insertRedirect(slug string, url string, typ string) error {
defer a.write.Unlock()
conn := a.dbpool.Get(context.Background())
defer a.dbpool.Put(conn)
return sqlitex.Exec(conn, "INSERT INTO redirect (slug, url, type) VALUES (?, ?, ?)", nil, slug, url, typ)
return sqlitex.Execute(conn, "INSERT INTO redirect (slug, url, type) VALUES (?, ?, ?)", &sqlitex.ExecOptions{
Args: []any{slug, url, typ},
})
}

func (a *app) deleteSlug(slug string) error {
a.write.Lock()
defer a.write.Unlock()
conn := a.dbpool.Get(context.Background())
defer a.dbpool.Put(conn)
return sqlitex.Exec(conn, "DELETE FROM redirect WHERE slug = ?", nil, slug)
return sqlitex.Execute(conn, "DELETE FROM redirect WHERE slug = ?", &sqlitex.ExecOptions{
Args: []any{slug},
})
}

func (a *app) updateSlug(ctx context.Context, url, typeStr, slug string) error {
a.write.Lock()
defer a.write.Unlock()
conn := a.dbpool.Get(ctx)
defer a.dbpool.Put(conn)
return sqlitex.Exec(conn, "UPDATE redirect SET url = ?, type = ? WHERE slug = ?", nil, url, typeStr, slug)
return sqlitex.Execute(conn, "UPDATE redirect SET url = ?, type = ? WHERE slug = ?", &sqlitex.ExecOptions{
Args: []any{url, typeStr, slug},
})
}

func (a *app) increaseHits(slug string) {
Expand All @@ -88,16 +94,21 @@ func (a *app) increaseHits(slug string) {
defer a.write.Unlock()
conn := a.dbpool.Get(context.Background())
defer a.dbpool.Put(conn)
_ = sqlitex.Exec(conn, "UPDATE redirect SET hits = hits + 1 WHERE slug = ?", nil, slug)
_ = sqlitex.Execute(conn, "UPDATE redirect SET hits = hits + 1 WHERE slug = ?", &sqlitex.ExecOptions{
Args: []any{slug},
})
}()
}

func (a *app) slugExists(slug string) (exists bool, err error) {
conn := a.dbpool.Get(context.Background())
defer a.dbpool.Put(conn)
err = sqlitex.Exec(conn, "SELECT EXISTS(SELECT 1 FROM redirect WHERE slug = ?)", func(stmt *sqlite.Stmt) error {
exists = stmt.ColumnInt(0) == 1
return nil
}, slug)
err = sqlitex.Execute(conn, "SELECT EXISTS(SELECT 1 FROM redirect WHERE slug = ?)", &sqlitex.ExecOptions{
Args: []any{slug},
ResultFunc: func(stmt *sqlite.Stmt) error {
exists = stmt.ColumnInt(0) == 1
return nil
},
})
return
}
44 changes: 24 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,39 @@ go 1.20

require (
git.jlel.se/jlelse/go-shutdowner v0.0.0-20210707065515-773db8099c30
github.com/go-chi/chi/v5 v5.0.8
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
zombiezen.com/go/sqlite v0.13.0
github.com/go-chi/chi/v5 v5.0.11
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
zombiezen.com/go/sqlite v1.0.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.22.5 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.22.1 // indirect
modernc.org/libc v1.38.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.28.0 // indirect
)
Loading

0 comments on commit 4e99941

Please sign in to comment.