Skip to content

Commit

Permalink
Incorporate Templ templates
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Balogh <javaducky@gmail.com>
  • Loading branch information
javaducky committed May 22, 2024
1 parent b2546fd commit 0570d9e
Show file tree
Hide file tree
Showing 28 changed files with 18,694 additions and 70 deletions.
8 changes: 5 additions & 3 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ tmp_dir = "tmp"
[build]
args_bin = []
bin = "./bin/weesvc"
cmd = "go build -o ./bin/weesvc .; ./bin/weesvc migrate"
## Templ will be watching for template changes, which then regenerate Go files.
## We just need to rebuild and notify the proxy to refresh the browser.
cmd = "go build -o ./bin/weesvc . && templ generate --notify-proxy"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_regex = ["_test.go", "_templ.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_ext = ["go", "tpl", "tmpl", "templ", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@
# Ignore other project items
artifacts/
bin/
tmp/
gorm.db
*_templ.go
*_templ.txt
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ test:

## imports: Organizes imports within the codebase.
imports:
echo "Organizing imports..."
goimports -w -l --local $(BASE_MODULE) .
echo "[SKIPPING] Organizing imports..."
# goimports -w -l --local $(BASE_MODULE) .

## fmt: Applies appropriate formatting on the codebase.
fmt:
Expand Down Expand Up @@ -109,7 +109,9 @@ release-docker: build-docker
## develop: Start the application in hot-reload mode.
develop: build-only
go install github.com/cosmtrek/air@latest
air -c ./.air.toml -- serve
go install github.com/a-h/templ/cmd/templ@latest
templ generate --watch --proxy=http://localhost:9092 &
air -c ./.air.toml -- serve -c config-postgres.yaml --server-port=9092


.PHONY: build build-all \
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func newRootCommand() *cobra.Command {
},
}

rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "config file")
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "config file")
rootCmd.PersistentFlags().BoolVar(&cfg.Verbose, "verbose", false, "verbose output")

_ = viper.BindPFlag("Verbose", rootCmd.PersistentFlags().Lookup("verbose"))
Expand Down
8 changes: 4 additions & 4 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func newServeCommand(config *config.Config) *cobra.Command {
serveCmd := &cobra.Command{
Use: "serve",
Short: "Starts the application server",
RunE: func(_ *cobra.Command, _ []string) error {
return server.StartServer(config)
Run: func(_ *cobra.Command, _ []string) {
server.StartServer(config)
},
}

serveCmd.PersistentFlags().IntVarP(&config.Port, "api-port", "p", 9092, "port to access the api")
serveCmd.PersistentFlags().IntVarP(&config.Port, "server-port", "p", 9092, "port to access the api")
serveCmd.PersistentFlags().StringVar(&config.Dialect, "dialect", "sqlite3", "database dialect")
serveCmd.PersistentFlags().StringVar(&config.DatabaseURI, "database-uri", "", "database connection string")

_ = viper.BindPFlag("Port", serveCmd.PersistentFlags().Lookup("api-port"))
_ = viper.BindPFlag("Port", serveCmd.PersistentFlags().Lookup("server-port"))
_ = viper.BindPFlag("Dialect", serveCmd.PersistentFlags().Lookup("dialect"))
_ = viper.BindPFlag("DatabaseURI", serveCmd.PersistentFlags().Lookup("database-uri"))

Expand Down
4 changes: 4 additions & 0 deletions config-postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DatabaseURI: "postgres://postgres:postgres@localhost:5432/weesvc?sslmode=disable"
# Specify dialect as "postgres" or "sqlite3". "sqlite3" is default.
Dialect: postgres
Verbose: false
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
db:
image: postgres:15.3-alpine
volumes:
- ./testdata/:/docker-entrypoint-initdb.d/
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_DB: weesvc
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/weesvc/weesvc-gorilla
go 1.22.3

require (
github.com/a-h/templ v0.2.697
github.com/google/uuid v1.6.0
github.com/gorilla/handlers v1.5.2
github.com/gorilla/mux v1.8.1
Expand All @@ -21,7 +22,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/containerd/containerd v1.7.11 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/a-h/templ v0.2.697 h1:OILxtWvD0NRJaoCOiZCopRDPW8paroKlGsrAiHLykNE=
github.com/a-h/templ v0.2.697/go.mod h1:5cqsugkq9IerRNucNsI4DEamdHPsoGMQy99DzydLhM8=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/containerd/containerd v1.7.11 h1:lfGKw3eU35sjV0aG2eYZTiwFEY1pCzxdzicHP3SZILw=
github.com/containerd/containerd v1.7.11/go.mod h1:5UluHxHTX2rdvYuZ5OJTC5m/KJNs0Zs9wVoJm9zf5ZE=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0570d9e

Please sign in to comment.