removed intermediate /internal directory
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
Platform string
|
||||
)
|
||||
|
||||
const (
|
||||
Amazon Platform = "amazon"
|
||||
BigCartel Platform = "big_cartel"
|
||||
Ebay Platform = "ebay"
|
||||
Ecwid Platform = "ecwid"
|
||||
Etsy Platform = "Etsy"
|
||||
Shopify Platform = "shopify"
|
||||
SquareOnline Platform = "square_online"
|
||||
Squarespace Platform = "squarespace"
|
||||
Tiktok Platform = "Tiktok"
|
||||
WalmartMarketplace Platform = "walmart_marketplace"
|
||||
Wix Platform = "Wix"
|
||||
WooCommerce Platform = "woo_commerce"
|
||||
Zoho Platform = "zoho"
|
||||
)
|
||||
|
||||
var (
|
||||
allPlatforms = []Platform{
|
||||
Amazon,
|
||||
BigCartel,
|
||||
Ebay,
|
||||
Ecwid,
|
||||
Etsy,
|
||||
Shopify,
|
||||
SquareOnline,
|
||||
Squarespace,
|
||||
Tiktok,
|
||||
WalmartMarketplace,
|
||||
Wix,
|
||||
WooCommerce,
|
||||
Zoho,
|
||||
}
|
||||
)
|
||||
|
||||
func NewPlatform(s string) (Platform, error) {
|
||||
for _, v := range allPlatforms {
|
||||
if strings.ToLower(s) == strings.ToLower(string(v)) {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("unrecognized constant: %q", s)
|
||||
}
|
||||
|
||||
func (p Platform) PrettyPrint() string {
|
||||
switch p {
|
||||
case Etsy:
|
||||
return "Etsy"
|
||||
case Tiktok:
|
||||
return "Tiktok"
|
||||
case Wix:
|
||||
return "Wix"
|
||||
case Ebay:
|
||||
return "Ebay"
|
||||
case WalmartMarketplace:
|
||||
return "Walmart Marketplace"
|
||||
case Amazon:
|
||||
return "Amazon"
|
||||
case BigCartel:
|
||||
return "Big Cartel"
|
||||
case Ecwid:
|
||||
return "Ecwid"
|
||||
case Zoho:
|
||||
return "Zoho"
|
||||
case SquareOnline:
|
||||
return "Square Online"
|
||||
case Squarespace:
|
||||
return "Squarespace"
|
||||
case WooCommerce:
|
||||
return "Woo Commerce"
|
||||
case Shopify:
|
||||
return "Shopify"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user