feat: connect to sqlite

This commit is contained in:
Tine 2024-02-11 11:56:21 +01:00
parent 8590661534
commit 1b822156d6
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
17 changed files with 717 additions and 51 deletions

3
.gitignore vendored
View file

@ -1 +1,4 @@
dist/
# Database
gorm.db

28
cmd/generate/main.go Normal file
View file

@ -0,0 +1,28 @@
package main
import (
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/models"
"gorm.io/gen"
)
func main() {
// Initialize the generator with configuration
g := gen.NewGenerator(gen.Config{
OutPath: "internal/database/query",
Mode: gen.WithDefaultQuery | gen.WithQueryInterface,
FieldNullable: true,
})
db, _ := internal.ConnectToDatabase()
// Use the above `*gorm.DB` instance to initialize the generator,
// which is required to generate structs from db when using `GenerateModel/GenerateModelAs`
g.UseDB(db)
// Generate default DAO interface for those specified structs
g.ApplyBasic(models.Healthcheck{})
// Execute the generator
g.Execute()
}

View file

@ -9,6 +9,7 @@ import (
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/pages"
"code.tjo.space/mentos1386/zdravko/internal/static"
)
func main() {
@ -19,11 +20,19 @@ func main() {
r := mux.NewRouter()
// Server static files
r.PathPrefix("/static/").Handler(http.FileServer(http.FS(internal.Static)))
db, err := internal.ConnectToDatabase()
if err != nil {
log.Fatal(err)
}
log.Println("Connected to database")
r.HandleFunc("/", pages.Index).Methods("GET")
r.HandleFunc("/settings", pages.Settings).Methods("GET")
page := pages.NewPageHandler(db)
// Server static files
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.FS(static.Static))))
r.HandleFunc("/", page.Index).Methods("GET")
r.HandleFunc("/settings", page.Settings).Methods("GET")
log.Println("Server started on", port)
log.Fatal(http.ListenAndServe(":"+port, r))

29
go.mod
View file

@ -9,30 +9,51 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/glebarez/sqlite v1.10.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/status v1.1.1 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
go.temporal.io/api v1.24.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/genproto v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/datatypes v1.2.0 // indirect
gorm.io/driver/mysql v1.5.4 // indirect
gorm.io/gen v0.3.25 // indirect
gorm.io/gorm v1.25.7 // indirect
gorm.io/hints v1.1.2 // indirect
gorm.io/plugin/dbresolver v1.5.0 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.28.0 // indirect
)

59
go.sum
View file

