Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda168dc

Browse files
committed
add custom port
1 parent7989d12 commitda168dc

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ Example:
8181
curl"http://localhost:8080/compressor?url=https://example.com/image.jpg&output=webp&quality=80&resolution=1024x720"
8282
```
8383

84+
###Custom Port
85+
86+
By default, the server listens on port`8080`. If you wish to use a custom port, you can specify it during the startup of the server using the`-p` flag. For example:
87+
88+
```bash
89+
./image-compressor -o ./tmp -p 8888
90+
```
91+
8492
##License
8593

8694
This project is licensed under the[MIT License](LICENSE).

‎image-compressor‎

96 Bytes
Binary file not shown.

‎main.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ import (
1919
"github.com/nfnt/resize"
2020
)
2121

22-
varoutputDirectorystring
22+
var (
23+
outputDirectorystring
24+
portint
25+
)
2326

2427
funcinit() {
2528
flag.StringVar(&outputDirectory,"o",".","Output directory for compressed images")
29+
flag.IntVar(&port,"p",8080,"Port for the server to listen on")
2630
flag.Parse()
2731
}
2832

@@ -250,6 +254,6 @@ func main() {
250254

251255
http.Handle("/",r)
252256

253-
fmt.Printf("Server is listening on :8080. Output directory: %s\n",outputDirectory)
254-
http.ListenAndServe(":8080",nil)
257+
fmt.Printf("Server is listening on :%d. Output directory: %s\n",port,outputDirectory)
258+
http.ListenAndServe(fmt.Sprintf(":%d",port),nil)
255259
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp