This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
/
blockchain_aip.go
118 lines (102 loc) · 2.43 KB
/
blockchain_aip.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Code generated by protoc-gen-go-aip. DO NOT EDIT.
//
// versions:
// protoc-gen-go-aip development
// protoc (unknown)
// source: coinbase/cloud/blockchain/v1/blockchain.proto
package v1
import (
fmt "fmt"
resourcename "go.einride.tech/aip/resourcename"
strings "strings"
)
type NetworkResourceName struct {
NetworkId string
}
func (n NetworkResourceName) Validate() error {
if n.NetworkId == "" {
return fmt.Errorf("network_id: empty")
}
if strings.IndexByte(n.NetworkId, '/') != -1 {
return fmt.Errorf("network_id: contains illegal character '/'")
}
return nil
}
func (n NetworkResourceName) ContainsWildcard() bool {
return false || n.NetworkId == "-"
}
func (n NetworkResourceName) String() string {
return resourcename.Sprint(
"networks/{network_id}",
n.NetworkId,
)
}
func (n NetworkResourceName) MarshalString() (string, error) {
if err := n.Validate(); err != nil {
return "", err
}
return n.String(), nil
}
func (n *NetworkResourceName) UnmarshalString(name string) error {
return resourcename.Sscan(
name,
"networks/{network_id}",
&n.NetworkId,
)
}
type AssetResourceName struct {
NetworkId string
AssetId string
}
func (n NetworkResourceName) AssetResourceName(
assetId string,
) AssetResourceName {
return AssetResourceName{
NetworkId: n.NetworkId,
AssetId: assetId,
}
}
func (n AssetResourceName) Validate() error {
if n.NetworkId == "" {
return fmt.Errorf("network_id: empty")
}
if strings.IndexByte(n.NetworkId, '/') != -1 {
return fmt.Errorf("network_id: contains illegal character '/'")
}
if n.AssetId == "" {
return fmt.Errorf("asset_id: empty")
}
if strings.IndexByte(n.AssetId, '/') != -1 {
return fmt.Errorf("asset_id: contains illegal character '/'")
}
return nil
}
func (n AssetResourceName) ContainsWildcard() bool {
return false || n.NetworkId == "-" || n.AssetId == "-"
}
func (n AssetResourceName) String() string {
return resourcename.Sprint(
"networks/{network_id}/assets/{asset_id}",
n.NetworkId,
n.AssetId,
)
}
func (n AssetResourceName) MarshalString() (string, error) {
if err := n.Validate(); err != nil {
return "", err
}
return n.String(), nil
}
func (n *AssetResourceName) UnmarshalString(name string) error {
return resourcename.Sscan(
name,
"networks/{network_id}/assets/{asset_id}",
&n.NetworkId,
&n.AssetId,
)
}
func (n AssetResourceName) NetworkResourceName() NetworkResourceName {
return NetworkResourceName{
NetworkId: n.NetworkId,
}
}