Add flag to specify listening host:port
This commit is contained in:
@@ -22,7 +22,13 @@ If you installed fizzbuzz-lbc using `go get` or with `go install`, you can run i
|
|||||||
|
|
||||||
$ $GOPATH/bin/fizzbuzz-lbc
|
$ $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:
|
Then, you can query the server via http, providing the required parameters:
|
||||||
|
|
||||||
|
|||||||
9
main.go
9
main.go
@@ -1,15 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"dev.fxaguessy.fr/fx/fizzbuzz-lbc/fizzbuzz"
|
"dev.fxaguessy.fr/fx/fizzbuzz-lbc/fizzbuzz"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var hostPort = flag.String("hostport", ":8080", "server listening on host:port")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
hostPort := ":8080"
|
flag.Parse()
|
||||||
server := &fizzbuzz.Server{}
|
server := &fizzbuzz.Server{}
|
||||||
log.Printf("Starting fizzbuzz server on %s", hostPort)
|
log.Printf("Starting fizzbuzz server on %s", *hostPort)
|
||||||
log.Fatal(http.ListenAndServe(hostPort, server.Routes()))
|
log.Fatal(http.ListenAndServe(*hostPort, server.Routes()))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user