mirror of https://github.com/dmarkham/enumer.git
34 lines
605 B
Go
34 lines
605 B
Go
package main
|
|
|
|
// Arguments to format are:
|
|
// [1]: type name
|
|
const valuer = `func (i %[1]s) Value() (driver.Value, error) {
|
|
return i.String(), nil
|
|
}
|
|
`
|
|
|
|
const scanner = `func (i %[1]s) Scan(value interface{}) error {
|
|
bytes, ok := value.([]byte)
|
|
if !ok {
|
|
fmt.Errorf("value is not a byte slice")
|
|
}
|
|
|
|
str := string(bytes[:])
|
|
|
|
val, err := %[1]sString(str)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
i = val
|
|
return nil
|
|
}
|
|
`
|
|
|
|
func (g *Generator) addValuerAndScanner(runs [][]Value, typeName string, runsThreshold int) {
|
|
g.Printf("\n")
|
|
g.Printf(valuer, typeName)
|
|
g.Printf("\n\n")
|
|
g.Printf(scanner, typeName)
|
|
}
|