state

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownDirectionDirection = iota
	ParentToChild
	ChildToParent
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction uint

type MessageDescriptor

type MessageDescriptor struct {
	Descriptor    *descriptor.DescriptorProto
	StructureName string
	SourceName    string
}

MessageDescriptor is a descriptor for a message.

type Messages

type Messages []*descriptorpb.DescriptorProto

func (Messages) FindByName

func (t Messages) FindByName(name string) *descriptorpb.DescriptorProto

func (Messages) String

func (t Messages) String() string

type NestedMessages

type NestedMessages map[string]*MessageDescriptor

func (NestedMessages) CheckIsRelation

func (t NestedMessages) CheckIsRelation(f *descriptorpb.FieldDescriptorProto) bool

func (NestedMessages) Get

func (NestedMessages) GetByField

func (NestedMessages) GetByFieldDescriptor

GetByFieldDescriptor gets the table by the given descriptor.

func (NestedMessages) GetDescriptor

func (t NestedMessages) GetDescriptor(name string) (*descriptorpb.DescriptorProto, bool)

GetDescriptor returns the table with the given name.

func (NestedMessages) IsExist

IsExist checks if the given name exists in the Messages.

func (NestedMessages) IsJSON

IsJSON returns true if the field is a JSON field.

func (NestedMessages) String

func (t NestedMessages) String() string

String returns a string representation of the NestedMessages.

type NestedTableVal

type NestedTableVal struct {
	StructureName string
	HasType       bool
}

type Relation

type Relation struct {
	RelationDescriptor *descriptor.DescriptorProto
	ParentDescriptor   *descriptor.DescriptorProto
	Descriptor         *descriptor.FieldDescriptorProto
	Field              string
	Direction          Direction
	Reference          string
	TableName          string
	StructName         string
	Store              string
	Many               bool
	AllowSubCreating   bool
	UseTag             bool
}

type RelationType

type RelationType string

func NewRelationType

func NewRelationType(messageName string, structureName string) RelationType

NewRelationType creates a new relation type.

func (RelationType) String

func (r RelationType) String() string

Relation SingleTypes.

type Relations

type Relations map[RelationType]*Relation

func (Relations) Delete

func (r Relations) Delete(name string)

func (Relations) Get

func (r Relations) Get(name string) (*Relation, bool)

func (Relations) GetByFieldDescriptor

func (r Relations) GetByFieldDescriptor(f *descriptorpb.FieldDescriptorProto) *Relation

GetByFieldDescriptor returns the Relation by the given FieldDescriptorProto.

func (Relations) IsExist

IsExist checks if the given name exists in the Messages.

func (Relations) String

func (r Relations) String() string

type SingleType

type SingleType struct {
	ParentDescriptor *descriptor.DescriptorProto
	Descriptor       *descriptor.FieldDescriptorProto

	ParentStructureName string
	FieldName           string
	FieldType           string
	SourceType          string
	SourceName          string
	StructureName       string
	Repeated            bool
}

type SingleTypes

type SingleTypes map[string]SingleType

SingleTypes is a type for how to generate json statements.

func (SingleTypes) Delete

func (j SingleTypes) Delete(name string)

func (SingleTypes) ExistByName

func (j SingleTypes) ExistByName(name string) bool

func (SingleTypes) Get

func (j SingleTypes) Get(name string) (SingleType, bool)

func (SingleTypes) GetByFieldDescriptor

func (j SingleTypes) GetByFieldDescriptor(f *descriptorpb.FieldDescriptorProto) *SingleType

func (SingleTypes) GetByName

func (j SingleTypes) GetByName(name string) *SingleType

func (SingleTypes) IsExist

IsExist checks if the given name exists in the Messages.

func (SingleTypes) String

func (j SingleTypes) String() string

String returns a string representation of the SingleTypes.

type State

type State struct {
	Provider          string // Provider is the Provider of the plugin.
	PackageName       string // PackageName is the package name of the plugin.
	FileName          string // FileName is the file name of the plugin.
	Version           string // Version is the Version of the plugin.
	ProtocVersion     string // ProtocVersion is the Version of protoc.
	FileToGenerate    string // FileToGenerate is the file to generate.
	IncludeConnection bool   // IncludeConnection is the flag to include connection in the generated code.

	Imports        importpkg.ImportSet // Imports is the set of Imports.
	Relations      Relations           // Relations is the set of Relations Messages.
	Messages       Messages            // Messages is the set of root Messages.
	NestedMessages NestedMessages      // NestedMessages is the set of nested Messages.

	// SingleTypes is the set of single types. example: type UserNames []string
	// used for generating json statements.
	SingleTypes SingleTypes
}

State is the state of the plugin.

func NewState

func NewState(
	request *plugingo.CodeGeneratorRequest,
) *State

func (*State) ImportsFromTable

func (s *State) ImportsFromTable(tables []Templater)

ImportsFromTable Imports the given table.

func (*State) IsExistInNestedTables

func (s *State) IsExistInNestedTables(name string) bool

IsExistInNestedTables checks if the given name exists in the nested Messages.

func (*State) IsExistInTables

func (s *State) IsExistInTables(name string) bool

IsExistInTables checks if the given name exists in the Messages.

func (*State) String

func (s *State) String() string

type Templater

type Templater interface {
	BuildTemplate() string
	Imports() importpkg.ImportSet
}

Templater is an interface for generating templates.

Jump to

Keyboard shortcuts

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