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
* @Date: 2022-10-18 07:32:29
* @LastEditors: Vincent Young
* @LastEditTime: 2023-03-21 16:55:40
* @LastEditTime: 2023-04-23 13:25:08
* @FilePath: /DeepLX/README.md
* @Telegram: https://t.me/missuo
*
@ -12,10 +12,9 @@
Permanently free DeepL API written in Golang
## 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.
- `deeplx` is using `DeepL` Free API.
- `deeplx` is unlimited to the number of requests.
- `DeepLX` is listening to `0.0.0.0:1188` by default. You can modify the listening port by yourself.
- `DeepLX` is using `DeepL` Free API.
- `DeepLX` is unlimited to the number of requests.
## Usage
### Request Parameters
@ -36,6 +35,13 @@ Permanently free DeepL API written in Golang
"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
```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

19
main.go
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))
}