Skip to content

Commit

Permalink
auto import codegen package
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Wasko <[email protected]>
  • Loading branch information
Alice-Lilith committed May 9, 2024
1 parent 1c533cd commit 304519d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Ambassador Labs Go Generator",
"description": "Generates a new project for an API server writen in go",
"version": "0.0.2",
"version": "0.0.3",
"languages": ["go"],
"dir_name": "go"
}]
Expand Down
2 changes: 1 addition & 1 deletion generators/go/base/cmd/binary/main.go.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
api "{{{ .GoModule }}}/internal/{{{ toDir .ProjectName }}}"
api "{{{ .GoModule }}}/internal/{{{ _toDir .ProjectName }}}"
)

func main() {
Expand Down
8 changes: 7 additions & 1 deletion generators/go/base/internal/binary/server.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"os"
"time"

{{{- if _isCodegenEnabled }}}
api "{{{ .GoModule }}}/internal/api"
{{{ end -}}}

"github.com/gorilla/mux"
"github.com/rs/zerolog"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -63,7 +67,9 @@ func (s *apiService) Serve(ctx context.Context) error {
router.HandleFunc("/", s.handle404)
router.HandleFunc("/about", s.handleAbout)

{{{ codeGenGorillaMux "router" }}}
{{{- if _isCodegenEnabled }}}
{{{ _codegenGoAddRoutesToGorillaRouter "router" }}}
{{{ end -}}}

loggedMux := s.logMiddleware(router)

Expand Down
6 changes: 3 additions & 3 deletions generators/go/generator-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
metadata:
name: "Ambassador Labs Go Generator"
description: "Generates a new project for an API server writen in go"
version: "0.0.2"
version: "0.0.3"
languages: ["go"]

# Defines the base directory within the template folder.
Expand Down Expand Up @@ -80,9 +80,9 @@ variables:

renames:
- path: "base/cmd/binary"
value: "{{{ toDir .ProjectName }}}"
value: "{{{ _toDir .ProjectName }}}"
- path: "base/internal/binary"
value: "{{{ toDir .ProjectName }}}"
value: "{{{ _toDir .ProjectName }}}"

# TODO: Add support for conditions for auto loading modules?
# TODO: Add a description field
Expand Down

0 comments on commit 304519d

Please sign in to comment.