github.com/tsmith1024/pop@v4.12.2+incompatible/genny/model/_fixtures/models/widget_xml.go (about) 1 package models 2 3 import ( 4 "encoding/xml" 5 "time" 6 7 "github.com/gobuffalo/nulls" 8 "github.com/gobuffalo/pop" 9 "github.com/gobuffalo/validate" 10 "github.com/gobuffalo/validate/validators" 11 "github.com/gofrs/uuid" 12 ) 13 14 type Widget struct { 15 ID uuid.UUID `xml:"id" db:"id"` 16 CreatedAt time.Time `xml:"created_at" db:"created_at"` 17 UpdatedAt time.Time `xml:"updated_at" db:"updated_at"` 18 Name string `xml:"name" db:"name"` 19 Description string `xml:"description" db:"description"` 20 Age int `xml:"age" db:"age"` 21 Bar nulls.String `xml:"bar" db:"bar"` 22 } 23 24 // String is not required by pop and may be deleted 25 func (w Widget) String() string { 26 xw, _ := xml.Marshal(w) 27 return string(xw) 28 } 29 30 // Widgets is not required by pop and may be deleted 31 type Widgets []Widget 32 33 // String is not required by pop and may be deleted 34 func (w Widgets) String() string { 35 xw, _ := xml.Marshal(w) 36 return string(xw) 37 } 38 39 // Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. 40 // This method is not required and may be deleted. 41 func (w *Widget) Validate(tx *pop.Connection) (*validate.Errors, error) { 42 return validate.Validate( 43 &validators.StringIsPresent{Field: w.Name, Name: "Name"}, 44 &validators.StringIsPresent{Field: w.Description, Name: "Description"}, 45 &validators.IntIsPresent{Field: w.Age, Name: "Age"}, 46 ), nil 47 } 48 49 // ValidateCreate gets run every time you call "pop.ValidateAndCreate" method. 50 // This method is not required and may be deleted. 51 func (w *Widget) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) { 52 return validate.NewErrors(), nil 53 } 54 55 // ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method. 56 // This method is not required and may be deleted. 57 func (w *Widget) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) { 58 return validate.NewErrors(), nil 59 }