Debian Codegraph @

storage/2017-07-29/table/tables/resource_id.go

raw symbols SCIP
1 package tablesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/
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 Table
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/table/tables`/Client#) GetResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/Client#GetResourceID().(accountName, tableName string) string {
14 domain := endpointsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/endpoints`/.GetTableEndpointscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/endpoints`/GetTableEndpoint().(client.BaseURIscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/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/Tables('%s')", domain, tableName)
16 }
17
18 type ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/ResourceID# struct {
19 AccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/ResourceID#AccountName. string
20 TableNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/ResourceID#TableName. string
21 }
22
23 // ParseResourceID parses the Resource ID and returns an object which
24 // can be used to interact with the Table within the specified Storage Account
25 func ParseResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/ParseResourceID().(id string) (*ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/ResourceID#, error) {
26 // example: https://foo.table.core.windows.net/Table('foo')
27 if id == "" {
28 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")
29 }
30
31 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)
32 if err != nil {
33 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)
34 }
35
36 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.)
37 if err != nil {
38 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)
39 }
40
41 // assume there a `Table('')`
42 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., "/")
43 if !stringsscip-go gomod github.com/golang/go/src go1.13 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.13 strings/HasPrefix().(path, "Tables('") || !stringsscip-go gomod github.com/golang/go/src go1.13 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.13 strings/HasSuffix().(path, "')") {
44 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 Table Name to be in the format `Tables('name')` but got %q", path)
45 }
46
47 // strip off the `Table('')`
48 tableName := 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., "/Tables('")
49 tableName = stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.13 strings/TrimSuffix().(tableName, "')")
50 return &ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/ResourceID#{
51 AccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/ResourceID#AccountName.: *accountName,
52 TableNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2017-07-29/table/tables`/ResourceID#TableName.: tableName,
53 }, nil
54 }