diff --git a/{{cookiecutter.project_name}}/Dockerfile b/{{cookiecutter.project_name}}/Dockerfile index aa9e66d..668abb1 100644 --- a/{{cookiecutter.project_name}}/Dockerfile +++ b/{{cookiecutter.project_name}}/Dockerfile @@ -10,7 +10,7 @@ COPY . . RUN go mod download # Builds the application as a staticly linked one, to allow it to run on alpine -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app cmd/{{cookiecutter.project_name}}.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app cmd/{{cookiecutter.project_name}}/main.go # Moving the binary to the 'final Image' to make it smaller diff --git a/{{cookiecutter.project_name}}/cmd/{{cookiecutter.project_name}}.go b/{{cookiecutter.project_name}}/cmd/{{cookiecutter.project_name}}.go deleted file mode 100644 index af68c20..0000000 --- a/{{cookiecutter.project_name}}/cmd/{{cookiecutter.project_name}}.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "log" - - "github.com/gofiber/fiber/v2" -) - -func main() { - app := fiber.New() - - app.Get("/", func (c *fiber.Ctx) error { - return c.SendString("Hello, World!") - }) - - log.Fatal(app.Listen(":3000")) -} diff --git a/{{cookiecutter.project_name}}/cmd/{{cookiecutter.project_name}}/main.go b/{{cookiecutter.project_name}}/cmd/{{cookiecutter.project_name}}/main.go new file mode 100644 index 0000000..bcc7886 --- /dev/null +++ b/{{cookiecutter.project_name}}/cmd/{{cookiecutter.project_name}}/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "log" + + "{{cookiecutter.module_path}}/internal/app" +) + +func main() { + if err := app.Run(); err != nil { + log.Fatal(err) + } +} diff --git a/{{cookiecutter.project_name}}/internal/routes/api/router.go b/{{cookiecutter.project_name}}/internal/routes/api/router.go new file mode 100644 index 0000000..3f7897e --- /dev/null +++ b/{{cookiecutter.project_name}}/internal/routes/api/router.go @@ -0,0 +1,20 @@ +package api + +import ( + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/helmet" + v1 "{{cookiecutter.module_path}}/internal/app/api/v1" +) + +func ConfigureRoutes(router *fiber.App) error { + api := router.Group("/api") + + api.Use(helmet.New()) + + err := v1.ConfigureRoutes(api) + if err != nil { + return err + } + + return nil +} diff --git a/{{cookiecutter.project_name}}/internal/routes/api/v1/router.go b/{{cookiecutter.project_name}}/internal/routes/api/v1/router.go new file mode 100644 index 0000000..dd16347 --- /dev/null +++ b/{{cookiecutter.project_name}}/internal/routes/api/v1/router.go @@ -0,0 +1,15 @@ +package v1 + +import ( + "github.com/gofiber/fiber/v2" +) + +func ConfigureRoutes(router fiber.Router) error { + v1 := router.Group("/v1") + + v1.Get("/ping", func(c *fiber.Ctx) error { + return c.SendString("pong") + }) + + return nil +} diff --git a/{{cookiecutter.project_name}}/internal/routes/main.go b/{{cookiecutter.project_name}}/internal/routes/main.go new file mode 100644 index 0000000..79b4e9d --- /dev/null +++ b/{{cookiecutter.project_name}}/internal/routes/main.go @@ -0,0 +1,19 @@ +package app + +import ( + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/compress" + "github.com/gofiber/fiber/v2/middleware/logger" + "{{cookiecutter.module_path}}/internal/app/api" +) + +func Run() error { + app := fiber.New() + + app.Use(logger.New()) + app.Use(compress.New()) + + api.ConfigureRoutes(app) + + return app.Listen(":3000") +} diff --git a/{{cookiecutter.project_name}}/justfile b/{{cookiecutter.project_name}}/justfile index 1cd0c17..9a321f9 100644 --- a/{{cookiecutter.project_name}}/justfile +++ b/{{cookiecutter.project_name}}/justfile @@ -2,7 +2,7 @@ project_name := "{{cookiecutter.project_name}}" image_name := "{{cookiecutter.image_name}}" run: ## Run the app - go run cmd/{{cookiecutter.project_name}}.go + go run cmd/{{cookiecutter.project_name}}/main.go {% raw -%} tidy: ## Generate go.mod & go.sum files