Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc140583 committed Aug 30, 2024
1 parent 060eeea commit a1a511f
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion echo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package echo
type LogConfig struct {
Separate bool `yaml:"separate" mapstructure:"separate" json:"separate,omitempty" gorm:"column:separate" bson:"separate,omitempty" dynamodbav:"separate,omitempty" firestore:"separate,omitempty"`
Build bool `yaml:"build" mapstructure:"build" json:"build,omitempty" gorm:"column:build" bson:"build,omitempty" dynamodbav:"build,omitempty" firestore:"build,omitempty"`
StringFormat bool `yaml:"string_format" mapstructure:"string_format" json:"stringFormat,omitempty" gorm:"column:string_format" bson:"stringFormat,omitempty" dynamodbav:"stringFormat,omitempty" firestore:"stringFormat,omitempty"`
Json bool `yaml:"json" mapstructure:"json" json:"json,omitempty" gorm:"column:json" bson:"json,omitempty" dynamodbav:"json,omitempty" firestore:"json,omitempty"`
Log bool `yaml:"log" mapstructure:"log" json:"log,omitempty" gorm:"column:log" bson:"log,omitempty" dynamodbav:"log,omitempty" firestore:"log,omitempty"`
Skips string `yaml:"skips" mapstructure:"skips" json:"skips,omitempty" gorm:"column:skips" bson:"skips,omitempty" dynamodbav:"skips,omitempty" firestore:"skips,omitempty"`
Ip string `yaml:"ip" mapstructure:"ip" json:"ip,omitempty" gorm:"column:ip" bson:"ip,omitempty" dynamodbav:"ip,omitempty" firestore:"ip,omitempty"`
Expand Down
6 changes: 5 additions & 1 deletion echo/mask_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ type MaskLogger struct {
JsonFormat bool
}

func NewMaskLogger(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), jsonFormat bool) *MaskLogger {
func NewMaskLogger(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), opts ...bool) *MaskLogger {
jsonFormat := false
if len(opts) > 0 {
jsonFormat = opts[0]
}
return &MaskLogger{RequestKey: requestKey, MaskRequest: maskRequest, MaskResponse: maskResponse, JsonFormat: jsonFormat}
}
func NewMaskLoggerWithSending(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), jsonFormat bool, send func(context.Context, []byte, map[string]string) error, options ...map[string]string) *MaskLogger {
Expand Down
2 changes: 1 addition & 1 deletion echo/structured_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var fieldConfig FieldConfig
func NewLogger() *StructuredLogger {
return &StructuredLogger{}
}
func NewLoggerWithStringFormat(requestKey string, jsonFormat bool) *StructuredLogger {
func NewLoggerWithJsonFormat(requestKey string, jsonFormat bool) *StructuredLogger {
return &StructuredLogger{RequestKey: requestKey, JsonFormat: jsonFormat}
}
func NewLoggerWithSending(requestKey string, jsonFormat bool, send func(context.Context, []byte, map[string]string) error, options ...map[string]string) *StructuredLogger {
Expand Down
2 changes: 1 addition & 1 deletion echo/v3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package echo
type LogConfig struct {
Separate bool `yaml:"separate" mapstructure:"separate" json:"separate,omitempty" gorm:"column:separate" bson:"separate,omitempty" dynamodbav:"separate,omitempty" firestore:"separate,omitempty"`
Build bool `yaml:"build" mapstructure:"build" json:"build,omitempty" gorm:"column:build" bson:"build,omitempty" dynamodbav:"build,omitempty" firestore:"build,omitempty"`
StringFormat bool `yaml:"string_format" mapstructure:"string_format" json:"stringFormat,omitempty" gorm:"column:string_format" bson:"stringFormat,omitempty" dynamodbav:"stringFormat,omitempty" firestore:"stringFormat,omitempty"`
Json bool `yaml:"json" mapstructure:"json" json:"json,omitempty" gorm:"column:json" bson:"json,omitempty" dynamodbav:"json,omitempty" firestore:"json,omitempty"`
Log bool `yaml:"log" mapstructure:"log" json:"log,omitempty" gorm:"column:log" bson:"log,omitempty" dynamodbav:"log,omitempty" firestore:"log,omitempty"`
Skips string `yaml:"skips" mapstructure:"skips" json:"skips,omitempty" gorm:"column:skips" bson:"skips,omitempty" dynamodbav:"skips,omitempty" firestore:"skips,omitempty"`
Ip string `yaml:"ip" mapstructure:"ip" json:"ip,omitempty" gorm:"column:ip" bson:"ip,omitempty" dynamodbav:"ip,omitempty" firestore:"ip,omitempty"`
Expand Down
6 changes: 5 additions & 1 deletion echo/v3/mask_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ type MaskLogger struct {
JsonFormat bool
}

func NewMaskLogger(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), jsonFormat bool) *MaskLogger {
func NewMaskLogger(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), opts ...bool) *MaskLogger {
jsonFormat := false
if len(opts) > 0 {
jsonFormat = opts[0]
}
return &MaskLogger{RequestKey: requestKey, MaskRequest: maskRequest, MaskResponse: maskResponse, JsonFormat: jsonFormat}
}
func NewMaskLoggerWithSending(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), jsonFormat bool, send func(context.Context, []byte, map[string]string) error, options ...map[string]string) *MaskLogger {
Expand Down
2 changes: 1 addition & 1 deletion echo/v3/structured_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var fieldConfig FieldConfig
func NewLogger() *StructuredLogger {
return &StructuredLogger{}
}
func NewLoggerWithStringFormat(requestKey string, jsonFormat bool) *StructuredLogger {
func NewLoggerWithJsonFormat(requestKey string, jsonFormat bool) *StructuredLogger {
return &StructuredLogger{RequestKey: requestKey, JsonFormat: jsonFormat}
}
func NewLoggerWithSending(requestKey string, jsonFormat bool, send func(context.Context, []byte, map[string]string) error, options ...map[string]string) *StructuredLogger {
Expand Down
2 changes: 1 addition & 1 deletion gin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gin
type LogConfig struct {
Separate bool `yaml:"separate" mapstructure:"separate" json:"separate,omitempty" gorm:"column:separate" bson:"separate,omitempty" dynamodbav:"separate,omitempty" firestore:"separate,omitempty"`
Build bool `yaml:"build" mapstructure:"build" json:"build,omitempty" gorm:"column:build" bson:"build,omitempty" dynamodbav:"build,omitempty" firestore:"build,omitempty"`
StringFormat bool `yaml:"string_format" mapstructure:"string_format" json:"stringFormat,omitempty" gorm:"column:string_format" bson:"stringFormat,omitempty" dynamodbav:"stringFormat,omitempty" firestore:"stringFormat,omitempty"`
Json bool `yaml:"json" mapstructure:"json" json:"json,omitempty" gorm:"column:json" bson:"json,omitempty" dynamodbav:"json,omitempty" firestore:"json,omitempty"`
Log bool `yaml:"log" mapstructure:"log" json:"log,omitempty" gorm:"column:log" bson:"log,omitempty" dynamodbav:"log,omitempty" firestore:"log,omitempty"`
Skips string `yaml:"skips" mapstructure:"skips" json:"skips,omitempty" gorm:"column:skips" bson:"skips,omitempty" dynamodbav:"skips,omitempty" firestore:"skips,omitempty"`
Ip string `yaml:"ip" mapstructure:"ip" json:"ip,omitempty" gorm:"column:ip" bson:"ip,omitempty" dynamodbav:"ip,omitempty" firestore:"ip,omitempty"`
Expand Down
6 changes: 5 additions & 1 deletion gin/mask_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ type MaskLogger struct {
JsonFormat bool
}

func NewMaskLogger(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), jsonFormat bool) *MaskLogger {
func NewMaskLogger(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), opts ...bool) *MaskLogger {
jsonFormat := false
if len(opts) > 0 {
jsonFormat = opts[0]
}
return &MaskLogger{RequestKey: requestKey, MaskRequest: maskRequest, MaskResponse: maskResponse, JsonFormat: jsonFormat}
}
func NewMaskLoggerWithSending(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), jsonFormat bool, send func(context.Context, []byte, map[string]string) error, options ...map[string]string) *MaskLogger {
Expand Down
2 changes: 1 addition & 1 deletion gin/structured_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var fieldConfig FieldConfig
func NewLogger() *StructuredLogger {
return &StructuredLogger{}
}
func NewLoggerWithStringFormat(requestKey string, jsonFormat bool) *StructuredLogger {
func NewLoggerWithJsonFormat(requestKey string, jsonFormat bool) *StructuredLogger {
return &StructuredLogger{RequestKey: requestKey, JsonFormat: jsonFormat}
}
func NewLoggerWithSending(requestKey string, jsonFormat bool, send func(context.Context, []byte, map[string]string) error, options ...map[string]string) *StructuredLogger {
Expand Down
2 changes: 1 addition & 1 deletion log_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package middleware
type LogConfig struct {
Separate bool `yaml:"separate" mapstructure:"separate" json:"separate,omitempty" gorm:"column:separate" bson:"separate,omitempty" dynamodbav:"separate,omitempty" firestore:"separate,omitempty"`
Build bool `yaml:"build" mapstructure:"build" json:"build,omitempty" gorm:"column:build" bson:"build,omitempty" dynamodbav:"build,omitempty" firestore:"build,omitempty"`
StringFormat bool `yaml:"string_format" mapstructure:"string_format" json:"stringFormat,omitempty" gorm:"column:string_format" bson:"stringFormat,omitempty" dynamodbav:"stringFormat,omitempty" firestore:"stringFormat,omitempty"`
Json bool `yaml:"json" mapstructure:"json" json:"json,omitempty" gorm:"column:json" bson:"json,omitempty" dynamodbav:"json,omitempty" firestore:"json,omitempty"`
Log bool `yaml:"log" mapstructure:"log" json:"log,omitempty" gorm:"column:log" bson:"log,omitempty" dynamodbav:"log,omitempty" firestore:"log,omitempty"`
Skips string `yaml:"skips" mapstructure:"skips" json:"skips,omitempty" gorm:"column:skips" bson:"skips,omitempty" dynamodbav:"skips,omitempty" firestore:"skips,omitempty"`
Ip string `yaml:"ip" mapstructure:"ip" json:"ip,omitempty" gorm:"column:ip" bson:"ip,omitempty" dynamodbav:"ip,omitempty" firestore:"ip,omitempty"`
Expand Down
6 changes: 5 additions & 1 deletion mask_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ type MaskLogger struct {
JsonFormat bool
}

func NewMaskLogger(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), jsonFormat bool) *MaskLogger {
func NewMaskLogger(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), opts ...bool) *MaskLogger {
jsonFormat := false
if len(opts) > 0 {
jsonFormat = opts[0]
}
return &MaskLogger{RequestKey: requestKey, MaskRequest: maskRequest, MaskResponse: maskResponse, JsonFormat: jsonFormat}
}
func NewMaskLoggerWithSending(requestKey string, maskRequest func(map[string]interface{}), maskResponse func(map[string]interface{}), jsonFormat bool, send func(context.Context, []byte, map[string]string) error, options ...map[string]string) *MaskLogger {
Expand Down
2 changes: 1 addition & 1 deletion structured_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var fieldConfig FieldConfig
func NewLogger() *StructuredLogger {
return &StructuredLogger{}
}
func NewLoggerWithStringFormat(requestKey string, jsonFormat bool) *StructuredLogger {
func NewLoggerWithJsonFormat(requestKey string, jsonFormat bool) *StructuredLogger {
return &StructuredLogger{RequestKey: requestKey, JsonFormat: jsonFormat}
}
func NewLoggerWithSending(requestKey string, jsonFormat bool, send func(context.Context, []byte, map[string]string) error, options ...map[string]string) *StructuredLogger {
Expand Down

0 comments on commit a1a511f

Please sign in to comment.