-
Notifications
You must be signed in to change notification settings - Fork 5
/
action_aip.go
106 lines (94 loc) 路 2.26 KB
/
action_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
// Code generated by protoc-gen-go-aip. DO NOT EDIT.
//
// versions:
// protoc-gen-go-aip development
// protoc (unknown)
// source: coinbase/staking/orchestration/v1/action.proto
package v1
import (
fmt "fmt"
resourcename "go.einride.tech/aip/resourcename"
strings "strings"
)
type ActionResourceName struct {
Protocol string
Network string
Action string
}
func (n ProtocolResourceName) ActionResourceName(
network string,
action string,
) ActionResourceName {
return ActionResourceName{
Protocol: n.Protocol,
Network: network,
Action: action,
}
}
func (n NetworkResourceName) ActionResourceName(
action string,
) ActionResourceName {
return ActionResourceName{
Protocol: n.Protocol,
Network: n.Network,
Action: action,
}
}
func (n ActionResourceName) Validate() error {
if n.Protocol == "" {
return fmt.Errorf("protocol: empty")
}
if strings.IndexByte(n.Protocol, '/') != -1 {
return fmt.Errorf("protocol: contains illegal character '/'")
}
if n.Network == "" {
return fmt.Errorf("network: empty")
}
if strings.IndexByte(n.Network, '/') != -1 {
return fmt.Errorf("network: contains illegal character '/'")
}
if n.Action == "" {
return fmt.Errorf("action: empty")
}
if strings.IndexByte(n.Action, '/') != -1 {
return fmt.Errorf("action: contains illegal character '/'")
}
return nil
}
func (n ActionResourceName) ContainsWildcard() bool {
return false || n.Protocol == "-" || n.Network == "-" || n.Action == "-"
}
func (n ActionResourceName) String() string {
return resourcename.Sprint(
"protocols/{protocol}/networks/{network}/actions/{action}",
n.Protocol,
n.Network,
n.Action,
)
}
func (n ActionResourceName) MarshalString() (string, error) {
if err := n.Validate(); err != nil {
return "", err
}
return n.String(), nil
}
func (n *ActionResourceName) UnmarshalString(name string) error {
return resourcename.Sscan(
name,
"protocols/{protocol}/networks/{network}/actions/{action}",
&n.Protocol,
&n.Network,
&n.Action,
)
}
func (n ActionResourceName) ProtocolResourceName() ProtocolResourceName {
return ProtocolResourceName{
Protocol: n.Protocol,
}
}
func (n ActionResourceName) NetworkResourceName() NetworkResourceName {
return NetworkResourceName{
Protocol: n.Protocol,
Network: n.Network,
}
}