This repository was archived by the owner on Nov 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ type Client struct {
11
11
larkIns * larkClient
12
12
chatGPTIns * chatGPTClient
13
13
metricsIns IMetrics
14
- serverPort int
14
+ serverPort string
15
15
maintained bool
16
16
enableSessionForLarkGroup bool
17
17
}
@@ -27,7 +27,7 @@ type ClientConfig struct {
27
27
Maintained bool
28
28
29
29
// server
30
- ServerPort int
30
+ ServerPort string
31
31
Metrics IMetrics
32
32
EnableSessionForLarkGroup bool // 给群聊的消息启动 session,session id 是消息的 root id
33
33
}
@@ -45,9 +45,6 @@ func New(config *ClientConfig) *Client {
45
45
res .chatGPTIns = newChatGPTClient (config .ChatGPTAPIURL , config .ChatGPTAPIKey , res .metricsIns )
46
46
47
47
res .serverPort = config .ServerPort
48
- if res .serverPort == 0 {
49
- res .serverPort = 9726
50
- }
51
48
52
49
res .maintained = config .Maintained
53
50
res .enableSessionForLarkGroup = config .EnableSessionForLarkGroup
@@ -62,6 +59,6 @@ func (r *Client) Start() error {
62
59
r .larkIns .cli .EventCallback .ListenCallback (req .Context (), req .Body , w )
63
60
})
64
61
65
- fmt .Printf ("start server: %d ...\n " , r .serverPort )
66
- return http .ListenAndServe (fmt .Sprintf ( ":%d " , r .serverPort ), nil )
62
+ fmt .Printf ("start server: %s ...\n " , r .serverPort )
63
+ return http .ListenAndServe (fmt .Sprint ( "[::]: " , r .serverPort ), nil )
67
64
}
Original file line number Diff line number Diff line change @@ -20,11 +20,17 @@ func main() {
20
20
}
21
21
22
22
func loadConfig () (* larkgpt.ClientConfig , error ) {
23
+ port := os .Getenv ("PORT" )
24
+ if port == "" {
25
+ port = "8080"
26
+ }
27
+
23
28
return & larkgpt.ClientConfig {
24
29
AppID : os .Getenv ("APP_ID" ),
25
30
AppSecret : os .Getenv ("APP_SECRET" ),
26
31
ChatGPTAPIKey : os .Getenv ("CHATGPT_API_KEY" ),
27
32
ChatGPTAPIURL : os .Getenv ("CHATGPT_API_URL" ),
33
+ ServerPort : port ,
28
34
Maintained : os .Getenv ("MAINTAINED" ) == "true" ,
29
35
EnableSessionForLarkGroup : os .Getenv ("ENABLE_SESSION_FOR_LARK_GROUP" ) == "true" ,
30
36
}, nil
You can’t perform that action at this time.
0 commit comments