-
Notifications
You must be signed in to change notification settings - Fork 434
/
main.go
186 lines (167 loc) · 5.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
import (
"context"
"fmt"
"math/rand"
"path/filepath"
"time"
"github.com/mylxsw/aidea-server/internal/payment/wechatpay"
"github.com/mylxsw/aidea-server/pkg/ai/google"
"github.com/mylxsw/aidea-server/pkg/ai/moonshot"
"github.com/mylxsw/aidea-server/pkg/ai/openrouter"
"github.com/mylxsw/aidea-server/pkg/ai/sky"
"github.com/mylxsw/aidea-server/pkg/ai/zhipuai"
"github.com/mylxsw/aidea-server/pkg/file"
"github.com/mylxsw/aidea-server/pkg/wechat"
"github.com/mylxsw/aidea-server/api"
"github.com/mylxsw/aidea-server/migrate"
"github.com/mylxsw/aidea-server/pkg/ai/anthropic"
"github.com/mylxsw/aidea-server/pkg/ai/baichuan"
"github.com/mylxsw/aidea-server/pkg/ai/baidu"
"github.com/mylxsw/aidea-server/pkg/ai/chat"
"github.com/mylxsw/aidea-server/pkg/ai/dashscope"
"github.com/mylxsw/aidea-server/pkg/ai/deepai"
"github.com/mylxsw/aidea-server/pkg/ai/fromston"
"github.com/mylxsw/aidea-server/pkg/ai/getimgai"
"github.com/mylxsw/aidea-server/pkg/ai/gpt360"
"github.com/mylxsw/aidea-server/pkg/ai/leap"
"github.com/mylxsw/aidea-server/pkg/ai/lepton"
"github.com/mylxsw/aidea-server/pkg/ai/oneapi"
"github.com/mylxsw/aidea-server/pkg/ai/openai"
"github.com/mylxsw/aidea-server/pkg/ai/sensenova"
"github.com/mylxsw/aidea-server/pkg/ai/stabilityai"
"github.com/mylxsw/aidea-server/pkg/ai/tencentai"
"github.com/mylxsw/aidea-server/pkg/ai/xfyun"
"github.com/mylxsw/aidea-server/pkg/aliyun"
"github.com/mylxsw/aidea-server/pkg/dingding"
"github.com/mylxsw/aidea-server/pkg/mail"
"github.com/mylxsw/aidea-server/pkg/proxy"
"github.com/mylxsw/aidea-server/pkg/rate"
"github.com/mylxsw/aidea-server/pkg/redis"
"github.com/mylxsw/aidea-server/pkg/repo"
"github.com/mylxsw/aidea-server/pkg/service"
"github.com/mylxsw/aidea-server/pkg/sms"
"github.com/mylxsw/aidea-server/pkg/tencent"
"github.com/mylxsw/aidea-server/pkg/token"
"github.com/mylxsw/aidea-server/pkg/uploader"
"github.com/mylxsw/aidea-server/pkg/voice"
"github.com/mylxsw/aidea-server/pkg/youdao"
"github.com/mylxsw/aidea-server/internal/jobs"
"github.com/mylxsw/aidea-server/internal/payment/alipay"
"github.com/mylxsw/aidea-server/internal/payment/applepay"
"github.com/mylxsw/aidea-server/internal/queue"
"github.com/mylxsw/aidea-server/internal/queue/consumer"
"github.com/mylxsw/asteria/formatter"
"github.com/mylxsw/asteria/level"
"github.com/mylxsw/asteria/log"
"github.com/mylxsw/asteria/writer"
"github.com/mylxsw/aidea-server/config"
_ "github.com/mylxsw/aidea-server/docs"
"github.com/mylxsw/aidea-server/server"
"github.com/mylxsw/glacier/infra"
"github.com/mylxsw/glacier/starter/app"
)
var GitCommit string
var Version string
// @title AIdea API
// @version 1.0
// @description AIdea API
// @host localhost:8080
// @schemes http
// @contact.email mylxsw@aicode.cc
// @contact.name mylxsw
// @contact.url https://ai.aicode.cc
//
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
func main() {
// 初始化随机数种子
rand.Seed(time.Now().UnixNano())
// 关闭框架的 WARN 日志
infra.WARN = false
ins := app.Create(fmt.Sprintf("%s(%s)", Version, GitCommit), 3).WithYAMLFlag("conf")
// 配置文件
// 命令行选项(使用配置文件的话,只需要指定 `--conf 配置文件地址`,格式为 YAML)
config.Register(ins)
// 日志配置
ins.Init(func(f infra.FlagContext) error {
if !f.Bool("log-colorful") {
log.All().LogFormatter(formatter.NewJSONFormatter())
}
if f.String("log-path") != "" {
log.All().LogWriter(writer.NewDefaultRotatingFileWriter(context.TODO(), func(le level.Level, module string) string {
return filepath.Join(f.String("log-path"), fmt.Sprintf("%s.%s.log", le.GetLevelName(), time.Now().Format("20060102")))
}))
}
startDelay := f.Duration("start-delay")
if startDelay > 0 {
log.Infof("服务延迟 %s 后启动", startDelay)
time.Sleep(startDelay)
}
return nil
})
//ins.Async(func(conf *config.Config) {
// log.With(conf).Debugf("configuration loaded")
//})
ins.OnServerReady(func(conf *config.Config) {
log.Infof("服务启动成功,监听地址为 %s", conf.Listen)
})
// 配置要加载的服务模块
ins.Provider(
api.Provider{},
server.Provider{},
repo.Provider{},
redis.Provider{},
queue.Provider{},
consumer.Provider{},
token.Provider{},
rate.Provider{},
service.Provider{},
jobs.Provider{},
chat.Provider{},
proxy.Provider{},
file.Provider{},
migrate.Provider{},
)
// 普通云服务商
ins.Provider(
uploader.Provider{},
tencent.Provider{},
aliyun.Provider{},
sms.Provider{},
mail.Provider{},
dingding.Provider{},
voice.Provider{},
youdao.Provider{},
alipay.Provider{},
applepay.Provider{},
wechat.Provider{},
wechatpay.Provider{},
)
// AI 服务
ins.Provider(
openai.Provider{},
stabilityai.Provider{},
deepai.Provider{},
fromston.Provider{},
getimgai.Provider{},
dashscope.Provider{},
xfyun.Provider{},
leap.Provider{},
baidu.Provider{},
sensenova.Provider{},
tencentai.Provider{},
anthropic.Provider{},
baichuan.Provider{},
gpt360.Provider{},
oneapi.Provider{},
lepton.Provider{},
google.Provider{},
openrouter.Provider{},
sky.Provider{},
zhipuai.Provider{},
moonshot.Provider{},
)
app.MustRun(ins)
}