gomodel

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindValuesMatching

func FindValuesMatching(first, second PathTemplate) (fullMatch bool, longestMatch string, err error)

FindValuesMatching returns the the longest string prefix that matches the templates `first` and `second`, and a bool indicating whether this prefix if a full match for both expressions.

Types

type BodyFieldSpec

type BodyFieldSpec int

BodyFieldSpec encodes what request field was annotated as the REST request body.

const (
	BodyFieldNone   BodyFieldSpec = iota // no RPC field specified in the REST body
	BodyFieldSingle                      // a single top-level RPC request field was specified in the REST body
	BodyFieldAll                         // the whole RPC request message is encoded in the REST body
)

type Model

type Model struct {
	errorhandling.Accumulator
	Service []*ServiceModel
}

Model is a data model intended to be capture all the information needed for generating Go source files that provide shims between REST messages on the wire and protocol buffer messages in the back end, for multiple services.

func (*Model) Add

func (gm *Model) Add(service *ServiceModel)

Add adds `service` to this Model.

func (*Model) CheckConsistency

func (gm *Model) CheckConsistency()

CheckConsistency checks this Model for consistency, accumulating any errors found. This means checking that all the HTTP annotations across all services resolve to distinct paths.

func (*Model) String

func (gm *Model) String() string

String returns a string representation of this Model.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser contains the context for parsing a path template string.

func NewParser

func NewParser(template string) *Parser

NewParser returns a Parser ready to process template.

func (*Parser) GetRegexp

func (parser *Parser) GetRegexp(expr string) *regexp.Regexp

GetRegexp returns the memoized compiled regex corresponding to expr. This allows defining regexes where they're used while still compiling them only once.

type PathTemplate

type PathTemplate []*Segment

PathTemplate contains a sequence of parsed Segment to represent an HTTP binding.

func NewPathTemplate

func NewPathTemplate(pattern string) (PathTemplate, error)

NewPathTemplate parses `pattern` to return the corresponding PathTemplate.

func ParseTemplate

func ParseTemplate(template string) (parsed PathTemplate, err error)

ParseTemplate parses a path template string according to https://cloud.google.com/endpoints/docs/grpc-service-config/reference/rpc/google.api#path-template-syntax

Grammar:

Template = "/" Segments [ Verb ] ;
Segments = Segment { "/" Segment } ;
Segment  = "*" | "**" | LITERAL | Variable ;
Variable = "{" FieldPath [ "=" Segments ] "}" ;
FieldPath = IDENT { "." IDENT } ;
Verb     = ":" LITERAL ;

with "**" matching the last part of the path template string except for the Verb.

func (PathTemplate) Flatten

func (pt PathTemplate) Flatten() PathTemplate

Flatten returns a flattened PathTemplate, which contains no recursively nested PathTemplate. Effectively, this removes any Segment with `Kind==Variable`.

func (PathTemplate) HasVariables

func (pt PathTemplate) HasVariables() (topVar, nestedVar bool)

HasVariables returns two booleans depending on whether `pt` has top-level and nested (lower-level) variables.

func (PathTemplate) ListVariables

func (pt PathTemplate) ListVariables() []string

ListVariables returns a list of all the variables (proto field names) found in `pt`,

type RESTHandler

type RESTHandler struct {
	HTTPMethod      string
	URIPattern      string       // as it appears in the HTTP annotation
	PathTemplate    PathTemplate // parsed version of URIPattern
	StreamingServer bool         // whether this method uses server-side streaming
	StreamingClient bool         // whether this method uses client-side streaming

	GoMethod                  string
	RequestType               string
	RequestTypePackage        string
	RequestVariable           string
	RequestBodyFieldSpec      BodyFieldSpec
	RequestBodyFieldProtoName string
	RequestBodyFieldName      string
	RequestBodyFieldType      string
	RequestBodyFieldVariable  string
	RequestBodyFieldPackage   string
	ResponseType              string
	ResponseTypePackage       string
	ResponseVariable          string
}

RESTHandler contains the information needed to generate a single HTTP handler.

func (*RESTHandler) String

func (rh *RESTHandler) String() string

String returns a string representation of this RESTHandler.

type Segment

type Segment struct {
	Kind SegmentKind

	// the semantics of Value depend on Kind:
	// Kind==Variable: field path
	// Kind==Literal: literal value
	// Kind==SingleValue: "*"
	// Kind== MultipleValue: "**"
	Value string

	Subsegments PathTemplate
}

Segment is a single structural element in an HTTP binding

func (*Segment) Flatten

func (seg *Segment) Flatten() PathTemplate

Flatten returns a flattened PathTemplate containing either this Segment or its flattened sub-segments. Effectively, this removes any Segment with `Kind==Variable`.

func (*Segment) String

func (seg *Segment) String() string

String returns a string representation of this Segment.

type SegmentKind

type SegmentKind int

SegmentKind describes a type of Segment.

const (
	KindUndefined SegmentKind = iota
	Literal
	Variable
	SingleValue
	MultipleValue
	KindEnd
)

func (SegmentKind) String

func (sk SegmentKind) String() string

String returns a string representation of this SegmentKind.

func (SegmentKind) Valid

func (sk SegmentKind) Valid() bool

Valid returns true iff this SegmentKind value is valid.

type ServiceModel

type ServiceModel struct {
	// the fully qualified protocol buffer type name of this service
	ProtoPath string

	// the non-qualified name of this service
	ShortName string

	// a map of import paths to import info for each of the service-related Go imports that will
	// be needed to implement all of the Handlers
	Imports map[string]*pbinfo.ImportSpec

	// a list of all the HTTP handlers that will need to be generated, one for each HTTP
	// annotation for each service RPC
	Handlers []*RESTHandler
}

ServiceModel is a data model for generating a REST/proto shim for a single protocol buffer service.

func (*ServiceModel) AddHandler

func (service *ServiceModel) AddHandler(handler *RESTHandler)

AddHandler adds handler to this ServiceModel.

func (*ServiceModel) AddImports

func (service *ServiceModel) AddImports(imports ...*pbinfo.ImportSpec)

AddImports adds each element of imports to the imports in this ServiceModel.

func (*ServiceModel) FullName

func (service *ServiceModel) FullName() string

FullName pretty-prints the short name and proto path.

func (*ServiceModel) String

func (service *ServiceModel) String() string

String returns a string representation of this ServiceModel.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source contains the context for the source string being parsed. Note that Source and its methods are NOT rune-safe and operate on each individual character, not each rune.

func (*Source) Consume

func (src *Source) Consume(num int)

Consume advances source by num characters.

func (*Source) ConsumeIf

func (src *Source) ConsumeIf(query byte) bool

ConsumeIf advances the source and returns true iff the next character matches `query`.

func (*Source) ConsumeRegex

func (src *Source) ConsumeRegex(re *regexp.Regexp) string

ConsumeMatch consumes and returns characters matching re, and returns them.

func (*Source) InRange

func (src *Source) InRange() bool

InRange returns true iff there are more characters that can be read from the source string.

func (*Source) IsNextByte

func (src *Source) IsNextByte(query byte) bool

IsNextByte returns true iff the next character to be read is `query`.

func (*Source) Str

func (src *Source) Str() string

Str returns the unparsed part of the original source string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL