291 lines
5.5 KiB
Go
291 lines
5.5 KiB
Go
package conf
|
|
|
|
import (
|
|
"github.com/google/wire"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// ProviderSet is conf providers.
|
|
var ProviderSet = wire.NewSet(
|
|
ProvideServer,
|
|
ProvideJWT,
|
|
ProvideMysql,
|
|
ProvidePgsql,
|
|
ProvideSqlite,
|
|
ProvideMssql,
|
|
ProvideOracle,
|
|
ProvideRedis,
|
|
ProvideMongo,
|
|
ProvideCaptcha,
|
|
ProvideSystem,
|
|
ProvideUseStrictAuth,
|
|
ProvideZapLogger,
|
|
ProvideAutocode,
|
|
ProvideAutoCodeConfig,
|
|
ProvideAutoCodeLLMConfig,
|
|
ProvideAutoCodeMCPConfig,
|
|
ProvideMCP,
|
|
ProvideLocal,
|
|
ProvideQiniu,
|
|
ProvideMinio,
|
|
ProvideAliyunOss,
|
|
ProvideTencentCos,
|
|
ProvideAwsS3,
|
|
ProvideCloudflareR2,
|
|
ProvideHuaweiObs,
|
|
ProvideEmail,
|
|
ProvideExcel,
|
|
ProvideCors,
|
|
ProvideZap,
|
|
)
|
|
|
|
// ProvideZapLogger 提供zap日志实例
|
|
func ProvideZapLogger() *zap.Logger {
|
|
logger, _ := zap.NewProduction()
|
|
return logger
|
|
}
|
|
|
|
// ProvideServer 提供Server配置
|
|
func ProvideServer(c *Bootstrap) *Server {
|
|
return c.Server
|
|
}
|
|
|
|
// ProvideJWT 提供JWT配置
|
|
func ProvideJWT(c *Bootstrap) *JWT {
|
|
return c.Jwt
|
|
}
|
|
|
|
// ProvideMysql 提供Mysql配置
|
|
func ProvideMysql(c *Bootstrap) *Mysql {
|
|
return c.Mysql
|
|
}
|
|
|
|
// ProvidePgsql 提供Pgsql配置
|
|
func ProvidePgsql(c *Bootstrap) *Pgsql {
|
|
return c.Pgsql
|
|
}
|
|
|
|
// ProvideSqlite 提供Sqlite配置
|
|
func ProvideSqlite(c *Bootstrap) *Sqlite {
|
|
return c.Sqlite
|
|
}
|
|
|
|
// ProvideMssql 提供Mssql配置
|
|
func ProvideMssql(c *Bootstrap) *Mssql {
|
|
return c.Mssql
|
|
}
|
|
|
|
// ProvideOracle 提供Oracle配置
|
|
func ProvideOracle(c *Bootstrap) *Oracle {
|
|
return c.Oracle
|
|
}
|
|
|
|
// ProvideRedis 提供Redis配置
|
|
func ProvideRedis(c *Bootstrap) *Redis {
|
|
return c.Redis
|
|
}
|
|
|
|
// ProvideMongo 提供Mongo配置
|
|
func ProvideMongo(c *Bootstrap) *Mongo {
|
|
return c.Mongo
|
|
}
|
|
|
|
// ProvideCaptcha 提供Captcha配置
|
|
func ProvideCaptcha(c *Bootstrap) *Captcha {
|
|
return c.Captcha
|
|
}
|
|
|
|
// ProvideSystem 提供System配置
|
|
func ProvideSystem(c *Bootstrap) *System {
|
|
return c.System
|
|
}
|
|
|
|
// UseStrictAuth 用于wire注入的类型包装
|
|
type UseStrictAuth bool
|
|
|
|
// ProvideUseStrictAuth 提供UseStrictAuth配置
|
|
func ProvideUseStrictAuth(c *System) UseStrictAuth {
|
|
if c == nil {
|
|
return false
|
|
}
|
|
return UseStrictAuth(c.UseStrictAuth)
|
|
}
|
|
|
|
// ProvideAutocode 提供Autocode配置
|
|
func ProvideAutocode(c *Bootstrap) *Autocode {
|
|
if c.Autocode == nil {
|
|
return &Autocode{
|
|
Web: "web/src",
|
|
Root: "./",
|
|
Server: "server",
|
|
Module: "kra",
|
|
AiPath: "",
|
|
}
|
|
}
|
|
return c.Autocode
|
|
}
|
|
|
|
// AutoCodeConfig 自动代码配置
|
|
type AutoCodeConfig struct {
|
|
Root string
|
|
Server string
|
|
Web string
|
|
Module string
|
|
}
|
|
|
|
// AutoCodeLLMConfig LLM配置
|
|
type AutoCodeLLMConfig struct {
|
|
AiPath string
|
|
}
|
|
|
|
// AutoCodeMCPConfig MCP配置
|
|
type AutoCodeMCPConfig struct {
|
|
Root string
|
|
Server string
|
|
}
|
|
|
|
// ProvideAutoCodeConfig 提供AutoCode配置
|
|
func ProvideAutoCodeConfig(autocode *Autocode) *AutoCodeConfig {
|
|
if autocode == nil {
|
|
return &AutoCodeConfig{
|
|
Root: "./",
|
|
Server: "server",
|
|
Web: "web",
|
|
Module: "kra",
|
|
}
|
|
}
|
|
return &AutoCodeConfig{
|
|
Root: autocode.Root,
|
|
Server: autocode.Server,
|
|
Web: autocode.Web,
|
|
Module: autocode.Module,
|
|
}
|
|
}
|
|
|
|
// ProvideAutoCodeLLMConfig 提供AutoCodeLLM配置
|
|
func ProvideAutoCodeLLMConfig(autocode *Autocode) *AutoCodeLLMConfig {
|
|
if autocode == nil {
|
|
return &AutoCodeLLMConfig{
|
|
AiPath: "",
|
|
}
|
|
}
|
|
return &AutoCodeLLMConfig{
|
|
AiPath: autocode.AiPath,
|
|
}
|
|
}
|
|
|
|
// ProvideAutoCodeMCPConfig 提供AutoCodeMCP配置
|
|
func ProvideAutoCodeMCPConfig(autocode *Autocode) *AutoCodeMCPConfig {
|
|
if autocode == nil {
|
|
return &AutoCodeMCPConfig{
|
|
Root: "./",
|
|
Server: "server",
|
|
}
|
|
}
|
|
return &AutoCodeMCPConfig{
|
|
Root: autocode.Root,
|
|
Server: autocode.Server,
|
|
}
|
|
}
|
|
|
|
// ProvideMCP 提供MCP配置
|
|
func ProvideMCP(c *Bootstrap) *MCP {
|
|
if c.Mcp == nil {
|
|
return &MCP{
|
|
Name: "kra-mcp",
|
|
Version: "v1.0.0",
|
|
SsePath: "/mcp/sse",
|
|
MessagePath: "/mcp/message",
|
|
UrlPrefix: "",
|
|
Addr: 8889,
|
|
Separate: false,
|
|
Enabled: false,
|
|
}
|
|
}
|
|
return c.Mcp
|
|
}
|
|
|
|
// ProvideLocal 提供Local配置
|
|
func ProvideLocal(c *Bootstrap) *Local {
|
|
if c.Local == nil {
|
|
return &Local{
|
|
Path: "uploads/file",
|
|
StorePath: "uploads/file",
|
|
}
|
|
}
|
|
return c.Local
|
|
}
|
|
|
|
// ProvideQiniu 提供Qiniu配置
|
|
func ProvideQiniu(c *Bootstrap) *Qiniu {
|
|
return c.Qiniu
|
|
}
|
|
|
|
// ProvideMinio 提供Minio配置
|
|
func ProvideMinio(c *Bootstrap) *Minio {
|
|
return c.Minio
|
|
}
|
|
|
|
// ProvideAliyunOss 提供AliyunOss配置
|
|
func ProvideAliyunOss(c *Bootstrap) *AliyunOss {
|
|
return c.AliyunOss
|
|
}
|
|
|
|
// ProvideTencentCos 提供TencentCos配置
|
|
func ProvideTencentCos(c *Bootstrap) *TencentCos {
|
|
return c.TencentCos
|
|
}
|
|
|
|
// ProvideAwsS3 提供AwsS3配置
|
|
func ProvideAwsS3(c *Bootstrap) *AwsS3 {
|
|
return c.AwsS3
|
|
}
|
|
|
|
// ProvideCloudflareR2 提供CloudflareR2配置
|
|
func ProvideCloudflareR2(c *Bootstrap) *CloudflareR2 {
|
|
return c.CloudflareR2
|
|
}
|
|
|
|
// ProvideHuaweiObs 提供HuaweiObs配置
|
|
func ProvideHuaweiObs(c *Bootstrap) *HuaweiObs {
|
|
return c.HuaweiObs
|
|
}
|
|
|
|
// ProvideEmail 提供Email配置
|
|
func ProvideEmail(c *Bootstrap) *Email {
|
|
return c.Email
|
|
}
|
|
|
|
// ProvideExcel 提供Excel配置
|
|
func ProvideExcel(c *Bootstrap) *Excel {
|
|
if c.Excel == nil {
|
|
return &Excel{
|
|
Dir: "./resource/excel/",
|
|
}
|
|
}
|
|
return c.Excel
|
|
}
|
|
|
|
// ProvideCors 提供Cors配置
|
|
func ProvideCors(c *Bootstrap) *Cors {
|
|
return c.Cors
|
|
}
|
|
|
|
// ProvideZap 提供Zap配置
|
|
func ProvideZap(c *Bootstrap) *Zap {
|
|
if c.Zap == nil {
|
|
return &Zap{
|
|
Level: "info",
|
|
Format: "console",
|
|
Prefix: "[kratos-admin]",
|
|
Director: "log",
|
|
ShowLine: true,
|
|
EncodeLevel: "LowercaseColorLevelEncoder",
|
|
StacktraceKey: "stacktrace",
|
|
LogInConsole: true,
|
|
RetentionDay: -1,
|
|
}
|
|
}
|
|
return c.Zap
|
|
}
|