mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2025-06-09 02:13:24 +00:00
switch to cli
This commit is contained in:
parent
9145b9ce1d
commit
4a0920579e
@ -85,9 +85,11 @@ systemctl enable deeplx
|
|||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
You can change the default configuration by setting environment variables, such as setting the port:
|
You can change the default configuration in command line, such as setting the port:
|
||||||
```bash
|
```bash
|
||||||
env DEEPLX_PORT=27001 deeplx_linux_amd64
|
deeplx_linux_amd64 --port 27001
|
||||||
|
#or shorthand
|
||||||
|
deeplx_linux_amd64 -p 27001
|
||||||
```
|
```
|
||||||
|
|
||||||
## Setup on [Bob App](https://bobtranslate.com/)
|
## Setup on [Bob App](https://bobtranslate.com/)
|
||||||
|
49
main.go
49
main.go
@ -3,13 +3,12 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -18,7 +17,17 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var port int
|
||||||
|
|
||||||
func init() {
|
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)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,35 +101,6 @@ func getTimeStamp(iCount int64) int64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
DEEPLXPORT = "DEEPLX_PORT"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
Port uint16
|
|
||||||
}
|
|
||||||
|
|
||||||
var DefaultConfig = Config{
|
|
||||||
Port: 1188,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config *Config) readConfig() {
|
|
||||||
portStr := os.Getenv(DEEPLXPORT)
|
|
||||||
|
|
||||||
if portStr == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
port, err := strconv.ParseUint(portStr, 10, 32)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Unable to resolve %v, please give the correct port", DEEPLXPORT)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
config.Port = uint16(port)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResData struct {
|
type ResData struct {
|
||||||
TransText string `json:"text"`
|
TransText string `json:"text"`
|
||||||
SourceLang string `json:"source_lang"`
|
SourceLang string `json:"source_lang"`
|
||||||
@ -128,11 +108,8 @@ type ResData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// read user config
|
// parse flags
|
||||||
config := DefaultConfig
|
flag.Parse()
|
||||||
config.readConfig()
|
|
||||||
|
|
||||||
port := config.Port
|
|
||||||
|
|
||||||
// display information
|
// display information
|
||||||
fmt.Printf("DeepL X has been successfully launched! Listening on 0.0.0.0:%v\n", port)
|
fmt.Printf("DeepL X has been successfully launched! Listening on 0.0.0.0:%v\n", port)
|
||||||
|
Loading…
Reference in New Issue
Block a user