Skip to content

Commit

Permalink
ping handler
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaroland committed Sep 16, 2017
1 parent a947f04 commit 05fec1e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cmd/wof-libpostal-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ func main() {
logger.Fatal("failed to create expand handler, because %v", err)
}

ping_hander, err := http.PingHandler()

if err != nil {
logger.Fatal("failed to create ping handler, because %v", err)
}

endpoint := fmt.Sprintf("%s:%d", *host, *port)

mux := http.NewServeMux()

mux.HandleFunc("/parse", parser_handler)
mux.HandleFunc("/expand", expand_handler)
mux.HandleFunc("/ping", ping_handler)

err := gracehttp.Serve(&http.Server{Addr: endpoint, Handler: mux})

Expand Down
3 changes: 1 addition & 2 deletions http/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func ExpandHandler() (gohttp.Handler, error) {
}

expansions := expand.ExpandAddress(address)

WriteResponse(rsp, expansions, expandSuccess)
WriteResponse(rsp, expansions)
}

h := gohttp.HandlerFunc(fn)
Expand Down
16 changes: 16 additions & 0 deletions http/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package http

import (
gohttp "net/http"
)

func PingHandler() (gohttp.Handler, error) {

fn := func(rsp gohttp.ResponseWriter, req *gohttp.Request) {
rsp.Header().Set("Content-Type", "text/plain")
rsp.Write([]byte("PONG"))
}

h := gohttp.HandlerFunc(fn)
return h, nil
}

0 comments on commit 05fec1e

Please sign in to comment.