-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecho.go
73 lines (59 loc) · 1.93 KB
/
echo.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
// Copyright 2018 Sergey Novichkov. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
package echo
import (
"github.com/gozix/di"
"github.com/gozix/glue/v3"
gzValidator "github.com/gozix/validator/v3"
gzViper "github.com/gozix/viper/v3"
gzZap "github.com/gozix/zap/v3"
"github.com/gozix/echo/v3/internal/command"
"github.com/gozix/echo/v3/internal/configurator"
"github.com/gozix/echo/v3/internal/echo"
)
type (
// Bundle implements the glue.Bundle interface.
Bundle struct{}
// Configurator is type alias of configurator.Configurator.
Configurator = configurator.Configurator
// Controller is type alias of controller.Controller.
Controller = configurator.Controller
)
// BundleName is default definition name.
const BundleName = "echo"
var _ glue.Bundle = (*Bundle)(nil)
// NewBundle create bundle instance.
func NewBundle() *Bundle {
return new(Bundle)
}
// Name implements the glue.Bundle interface.
func (b *Bundle) Name() string {
return BundleName
}
// Build implements the glue.Bundle interface.
func (b *Bundle) Build(builder di.Builder) error {
return builder.Apply(
// echo
di.Provide(echo.New, di.Constraint(0, di.Optional(true), withConfigurator())),
// command's
di.Provide(command.NewHTTPServer, glue.AsCliCommand()),
// configurator's
di.Provide(configurator.NewController, di.Constraint(0, di.Optional(true)), AsConfigurator()),
di.Provide(configurator.NewEcho, AsConfigurator()),
di.Provide(configurator.NewErrHandler, AsConfigurator()),
di.Provide(
configurator.NewMiddleware, AsConfigurator(),
di.Constraint(0, withMiddleware(), sortByPriority()),
),
di.Provide(configurator.NewValidator, AsConfigurator()),
)
}
// DependsOn implements the glue.DependsOn interface.
func (b *Bundle) DependsOn() []string {
return []string{
gzValidator.BundleName,
gzViper.BundleName,
gzZap.BundleName,
}
}