-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
65 lines (48 loc) · 1.48 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
60
61
62
63
64
65
package main
import (
"flag"
"github.com/goharbor/harbor-scanner-fake/api"
"github.com/goharbor/harbor-scanner-fake/pkg/config"
"github.com/goharbor/harbor-scanner-fake/pkg/server"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
mw "github.com/oapi-codegen/echo-middleware"
log "github.com/sirupsen/logrus"
)
//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -generate types,server,spec -package api -o ./api/api.gen.go ./api/openapi.yaml
var (
configPath string
debug bool
)
func init() {
flag.StringVar(&configPath, "config", config.DefaultConfigPath, "Path to the configuration file")
flag.StringVar(&configPath, "c", config.DefaultConfigPath, "Path to the configuration file (shorthand)")
flag.BoolVar(&debug, "d", false, "set debug on")
}
func main() {
flag.Parse()
if debug {
log.SetLevel(log.DebugLevel)
}
cfg, err := config.Load(configPath)
if err != nil {
log.Fatal(err)
}
swagger, err := api.GetSwagger()
if err != nil {
log.Fatalf("failed to load swagger spec: %v\n", err)
}
swagger.Security = nil
s := server.New(cfg)
e := echo.New()
if cfg.Server.AsscessLog {
e.Use(middleware.Logger())
}
if cfg.Server.Timeout > 0 {
e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{Timeout: cfg.Server.Timeout}))
}
// Validate requests against the OpenAPI spec
e.Use(mw.OapiRequestValidator(swagger))
api.RegisterHandlersWithBaseURL(e, s, "/api/v1")
e.Logger.Fatal(e.Start(cfg.Server.Address))
}