mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-16 15:50:52 -07:00
parent
ad0cf55955
commit
3b0edef864
12
README.md
12
README.md
@ -27,8 +27,12 @@ See the example in [server.yaml](example/server.yaml) file.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
api_key:
|
api_key:
|
||||||
chatgpt: CHATGPT_API_KEY # <- Replace with your API Key
|
chatgpt:
|
||||||
deepl: DEEPL_API_KEY # <- Replace with your API Key
|
value: CHATGPT_API_KEY # <- Replace with your API Key
|
||||||
|
# file: $HOME/secrets/chatgpt.txt # <- You can also specify the file where to read api key
|
||||||
|
deepl:
|
||||||
|
value: DEEPL_API_KEY # <- Replace with your API Key
|
||||||
|
# file: $HOME/secrets/deepl.txt # <- You can also specify the file where to read api key
|
||||||
```
|
```
|
||||||
|
|
||||||
## DeepLX
|
## DeepLX
|
||||||
@ -41,7 +45,9 @@ See the example in [server.yaml](example/server.yaml) file.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
api_key:
|
api_key:
|
||||||
deeplx: DEEPLX_API_KEY # <- Replace with your API Key
|
deeplx:
|
||||||
|
value: DEEPLX_API_KEY # <- Replace with your API Key
|
||||||
|
# file: $HOME/secrets/deeplx.txt # <- You can also specify the file where to read api key
|
||||||
host:
|
host:
|
||||||
deeplx: 127.0.0.1:1188 # <- Replace with your server IP address and port
|
deeplx: 127.0.0.1:1188 # <- Replace with your server IP address and port
|
||||||
```
|
```
|
||||||
|
11
config.go
11
config.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/eeeXun/gtt/internal/style"
|
"github.com/eeeXun/gtt/internal/style"
|
||||||
"github.com/eeeXun/gtt/internal/translate"
|
"github.com/eeeXun/gtt/internal/translate"
|
||||||
@ -160,8 +161,14 @@ func configInit() {
|
|||||||
if err := serverConfig.ReadInConfig(); err == nil {
|
if err := serverConfig.ReadInConfig(); err == nil {
|
||||||
// api key
|
// api key
|
||||||
for _, name := range []string{"ChatGPT", "DeepL", "DeepLX"} {
|
for _, name := range []string{"ChatGPT", "DeepL", "DeepLX"} {
|
||||||
if serverConfig.Get(fmt.Sprintf("api_key.%s", name)) != nil {
|
// Read from value first, then read from file
|
||||||
translators[name].SetAPIKey(serverConfig.GetString(fmt.Sprintf("api_key.%s", name)))
|
if serverConfig.Get(fmt.Sprintf("api_key.%s.value", name)) != nil {
|
||||||
|
translators[name].SetAPIKey(serverConfig.GetString(fmt.Sprintf("api_key.%s.value", name)))
|
||||||
|
} else if serverConfig.Get(fmt.Sprintf("api_key.%s.file", name)) != nil {
|
||||||
|
buff, err := os.ReadFile(os.ExpandEnv(serverConfig.GetString(fmt.Sprintf("api_key.%s.file", name))))
|
||||||
|
if err == nil {
|
||||||
|
translators[name].SetAPIKey(strings.TrimSpace(string(buff)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// host
|
// host
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
# This file should be located at $XDG_CONFIG_HOME/gtt/server.yaml or $HOME/.config/gtt/server.yaml.
|
# This file should be located at $XDG_CONFIG_HOME/gtt/server.yaml or $HOME/.config/gtt/server.yaml.
|
||||||
api_key:
|
api_key:
|
||||||
chatgpt: CHATGPT_API_KEY
|
chatgpt:
|
||||||
deepl: DEEPL_API_KEY
|
value: CHATGPT_API_KEY
|
||||||
deeplx: DEEPLX_API_KEY
|
# file: $HOME/secrets/chatgpt.txt
|
||||||
|
deepl:
|
||||||
|
value: DEEPL_API_KEY
|
||||||
|
# file: $HOME/secrets/deepl.txt
|
||||||
|
deeplx:
|
||||||
|
value: DEEPLX_API_KEY
|
||||||
|
# file: $HOME/secrets/deeplx.txt
|
||||||
host:
|
host:
|
||||||
deeplx: 127.0.0.1:1188
|
deeplx: 127.0.0.1:1188
|
||||||
|
Loading…
x
Reference in New Issue
Block a user