@ -801,6 +801,7 @@ 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/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@ -824,6 +825,10 @@ github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40eg
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/glebarez/go-sqlite v1.22.0 h1:uAcMJhaA6r3LHMTFgP0SifzgXg46yJkgxqyuyec+ruQ=
github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL0L8Li6yQJbc=
github.com/glebarez/sqlite v1.10.0 h1:u4gt8y7OND/cCei/NMHmfbLxF6xP2wgKcT/BJf2pYkc=
github.com/glebarez/sqlite v1.10.0/go.mod h1:IJ+lfSOmiekhQsFTJRx/lHtGYmCdtAiTaf5wI9u5uHA=
github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g=
github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks=
github.com/go-fonts/liberation v0.1.1/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY=
@ -838,6 +843,10 @@ github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpx
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
@ -933,6 +942,10 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg=
@ -967,6 +980,11 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
@ -994,10 +1012,15 @@ github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WV
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
@ -1016,6 +1039,7 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
@ -1150,6 +1174,8 @@ golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -1212,6 +1238,7 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -1341,6 +1368,8 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@ -1370,6 +1399,7 @@ golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@ -1441,6 +1471,8 @@ golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
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=
@ -1767,6 +1799,25 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/datatypes v1.2.0 h1:5YT+eokWdIxhJgWHdrb2zYUimyk0+TaFth+7a0ybzco=
gorm.io/datatypes v1.2.0/go.mod h1:o1dh0ZvjIjhH/bngTpypG6lVRJ5chTBxE09FH/71k04=
gorm.io/driver/mysql v1.4.3/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
gorm.io/driver/mysql v1.5.4 h1:igQmHfKcbaTVyAIHNhhB888vvxh8EdQ2uSUT0LPcBso=
gorm.io/driver/mysql v1.5.4/go.mod h1:9rYxJph/u9SWkWc9yY4XJ1F/+xO0S/ChOmbk3+Z5Tvs=
gorm.io/driver/sqlite v1.5.0/go.mod h1:kDMDfntV9u/vuMmz8APHtHF0b4nyBB7sfCieC6G8k8I=
gorm.io/gen v0.3.25 h1:uT/1YfvcnYUdike4XPYyi89FEnVHZF115GUXQm2Sfug=
gorm.io/gen v0.3.25/go.mod h1:p+t0iCKjaPz+pKRxcx63nXdRgnrah/QD2l92747ihyA=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/hints v1.1.2 h1:b5j0kwk5p4+3BtDtYqqfY+ATSxjj+6ptPgVveuynn9o=
gorm.io/hints v1.1.2/go.mod h1:/ARdpUHAtyEMCh5NNi3tI7FsGh+Cj/MIUlvNxCNCFWg=
gorm.io/plugin/dbresolver v1.5.0 h1:XVHLxh775eP0CqVh3vcfJtYqja3uFl5Wr3cKlY8jgDY=
gorm.io/plugin/dbresolver v1.5.0/go.mod h1:l4Cn87EHLEYuqUncpEeTC2tTJQkjngPSD+lo8hIvcT0=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
@ -1805,19 +1856,27 @@ modernc.org/libc v1.18.0/go.mod h1:vj6zehR5bfc98ipowQOM2nIDUZnVew/wNC/2tOGS+q0=
modernc.org/libc v1.20.3/go.mod h1:ZRfIaEkgrYgZDl6pa4W39HgN5G/yDW+NRmNKZBDFrk0=
modernc.org/libc v1.21.4/go.mod h1:przBsL5RDOZajTVslkugzLBj1evTue36jEomFQOoYuI=
modernc.org/libc v1.22.2/go.mod h1:uvQavJ1pZ0hIoC/jfqNoMLURIMhKzINIWypNM17puug=
modernc.org/libc v1.41.0 h1:g9YAc6BkKlgORsUWj+JwqoB1wU3o4DE3bM3yvA3k+Gk=
modernc.org/libc v1.41.0/go.mod h1:w0eszPsiXoOnoMJgrXjglgLuDy/bt5RR4y3QzUUeodY=
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/mathutil v1.4.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
modernc.org/memory v1.1.1/go.mod h1:/0wo5ibyrQiaoUoH7f9D8dnglAmILJ5/cxZlRECf+Nw=
modernc.org/memory v1.2.0/go.mod h1:/0wo5ibyrQiaoUoH7f9D8dnglAmILJ5/cxZlRECf+Nw=
modernc.org/memory v1.2.1/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/memory v1.3.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/memory v1.4.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
modernc.org/opt v0.1.1/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sqlite v1.18.1/go.mod h1:6ho+Gow7oX5V+OiOQ6Tr4xeqbx13UZ6t+Fw9IRUG4d4=
modernc.org/sqlite v1.18.2/go.mod h1:kvrTLEWgxUcHa2GfHBQtanR1H9ht3hTJNtKpzH9k1u0=
modernc.org/sqlite v1.28.0 h1:Zx+LyDDmXczNnEQdvPuEfcFVA2ZPyaD7UCZDjef3BHQ=
modernc.org/sqlite v1.28.0/go.mod h1:Qxpazz0zH8Z1xCFyi5GSL3FzbtZ3fvbjmywNogldEW0=
modernc.org/strutil v1.1.1/go.mod h1:DE+MQQ/hjKBZS2zNInV5hhcipt5rLPWkmpbGeW5mmdw=
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
modernc.org/tcl v1.13.1/go.mod h1:XOLfOwzhkljL4itZkK6T72ckMgvj0BDsnKNdZVUOecw=

16
internal/database.go Normal file
View file

