mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Remove -camel_case_functions flag and generate CamelCase function names by default.
This commit is contained in:
@@ -22,13 +22,11 @@ generate: root build
|
||||
.root/src/$(PKG)/tests/data.go \
|
||||
.root/src/$(PKG)/tests/omitempty.go \
|
||||
.root/src/$(PKG)/tests/nothing.go \
|
||||
.root/src/$(PKG)/tests/camel_case_functions.go
|
||||
|
||||
.root/bin/easyjson -all .root/src/$(PKG)/tests/data.go
|
||||
.root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go
|
||||
.root/bin/easyjson -snake_case .root/src/$(PKG)/tests/snake.go
|
||||
.root/bin/easyjson -omit_empty .root/src/$(PKG)/tests/omitempty.go
|
||||
.root/bin/easyjson -camel_case_functions .root/src/$(PKG)/tests/camel_case_functions.go
|
||||
.root/bin/easyjson -build_tags=use_easyjson .root/src/$(PKG)/benchmark/data.go
|
||||
|
||||
test: generate root
|
||||
|
||||
@@ -31,8 +31,6 @@ Usage of .root/bin/easyjson:
|
||||
use snake_case names instead of CamelCase by default
|
||||
-stubs
|
||||
only generate stubs for marshallers/unmarshallers methods
|
||||
-camel_case_functions
|
||||
generate functions with CamelCase names instead of under_score by default
|
||||
```
|
||||
|
||||
Using `-all` will generate (un-)marshallers for all structs in the file. By default, structs need to have a line beginning with `easyjson:json` in their docstring, e.g.:
|
||||
|
||||
@@ -21,10 +21,9 @@ type Generator struct {
|
||||
PkgPath, PkgName string
|
||||
Types []string
|
||||
|
||||
NoStdMarshalers bool
|
||||
SnakeCaseFields bool
|
||||
CamelCaseFunctions bool
|
||||
OmitEmpty bool
|
||||
NoStdMarshalers bool
|
||||
SnakeCaseFields bool
|
||||
OmitEmpty bool
|
||||
|
||||
OutName string
|
||||
BuildTags string
|
||||
@@ -109,9 +108,6 @@ func (g *Generator) writeMain() (path string, err error) {
|
||||
if g.SnakeCaseFields {
|
||||
fmt.Fprintln(f, " g.UseSnakeCaseFieldNamer()")
|
||||
}
|
||||
if g.CamelCaseFunctions {
|
||||
fmt.Fprintln(f, " g.UseCamelCaseFunctionNamer()")
|
||||
}
|
||||
if g.OmitEmpty {
|
||||
fmt.Fprintln(f, " g.OmitEmpty()")
|
||||
}
|
||||
|
||||
+11
-13
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
var buildTags = flag.String("build_tags", "", "build tags to add to generated file")
|
||||
var snakeCaseFields = flag.Bool("snake_case", false, "use snake_case names instead of CamelCase by default")
|
||||
var camelCaseFunctions = flag.Bool("camel_case_functions", false, "generate functions with CamelCase names instead of under_score by default")
|
||||
var noStdMarshalers = flag.Bool("no_std_marshalers", false, "don't generate MarshalJSON/UnmarshalJSON methods")
|
||||
var omitEmpty = flag.Bool("omit_empty", false, "omit empty fields by default")
|
||||
var allStructs = flag.Bool("all", false, "generate un-/marshallers for all structs in a file")
|
||||
@@ -43,18 +42,17 @@ func generate(fname string) (err error) {
|
||||
}
|
||||
|
||||
g := bootstrap.Generator{
|
||||
BuildTags: *buildTags,
|
||||
PkgPath: p.PkgPath,
|
||||
PkgName: p.PkgName,
|
||||
Types: p.StructNames,
|
||||
SnakeCaseFields: *snakeCaseFields,
|
||||
CamelCaseFunctions: *camelCaseFunctions,
|
||||
NoStdMarshalers: *noStdMarshalers,
|
||||
OmitEmpty: *omitEmpty,
|
||||
LeaveTemps: *leaveTemps,
|
||||
OutName: outName,
|
||||
StubsOnly: *stubs,
|
||||
NoFormat: *noformat,
|
||||
BuildTags: *buildTags,
|
||||
PkgPath: p.PkgPath,
|
||||
PkgName: p.PkgName,
|
||||
Types: p.StructNames,
|
||||
SnakeCaseFields: *snakeCaseFields,
|
||||
NoStdMarshalers: *noStdMarshalers,
|
||||
OmitEmpty: *omitEmpty,
|
||||
LeaveTemps: *leaveTemps,
|
||||
OutName: outName,
|
||||
StubsOnly: *stubs,
|
||||
NoFormat: *noformat,
|
||||
}
|
||||
|
||||
if err := g.Run(); err != nil {
|
||||
|
||||
+1
-19
@@ -67,8 +67,7 @@ func NewGenerator(filename string) *Generator {
|
||||
"encoding/json": "json",
|
||||
},
|
||||
fieldNamer: DefaultFieldNamer{},
|
||||
functionNamer: UnderScoreFunctionNamer{},
|
||||
//functionNamer: CamelCaseFunctionNamer{},
|
||||
functionNamer: CamelCaseFunctionNamer{},
|
||||
marshallers: make(map[reflect.Type]bool),
|
||||
typesSeen: make(map[reflect.Type]bool),
|
||||
functionNames: make(map[string]reflect.Type),
|
||||
@@ -104,16 +103,6 @@ func (g *Generator) UseSnakeCaseFieldNamer() {
|
||||
g.fieldNamer = SnakeCaseFieldNamer{}
|
||||
}
|
||||
|
||||
// SetFunctionNamer sets function naming strategy.
|
||||
func (g *Generator) SetFunctionNamer(n FunctionNamer) {
|
||||
g.functionNamer = n
|
||||
}
|
||||
|
||||
// UseCamelCaseFunctionNamer sets CamelCase function naming strategy.
|
||||
func (g *Generator) UseCamelCaseFunctionNamer() {
|
||||
g.functionNamer = CamelCaseFunctionNamer{}
|
||||
}
|
||||
|
||||
// NoStdMarshalers instructs not to generate standard MarshalJSON/UnmarshalJSON
|
||||
// methods (only the custom interface).
|
||||
func (g *Generator) NoStdMarshalers() {
|
||||
@@ -414,10 +403,3 @@ func (CamelCaseFunctionNamer) GetName(keepFirst bool, parts ...string) string {
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// UnderScoreFunctionNamer implements FunctionNamer interface with under_score format
|
||||
type UnderScoreFunctionNamer struct{}
|
||||
|
||||
func (UnderScoreFunctionNamer) GetName(keepFirst bool, parts ...string) string {
|
||||
return strings.Join(parts, "_")
|
||||
}
|
||||
|
||||
@@ -55,13 +55,3 @@ func TestCamelCaseFunctionNamer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnderScoreFunctionNamer(t *testing.T) {
|
||||
namer := UnderScoreFunctionNamer{}
|
||||
for i, test := range getFunctionNamerCases() {
|
||||
got := namer.GetName(test.keepFirst, test.parts...)
|
||||
if got != test.underScoreOut {
|
||||
t.Errorf("[%d] UnderScoreFunctionNamer.GetName(%v) = %s; want %s", i, test.parts, got, test.underScoreOut)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ var testCases = []struct {
|
||||
{&mapsValue, mapsString},
|
||||
{&deepNestValue, deepNestString},
|
||||
{&IntsValue, IntsString},
|
||||
{&camelCasesFunctionsValue, camelCasesFunctionsString},
|
||||
}
|
||||
|
||||
func TestMarshal(t *testing.T) {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package tests
|
||||
|
||||
//easyjson:json
|
||||
type CamelCasesFunctions struct {
|
||||
Field string
|
||||
}
|
||||
|
||||
var camelCasesFunctionsValue = CamelCasesFunctions{Field: "test"}
|
||||
var camelCasesFunctionsString = `{"Field":"test"}`
|
||||
Reference in New Issue
Block a user