forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
54 lines (45 loc) · 1.52 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
49
50
51
52
53
54
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 an order path
func OrderPathPrefix(prefix string, resource string, resourceID int64) string {
if resource != "" {
return fmt.Sprintf("%s/%d/%s", resource, resourceID, prefix)
}
return prefix
}
// Return the prefix for a metafield path
func MetafieldPathPrefix(resource string, resourceID int64) string {
return OrderPathPrefix("metafields", resource, resourceID)
}
// Return the prefix for a fulfillment path
func FulfillmentPathPrefix(resource string, resourceID int64) string {
return OrderPathPrefix("fulfillments", resource, resourceID)
}
// Return the prefix for a fulfillment order path
func FulfillmentOrderPathPrefix(resource string, resourceID int64) string {
return OrderPathPrefix("fulfillment_orders", resource, resourceID)
}