-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.go
41 lines (35 loc) · 977 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
package main
import (
"net/http"
"github.com/go-chi/chi"
"github.com/rakyll/statik/fs"
"github.com/sirupsen/logrus"
sum "github.com/utrack/clay/doc/example/implementation"
"github.com/utrack/clay/v3/log"
"github.com/utrack/clay/v3/transport/middlewares/mwgrpc"
"github.com/utrack/clay/v3/transport/server"
// We're using statik-compiled files of Swagger UI
// for the sake of example.
_ "github.com/utrack/clay/doc/example/static/statik"
)
func main() {
// Wire up our bundled Swagger UI
staticFS, err := fs.New()
if err != nil {
logrus.Fatal(err)
}
hmux := chi.NewRouter()
hmux.Mount("/", http.FileServer(staticFS))
impl := sum.NewSummator()
srv := server.NewServer(
12345,
// Pass our mux with Swagger UI
server.WithHTTPMux(hmux),
// Recover from both HTTP and gRPC panics and use our own middleware
server.WithGRPCUnaryMiddlewares(mwgrpc.UnaryPanicHandler(log.Default)),
)
err = srv.Run(impl)
if err != nil {
logrus.Fatal(err)
}
}