Skip to content

Commit c27d016

Browse files
committed
proxy port can be set via command args
1 parent d278449 commit c27d016

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@ import (
88
"net/http"
99
"net/url"
1010
"os"
11+
"strconv"
1112
"strings"
1213
"time"
1314
)
1415

1516
var (
1617
target string // 目标域名
18+
port int // 代理端口
1719
httpProxy = "http://127.0.0.1:10809" // 本地代理地址和端口
1820
)
1921

2022
func main() {
2123
// 从命令行参数获取配置文件路径
2224
flag.StringVar(&target, "domain", "https://api.openai.com", "The target domain to proxy.")
25+
flag.IntVar(&port, "port", 9000, "The proxy port.")
2326
flag.Parse()
2427

25-
// 检查命令行参数是否提供了配置文件路径
26-
if target == "" {
27-
log.Fatalf("Please provide the target domain to proxy by '-domain' option")
28-
}
28+
// 打印配置信息
2929
log.Println("Target domain: ", target)
30+
log.Println("Proxy port: ", port)
31+
3032
http.HandleFunc("/", handleRequest)
31-
http.ListenAndServe(":9001", nil)
33+
http.ListenAndServe(":"+strconv.Itoa(port), nil)
3234
}
3335

3436
func handleRequest(w http.ResponseWriter, r *http.Request) {

scf_bootstrap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
./main
44

5-
# support other domain than https://api.openai.com(default)
6-
# ./main -domain=https://api.other.com
5+
# support other domain and proxy port (default domain: https://api.openai.com, default port: 9000)
6+
# ./main -domain=https://api.other1.com -port=9001

0 commit comments

Comments
 (0)