-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
45 lines (39 loc) · 885 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
package main
import (
"fmt"
"github.com/ragoncsa/todo/config"
"github.com/ragoncsa/todo/gorm"
"github.com/ragoncsa/todo/http"
"github.com/spf13/viper"
)
func loadConfig() *config.Config {
viper.SetConfigName("local-env")
viper.SetConfigType("yaml")
viper.AddConfigPath("./config/")
viper.AutomaticEnv()
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %w", err))
}
var conf config.Config
err = viper.Unmarshal(&conf)
if err != nil {
panic(fmt.Errorf("unable to decode into struct: %w", err))
}
return &conf
}
func main() {
conf := loadConfig()
db, err := gorm.Connect(conf)
if err != nil {
panic("failed to connect database")
}
gorm.RunMigration(db)
server := http.InitServer()
tsDB := &gorm.TaskService{DB: db}
tsHTTP := http.TaskService{
Service: tsDB,
}
server.RegisterRoutes(&tsHTTP)
server.Start()
}