Skip to content

Commit 49adb94

Browse files
committed
feat(runtime): simplify App constructors using configure.Apply helper
1 parent 4a1145f commit 49adb94

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

runtime.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/go-kratos/kratos/v2/log"
1010
"github.com/go-kratos/kratos/v2/registry"
1111
"github.com/go-kratos/kratos/v2/transport"
12+
"github.com/goexts/generic/configure"
1213

1314
"github.com/origadmin/runtime/bootstrap"
1415
"github.com/origadmin/runtime/container"
@@ -31,34 +32,22 @@ type App struct {
3132
// New is the primary and most common constructor for creating a new App instance.
3233
// It requires the application name and version directly.
3334
func New(name, version string, opts ...Option) *App {
34-
app := &App{
35+
return configure.Apply(&App{
3536
appInfo: NewAppInfo(name, version),
3637
componentOpts: make(map[string][]options.Option),
3738
containerOpts: make([]options.Option, 0),
38-
}
39-
40-
for _, o := range opts {
41-
o(app)
42-
}
43-
44-
return app
39+
}, opts)
4540
}
4641

4742
// NewWithOptions creates a new, partially initialized App instance using only functional options.
4843
// This constructor provides maximum flexibility. It requires that the application's name and
4944
// version be provided via options (e.g., by using WithAppInfo).
5045
func NewWithOptions(opts ...Option) *App {
51-
app := &App{
46+
return configure.Apply(&App{
5247
appInfo: NewAppInfoBuilder(),
5348
componentOpts: make(map[string][]options.Option),
5449
containerOpts: make([]options.Option, 0),
55-
}
56-
57-
for _, o := range opts {
58-
o(app)
59-
}
60-
61-
return app
50+
}, opts)
6251
}
6352

6453
// Load reads the configuration from the given path, completes the App initialization,

0 commit comments

Comments
 (0)