-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (40 loc) · 1014 Bytes
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"log"
"net/http"
"os"
"cloud.google.com/go/logging"
"github.com/go-chi/chi"
"github.com/mikemackintosh/pallet"
)
func main() {
// Set listening port
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
// Create the router
r := chi.NewRouter()
loggingOptions := pallet.NewOptionSet()
loggingOptions.SetLabels(map[string]string{
"test": "test",
})
loggingOptions.SetProject(os.Getenv("GOOGLE_CLOUD_PROJECT"))
// A good base middleware stack.
//r.Use(MiddlewareSlackWrapper)
r.Use(pallet.DefaultMiddleware(loggingOptions))
r.Get("/", handler)
// Listen and serve
log.Fatal(http.ListenAndServe(":"+port, r))
}
// handler is a sample route
func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
logger := pallet.GetLoggerFromRequest(r)
logger.Logf(logging.Warning, "url: %+v", r.URL.Path)
_, err := w.Write([]byte("{\"status\": \"ok\"}"))
if err != nil {
log.Fatal(err)
}
}