-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: redesigned input arg handler to be more extensible
- Loading branch information
Showing
4 changed files
with
102 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package pkg | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// NOTE: add new fields here and to following function to extend functionalities | ||
// - The fields in this struct should mirror the "command_args" table in `lua/pendulum/remote.lua` | ||
type PendulumArgs struct { | ||
LogFile string | ||
Timeout float64 | ||
TopN int | ||
TimeRange string | ||
} | ||
|
||
// Parse input arguments from lua table args | ||
func ParsePendlumArgs(args map[string]interface{}) (*PendulumArgs, error) { | ||
logFile, ok := args["log_file"].(string) | ||
if !ok { | ||
return nil, errors.New("log_file missing or not a string. " + | ||
fmt.Sprintf("Type: %T\n", args["log_file"])) | ||
} | ||
|
||
topN, ok := args["top_n"].(int64) | ||
if !ok { | ||
return nil, errors.New("top_n missing or not a number. " + | ||
fmt.Sprintf("Type: %T\n", args["top_n"])) | ||
} | ||
|
||
timerLen, ok := args["timer_len"].(int64) | ||
if !ok { | ||
return nil, errors.New("timer_len missing or not a number. " + | ||
fmt.Sprintf("Type: %T\n", args["timer_len"])) | ||
} | ||
|
||
timeRange, ok := args["time_range"].(string) | ||
if !ok { | ||
return nil, errors.New("timeRange missing or not a string. " + | ||
fmt.Sprintf("Type: %T\n", args["time_range"])) | ||
} | ||
|
||
out := PendulumArgs{ | ||
LogFile: logFile, | ||
Timeout: float64(timerLen), | ||
TopN: int(topN), | ||
TimeRange: timeRange, | ||
} | ||
|
||
return &out, nil | ||
} |