init project

This commit is contained in:
2023-04-24 17:19:41 +08:00
parent 84729ebb66
commit cdb5a4f9cd
51 changed files with 3328 additions and 1 deletions

14
config/aliyun.go Normal file
View File

@@ -0,0 +1,14 @@
package config
// 阿里云配置
type aliyunConfig struct {
Oss aliOssConfig `mapstructure:"oss" yaml:"oss"` // oss配置
}
// OSSConfig 阿里云OSS配置
type aliOssConfig struct {
Endpoint string `mapstructure:"endpoint" yaml:"endpoint"`
Bucket string `mapstructure:"bucket" yaml:"bucket"`
AccessKeyId string `mapstructure:"access-key" yaml:"access-key"`
AccessKeySecret string `mapstructure:"access-key-secret" yaml:"access-key-secret"`
}

9
config/app.go Normal file
View File

@@ -0,0 +1,9 @@
package config
type appInfo struct {
AppName string `mapstructure:"name" yaml:"name"` // 应用名称
Port uint64 `mapstructure:"port" yaml:"port"` // 端口号
Prefix string `mapstructure:"prefix" yaml:"prefix"` // 接口前缀
Version string `mapstructure:"version" yaml:"version"` // 版本号
Monster bool `mapstructure:"monster" yaml:"monster"` // 妖怪模式
}

14
config/config.go Normal file
View File

@@ -0,0 +1,14 @@
package config
var Scd systemConfigData
var Nacos nacosConfig
// 配置信息
type systemConfigData struct {
Admin appInfo `mapstructure:"admin" yaml:"admin"` // 系统配置-Admin
Api appInfo `mapstructure:"api" yaml:"api"` // 系统配置-Api
MySQL mysqlConfig `mapstructure:"mysql" yaml:"mysql"` // MySQL配置
Aliyun aliyunConfig `mapstructure:"aliyun" yaml:"aliyun"` // 阿里云配置
Tencent tencentConfig `mapstructure:"tencent" yaml:"tencent"` // 腾讯相关配置
JWT JWT `mapstructure:"jwt" yaml:"jwt"`
}

8
config/jwt.go Normal file
View File

@@ -0,0 +1,8 @@
package config
// JWT JWT配置
type JWT struct {
AccessSecret string `yaml:"AccessSecret"` // 加密签名
AccessExpire int64 `yaml:"AccessExpire"` // 签名有效时间
RefreshAfter int64 `yaml:"RefreshAfter"` // 签名刷新时间
}

20
config/mysql.go Normal file
View File

@@ -0,0 +1,20 @@
package config
import (
"fmt"
)
// MySQL配置
type mysqlConfig struct {
Host string `mapstructure:"host" yaml:"host"` // 主机
Port int `mapstructure:"port" yaml:"port"` // 端口
User string `mapstructure:"user" yaml:"user"` // 用户名
Password string `mapstructure:"password" yaml:"password"` // 密码
Db string `mapstructure:"db" yaml:"db"` // 数据库名称
}
// GetDSN 返回 MySQL 连接字符串
func (c mysqlConfig) GetDSN() string {
return fmt.Sprintf("%s:%s@tcp(%s:%v)/%s?charset=utf8mb4&parseTime=True&loc=Local",
c.User, c.Password, c.Host, c.Port, c.Db)
}

9
config/nacos.go Normal file
View File

@@ -0,0 +1,9 @@
package config
// Nacos配置
type nacosConfig struct {
Host string `env:"NACOS_HOST"` // 主机
Port uint64 `env:"NACOS_PORT" envDefault:"8848"` // 端口
NamespaceId string `env:"NACOS_NAMESPACE"` // 命名空间
CenterConfigName string `env:"NACOS_CONFIG_NAME" envDefault:"gtest.yml"` // 外部配置文件名,多个以逗号隔开
}

12
config/tencent.go Normal file
View File

@@ -0,0 +1,12 @@
package config
// 腾讯相关配置
type tencentConfig struct {
MiniApp wechatMiniAppConfig `mapstructure:"mini-app" yaml:"mini-app"`
}
// 微信小程序配置
type wechatMiniAppConfig struct {
AppId string `mapstructure:"app-id" yaml:"app-id"`
AppSecret string `mapstructure:"app-secret" yaml:"app-secret"`
}