forked from mirror/go-json
Refactor
This commit is contained in:
parent
2356c0ceab
commit
e372b3498c
|
@ -23,8 +23,6 @@ type opType struct {
|
|||
HeadToStringTagHead func() string
|
||||
PtrHeadToHead func() string
|
||||
FieldToEnd func() string
|
||||
FieldToOmitEmptyEnd func() string
|
||||
FieldToStringTagEnd func() string
|
||||
FieldToOmitEmptyField func() string
|
||||
FieldToStringTagField func() string
|
||||
}
|
||||
|
@ -42,8 +40,6 @@ func createOpType(op, code string) opType {
|
|||
HeadToStringTagHead: func() string { return op },
|
||||
PtrHeadToHead: func() string { return op },
|
||||
FieldToEnd: func() string { return op },
|
||||
FieldToOmitEmptyEnd: func() string { return op },
|
||||
FieldToStringTagEnd: func() string { return op },
|
||||
FieldToOmitEmptyField: func() string { return op },
|
||||
FieldToStringTagField: func() string { return op },
|
||||
}
|
||||
|
@ -179,26 +175,6 @@ func (t opType) fieldToEnd() opType {
|
|||
return t
|
||||
}
|
||||
|
||||
func (t opType) fieldToOmitEmptyEnd() opType {
|
||||
switch t {
|
||||
{{- range $type := .OpTypes }}
|
||||
case op{{ $type.Op }}:
|
||||
return op{{ call $type.FieldToOmitEmptyEnd }}
|
||||
{{- end }}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t opType) fieldToStringTagEnd() opType {
|
||||
switch t {
|
||||
{{- range $type := .OpTypes }}
|
||||
case op{{ $type.Op }}:
|
||||
return op{{ call $type.FieldToStringTagEnd }}
|
||||
{{- end }}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t opType) fieldToOmitEmptyField() opType {
|
||||
switch t {
|
||||
{{- range $type := .OpTypes }}
|
||||
|
@ -385,8 +361,6 @@ func (t opType) fieldToStringTagField() opType {
|
|||
)
|
||||
},
|
||||
FieldToEnd: func() string { return op },
|
||||
FieldToOmitEmptyEnd: func() string { return op },
|
||||
FieldToStringTagEnd: func() string { return op },
|
||||
FieldToOmitEmptyField: func() string { return op },
|
||||
FieldToStringTagField: func() string { return op },
|
||||
})
|
||||
|
@ -445,28 +419,6 @@ func (t opType) fieldToStringTagField() opType {
|
|||
typ,
|
||||
)
|
||||
},
|
||||
FieldToOmitEmptyEnd: func() string {
|
||||
switch typ {
|
||||
case "Array", "Map", "MapLoad", "Slice", "Struct", "Recursive":
|
||||
return op
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"Struct%sEndOmitEmpty%s",
|
||||
escapedOrNot,
|
||||
typ,
|
||||
)
|
||||
},
|
||||
FieldToStringTagEnd: func() string {
|
||||
switch typ {
|
||||
case "Array", "Map", "MapLoad", "Slice", "Struct", "Recursive":
|
||||
return op
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"Struct%sEndStringTag%s",
|
||||
escapedOrNot,
|
||||
typ,
|
||||
)
|
||||
},
|
||||
FieldToOmitEmptyField: func() string {
|
||||
return fmt.Sprintf(
|
||||
"Struct%sFieldOmitEmpty%s",
|
||||
|
@ -524,8 +476,6 @@ func (t opType) fieldToStringTagField() opType {
|
|||
HeadToStringTagHead: func() string { return op },
|
||||
PtrHeadToHead: func() string { return op },
|
||||
FieldToEnd: func() string { return op },
|
||||
FieldToOmitEmptyEnd: func() string { return op },
|
||||
FieldToStringTagEnd: func() string { return op },
|
||||
FieldToOmitEmptyField: func() string { return op },
|
||||
FieldToStringTagField: func() string { return op },
|
||||
})
|
||||
|
@ -567,12 +517,6 @@ func (t opType) fieldToStringTagField() opType {
|
|||
FieldToEnd: func() string {
|
||||
return fmt.Sprintf("%sIndent", typ.FieldToEnd())
|
||||
},
|
||||
FieldToOmitEmptyEnd: func() string {
|
||||
return fmt.Sprintf("%sIndent", typ.FieldToOmitEmptyEnd())
|
||||
},
|
||||
FieldToStringTagEnd: func() string {
|
||||
return fmt.Sprintf("%sIndent", typ.FieldToStringTagEnd())
|
||||
},
|
||||
})
|
||||
}
|
||||
var b bytes.Buffer
|
||||
|
|
26428
encode_optype.go
26428
encode_optype.go
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue