Skip to content

Commit 9b2b4ed

Browse files
committed
initial commit
0 parents  commit 9b2b4ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5146
-0
lines changed

.air.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "tmp"
4+
5+
[build]
6+
args_bin = []
7+
bin = "./tmp/main"
8+
cmd = "scripts/air_build.sh"
9+
delay = 1000
10+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
11+
exclude_file = []
12+
exclude_regex = ["_test.go", ".*_templ.go"]
13+
exclude_unchanged = false
14+
follow_symlink = false
15+
full_bin = ""
16+
include_dir = []
17+
include_ext = ["go", "tpl", "tmpl", "templ", "html", "css"]
18+
include_file = []
19+
kill_delay = "0s"
20+
log = "build-errors.log"
21+
poll = false
22+
poll_interval = 0
23+
post_cmd = []
24+
pre_cmd = []
25+
rerun = false
26+
rerun_delay = 500
27+
send_interrupt = false
28+
stop_on_error = false
29+
30+
[color]
31+
app = ""
32+
build = "yellow"
33+
main = "magenta"
34+
runner = "green"
35+
watcher = "cyan"
36+
37+
[log]
38+
main_only = false
39+
time = false
40+
41+
[misc]
42+
clean_on_exit = false
43+
44+
[screen]
45+
clear_on_rebuild = false
46+
keep_scroll = true

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HOST=localhost
2+
PORT=8080
3+
ENV=local
4+
# DSN=postgres://user:password@localhost:5432/dev?sslmode=disable
5+
# TRACING=http://localhost:9411/api/v2/spans
6+
# METRICS=true

.github/pull_request_template.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## What's been done
2+
3+
<!--
4+
- `feat:` Added a new feature
5+
- `fix:` Fixed a bug
6+
- `refactor:` Refactored code
7+
- `docs:` Updated documentation
8+
- `style:` Updated styles
9+
- `test:` Updated tests
10+
- `chore:` Updated build process
11+
- `ci:` Updated CI/CD
12+
-->
13+
14+
## Issue
15+
16+
<!-- Link the github issue here if there is one, delete this section otherwise. -->
17+
<!-- Example: Closes #1 -->
18+
19+
## Demo
20+
21+
<!-- Link to screen shot or video of the change if relevant -->

.github/workflows/app.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: App CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
# paths:
9+
# - .github/workflows/app.yaml
10+
# - .github/workflows/build.yaml
11+
# - .github/workflows/lint.yaml
12+
# - .github/workflows/test.yaml
13+
# - "**"
14+
tags:
15+
- app/v[0-9]+\.[0-9]+\.[0-9]+
16+
- app/v[0-9]+\.[0-9]+\.[0-9]+-staging
17+
18+
pull_request:
19+
branches:
20+
- main
21+
# paths:
22+
# - .github/workflows/app.yaml
23+
# - .github/workflows/build.yaml
24+
# - .github/workflows/lint.yaml
25+
# - .github/workflows/test.yaml
26+
# - "**"
27+
28+
jobs:
29+
checkout:
30+
name: Checkout
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
name: Checkout project
35+
- uses: actions/setup-go@v5
36+
name: Install Golang
37+
with:
38+
go-version-file: "go.mod"
39+
- run: make templ
40+
name: Install Templ
41+
- run: templ generate
42+
name: Generate templ files
43+
- uses: actions/upload-artifact@v4
44+
name: Upload artifact
45+
with:
46+
include-hidden-files: true
47+
name: checkout-${{ github.run_id }}
48+
path: ${{ github.workspace }}/
49+
50+
build:
51+
needs: checkout
52+
name: Build
53+
uses: "./.github/workflows/build.yml"
54+
55+
lint:
56+
needs: checkout
57+
name: Lint
58+
uses: "./.github/workflows/lint.yml"
59+
60+
test:
61+
needs: checkout
62+
name: Test
63+
uses: ./.github/workflows/test.yml

.github/workflows/build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Build
2+
3+
on: workflow_call
4+
5+
jobs:
6+
test:
7+
name: Compile app
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Get Cached Checkout
11+
uses: actions/download-artifact@v4
12+
with:
13+
name: checkout-${{ github.run_id }}
14+
- uses: actions/setup-go@v5
15+
name: Install Golang
16+
with:
17+
go-version-file: "go.mod"
18+
- run: make build
19+
name: Run build

.github/workflows/lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Lint
2+
3+
on: workflow_call
4+
5+
jobs:
6+
lint:
7+
name: golangci-lint
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/download-artifact@v4
11+
name: Get Cached Checkout
12+
with:
13+
name: checkout-${{ github.run_id }}
14+
- uses: actions/setup-go@v5
15+
name: Install Golang
16+
with:
17+
go-version-file: "go.mod"
18+
- uses: golangci/golangci-lint-action@v6
19+
name: Run golangci-lint
20+
with:
21+
args: --config=.golangci.yml
22+
version: latest

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Test
2+
3+
on: workflow_call
4+
5+
jobs:
6+
test:
7+
name: Golang unit tests
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Get Cached Checkout
11+
uses: actions/download-artifact@v4
12+
with:
13+
name: checkout-${{ github.run_id }}
14+
- uses: actions/setup-go@v5
15+
name: Install Golang
16+
with:
17+
go-version-file: "go.mod"
18+
- run: make test
19+
name: Run unit tests

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
.env
25+
node_modules
26+
tmp
27+
.DS_Store

