...

Source file src/go.einride.tech/aip/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/originallysinglepattern/testdata_aip.go

Documentation: go.einride.tech/aip/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/originallysinglepattern

     1  // Code generated by protoc-gen-go-aip. DO NOT EDIT.
     2  //
     3  // versions:
     4  // 	protoc-gen-go-aip development
     5  // 	protoc (unknown)
     6  // source: test/originallysinglepattern/testdata.proto
     7  
     8  package originallysinglepattern
     9  
    10  import (
    11  	fmt "fmt"
    12  	resourcename "go.einride.tech/aip/resourcename"
    13  	strings "strings"
    14  )
    15  
    16  type BookMultiPatternResourceName interface {
    17  	fmt.Stringer
    18  	MarshalString() (string, error)
    19  	ContainsWildcard() bool
    20  }
    21  
    22  func ParseBookMultiPatternResourceName(name string) (BookMultiPatternResourceName, error) {
    23  	switch {
    24  	case resourcename.Match("shelves/{shelf}/books/{book}", name):
    25  		var result ShelvesBookResourceName
    26  		return &result, result.UnmarshalString(name)
    27  	case resourcename.Match("publishers/{publisher}/books/{book}", name):
    28  		var result PublishersBookResourceName
    29  		return &result, result.UnmarshalString(name)
    30  	default:
    31  		return nil, fmt.Errorf("no matching pattern")
    32  	}
    33  }
    34  
    35  type BookResourceName struct {
    36  	Shelf string
    37  	Book  string
    38  }
    39  
    40  func (n ShelfResourceName) BookResourceName(
    41  	book string,
    42  ) BookResourceName {
    43  	return BookResourceName{
    44  		Shelf: n.Shelf,
    45  		Book:  book,
    46  	}
    47  }
    48  
    49  func (n BookResourceName) Validate() error {
    50  	if n.Shelf == "" {
    51  		return fmt.Errorf("shelf: empty")
    52  	}
    53  	if strings.IndexByte(n.Shelf, '/') != -1 {
    54  		return fmt.Errorf("shelf: contains illegal character '/'")
    55  	}
    56  	if n.Book == "" {
    57  		return fmt.Errorf("book: empty")
    58  	}
    59  	if strings.IndexByte(n.Book, '/') != -1 {
    60  		return fmt.Errorf("book: contains illegal character '/'")
    61  	}
    62  	return nil
    63  }
    64  
    65  func (n BookResourceName) ContainsWildcard() bool {
    66  	return false || n.Shelf == "-" || n.Book == "-"
    67  }
    68  
    69  func (n BookResourceName) String() string {
    70  	return resourcename.Sprint(
    71  		"shelves/{shelf}/books/{book}",
    72  		n.Shelf,
    73  		n.Book,
    74  	)
    75  }
    76  
    77  func (n BookResourceName) MarshalString() (string, error) {
    78  	if err := n.Validate(); err != nil {
    79  		return "", err
    80  	}
    81  	return n.String(), nil
    82  }
    83  
    84  func (n *BookResourceName) UnmarshalString(name string) error {
    85  	err := resourcename.Sscan(
    86  		name,
    87  		"shelves/{shelf}/books/{book}",
    88  		&n.Shelf,
    89  		&n.Book,
    90  	)
    91  	if err != nil {
    92  		return err
    93  	}
    94  	return n.Validate()
    95  }
    96  
    97  func (n BookResourceName) ShelfResourceName() ShelfResourceName {
    98  	return ShelfResourceName{
    99  		Shelf: n.Shelf,
   100  	}
   101  }
   102  
   103  type ShelvesBookResourceName struct {
   104  	Shelf string
   105  	Book  string
   106  }
   107  
   108  func (n ShelfResourceName) ShelvesBookResourceName(
   109  	book string,
   110  ) ShelvesBookResourceName {
   111  	return ShelvesBookResourceName{
   112  		Shelf: n.Shelf,
   113  		Book:  book,
   114  	}
   115  }
   116  
   117  func (n ShelvesBookResourceName) Validate() error {
   118  	if n.Shelf == "" {
   119  		return fmt.Errorf("shelf: empty")
   120  	}
   121  	if strings.IndexByte(n.Shelf, '/') != -1 {
   122  		return fmt.Errorf("shelf: contains illegal character '/'")
   123  	}
   124  	if n.Book == "" {
   125  		return fmt.Errorf("book: empty")
   126  	}
   127  	if strings.IndexByte(n.Book, '/') != -1 {
   128  		return fmt.Errorf("book: contains illegal character '/'")
   129  	}
   130  	return nil
   131  }
   132  
   133  func (n ShelvesBookResourceName) ContainsWildcard() bool {
   134  	return false || n.Shelf == "-" || n.Book == "-"
   135  }
   136  
   137  func (n ShelvesBookResourceName) String() string {
   138  	return resourcename.Sprint(
   139  		"shelves/{shelf}/books/{book}",
   140  		n.Shelf,
   141  		n.Book,
   142  	)
   143  }
   144  
   145  func (n ShelvesBookResourceName) MarshalString() (string, error) {
   146  	if err := n.Validate(); err != nil {
   147  		return "", err
   148  	}
   149  	return n.String(), nil
   150  }
   151  
   152  func (n *ShelvesBookResourceName) UnmarshalString(name string) error {
   153  	err := resourcename.Sscan(
   154  		name,
   155  		"shelves/{shelf}/books/{book}",
   156  		&n.Shelf,
   157  		&n.Book,
   158  	)
   159  	if err != nil {
   160  		return err
   161  	}
   162  	return n.Validate()
   163  }
   164  
   165  func (n ShelvesBookResourceName) ShelfResourceName() ShelfResourceName {
   166  	return ShelfResourceName{
   167  		Shelf: n.Shelf,
   168  	}
   169  }
   170  
   171  type PublishersBookResourceName struct {
   172  	Publisher string
   173  	Book      string
   174  }
   175  
   176  func (n PublishersBookResourceName) Validate() error {
   177  	if n.Publisher == "" {
   178  		return fmt.Errorf("publisher: empty")
   179  	}
   180  	if strings.IndexByte(n.Publisher, '/') != -1 {
   181  		return fmt.Errorf("publisher: contains illegal character '/'")
   182  	}
   183  	if n.Book == "" {
   184  		return fmt.Errorf("book: empty")
   185  	}
   186  	if strings.IndexByte(n.Book, '/') != -1 {
   187  		return fmt.Errorf("book: contains illegal character '/'")
   188  	}
   189  	return nil
   190  }
   191  
   192  func (n PublishersBookResourceName) ContainsWildcard() bool {
   193  	return false || n.Publisher == "-" || n.Book == "-"
   194  }
   195  
   196  func (n PublishersBookResourceName) String() string {
   197  	return resourcename.Sprint(
   198  		"publishers/{publisher}/books/{book}",
   199  		n.Publisher,
   200  		n.Book,
   201  	)
   202  }
   203  
   204  func (n PublishersBookResourceName) MarshalString() (string, error) {
   205  	if err := n.Validate(); err != nil {
   206  		return "", err
   207  	}
   208  	return n.String(), nil
   209  }
   210  
   211  func (n *PublishersBookResourceName) UnmarshalString(name string) error {
   212  	err := resourcename.Sscan(
   213  		name,
   214  		"publishers/{publisher}/books/{book}",
   215  		&n.Publisher,
   216  		&n.Book,
   217  	)
   218  	if err != nil {
   219  		return err
   220  	}
   221  	return n.Validate()
   222  }
   223  
   224  type ShelfMultiPatternResourceName interface {
   225  	fmt.Stringer
   226  	MarshalString() (string, error)
   227  	ContainsWildcard() bool
   228  }
   229  
   230  func ParseShelfMultiPatternResourceName(name string) (ShelfMultiPatternResourceName, error) {
   231  	switch {
   232  	case resourcename.Match("shelves/{shelf}", name):
   233  		var result ShelfResourceName
   234  		return &result, result.UnmarshalString(name)
   235  	case resourcename.Match("libraries/{library}/shelves/{shelf}", name):
   236  		var result LibrariesShelfResourceName
   237  		return &result, result.UnmarshalString(name)
   238  	case resourcename.Match("rooms/{room}/shelves/{shelf}", name):
   239  		var result RoomsShelfResourceName
   240  		return &result, result.UnmarshalString(name)
   241  	default:
   242  		return nil, fmt.Errorf("no matching pattern")
   243  	}
   244  }
   245  
   246  type ShelfResourceName struct {
   247  	Shelf string
   248  }
   249  
   250  func (n ShelfResourceName) Validate() error {
   251  	if n.Shelf == "" {
   252  		return fmt.Errorf("shelf: empty")
   253  	}
   254  	if strings.IndexByte(n.Shelf, '/') != -1 {
   255  		return fmt.Errorf("shelf: contains illegal character '/'")
   256  	}
   257  	return nil
   258  }
   259  
   260  func (n ShelfResourceName) ContainsWildcard() bool {
   261  	return false || n.Shelf == "-"
   262  }
   263  
   264  func (n ShelfResourceName) String() string {
   265  	return resourcename.Sprint(
   266  		"shelves/{shelf}",
   267  		n.Shelf,
   268  	)
   269  }
   270  
   271  func (n ShelfResourceName) MarshalString() (string, error) {
   272  	if err := n.Validate(); err != nil {
   273  		return "", err
   274  	}
   275  	return n.String(), nil
   276  }
   277  
   278  func (n *ShelfResourceName) UnmarshalString(name string) error {
   279  	err := resourcename.Sscan(
   280  		name,
   281  		"shelves/{shelf}",
   282  		&n.Shelf,
   283  	)
   284  	if err != nil {
   285  		return err
   286  	}
   287  	return n.Validate()
   288  }
   289  
   290  type LibrariesShelfResourceName struct {
   291  	Library string
   292  	Shelf   string
   293  }
   294  
   295  func (n LibrariesShelfResourceName) Validate() error {
   296  	if n.Library == "" {
   297  		return fmt.Errorf("library: empty")
   298  	}
   299  	if strings.IndexByte(n.Library, '/') != -1 {
   300  		return fmt.Errorf("library: contains illegal character '/'")
   301  	}
   302  	if n.Shelf == "" {
   303  		return fmt.Errorf("shelf: empty")
   304  	}
   305  	if strings.IndexByte(n.Shelf, '/') != -1 {
   306  		return fmt.Errorf("shelf: contains illegal character '/'")
   307  	}
   308  	return nil
   309  }
   310  
   311  func (n LibrariesShelfResourceName) ContainsWildcard() bool {
   312  	return false || n.Library == "-" || n.Shelf == "-"
   313  }
   314  
   315  func (n LibrariesShelfResourceName) String() string {
   316  	return resourcename.Sprint(
   317  		"libraries/{library}/shelves/{shelf}",
   318  		n.Library,
   319  		n.Shelf,
   320  	)
   321  }
   322  
   323  func (n LibrariesShelfResourceName) MarshalString() (string, error) {
   324  	if err := n.Validate(); err != nil {
   325  		return "", err
   326  	}
   327  	return n.String(), nil
   328  }
   329  
   330  func (n *LibrariesShelfResourceName) UnmarshalString(name string) error {
   331  	err := resourcename.Sscan(
   332  		name,
   333  		"libraries/{library}/shelves/{shelf}",
   334  		&n.Library,
   335  		&n.Shelf,
   336  	)
   337  	if err != nil {
   338  		return err
   339  	}
   340  	return n.Validate()
   341  }
   342  
   343  type RoomsShelfResourceName struct {
   344  	Room  string
   345  	Shelf string
   346  }
   347  
   348  func (n RoomsShelfResourceName) Validate() error {
   349  	if n.Room == "" {
   350  		return fmt.Errorf("room: empty")
   351  	}
   352  	if strings.IndexByte(n.Room, '/') != -1 {
   353  		return fmt.Errorf("room: contains illegal character '/'")
   354  	}
   355  	if n.Shelf == "" {
   356  		return fmt.Errorf("shelf: empty")
   357  	}
   358  	if strings.IndexByte(n.Shelf, '/') != -1 {
   359  		return fmt.Errorf("shelf: contains illegal character '/'")
   360  	}
   361  	return nil
   362  }
   363  
   364  func (n RoomsShelfResourceName) ContainsWildcard() bool {
   365  	return false || n.Room == "-" || n.Shelf == "-"
   366  }
   367  
   368  func (n RoomsShelfResourceName) String() string {
   369  	return resourcename.Sprint(
   370  		"rooms/{room}/shelves/{shelf}",
   371  		n.Room,
   372  		n.Shelf,
   373  	)
   374  }
   375  
   376  func (n RoomsShelfResourceName) MarshalString() (string, error) {
   377  	if err := n.Validate(); err != nil {
   378  		return "", err
   379  	}
   380  	return n.String(), nil
   381  }
   382  
   383  func (n *RoomsShelfResourceName) UnmarshalString(name string) error {
   384  	err := resourcename.Sscan(
   385  		name,
   386  		"rooms/{room}/shelves/{shelf}",
   387  		&n.Room,
   388  		&n.Shelf,
   389  	)
   390  	if err != nil {
   391  		return err
   392  	}
   393  	return n.Validate()
   394  }
   395  

View as plain text