mirror of https://github.com/dmarkham/enumer.git
feat: do not ignore errors in sql and yaml
This commit is contained in:
parent
3a35ba062e
commit
17bbb5dc07
11
enumer.go
11
enumer.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const stringNameToValueMethod = `// %[1]sString retrieves an enum value from the enum constants string name.
|
const stringNameToValueMethod = `// %[1]sString retrieves an enum value from the enum constants string name.
|
||||||
// Throws an error if the param is not part of the enum.
|
// Throws an error if the param is not part of the enum.
|
||||||
|
@ -19,6 +20,7 @@ func %[1]sString(s string) (%[1]s, error) {
|
||||||
`
|
`
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const stringValuesMethod = `// %[1]sValues returns all values of the enum
|
const stringValuesMethod = `// %[1]sValues returns all values of the enum
|
||||||
func %[1]sValues() []%[1]s {
|
func %[1]sValues() []%[1]s {
|
||||||
|
@ -27,6 +29,7 @@ func %[1]sValues() []%[1]s {
|
||||||
`
|
`
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const stringsMethod = `// %[1]sStrings returns a slice of all String values of the enum
|
const stringsMethod = `// %[1]sStrings returns a slice of all String values of the enum
|
||||||
func %[1]sStrings() []string {
|
func %[1]sStrings() []string {
|
||||||
|
@ -37,6 +40,7 @@ func %[1]sStrings() []string {
|
||||||
`
|
`
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const stringBelongsMethodLoop = `// IsA%[1]s returns "true" if the value is listed in the enum definition. "false" otherwise
|
const stringBelongsMethodLoop = `// IsA%[1]s returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
func (i %[1]s) IsA%[1]s() bool {
|
func (i %[1]s) IsA%[1]s() bool {
|
||||||
|
@ -50,6 +54,7 @@ func (i %[1]s) IsA%[1]s() bool {
|
||||||
`
|
`
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const stringBelongsMethodSet = `// IsA%[1]s returns "true" if the value is listed in the enum definition. "false" otherwise
|
const stringBelongsMethodSet = `// IsA%[1]s returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
func (i %[1]s) IsA%[1]s() bool {
|
func (i %[1]s) IsA%[1]s() bool {
|
||||||
|
@ -59,6 +64,7 @@ func (i %[1]s) IsA%[1]s() bool {
|
||||||
`
|
`
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const altStringValuesMethod = `func (%[1]s) Values() []string {
|
const altStringValuesMethod = `func (%[1]s) Values() []string {
|
||||||
return %[1]sStrings()
|
return %[1]sStrings()
|
||||||
|
@ -144,6 +150,7 @@ func (g *Generator) printNamesSlice(runs [][]Value, typeName string, runsThresho
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const jsonMethods = `
|
const jsonMethods = `
|
||||||
// MarshalJSON implements the json.Marshaler interface for %[1]s
|
// MarshalJSON implements the json.Marshaler interface for %[1]s
|
||||||
|
@ -169,6 +176,7 @@ func (g *Generator) buildJSONMethods(runs [][]Value, typeName string, runsThresh
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const textMethods = `
|
const textMethods = `
|
||||||
// MarshalText implements the encoding.TextMarshaler interface for %[1]s
|
// MarshalText implements the encoding.TextMarshaler interface for %[1]s
|
||||||
|
@ -189,11 +197,12 @@ func (g *Generator) buildTextMethods(runs [][]Value, typeName string, runsThresh
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const yamlMethods = `
|
const yamlMethods = `
|
||||||
// MarshalYAML implements a YAML Marshaler for %[1]s
|
// MarshalYAML implements a YAML Marshaler for %[1]s
|
||||||
func (i %[1]s) MarshalYAML() (interface{}, error) {
|
func (i %[1]s) MarshalYAML() (interface{}, error) {
|
||||||
return i.String(), nil
|
return i.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalYAML implements a YAML Unmarshaler for %[1]s
|
// UnmarshalYAML implements a YAML Unmarshaler for %[1]s
|
||||||
|
|
3
sql.go
3
sql.go
|
@ -1,9 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
|
//
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const valueMethod = `func (i %[1]s) Value() (driver.Value, error) {
|
const valueMethod = `func (i %[1]s) Value() (driver.Value, error) {
|
||||||
return i.String(), nil
|
return i.string()
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue