-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (55 loc) · 1.35 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/gin-gonic/gin"
"github.com/ophum/humbase/pkg/auth"
"github.com/ophum/humbase/pkg/method"
"github.com/ophum/humbase/pkg/store"
"gopkg.in/yaml.v2"
"github.com/gin-contrib/cors"
)
type Config struct {
ListenAddress string `yaml:"listenAddress"`
ListenPort int `yaml:"listenPort"`
AuthConfig auth.Config `yaml:"auth"`
StoreConfig store.Config `yaml:"store"`
MethodConfig method.Config `yaml:"method"`
}
var (
configFilePath string
config Config
)
func init() {
flag.StringVar(&configFilePath, "config", "config.yaml", "config file path")
flag.Parse()
f, err := os.Open(configFilePath)
if err != nil {
log.Fatal(err.Error())
return
}
defer f.Close()
if err := yaml.NewDecoder(f).Decode(&config); err != nil {
f.Close()
log.Fatal(err.Error())
}
}
func main() {
r := gin.Default()
corsConfig := cors.DefaultConfig()
corsConfig.AllowOrigins = []string{"*"}
corsConfig.AllowHeaders = append(corsConfig.AllowHeaders, "*")
r.Use(cors.New(corsConfig))
v0 := r.Group("api/v0")
{
a := auth.NewAuth(&config.AuthConfig)
s := store.NewStore(&config.StoreConfig)
m := method.NewMethod(&config.MethodConfig)
a.RegisterRoutes(v0)
s.RegisterRoutes(v0)
m.RegisterRoutes(v0)
}
r.Run(fmt.Sprintf("%s:%d", config.ListenAddress, config.ListenPort))
}