package main import ( "strings" "time" "errors" "gorm.io/gorm" ) type Contact struct { gorm.Model Firstname string Lastname string Association string Job string Emails []EmailAddress PhoneNumbers []PhoneNumber Urls []URL StreetAddresses []StreetAddress Dates []Date Other []OtherField Notes string } func (contact Contact) Validate() error { if len(strings.TrimSpace(contact.Firstname)) == 0 && len(strings.TrimSpace(contact.Lastname)) == 0 { return errors.New("Not a valid name") } return nil } func (app *App) GetUserContact() Contact { return app.UserContact } func (app *App) SaveContact(contact Contact) error { if err := contact.Validate(); err != nil { return err } if contact.ID == 1 { app.UserContact = contact } return app.DB.Save(&contact).Error } type EmailAddress struct { gorm.Model ContactID uint Key string Value string } type PhoneNumber struct { gorm.Model ContactID uint Key string Value string } type URL struct { gorm.Model ContactID uint Key string Value string } type StreetAddress struct { gorm.Model ContactID uint Key string Street1 string Street2 string City string State string ZipCode string Country string } type Date struct { gorm.Model ContactID uint Key string Value time.Time } type OtherField struct { gorm.Model ContactID uint Key string Value string }