generated from Caknoooo/go-gin-clean-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (54 loc) · 1.23 KB
/
main.go
File metadata and controls
71 lines (54 loc) · 1.23 KB
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
package main
import (
"log"
"os"
"github.com/Lab-RPL-ITS/twitter-clone-api/command"
"github.com/Lab-RPL-ITS/twitter-clone-api/middleware"
"github.com/Lab-RPL-ITS/twitter-clone-api/provider"
"github.com/Lab-RPL-ITS/twitter-clone-api/routes"
"github.com/samber/do"
"github.com/common-nighthawk/go-figure"
"github.com/gin-gonic/gin"
)
func args(injector *do.Injector) bool {
if len(os.Args) > 1 {
flag := command.Commands(injector)
return flag
}
return true
}
func run(server *gin.Engine) {
server.Static("/assets", "./assets")
if os.Getenv("IS_LOGGER") == "true" {
routes.LoggerRoute(server)
}
port := os.Getenv("PORT")
if port == "" {
port = "8888"
}
var serve string
if os.Getenv("APP_ENV") == "localhost" {
serve = "127.0.0.1:" + port
} else {
serve = ":" + port
}
myFigure := figure.NewColorFigure("Twitter Clone API", "", "green", true)
myFigure.Print()
if err := server.Run(serve); err != nil {
log.Fatalf("error running server: %v", err)
}
}
func main() {
var (
injector = do.New()
)
provider.RegisterDependencies(injector)
if !args(injector) {
return
}
server := gin.Default()
server.Use(middleware.CORSMiddleware())
// routes
routes.RegisterRoutes(server, injector)
run(server)
}