github.com/reggieriser/pop@v4.13.1+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  // Widget is used by pop to map your widgets database table to your go code.
    15  type Widget struct {
    16  	ID          uuid.UUID    `xml:"id" db:"id"`
    17  	CreatedAt   time.Time    `xml:"created_at" db:"created_at"`
    18  	UpdatedAt   time.Time    `xml:"updated_at" db:"updated_at"`
    19  	Name        string       `xml:"name" db:"name"`
    20  	Description string       `xml:"description" db:"description"`
    21  	Age         int          `xml:"age" db:"age"`
    22  	Bar         nulls.String `xml:"bar" db:"bar"`
    23  }
    24  
    25  // String is not required by pop and may be deleted
    26  func (w Widget) String() string {
    27  	xw, _ := xml.Marshal(w)
    28  	return string(xw)
    29  }
    30  
    31  // Widgets is not required by pop and may be deleted
    32  type Widgets []Widget
    33  
    34  // String is not required by pop and may be deleted
    35  func (w Widgets) String() string {
    36  	xw, _ := xml.Marshal(w)
    37  	return string(xw)
    38  }
    39  
    40  // Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
    41  // This method is not required and may be deleted.
    42  func (w *Widget) Validate(tx *pop.Connection) (*validate.Errors, error) {
    43  	return validate.Validate(
    44  		&validators.StringIsPresent{Field: w.Name, Name: "Name"},
    45  		&validators.StringIsPresent{Field: w.Description, Name: "Description"},
    46  		&validators.IntIsPresent{Field: w.Age, Name: "Age"},
    47  	), nil
    48  }
    49  
    50  // ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
    51  // This method is not required and may be deleted.
    52  func (w *Widget) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) {
    53  	return validate.NewErrors(), nil
    54  }
    55  
    56  // ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method.
    57  // This method is not required and may be deleted.
    58  func (w *Widget) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
    59  	return validate.NewErrors(), nil
    60  }