forked from getconversio/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
41 lines (36 loc) · 1.04 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package goshopify
import (
"fmt"
"strings"
)
// Return the full shop name, including .myshopify.com
func ShopFullName(name string) string {
name = strings.TrimSpace(name)
name = strings.Trim(name, ".")
if strings.Contains(name, "myshopify.com") {
return name
}
return name + ".myshopify.com"
}
// Return the short shop name, excluding .myshopify.com
func ShopShortName(name string) string {
// Convert to fullname and remove the myshopify part. Perhaps not the most
// performant solution, but then we don't have to repeat all the trims here
// :-)
return strings.Replace(ShopFullName(name), ".myshopify.com", "", -1)
}
// Return the Shop's base url.
func ShopBaseUrl(name string) string {
name = ShopFullName(name)
return fmt.Sprintf("https://%s", name)
}
// Return the prefix for a metafield path
func MetafieldPathPrefix(resource string, resourceID int) string {
var prefix string
if resource == "" {
prefix = fmt.Sprintf("admin/metafields")
} else {
prefix = fmt.Sprintf("admin/%s/%d/metafields", resource, resourceID)
}
return prefix
}