Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit beee1ae

Browse files
committed
feat: add ipv6 support
1 parent 086d853 commit beee1ae

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

larkgpt/client.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Client struct {
1111
larkIns *larkClient
1212
chatGPTIns *chatGPTClient
1313
metricsIns IMetrics
14-
serverPort int
14+
serverPort string
1515
maintained bool
1616
enableSessionForLarkGroup bool
1717
}
@@ -27,7 +27,7 @@ type ClientConfig struct {
2727
Maintained bool
2828

2929
// server
30-
ServerPort int
30+
ServerPort string
3131
Metrics IMetrics
3232
EnableSessionForLarkGroup bool // 给群聊的消息启动 session,session id 是消息的 root id
3333
}
@@ -45,9 +45,6 @@ func New(config *ClientConfig) *Client {
4545
res.chatGPTIns = newChatGPTClient(config.ChatGPTAPIURL, config.ChatGPTAPIKey, res.metricsIns)
4646

4747
res.serverPort = config.ServerPort
48-
if res.serverPort == 0 {
49-
res.serverPort = 9726
50-
}
5148

5249
res.maintained = config.Maintained
5350
res.enableSessionForLarkGroup = config.EnableSessionForLarkGroup
@@ -62,6 +59,6 @@ func (r *Client) Start() error {
6259
r.larkIns.cli.EventCallback.ListenCallback(req.Context(), req.Body, w)
6360
})
6461

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)
6764
}

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ func main() {
2020
}
2121

2222
func loadConfig() (*larkgpt.ClientConfig, error) {
23+
port := os.Getenv("PORT")
24+
if port == "" {
25+
port = "8080"
26+
}
27+
2328
return &larkgpt.ClientConfig{
2429
AppID: os.Getenv("APP_ID"),
2530
AppSecret: os.Getenv("APP_SECRET"),
2631
ChatGPTAPIKey: os.Getenv("CHATGPT_API_KEY"),
2732
ChatGPTAPIURL: os.Getenv("CHATGPT_API_URL"),
33+
ServerPort: port,
2834
Maintained: os.Getenv("MAINTAINED") == "true",
2935
EnableSessionForLarkGroup: os.Getenv("ENABLE_SESSION_FOR_LARK_GROUP") == "true",
3036
}, nil

0 commit comments

Comments
 (0)