-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (48 loc) · 1.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"embed"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/scheidti/docker-mailserver-aliases/docs"
"github.com/scheidti/docker-mailserver-aliases/routes"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Docker Mailserver Aliases API
// @version 1.0
// @description API for managing aliases in a Docker Mailserver container
// @contact.name Christian Scheid
// @contact.url https://github.com/scheidti/docker-mailserver-aliases
// @contact.email [email protected]
// @license.name MIT
// @license.url https://github.com/scheidti/docker-mailserver-aliases?tab=MIT-1-ov-file#readme
// @host localhost:8080
//go:embed frontend/dist/*
var frontend embed.FS
func main() {
engine := gin.Default()
docs.SwaggerInfo.BasePath = "/"
api := engine.Group("/v1")
{
api.GET("/status", routes.StatusGetHandler)
api.GET("/emails", routes.EmailsGetHandler)
api.GET("/aliases", routes.AliasesGetHandler)
api.POST("/aliases", routes.AliasesPostHandler)
api.DELETE("/aliases/:alias", routes.AliasesDeleteHandler)
}
addr := os.Getenv("GIN_ADDR")
if addr == "" {
addr = ":8080"
}
if gin.Mode() != gin.ReleaseMode {
engine.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}
engine.NoRoute(serveFrontend)
engine.Run(addr)
}
func serveFrontend(c *gin.Context) {
fileServer := http.StripPrefix("/", http.FileServer(http.FS(frontend)))
c.Request.URL.Path = "/frontend/dist" + c.Request.URL.Path
fileServer.ServeHTTP(c.Writer, c.Request)
}