mirror of
https://github.com/makayabou/asg-server.git
synced 2026-05-02 17:43:36 +02:00
[api] embed docs in binary
This commit is contained in:
parent
67e5d1314c
commit
c22f4f1e80
2
Makefile
2
Makefile
@ -51,7 +51,7 @@ docker-dev:
|
||||
|
||||
api-docs:
|
||||
swag fmt -g ./cmd/$(project_name)/main.go \
|
||||
&& swag init --parseDependency -g ./cmd/$(project_name)/main.go -o ./api
|
||||
&& swag init --outputTypes json,yaml --parseDependency -g ./cmd/$(project_name)/main.go -o ./pkg/swagger/docs
|
||||
|
||||
view-docs:
|
||||
php -S 127.0.0.1:8080 -t ./api
|
||||
|
||||
@ -1 +0,0 @@
|
||||
module dummy
|
||||
@ -22,7 +22,7 @@ COPY . .
|
||||
RUN sed -i "s/{APP_VERSION}/${APP_VERSION}/g" ./cmd/${APP}/main.go
|
||||
|
||||
# Generate swagger docs
|
||||
RUN swag init --parseDependency -g ./cmd/${APP}/main.go -o ./api
|
||||
RUN go generate ./...
|
||||
|
||||
# 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 .
|
||||
@ -37,7 +37,6 @@ RUN apk add --no-cache tzdata
|
||||
|
||||
COPY scripts/docker-entrypoint.sh /docker-entrypoint.sh
|
||||
|
||||
COPY --from=build /go/src/api /app/api
|
||||
COPY --from=build /go/src/app /app
|
||||
|
||||
# Exposes port 3000 because our program listens on that port
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/capcom6/sms-gateway/pkg/swagger"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||
)
|
||||
|
||||
type rootHandler struct {
|
||||
@ -18,7 +22,12 @@ func (h *rootHandler) Register(app *fiber.App) {
|
||||
})
|
||||
|
||||
h.healthHandler.Register(app)
|
||||
app.Static("/api", "api")
|
||||
app.Use("/api", filesystem.New(filesystem.Config{
|
||||
Root: http.FS(swagger.Docs),
|
||||
PathPrefix: "docs",
|
||||
MaxAge: 1 * 24 * 60 * 60,
|
||||
}))
|
||||
// app.Static("/api", "api")
|
||||
}
|
||||
|
||||
func newRootHandler(healthHandler *healthHandler) *rootHandler {
|
||||
|
||||
|
Before Width: | Height: | Size: 665 B After Width: | Height: | Size: 665 B |
|
Before Width: | Height: | Size: 628 B After Width: | Height: | Size: 628 B |
8
pkg/swagger/swagger.go
Normal file
8
pkg/swagger/swagger.go
Normal file
@ -0,0 +1,8 @@
|
||||
package swagger
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:generate swag init --parseDependency --outputTypes json,yaml -d ../../ -g ./cmd/sms-gateway/main.go -o ../../pkg/swagger/docs
|
||||
|
||||
//go:embed docs/*.png docs/*.js docs/*.css docs/swagger.* docs/*.html
|
||||
var Docs embed.FS
|
||||
Loading…
x
Reference in New Issue
Block a user