Skip to content

Commit

Permalink
API: Added ping endpoint to check if service is available
Browse files Browse the repository at this point in the history
  • Loading branch information
donutloop committed Dec 5, 2018
1 parent bd1af46 commit d0cc6cf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ COPY --from=builder /go/src/${PACKAGE}/httpcache /httpcache

USER nobody:nobody

EXPOSE 8000
ENTRYPOINT ["./httpcache"]
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ client = &http.Client{

client.Do(req)
...
```
```

## Run container
It's expose port 8000 and run a spefici container by id
```bash
sudo docker run -p 8000:8000 {{container_id}}
```
2 changes: 2 additions & 0 deletions cmd/httpcache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ func main() {

proxy := handler.NewProxy(c, logger.Println, *responseBodyContentLenghtLimit)
stats := handler.NewStats(c, logger.Println)
ping := handler.NewPing(logger.Println)

mux := http.NewServeMux()
mux.Handle("/stats", stats)
mux.Handle("/", proxy)
mux.Handle("/ping", ping)

stack := middleware.NewPanic(mux, logger.Println)

Expand Down
22 changes: 22 additions & 0 deletions internal/handler/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package handler

import (
"net/http"
)

func NewPing(logger func(v ...interface{})) *Ping {
return &Ping{
logger: logger,
}
}

type Ping struct {
logger func(v ...interface{})
}

func (s *Ping) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
s.logger("pinged cache")
resp.WriteHeader(http.StatusOK)
resp.Write([]byte("ok"))
}

0 comments on commit d0cc6cf

Please sign in to comment.