Skip to content

Commit

Permalink
♻️ refactor: rename function message #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 14, 2024
1 parent 7a9286b commit 5b92498
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions pkg/ami/ami_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (a *AMIAction) SetTimeout(timeout int) *AMIAction {
return a
}

// Revoke run cli on asterisk server
func (c *AMIAction) Revoke(a *AMI, d *AMIDictionary, e *AMIMessage, deadlock bool) (*AMIResponse, error) {
D().Info("Ami revoking action (state mutex opened lock~unlock): '%v'", e.String())
var response AMIResponse
Expand Down Expand Up @@ -75,33 +74,29 @@ on_failed:
return &response, _err
}

// Run for run cli asterisk server
func (c *AMIAction) Run(a *AMI) (*AMIResponse, error) {
action := NewActionWith(config.AmiActionCommand)
action := WithMessage(config.AmiActionCommand)
action.AddField(config.AmiActionCommand, c.Name)
return c.Revoke(a, NewDictionary(), action, false)
}

// RunDictionary
func (c *AMIAction) RunDictionary(a *AMI, dictionaries map[string]string) (*AMIResponse, error) {
action := NewActionWith(config.AmiActionCommand)
func (c *AMIAction) WithRunX(a *AMI, dictionaries map[string]string) (*AMIResponse, error) {
action := WithMessage(config.AmiActionCommand)
action.AddField(config.AmiActionCommand, c.Name)
d := NewDictionary()
d.AddKeysTranslator(dictionaries)
return c.Revoke(a, d, action, false)
}

// RunScript with script action
func (c *AMIAction) RunScript(a *AMI, script map[string]string) (*AMIResponse, error) {
action := NewActionWith(c.Name)
action.AddFields(script)
func (c *AMIAction) WithRunV(a *AMI, command map[string]string) (*AMIResponse, error) {
action := WithMessage(c.Name)
action.AddFields(command)
return c.Revoke(a, NewDictionary(), action, false)
}

// WithRun with script action
func (c *AMIAction) WithRun(a *AMI, script, dictionaries map[string]string) (*AMIResponse, error) {
action := NewActionWith(c.Name)
action.AddFields(script)
func (c *AMIAction) WithRunXV(a *AMI, command, dictionaries map[string]string) (*AMIResponse, error) {
action := WithMessage(c.Name)
action.AddFields(command)
d := NewDictionary()
d.AddKeysTranslator(dictionaries)
return c.Revoke(a, d, action, false)
Expand Down
4 changes: 2 additions & 2 deletions pkg/ami/ami_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/pnguyen215/voipkit/pkg/ami/config"
)

func NewActionWith(name string) *AMIMessage {
func WithMessage(name string) *AMIMessage {
a := NewMessage()
a.AddField(config.AmiActionKey, name)
return a
Expand Down Expand Up @@ -70,7 +70,7 @@ func ofMessageWithDictionary(d *AMIDictionary, header textproto.MIMEHeader) *AMI

// Authenticate action by message
func Authenticate(username, password string) *AMIMessage {
a := NewActionWith(config.AmiLoginKey)
a := WithMessage(config.AmiLoginKey)
a.AddField(config.AmiFieldUsername, username)
a.AddField(config.AmiFieldSecret, password)
return a
Expand Down

0 comments on commit 5b92498

Please sign in to comment.