From 5b924984abc37d7af1d4e0fe318cac02532705af Mon Sep 17 00:00:00 2001 From: arisnguyenit97 Date: Sun, 14 Jan 2024 18:39:43 +0700 Subject: [PATCH] :recycle: refactor: rename function message #14 --- pkg/ami/ami_action.go | 23 +++++++++-------------- pkg/ami/ami_message.go | 4 ++-- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pkg/ami/ami_action.go b/pkg/ami/ami_action.go index 8313039..3dd0f2f 100644 --- a/pkg/ami/ami_action.go +++ b/pkg/ami/ami_action.go @@ -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 @@ -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) diff --git a/pkg/ami/ami_message.go b/pkg/ami/ami_message.go index d232838..5059817 100644 --- a/pkg/ami/ami_message.go +++ b/pkg/ami/ami_message.go @@ -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 @@ -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