Last active
April 4, 2017 20:12
-
-
Save fgbreel/28e736722e7439d9c55d519a11953867 to your computer and use it in GitHub Desktop.
A self registered micro service example from gomicro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:onbuild |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM scratch | |
ADD main / | |
CMD ["/main"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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