Skip to content

Commit

Permalink
♻️ refactor: rename functions #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 14, 2024
1 parent 1e572c1 commit 941edb4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion pkg/ami/ami_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *AMIAction) Revoke(a *AMI, d *AMIDictionary, e *AMIMessage, deadlock boo
for {
select {
case message := <-all:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
Expand Down
2 changes: 1 addition & 1 deletion pkg/ami/ami_cdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func ParseCdr(e *AMIMessage, d *AMIDictionary) *AMICdr {
SetBillableSecondWith(e.FieldDictionaryOrRefer(d, config.AmiJsonFieldBillableSeconds, "BillableSeconds")).
SetCallerId(e.FieldDictionaryOrRefer(d, config.AmiJsonFieldCallerId, "CallerID")).
SetChannel(e.FieldDictionaryOrRefer(d, config.AmiJsonFieldChannel, "Channel")).
SetDateReceivedAtWith(e.DateTimeLayout, e.FieldDictionaryOrRefer(d, config.AmiJsonFieldDateReceivedAt, "DateReceivedAt")).
SetDateReceivedAtWith(e.TimeFormat, e.FieldDictionaryOrRefer(d, config.AmiJsonFieldDateReceivedAt, "DateReceivedAt")).
SetDestination(e.FieldDictionaryOrRefer(d, config.AmiJsonFieldDestination, "Destination")).
SetDestinationChannel(e.FieldDictionaryOrRefer(d, config.AmiJsonFieldDestinationChannel, "DestinationChannel")).
SetDestinationContext(e.FieldDictionaryOrRefer(d, config.AmiJsonFieldDestinationContext, "DestinationContext")).
Expand Down
6 changes: 3 additions & 3 deletions pkg/ami/ami_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewAMIPeerStatus() *AMIPeerStatus {

func NewAMIPeerStatusGuard() *AMIPeerStatusGuard {
e := &AMIPeerStatusGuard{}
e.SetDateTimeLayout(config.DateTimeFormat20060102150405)
e.SetTimeFormat(config.DateTimeFormat20060102150405)
e.SetTimezone(config.DefaultTimezoneVietnam)
return e
}
Expand Down Expand Up @@ -237,8 +237,8 @@ func (e *AMIPeerStatus) SetPublishedAt(value time.Time) *AMIPeerStatus {
return e
}

func (e *AMIPeerStatusGuard) SetDateTimeLayout(value string) *AMIPeerStatusGuard {
e.DateTimeLayout = TrimStringSpaces(value)
func (e *AMIPeerStatusGuard) SetTimeFormat(value string) *AMIPeerStatusGuard {
e.TimeFormat = TrimStringSpaces(value)
return e
}

Expand Down
52 changes: 26 additions & 26 deletions pkg/ami/ami_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func NewEventListener() *AMIEvent {
return e
}

func (m *AMIEvent) SetDateTimeLayout(value string) *AMIEvent {
m.DateTimeLayout = value
func (m *AMIEvent) SetTimeFormat(value string) *AMIEvent {
m.TimeFormat = value
return m
}

Expand All @@ -42,14 +42,14 @@ func (e *AMIEvent) OpenFullEvents(c *AMI) {
for {
select {
case message := <-all:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
log.Printf("ami event: '%s' received = %s", message.Field(strings.ToLower(config.AmiEventKey)), message.Json())
log.Printf("ami event: '%s' received: %s", message.Field(strings.ToLower(config.AmiEventKey)), message.Json())
case err := <-c.Error():
c.Close()
log.Printf("ami listener has error occurred = %s", err.Error())
log.Printf("ami listener has error occurred: %s", err.Error())
}
}
}
Expand All @@ -62,14 +62,14 @@ func (e *AMIEvent) OpenFullEventsTranslator(c *AMI, d *AMIDictionary) {
for {
select {
case message := <-all:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
log.Printf("ami event: '%s' received = %s", message.Field(strings.ToLower(config.AmiEventKey)), message.JsonTranslator(d))
log.Printf("ami event: '%s' received: %s", message.Field(strings.ToLower(config.AmiEventKey)), message.JsonTranslator(d))
case err := <-c.Error():
c.Close()
log.Printf("ami listener has error occurred = %s", err.Error())
log.Printf("ami listener has error occurred: %s", err.Error())
}
}
}
Expand All @@ -82,14 +82,14 @@ func (e *AMIEvent) OpenFullEventsCallbackTranslator(c *AMI, d *AMIDictionary, ca
for {
select {
case message := <-all:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
callback(message, message.JsonTranslator(d), nil)
case err := <-c.Error():
c.Close()
log.Printf("ami listener has error occurred = %s", err.Error())
log.Printf("ami listener has error occurred: %s", err.Error())
callback(nil, err.Error(), err)
}
}
Expand All @@ -103,14 +103,14 @@ func (e *AMIEvent) OpenEvent(c *AMI, name string) {
for {
select {
case message := <-event:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
log.Printf("ami event: '%s' received = %s", name, message.Json())
log.Printf("ami event: '%s' received: %s", name, message.Json())
case err := <-c.Error():
c.Close()
log.Printf("ami listener event: '%s' has error occurred = %s", name, err.Error())
log.Printf("ami listener event: '%s' has error occurred: %s", name, err.Error())
}
}
}
Expand All @@ -123,14 +123,14 @@ func (e *AMIEvent) OpenEventTranslator(c *AMI, d *AMIDictionary, name string) {
for {
select {
case message := <-event:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
log.Printf("ami event: '%s' received = %s", name, message.JsonTranslator(d))
log.Printf("ami event: '%s' received: %s", name, message.JsonTranslator(d))
case err := <-c.Error():
c.Close()
log.Printf("ami listener event: '%s' has error occurred = %s", name, err.Error())
log.Printf("ami listener event: '%s' has error occurred: %s", name, err.Error())
}
}
}
Expand All @@ -143,14 +143,14 @@ func (e *AMIEvent) OpenEventCallbackTranslator(c *AMI, d *AMIDictionary, name st
for {
select {
case message := <-event:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
callback(message, message.JsonTranslator(d), nil)
case err := <-c.Error():
c.Close()
log.Printf("ami listener event: '%s' has error occurred = %s", name, err.Error())
log.Printf("ami listener event: '%s' has error occurred: %s", name, err.Error())
callback(nil, err.Error(), err)
}
}
Expand All @@ -164,14 +164,14 @@ func (e *AMIEvent) OpenEvents(c *AMI, keys ...string) {
for {
select {
case message := <-event:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
log.Printf("ami event(s): '%s' received = %s", keys, message.Json())
log.Printf("ami event(s): '%s' received: %s", keys, message.Json())
case err := <-c.Error():
c.Close()
log.Printf("ami listener event(s): '%s' has error occurred = %s", keys, err.Error())
log.Printf("ami listener event(s): '%s' has error occurred: %s", keys, err.Error())
}
}
}
Expand All @@ -184,14 +184,14 @@ func (e *AMIEvent) OpenEventsTranslator(c *AMI, d *AMIDictionary, keys ...string
for {
select {
case message := <-event:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
log.Printf("ami event(s): '%s' received = %s", keys, message.JsonTranslator(d))
log.Printf("ami event(s): '%s' received: %s", keys, message.JsonTranslator(d))
case err := <-c.Error():
c.Close()
log.Printf("ami listener event(s): '%s' has error occurred = %s", keys, err.Error())
log.Printf("ami listener event(s): '%s' has error occurred: %s", keys, err.Error())
}
}
}
Expand All @@ -204,14 +204,14 @@ func (e *AMIEvent) OpenEventsCallbackTranslator(c *AMI, d *AMIDictionary, callba
for {
select {
case message := <-event:
message.SetDateTimeLayout(e.DateTimeLayout)
message.SetTimeFormat(e.TimeFormat)
message.SetPhonePrefix(e.PhonePrefix)
message.SetRegion(e.Region)
message.AddFieldDateReceivedAt()
callback(message, message.JsonTranslator(d), nil)
case err := <-c.Error():
c.Close()
log.Printf("ami listener event(s): '%s' has error occurred = %s", keys, err.Error())
log.Printf("ami listener event(s): '%s' has error occurred: %s", keys, err.Error())
callback(nil, err.Error(), err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ami/ami_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func (c *AMICore) convRaw2PeerStatus(v AmiReply, g *AMIPeerStatusGuard) *AMIPeer
e.SetPublishedAt(e.PublishedAt.Add(-time.Millisecond * time.Duration(e.TimeInMs)))
}

if IsStringEmpty(g.DateTimeLayout) {
if IsStringEmpty(g.TimeFormat) {
e.SetPrePublishedAt(e.PublishedAt.Format(config.DateTimeFormat20060102150405))
} else {
e.SetPrePublishedAt(e.PublishedAt.Format(g.DateTimeLayout))
e.SetPrePublishedAt(e.PublishedAt.Format(g.TimeFormat))
}

return e
Expand Down
8 changes: 4 additions & 4 deletions pkg/ami/ami_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func NewMessage() *AMIMessage {
return ofMessage(header)
}

func (m *AMIMessage) SetDateTimeLayout(value string) *AMIMessage {
m.DateTimeLayout = value
func (m *AMIMessage) SetTimeFormat(value string) *AMIMessage {
m.TimeFormat = value
return m
}

Expand Down Expand Up @@ -206,8 +206,8 @@ func (k *AMIMessage) AddActionId() {

// Added Date Received at generated
func (k *AMIMessage) AddFieldDateReceivedAt() {
if len(k.DateTimeLayout) > 0 {
k.AddField(config.AmiFieldDateReceivedAt, time.Now().Format(k.DateTimeLayout))
if len(k.TimeFormat) > 0 {
k.AddField(config.AmiFieldDateReceivedAt, time.Now().Format(k.TimeFormat))
} else {
k.AddField(config.AmiFieldDateReceivedAt, time.Now().String())
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/ami/ami_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ type AMIPubSubQueue struct {
}

type AMIMessage struct {
header textproto.MIMEHeader
mutex sync.RWMutex
DateTimeLayout string `json:"date_time_layout,omitempty"`
PhonePrefix []string `json:"phone_prefix,omitempty"`
Region string `json:"region,omitempty"`
header textproto.MIMEHeader
mutex sync.RWMutex
TimeFormat string `json:"time_format,omitempty"`
PhonePrefix []string `json:"phone_prefix,omitempty"`
Region string `json:"region,omitempty"`
}

type AMIEvent struct {
DateTimeLayout string `json:"date_time_layout,omitempty"`
PhonePrefix []string `json:"phone_prefix,omitempty"`
Region string `json:"region,omitempty"`
TimeFormat string `json:"time_format,omitempty"`
PhonePrefix []string `json:"phone_prefix,omitempty"`
Region string `json:"region,omitempty"`
}

type AMIDictionary struct {
Expand Down Expand Up @@ -389,8 +389,8 @@ type AMIPeerStatus struct {
}

type AMIPeerStatusGuard struct {
DateTimeLayout string `json:"date_time_layout"`
Timezone string `json:"timezone"`
TimeFormat string `json:"time_format"`
Timezone string `json:"timezone"`
}

type AMICdr struct {
Expand Down

0 comments on commit 941edb4

Please sign in to comment.