Skip to content

Commit

Permalink
make port configurable
Browse files Browse the repository at this point in the history
make port configurable
  • Loading branch information
notnmeyer committed Oct 20, 2023
1 parent 36a1e66 commit 4a6c11b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/notnmeyer/mockpi

go 1.20

require github.com/spf13/pflag v1.0.5
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ import (
"net/http"
"os"
"strconv"

flag "github.com/spf13/pflag"
)

type config struct {
port int
}

var c config

func init() {
flag.IntVarP(&c.port, "port", "p", 8080, "the listen port")
flag.Parse()
}

func main() {
http.HandleFunc("/", handler)

listenAddr := ":8080"
listenAddr := fmt.Sprintf(":%d", c.port)
fmt.Printf("Listening on %s...\n", listenAddr)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
fmt.Println("server error: ", err)
Expand Down

0 comments on commit 4a6c11b

Please sign in to comment.