Skip to content

Commit

Permalink
Use [[ and ]] as delims
Browse files Browse the repository at this point in the history
  • Loading branch information
lfritz committed Feb 23, 2024
1 parent c7e5b98 commit 2d7a38d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
11 changes: 3 additions & 8 deletions gootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ func generate(name, group string) {
}

applyTemplate := func(templ string) string {
// Why: some files, like Github CI files, have notation identical
// To Go templates. So for now we just try to apply the template and if it
// fails we assume it should be used as is (not the safest option, but no more time to deal
// with this right now).
t, err := template.New("templ").Parse(templ)
if err != nil {
return templ
}
// we use [[ and ]] because {{ and }} are also used by GitHub workflow definitions
t, err := template.New("templ").Delims("[[", "]]").Parse(templ)
assert(err)
result := bytes.Buffer{}
assert(t.Execute(&result, info))
return result.String()
Expand Down
2 changes: 1 addition & 1 deletion templates/basic/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
go.work

coverage.txt
cmd/{{.Name}}/{{.Name}}
cmd/[[.Name]]/[[.Name]]
tmp/
4 changes: 2 additions & 2 deletions templates/basic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ RUN make service

FROM docker.io/alpine:${ALPINE_VERSION}
RUN apk --no-cache add ca-certificates
COPY --from=builder /app/cmd/{{.Name}}/{{.Name}} /usr/bin/{{.Name}}
CMD ["{{.Name}}"]
COPY --from=builder /app/cmd/[[.Name]]/[[.Name]] /usr/bin/[[.Name]]
CMD ["[[.Name]]"]
10 changes: 5 additions & 5 deletions templates/basic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ALPINE_VERSION=3.19

# configuration/aliases
version=$(shell git rev-parse --short HEAD)
base_image=us-central1-docker.pkg.dev/birdie-org/birdie/{{.Group}}/{{.Name}}
base_image=us-central1-docker.pkg.dev/birdie-org/birdie/[[.Group]]/[[.Name]]
image=$(base_image):$(version)
devimage={{.Name}}-dev
devimage=[[.Name]]-dev
# To avoid downloading deps everytime it runs on containers
gopkg=$(devimage)-gopkg
gocache=$(devimage)-gocache
Expand All @@ -36,12 +36,12 @@ fmt:
## builds the service
.PHONY: service
service:
go build -o ./cmd/{{.Name}}/{{.Name}} ./cmd/{{.Name}}
go build -o ./cmd/[[.Name]]/[[.Name]] ./cmd/[[.Name]]

## runs the service locally
.PHONY: run
run: service
./cmd/{{.Name}}/{{.Name}}
./cmd/[[.Name]]/[[.Name]]

## tidy up go modules
.PHONY: mod
Expand Down Expand Up @@ -71,7 +71,7 @@ test/coverage/show: test/coverage
## Configure a proxy to the service running on GKE (environment depends on which cluster is configured on kubectl).
.PHONY: port-forward
port-forward:
kubectl port-forward -n enrichment service/{{.Name}} 8080:80
kubectl port-forward -n enrichment service/[[.Name]] 8080:80

## Build the service image
.PHONY: image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// {{.Name}} runs the service.
// [[.Name]] runs the service.
// For details on how to configure it just run:
//
// {{.Name}} --help
// [[.Name]] --help
package main

import (
Expand All @@ -11,13 +11,13 @@ import (
)

func main() {
logcfg, err := slog.LoadConfig("{{.ConfigPrefix}}")
logcfg, err := slog.LoadConfig("[[.ConfigPrefix]]")
abortonerr(err)

err = slog.Configure(logcfg)
abortonerr(err)

slog.Info("TODO: implement {{.Name}}")
slog.Info("TODO: implement [[.Name]]")
}

func abortonerr(err error) {
Expand Down
2 changes: 1 addition & 1 deletion templates/basic/go.mod.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/birdie-ai/{{.Name}}
module github.com/birdie-ai/[[.Name]]

go 1.21

Expand Down

0 comments on commit 2d7a38d

Please sign in to comment.