-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
35 lines (30 loc) · 917 Bytes
/
main.go
File metadata and controls
35 lines (30 loc) · 917 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
"github.com/rubleowen/GetMerlin2Api/api"
"github.com/rubleowen/GetMerlin2Api/auth"
"github.com/rubleowen/GetMerlin2Api/utils"
)
func main() {
utils.LoadEnv()
// 生成一个token用于测试
token, err := auth.GenerateToken()
if err != nil {
log.Fatalf("Failed to generate token: %v", err)
}
// 打印token的前100个字符,避免日志过长
fmt.Printf("Token prefix: %s...\n", token[:100])
// 注册路由
http.HandleFunc("/", api.HandleChat)
http.HandleFunc("/v1/chat/completions", api.HandleChat)
http.HandleFunc("/v1/images/generations", api.HandleImageGenerations)
http.HandleFunc("/web/v2/image-generation", api.HandleImageGeneration)
// 启动服务器
port := "8081"
fmt.Printf("Server starting on port %s...\n", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}