forked from Chipsterjulien/zut
/
app.go
68 lines (55 loc) · 1.28 KB
/
app.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
67
68
package main
import (
"strconv"
"time"
"github.com/gin-gonic/gin"
"github.com/itsjamie/gin-cors"
"github.com/jinzhu/gorm"
"github.com/op/go-logging"
"github.com/spf13/viper"
)
// Struct permit to have DB access on method
type Ressource struct {
db *gorm.DB
}
// Init DB
func NewRessource(db *gorm.DB) Ressource {
return Ressource{
db: db,
}
}
func startApp(db *gorm.DB) {
log := logging.MustGetLogger("log")
if viper.GetString("logtype") != "debug" {
gin.SetMode(gin.ReleaseMode)
}
g := gin.Default()
//r := NewRessource(db)
g.Use(cors.Middleware(cors.Config{
Origins: "*",
Methods: "GET, PUT, POST, DELETE",
RequestHeaders: "Origin, Authorization, Content-Type",
ExposedHeaders: "",
MaxAge: 50 * time.Second,
Credentials: true,
ValidateHeaders: false,
}))
g.Static("/", "./static")
/*v1 := g.Group("api/v1")
{
v1.GET("/temperatures", r.GetTemperatures)
v1.POST("/temperature", r.PostTemperature)
}*/
log.Debug("Port: %d", viper.GetInt("server.port"))
g.Run(":" + strconv.Itoa(viper.GetInt("server.port")))
}
func main() {
confPath := "cfg"
confFilename := "server"
logFilename := "error.log"
fd := initLogging(&logFilename)
defer fd.Close()
loadConfig(&confPath, &confFilename)
dbmap := Initdb()
startApp(dbmap)
}