-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
70 lines (53 loc) · 1.39 KB
/
Copy pathserver.go
File metadata and controls
70 lines (53 loc) · 1.39 KB
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
66
67
68
69
70
package authserver
import (
"os"
"github.com/gin-gonic/gin"
"github.com/p1nant0m/gin-gin/config"
"github.com/p1nant0m/gin-gin/pkg/server"
genericAPIServer "github.com/p1nant0m/gin-gin/pkg/server"
"github.com/sirupsen/logrus"
)
type authzServer struct {
genericAPIServer *server.GenericAPIServer
}
type preparedAuthzServer struct {
*authzServer
}
func CreateAuthzServer(cfg *config.Config) (*authzServer, error) {
genericConfig, err := buildGenericConfig(cfg)
if err != nil {
return nil, err
}
genericAPIServer, err := genericConfig.Complete().New()
if err != nil {
return nil, err
}
authzServer := &authzServer{
genericAPIServer: genericAPIServer,
}
return authzServer, nil
}
func (s *authzServer) PrepareRun() preparedAuthzServer {
initRouter(s.genericAPIServer.Engine)
return preparedAuthzServer{s}
}
func buildGenericConfig(cfg *config.Config) (genericConfig *genericAPIServer.Config, lastErr error) {
genericConfig = genericAPIServer.NewConfig()
if lastErr = cfg.GenericServerRunoptions.ApplyTo(genericConfig); lastErr != nil {
return
}
if lastErr = cfg.TraceExporterOptions.ApplyTo(genericConfig); lastErr != nil {
return
}
return
}
func (s preparedAuthzServer) Run() error {
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
if gin.Mode() == gin.DebugMode {
logrus.SetLevel(logrus.DebugLevel)
}
return s.genericAPIServer.Engine.Run(":" + port)
}