Skip to content

Commit 54d5668

Browse files
committed
refactor: project file structure
1 parent 2398307 commit 54d5668

24 files changed

+205
-1293
lines changed

Dockerfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
FROM golang:1.21.0-bullseye
1+
FROM golang:1.21.0-bookworm
22
WORKDIR /app
33
COPY go.mod ./
44
COPY go.sum ./
55
RUN go mod download
66
RUN go install github.com/swaggo/swag/cmd/swag@latest
77
COPY . /app
8-
RUN swag init
8+
RUN swag init --dir cmd/server/
99
EXPOSE 8001
10-
CMD go run main.go
10+
RUN CGO_ENABLED=1 go build -o ./bin/server cmd/server/main.go
11+
CMD ./bin/server

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ setup:
33
swag init
44

55
build:
6-
docker compose up --build
6+
docker compose build --no-cache
77

88
up:
99
docker compose up
@@ -19,5 +19,6 @@ clean:
1919
docker stop dockerPostgres
2020
docker rm go-rest-api-template
2121
docker rm dockerPostgres
22-
docker image rm go-rest-api-template
22+
docker rm dockerRedis
23+
docker image rm golang-rest-api-template-backend
2324
rm -rf .dbdata

bin/server

33.5 MB
Binary file not shown.

cmd/server/main.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"golang-rest-api-template/pkg/api"
5+
"golang-rest-api-template/pkg/cache"
6+
"golang-rest-api-template/pkg/database"
7+
"log"
8+
9+
"github.com/gin-gonic/gin"
10+
)
11+
12+
// @title Swagger Example API
13+
// @version 1.0
14+
// @description This is a sample server celler server.
15+
// @termsOfService http://swagger.io/terms/
16+
17+
// @contact.name API Support
18+
// @contact.url http://www.swagger.io/support
19+
// @contact.email [email protected]
20+
21+
// @license.name Apache 2.0
22+
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
23+
24+
// @host localhost:8001
25+
// @BasePath /api/v1
26+
27+
// @securityDefinitions.apikey JwtAuth
28+
// @in header
29+
// @name Authorization
30+
31+
// @securityDefinitions.apikey ApiKeyAuth
32+
// @in header
33+
// @name X-API-Key
34+
35+
// @externalDocs.description OpenAPI
36+
// @externalDocs.url https://swagger.io/resources/open-api/
37+
func main() {
38+
cache.InitRedis()
39+
database.ConnectDatabase()
40+
41+
//gin.SetMode(gin.ReleaseMode)
42+
gin.SetMode(gin.DebugMode)
43+
44+
r := api.InitRouter()
45+
46+
if err := r.Run(":8001"); err != nil {
47+
log.Fatal(err)
48+
}
49+
}

0 commit comments

Comments
 (0)