Browse Source

added basic skeleton and two API endpoints to test backend stack.

mian
Gisle Aune 3 years ago
parent
commit
11c0bd62e2
  1. 31
      api/common.go
  2. 31
      api/scope.go
  3. 61
      cmd/stufflog3-server.go
  4. 28
      go.mod
  5. 275
      go.sum
  6. 71
      internal/auth/auth.go
  7. 4
      internal/database/database.go
  8. 48
      internal/database/mysql/database.go
  9. 158
      internal/database/mysql/mysqlcore/db.go
  10. 78
      internal/database/mysql/mysqlcore/models.go
  11. 3
      internal/database/mysql/mysqlcore/package.go
  12. 45
      internal/database/mysql/mysqlcore/project.sql.go
  13. 175
      internal/database/mysql/mysqlcore/scope.sql.go
  14. 54
      internal/database/mysql/mysqlcore/stats.sql.go
  15. 5
      internal/database/mysql/queries/project.sql
  16. 28
      internal/database/mysql/queries/scope.sql
  17. 3
      internal/database/mysql/queries/stats.sql
  18. 175
      internal/database/mysql/scopes.go
  19. 20
      internal/envvars/int.go
  20. 7
      internal/envvars/string.go
  21. 2
      internal/models/item.go
  22. 14
      internal/models/scope.go
  23. 2
      internal/models/stat.go
  24. 18
      internal/slerrors/badrequest.go
  25. 22
      internal/slerrors/forbidden.go
  26. 35
      internal/slerrors/gin.go
  27. 18
      internal/slerrors/notfound.go
  28. 36
      internal/sqltypes/nullrawmessage.go
  29. 2
      scripts/goose-mysql/20220313115117_scope.sql
  30. 0
      scripts/goose-mysql/20220313115122_scope_member.sql
  31. 0
      scripts/goose-mysql/20220326173144_stat.sql
  32. 2
      scripts/goose-mysql/20220326174046_project.sql
  33. 0
      scripts/goose-mysql/20220404144911_project_requirement.sql
  34. 0
      scripts/goose-mysql/20220404144914_item.sql
  35. 0
      scripts/goose-mysql/20220404144947_item_stat_progress.sql
  36. 2
      scripts/goose-mysql/20220404184237_project_requirement_stat.sql
  37. 9
      scripts/goose-mysql/20220411190154_project_created_time.sql
  38. 21
      sqlc.yaml
  39. BIN
      stufflog3-server
  40. 5
      tools.go

31
api/common.go

@ -0,0 +1,31 @@
package api
import (
"git.aiterp.net/stufflog3/stufflog3-api/internal/slerrors"
"github.com/gin-gonic/gin"
"strconv"
)
func handler(key string, callback func(c *gin.Context) (interface{}, error)) gin.HandlerFunc {
return func(c *gin.Context) {
res, err := callback(c)
if err != nil {
slerrors.Respond(c, err)
return
}
resJson := make(map[string]interface{}, 1)
resJson[key] = res
c.JSON(200, resJson)
}
}
func reqInt(c *gin.Context, key string) (int, error) {
v, err := strconv.Atoi(c.Param(key))
if err != nil {
return 0, slerrors.BadRequest(key + " parameter must be a number")
}
return v, nil
}

31
api/scope.go

@ -0,0 +1,31 @@
package api
import (
"git.aiterp.net/stufflog3/stufflog3-api/internal/auth"
"git.aiterp.net/stufflog3/stufflog3-api/internal/database"
"git.aiterp.net/stufflog3/stufflog3-api/internal/slerrors"
"github.com/gin-gonic/gin"
)
func Scopes(g *gin.RouterGroup, db database.Database) {
g.GET("/", handler("goals", func(c *gin.Context) (interface{}, error) {
return db.Scopes().ListByUser(c.Request.Context(), auth.UserID(c))
}))
g.GET("/:id", handler("goals", func(c *gin.Context) (interface{}, error) {
id, err := reqInt(c, "id")
if err != nil {
return nil, err
}
scope, err := db.Scopes().Find(c.Request.Context(), id)
if err != nil {
return nil, err
}
if !scope.HasMember(auth.UserID(c)) {
return nil, slerrors.NotFound("Scope")
}
return scope, nil
}))
}

61
cmd/stufflog3-server.go

@ -0,0 +1,61 @@
package main
import (
"git.aiterp.net/stufflog3/stufflog3-api/api"
"git.aiterp.net/stufflog3/stufflog3-api/internal/auth"
"git.aiterp.net/stufflog3/stufflog3-api/internal/database/mysql"
"git.aiterp.net/stufflog3/stufflog3-api/internal/envvars"
"github.com/gin-gonic/gin"
"log"
"os"
"os/signal"
"syscall"
)
func main() {
db, err := mysql.Connect(
envvars.String("STUFFLOG3_MYSQL_HOST"),
envvars.Int("STUFFLOG3_MYSQL_PORT"),
envvars.String("STUFFLOG3_MYSQL_USERNAME"),
envvars.String("STUFFLOG3_MYSQL_PASSWORD"),
envvars.String("STUFFLOG3_MYSQL_SCHEMA"),
)
if err != nil {
log.Println("Failed to open database:", err)
os.Exit(1)
}
server := gin.New()
if envvars.String("STUFFLOG3_USE_DUMMY_USER") != "" {
log.Println("Using dummy UUID")
server.Use(auth.DummyMiddleware("c11230be-4912-4313-83b0-410a248b5bd1"))
} else {
server.Use(auth.TrustingJwtParserMiddleware())
}
api.Scopes(server.Group("/api/scopes"), db)
exitSignal := make(chan os.Signal)
signal.Notify(exitSignal, os.Interrupt, os.Kill, syscall.SIGTERM)
errCh := make(chan error)
go func() {
err := server.Run(":8239")
if err != nil {
errCh <- err
}
}()
select {
case sig := <-exitSignal:
{
log.Println("Received signal", sig)
os.Exit(0)
}
case err := <-errCh:
{
log.Println("Server run failed:", err)
os.Exit(2)
}
}
}

28
go.mod

@ -1,3 +1,31 @@
module git.aiterp.net/stufflog3/stufflog3-api module git.aiterp.net/stufflog3/stufflog3-api
go 1.17 go 1.17
require (
github.com/gin-gonic/gin v1.7.7
github.com/go-sql-driver/mysql v1.6.0
github.com/kyleconroy/sqlc v1.13.0
)
require (
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

275
go.sum

@ -0,0 +1,275 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/cznic/golex v0.0.0-20181122101858-9c343928389c/go.mod h1:+bmmJDNmKlhWNG+gwWCkaBoTy39Fs+bzRxVBzoTQbIc=
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
github.com/cznic/parser v0.0.0-20160622100904-31edd927e5b1/go.mod h1:2B43mz36vGZNZEwkWi8ayRSSUXLfjL8OkbzwW4NcPMM=
github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8/go.mod h1:q2w6Bg5jeox1B+QkJ6Wp/+Vn0G/bo3f1uY7Fn3vivIQ=
github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186/go.mod h1:AHHPPPXTw0h6pVabbcbyGRK1DckRn7r/STdZEeIDzZc=
github.com/cznic/y v0.0.0-20170802143616-045f81c6662a/go.mod h1:1rk5VM7oSnA4vjp+hrLQ3HWHa+Y4yPCa3/CsJrcNnvs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-sql-driver/mysql v1.3.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA=
github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE=
github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s=
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY=
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
github.com/jackc/pgconn v1.11.0/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c=
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgproto3/v2 v2.2.0/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM=
github.com/jackc/pgtype v1.10.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
github.com/jackc/pgx/v4 v4.15.0/go.mod h1:D/zyOyXiaM1TmVWnOM18p0xdDtdakRBa0RsVGI3U3bw=
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kyleconroy/sqlc v1.13.0 h1:fhfOZbfuF7ELo5uMB8XkgZJRTnc1YQYtzhyLgp7PzFM=
github.com/kyleconroy/sqlc v1.13.0/go.mod h1:vO++DmIYZfpVDnR8sgiYkjGB/22E8R7h66fykOIzhI8=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pganalyze/pg_query_go/v2 v2.1.0/go.mod h1:XAxmVqz1tEGqizcQ3YSdN90vCOHBWjJi8URL1er5+cA=
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8/go.mod h1:B1+S9LNcuMyLH/4HMTViQOJevkGiik3wW2AN9zb2fNQ=
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pingcap/parser v0.0.0-20210914110036-002913dd28ec/go.mod h1:+xcMiiZzdIktT/Nqdfm81dkECJ2EPuoAYywd57py4Pk=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=

71
internal/auth/auth.go

@ -0,0 +1,71 @@
package auth
import (
"context"
"encoding/base64"
"encoding/json"
"git.aiterp.net/stufflog3/stufflog3-api/internal/slerrors"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
var contextKey = struct{}{}
func UserID(ctx context.Context) string {
if c, ok := ctx.(*gin.Context); ok {
return UserID(c.Request.Context())
}
return ctx.Value(&contextKey).(string)
}
func DummyMiddleware(uuid string) gin.HandlerFunc {
return func(c *gin.Context) {
c.Request = c.Request.WithContext(
context.WithValue(c.Request.Context(), &contextKey, uuid),
)
}
}
func abortRequest(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusUnauthorized, slerrors.ErrorResponse{
Code: http.StatusUnauthorized,
Message: "You're not supposed to be here!",
})
}
// TrustingJwtParserMiddleware is meant to be put behind an AWS API gateway that has already
// verified this token.
func TrustingJwtParserMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
auth := c.GetHeader("Authorization")
split := strings.Split(auth, ".")
if len(split) >= 3 {
data, err := base64.RawStdEncoding.DecodeString(split[1])
if err != nil {
abortRequest(c)
return
}
fields := make(map[string]interface{})
err = json.Unmarshal(data, &fields)
if err != nil {
abortRequest(c)
return
}
if sub, ok := fields["sub"].(string); ok {
c.Request = c.Request.WithContext(
context.WithValue(c.Request.Context(), &contextKey, sub),
)
} else {
abortRequest(c)
return
}
} else {
abortRequest(c)
}
}
}

