MCPcopy Create free account
hub / github.com/bep/s3deploy / determineRootAndSubPath

Method determineRootAndSubPath

lib/cloudfront.go:134–156  ·  view source on GitHub ↗

determineRootAndSubPath takes the bucketPath, as set as a flag, and the originPath, as set in the CDN config, and determines the web context root and the sub path below this context.

(bucketPath, originPath string)

Source from the content-addressed store, hash-verified

132// and the originPath, as set in the CDN config, and
133// determines the web context root and the sub path below this context.
134func (c *cloudFrontClient) determineRootAndSubPath(bucketPath, originPath string) (webContextRoot string, subPath string) {
135 if bucketPath == "" && originPath == "" {
136 panic("one of bucketPath or originPath must be set")
137 }
138 bucketPath = strings.Trim(bucketPath, "/")
139 originPath = strings.Trim(originPath, "/")
140
141 webContextRoot = strings.TrimPrefix(bucketPath, originPath)
142 if webContextRoot == "" {
143 webContextRoot = "/"
144 }
145
146 if originPath != bucketPath {
147 // If the bucket path is a prefix of the origin, these resources
148 // are served from a sub path, e.g. https://example.com/foo.
149 subPath = strings.TrimPrefix(originPath, bucketPath)
150 } else {
151 // Served from the root.
152 subPath = bucketPath
153 }
154
155 return
156}
157
158// For path rules, see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html
159func (c *cloudFrontClient) normalizeInvalidationPaths(

Callers 2

InvalidateCDNCacheMethod · 0.95

Calls

no outgoing calls

Tested by 1