Skip to content

Commit 51df6b5

Browse files
committed
refactor(项目): 完成基于依赖注入重构框架
1 parent 26fd947 commit 51df6b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+272
-416
lines changed

argument.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package boot
22

33
import (
4+
"github.com/harluo/boot/internal/application"
45
"github.com/harluo/boot/internal/argument"
56
"github.com/harluo/boot/internal/constraint"
67
)
78

89
// Argument 参数
9-
type Argument[T constraint.Argument] = argument.Default[T]
10+
type Argument = application.Argument
1011

1112
// NewArgument 创建参数
1213
func NewArgument[T constraint.Argument](name string, target *T) *argument.Builder[T] {

command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package boot
22

33
import (
4+
"github.com/harluo/boot/internal/application"
45
"github.com/harluo/boot/internal/builder"
5-
"github.com/harluo/boot/internal/core"
66
)
77

88
// Command 命令
9-
type Command = core.Command
9+
type Command = application.Command
1010

1111
// NewCommand 创建命令
1212
func NewCommand(name string) *builder.Command {

initializer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package boot
2+
3+
import (
4+
"github.com/harluo/boot/internal/application"
5+
)
6+
7+
type Initializer = application.Initializer

internal/application/after.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package application
2+
3+
import (
4+
"context"
5+
)
6+
7+
type After interface {
8+
After(ctx context.Context) error
9+
}

internal/application/before.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package application
2+
3+
import (
4+
"context"
5+
)
6+
7+
type Before interface {
8+
Before(ctx context.Context) error
9+
}

internal/application/command.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
// Command 描述一个可以被执行的命令
88
type Command interface {
99
Parameter
10-
Stopper
11-
Lifecycle
1210

1311
// Run 执行命令
1412
Run(ctx context.Context) error

internal/application/initializer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package application
2+
3+
import (
4+
"context"
5+
)
6+
7+
type Initializer interface {
8+
Initialize(ctx context.Context) error
9+
}

internal/application/lifecycle.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

internal/application/serve.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

internal/application/stopper.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
)
66

7-
// Stopper 可停止
87
type Stopper interface {
9-
// Stop 停止
10-
Stop(ctx context.Context) (err error)
8+
Stop(ctx context.Context) error
119
}

internal/argument/builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package argument
22

33
import (
4+
"github.com/harluo/boot/internal/application"
45
"github.com/harluo/boot/internal/constraint"
56
)
67

@@ -16,7 +17,7 @@ func New[T constraint.Argument](name string, target *T) *Builder[T] {
1617
}
1718
}
1819

19-
func (b *Builder[T]) Build() *Default[T] {
20+
func (b *Builder[T]) Build() application.Argument {
2021
return b.argument
2122
}
2223

internal/argument/default.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ package argument
33
import (
44
"time"
55

6-
"github.com/goexl/gox"
76
"github.com/harluo/boot/internal/application"
87
"github.com/harluo/boot/internal/constraint"
98
"github.com/harluo/boot/internal/runtime"
109
"github.com/urfave/cli/v2"
1110
)
1211

13-
var _ application.Argument = (*Default[int])(nil)
14-
1512
type Default[T constraint.Argument] struct {
1613
// 名称
1714
name string
@@ -35,8 +32,6 @@ type Default[T constraint.Argument] struct {
3532
text string
3633
// 动作
3734
action Action[T]
38-
39-
_ gox.Pointerized
4035
}
4136

4237
func NewDefault[T constraint.Argument](name string, target *T) *Default[T] {

internal/builder/application.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"github.com/harluo/boot/internal/builder/internal/function"
66
"github.com/harluo/boot/internal/builder/internal/once"
77
"github.com/harluo/boot/internal/core"
8+
"github.com/harluo/boot/internal/internal/config"
89
"github.com/harluo/boot/internal/internal/kernel"
9-
"github.com/harluo/boot/internal/internal/param"
1010
)
1111

1212
var shadow *Application
1313

1414
type Application struct {
15-
params *param.Application
15+
params *config.Application
1616
timeout *Timeout
1717
banner *Banner
1818
help *Help
@@ -28,7 +28,7 @@ func NewApplication() (application *Application) {
2828

2929
func newApplication() {
3030
shadow = new(Application)
31-
shadow.params = param.NewApplication()
31+
shadow.params = config.NewApplication()
3232

3333
// !预创建,保证单例
3434
shadow.timeout = newTimeout(shadow)

internal/builder/banner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package builder
22

33
import (
44
"github.com/harluo/boot/internal/internal/banner"
5-
"github.com/harluo/boot/internal/internal/param"
5+
"github.com/harluo/boot/internal/internal/config"
66
)
77

88
type Banner struct {
9-
params *param.Banner
9+
params *config.Banner
1010
application *Application
1111
}
1212

internal/builder/code.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package builder
22

33
import (
4-
"github.com/harluo/boot/internal/internal/param"
4+
"github.com/harluo/boot/internal/internal/config"
55
)
66

77
type Code struct {
8-
params *param.Code
8+
params *config.Code
99
application *Application
1010
}
1111

internal/builder/command.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package builder
33
import (
44
"github.com/harluo/boot/internal/builder/internal/function"
55
"github.com/harluo/boot/internal/internal/command"
6-
"github.com/harluo/boot/internal/internal/param"
6+
"github.com/harluo/boot/internal/internal/config"
77
)
88

99
type Command struct {
10-
params *param.Command
10+
params *config.Command
1111
}
1212

1313
func NewCommand(name string) *Command {
1414
return &Command{
15-
params: param.NewCommand(name),
15+
params: config.NewCommand(name),
1616
}
1717
}
1818

internal/builder/help.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package builder
22

33
import (
4-
"github.com/harluo/boot/internal/internal/param"
4+
"github.com/harluo/boot/internal/internal/config"
55
)
66

77
type Help struct {
8-
params *param.Help
8+
params *config.Help
99
application *Application
1010
}
1111

internal/builder/timeout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package builder
33
import (
44
"time"
55

6-
"github.com/harluo/boot/internal/internal/param"
6+
"github.com/harluo/boot/internal/internal/config"
77
)
88

99
type Timeout struct {
10-
params *param.Timeout
10+
params *config.Timeout
1111
application *Application
1212
}
1313

0 commit comments

Comments
 (0)