79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package accounts
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type (
|
|
Platform string
|
|
)
|
|
|
|
const (
|
|
Etsy Platform = "Etsy"
|
|
Tiktok Platform = "Tiktok"
|
|
Wix Platform = "Wix"
|
|
Ebay Platform = "ebay"
|
|
WalmartMarketplace Platform = "walmart_marketplace"
|
|
Amazon Platform = "amazon"
|
|
BigCartel Platform = "big_cartel"
|
|
Ecwid Platform = "ecwid"
|
|
Zoho Platform = "zoho"
|
|
SquareOnline Platform = "square_online"
|
|
Squarespace Platform = "squarespace"
|
|
WooCommerce Platform = "woo_commerce"
|
|
Shopify Platform = "shopify"
|
|
)
|
|
|
|
var (
|
|
allValues = []Platform{
|
|
Etsy,
|
|
Tiktok,
|
|
Wix,
|
|
Ebay,
|
|
WalmartMarketplace,
|
|
Amazon,
|
|
BigCartel,
|
|
Ecwid,
|
|
Zoho,
|
|
SquareOnline,
|
|
Squarespace,
|
|
WooCommerce,
|
|
Shopify,
|
|
}
|
|
)
|
|
|
|
func NewPlatform(s string) (Platform, error) {
|
|
for _, v := range allValues {
|
|
if strings.ToLower(s) == strings.ToLower(string(v)) {
|
|
return v, nil
|
|
}
|
|
}
|
|
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
|
|
}
|