Browse Source

Add flag to specify listening host:port

master
parent
commit
3a2468dc83
  1. 10
      README.md
  2. 9
      main.go

10
README.md

@ -22,7 +22,13 @@ If you installed fizzbuzz-lbc using `go get` or with `go install`, you can run i
$ $GOPATH/bin/fizzbuzz-lbc
It will launch the fizz-buzz endpoint listenning on `*:8080`.
or you can run it in the source folder by running
$ go run main.go
`fizzbuzz-lbc` will listen by default on `*:8080`, but you can specify the host and port by using the `-hostport flag`, for example:
$ ./fizzbuzz-lbc -hostport 127.0.0.1:8000
Then, you can query the server via http, providing the required parameters:
@ -34,4 +40,4 @@ fizzbuzz-lbc expects 5 parameters:
- `string2`: the second string
- `int1`: the first integer
- `int2`: the second integer
- `limit`: the limit
- `limit`: the limit

9
main.go

@ -1,15 +1,18 @@
package main
import (
"flag"
"log"
"net/http"
"dev.fxaguessy.fr/fx/fizzbuzz-lbc/fizzbuzz"
)
var hostPort = flag.String("hostport", ":8080", "server listening on host:port")
func main() {
hostPort := ":8080"
flag.Parse()
server := &fizzbuzz.Server{}
log.Printf("Starting fizzbuzz server on %s", hostPort)
log.Fatal(http.ListenAndServe(hostPort, server.Routes()))
log.Printf("Starting fizzbuzz server on %s", *hostPort)
log.Fatal(http.ListenAndServe(*hostPort, server.Routes()))
}

Loading…
Cancel
Save