add some utils
This commit is contained in:
@@ -10,13 +10,12 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var c *Config
|
||||
|
||||
type Config struct {
|
||||
App App
|
||||
Http Http
|
||||
Log Log
|
||||
Database Database
|
||||
Storage Storage
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package config
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Database database config
|
||||
type Database struct {
|
||||
Driver string
|
||||
MySQL MySQL
|
||||
Redis Redis
|
||||
PostgreSQL PostgreSQL
|
||||
}
|
||||
|
||||
@@ -17,7 +21,7 @@ type MySQL struct {
|
||||
Password string
|
||||
}
|
||||
|
||||
// DSN is the mysql connection dsn
|
||||
// DSN connection dsn
|
||||
func (m *MySQL) DSN() string {
|
||||
dsnTpl := "%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
|
||||
@@ -41,8 +45,22 @@ type PostgreSQL struct {
|
||||
TimeZone string
|
||||
}
|
||||
|
||||
// DSN is the mysql connection dsn
|
||||
// DSN connection dsn
|
||||
func (m *PostgreSQL) DSN() string {
|
||||
dsnTpl := "host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s"
|
||||
return fmt.Sprintf(dsnTpl, m.Host, m.User, m.Password, m.Database, m.Port, m.SslMode, m.TimeZone)
|
||||
}
|
||||
|
||||
type Redis struct {
|
||||
Host string
|
||||
Port uint
|
||||
Database uint
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
// DSN connection dsn
|
||||
func (m *Redis) DSN() string {
|
||||
dsnTpl := "%s:%d"
|
||||
return fmt.Sprintf(dsnTpl, m.Host, m.Port)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package config
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Http struct {
|
||||
Static string
|
||||
@@ -13,6 +17,30 @@ type Http struct {
|
||||
Mode string
|
||||
Whitelist []Whitelist
|
||||
}
|
||||
JWT JWT
|
||||
}
|
||||
|
||||
type JWT struct {
|
||||
SigningKey string // jwt签名
|
||||
ExpiresTime string // 过期时间
|
||||
BufferTime string // 缓冲时间
|
||||
Issuer string // 签发者
|
||||
}
|
||||
|
||||
func (j JWT) ExpiresTimeDuration() time.Duration {
|
||||
d, err := time.ParseDuration(j.ExpiresTime)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (j JWT) BufferTimeDuration() time.Duration {
|
||||
d, err := time.ParseDuration(j.BufferTime)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
type Whitelist struct {
|
||||
|
||||
29
providers/config/section_storage.go
Normal file
29
providers/config/section_storage.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package config
|
||||
|
||||
type Storage struct {
|
||||
Driver string
|
||||
AliYunOSS AliYunOSS
|
||||
AwsS3 AwsS3
|
||||
}
|
||||
|
||||
type AliYunOSS struct {
|
||||
Bucket string
|
||||
Region string
|
||||
Endpoint string
|
||||
AccessKeyID string
|
||||
AccessKeySecret string
|
||||
BaseURL string
|
||||
Path string
|
||||
}
|
||||
|
||||
type AwsS3 struct {
|
||||
Bucket string
|
||||
Region string
|
||||
Endpoint string
|
||||
DisableSSL bool
|
||||
SecretID string
|
||||
SecretKey string
|
||||
BaseURL string
|
||||
Path string
|
||||
S3ForcePathStyle bool
|
||||
}
|
||||
Reference in New Issue
Block a user