gotygen/pkg/document/field.go

29 lines
460 B
Go

package document
import (
"fmt"
"strings"
)
type Field struct {
Name string
Type Type
// Json tag params
Key string
OmitEmpty bool
}
func (f *Field) String() string {
return fmt.Sprintf("%s %s `json:\"%s\"`", f.Name, f.Type, f.Options())
}
func (f *Field) Options() string {
options := make([]string, 0, 3)
options = append(options, f.Key)
if f.OmitEmpty {
options = append(options, "omitempty")
}
return strings.Join(options, ",")
}