Debian Codegraph @

storage/2018-11-09/table/entities/resource_id.go

raw symbols SCIP
1 package entitiesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/
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 Entity
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/2018-11-09/table/entities`/Client#) GetResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/Client#GetResourceID().(accountName, tableName, partitionKey, rowKey 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/2018-11-09/table/entities`/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(PartitionKey='%s',RowKey='%s')", domain, tableName, partitionKey, rowKey)
16 }
17
18 type ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID# struct {
19 AccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#AccountName. string
20 TableNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#TableName. string
21 PartitionKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#PartitionKey. string
22 RowKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#RowKey. string
23 }
24
25 // ParseResourceID parses the specified Resource ID and returns an object which
26 // can be used to look up the specified Entity within the specified Table
27 func ParseResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ParseResourceID().(id string) (*ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#, error) {
28 // example: https://account1.table.core.chinacloudapi.cn/table1(PartitionKey='partition1',RowKey='row1')
29 if id == "" {
30 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")
31 }
32
33 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)
34 if err != nil {
35 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)
36 }
37
38 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.)
39 if err != nil {
40 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)
41 }
42
43 // assume there a `Table('')`
44 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., "/")
45 if !stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Containsscip-go gomod github.com/golang/go/src go1.13 strings/Contains().(uri.Pathscip-go gomod github.com/golang/go/src go1.13 `net/url`/URL#Path., "(") || !stringsscip-go gomod github.com/golang/go/src go1.13 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.13 strings/HasSuffix().(uri.Pathscip-go gomod github.com/golang/go/src go1.13 `net/url`/URL#Path., ")") {
46 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(PartitionKey='',RowKey='')` but got %q", path)
47 }
48
49 // NOTE: honestly this could probably be a RegEx, but this seemed like the simplest way to
50 // allow these two fields to be specified in either order
51 indexOfBracket := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.13 strings/IndexByte().(path, '(')
52 tableName := path[0:indexOfBracket]
53
54 // trim off the brackets
55 temp := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.13 strings/TrimPrefix().(path, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%s(", tableName))
56 temp = stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.13 strings/TrimSuffix().(temp, ")")
57
58 dictionary := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Splitscip-go gomod github.com/golang/go/src go1.13 strings/Split().(temp, ",")
59 partitionKey := ""
60 rowKey := ""
61 for _, v := range dictionary {
62 split := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Splitscip-go gomod github.com/golang/go/src go1.13 strings/Split().(v, "=")
63 if len(split) != 2 {
64 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 2 segments but got %d for %q", len(split), v)
65 }
66
67 key := split[0]
68 value := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.13 strings/TrimSuffix().(stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.13 strings/TrimPrefix().(split[1], "'"), "'")
69 if stringsscip-go gomod github.com/golang/go/src go1.13 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.13 strings/EqualFold().(key, "PartitionKey") {
70 partitionKey = value
71 } else if stringsscip-go gomod github.com/golang/go/src go1.13 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.13 strings/EqualFold().(key, "RowKey") {
72 rowKey = value
73 } else {
74 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().("Unexpected Key %q", key)
75 }
76 }
77
78 if partitionKey == "" {
79 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 a PartitionKey but didn't get one")
80 }
81 if rowKey == "" {
82 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 a RowKey but didn't get one")
83 }
84
85 return &ResourceIDscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#{
86 AccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#AccountName.: *accountName,
87 TableNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#TableName.: tableName,
88 PartitionKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#PartitionKey.: partitionKey,
89 RowKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2018-11-09/table/entities`/ResourceID#RowKey.: rowKey,
90 }, nil
91 }