Added directory structure for routing
This commit is contained in:
parent
2fba1066f8
commit
416eb415a9
@ -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
|
||||
|
@ -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"))
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"{{cookiecutter.module_path}}/internal/app"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := app.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
20
{{cookiecutter.project_name}}/internal/routes/api/router.go
Normal file
20
{{cookiecutter.project_name}}/internal/routes/api/router.go
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
}
|
19
{{cookiecutter.project_name}}/internal/routes/main.go
Normal file
19
{{cookiecutter.project_name}}/internal/routes/main.go
Normal file
@ -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")
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user