-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
38 lines (32 loc) · 951 Bytes
/
config.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
package api
import (
"fmt"
"time"
)
type Model struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt *time.Time `gorm:"index" json:"-"`
}
// Config is main config
type Config struct {
Title string
Mode string
Addr string
Locale string
Mysql struct {
Host string `mapstructure:"mysql_host"`
Port int `mapstructure:"mysql_port"`
User string `mapstructure:"mysql_user"`
Password string `mapstructure:"mysql_password"`
Database string `mapstructure:"mysql_database"`
} `mapstructure:",squash"`
JWT struct {
Secret string `mapstructure:"jwt_secret"`
TTL int `mapstructure:"jwt_ttl"`
} `mapstructure:",squash"`
}
func (c *Config) GetMysqlDsn() string {
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", c.Mysql.User, c.Mysql.Password, c.Mysql.Host, c.Mysql.Port, c.Mysql.Database)
}