Skip to content

Instantly share code, notes, and snippets.

@fgbreel
Last active April 4, 2017 20:12
Show Gist options
  • Save fgbreel/28e736722e7439d9c55d519a11953867 to your computer and use it in GitHub Desktop.
Save fgbreel/28e736722e7439d9c55d519a11953867 to your computer and use it in GitHub Desktop.
A self registered micro service example from gomicro
FROM golang:onbuild
FROM scratch
ADD main /
CMD ["/main"]
package main
import (
"fmt"
"log"
"net/http"
"github.com/micro/go-web"
)
func healthHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `I'm healty!`)
}
func helloWorldHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `<body><h1>Hello World</h1></br><p>I'm a self-registering microservice!</body>'`)
}
func main() {
service := web.NewService(
web.Name("example"),
)
service.HandleFunc("/", helloWorldHandler)
service.HandleFunc("/health", healthHandler)
if err := service.Init(); err != nil {
log.Fatal(err)
}
if err := service.Run(); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment