Skip to content

Commit 82e5b57

Browse files
committed
feat: add command-line flag for customizable port
1 parent 71ab678 commit 82e5b57

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ Head to [Releases](https://github.com/ksamirdev/schedy/releases) and grab the la
2626
### 2. Run
2727

2828
```bash
29-
./schedy
29+
./schedy --port 8081
3030
```
3131

32-
Schedy will listen on `:8080` by default.
32+
Schedy will listen on the port you specify with `--port` (default: `8080`).
3333

3434
---
3535

cmd/schedy/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"flag"
56
"log"
67
"net/http"
78
"os"
@@ -15,6 +16,9 @@ import (
1516
)
1617

1718
func main() {
19+
port := flag.String("port", "8080", "port to listen on")
20+
flag.Parse()
21+
1822
store, err := scheduler.NewBadgerStore("data")
1923
if err != nil {
2024
log.Fatal(err)
@@ -26,15 +30,16 @@ func main() {
2630
mux := http.NewServeMux()
2731
mux.HandleFunc("/tasks", handler.CreateTask)
2832

29-
srv := &http.Server{Addr: ":8080", Handler: mux}
33+
addr := ":" + *port
34+
srv := &http.Server{Addr: addr, Handler: mux}
3035

3136
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
3237
defer stop()
3338

3439
go r.Start(ctx)
3540

3641
go func() {
37-
log.Println("Listening on :8080")
42+
log.Printf("Listening on %s", addr)
3843
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
3944
log.Fatal(err)
4045
}

0 commit comments

Comments
 (0)