Skip to content

Commit 1bf662c

Browse files
committed
feat(param): add method to create Params
1 parent e13c92d commit 1bf662c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/app/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (app *App) ReOpenLog() []error {
3232
return app.logFileMan.Reopen()
3333
}
3434

35-
func NewApp(params []*param.Param, setting *setting.Setting) (*App, []error) {
35+
func NewApp(params param.Params, setting *setting.Setting) (*App, []error) {
3636
if len(setting.PidFile) > 0 {
3737
errs := writePidFile(setting.PidFile)
3838
if len(errs) > 0 {

src/param/cli.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ func ArgsToCmdResults(cmd *goNixArgParser.Command, args []string) (results []*go
278278
return
279279
}
280280

281-
func CmdResultsToParams(results []*goNixArgParser.ParseResult) (params []*Param, errs []error) {
281+
func CmdResultsToParams(results []*goNixArgParser.ParseResult) (params Params, errs []error) {
282282
// init param data
283-
params = make([]*Param, 0, len(results))
283+
params = make(Params, 0, len(results))
284284
for _, result := range results {
285285
param := &Param{}
286286

@@ -418,7 +418,7 @@ func CmdResultsToParams(results []*goNixArgParser.ParseResult) (params []*Param,
418418
return
419419
}
420420

421-
func ParseFromCli() (params []*Param, printVersion, printHelp bool, errs []error) {
421+
func ParseFromCli() (params Params, printVersion, printHelp bool, errs []error) {
422422
var cmdResults []*goNixArgParser.ParseResult
423423

424424
cmdResults, printVersion, printHelp, errs = ArgsToCmdResults(cliCmd, os.Args)

src/param/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ type Param struct {
8585
ErrorLog string
8686
}
8787

88+
type Params []*Param
89+
8890
func (param *Param) normalize() (errs []error) {
8991
var es []error
9092
var err error
@@ -177,3 +179,15 @@ func (param *Param) normalize() (errs []error) {
177179

178180
return
179181
}
182+
183+
func NewParams(paramList []Param) (params Params, errs []error) {
184+
params = make(Params, len(paramList))
185+
186+
for i := range params {
187+
copiedParam := paramList[i]
188+
params[i] = &copiedParam
189+
errs = append(errs, params[i].normalize()...)
190+
}
191+
192+
return
193+
}

0 commit comments

Comments
 (0)