Skip to content

Commit

Permalink
♻️ refactor: updated codebase #9
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 15, 2024
1 parent b46b382 commit c392de7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
28 changes: 14 additions & 14 deletions apix/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,37 +210,37 @@ func (s *apiServiceImpl) alert(endpoint EndpointConfig, response *restify.Respon
message.WriteString(fmt.Sprintf("%v ", icon))
}
message.WriteString("API REST HTTP\n")
message.WriteString(fmt.Sprintf("Tz: `%s` (Received At: `%v`)\n\n",
time.Now().Format(timex.DateTimeFormYearMonthDayHourMinuteSecond), response.ReceivedAt()))
message.WriteString(fmt.Sprintf("tz: `%s` (received at: `%v`)\n\n",
time.Now().Format(timex.TimeFormat20060102150405), response.ReceivedAt()))
if utils.IsNotEmpty(endpoint.Description) {
message.WriteString(fmt.Sprintf("Decs: `%s`\n", endpoint.Description))
message.WriteString(fmt.Sprintf("decs: `%s`\n", endpoint.Description))
}
message.WriteString(fmt.Sprintf("(`%s`) URL: `%s`\n", response.Request.Method, response.Request.URL))
message.WriteString(fmt.Sprintf("(`%s`) url: `%s`\n", response.Request.Method, response.Request.URL))
message.WriteString("\n---\n")
if endpoint.AvailableHeaders() && !endpoint.TelegramOptions.SkipMessageHeader {
message.WriteString(fmt.Sprintf("Header(s): \n\t`%s`\n", coltx.MapString2Table(endpoint.Headers)))
message.WriteString(fmt.Sprintf("header(s): \n\t`%s`\n", coltx.MapString2Table(endpoint.Headers)))
}
if endpoint.AvailableQueryParams() && !endpoint.TelegramOptions.SkipMessageQueryParam {
message.WriteString(fmt.Sprintf("Query Param(s): `%s`\n", coltx.MapString2Table(endpoint.QueryParams)))
message.WriteString(fmt.Sprintf("query param(s): `%s`\n", coltx.MapString2Table(endpoint.QueryParams)))
}
if endpoint.AvailablePathParams() && !endpoint.TelegramOptions.SkipMessagePathParam {
message.WriteString(fmt.Sprintf("Path Param(s): `%s`\n", coltx.MapString2Table(endpoint.PathParams)))
message.WriteString(fmt.Sprintf("path param(s): `%s`\n", coltx.MapString2Table(endpoint.PathParams)))
}
if endpoint.AvailableBody() && !endpoint.TelegramOptions.SkipMessageRequestBody {
message.WriteString(fmt.Sprintf("Request Body: `%s`\n", utils.ToJson(endpoint.Body)))
message.WriteString(fmt.Sprintf("request body: `%s`\n", utils.ToJson(endpoint.Body)))
}
if endpoint.Retry.AvailableRetryOnStatus() {
message.WriteString(fmt.Sprintf("Retry On Status: `%s`\n", utils.ToJson(endpoint.Retry.RetryOnStatus)))
message.WriteString(fmt.Sprintf("retry on status: `%s`\n", utils.ToJson(endpoint.Retry.RetryOnStatus)))
}
message.WriteString("\n---\n")
message.WriteString(fmt.Sprintf("Status Code: %v\n", response.StatusCode()))
message.WriteString(fmt.Sprintf("status code: %v\n", response.StatusCode()))
if utils.IsNotEmpty(response.String()) && !endpoint.TelegramOptions.SkipMessageResponseBody {
message.WriteString(fmt.Sprintf("Response: `%v`\n", response.String()))
message.WriteString(fmt.Sprintf("response: `%v`\n", response.String()))
}
message.WriteString(fmt.Sprintf("No. attempt: %v\n", response.Request.Attempt))
message.WriteString(fmt.Sprintf("Duration: `%v`\n", response.Time()))
message.WriteString(fmt.Sprintf("no. attempt: %v\n", response.Request.Attempt))
message.WriteString(fmt.Sprintf("duration: `%v`\n", response.Time()))
if err != nil {
message.WriteString(fmt.Sprintf("Error(R): `%v`\n", err.Error()))
message.WriteString(fmt.Sprintf("error(r): `%v`\n", err.Error()))
}
s.telegramSvc.SendMessage(message.String())
}
48 changes: 24 additions & 24 deletions configx/configx.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,30 +205,30 @@ func (KeysConfig) WriteDefaultConfig() {
m := NewKeyCmtConfig()
m.SetData(GetKeysDefaultConfig())
m.SetComment(map[string]string{
"server": fmt.Sprintf("################################\n%s\n%s\n################################", "Server Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"cookie": fmt.Sprintf("################################\n%s\n%s\n################################", "Cookie Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"logger": fmt.Sprintf("################################\n%s\n%s\n################################", "Logger Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"kafka": fmt.Sprintf("################################\n%s\n%s\n################################", "Kafka Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"asterisk": fmt.Sprintf("################################\n%s\n%s\n################################", "Asterisk Server Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"mongodb": fmt.Sprintf("################################\n%s\n%s\n################################", "Mongodb Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"mysql": fmt.Sprintf("################################\n%s\n%s\n################################", "MySQL Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"postgres": fmt.Sprintf("################################\n%s\n%s\n################################", "Postgres Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"rabbitmq": fmt.Sprintf("################################\n%s\n%s\n################################", "RabbitMQ Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"redis": fmt.Sprintf("################################\n%s\n%s\n################################", "Redis Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"telegram": fmt.Sprintf("################################\n%s\n%s\n################################", "Telegram Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"slack": fmt.Sprintf("################################\n%s\n%s\n################################", "Slack Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"cors": fmt.Sprintf("################################\n%s\n%s\n################################", "Cors Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"telegram-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Telegram Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"slack-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Slack Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"asterisk-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Asterisk Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"mongodb-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Mongodb Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"mysql-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "MySQL Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"postgres-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Postgres Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"rabbitmq-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "RabbitMQ Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"redis-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Redis Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"cookie-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Cookie Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"logger-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Logger Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"kafka-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Kafka Seekers Config", timex.With(time.Now()).Format(timex.DateTimeFormYearMonthDayHourMinuteSecond)),
"server": fmt.Sprintf("################################\n%s\n%s\n################################", "Server Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"cookie": fmt.Sprintf("################################\n%s\n%s\n################################", "Cookie Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"logger": fmt.Sprintf("################################\n%s\n%s\n################################", "Logger Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"kafka": fmt.Sprintf("################################\n%s\n%s\n################################", "Kafka Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"asterisk": fmt.Sprintf("################################\n%s\n%s\n################################", "Asterisk Server Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"mongodb": fmt.Sprintf("################################\n%s\n%s\n################################", "Mongodb Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"mysql": fmt.Sprintf("################################\n%s\n%s\n################################", "MySQL Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"postgres": fmt.Sprintf("################################\n%s\n%s\n################################", "Postgres Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"rabbitmq": fmt.Sprintf("################################\n%s\n%s\n################################", "RabbitMQ Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"redis": fmt.Sprintf("################################\n%s\n%s\n################################", "Redis Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"telegram": fmt.Sprintf("################################\n%s\n%s\n################################", "Telegram Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"slack": fmt.Sprintf("################################\n%s\n%s\n################################", "Slack Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"cors": fmt.Sprintf("################################\n%s\n%s\n################################", "Cors Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"telegram-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Telegram Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"slack-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Slack Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"asterisk-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Asterisk Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"mongodb-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Mongodb Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"mysql-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "MySQL Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"postgres-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Postgres Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"rabbitmq-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "RabbitMQ Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"redis-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Redis Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"cookie-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Cookie Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"logger-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Logger Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
"kafka-seekers": fmt.Sprintf("################################\n%s\n%s\n################################", "Kafka Seekers Config", timex.With(time.Now()).Format(timex.TimeFormat20060102150405)),
})
err = CreateConfigWithComments[KeysConfig](filepath.Join(".", FilenameDefaultConf), *m)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (l *Logger) JsonFormatter() *logrus.JSONFormatter {
DisableTimestamp: false,
PrettyPrint: false,
DisableHTMLEscape: false,
TimestampFormat: timex.DateTimeFormYearMonthDayHourMinuteSecond,
TimestampFormat: timex.TimeFormat20060102150405,
FieldMap: logrus.FieldMap{
logrus.FieldKeyTime: "@timestamp",
logrus.FieldKeyLevel: "@level",
Expand All @@ -105,7 +105,7 @@ func (l *Logger) TextFormatter() *logrus.TextFormatter {
FullTimestamp: true,
QuoteEmptyFields: true,
DisableQuote: true,
TimestampFormat: timex.DateTimeFormYearMonthDayHourMinuteSecond,
TimestampFormat: timex.TimeFormat20060102150405,
FieldMap: logrus.FieldMap{
logrus.FieldKeyTime: "@timestamp",
logrus.FieldKeyLevel: "@level",
Expand Down

0 comments on commit c392de7

Please sign in to comment.