-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (32 loc) 路 889 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
package main
import (
"context"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/go-chi/chi"
"github.com/spy16/moonshot"
"github.com/spy16/moonshot/httputils"
)
var appCfg struct {
Addr string `mapstructure:"addr" yaml:"addr" json:"addr"`
LogLevel string `mapstructure:"log_level" yaml:"log_level" json:"log_level"`
LogFormat string `mapstructure:"log_format" yaml:"log_format" json:"log_format"`
}
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
app := &moonshot.App{
Name: "moonshot-demo",
Short: "A sample moonshot app setup",
CfgPtr: &appCfg,
Routes: func(r *chi.Mux) {
// set up any custom routes here.
r.Get("/hello", func(wr http.ResponseWriter, req *http.Request) {
httputils.Respond(wr, req, http.StatusOK, "Hello!")
})
},
}
os.Exit(app.Launch(ctx))
}