github.com/cloudwan/edgelq-sdk@v1.15.4/monitoring/resources/v4/phantom_time_serie/phantom_time_serie.pb.name.go (about)

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: PhantomTimeSerie
     3  // DO NOT EDIT!!!
     4  
     5  package phantom_time_serie
     6  
     7  import (
     8  	"fmt"
     9  	"net/url"
    10  	"reflect"
    11  	"regexp"
    12  	"strings"
    13  
    14  	"google.golang.org/grpc/codes"
    15  	"google.golang.org/grpc/status"
    16  	"google.golang.org/protobuf/proto"
    17  
    18  	"github.com/cloudwan/goten-sdk/runtime/goten"
    19  	gotenresource "github.com/cloudwan/goten-sdk/runtime/resource"
    20  )
    21  
    22  // proto imports
    23  import (
    24  	common "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/common"
    25  	metric_descriptor "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/metric_descriptor"
    26  	project "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/project"
    27  	meta "github.com/cloudwan/goten-sdk/types/meta"
    28  )
    29  
    30  // ensure the imports are used
    31  var (
    32  	_ = codes.NotFound
    33  	_ = new(fmt.Stringer)
    34  	_ = new(proto.Message)
    35  	_ = status.Status{}
    36  	_ = url.URL{}
    37  	_ = strings.Builder{}
    38  
    39  	_ = new(goten.GotenMessage)
    40  	_ = new(gotenresource.ListQuery)
    41  )
    42  
    43  // make sure we're using proto imports
    44  var (
    45  	_ = &common.LabelDescriptor{}
    46  	_ = &metric_descriptor.MetricDescriptor{}
    47  	_ = &project.Project{}
    48  	_ = &meta.Meta{}
    49  )
    50  
    51  var phantomTimeSerie_RegexpId = regexp.MustCompile("^(?P<phantom_time_serie_id>[\\w+/=]{1,256})$")
    52  var regexPath_Project_Region = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])/phantomTimeSeries/(?P<phantom_time_serie_id>-|[\\w+/=]{1,256})$")
    53  
    54  func (r *PhantomTimeSerie) MaybePopulateDefaults() error {
    55  	phantomTimeSerieInterface := interface{}(r)
    56  	if defaulter, ok := phantomTimeSerieInterface.(goten.Defaulter); ok {
    57  		return defaulter.PopulateDefaults()
    58  	}
    59  	return nil
    60  }
    61  
    62  type Name struct {
    63  	ParentName
    64  	PhantomTimeSerieId string `firestore:"phantomTimeSerieId"`
    65  }
    66  
    67  func ParseName(name string) (*Name, error) {
    68  	var matches []string
    69  	if matches = regexPath_Project_Region.FindStringSubmatch(name); matches != nil {
    70  		return NewNameBuilder().
    71  			SetProjectId(matches[1]).
    72  			SetRegionId(matches[2]).
    73  			SetId(matches[3]).
    74  			Name(), nil
    75  	}
    76  
    77  	return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as PhantomTimeSerie name", name)
    78  }
    79  
    80  func MustParseName(name string) *Name {
    81  	result, err := ParseName(name)
    82  	if err != nil {
    83  		panic(err)
    84  	}
    85  	return result
    86  }
    87  
    88  func ParseNameOrId(nameOrId string) (*Name, error) {
    89  	name, err := ParseName(nameOrId)
    90  	if err == nil {
    91  		return name, err
    92  	}
    93  	if phantomTimeSerie_RegexpId.MatchString(nameOrId) {
    94  		return &Name{PhantomTimeSerieId: nameOrId}, nil
    95  	} else {
    96  		return nil, fmt.Errorf("unable to parse '%s' as PhantomTimeSerie name or id", nameOrId)
    97  	}
    98  }
    99  
   100  func (name *Name) SetFromSegments(segments gotenresource.NameSegments) error {
   101  	if len(segments) == 0 {
   102  		return status.Errorf(codes.InvalidArgument, "No segments given for PhantomTimeSerie name")
   103  	}
   104  	if err := name.ParentName.SetFromSegments(segments[:len(segments)-1]); err != nil {
   105  		return err
   106  	}
   107  	if segments[len(segments)-1].CollectionLowerJson != "phantomTimeSeries" {
   108  		return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form PhantomTimeSerie name", segments)
   109  	}
   110  	name.PhantomTimeSerieId = segments[len(segments)-1].Id
   111  	return nil
   112  }
   113  
   114  func (name *Name) GetProjectName() *project.Name {
   115  	if name == nil {
   116  		return nil
   117  	}
   118  	return name.ParentName.GetProjectName()
   119  }
   120  
   121  func (name *Name) IsSpecified() bool {
   122  	if name == nil || name.Pattern == "" || name.PhantomTimeSerieId == "" {
   123  		return false
   124  	}
   125  	return name.ParentName.IsSpecified()
   126  }
   127  
   128  func (name *Name) IsFullyQualified() bool {
   129  	if name == nil {
   130  		return false
   131  	}
   132  	if name.ParentName.IsFullyQualified() == false {
   133  		return false
   134  	}
   135  	if name.PhantomTimeSerieId == "" || name.PhantomTimeSerieId == gotenresource.WildcardId {
   136  		return false
   137  	}
   138  	return true
   139  }
   140  
   141  func (name *Name) FullyQualifiedName() (string, error) {
   142  	if !name.IsFullyQualified() {
   143  		return "", status.Errorf(codes.InvalidArgument, "Name for PhantomTimeSerie is not fully qualified")
   144  	}
   145  	return fmt.Sprintf("//monitoring.edgelq.com/%s", name.String()), nil
   146  }
   147  
   148  func (name *Name) String() string {
   149  	if name == nil {
   150  		return "<nil>"
   151  	}
   152  	if valueStr, err := name.ProtoString(); err != nil {
   153  		panic(err)
   154  	} else {
   155  		return valueStr
   156  	}
   157  }
   158  
   159  func (name *Name) AsReference() *Reference {
   160  	return &Reference{Name: *name}
   161  }
   162  
   163  func (name *Name) AsRawReference() gotenresource.Reference {
   164  	return name.AsReference()
   165  }
   166  
   167  func (name *Name) GetResourceDescriptor() gotenresource.Descriptor {
   168  	return descriptor
   169  }
   170  
   171  func (name *Name) GetPattern() gotenresource.NamePattern {
   172  	if name == nil {
   173  		return ""
   174  	}
   175  	return name.Pattern
   176  }
   177  
   178  func (name *Name) GetIdParts() map[string]string {
   179  	if name != nil {
   180  		return map[string]string{
   181  			"projectId":          name.ProjectId,
   182  			"regionId":           name.RegionId,
   183  			"phantomTimeSerieId": name.PhantomTimeSerieId,
   184  		}
   185  	}
   186  	return map[string]string{
   187  		"projectId":          "",
   188  		"regionId":           "",
   189  		"phantomTimeSerieId": "",
   190  	}
   191  }
   192  
   193  func (name *Name) GetSegments() gotenresource.NameSegments {
   194  	if name == nil || name.Pattern == "" {
   195  		return nil
   196  	}
   197  	segments := name.ParentName.GetSegments()
   198  	return append(segments, gotenresource.NameSegment{
   199  		CollectionLowerJson: "phantomTimeSeries",
   200  		Id:                  name.PhantomTimeSerieId,
   201  	})
   202  }
   203  
   204  func (name *Name) GetIParentName() gotenresource.Name {
   205  	if name == nil {
   206  		return (*ParentName)(nil)
   207  	}
   208  	return &name.ParentName
   209  }
   210  
   211  func (name *Name) GetIUnderlyingParentName() gotenresource.Name {
   212  	if parentName := name.GetProjectName(); parentName != nil {
   213  		return parentName
   214  	}
   215  	return nil
   216  }
   217  
   218  // implement methods required by protobuf-go library for string-struct conversion
   219  
   220  func (name *Name) ProtoString() (string, error) {
   221  	if name == nil {
   222  		return "", nil
   223  	}
   224  	result := ""
   225  	parentPrefix, err := name.ParentName.ProtoString()
   226  	if err != nil {
   227  		return "", err
   228  	}
   229  	if parentPrefix != "" {
   230  		result += parentPrefix + "/"
   231  	}
   232  	result += "phantomTimeSeries/" + name.PhantomTimeSerieId
   233  	return result, nil
   234  }
   235  
   236  func (name *Name) ParseProtoString(data string) error {
   237  	parsed, err := ParseName(data)
   238  	if err != nil {
   239  		return err
   240  	}
   241  	*name = *parsed
   242  	return nil
   243  }
   244  
   245  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   246  func (name *Name) GotenEqual(other interface{}) bool {
   247  	if other == nil {
   248  		return name == nil
   249  	}
   250  	other1, ok := other.(*Name)
   251  	if !ok {
   252  		other2, ok := other.(Name)
   253  		if ok {
   254  			other1 = &other2
   255  		} else {
   256  			return false
   257  		}
   258  	}
   259  	if other1 == nil {
   260  		return name == nil
   261  	} else if name == nil {
   262  		return false
   263  	}
   264  	if name.ParentName.GotenEqual(other1.ParentName) == false {
   265  		return false
   266  	}
   267  	if name.PhantomTimeSerieId != other1.PhantomTimeSerieId {
   268  		return false
   269  	}
   270  
   271  	return true
   272  }
   273  
   274  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   275  func (name *Name) Matches(other interface{}) bool {
   276  	if other == nil {
   277  		return name == nil
   278  	}
   279  	other1, ok := other.(*Name)
   280  	if !ok {
   281  		other2, ok := other.(Name)
   282  		if ok {
   283  			other1 = &other2
   284  		} else {
   285  			return false
   286  		}
   287  	}
   288  	if other1 == nil {
   289  		return name == nil
   290  	} else if name == nil {
   291  		return false
   292  	}
   293  	if name.ParentName.Matches(other1.ParentName) == false {
   294  		return false
   295  	}
   296  	if name.PhantomTimeSerieId != other1.PhantomTimeSerieId {
   297  		return name.PhantomTimeSerieId == gotenresource.WildcardId
   298  	}
   299  
   300  	return true
   301  }
   302  
   303  // implement CustomTypeCliValue method
   304  func (name *Name) SetFromCliFlag(raw string) error {
   305  	parsedName, err := ParseName(raw)
   306  	if err != nil {
   307  		return err
   308  	}
   309  	*name = *parsedName
   310  	return nil
   311  }
   312  
   313  type Reference struct {
   314  	Name
   315  	phantomTimeSerie *PhantomTimeSerie
   316  }
   317  
   318  func MakeReference(name *Name, phantomTimeSerie *PhantomTimeSerie) (*Reference, error) {
   319  	return &Reference{
   320  		Name:             *name,
   321  		phantomTimeSerie: phantomTimeSerie,
   322  	}, nil
   323  }
   324  
   325  func ParseReference(name string) (*Reference, error) {
   326  	parsedName, err := ParseName(name)
   327  	if err != nil {
   328  		return nil, err
   329  	}
   330  	return MakeReference(parsedName, nil)
   331  }
   332  
   333  func MustParseReference(name string) *Reference {
   334  	result, err := ParseReference(name)
   335  	if err != nil {
   336  		panic(err)
   337  	}
   338  	return result
   339  }
   340  
   341  func (ref *Reference) Resolve(resolved *PhantomTimeSerie) {
   342  	ref.phantomTimeSerie = resolved
   343  }
   344  
   345  func (ref *Reference) ResolveRaw(res gotenresource.Resource) error {
   346  	if res == nil {
   347  		ref.Resolve(nil)
   348  		return nil
   349  	}
   350  	if typedRes, ok := res.(*PhantomTimeSerie); ok {
   351  		ref.Resolve(typedRes)
   352  		return nil
   353  	}
   354  	return status.Errorf(codes.Internal, "Invalid resource type for PhantomTimeSerie: %s", reflect.TypeOf(res).Elem().Name())
   355  }
   356  
   357  func (ref *Reference) Resolved() bool {
   358  	return ref != nil && ref.phantomTimeSerie != nil
   359  }
   360  
   361  func (ref *Reference) ClearCached() {
   362  	ref.phantomTimeSerie = nil
   363  }
   364  
   365  func (ref *Reference) GetPhantomTimeSerie() *PhantomTimeSerie {
   366  	if ref == nil {
   367  		return nil
   368  	}
   369  	return ref.phantomTimeSerie
   370  }
   371  
   372  func (ref *Reference) GetRawResource() gotenresource.Resource {
   373  	if ref == nil {
   374  		return (*PhantomTimeSerie)(nil)
   375  	}
   376  	return ref.phantomTimeSerie
   377  }
   378  
   379  func (ref *Reference) IsFullyQualified() bool {
   380  	if ref == nil {
   381  		return false
   382  	}
   383  	return ref.Name.IsFullyQualified()
   384  }
   385  
   386  func (ref *Reference) IsSpecified() bool {
   387  	if ref == nil {
   388  		return false
   389  	}
   390  	return ref.Name.IsSpecified()
   391  }
   392  
   393  func (ref *Reference) FullyQualifiedName() (string, error) {
   394  	if !ref.IsFullyQualified() {
   395  		return "", status.Errorf(codes.InvalidArgument, "Name for PhantomTimeSerie is not fully qualified")
   396  	}
   397  	return fmt.Sprintf("//monitoring.edgelq.com/%s", ref.String()), nil
   398  }
   399  
   400  func (ref *Reference) GetResourceDescriptor() gotenresource.Descriptor {
   401  	return descriptor
   402  }
   403  
   404  func (ref *Reference) GetPattern() gotenresource.NamePattern {
   405  	if ref == nil {
   406  		return ""
   407  	}
   408  	return ref.Pattern
   409  }
   410  
   411  func (ref *Reference) GetIdParts() map[string]string {
   412  	if ref != nil {
   413  		return ref.Name.GetIdParts()
   414  	}
   415  	return map[string]string{
   416  		"projectId":          "",
   417  		"regionId":           "",
   418  		"phantomTimeSerieId": "",
   419  	}
   420  }
   421  
   422  func (ref *Reference) GetSegments() gotenresource.NameSegments {
   423  	if ref != nil {
   424  		return ref.Name.GetSegments()
   425  	}
   426  	return nil
   427  }
   428  
   429  func (ref *Reference) GetIParentName() gotenresource.Name {
   430  	if ref == nil {
   431  		return (*ParentName)(nil)
   432  	}
   433  	return ref.Name.GetIParentName()
   434  }
   435  
   436  func (ref *Reference) GetIUnderlyingParentName() gotenresource.Name {
   437  	if ref != nil {
   438  		return ref.Name.GetIUnderlyingParentName()
   439  	}
   440  	return nil
   441  }
   442  
   443  func (ref *Reference) String() string {
   444  	if ref == nil {
   445  		return "<nil>"
   446  	}
   447  	return ref.Name.String()
   448  }
   449  
   450  // implement methods required by protobuf-go library for string-struct conversion
   451  
   452  func (ref *Reference) ProtoString() (string, error) {
   453  	if ref == nil {
   454  		return "", nil
   455  	}
   456  	return ref.Name.ProtoString()
   457  }
   458  
   459  func (ref *Reference) ParseProtoString(data string) error {
   460  	parsed, err := ParseReference(data)
   461  	if err != nil {
   462  		return err
   463  	}
   464  	*ref = *parsed
   465  	return nil
   466  }
   467  
   468  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   469  func (ref *Reference) GotenEqual(other interface{}) bool {
   470  	if other == nil {
   471  		return ref == nil
   472  	}
   473  	other1, ok := other.(*Reference)
   474  	if !ok {
   475  		other2, ok := other.(Reference)
   476  		if ok {
   477  			other1 = &other2
   478  		} else {
   479  			return false
   480  		}
   481  	}
   482  	if other1 == nil {
   483  		return ref == nil
   484  	} else if ref == nil {
   485  		return false
   486  	}
   487  
   488  	return ref.Name.GotenEqual(other1.Name)
   489  }
   490  
   491  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   492  func (name *Reference) Matches(other interface{}) bool {
   493  	if other == nil {
   494  		return name == nil
   495  	}
   496  	other1, ok := other.(*Reference)
   497  	if !ok {
   498  		other2, ok := other.(Reference)
   499  		if ok {
   500  			other1 = &other2
   501  		} else {
   502  			return false
   503  		}
   504  	}
   505  	if other1 == nil {
   506  		return name == nil
   507  	} else if name == nil {
   508  		return false
   509  	}
   510  	return name.Name.Matches(&other1.Name)
   511  }
   512  
   513  // implement CustomTypeCliValue method
   514  func (ref *Reference) SetFromCliFlag(raw string) error {
   515  	parsedRef, err := ParseReference(raw)
   516  	if err != nil {
   517  		return err
   518  	}
   519  	*ref = *parsedRef
   520  	return nil
   521  }