.gofs/templates/db.tmpl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Code generated by gofs codegen. DO NOT EDIT.
2+
package {{.Package}}
3+
4+
import (
5+
"context"
6+
"database/sql"
7+
"encoding/json"
8+
"time"
9+
)
10+
11+
func get{{.StructName}}By{{range .PkFields}}{{.FieldName}}{{end}}(ctx context.Context, tx *sql.Tx{{range .PkFields}}, {{.FieldName}} {{.FieldType}}{{end}}) (*{{.StructName}}, error) {
12+
var data []byte
13+
err := tx.QueryRowContext(ctx, "SELECT blob FROM {{.StructName | Snake}}s WHERE {{range .PkFields}}{{.FieldName | Snake}} = ${{Add .FieldNumber 1}}{{end}}",{{range .PkFields}}{{.FieldName}}{{end}}).Scan(&data)
14+
if err != nil {
15+
return nil, err
16+
}
17+
var v {{.StructName}}
18+
return &v, json.Unmarshal(data, &v)
19+
}
20+
21+
func create{{.StructName}}(ctx context.Context, tx *sql.Tx, v *{{.StructName}}) error {
22+
jsonb, err := json.Marshal(&v)
23+
if err != nil {
24+
return err
25+
}
26+
_, err = tx.ExecContext(ctx, "INSERT INTO {{.StructName | Snake}}s (last_updated, blob{{range .GofsFields}}, {{.FieldName | Snake}}{{end}}) VALUES ($1, $2{{range .GofsFields}}, ${{Add .FieldNumber 3}}{{end}})",
27+
time.Now().UTC(), jsonb{{range .GofsFields}}, v.{{.FieldName}}{{end}})
28+
return err
29+
}
30+
31+
func update{{.StructName}}(ctx context.Context, tx *sql.Tx, v *{{.StructName}}) error {
32+
jsonb, err := json.Marshal(&v)
33+
if err != nil {
34+
return err
35+
}
36+
_, err = tx.ExecContext(ctx, "UPDATE {{.StructName | Snake}}s SET last_updated = $1, blob = $2{{range .SearchableFields}}, {{.FieldName | Snake}} = ${{Add .FieldNumber 3}}{{end}} WHERE {{ $length := len .SearchableFields }}{{range .PkFields}}{{.FieldName | Snake}} = ${{Add $length 3}}{{end}}",
37+
time.Now().UTC(), jsonb{{range .SearchableFields}}, v.{{.FieldName}}{{end}}{{range .PkFields}}, v.{{.FieldName}}{{end}})
38+
return err
39+
}
40+
41+
func delete{{.StructName}}By{{range .PkFields}}{{.FieldName}}{{end}}(ctx context.Context, tx *sql.Tx{{range .PkFields}}, {{.FieldName}} {{.FieldType}}{{end}}) error {
42+
_, err := tx.ExecContext(ctx, "DELETE FROM {{.StructName | Snake}}s WHERE {{range .PkFields}}{{.FieldName | Snake}} = ${{Add .FieldNumber 1}}{{end}}"{{range .PkFields}}, {{.FieldName}}{{end}})
43+
return err
44+
}
45+
46+
{{range .SearchableFields -}}
47+
func get{{.StructName}}sBy{{.FieldName}}(ctx context.Context, tx *sql.Tx, {{.FieldName}} {{.FieldType}}) ([]{{.StructName}}, error) {
48+
rows, err := tx.QueryContext(ctx, "SELECT blob FROM {{.StructName | Snake}}s WHERE {{.FieldName | Snake}} = $1 LIMIT 5000", {{.FieldName}})
49+
if err != nil {
50+
return nil, err
51+
}
52+
defer rows.Close()
53+
54+
vs := []{{.StructName}}{}
55+
for rows.Next() {
56+
var data []byte
57+
if err = rows.Scan(&data); err != nil {
58+
return nil, err
59+
}
60+
var v {{.StructName}}
61+
if err = json.Unmarshal(data, &v); err != nil {
62+
return nil, err
63+
}
64+
vs = append(vs, v)
65+
}
66+
return vs, nil
67+
}
68+
69+
{{end}}

.gofs/templates/sql.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Code generated by gofs codegen. DO NOT EDIT.
2+
3+
CREATE TABLE IF NOT EXISTS {{.StructName | Snake}}s ({{range .PkFields}}
4+
{{.FieldName | Snake}} {{.DBType}} PRIMARY KEY,{{end}}{{range .SearchableFields}}
5+
{{.FieldName | Snake}} {{.DBType}} NOT NULL,{{end}}
6+
last_updated TIMESTAMP NOT NULL,
7+
blob JSONB NOT NULL
8+
)

0 commit comments

Comments
 (0)