-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
37 lines (28 loc) · 913 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"net/http"
"oss.nandlabs.io/golly/lifecycle"
"oss.nandlabs.io/golly/rest/server"
)
func main() {
// register the router by creating the server object
restServer, err := server.Default()
if err != nil {
panic(err)
}
// Add path prefix if you want
restServer.Opts().PathPrefix = "/api/v1"
// add a GET endpoint to your server by providing the "endpoint" and handler function
restServer.Get("/healthz", healthCheck)
// create the http.Server object and register the router as Handler
// provide the necessary configurations such as PORT, ReadTimeout, WriteTimeout...
manager := lifecycle.NewSimpleComponentManager()
// Register the server
manager.Register(restServer)
// start the server
manager.StartAndWait()
}
func healthCheck(ctx server.Context) {
ctx.HttpResWriter().Write([]byte("server is up and running"))
ctx.HttpResWriter().WriteHeader(http.StatusOK)
}