4
internal/database/database.go

@ -9,11 +9,13 @@ import (
type Database interface { type Database interface {
Scopes() ScopeRepository Scopes() ScopeRepository
Stats(scopeID int) StatRepository Stats(scopeID int) StatRepository
Items(scopeID int) ItemRepository
} }
type ScopeRepository interface { type ScopeRepository interface {
Find(ctx context.Context, id int) (*models.Scope, error) Find(ctx context.Context, id int) (*models.Scope, error)
List(ctx context.Context, userID string) ([]models.ScopeEntry, error)
List(ctx context.Context) ([]models.ScopeEntry, error)
ListByUser(ctx context.Context, userID string) ([]models.ScopeEntry, error)
Create(ctx context.Context, scope models.ScopeEntry, owner models.ScopeMember) (*models.Scope, error) Create(ctx context.Context, scope models.ScopeEntry, owner models.ScopeMember) (*models.Scope, error)
Update(ctx context.Context, scope models.ScopeEntry) error Update(ctx context.Context, scope models.ScopeEntry) error
Delete(ctx context.Context, scope models.Scope) error Delete(ctx context.Context, scope models.Scope) error

48
internal/database/mysql/database.go

@ -0,0 +1,48 @@
package mysql
import (
"database/sql"
"fmt"
"git.aiterp.net/stufflog3/stufflog3-api/internal/database"
"time"
_ "github.com/go-sql-driver/mysql"
)
type Database struct {
db *sql.DB
}
func (d *Database) Scopes() database.ScopeRepository {
return &scopeRepository{db: d.db}
}
func (d *Database) Stats(scopeID int) database.StatRepository {
//TODO implement me
panic("implement me")
}
func (d *Database) Items(scopeID int) database.ItemRepository {
//TODO implement me
panic("implement me")
}
func Connect(host string, port int, username, password, database string) (*Database, error) {
db, err := sql.Open("mysql", fmt.Sprintf(
"%s:%s@(%s:%d)/%s?parseTime=true", username, password, host, port, database,
))
if err != nil {
return nil, err
}
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
db.SetConnMaxIdleTime(time.Minute)
err = db.Ping()
if err != nil {
return nil, err
}
return &Database{db: db}, nil
}

158
internal/database/mysql/mysqlcore/db.go

@ -0,0 +1,158 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
package mysqlcore
import (
"context"
"database/sql"
"fmt"
)
type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
q := Queries{db: db}
var err error
if q.getScopeStmt, err = db.PrepareContext(ctx, getScope); err != nil {
return nil, fmt.Errorf("error preparing query GetScope: %w", err)
}
if q.getScopeDisplayNameStmt, err = db.PrepareContext(ctx, getScopeDisplayName); err != nil {
return nil, fmt.Errorf("error preparing query GetScopeDisplayName: %w", err)
}
if q.getScopeWithDisplayNameStmt, err = db.PrepareContext(ctx, getScopeWithDisplayName); err != nil {
return nil, fmt.Errorf("error preparing query GetScopeWithDisplayName: %w", err)
}
if q.listProjectEntriesStmt, err = db.PrepareContext(ctx, listProjectEntries); err != nil {
return nil, fmt.Errorf("error preparing query ListProjectEntries: %w", err)
}
if q.listScopeMembersStmt, err = db.PrepareContext(ctx, listScopeMembers); err != nil {
return nil, fmt.Errorf("error preparing query ListScopeMembers: %w", err)
}
if q.listScopesStmt, err = db.PrepareContext(ctx, listScopes); err != nil {
return nil, fmt.Errorf("error preparing query ListScopes: %w", err)
}
if q.listScopesByUserStmt, err = db.PrepareContext(ctx, listScopesByUser); err != nil {
return nil, fmt.Errorf("error preparing query ListScopesByUser: %w", err)
}
if q.listStatsStmt, err = db.PrepareContext(ctx, listStats); err != nil {
return nil, fmt.Errorf("error preparing query ListStats: %w", err)
}
return &q, nil
}
func (q *Queries) Close() error {
var err error
if q.getScopeStmt != nil {
if cerr := q.getScopeStmt.Close(); cerr != nil {
err = fmt.Errorf("error closing getScopeStmt: %w", cerr)
}
}
if q.getScopeDisplayNameStmt != nil {
if cerr := q.getScopeDisplayNameStmt.Close(); cerr != nil {
err = fmt.Errorf("error closing getScopeDisplayNameStmt: %w", cerr)
}
}
if q.getScopeWithDisplayNameStmt != nil {
if cerr := q.getScopeWithDisplayNameStmt.Close(); cerr != nil {
err = fmt.Errorf("error closing getScopeWithDisplayNameStmt: %w", cerr)
}
}
if q.listProjectEntriesStmt != nil {
if cerr := q.listProjectEntriesStmt.Close(); cerr != nil {
err = fmt.Errorf("error closing listProjectEntriesStmt: %w", cerr)
}
}
if q.listScopeMembersStmt != nil {
if cerr := q.listScopeMembersStmt.Close(); cerr != nil {
err = fmt.Errorf("error closing listScopeMembersStmt: %w", cerr)
}
}
if q.listScopesStmt != nil {
if cerr := q.listScopesStmt.Close(); cerr != nil {
err = fmt.Errorf("error closing listScopesStmt: %w", cerr)
}
}
if q.listScopesByUserStmt != nil {
if cerr := q.listScopesByUserStmt.Close(); cerr != nil {
err = fmt.Errorf("error closing listScopesByUserStmt: %w", cerr)
}
}
if q.listStatsStmt != nil {
if cerr := q.listStatsStmt.Close(); cerr != nil {
err = fmt.Errorf("error closing listStatsStmt: %w", cerr)
}
}
return err
}
func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
switch {
case stmt != nil && q.tx != nil:
return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
case stmt != nil:
return stmt.ExecContext(ctx, args...)
default:
return q.db.ExecContext(ctx, query, args...)
}
}
func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
switch {
case stmt != nil && q.tx != nil:
return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
case stmt != nil:
return stmt.QueryContext(ctx, args...)
default:
return q.db.QueryContext(ctx, query, args...)
}
}
func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
switch {
case stmt != nil && q.tx != nil:
return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
case stmt != nil:
return stmt.QueryRowContext(ctx, args...)
default:
return q.db.QueryRowContext(ctx, query, args...)
}
}
type Queries struct {
db DBTX
tx *sql.Tx
getScopeStmt *sql.Stmt
getScopeDisplayNameStmt *sql.Stmt
getScopeWithDisplayNameStmt *sql.Stmt
listProjectEntriesStmt *sql.Stmt
listScopeMembersStmt *sql.Stmt
listScopesStmt *sql.Stmt
listScopesByUserStmt *sql.Stmt
listStatsStmt *sql.Stmt
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
return &Queries{
db: tx,
tx: tx,
getScopeStmt: q.getScopeStmt,
getScopeDisplayNameStmt: q.getScopeDisplayNameStmt,
getScopeWithDisplayNameStmt: q.getScopeWithDisplayNameStmt,
listProjectEntriesStmt: q.listProjectEntriesStmt,
listScopeMembersStmt: q.listScopeMembersStmt,
listScopesStmt: q.listScopesStmt,
listScopesByUserStmt: q.listScopesByUserStmt,
listStatsStmt: q.listStatsStmt,
}
}

