Skip to content

Instantly share code, notes, and snippets.

@cbweixin
Created April 24, 2022 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbweixin/c137b15414192e800f0c5f1d9066a231 to your computer and use it in GitHub Desktop.
Save cbweixin/c137b15414192e800f0c5f1d9066a231 to your computer and use it in GitHub Desktop.
type ParamSet struct {
Caller lib.Caller
TimeoutNS time.Duration
LPS uint32
DurationNS time.Duration
ResultCh chan *lib.CallResult
}
func (pset *ParamSet) Check() error {
var errMsgs []string
if pset.Caller == nil {
errMsgs = append(errMsgs, "Invalid caller!")
}
if pset.LPS == 0 {
errMsgs = append(errMsgs, "Invalid lps(load per second)!")
}
if pset.TimeoutNS == 0 {
errMsgs = append(errMsgs, "Invalid timeoutNS!")
}
if pset.DurationNS == 0 {
errMsgs = append(errMsgs, "Invalid durationNS!")
}
if pset.ResultCh == nil {
errMsgs = append(errMsgs, "Invalid result channel!")
}
var buf bytes.Buffer
buf.WriteString("Checking the parameters...")
if errMsgs != nil {
errMsg := strings.Join(errMsgs, " ")
buf.WriteString(fmt.Sprintf("NOT passed! (%s)", errMsg))
logger.Infoln(buf.String())
return errors.New(errMsg)
}
buf.WriteString(
fmt.Sprintf("Passed. (timeoutNS=%s, lps=%d,durationNS=%s)",
pset.TimeoutNS, pset.LPS, pset.DurationNS))
logger.Infoln(buf.String())
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment