-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (59 loc) · 1.61 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
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"github.com/gin-gonic/gin"
"github.com/saibaggins/etherfufu-server/controllers"
"github.com/saibaggins/etherfufu-server/core"
"github.com/saibaggins/etherfufu-server/core/middlewares"
"net/http"
)
const (
Production = "production"
)
type ErrorResponse struct {
Code string `json:"code"`
Message string `json:"message"`
}
func main() {
setAppVerbosity()
router := gin.New()
loadMiddlewares(router)
defineRoutes(router)
// Initialize the server
http.ListenAndServe(":3000", router)
}
func setAppVerbosity() {
if core.ActiveENV() == Production {
gin.SetMode(gin.ReleaseMode)
}
}
// Load Middlewares
func loadMiddlewares(router *gin.Engine) {
router.Use(gin.Logger())
router.Use(gin.Recovery())
router.Use(middlewares.CORSMiddleware())
router.Use(gin.ErrorLogger())
}
// Define the routes
func defineRoutes(router *gin.Engine) {
v1 := router.Group("/v1")
{
audiobank := v1.Group("/audiobank")
{
audiobank_controller := new(controllers.DisplayOptionController)
audiobank.GET("options", audiobank_controller.ListAll)
audiobank.PUT("options", audiobank_controller.Create)
metadata_controller := new(controllers.MetadataController)
audiobank.POST("metadata", metadata_controller.Create)
audiobank.POST("metadata/:metadata_id/sample", metadata_controller.UploadAudioSample)
}
home_controller := new(controllers.HomeController)
v1.Any("call", home_controller.Call)
}
router.NoRoute(func(c *gin.Context) {
statusCode := http.StatusNotFound
c.JSON(http.StatusNotFound, ErrorResponse{
Code: "NOT_FOUND",
Message: http.StatusText(statusCode),
})
})
}