Skip to content

Commit

Permalink
chore: Fix comment blocks and other revive linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassiweni42 committed Nov 16, 2022
1 parent 8282dc0 commit b1b146a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
27 changes: 12 additions & 15 deletions dialoguss.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ const (
`
)

// Dialoguss the main type for interacting with dialoguss sessions
type Dialoguss core.Dialoguss

/// UnexpectedResultError
///
/// Unexpected result from the USSD application
// UnexpectedResultError unexpected result from the USSD application
func UnexpectedResultError(want string, have string) error {
return fmt.Errorf("Unexpected result.\n\tWant: %s\n\tHave: %s", want, have)
}

/// DialStep
///
/// DialStep is the first step in the session, dials the USSD service
// DialStep is the first step in the session, dials the USSD service
func DialStep(expect string) *core.Step {
return &core.Step{
StepNo: 0,
Expand All @@ -57,9 +54,7 @@ func DialStep(expect string) *core.Step {
}
}

/// NewStep
///
/// a subsequent step in the session to the USSD service
// NewStep a subsequent step in the session to the USSD service
func NewStep(i int, text string, expect string) *core.Step {
return &core.Step{
StepNo: i,
Expand All @@ -70,8 +65,7 @@ func NewStep(i int, text string, expect string) *core.Step {
}
}

/// Executes a step and returns the result of the request
/// May return an empty string ("") upon failure
// Execute executes a step and returns the result of the request may return an empty string ("") upon failure
func Execute(s *core.Step, session *core.Session) (string, error) {
if trurouteMode {
step := trueroute.TrueRouteStep{Step: s}
Expand All @@ -82,11 +76,12 @@ func Execute(s *core.Step, session *core.Session) (string, error) {
return step.ExecuteAsAfricasTalking(session)
}

/// AddStep adds step to session
// AddStep adds step to session
func AddStep(s *core.Session, step *core.Step) {
s.Steps = append(s.Steps, step)
}

// NewInteractiveSession creates a new interactive session that should be run using RunInteractive
func NewInteractiveSession(d core.DialogussConfig) *core.Session {
rand.Seed(time.Now().UnixNano())
apiType := ApiTypeAfricastalking
Expand All @@ -110,6 +105,7 @@ func NewInteractiveSession(d core.DialogussConfig) *core.Session {
}
}

// Run runs the dialoguss session and executes the steps in each session
func Run(s *core.Session) error {
first := true
for i, step := range s.Steps {
Expand Down Expand Up @@ -147,6 +143,7 @@ func promptCh(ch chan string) {
ch <- value
}

// RunInteractive runs and interactive session that prompts ufor user input
func RunInteractive(s *core.Session) error {
var input, output string
var err error
Expand Down Expand Up @@ -202,7 +199,7 @@ sessionLoop:
return nil
}

/// LoadConfig loads configuration from YAML
// LoadConfig loads configuration from YAML
func (d *Dialoguss) LoadConfig() error {
d.Config = core.DialogussConfig{Timeout: int(defaultTimeout)}
b, err := ioutil.ReadFile(d.File)
Expand All @@ -213,7 +210,7 @@ func (d *Dialoguss) LoadConfig() error {
return yaml.Unmarshal(b, &d.Config)
}

/// Loads the sessions for this application
// RunAutomatedSessions Loads the sessions for this application
func (d *Dialoguss) RunAutomatedSessions() error {
var wg sync.WaitGroup
wg.Add(len(d.Config.Sessions))
Expand Down Expand Up @@ -257,7 +254,7 @@ func (d *Dialoguss) RunAutomatedSessions() error {
return nil
}

/// Run executes the sessions
// Run executes the sessions
func (d *Dialoguss) Run() error {
// log.Print("Running dialoguss with config", d.config)
if d.IsInteractive {
Expand Down
6 changes: 4 additions & 2 deletions pkg/trueroute/truroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type TruRouteResponse struct {
Msisdn string `xml:"msisdn"`
}

// isResponse checks if the response is truly a success
func (t *TruRouteResponse) isResponse() bool {
return t.Type == TrurouteCodeResponse
}
Expand All @@ -53,16 +54,17 @@ func (t *TruRouteResponse) isRelease() bool {
return t.Type == TrurouteCodeRelease
}

// GetText returns the response text
func (t *TruRouteResponse) GetText() string {
return t.Message
}

/// Executes a step and returns the result of the request
/// ExecuteAsTruRouteRequest executes a step and returns the result of the request
/// May return an empty string ("") upon failure
func (s *TrueRouteStep) ExecuteAsTruRouteRequest(session *core.Session) (string, error) {
var text = s.Text
if &text == nil {
return "", errors.New("Input Text cannot be nil")
return "", errors.New("input Text cannot be nil")
}

req := &TruRouteRequest{}
Expand Down

0 comments on commit b1b146a

Please sign in to comment.