feat(ik3cloud): 初始化项目基础配置与部门模块
- 添加 .gitignore 忽略规则 - 实现应用配置加载与管理逻辑 - 添加默认配置文件 app.ini - 配置 Gitea CI/CD 工作流用于构建和部署 - 实现金蝶云客户端初始化功能 - 添加 RPC 插件支持 Consul 注册中心 - 实现部门数据获取及树形结构处理逻辑 - 添加通用工具函数库 - 初始化 Go 模块依赖管理 - 创建 Dockerfile 用于服务容器化部署
This commit is contained in:
90
app/config/app.go
Normal file
90
app/config/app.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
var Config = &App{}
|
||||
|
||||
type App struct {
|
||||
iniLoader *ini.File
|
||||
initConfig *IniConfig
|
||||
Debug bool `ini:"debug"`
|
||||
Log Log `ini:"log"`
|
||||
Server Server `ini:"server"`
|
||||
Ik3cloud Ik3cloud `ini:"ik3cloud"`
|
||||
Page Page `ini:"page"`
|
||||
}
|
||||
type IniConfig struct {
|
||||
ConfigPath string
|
||||
ConfigName string
|
||||
RunModelName string
|
||||
RunModel string
|
||||
RunModelErrAllow bool // 允许不使用拓展配置文件
|
||||
}
|
||||
|
||||
// InitConfig @TITLE 初始化配置
|
||||
func InitConfig(config *IniConfig) {
|
||||
if config.ConfigName == "" {
|
||||
config.ConfigName = "app.ini"
|
||||
}
|
||||
// 读取配置文件
|
||||
load, err := ini.Load(filepath.Join(config.ConfigPath, config.ConfigName))
|
||||
if err != nil {
|
||||
log.Fatal("配置文件读取错误,err:", err)
|
||||
return
|
||||
}
|
||||
// 环境配置
|
||||
if config.RunModel == "" {
|
||||
config.RunModel = os.Getenv("RunModel")
|
||||
if config.RunModel == "" {
|
||||
config.RunModel = load.Section("").Key("defaultModel").String()
|
||||
if config.RunModel == "" {
|
||||
config.RunModel = "test"
|
||||
}
|
||||
}
|
||||
}
|
||||
if config.RunModelName == "" {
|
||||
config.RunModelName = fmt.Sprintf("app.%s.ini", config.RunModel)
|
||||
}
|
||||
if err := load.Append(filepath.Join(config.ConfigPath, config.RunModelName)); err != nil {
|
||||
if config.RunModelErrAllow {
|
||||
log.Println("环境配置文件读取错误,err:", err)
|
||||
} else {
|
||||
log.Fatal("环境配置文件读取错误,err:", err)
|
||||
}
|
||||
}
|
||||
// 运行配置
|
||||
load.Append(filepath.Join(config.ConfigPath, "app.run.ini"))
|
||||
// 映射配置
|
||||
if err := load.MapTo(Config); err != nil {
|
||||
log.Fatal("配置文件映射错误,err:", err)
|
||||
return
|
||||
}
|
||||
Config.iniLoader = load
|
||||
Config.initConfig = config
|
||||
}
|
||||
|
||||
// SetConfig @Title 写入配置
|
||||
func (a *App) SetConfig(section, name, value string) error {
|
||||
runConfig := filepath.Join(Config.initConfig.ConfigPath, "app.run.ini")
|
||||
load, err := ini.LooseLoad(runConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
load.Section(section).Key(name).SetValue(value)
|
||||
load.SaveTo(runConfig)
|
||||
Config.iniLoader.Reload()
|
||||
Config.iniLoader.MapTo(Config)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRunModel @Title 获取RunModel
|
||||
func (a *App) GetRunModel() string {
|
||||
return a.initConfig.RunModel
|
||||
}
|
||||
11
app/config/ik3cloud.go
Normal file
11
app/config/ik3cloud.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package config
|
||||
|
||||
type Ik3cloud struct {
|
||||
Host string `ini:"host"` // 接口地址
|
||||
AccountId string `ini:"accountId"` // 账套ID
|
||||
Username string `ini:"username"` // 用户名
|
||||
AppId string `ini:"appId"` // 应用ID
|
||||
AppSecret string `ini:"appSecret"` // 应用秘钥
|
||||
LanguageId string `ini:"languageId"` // 语言ID
|
||||
OrganizationNumber string `ini:"organizationNumber"` // 组织编码
|
||||
}
|
||||
12
app/config/log.go
Normal file
12
app/config/log.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package config
|
||||
|
||||
type Log struct {
|
||||
Director string `ini:"director"`
|
||||
Levels []int64 `ini:"levels"`
|
||||
ShowLine bool `ini:"showLine"`
|
||||
LogInConsole bool `ini:"logInConsole"`
|
||||
Prefix string `ini:"prefix"`
|
||||
MaxAge int `ini:"maxAge"`
|
||||
MaxSize int `ini:"maxSize"`
|
||||
MaxBackups int `ini:"maxBackups"`
|
||||
}
|
||||
7
app/config/page.go
Normal file
7
app/config/page.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
type Page struct {
|
||||
MaxLimit int `ini:"maxLimit"`
|
||||
MinLimit int `ini:"minLimit"`
|
||||
DefaultLimit int `ini:"defaultLimit"`
|
||||
}
|
||||
14
app/config/server.go
Normal file
14
app/config/server.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package config
|
||||
|
||||
type Server struct {
|
||||
RegistryServer []string `ini:"registryServer"`
|
||||
Addr string `ini:"addr"`
|
||||
Host string `ini:"host"`
|
||||
Port uint `ini:"port"`
|
||||
BasePath string `ini:"basePath"`
|
||||
FilePath string `ini:"filePath"`
|
||||
WorkerId int64 `ini:"workerId"`
|
||||
Segment string `ini:"segment"`
|
||||
YzmExpiry int `ini:"yzmExpiry"`
|
||||
YzmRate int `ini:"yzmRate"`
|
||||
}
|
||||
Reference in New Issue
Block a user