registry

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const OptionDartPackage = "dart_package"

Variables

View Source
var ReservedNames = []string{"Reset", "String", "ProtoMessage", "Descriptor"}

ReservedNames are reserved by Protobuf and therefore cannot be field names (Protobuf generates methods with those names).

Functions

func CamelCase

func CamelCase(s string) string

CamelCase converts a snake_cased (_) identifier to an CamelCased identifier (hello_world -> HelloWorld) From the golang/protobuf

func ParsePath

func ParsePath(p string) []string

ParsePath parses the Path format for the router and extract the parameters in the path (from /City/:postal/Street/:name we extract postal and name).

func Sanitize

func Sanitize(s string) string

Sanitize will apply CamelCase and rename Fields from the ReservedNames list following the scheme: Reset -> Reset_ and so on

Types

type ByKey

ByAge implements sort.Interface for []Person based on the Age field.

func (ByKey) Len

func (a ByKey) Len() int

func (ByKey) Less

func (a ByKey) Less(i, j int) bool

func (ByKey) Swap

func (a ByKey) Swap(i, j int)

type Enum

type Enum struct {
	Type *descriptorpb.EnumDescriptorProto

	File     *File
	Registry *Registry

	Filename string
	Package  string
	Comment  string
	Index    int
	Name     string

	Values []*EnumValue
}

func NewEnum

func NewEnum(d *descriptorpb.EnumDescriptorProto, f *File, index int) *Enum

func (*Enum) String

func (e *Enum) String() string

type EnumValue

type EnumValue struct {
	Type *descriptorpb.EnumValueDescriptorProto
	Enum *Enum

	Name   string
	Number int32

	Registry *Registry
}

type Enums

type Enums []*Enum

func (*Enums) Add

func (es *Enums) Add(ne *Enum)

func (*Enums) Get

func (es *Enums) Get(name string) (*Enum, bool)

type Field

type Field struct {
	Type *descriptorpb.FieldDescriptorProto
	// Is used for maps. A map is a nested type in protobuf. This nested type is only accessible via the descriptorpb.DescriptorProto
	Message   *Message
	Registry  *Registry
	Name      string
	IsComplex bool
}

Field represents the information about a field in a message at the moment just a simple wrapper for easier access and a reference to the Registry

func NewField

NewField instantiates a new Field

func (*Field) IsBytes

func (f *Field) IsBytes() bool

IsBytes returns true if the protobuf field is of types bytes

func (*Field) IsEnum

func (f *Field) IsEnum() bool

func (*Field) IsIntermediateMap

func (f *Field) IsIntermediateMap() bool

func (*Field) IsMessage

func (f *Field) IsMessage() bool

IsMessage returns true if the protobuf field is a protobuf message

func (*Field) IsRepeated

func (f *Field) IsRepeated() bool

IsRepeated returns true, if the protobuf field is repated

type FieldMetadata

type FieldMetadata struct {
	Type      string
	ProtoKind descriptorpb.FieldDescriptorProto_Type
	Name      string
}

FieldMetadata holds Information needed to generate the code to copy a defined QueryString parameters to a actually field

func (*FieldMetadata) GetType

func (f *FieldMetadata) GetType() string

GetType gets the type of the final field. Protobuf has a leading . which will be removed for being a proper go identifier

type FieldMetadatas

type FieldMetadatas []FieldMetadata

FieldMetadatas are not part of the Registry. They represent a path to a field in the object tree. like r.User.Name.Firstname in a Protobuf Request.

func (*FieldMetadatas) Generate

func (fmds *FieldMetadatas) Generate() string

Generate returns the go code to set a field value in an struct tree Since protobuf works with pointer intermediate structs have to be instantiated

func (*FieldMetadatas) GetPath

func (fmds *FieldMetadatas) GetPath() string

GetPath returns the path to write out to set a value For example r.User.Name.Firstname

type Fields

type Fields []*Field

Fields is a slice of Fields of a protobuf message

type File

type File struct {
	Type     *descriptorpb.FileDescriptorProto
	Name     string
	Messages []*Message
	Enums    []*Enum
	Package  string
	Registry *Registry
	// Options holds additional options. For example our dart_package options
	Options map[string]string
}

type Files

type Files []*File

func (*Files) Add

func (fs *Files) Add(f *File)

func (*Files) Get

func (fs *Files) Get(key string) (*File, bool)

type Message

type Message struct {
	Type *descriptorpb.DescriptorProto

	File     *File
	Registry *Registry

	Filename string
	Package  string
	Comment  string
	Index    int
	Fields   Fields
}

Message wraps a protobuf message with a little extra information for code generation

func NewMessage

func NewMessage(d *descriptorpb.DescriptorProto, f *File, index int) *Message

func (*Message) GetFieldType

func (m *Message) GetFieldType(path string) *FieldMetadatas

GetFieldType returns the type of a field in the struct tree below the message

func (*Message) Name

func (m *Message) Name() string

Name returns the Name of the message

func (*Message) String

func (m *Message) String() string

type Messages

type Messages []*Message

Messages is a map from the messages name ot the Message

func (*Messages) Add

