-
Notifications
You must be signed in to change notification settings - Fork 0
/
act.go
79 lines (65 loc) · 1.78 KB
/
act.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package lama
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/core/router"
"github.com/kataras/iris/v12/middleware/accesslog"
"github.com/kataras/iris/v12/middleware/cors"
"github.com/kataras/iris/v12/middleware/requestid"
"github.com/kataras/iris/v12/mvc"
)
type NewMvc func(string) MVCApp
type NewMvcApp func(router.Party) MVCApp
type NewParty func(string, ...iris.Handler) router.Party
type Version func(string) mvc.OptionFunc
type Deprecated func(mvc.DeprecationOptions) mvc.OptionFunc
type IRISApp = *iris.Application
type MVCApp = *mvc.Application
var App IRISApp
func NewIRISApp() IRISApp {
if App == nil {
App = iris.New()
if Conf.Bool("app.accesslog") {
App.UseRouter(accesslog.New(Print.Printer).Handler)
}
if Conf.Bool("app.recover") {
r := &Recover{debug: Conf.Bool("app.debug")}
r.Init(App)
}
App.UseRouter(requestid.New())
App.UseRouter(cors.New().
ExtractOriginFunc(cors.DefaultOriginExtractor).
ReferrerPolicy(cors.NoReferrerWhenDowngrade).
AllowOriginFunc(cors.AllowAnyOrigin).
Handler())
var disableStartupLog bool
debug := Conf.Bool("app.debug")
if !debug {
disableStartupLog = true
}
conf := []iris.Configurator{
iris.WithoutInterruptHandler,
iris.WithoutServerError(iris.ErrServerClosed),
iris.WithConfiguration(iris.Configuration{
PostMaxMemory: 100 << 20,
DisableStartupLog: disableStartupLog,
}),
}
App.Configure(conf...)
App.AllowMethods(iris.MethodOptions)
}
return App
}
type Act struct {
}
func (s *Act) Provide() (IRISApp, NewMvcApp, Version, Deprecated, NewParty, NewMvc) {
app := NewIRISApp()
newMvc := func(path string) MVCApp {
return mvc.New(app.APIBuilder.Party(path))
}
return app,
mvc.New,
mvc.Version,
mvc.Deprecated,
app.APIBuilder.Party,
newMvc
}