-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
587 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* @Author: Vincent Yang | ||
* @Date: 2024-04-23 00:39:03 | ||
* @LastEditors: Vincent Yang | ||
* @LastEditTime: 2024-04-23 00:43:43 | ||
* @FilePath: /DeepLX/config.go | ||
* @Telegram: https://t.me/missuo | ||
* @GitHub: https://github.com/missuo | ||
* | ||
* Copyright © 2024 by Vincent, All Rights Reserved. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
) | ||
|
||
func initConfig() *Config { | ||
cfg := &Config{ | ||
Port: 1188, | ||
} | ||
|
||
// Port flag | ||
flag.IntVar(&cfg.Port, "port", cfg.Port, "set up the port to listen on") | ||
flag.IntVar(&cfg.Port, "p", cfg.Port, "set up the port to listen on") | ||
|
||
// DL Session flag | ||
flag.StringVar(&cfg.DlSession, "s", "", "set the dl-session for /v1/translate endpoint") | ||
if cfg.DlSession == "" { | ||
if dlSession, ok := os.LookupEnv("DL_SESSION"); ok { | ||
cfg.DlSession = dlSession | ||
} | ||
} | ||
|
||
// Access token flag | ||
flag.StringVar(&cfg.Token, "token", "", "set the access token for /translate endpoint") | ||
if cfg.Token == "" { | ||
if token, ok := os.LookupEnv("TOKEN"); ok { | ||
cfg.Token = token | ||
} | ||
} | ||
|
||
// DeepL Official Authentication key flag | ||
flag.StringVar(&cfg.AuthKey, "authkey", "", "The authentication key for DeepL API") | ||
if cfg.AuthKey == "" { | ||
if authKey, ok := os.LookupEnv("AUTHKEY"); ok { | ||
cfg.AuthKey = authKey | ||
} | ||
} | ||
|
||
flag.Parse() | ||
return cfg | ||
} |
Oops, something went wrong.