package accounts import ( "fmt" "strings" ) type ( Platform string ) const ( Etsy Platform = "Etsy" Tiktok Platform = "Tiktok" Wix Platform = "Wix" ) func NewPlatform(s string) (Platform, error) { switch strings.ToLower(s) { case strings.ToLower(string(Etsy)): return Etsy, nil case strings.ToLower(string(Tiktok)): return Tiktok, nil case strings.ToLower(string(Wix)): return Wix, nil default: return "", fmt.Errorf("unrecognized constant: %q", s) } } // sql.Scanner implementation func (p *Platform) Scan(src any) error { var s string switch v := src.(type) { case string: s = v case byte: s = string(v) default: return fmt.Errorf("unsupported type: %T: %v", src, src) } dst, err := NewPlatform(s) if err == nil { *p = dst } return err } // sql/driver.Valuer implementation func (p Platform) Value() (any, error) { return string(p), nil }