| 1 | package filesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 5 | "net/urlscip-go gomod github.com/golang/go/src go1.13 `net/url`/" |
| 6 | "stringsscip-go gomod github.com/golang/go/src go1.13 strings/" |
| 7 | |
| 8 | "github.com/tombuildsstuff/giovanni/storage/internal/endpointsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/endpoints`/" |
| 9 | ) |
| 10 | |
| 11 | // GetResourceID returns the Resource ID for the given File |
| 12 | // This can be useful when, for example, you're using this as a unique identifier |
| 13 | func (client Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/Client#) GetResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/Client#GetResourceID().(accountName, shareName, directoryName, filePath string) string { |
| 14 | domain := endpointsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/endpoints`/.GetFileEndpointscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/endpoints`/GetFileEndpoint().(client.BaseURIscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/Client#BaseURI., accountName) |
| 15 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%s/%s/%s/%s", domain, shareName, directoryName, filePath) |
| 16 | } |
| 17 | |
| 18 | type ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID# struct { |
| 19 | AccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#AccountName. string |
| 20 | DirectoryNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#DirectoryName. string |
| 21 | FileNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#FileName. string |
| 22 | ShareNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#ShareName. string |
| 23 | } |
| 24 | |
| 25 | // ParseResourceID parses the specified Resource ID and returns an object |
| 26 | // which can be used to interact with Files within a Storage Share. |
| 27 | func ParseResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ParseResourceID().(id string) (*ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#, error) { |
| 28 | // example: https://account1.file.core.chinacloudapi.cn/share1/directory1/file1.txt |
| 29 | // example: https://account1.file.core.chinacloudapi.cn/share1/directory1/directory2/file1.txt |
| 30 | |
| 31 | if id == "" { |
| 32 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("`id` was empty") |
| 33 | } |
| 34 | |
| 35 | uri, err := urlscip-go gomod github.com/golang/go/src go1.13 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.13 `net/url`/Parse().(id) |
| 36 | if err != nil { |
| 37 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Error parsing ID as a URL: %s", err) |
| 38 | } |
| 39 | |
| 40 | accountName, err := endpointsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/endpoints`/.GetAccountNameFromEndpointscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/endpoints`/GetAccountNameFromEndpoint().(uri.Hostscip-go gomod github.com/golang/go/src go1.13 `net/url`/URL#Host.) |
| 41 | if err != nil { |
| 42 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Error parsing Account Name: %s", err) |
| 43 | } |
| 44 | |
| 45 | path := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.13 strings/TrimPrefix().(uri.Pathscip-go gomod github.com/golang/go/src go1.13 `net/url`/URL#Path., "/") |
| 46 | segments := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Splitscip-go gomod github.com/golang/go/src go1.13 strings/Split().(path, "/") |
| 47 | if len(segments) == 0 { |
| 48 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Expected the path to contain segments but got none") |
| 49 | } |
| 50 | |
| 51 | shareName := segments[0] |
| 52 | fileName := segments[len(segments)-1] |
| 53 | |
| 54 | directoryName := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.13 strings/TrimPrefix().(path, shareName) |
| 55 | directoryName = stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.13 strings/TrimPrefix().(directoryName, "/") |
| 56 | directoryName = stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.13 strings/TrimSuffix().(directoryName, fileName) |
| 57 | directoryName = stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.13 strings/TrimSuffix().(directoryName, "/") |
| 58 | return &ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#{ |
| 59 | AccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#AccountName.: *accountName, |
| 60 | ShareNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#ShareName.: shareName, |
| 61 | DirectoryNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#DirectoryName.: directoryName, |
| 62 | FileNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/file/files`/ResourceID#FileName.: fileName, |
| 63 | }, nil |
| 64 | } |