-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (58 loc) · 1.66 KB
/
main.go
File metadata and controls
65 lines (58 loc) · 1.66 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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/knight7024/go-push-server/common/config"
"github.com/knight7024/go-push-server/common/mysql"
"github.com/knight7024/go-push-server/common/redis"
_ "github.com/knight7024/go-push-server/docs"
"github.com/knight7024/go-push-server/server"
"github.com/spf13/viper"
"log"
)
func init() {
setViperConfig()
mysql.Connection.InitConnection()
redis.Connection.InitConnection()
config.InitCache()
}
func setViperConfig() {
viper.SetConfigName("application_config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("./config/")
viper.AddConfigPath("./resources/")
if err := viper.ReadInConfig(); err != nil {
switch err := err.(type) {
case viper.ConfigFileNotFoundError:
log.Fatalf("config file not found: %v\n", err)
case viper.ConfigParseError:
log.Fatalf("failed parsing config file: %v\n", err)
default:
log.Fatalf("fatal error config file: %v\n", err)
}
}
if err := viper.Unmarshal(&config.Config); err != nil {
log.Fatalf("fatal error config file: %v\n", err)
}
}
// @title Push Server API
// @version 1.0.0
// @description Push Server developed by Jongwoo Jeong
// @license.name MIT License
// @license.url https://opensource.org/licenses/MIT
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
func main() {
// MySQL 커넥션풀 종료
defer mysql.Connection.Close()
// gin 설정
if config.Config.Core.Env == "prod" {
gin.SetMode(gin.ReleaseMode)
} else {
gin.SetMode(gin.DebugMode)
}
r := server.InitRouter()
_ = r.Run(fmt.Sprintf(":%d", config.Config.Core.Port))
}