feat: support for specified ports

This commit is contained in:
Vincent Young 2023-04-23 13:25:47 +08:00
parent f9f378e7eb
commit c4e7565703
No known key found for this signature in database
GPG Key ID: 84A0830C90354A56
3 changed files with 29 additions and 8 deletions

View File

@ -2,7 +2,7 @@
* @Author: Vincent Young * @Author: Vincent Young
* @Date: 2022-10-18 07:32:29 * @Date: 2022-10-18 07:32:29
* @LastEditors: Vincent Young * @LastEditors: Vincent Young
* @LastEditTime: 2023-03-21 16:55:40 * @LastEditTime: 2023-04-23 13:25:08
* @FilePath: /DeepLX/README.md * @FilePath: /DeepLX/README.md
* @Telegram: https://t.me/missuo * @Telegram: https://t.me/missuo
* *
@ -12,10 +12,9 @@
Permanently free DeepL API written in Golang Permanently free DeepL API written in Golang
## Description ## Description
- `deeplx` in only run in port `1188`, later versions will do the specified port. - `DeepLX` is listening to `0.0.0.0:1188` by default. You can modify the listening port by yourself.
- `deeplx` is listening to `0.0.0.0:1188` by default. - `DeepLX` is using `DeepL` Free API.
- `deeplx` is using `DeepL` Free API. - `DeepLX` is unlimited to the number of requests.
- `deeplx` is unlimited to the number of requests.
## Usage ## Usage
### Request Parameters ### Request Parameters
@ -36,6 +35,13 @@ Permanently free DeepL API written in Golang
"id": 8300079001 "id": 8300079001
} }
``` ```
### Specify the port
**Thanks to [cijiugechu](https://github.com/cijiugechu) for [his contribution](https://github.com/OwO-Network/DeepLX/commit/4a0920579ea868b0f05ccdff6bceae316bfd5dc8) to make this feature possible for this project!**
```bash
./deeplx -p 3333
# or
./deeplx -port 3333
```
### Run with Docker ### Run with Docker
```bash ```bash

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/OwO-Network/deepl-api module github.com/OwO-Network/DeepLX
go 1.19 go 1.19

19
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -17,7 +18,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)
} }
@ -98,8 +109,11 @@ type ResData struct {
} }
func main() { func main() {
// parse flags
flag.Parse()
// display information // 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.") fmt.Println("Made by sjlleo and missuo.")
// create a random id // 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))
} }