73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/rest"
|
|
"net/url"
|
|
"nova_task/internal/pkg/earn"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
rest.RestConf
|
|
MySql MySqlConf
|
|
GameDB MySqlConf
|
|
Redis redis.RedisConf
|
|
Cache cache.CacheConf
|
|
Auth struct {
|
|
AccessSecret string
|
|
AccessExpire time.Duration `json:",default=168h"`
|
|
}
|
|
Earn earn.Config
|
|
EarnCorn struct {
|
|
Spec string
|
|
RunOnStart bool `json:",optional"`
|
|
} `json:",optional"`
|
|
NftTaskCron struct {
|
|
HolderSpec string
|
|
SettleSpec string
|
|
HolderCheckRunOnStart bool `json:",optional"`
|
|
} `json:",optional"`
|
|
AptosConf struct {
|
|
PrivateKey string
|
|
IsTest bool `json:",default=false"`
|
|
} `json:",optional"`
|
|
NovaToken string `json:",default=JInj73uK5gK5BG7I53h5PaEJH41tWwBT"`
|
|
}
|
|
|
|
type Cron struct {
|
|
Spec string
|
|
RunOnStart bool `json:",optional"`
|
|
}
|
|
|
|
type DailyPay struct {
|
|
Contract string
|
|
Network string `json:",default=mainnet"`
|
|
}
|
|
|
|
// MySqlConf mysql配置
|
|
type MySqlConf struct {
|
|
Addr string
|
|
User string
|
|
Password string
|
|
Database string
|
|
Loc string `json:",default=Local"`
|
|
Log string `json:",default=disableStmt,options=allow|disable|disableStmt"`
|
|
}
|
|
|
|
func (m MySqlConf) Dsn() string {
|
|
return fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=True&loc=%s", m.User, m.Password, m.Addr, m.Database, url.QueryEscape(m.Loc))
|
|
}
|
|
|
|
func (m MySqlConf) Conn(opts ...sqlx.SqlOption) sqlx.SqlConn {
|
|
if m.Log == "disable" {
|
|
sqlx.DisableLog()
|
|
} else if m.Log == "disableStmt" {
|
|
sqlx.DisableStmtLog()
|
|
}
|
|
return sqlx.NewMysql(m.Dsn(), opts...)
|
|
}
|