@ -0,0 +1,16 @@
package internal
import (
"github.com/glebarez/sqlite"
"gorm.io/gorm"
)
// go:generate just _generate-gorm
func ConnectToDatabase() (*gorm.DB, error) {
db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})
if err != nil {
return nil, err
}
return db, nil
}

View file

@ -0,0 +1,8 @@
package models
type Healthcheck struct {
ID uint `gorm:"primary_key"`
Name string
Status string // UP, DOWN
UptimePercentage float64
}

View file

@ -0,0 +1,103 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
Healthcheck *healthcheck
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Healthcheck = &Q.Healthcheck
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Healthcheck: newHealthcheck(db, opts...),
}
}
type Query struct {
db *gorm.DB
Healthcheck healthcheck
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Healthcheck: q.Healthcheck.clone(db),
}
}
func (q *Query) ReadDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Healthcheck: q.Healthcheck.replaceDB(db),
}
}
type queryCtx struct {
Healthcheck IHealthcheckDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Healthcheck: q.Healthcheck.WithContext(ctx),
}
}
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
tx := q.db.Begin(opts...)
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
}
type QueryTx struct {
*Query
Error error
}
func (q *QueryTx) Commit() error {
return q.db.Commit().Error
}
func (q *QueryTx) Rollback() error {
return q.db.Rollback().Error
}
func (q *QueryTx) SavePoint(name string) error {
return q.db.SavePoint(name).Error
}
func (q *QueryTx) RollbackTo(name string) error {
return q.db.RollbackTo(name).Error
}

View file

@ -0,0 +1,402 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"code.tjo.space/mentos1386/zdravko/internal/database"
)
func newHealthcheck(db *gorm.DB, opts ...gen.DOOption) healthcheck {
_healthcheck := healthcheck{}
_healthcheck.healthcheckDo.UseDB(db, opts...)
_healthcheck.healthcheckDo.UseModel(&database.Healthcheck{})
tableName := _healthcheck.healthcheckDo.TableName()
_healthcheck.ALL = field.NewAsterisk(tableName)
_healthcheck.ID = field.NewUint(tableName, "id")
_healthcheck.Name = field.NewString(tableName, "name")
_healthcheck.Status = field.NewString(tableName, "status")
_healthcheck.UptimePercentage = field.NewFloat64(tableName, "uptime_percentage")
_healthcheck.fillFieldMap()
return _healthcheck
}
type healthcheck struct {
healthcheckDo healthcheckDo
ALL field.Asterisk
ID field.Uint
Name field.String
Status field.String
UptimePercentage field.Float64
fieldMap map[string]field.Expr
}
func (h healthcheck) Table(newTableName string) *healthcheck {
h.healthcheckDo.UseTable(newTableName)
return h.updateTableName(newTableName)
}
func (h healthcheck) As(alias string) *healthcheck {
h.healthcheckDo.DO = *(h.healthcheckDo.As(alias).(*gen.DO))
return h.updateTableName(alias)
}
func (h *healthcheck) updateTableName(table string) *healthcheck {
h.ALL = field.NewAsterisk(table)
h.ID = field.NewUint(table, "id")
h.Name = field.NewString(table, "name")
h.Status = field.NewString(table, "status")
h.UptimePercentage = field.NewFloat64(table, "uptime_percentage")
h.fillFieldMap()
return h
}
func (h *healthcheck) WithContext(ctx context.Context) IHealthcheckDo {
return h.healthcheckDo.WithContext(ctx)
}
func (h healthcheck) TableName() string { return h.healthcheckDo.TableName() }
func (h healthcheck) Alias() string { return h.healthcheckDo.Alias() }
func (h healthcheck) Columns(cols ...field.Expr) gen.Columns { return h.healthcheckDo.Columns(cols...) }
func (h *healthcheck) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := h.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (h *healthcheck) fillFieldMap() {
h.fieldMap = make(map[string]field.Expr, 4)
h.fieldMap["id"] = h.ID
h.fieldMap["name"] = h.Name
h.fieldMap["status"] = h.Status
h.fieldMap["uptime_percentage"] = h.UptimePercentage
}
func (h healthcheck) clone(db *gorm.DB) healthcheck {
h.healthcheckDo.ReplaceConnPool(db.Statement.ConnPool)
return h
}
func (h healthcheck) replaceDB(db *gorm.DB) healthcheck {
h.healthcheckDo.ReplaceDB(db)
return h
}
type healthcheckDo struct{ gen.DO }
type IHealthcheckDo interface {
gen.SubQuery
Debug() IHealthcheckDo
WithContext(ctx context.Context) IHealthcheckDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IHealthcheckDo
WriteDB() IHealthcheckDo
As(alias string) gen.Dao
Session(config *gorm.Session) IHealthcheckDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IHealthcheckDo
Not(conds ...gen.Condition) IHealthcheckDo
Or(conds ...gen.Condition) IHealthcheckDo
Select(conds ...field.Expr) IHealthcheckDo
Where(conds ...gen.Condition) IHealthcheckDo
Order(conds ...field.Expr) IHealthcheckDo
Distinct(cols ...field.Expr) IHealthcheckDo
Omit(cols ...field.Expr) IHealthcheckDo
Join(table schema.Tabler, on ...field.Expr) IHealthcheckDo
LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo
RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo
Group(cols ...field.Expr) IHealthcheckDo
Having(conds ...gen.Condition) IHealthcheckDo
Limit(limit int) IHealthcheckDo
Offset(offset int) IHealthcheckDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckDo
Unscoped() IHealthcheckDo
Create(values ...*database.Healthcheck) error
CreateInBatches(values []*database.Healthcheck, batchSize int) error
Save(values ...*database.Healthcheck) error
First() (*database.Healthcheck, error)
Take() (*database.Healthcheck, error)
Last() (*database.Healthcheck, error)
Find() ([]*database.Healthcheck, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*database.Healthcheck, err error)
FindInBatches(result *[]*database.Healthcheck, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*database.Healthcheck) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IHealthcheckDo
Assign(attrs ...field.AssignExpr) IHealthcheckDo
Joins(fields ...field.RelationField) IHealthcheckDo
Preload(fields ...field.RelationField) IHealthcheckDo
FirstOrInit() (*database.Healthcheck, error)
FirstOrCreate() (*database.Healthcheck, error)
FindByPage(offset int, limit int) (result []*database.Healthcheck, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IHealthcheckDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (h healthcheckDo) Debug() IHealthcheckDo {
return h.withDO(h.DO.Debug())
}
func (h healthcheckDo) WithContext(ctx context.Context) IHealthcheckDo {
return h.withDO(h.DO.WithContext(ctx))
}
func (h healthcheckDo) ReadDB() IHealthcheckDo {
return h.Clauses(dbresolver.Read)
}
func (h healthcheckDo) WriteDB() IHealthcheckDo {
return h.Clauses(dbresolver.Write)
}
func (h healthcheckDo) Session(config *gorm.Session) IHealthcheckDo {
return h.withDO(h.DO.Session(config))
}
func (h healthcheckDo) Clauses(conds ...clause.Expression) IHealthcheckDo {
return h.withDO(h.DO.Clauses(conds...))
}
func (h healthcheckDo) Returning(value interface{}, columns ...string) IHealthcheckDo {
return h.withDO(h.DO.Returning(value, columns...))
}
func (h healthcheckDo) Not(conds ...gen.Condition) IHealthcheckDo {
return h.withDO(h.DO.Not(conds...))
}
func (h healthcheckDo) Or(conds ...gen.Condition) IHealthcheckDo {
return h.withDO(h.DO.Or(conds...))
}
func (h healthcheckDo) Select(conds ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Select(conds...))
}
func (h healthcheckDo) Where(conds ...gen.Condition) IHealthcheckDo {
return h.withDO(h.DO.Where(conds...))
}
func (h healthcheckDo) Order(conds ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Order(conds...))
}
func (h healthcheckDo) Distinct(cols ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Distinct(cols...))
}
func (h healthcheckDo) Omit(cols ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Omit(cols...))
}
func (h healthcheckDo) Join(table schema.Tabler, on ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Join(table, on...))
}
func (h healthcheckDo) LeftJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.LeftJoin(table, on...))
}
func (h healthcheckDo) RightJoin(table schema.Tabler, on ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.RightJoin(table, on...))
}
func (h healthcheckDo) Group(cols ...field.Expr) IHealthcheckDo {
return h.withDO(h.DO.Group(cols...))
}
func (h healthcheckDo) Having(conds ...gen.Condition) IHealthcheckDo {
return h.withDO(h.DO.Having(conds...))
}
func (h healthcheckDo) Limit(limit int) IHealthcheckDo {
return h.withDO(h.DO.Limit(limit))
}
func (h healthcheckDo) Offset(offset int) IHealthcheckDo {
return h.withDO(h.DO.Offset(offset))
}
func (h healthcheckDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IHealthcheckDo {
return h.withDO(h.DO.Scopes(funcs...))
}
func (h healthcheckDo) Unscoped() IHealthcheckDo {
return h.withDO(h.DO.Unscoped())
}
func (h healthcheckDo) Create(values ...*database.Healthcheck) error {
if len(values) == 0 {
return nil
}
return h.DO.Create(values)
}
func (h healthcheckDo) CreateInBatches(values []*database.Healthcheck, batchSize int) error {
return h.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (h healthcheckDo) Save(values ...*database.Healthcheck) error {
if len(values) == 0 {
return nil
}
return h.DO.Save(values)
}
func (h healthcheckDo) First() (*database.Healthcheck, error) {
if result, err := h.DO.First(); err != nil {
return nil, err
} else {
return result.(*database.Healthcheck), nil
}
}
func (h healthcheckDo) Take() (*database.Healthcheck, error) {
if result, err := h.DO.Take(); err != nil {
return nil, err
} else {
return result.(*database.Healthcheck), nil
}
}
func (h healthcheckDo) Last() (*database.Healthcheck, error) {
if result, err := h.DO.Last(); err != nil {
return nil, err
} else {
return result.(*database.Healthcheck), nil
}
}
func (h healthcheckDo) Find() ([]*database.Healthcheck, error) {
result, err := h.DO.Find()
return result.([]*database.Healthcheck), err
}
func (h healthcheckDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*database.Healthcheck, err error) {
buf := make([]*database.Healthcheck, 0, batchSize)
err = h.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (h healthcheckDo) FindInBatches(result *[]*database.Healthcheck, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return h.DO.FindInBatches(result, batchSize, fc)
}
func (h healthcheckDo) Attrs(attrs ...field.AssignExpr) IHealthcheckDo {
return h.withDO(h.DO.Attrs(attrs...))
}
func (h healthcheckDo) Assign(attrs ...field.AssignExpr) IHealthcheckDo {
return h.withDO(h.DO.Assign(attrs...))
}
func (h healthcheckDo) Joins(fields ...field.RelationField) IHealthcheckDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Joins(_f))
}
return &h
}
func (h healthcheckDo) Preload(fields ...field.RelationField) IHealthcheckDo {
for _, _f := range fields {
h = *h.withDO(h.DO.Preload(_f))
}
return &h
}
func (h healthcheckDo) FirstOrInit() (*database.Healthcheck, error) {
if result, err := h.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*database.Healthcheck), nil
}
}
func (h healthcheckDo) FirstOrCreate() (*database.Healthcheck, error) {
if result, err := h.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*database.Healthcheck), nil
}
}
func (h healthcheckDo) FindByPage(offset int, limit int) (result []*database.Healthcheck, count int64, err error) {
result, err = h.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = h.Offset(-1).Limit(-1).Count()
return
}
func (h healthcheckDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = h.Count()
if err != nil {
return
}
err = h.Offset(offset).Limit(limit).Scan(result)
return
}
func (h healthcheckDo) Scan(result interface{}) (err error) {
return h.DO.Scan(result)
}
func (h healthcheckDo) Delete(models ...*database.Healthcheck) (result gen.ResultInfo, err error) {
return h.DO.Delete(models)
}
func (h *healthcheckDo) withDO(do gen.Dao) *healthcheckDo {
h.DO = *do.(*gen.DO)
return h
}

