...
1
2
3
4
5
6
7
8 package freightv1
9
10 import (
11 fmt "fmt"
12 resourcename "go.einride.tech/aip/resourcename"
13 strings "strings"
14 )
15
16 type ShipperResourceName struct {
17 Shipper string
18 }
19
20 func (n ShipperResourceName) Validate() error {
21 if n.Shipper == "" {
22 return fmt.Errorf("shipper: empty")
23 }
24 if strings.IndexByte(n.Shipper, '/') != -1 {
25 return fmt.Errorf("shipper: contains illegal character '/'")
26 }
27 return nil
28 }
29
30 func (n ShipperResourceName) ContainsWildcard() bool {
31 return false || n.Shipper == "-"
32 }
33
34 func (n ShipperResourceName) String() string {
35 return resourcename.Sprint(
36 "shippers/{shipper}",
37 n.Shipper,
38 )
39 }
40
41 func (n ShipperResourceName) MarshalString() (string, error) {
42 if err := n.Validate(); err != nil {
43 return "", err
44 }
45 return n.String(), nil
46 }
47
48 func (n *ShipperResourceName) UnmarshalString(name string) error {
49 err := resourcename.Sscan(
50 name,
51 "shippers/{shipper}",
52 &n.Shipper,
53 )
54 if err != nil {
55 return err
56 }
57 return n.Validate()
58 }
59
View as plain text