feat: support for specified ports

This commit is contained in:
Vincent Young
2023-04-23 13:25:47 +08:00
parent f9f378e7eb
commit c4e7565703
3 changed files with 29 additions and 8 deletions
+17 -2
View File
@@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io"
"log"
@@ -17,7 +18,17 @@ import (
"github.com/tidwall/gjson"
)
var port int
func init() {
const (
defaultPort = 1188
usage = "set up the port to listen on"
)
flag.IntVar(&port, "port", defaultPort, usage)
flag.IntVar(&port, "p", defaultPort, usage)
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
@@ -98,8 +109,11 @@ type ResData struct {
}
func main() {
// parse flags
flag.Parse()
// display information
fmt.Println("DeepL X has been successfully launched! Listening on 0.0.0.0:1188")
fmt.Printf("DeepL X has been successfully launched! Listening on 0.0.0.0:%v\n", port)
fmt.Println("Made by sjlleo and missuo.")
// create a random id
@@ -225,5 +239,6 @@ func main() {
}
}
})
r.Run(":1188") // listen and serve on 0.0.0.0:1188
// by default, listen and serve on 0.0.0.0:1188
r.Run(fmt.Sprintf(":%v", port))
}