-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
41 lines (34 loc) · 1.13 KB
/
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
package kernel
import (
"github.com/BugKillerPro/less/framework"
"github.com/BugKillerPro/less/framework/contract"
"github.com/BugKillerPro/less/framework/gin"
)
// LessKernelProvider 提供web引擎
type LessKernelProvider struct {
HttpEngine *gin.Engine
}
// Register 注册服务提供者
func (provider *LessKernelProvider) Register(c framework.Container) framework.NewInstance {
return NewlessKernelService
}
// Boot 启动的时候判断是否由外界注入了Engine,如果注入的化,用注入的,如果没有,重新实例化
func (provider *LessKernelProvider) Boot(c framework.Container) error {
if provider.HttpEngine == nil {
provider.HttpEngine = gin.Default()
}
provider.HttpEngine.SetContainer(c)
return nil
}
// IsDefer 引擎的初始化我们希望开始就进行初始化
func (provider *LessKernelProvider) IsDefer() bool {
return false
}
// Params 参数就是一个HttpEngine
func (provider *LessKernelProvider) Params(c framework.Container) []interface{} {
return []interface{}{provider.HttpEngine}
}
// Name 提供凭证
func (provider *LessKernelProvider) Name() string {
return contract.KernelKey
}