-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (47 loc) · 1.33 KB
/
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
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/aaletov/go-smo/api"
"github.com/aaletov/go-smo/pkg/clock"
"github.com/aaletov/go-smo/server"
"github.com/go-chi/chi/v5"
"github.com/rs/cors"
)
const (
sourcesLambda = 13
sourcesCount = 3
bufferCount = 4
devicesCount = 3
)
func main() {
var port = 8081
clock.InitClock(time.Unix(0, 0))
swagger, err := api.GetSwagger()
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading swagger spec\n: %s", err)
os.Exit(1)
}
// Clear out the servers array in the swagger spec, that skips validating
// that server names match. We don't know how this thing will be run.
swagger.Servers = nil
// Create an instance of our handler which satisfies the generated interface
smoServer := server.NewServer()
// This is how you set up a basic chi router
r := chi.NewRouter()
r.Use(cors.Default().Handler)
// Use our validation middleware to check all requests against the
// OpenAPI schema.
//r.Use(middleware.OapiRequestValidator(swagger))
// We now register our petStore above as the handler for the interface
api.HandlerFromMux(smoServer, r)
s := &http.Server{
Handler: r,
Addr: fmt.Sprintf("0.0.0.0:%d", port),
}
// And we serve HTTP until the world ends.
log.Fatal(s.ListenAndServe())
}