-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (42 loc) · 830 Bytes
/
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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"log"
"os"
"sns-api/api"
"sns-api/config"
"sns-api/logger"
)
var AppEnvironment string
func init() {
AppEnvironment = os.Getenv("APP_ENVIRONMENT")
}
func main() {
if err := run(); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v", err)
os.Exit(-1)
}
}
func setup() (*gin.Engine, *config.Config) {
c, err := config.NewConfig(AppEnvironment)
if err != nil {
log.Fatalf("cannot load config: %v", err)
}
l, err := logger.NewLogger(c)
if err != nil {
log.Fatalf("cannot create logger instance: %v", err)
}
if c.Env == "prod" {
gin.SetMode(gin.ReleaseMode)
}
r := gin.New()
r.Use(gin.Recovery())
server := api.NewServer(r, c, l)
server.NewRouter()
return r, c
}
func run() error {
r, c := setup()
return r.Run(fmt.Sprintf(":%s", c.Port))
}