Skip to content

Commit da168dc

Browse files
committed
add custom port
1 parent 7989d12 commit da168dc

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-
var outputDirectory string
22+
var (
23+
outputDirectory string
24+
port int
25+
)
2326

2427
func init() {
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy