Skip to content

Commit ffd1dc2

Browse files
committed
Refactor code
1 parent d1ef7d6 commit ffd1dc2

File tree

6 files changed

+46
-46
lines changed

6 files changed

+46
-46
lines changed

code.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ const (
2020
)
2121

2222
type Model struct {
23-
Id string `mapstructure:"id" json:"id,omitempty" gorm:"column:id" bson:"id,omitempty" dynamodbav:"id,omitempty" firestore:"id,omitempty"`
24-
Code string `mapstructure:"code" json:"code,omitempty" gorm:"column:code" bson:"code,omitempty" dynamodbav:"code,omitempty" firestore:"code,omitempty"`
25-
Value string `mapstructure:"value" json:"value,omitempty" gorm:"column:value" bson:"value,omitempty" dynamodbav:"value,omitempty" firestore:"value,omitempty"`
26-
Name string `mapstructure:"name" json:"name,omitempty" gorm:"column:name" bson:"name,omitempty" dynamodbav:"name,omitempty" firestore:"name,omitempty"`
27-
Text string `mapstructure:"text" json:"text,omitempty" gorm:"column:text" bson:"text,omitempty" dynamodbav:"text,omitempty" firestore:"text,omitempty"`
28-
Sequence int32 `mapstructure:"sequence" json:"sequence,omitempty" gorm:"column:sequence" bson:"sequence,omitempty" dynamodbav:"sequence,omitempty" firestore:"sequence,omitempty"`
23+
Id string `yaml:"id" mapstructure:"id" json:"id,omitempty" gorm:"column:id" bson:"id,omitempty" dynamodbav:"id,omitempty" firestore:"id,omitempty"`
24+
Code string `yaml:"code" mapstructure:"code" json:"code,omitempty" gorm:"column:code" bson:"code,omitempty" dynamodbav:"code,omitempty" firestore:"code,omitempty"`
25+
Value string `yaml:"value" mapstructure:"value" json:"value,omitempty" gorm:"column:value" bson:"value,omitempty" dynamodbav:"value,omitempty" firestore:"value,omitempty"`
26+
Name string `yaml:"name"" mapstructure:"name" json:"name,omitempty" gorm:"column:name" bson:"name,omitempty" dynamodbav:"name,omitempty" firestore:"name,omitempty"`
27+
Text string `yaml:"text" mapstructure:"text" json:"text,omitempty" gorm:"column:text" bson:"text,omitempty" dynamodbav:"text,omitempty" firestore:"text,omitempty"`
28+
Sequence int32 `yaml:"sequence mapstructure:"sequence" json:"sequence,omitempty" gorm:"column:sequence" bson:"sequence,omitempty" dynamodbav:"sequence,omitempty" firestore:"sequence,omitempty"`
2929
}
3030
type StructureConfig struct {
31-
Master string `mapstructure:"master" json:"master,omitempty" gorm:"column:master" bson:"master,omitempty" dynamodbav:"master,omitempty" firestore:"master,omitempty"`
32-
Id string `mapstructure:"id" json:"id,omitempty" gorm:"column:id" bson:"id,omitempty" dynamodbav:"id,omitempty" firestore:"id,omitempty"`
33-
Code string `mapstructure:"code" json:"code,omitempty" gorm:"column:code" bson:"code,omitempty" dynamodbav:"code,omitempty" firestore:"code,omitempty"`
34-
Text string `mapstructure:"text" json:"text,omitempty" gorm:"column:text" bson:"text,omitempty" dynamodbav:"text,omitempty" firestore:"text,omitempty"`
35-
Name string `mapstructure:"name" json:"name,omitempty" gorm:"column:name" bson:"name,omitempty" dynamodbav:"name,omitempty" firestore:"name,omitempty"`
36-
Value string `mapstructure:"value" json:"value,omitempty" gorm:"column:value" bson:"value,omitempty" dynamodbav:"value,omitempty" firestore:"value,omitempty"`
37-
Sequence string `mapstructure:"sequence" json:"sequence,omitempty" gorm:"column:sequence" bson:"sequence,omitempty" dynamodbav:"sequence,omitempty" firestore:"sequence,omitempty"`
38-
Status string `mapstructure:"status" json:"status,omitempty" gorm:"column:status" bson:"status,omitempty" dynamodbav:"status,omitempty" firestore:"status,omitempty"`
39-
Active interface{} `mapstructure:"active" json:"active,omitempty" gorm:"column:active" bson:"active,omitempty" dynamodbav:"active,omitempty" firestore:"active,omitempty"`
31+
Master string `yaml:"master" mapstructure:"master" json:"master,omitempty" gorm:"column:master" bson:"master,omitempty" dynamodbav:"master,omitempty" firestore:"master,omitempty"`
32+
Id string `yaml:"id" mapstructure:"id" json:"id,omitempty" gorm:"column:id" bson:"id,omitempty" dynamodbav:"id,omitempty" firestore:"id,omitempty"`
33+
Code string `yaml:"code" mapstructure:"code" json:"code,omitempty" gorm:"column:code" bson:"code,omitempty" dynamodbav:"code,omitempty" firestore:"code,omitempty"`
34+
Text string `yaml:"text" mapstructure:"text" json:"text,omitempty" gorm:"column:text" bson:"text,omitempty" dynamodbav:"text,omitempty" firestore:"text,omitempty"`
35+
Name string `yaml:"name" mapstructure:"name" json:"name,omitempty" gorm:"column:name" bson:"name,omitempty" dynamodbav:"name,omitempty" firestore:"name,omitempty"`
36+
Value string `yaml:"value" mapstructure:"value" json:"value,omitempty" gorm:"column:value" bson:"value,omitempty" dynamodbav:"value,omitempty" firestore:"value,omitempty"`
37+
Sequence string `yaml:"sequence" mapstructure:"sequence" json:"sequence,omitempty" gorm:"column:sequence" bson:"sequence,omitempty" dynamodbav:"sequence,omitempty" firestore:"sequence,omitempty"`
38+
Status string `yaml:"status" mapstructure:"status" json:"status,omitempty" gorm:"column:status" bson:"status,omitempty" dynamodbav:"status,omitempty" firestore:"status,omitempty"`
39+
Active interface{} `yaml:"active" mapstructure:"active" json:"active,omitempty" gorm:"column:active" bson:"active,omitempty" dynamodbav:"active,omitempty" firestore:"active,omitempty"`
4040
}
4141
type Loader interface {
4242
Load(ctx context.Context, master string) ([]Model, error)

config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package code
22

33
type Config struct {
4-
Handler HandlerConfig `mapstructure:"handler" json:"handler,omitempty" gorm:"column:handler" bson:"handler,omitempty" dynamodbav:"handler,omitempty" firestore:"handler,omitempty"`
5-
Loader StructureConfig `mapstructure:"loader" json:"loader,omitempty" gorm:"column:loader" bson:"loader,omitempty" dynamodbav:"loader,omitempty" firestore:"loader,omitempty"`
4+
Handler HandlerConfig `yaml:"handler" mapstructure:"handler" json:"handler,omitempty" gorm:"column:handler" bson:"handler,omitempty" dynamodbav:"handler,omitempty" firestore:"handler,omitempty"`
5+
Loader StructureConfig `yaml:"loader" mapstructure:"loader" json:"loader,omitempty" gorm:"column:loader" bson:"loader,omitempty" dynamodbav:"loader,omitempty" firestore:"loader,omitempty"`
66
}

echo/handler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ const internalServerError = "Internal Server Error"
1414
type Handler struct {
1515
Codes func(ctx context.Context, master string) ([]co.Model, error)
1616
RequiredMaster bool
17-
Error func(context.Context, string)
17+
Error func(context.Context, string, ...map[string]interface{})
1818
Log func(ctx context.Context, resource string, action string, success bool, desc string) error
1919
Resource string
2020
Action string
2121
Id string
2222
Name string
2323
}
2424

25-
func NewDefaultCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), options ...func(context.Context, string, string, bool, string) error) *Handler {
25+
func NewDefaultCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), options ...func(context.Context, string, string, bool, string) error) *Handler {
2626
var writeLog func(context.Context, string, string, bool, string) error
2727
if len(options) >= 1 {
2828
writeLog = options[0]
2929
}
3030
return NewCodeHandlerWithLog(load, logError, true, writeLog, "", "")
3131
}
32-
func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.Model, error), c co.HandlerConfig, logError func(context.Context, string), options ...func(context.Context, string, string, bool, string) error) *Handler {
32+
func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.Model, error), c co.HandlerConfig, logError func(context.Context, string, ...map[string]interface{}), options ...func(context.Context, string, string, bool, string) error) *Handler {
3333
var requireMaster bool
3434
if c.Master != nil {
3535
requireMaster = *c.Master
@@ -45,14 +45,14 @@ func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.
4545
h.Name = c.Name
4646
return h
4747
}
48-
func NewCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), requiredMaster bool, options ...func(context.Context, string, string, bool, string) error) *Handler {
48+
func NewCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), requiredMaster bool, options ...func(context.Context, string, string, bool, string) error) *Handler {
4949
var writeLog func(context.Context, string, string, bool, string) error
5050
if len(options) >= 1 {
5151
writeLog = options[0]
5252
}
5353
return NewCodeHandlerWithLog(load, logError, requiredMaster, writeLog, "", "")
5454
}
55-
func NewCodeHandlerWithLog(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), requiredMaster bool, writeLog func(context.Context, string, string, bool, string) error, options ...string) *Handler {
55+
func NewCodeHandlerWithLog(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), requiredMaster bool, writeLog func(context.Context, string, string, bool, string) error, options ...string) *Handler {
5656
var resource, action string
5757
if len(options) >= 1 && len(options[0]) > 0 {
5858
resource = options[0]
@@ -111,7 +111,7 @@ func respond(ctx echo.Context, code int, result interface{}, writeLog func(conte
111111
}
112112
return err
113113
}
114-
func respondError(ctx echo.Context, code int, result interface{}, logError func(context.Context, string), resource string, action string, err error, writeLog func(context.Context, string, string, bool, string) error) error {
114+
func respondError(ctx echo.Context, code int, result interface{}, logError func(context.Context, string, ...map[string]interface{}), resource string, action string, err error, writeLog func(context.Context, string, string, bool, string) error) error {
115115
if logError != nil {
116116
logError(ctx.Request().Context(), err.Error())
117117
}

echo_v3/handler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ const internalServerError = "Internal Server Error"
1414
type Handler struct {
1515
Codes func(ctx context.Context, master string) ([]co.Model, error)
1616
RequiredMaster bool
17-
Error func(context.Context, string)
17+
Error func(context.Context, string, ...map[string]interface{})
1818
Log func(ctx context.Context, resource string, action string, success bool, desc string) error
1919
Resource string
2020
Action string
2121
Id string
2222
Name string
2323
}
2424

25-
func NewDefaultCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), options ...func(context.Context, string, string, bool, string) error) *Handler {
25+
func NewDefaultCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), options ...func(context.Context, string, string, bool, string) error) *Handler {
2626
var writeLog func(context.Context, string, string, bool, string) error
2727
if len(options) >= 1 {
2828
writeLog = options[0]
2929
}
3030
return NewCodeHandlerWithLog(load, logError, true, writeLog, "", "")
3131
}
32-
func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.Model, error), c co.HandlerConfig, logError func(context.Context, string), options ...func(context.Context, string, string, bool, string) error) *Handler {
32+
func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.Model, error), c co.HandlerConfig, logError func(context.Context, string, ...map[string]interface{}), options ...func(context.Context, string, string, bool, string) error) *Handler {
3333
var requireMaster bool
3434
if c.Master != nil {
3535
requireMaster = *c.Master
@@ -45,14 +45,14 @@ func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.
4545
h.Name = c.Name
4646
return h
4747
}
48-
func NewCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), requiredMaster bool, options ...func(context.Context, string, string, bool, string) error) *Handler {
48+
func NewCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), requiredMaster bool, options ...func(context.Context, string, string, bool, string) error) *Handler {
4949
var writeLog func(context.Context, string, string, bool, string) error
5050
if len(options) >= 1 {
5151
writeLog = options[0]
5252
}
5353
return NewCodeHandlerWithLog(load, logError, requiredMaster, writeLog, "", "")
5454
}
55-
func NewCodeHandlerWithLog(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), requiredMaster bool, writeLog func(context.Context, string, string, bool, string) error, options ...string) *Handler {
55+
func NewCodeHandlerWithLog(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), requiredMaster bool, writeLog func(context.Context, string, string, bool, string) error, options ...string) *Handler {
5656
var resource, action string
5757
if len(options) >= 1 && len(options[0]) > 0 {
5858
resource = options[0]
@@ -111,7 +111,7 @@ func respond(ctx echo.Context, code int, result interface{}, writeLog func(conte
111111
}
112112
return err
113113
}
114-
func respondError(ctx echo.Context, code int, result interface{}, logError func(context.Context, string), resource string, action string, err error, writeLog func(context.Context, string, string, bool, string) error) error {
114+
func respondError(ctx echo.Context, code int, result interface{}, logError func(context.Context, string, ...map[string]interface{}), resource string, action string, err error, writeLog func(context.Context, string, string, bool, string) error) error {
115115
if logError != nil {
116116
logError(ctx.Request().Context(), err.Error())
117117
}

gin/handler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ const internalServerError = "Internal Server Error"
1414
type Handler struct {
1515
Codes func(ctx context.Context, master string) ([]co.Model, error)
1616
RequiredMaster bool
17-
Error func(context.Context, string)
17+
Error func(context.Context, string, ...map[string]interface{})
1818
Log func(ctx context.Context, resource string, action string, success bool, desc string) error
1919
Resource string
2020
Action string
2121
Id string
2222
Name string
2323
}
2424

25-
func NewDefaultCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), options ...func(context.Context, string, string, bool, string) error) *Handler {
25+
func NewDefaultCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), options ...func(context.Context, string, string, bool, string) error) *Handler {
2626
var writeLog func(context.Context, string, string, bool, string) error
2727
if len(options) >= 1 {
2828
writeLog = options[0]
2929
}
3030
return NewCodeHandlerWithLog(load, logError, true, writeLog, "", "")
3131
}
32-
func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.Model, error), c co.HandlerConfig, logError func(context.Context, string), options ...func(context.Context, string, string, bool, string) error) *Handler {
32+
func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.Model, error), c co.HandlerConfig, logError func(context.Context, string, ...map[string]interface{}), options ...func(context.Context, string, string, bool, string) error) *Handler {
3333
var requireMaster bool
3434
if c.Master != nil {
3535
requireMaster = *c.Master
@@ -45,14 +45,14 @@ func NewCodeHandlerByConfig(load func(ctx context.Context, master string) ([]co.
4545
h.Name = c.Name
4646
return h
4747
}
48-
func NewCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), requiredMaster bool, options ...func(context.Context, string, string, bool, string) error) *Handler {
48+
func NewCodeHandler(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), requiredMaster bool, options ...func(context.Context, string, string, bool, string) error) *Handler {
4949
var writeLog func(context.Context, string, string, bool, string) error
5050
if len(options) >= 1 {
5151
writeLog = options[0]
5252
}
5353
return NewCodeHandlerWithLog(load, logError, requiredMaster, writeLog, "", "")
5454
}
55-
func NewCodeHandlerWithLog(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string), requiredMaster bool, writeLog func(context.Context, string, string, bool, string) error, options ...string) *Handler {
55+
func NewCodeHandlerWithLog(load func(ctx context.Context, master string) ([]co.Model, error), logError func(context.Context, string, ...map[string]interface{}), requiredMaster bool, writeLog func(context.Context, string, string, bool, string) error, options ...string) *Handler {
5656
var resource, action string
5757
if len(options) >= 1 && len(options[0]) > 0 {
5858
resource = options[0]
@@ -110,7 +110,7 @@ func respond(ctx *gin.Context, code int, result interface{}, writeLog func(conte
110110
writeLog(ctx.Request.Context(), resource, action, success, desc)
111111
}
112112
}
113-
func respondError(ctx *gin.Context, code int, result interface{}, logError func(context.Context, string), resource string, action string, err error, writeLog func(context.Context, string, string, bool, string) error) {
113+
func respondError(ctx *gin.Context, code int, result interface{}, logError func(context.Context, string, ...map[string]interface{}), resource string, action string, err error, writeLog func(context.Context, string, string, bool, string) error) {
114114
if logError != nil {
115115
logError(ctx.Request.Context(), err.Error())
116116
}

0 commit comments

Comments
 (0)