View file

@ -4,13 +4,13 @@ import (
"net/http"
"text/template"
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/ui"
)
func Index(w http.ResponseWriter, r *http.Request) {
ts, err := template.ParseFS(internal.Templates,
"ui/components/base.tmpl",
"ui/pages/index.tmpl",
func (p *PageHandler) Index(w http.ResponseWriter, r *http.Request) {
ts, err := template.ParseFS(ui.Templates,
"components/base.tmpl",
"pages/index.tmpl",
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)

11
internal/pages/pages.go Normal file
View file

@ -0,0 +1,11 @@
package pages
import "gorm.io/gorm"
type PageHandler struct {
db *gorm.DB
}
func NewPageHandler(db *gorm.DB) *PageHandler {
return &PageHandler{db}
}

View file

@ -4,13 +4,13 @@ import (
"net/http"
"text/template"
"code.tjo.space/mentos1386/zdravko/internal"
"code.tjo.space/mentos1386/zdravko/internal/ui"
)
func Settings(w http.ResponseWriter, r *http.Request) {
ts, err := template.ParseFS(internal.Templates,
"ui/components/base.tmpl",
"ui/pages/settings.tmpl",
func (p *PageHandler) Settings(w http.ResponseWriter, r *http.Request) {
ts, err := template.ParseFS(ui.Templates,
"components/base.tmpl",
"pages/settings.tmpl",
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)

View file

@ -1,9 +0,0 @@
package internal
import (
"embed"
)
//go:generate just tailwindcss-build
//go:embed static
var Static embed.FS

11
internal/static/static.go Normal file
View file

@ -0,0 +1,11 @@
package static
import (
"embed"
)
//go:generate just _tailwindcss-build
//go:generate just _htmx-download
//go:generate just _feather-icons-download
//go:embed *
var Static embed.FS

View file

@ -1,8 +1,8 @@
package internal
package ui
import (
"embed"
)
//go:embed ui
//go:embed *
var Templates embed.FS

View file

@ -3,23 +3,9 @@ set shell := ["devbox", "run"]
STATIC_DIR := "./internal/static"
# Start devbox shell
shell:
devbox shell
tailwindcss-build:
tailwindcss build -i {{STATIC_DIR}}/css/main.css -o {{STATIC_DIR}}/css/tailwind.css
htmx-download:
mkdir -p {{STATIC_DIR}}/js
curl -sLo {{STATIC_DIR}}/js/htmx.min.js https://unpkg.com/htmx.org/dist/htmx.min.js
feather-icons-download:
mkdir -p {{STATIC_DIR}}/icons
curl -sLo {{STATIC_DIR}}/icons/feather-sprite.svg https://unpkg.com/feather-icons/dist/feather-sprite.svg
generate:
go generate ./...
# Run full development environment
run:
devbox services up
# Start temporal which is accassible at http://localhost:8233/
run-temporal:
@ -35,10 +21,28 @@ run-worker:
go build -o dist/worker cmd/worker/main.go
./dist/worker
# Run full development environment
run:
devbox services up
# Deploy the application to fly.io
deploy:
fly deploy
# Start devbox shell
shell:
devbox shell
# Generate and download all external dependencies.
generate:
go generate ./...
_tailwindcss-build:
tailwindcss build -i {{STATIC_DIR}}/css/main.css -o {{STATIC_DIR}}/css/tailwind.css
_htmx-download:
mkdir -p {{STATIC_DIR}}/js
curl -sLo {{STATIC_DIR}}/js/htmx.min.js https://unpkg.com/htmx.org/dist/htmx.min.js
_feather-icons-download:
mkdir -p {{STATIC_DIR}}/icons
curl -sLo {{STATIC_DIR}}/icons/feather-sprite.svg https://unpkg.com/feather-icons/dist/feather-sprite.svg
_generate-gorm:
go run cmd/generate/main.go

View file

@ -2,7 +2,7 @@ version: "0.5"
processes:
tailwind:
command: watchexec -r -e go,tmpl,css just tailwindcss-build
command: watchexec -r -e go,tmpl,css just _tailwindcss-build
availability:
restart: "always"
server: