Skip to content

Commit

Permalink
♻️ refactor: updated codebase #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 6, 2024
1 parent b4070b0 commit 1270488
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 15 deletions.
6 changes: 3 additions & 3 deletions pkg/ami/ami_cdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *AMICdr) SetStartTime(value time.Time) *AMICdr {
}

func (r *AMICdr) SetStartTimeWith(value string) *AMICdr {
t, err := time.Parse(config.DateTimeFormatYYYYMMDDHHMMSS, value)
t, err := time.Parse(config.DateTimeFormat20060102150405, value)
if err == nil {
r.SetStartTime(t)
}
Expand All @@ -94,7 +94,7 @@ func (r *AMICdr) SetAnswerTime(value time.Time) *AMICdr {
}

func (r *AMICdr) SetAnswerTimeWith(value string) *AMICdr {
t, err := time.Parse(config.DateTimeFormatYYYYMMDDHHMMSS, value)
t, err := time.Parse(config.DateTimeFormat20060102150405, value)
if err == nil {
r.SetAnswerTime(t)
}
Expand All @@ -115,7 +115,7 @@ func (r *AMICdr) SetEndTime(value time.Time) *AMICdr {
}

func (r *AMICdr) SetEndTimeWith(value string) *AMICdr {
t, err := time.Parse(config.DateTimeFormatYYYYMMDDHHMMSS, value)
t, err := time.Parse(config.DateTimeFormat20060102150405, value)
if err == nil {
r.SetEndTime(t)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ami/ami_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func NewAMIPeerStatus() *AMIPeerStatus {

func NewAMIPeerStatusGuard() *AMIPeerStatusGuard {
e := &AMIPeerStatusGuard{}
e.SetDateTimeLayout(config.DateTimeFormatYYYYMMDDHHMMSS)
e.SetTimezone(config.DefaultTimezoneAsia)
e.SetDateTimeLayout(config.DateTimeFormat20060102150405)
e.SetTimezone(config.DefaultTimezoneVietnam)
return e
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ami/ami_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *AMICore) convRaw2PeerStatus(v AMIResultRaw, g *AMIPeerStatusGuard) *AMI
}

if IsStringEmpty(g.DateTimeLayout) {
e.SetPrePublishedAt(e.PublishedAt.Format(config.DateTimeFormatYYYYMMDDHHMMSS))
e.SetPrePublishedAt(e.PublishedAt.Format(config.DateTimeFormat20060102150405))
} else {
e.SetPrePublishedAt(e.PublishedAt.Format(g.DateTimeLayout))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ami/ami_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ type AMICdr struct {
Direction string `json:"direction"`
FlowCall string `json:"flow_call"`
TypeDirection string `json:"type_direction"`
UserExtension string `json:"user_exten,omitempty"`
UserExtension string `json:"user_extension,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"`
PlaybackUrl string `json:"playback_url,omitempty"` // the only cdr has status answered
ExtenSplitterSymbol string `json:"-"` // default exten splitter symbol: -, example: SIP/1000-00098fec then split by -
Expand Down
72 changes: 64 additions & 8 deletions pkg/ami/config/ami_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,60 @@ import (
"time"
)

// Time format styles for date and time formatting.
const (
DateTimeFormatYYYYMMDDTHHMMSS = "2006-01-02T15:04:05"
DateTimeFormatYYYYMMDDHHMMSS = "2006-01-02 15:04:05"
DateTimeFormatYYYYMMDD = "2006-01-02"
DateTimeFormatYYYYMM = "2006-01"
DefaultTimezoneAsia = "Asia/Ho_Chi_Minh"
// DateTimeFormat20060102T150405 represents the time format "2006-01-02T15:04:05",
// which includes the full date in the format YYYY-MM-DD followed by the time in the
// format HH:MM:SS.
DateTimeFormat20060102T150405 = "2006-01-02T15:04:05"

// DateTimeFormat20060102150405 represents the time format "2006-01-02 15:04:05",
// which includes the full date in the format YYYY-MM-DD followed by the time in the
// format HH:MM:SS with a space between the date and time.
DateTimeFormat20060102150405 = "2006-01-02 15:04:05"

// DateTimeFormat20060102 represents the date format "2006-01-02",
// which includes the full date in the format YYYY-MM-DD without any time information.
DateTimeFormat20060102 = "2006-01-02"

// DateTimeFormat200601 represents the month format "2006-01",
// which includes the year and month in the format YYYY-MM without any day or time information.
DateTimeFormat200601 = "2006-01"
)

// Timezone constants representing default timezones for specific regions.
const (
// DefaultTimezoneVietnam is a constant that holds the IANA Time Zone identifier
// for the default timezone in Vietnam, which is "Asia/Ho_Chi_Minh".
DefaultTimezoneVietnam = "Asia/Ho_Chi_Minh"

// DefaultTimezoneNewYork is a constant that holds the IANA Time Zone identifier
// for the default timezone in New York, USA, which is "America/New_York".
DefaultTimezoneNewYork = "America/New_York"

// DefaultTimezoneLondon is a constant that holds the IANA Time Zone identifier
// for the default timezone in London, United Kingdom, which is "Europe/London".
DefaultTimezoneLondon = "Europe/London"

// DefaultTimezoneTokyo is a constant that holds the IANA Time Zone identifier
// for the default timezone in Tokyo, Japan, which is "Asia/Tokyo".
DefaultTimezoneTokyo = "Asia/Tokyo"

// DefaultTimezoneSydney is a constant that holds the IANA Time Zone identifier
// for the default timezone in Sydney, Australia, which is "Australia/Sydney".
DefaultTimezoneSydney = "Australia/Sydney"

// DefaultTimezoneParis is a constant that holds the IANA Time Zone identifier
// for the default timezone in Paris, France, which is "Europe/Paris".
DefaultTimezoneParis = "Europe/Paris"

// DefaultTimezoneMoscow is a constant that holds the IANA Time Zone identifier
// for the default timezone in Moscow, Russia, which is "Europe/Moscow".
DefaultTimezoneMoscow = "Europe/Moscow"

// DefaultTimezoneLosAngeles is a constant that holds the IANA Time Zone identifier
// for the default timezone in Los Angeles, USA, which is "America/Los_Angeles".
DefaultTimezoneLosAngeles = "America/Los_Angeles"
)

const (
Expand Down Expand Up @@ -466,7 +514,7 @@ const (
AmiTypeOutboundNormalDirection = "outbound_normal"
AmiTypeInboundDialDirection = "inbound_dial" // from application on user local machine
AmiTypeInboundQueueDirection = "inbound_queue" // from queue, not real user
AmiTypeChanSpyDirection = "chan_spy" //
AmiTypeChanSpyDirection = "chan_spy"
)

var (
Expand Down Expand Up @@ -613,9 +661,17 @@ const (
AmiLastApplicationChanSpy = "ChanSpy"
)

// AmiChanspySpy, AmiChanspyBarge, and AmiChanspyWhisper are constants representing different modes
// of ChanSpy functionality in Asterisk Manager Interface (AMI).
const (
AmiChanspySpy = "spy"
AmiChanspyBarge = "barge"
// AmiChanspySpy represents the "spy" mode in ChanSpy, allowing monitoring without intervention.
AmiChanspySpy = "spy"

// AmiChanspyBarge represents the "barge" mode in ChanSpy, allowing the interceptor to join an ongoing call.
AmiChanspyBarge = "barge"

// AmiChanspyWhisper represents the "whisper" mode in ChanSpy, allowing the interceptor to listen and talk to
// one party in a call without the other party hearing the interceptor's voice.
AmiChanspyWhisper = "whisper"
)

Expand Down

0 comments on commit 1270488

Please sign in to comment.