78
internal/database/mysql/mysqlcore/models.go

@ -0,0 +1,78 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
package mysqlcore
import (
"database/sql"
"time"
"git.aiterp.net/stufflog3/stufflog3-api/internal/sqltypes"
)
type Item struct {
ID int `json:"id"`
ScopeID int `json:"scope_id"`
ProjectRequirementID sql.NullInt32 `json:"project_requirement_id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedTime time.Time `json:"created_time"`
CreatedUserID string `json:"created_user_id"`
AcquiredTime sql.NullTime `json:"acquired_time"`
ScheduledDate sql.NullTime `json:"scheduled_date"`
}
type ItemStatProgress struct {
ItemID int `json:"item_id"`
StatID int `json:"stat_id"`
Acquired int `json:"acquired"`
Required int `json:"required"`
}
type Project struct {
ID int `json:"id"`
ScopeID int `json:"scope_id"`
AuthorID string `json:"author_id"`
Name string `json:"name"`
Status int `json:"status"`
Description string `json:"description"`
CreatedTime time.Time `json:"created_time"`
}
type ProjectRequirement struct {
ID int `json:"id"`
ScopeID int `json:"scope_id"`
ProjectID int `json:"project_id"`
Name string `json:"name"`
Status int `json:"status"`
Description string `json:"description"`
}
type ProjectRequirementStat struct {
ProjectRequirementID int `json:"project_requirement_id"`
StatID int `json:"stat_id"`
Required int `json:"required"`
}
type Scope struct {
ID int `json:"id"`
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
}
type ScopeMember struct {
ScopeID int `json:"scope_id"`
UserID string `json:"user_id"`
Name string `json:"name"`
Owner bool `json:"owner"`
}
type Stat struct {
ID int `json:"id"`
ScopeID int `json:"scope_id"`
Name string `json:"name"`
Description string `json:"description"`
Weight float64 `json:"weight"`
AllowedAmounts sqltypes.NullRawMessage `json:"allowed_amounts"`
}

3
internal/database/mysql/mysqlcore/package.go

@ -0,0 +1,3 @@
// Package mysqlcore contains generated code.
package mysqlcore

45
internal/database/mysql/mysqlcore/project.sql.go

@ -0,0 +1,45 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
// source: project.sql
package mysqlcore
import (
"context"
)
const listProjectEntries = `-- name: ListProjectEntries :many
SELECT id, name, status FROM project
WHERE scope_id = ?
ORDER BY status, created_time
`
type ListProjectEntriesRow struct {
ID int `json:"id"`
Name string `json:"name"`
Status int `json:"status"`
}
func (q *Queries) ListProjectEntries(ctx context.Context, scopeID int) ([]ListProjectEntriesRow, error) {
rows, err := q.query(ctx, q.listProjectEntriesStmt, listProjectEntries, scopeID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListProjectEntriesRow{}
for rows.Next() {
var i ListProjectEntriesRow
if err := rows.Scan(&i.ID, &i.Name, &i.Status); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

175
internal/database/mysql/mysqlcore/scope.sql.go

@ -0,0 +1,175 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
// source: scope.sql
package mysqlcore
import (
"context"
"database/sql"
)
const getScope = `-- name: GetScope :one
SELECT id, name, abbreviation FROM scope
WHERE id = ?
`
func (q *Queries) GetScope(ctx context.Context, id int) (Scope, error) {
row := q.queryRow(ctx, q.getScopeStmt, getScope, id)
var i Scope
err := row.Scan(&i.ID, &i.Name, &i.Abbreviation)
return i, err
}
const getScopeDisplayName = `-- name: GetScopeDisplayName :one
SELECT name FROM scope_member
WHERE user_id = ? AND scope_id = ?
`
type GetScopeDisplayNameParams struct {
UserID string `json:"user_id"`
ScopeID int `json:"scope_id"`
}
func (q *Queries) GetScopeDisplayName(ctx context.Context, arg GetScopeDisplayNameParams) (string, error) {
row := q.queryRow(ctx, q.getScopeDisplayNameStmt, getScopeDisplayName, arg.UserID, arg.ScopeID)
var name string
err := row.Scan(&name)
return name, err
}
const getScopeWithDisplayName = `-- name: GetScopeWithDisplayName :one
SELECT id, scope.name, abbreviation, sm.name AS display_name FROM scope
LEFT JOIN scope_member sm ON scope.id = sm.scope_id
WHERE id = ? AND sm.user_id = ?
`
type GetScopeWithDisplayNameParams struct {
ID int `json:"id"`
UserID string `json:"user_id"`
}
type GetScopeWithDisplayNameRow struct {
ID int `json:"id"`
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
DisplayName sql.NullString `json:"display_name"`
}
func (q *Queries) GetScopeWithDisplayName(ctx context.Context, arg GetScopeWithDisplayNameParams) (GetScopeWithDisplayNameRow, error) {
row := q.queryRow(ctx, q.getScopeWithDisplayNameStmt, getScopeWithDisplayName, arg.ID, arg.UserID)
var i GetScopeWithDisplayNameRow
err := row.Scan(
&i.ID,
&i.Name,
&i.Abbreviation,
&i.DisplayName,
)
return i, err
}
const listScopeMembers = `-- name: ListScopeMembers :many
SELECT user_id, name, owner FROM scope_member
WHERE scope_id = ?
ORDER BY name
`
type ListScopeMembersRow struct {
UserID string `json:"user_id"`
Name string `json:"name"`
Owner bool `json:"owner"`
}
func (q *Queries) ListScopeMembers(ctx context.Context, scopeID int) ([]ListScopeMembersRow, error) {
rows, err := q.query(ctx, q.listScopeMembersStmt, listScopeMembers, scopeID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListScopeMembersRow{}
for rows.Next() {
var i ListScopeMembersRow
if err := rows.Scan(&i.UserID, &i.Name, &i.Owner); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listScopes = `-- name: ListScopes :many
SELECT id, name, abbreviation FROM scope
ORDER BY name
`
func (q *Queries) ListScopes(ctx context.Context) ([]Scope, error) {
rows, err := q.query(ctx, q.listScopesStmt, listScopes)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Scope{}
for rows.Next() {
var i Scope
if err := rows.Scan(&i.ID, &i.Name, &i.Abbreviation); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listScopesByUser = `-- name: ListScopesByUser :many
SELECT id, s.name, abbreviation, sm.name as display_name FROM scope_member sm
RIGHT JOIN scope s on s.id = sm.scope_id
WHERE sm.user_id = ?
ORDER BY s.name
`
type ListScopesByUserRow struct {
ID int `json:"id"`
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
DisplayName sql.NullString `json:"display_name"`
}
func (q *Queries) ListScopesByUser(ctx context.Context, userID string) ([]ListScopesByUserRow, error) {
rows, err := q.query(ctx, q.listScopesByUserStmt, listScopesByUser, userID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListScopesByUserRow{}
for rows.Next() {
var i ListScopesByUserRow
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Abbreviation,
&i.DisplayName,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

54
internal/database/mysql/mysqlcore/stats.sql.go

@ -0,0 +1,54 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.13.0
// source: stats.sql
package mysqlcore
import (
"context"
"git.aiterp.net/stufflog3/stufflog3-api/internal/sqltypes"
)
const listStats = `-- name: ListStats :many
SELECT id, name, description, weight, allowed_amounts FROM stat
WHERE scope_id = ?
`
type ListStatsRow struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Weight float64 `json:"weight"`
AllowedAmounts sqltypes.NullRawMessage `json:"allowed_amounts"`
}
func (q *Queries) ListStats(ctx context.Context, scopeID int) ([]ListStatsRow, error) {
rows, err := q.query(ctx, q.listStatsStmt, listStats, scopeID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListStatsRow{}
for rows.Next() {
var i ListStatsRow
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Description,
&i.Weight,
&i.AllowedAmounts,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}

5
internal/database/mysql/queries/project.sql

@ -0,0 +1,5 @@
-- name: ListProjectEntries :many
SELECT id, name, status FROM project
WHERE scope_id = ?
ORDER BY status, created_time;

28
internal/database/mysql/queries/scope.sql

@ -0,0 +1,28 @@
-- name: GetScope :one
SELECT id, name, abbreviation FROM scope
WHERE id = ?;
-- name: ListScopes :many
SELECT id, name, abbreviation FROM scope
ORDER BY name;
-- name: ListScopesByUser :many
SELECT id, s.name, abbreviation, sm.name as display_name FROM scope_member sm
RIGHT JOIN scope s on s.id = sm.scope_id
WHERE sm.user_id = ?
ORDER BY s.name;
-- name: ListScopeMembers :many
SELECT user_id, name, owner FROM scope_member
WHERE scope_id = ?
ORDER BY name;
-- name: GetScopeWithDisplayName :one
SELECT id, scope.name, abbreviation, sm.name AS display_name FROM scope
LEFT JOIN scope_member sm ON scope.id = sm.scope_id
WHERE id = ? AND sm.user_id = ?;
-- name: GetScopeDisplayName :one
SELECT name FROM scope_member
WHERE user_id = ? AND scope_id = ?;

3
internal/database/mysql/queries/stats.sql

@ -0,0 +1,3 @@
-- name: ListStats :many
SELECT id, name, description, weight, allowed_amounts FROM stat
WHERE scope_id = ?;

175
internal/database/mysql/scopes.go

@ -0,0 +1,175 @@
package mysql
import (
"context"
"database/sql"
"encoding/json"
"git.aiterp.net/stufflog3/stufflog3-api/internal/database/mysql/mysqlcore"
"git.aiterp.net/stufflog3/stufflog3-api/internal/models"
"git.aiterp.net/stufflog3/stufflog3-api/internal/slerrors"
"golang.org/x/sync/errgroup"
"log"
"time"
)
type scopeRepository struct {
db *sql.DB
}
func (r *scopeRepository) Find(ctx context.Context, id int) (*models.Scope, error) {
q := mysqlcore.New(r.db)
scope, err := q.GetScope(ctx, id)
if err != nil {
if err == sql.ErrNoRows {
return nil, slerrors.NotFound("Scope")
}
return nil, err
}
res := &models.Scope{
ScopeEntry: models.ScopeEntry{
ID: scope.ID,
Name: scope.Name,
Abbreviation: scope.Abbreviation,
},
}
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error {
members, err := q.ListScopeMembers(ctx, id)
if err != nil && err != sql.ErrNoRows {
return err
}
for _, member := range members {
res.Members = append(res.Members, models.ScopeMember{
ID: member.UserID,
Name: member.Name,
Owner: member.Owner,
})
}
return nil
})
eg.Go(func() error {
projects, err := q.ListProjectEntries(ctx, id)
if err != nil && err != sql.ErrNoRows {
return err
}
for _, project := range projects {
res.Projects = append(res.Projects, models.ProjectEntry{
ID: project.ID,
Name: project.Name,
Status: models.Status(project.Status),
})
}
return nil
})
eg.Go(func() error {
stats, err := q.ListStats(ctx, id)
if err != nil && err != sql.ErrNoRows {
return err
}
for _, stat := range stats {
var amounts map[string]int
if stat.AllowedAmounts.Valid {
amounts = make(map[string]int)
err := json.Unmarshal(stat.AllowedAmounts.RawMessage, &amounts)
if err != nil {
return err
}
}
res.Stats = append(res.Stats, models.Stat{
StatEntry: models.StatEntry{
ID: stat.ID,
Name: stat.Name,
Weight: stat.Weight,
},
Description: stat.Description,
AllowedAmounts: amounts,
})
}
return nil
})
t := time.Now()
err = eg.Wait()
if err != nil {
return nil, err
}
log.Println(time.Since(t))
return res, nil
}
func (r *scopeRepository) List(ctx context.Context) ([]models.ScopeEntry, error) {
q := mysqlcore.New(r.db)
scopes, err := q.ListScopes(ctx)
if err != nil {
return nil, err
}
res := make([]models.ScopeEntry, 0, len(scopes))
for _, scope := range scopes {
res = append(res, models.ScopeEntry{
ID: scope.ID,
Name: scope.Name,
Abbreviation: scope.Abbreviation,
})
}
return res, nil
}
func (r *scopeRepository) ListByUser(ctx context.Context, userID string) ([]models.ScopeEntry, error) {
q := mysqlcore.New(r.db)
scopes, err := q.ListScopesByUser(ctx, userID)
if err != nil {
return nil, err
}
res := make([]models.ScopeEntry, 0, len(scopes))
for _, scope := range scopes {
res = append(res, models.ScopeEntry{
ID: scope.ID,
Name: scope.Name,
Abbreviation: scope.Abbreviation,
})
}
return res, nil
}
func (r *scopeRepository) Create(ctx context.Context, scope models.ScopeEntry, owner models.ScopeMember) (*models.Scope, error) {
//TODO implement me
panic("implement me")
}
func (r *scopeRepository) Update(ctx context.Context, scope models.ScopeEntry) error {
//TODO implement me
panic("implement me")
}
func (r *scopeRepository) Delete(ctx context.Context, scope models.Scope) error {
//TODO implement me
panic("implement me")
}
func (r *scopeRepository) UpdateMember(ctx context.Context, scope models.Scope, member models.ScopeMember) (*models.Scope, error) {
//TODO implement me
panic("implement me")
}
func (r *scopeRepository) DeleteMember(ctx context.Context, scope models.Scope, userID string) (*models.Scope, error) {
//TODO implement me
panic("implement me")
}

20
internal/envvars/int.go

@ -0,0 +1,20 @@
package envvars
import (
"os"
"strconv"
)
func Int(key string) int {
value := os.Getenv(key)
if value == "" {
return 0
}
intValue, err := strconv.Atoi(value)
if err != nil {
return 0
}
return intValue
}

7
internal/envvars/string.go

@ -0,0 +1,7 @@
package envvars
import "os"
func String(key string) string {
return os.Getenv(key)
}

2
internal/models/item.go

@ -13,5 +13,5 @@ type Item struct {
CreatedTime time.Time CreatedTime time.Time
AcquiredTime *time.Time AcquiredTime *time.Time
ScheduledDate *time.Time ScheduledDate *time.Time
Stats StatProgressEntry[]
Stats []StatProgressEntry
} }

14
internal/models/scope.go

@ -1,7 +1,7 @@
package models package models
type ScopeEntry struct { type ScopeEntry struct {
ID string `json:"id"`
ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Abbreviation string `json:"abbreviation"` Abbreviation string `json:"abbreviation"`
} }
@ -18,5 +18,15 @@ type Scope struct {
DisplayName string `json:"displayName"` DisplayName string `json:"displayName"`
Members []ScopeMember `json:"members"` Members []ScopeMember `json:"members"`
Projects []ProjectEntry `json:"projects"` Projects []ProjectEntry `json:"projects"`
Stat []Stat `json:"stat"`
Stats []Stat `json:"stats"`
}
func (s *Scope) HasMember(id string) bool {
for _, user := range s.Members {
if user.ID == id {
return true
}
}
return false
} }

2
internal/models/stat.go

@ -1,7 +1,7 @@
package models package models
type StatEntry struct { type StatEntry struct {
ID string `json:"id"`
ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Weight float64 `json:"weight"` Weight float64 `json:"weight"`
} }

18
internal/slerrors/badrequest.go

@ -0,0 +1,18 @@
package slerrors
type badRequestError struct {
Text string
}
func (err *badRequestError) Error() string {
return "validation failed: " + err.Text
}
func BadRequest(text string) error {
return &badRequestError{Text: text}
}
func IsBadRequest(err error) bool {
_, ok := err.(*badRequestError)
return ok
}

22
internal/slerrors/forbidden.go

@ -0,0 +1,22 @@
package slerrors
type forbiddenError struct {
Message string
}
func (e *forbiddenError) Error() string {
return e.Message
}
func Forbidden(message string) error {
return &forbiddenError{Message: message}
}
func IsForbidden(err error) bool {
if err == nil {
return false
}
_, ok := err.(*forbiddenError)
return ok
}

35
internal/slerrors/gin.go

@ -0,0 +1,35 @@
package slerrors
import (
"github.com/gin-gonic/gin"
"net/http"
)
type ErrorResponse struct {
Code int `json:"errorCode"`
Message string `json:"errorMessage"`
}
func Respond(c *gin.Context, err error) {
if IsNotFound(err) {
c.JSON(http.StatusNotFound, ErrorResponse{
Code: http.StatusNotFound,
Message: err.Error(),
})
} else if IsForbidden(err) {
c.JSON(http.StatusForbidden, ErrorResponse{
Code: http.StatusForbidden,
Message: err.Error(),
})
} else if IsBadRequest(err) {
c.JSON(http.StatusBadRequest, ErrorResponse{
Code: http.StatusBadRequest,
Message: err.Error(),
})
} else {
c.JSON(http.StatusInternalServerError, ErrorResponse{
Code: http.StatusInternalServerError,
Message: err.Error(),
})
}
}

18
internal/slerrors/notfound.go

@ -0,0 +1,18 @@
package slerrors
type notFoundError struct {
Subject string
}
func (err *notFoundError) Error() string {
return err.Subject + " not found"
}
func NotFound(subject string) error {
return &notFoundError{Subject: subject}
}
func IsNotFound(err error) bool {
_, ok := err.(*notFoundError)
return ok
}

36
internal/sqltypes/nullrawmessage.go

@ -0,0 +1,36 @@
package sqltypes
import (
"database/sql/driver"
"encoding/json"
"errors"
)
type NullRawMessage struct {
RawMessage json.RawMessage
Valid bool
}
func (n *NullRawMessage) Scan(value interface{}) error {
if value == nil {
n.RawMessage, n.Valid = json.RawMessage{}, false
return nil
}
buf, ok := value.([]byte)
if !ok {
return errors.New("cannot parse to bytes")
}
n.RawMessage, n.Valid = buf, true
return nil
}
func (n NullRawMessage) Value() (driver.Value, error) {
if !n.Valid {
return nil, nil
}
return n.RawMessage, nil
}

2
frontend/scripts/goose-mysql/20220313115117_scope.sql → scripts/goose-mysql/20220313115117_scope.sql

@ -4,7 +4,7 @@ CREATE TABLE scope (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT, `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL, `name` VARCHAR(255) NOT NULL,
`abbreviation` CHAR(8) NOT NULL `abbreviation` CHAR(8) NOT NULL
)
);
-- +goose StatementEnd -- +goose StatementEnd
-- +goose Down -- +goose Down

