-
Notifications
You must be signed in to change notification settings - Fork 8
/
service_provider.go
56 lines (43 loc) · 1.55 KB
/
service_provider.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
package gin
import (
"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/foundation"
"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/contracts/log"
"github.com/goravel/framework/contracts/validation"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)
const RouteBinding = "goravel.gin.route"
var (
App foundation.Application
ConfigFacade config.Config
LogFacade log.Log
ValidationFacade validation.Validation
ViewFacade http.View
)
type ServiceProvider struct{}
func (receiver *ServiceProvider) Register(app foundation.Application) {
App = app
app.BindWith(RouteBinding, func(app foundation.Application, parameters map[string]any) (any, error) {
return NewRoute(app.MakeConfig(), parameters)
})
}
func (receiver *ServiceProvider) Boot(app foundation.Application) {
module := "gin"
if ConfigFacade = app.MakeConfig(); ConfigFacade == nil {
color.Errorln(errors.ConfigFacadeNotSet.SetModule(module))
}
if LogFacade = app.MakeLog(); LogFacade == nil {
color.Errorln(errors.LogFacadeNotSet.SetModule(module))
}
if ValidationFacade = app.MakeValidation(); ValidationFacade == nil {
color.Errorln(errors.New("validation facade is not initialized").SetModule(module))
}
if ViewFacade = app.MakeView(); ViewFacade == nil {
color.Errorln(errors.New("view facade is not initialized").SetModule(module))
}
app.Publishes("github.com/goravel/gin", map[string]string{
"config/cors.go": app.ConfigPath("cors.go"),
})
}