func (ms *Messages) Add(m *Message)

func (*Messages) Get

func (ms *Messages) Get(key string) (*Message, bool)

type Method

type Method struct {
	Type            *descriptorpb.MethodDescriptorProto
	Package         string
	Name            string
	RESTMethod      string
	RESTPath        string
	RESTPathVars    PathParams
	RESTQueryString QueryStringParams
	RESTBody        string

	InputType  *descriptorpb.DescriptorProto
	OutputType *descriptorpb.DescriptorProto
	Registry   *Registry
	// contains filtered or unexported fields
}

Method is wrapper around the MethodDescriptorProto with some additional/extracted information useful to generate the Gateway

func (*Method) FullName

func (m *Method) FullName() string

func (*Method) HarmonizedRESTPath

func (m *Method) HarmonizedRESTPath() string

HarmonizedRESTPath returns a cleaned-up version of Mapped REST-Path so it can be registered without conflicts to the router

func (*Method) HasBodyMapping

func (m *Method) HasBodyMapping() bool

HasBodyMapping returns true, if in the REST Mapping the requests body is mapped

func (*Method) HasMethodMap

func (m *Method) HasMethodMap() bool

HasMethodMap returns true, if the method has a MethodMap options

func (*Method) HasPathParamsMapping

func (m *Method) HasPathParamsMapping() bool

HasPathParamsMapping returns true, if url-path parameters are mapped

func (*Method) HasQueryStringMapping

func (m *Method) HasQueryStringMapping() bool

HasQueryStringMapping returns true, if the Method has a Query String Mapping

func (*Method) InputTypeName

func (m *Method) InputTypeName() string

InputTypeName retrurns the mame if the method's input type

func (*Method) OutputTypeName

func (m *Method) OutputTypeName() string

OutputTypeName returns the name of the method's output type

type Methods

type Methods []*Method

func (*Methods) Add

func (ms *Methods) Add(m *Method)

func (*Methods) Get

func (ms *Methods) Get(key string) (*Method, bool)

type PathParam

type PathParam struct {
	N              int
	FieldSanitized string
	FieldRaw       string
	Metadata       *FieldMetadatas
}

PathParam collects information about the different URL path parameters.

func NewPathParam

func NewPathParam(field string) (*PathParam, error)

NewPathParam returns a correct PathParam value

type PathParams

type PathParams []PathParam

PathParams is a slice of PathParams

type QSParameter

type QSParameter struct {
	Key      string // Which key
	Field    string // goes to which field in a go struct
	Type     string // should have what type
	Metadata *FieldMetadatas
}

QSParameter represents the information of the mapping between parameters transported in the query string and how they map to a go struct

type QueryStringKV

type QueryStringKV struct {
	Key    string
	Values []string
}

type QueryStringParam

type QueryStringParam struct {
	Converter string
	Field     string // can also be more deep:
}

QueryStringParam is provides all the information nessesary for the code generation to map on query string parameter to a go field

type QueryStringParams

type QueryStringParams []QSParameter

QueryStringParams is a collection of query string parameter definitions The Format of a Query string has the following format: "key1=<field1:type1>&key2=<field2:type1>" The <> around field:type can be omitted Semantic: The value for key1 will be mapped to the field field1 in a go struct and is expected to have type type1 Supported types are int, string, float, bool, bytes Bytes are expected to be in Base64-URL (RFC 4648 Section 5)

func NewQueryStringParams

func NewQueryStringParams(definition string) (*QueryStringParams, error)

NewQueryStringParams creates at new QueryString from the given definition string

func (*QueryStringParams) GetParamForKey

func (q *QueryStringParams) GetParamForKey(key string) *QSParameter

GetParamForKey searches for the param with the given key in the QueryString. If non is found nil is returned.

type Registry

type Registry struct {
	Files    Files
	Service  *Service
	RootFile *File
	Messages Messages
	Enums    Enums
	Package  string
}

The Registry is the root for registering the Types found in the protobuf structures from the compiler

func New

New createsa new Registry that will read all the information neede from the given CodeGeneratorRequest

type Service

type Service struct {
	Type     *descriptorpb.ServiceDescriptorProto
	Registry *Registry
	File     *File

	Package       string
	GoPackage     string
	Name          string
	Imports       []string
	BaseURI       string
	Methods       Methods
	Comment       string
	Index         int
	TargetPackage string
	Version       string
}

Service wraps a ServiceDescriptorProto with additions for code Generation

func (*Service) GetMappedMethods

func (s *Service) GetMappedMethods() []*Method

GetMappedMethods returns all the Methods of the currenct service that have a MethodMap extension Only those with a MethodMap extension will be exposed on the REST interface

func (*Service) HasServiceMapExtension

func (s *Service) HasServiceMapExtension() bool

func (*Service) RegisterMethod

func (s *Service) RegisterMethod(method *descriptorpb.MethodDescriptorProto)

func (*Service) ServiceType

func (s *Service) ServiceType() string

ServiceType returns the name of the GRPC service, which will be used by the REST endpoints.

type SortedParsedQueryString

type SortedParsedQueryString []QueryStringKV

Jump to

Keyboard shortcuts

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