0
frontend/scripts/goose-mysql/20220313115122_scope_member.sql → scripts/goose-mysql/20220313115122_scope_member.sql

0
frontend/scripts/goose-mysql/20220326173144_stat.sql → scripts/goose-mysql/20220326173144_stat.sql

2
frontend/scripts/goose-mysql/20220326174046_project.sql → scripts/goose-mysql/20220326174046_project.sql

@ -9,7 +9,7 @@ CREATE TABLE project (
`description` TEXT NOT NULL, `description` TEXT NOT NULL,
UNIQUE (`scope_id`, `name`) UNIQUE (`scope_id`, `name`)
)
);
-- +goose StatementEnd -- +goose StatementEnd
-- +goose Down -- +goose Down

0
frontend/scripts/goose-mysql/20220404144911_project_requirement.sql → scripts/goose-mysql/20220404144911_project_requirement.sql

0
frontend/scripts/goose-mysql/20220404144914_item.sql → scripts/goose-mysql/20220404144914_item.sql

0
frontend/scripts/goose-mysql/20220404144947_item_stat_progress.sql → scripts/goose-mysql/20220404144947_item_stat_progress.sql

2
frontend/scripts/goose-mysql/20220404184237_project_requirement_stat.sql → scripts/goose-mysql/20220404184237_project_requirement_stat.sql

