forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
48 lines (42 loc) · 1.24 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
42
43
44
45
46
47
48
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 int64) string {
prefix := "metafields"
if resource != "" {
prefix = fmt.Sprintf("%s/%d/metafields", resource, resourceID)
}
return prefix
}
// Return the prefix for a fulfillment path
func FulfillmentPathPrefix(resource string, resourceID int64) string {
prefix := "fulfillments"
if resource != "" {
prefix = fmt.Sprintf("%s/%d/fulfillments", resource, resourceID)
}
return prefix
}