Documentation ¶
Overview ¶
Package aipreflect provides primitives to manipulate AIP annotations and descriptors.
Index ¶
- type GrammaticalName
- type MethodType
- type ResourceDescriptor
- type ResourceNameDescriptor
- type ResourceNamePatternDescriptor
- func (p ResourceNamePatternDescriptor) Ancestors() []ResourceNamePatternDescriptor
- func (p ResourceNamePatternDescriptor) IsAncestorOf(child ResourceNamePatternDescriptor) bool
- func (p ResourceNamePatternDescriptor) IsSingleton() bool
- func (p ResourceNamePatternDescriptor) Len() int
- func (p ResourceNamePatternDescriptor) MarshalResourceName(values ...string) (string, error)
- func (p ResourceNamePatternDescriptor) NonVariableLen() int
- func (p ResourceNamePatternDescriptor) Parent() (ResourceNamePatternDescriptor, bool)
- func (p ResourceNamePatternDescriptor) String() string
- func (p ResourceNamePatternDescriptor) ValidateResourceName(name string) error
- func (p ResourceNamePatternDescriptor) VariableCount() int
- func (p ResourceNamePatternDescriptor) Wildcard() string
- type ResourceNameSegmentDescriptor
- type ResourceType
- type ResourceTypeDescriptor
- type ResourceTypeName
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GrammaticalName ¶ added in v0.17.0
type GrammaticalName string // e.g. "userEvents"
GrammaticalName is the grammatical name for the singular or plural form of resource resource type. Grammatical names must be URL-safe and use lowerCamelCase.
func (GrammaticalName) UpperCamelCase ¶ added in v0.17.0
func (g GrammaticalName) UpperCamelCase() string
UpperCamelCase returns the UpperCamelCase version of the grammatical name, for use in e.g. method names.
func (GrammaticalName) Validate ¶ added in v0.17.0
func (g GrammaticalName) Validate() error
Validate checks that the grammatical name is non-empty, URL-safe, and uses lowerCamelCase.
type MethodType ¶ added in v0.17.0
type MethodType string
MethodType is an AIP method type.
const ( // MethodTypeGet is the method type of the AIP standard Get method. // See: https://google.aip.dev/131 (Standard methods: Get). MethodTypeGet MethodType = "Get" // MethodTypeList is the method type of the AIP standard List method. // See: https://google.aip.dev/132 (Standard methods: List). MethodTypeList MethodType = "List" // MethodTypeCreate is the method type of the AIP standard Create method. // See: https://google.aip.dev/133 (Standard methods: Create). MethodTypeCreate MethodType = "Create" // MethodTypeUpdate is the method type of the AIP standard Update method. // See: https://google.aip.dev/133 (Standard methods: Update). MethodTypeUpdate MethodType = "Update" // MethodTypeDelete is the method type of the AIP standard Delete method. // See: https://google.aip.dev/135 (Standard methods: Delete). MethodTypeDelete MethodType = "Delete" // MethodTypeSearch is the method type of the custom AIP method for searching a resource collection. // See: https://google.aip.dev/136 (Custom methods). MethodTypeSearch MethodType = "Search" // MethodTypeUndelete is the method type of the AIP Undelete method for soft delete. // See: https://google.aip.dev/164 (Soft delete). MethodTypeUndelete MethodType = "Undelete" // MethodTypeBatchGet is the method type of the AIP standard BatchGet method. // See: https://google.aip.dev/231 (Batch methods: Get). MethodTypeBatchGet MethodType = "BatchGet" // MethodTypeBatchCreate is the method type of the AIP standard BatchCreate method. // See: https://google.aip.dev/233 (Batch methods: Create). MethodTypeBatchCreate MethodType = "BatchCreate" // MethodTypeBatchUpdate is the method type of the AIP standard BatchUpdate method. // See: https://google.aip.dev/234 (Batch methods: Update). MethodTypeBatchUpdate MethodType = "BatchUpdate" // MethodTypeBatchDelete is the method type of the AIP standard BatchDelete method. // See: https://google.aip.dev/235 (Batch methods: Delete). MethodTypeBatchDelete MethodType = "BatchDelete" )
func (MethodType) IsPlural ¶ added in v0.17.0
func (s MethodType) IsPlural() bool
IsPlural returns true if the method type relates to a plurality of resources.
type ResourceDescriptor ¶
type ResourceDescriptor struct { // ParentFile is the path of the parent file that the resource descriptor is declared in. ParentFile string // Message is the full name of the message that the resource descriptor is declared in. Message protoreflect.FullName // Type is the resource's type name. Type ResourceTypeName // Names are the resource name descriptors for the resource. Names []*ResourceNameDescriptor // Singular is the singular name of the resource type. Singular GrammaticalName // Plural is the plural name of the resource type. Plural GrammaticalName }
ResourceDescriptor describes a resource.
func NewResourceDescriptor ¶
func NewResourceDescriptor(descriptor *annotations.ResourceDescriptor) (*ResourceDescriptor, error)
NewResourceDescriptor creates a new ResourceDescriptor from the provided resource descriptor message.
func (*ResourceDescriptor) InferMethodName ¶ added in v0.17.0
func (r *ResourceDescriptor) InferMethodName(t MethodType) (protoreflect.Name, error)
InferMethodName infers the method name of type t for the resource r.
type ResourceNameDescriptor ¶
type ResourceNameDescriptor struct { // Type is the resource type name of the resource name's resource type. Type ResourceTypeName // Ancestors are the resource type names of the resource name's ancestors. Ancestors []ResourceTypeName // Pattern describes the resource name's pattern. Pattern ResourceNamePatternDescriptor }
ResourceNameDescriptor describes a resource name.
func NewResourceNameDescriptor ¶
func NewResourceNameDescriptor(pattern string) (*ResourceNameDescriptor, error)
NewResourceNameDescriptor returns a new resource name descriptor for the provided pattern.
type ResourceNamePatternDescriptor ¶
type ResourceNamePatternDescriptor struct { // Segments are the individual segments in the pattern. Segments []ResourceNameSegmentDescriptor }
ResourceNamePatternDescriptor describes a resource name pattern.
Example: `publishers/{publisher}/books/{book}`.
func NewResourceNamePatternDescriptor ¶
func NewResourceNamePatternDescriptor(pattern string) (ResourceNamePatternDescriptor, error)
NewResourceNamePatternDescriptor creates a resource name pattern descriptorn from a resource name pattern.
Pattern syntax from the documentation:
The path pattern must follow the syntax, which aligns with HTTP binding syntax: Template = Segment { "/" Segment } ; Segment = LITERAL | Variable ; Variable = "{" LITERAL "}" ;
func (ResourceNamePatternDescriptor) Ancestors ¶ added in v0.16.0
func (p ResourceNamePatternDescriptor) Ancestors() []ResourceNamePatternDescriptor
Ancestors returns descriptors for the resource name's ancestors.
func (ResourceNamePatternDescriptor) IsAncestorOf ¶
func (p ResourceNamePatternDescriptor) IsAncestorOf(child ResourceNamePatternDescriptor) bool
IsAncestorOf returns true if p is an ancestor of child.
For example, the pattern `publishers/{publisher}` is an ancestor of the pattern `publishers/{publisher}/books/{book}`.
func (ResourceNamePatternDescriptor) IsSingleton ¶
func (p ResourceNamePatternDescriptor) IsSingleton() bool
IsSingleton returns true if the pattern is a singleton pattern.
From: https://aip.dev/156
Singleton resources must not have a user-provided or system-generated ID; their resource name includes the name of their parent followed by one static-segment.
func (ResourceNamePatternDescriptor) Len ¶ added in v0.16.0
func (p ResourceNamePatternDescriptor) Len() int
Len returns the length of the resource name pattern.
func (ResourceNamePatternDescriptor) MarshalResourceName ¶
func (p ResourceNamePatternDescriptor) MarshalResourceName(values ...string) (string, error)
MarshalResourceName marshals a resource name from the pattern p given a list of values for the variables.
func (ResourceNamePatternDescriptor) NonVariableLen ¶
func (p ResourceNamePatternDescriptor) NonVariableLen() int
NonVariableLen returns the non-variable length of the pattern, i.e. the length not counting variable segments.
For example, the non-variable length of the pattern `resources/{resource}` is is 10.
func (ResourceNamePatternDescriptor) Parent ¶ added in v0.16.0
func (p ResourceNamePatternDescriptor) Parent() (ResourceNamePatternDescriptor, bool)
Parent returns a descriptor for the resource name's closest parent.
func (ResourceNamePatternDescriptor) String ¶ added in v0.16.0
func (p ResourceNamePatternDescriptor) String() string
String returns the string representation of the resource name pattern.
func (ResourceNamePatternDescriptor) ValidateResourceName ¶
func (p ResourceNamePatternDescriptor) ValidateResourceName(name string) error
ValidateResourceName validates a resource name against the pattern p.
func (ResourceNamePatternDescriptor) VariableCount ¶
func (p ResourceNamePatternDescriptor) VariableCount() int
VariableCount returns the number of variables in the pattern.
func (ResourceNamePatternDescriptor) Wildcard ¶ added in v0.16.0
func (p ResourceNamePatternDescriptor) Wildcard() string
Wildcard returns a wildcard resource name representation of the pattern.
For example, the wildcard representation of the pattern `resources/{resource}` is `resources/*`.
type ResourceTypeDescriptor ¶
type ResourceTypeDescriptor struct { // ServiceName is the the name defined in the resource's service configuration. // // This usually (but not necessarily) matches the hostname that users use to call the service. // // For example: pubsub.googleapis.com. ServiceName string // Type is the type component of the resource type name. // // The type must be singular and use PascalCase (UpperCamelCase). Type string }
ResourceTypeDescriptor describes a resource type.
func NewResourceTypeDescriptor ¶
func NewResourceTypeDescriptor(s string) (ResourceTypeDescriptor, error)
ParseName parses a resource type name string.
func (ResourceTypeDescriptor) ResourceType ¶
func (n ResourceTypeDescriptor) ResourceType() ResourceType
ResourceType returns the descriptor's resource type.
For example: pubsub.googleapis.com/Topic.
func (ResourceTypeDescriptor) String ¶
func (n ResourceTypeDescriptor) String() string
String returns the string representation of the service type name.
func (ResourceTypeDescriptor) Validate ¶
func (n ResourceTypeDescriptor) Validate() error
Validate the resource type name.
type ResourceTypeName ¶ added in v0.16.0
type ResourceTypeName string // e.g. pubsub.googleapis.com/Topic.
ResourceTypeName represents a resource type name.
func (ResourceTypeName) ServiceName ¶ added in v0.16.0
func (n ResourceTypeName) ServiceName() string
ServiceName returns the service name of the resource type name.
func (ResourceTypeName) Type ¶ added in v0.16.0
func (n ResourceTypeName) Type() string
Type returns the type of the resource type name.
func (ResourceTypeName) Validate ¶ added in v0.16.0
func (n ResourceTypeName) Validate() error
Validate checks that the resource type name is syntactically valid.