@ -6,7 +6,7 @@ CREATE TABLE project_requirement_stat (
`required` INT NOT NULL, `required` INT NOT NULL,
PRIMARY KEY (`project_requirement_id`, `stat_id`) PRIMARY KEY (`project_requirement_id`, `stat_id`)
)
);
-- +goose StatementEnd -- +goose StatementEnd
-- +goose Down -- +goose Down

9
scripts/goose-mysql/20220411190154_project_created_time.sql

@ -0,0 +1,9 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE project ADD COLUMN created_time TIMESTAMP NOT NULL DEFAULT NOW();
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE project DROP COLUMN IF EXISTS created_time;
-- +goose StatementEnd

21
sqlc.yaml

@ -0,0 +1,21 @@
version: "1"
packages:
- name: "mysqlcore"
path: "./internal/database/mysql/mysqlcore"
queries: "./internal/database/mysql/queries"
schema: "./scripts/goose-mysql"
engine: "mysql"
emit_prepared_queries: true
emit_interface: false
emit_exact_table_names: false
emit_empty_slices: true
emit_json_tags: true
overrides:
- go_type: "git.aiterp.net/stufflog3/stufflog3-api/internal/sqltypes.NullRawMessage"
db_type: "json"
nullable: true
- go_type: "float64"
db_type: "float"
- go_type: "int"
db_type: "int"

BIN
stufflog3-server

5
tools.go

@ -0,0 +1,5 @@
package stufflog3
import (
_ "github.com/kyleconroy/sqlc"
)
Loading…
Cancel
Save