drivergen

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize() error

Initialize sets up drivergen for use. It must be called or all of the templates will be nil.

Types

type Builtin

type Builtin string

Builtin represent types that are built into the IDL.

const (
	Collection     Builtin = "collection"
	ReadPreference Builtin = "read preference"
	ReadConcern    Builtin = "read concern"
	WriteConcern   Builtin = "write concern"
	CommandMonitor Builtin = "command monitor"
	ClientSession  Builtin = "client session"
	ClusterClock   Builtin = "cluster clock"
	Selector       Builtin = "selector"
	Database       Builtin = "database"
	Deployment     Builtin = "deployment"
)

These constants are the built in types.

func (Builtin) Documentation

func (b Builtin) Documentation() string

Documentation returns the GoDoc documentation for this built-in.

func (Builtin) ExecuteName

func (b Builtin) ExecuteName() string

ExecuteName provides the name used when setting this built-in on a driver.Operation.

func (Builtin) ReferenceName

func (b Builtin) ReferenceName() string

ReferenceName returns the short name used to refer to this built in. It is used as the field name in the struct and as the variable name for the setter.

func (Builtin) SetterName

func (b Builtin) SetterName() string

SetterName returns the name to be used when creating a setter for this built-in.

func (Builtin) Type

func (b Builtin) Type() string

Type returns the Go type for this built-in.

type BuiltinResponseType

type BuiltinResponseType string

BuiltinResponseType is the type used to define built in response types.

const (
	BatchCursor BuiltinResponseType = "batch cursor"
)

These constants represents the different built in response types.

type Command

type Command struct {
	Name      string
	Parameter string
	Database  bool
}

Command holds the command serialization specific information for an operation.

type LegacyOperation

type LegacyOperation string

LegacyOperation enables legacy versions of find, getMore, or killCursors operations.

const (
	LegacyFind            LegacyOperation = "find"
	LegacyGetMore         LegacyOperation = "getMore"
	LegacyKillCursors     LegacyOperation = "killCursors"
	LegacyListCollections LegacyOperation = "listCollections"
	LegacyListIndexes     LegacyOperation = "listIndexes"
)

These constants are the various legacy operations that can be generated.

type Operation

type Operation struct {
	Name           string
	Documentation  string
	Version        int
	DriverInternal bool
	Properties     Properties
	Command        Command
	Request        map[string]RequestField
	Response       Response
	// contains filtered or unexported fields
}

Operation is the top-level configuration type. It's the direct representation of an operation TOML file.

func ParseFile

func ParseFile(filename, packagename string) (Operation, error)

ParseFile will construct an Operation using the TOML in filename. The Operation will have the package name set to packagename.

func (Operation) CommandMethod

func (op Operation) CommandMethod() (string, error)

CommandMethod returns the code required to transform the operation into a command. This code only returns the contents of the command method, without the function definition and return.

func (Operation) ConstructorFields

func (op Operation) ConstructorFields() []string

ConstructorFields returns a slice of name name pairs that set fields in a newly instantiated operation.

func (Operation) ConstructorParameters

func (op Operation) ConstructorParameters() string

ConstructorParameters builds the parameter names and types for the operation constructor.

func (Operation) EscapeDocumentation

func (Operation) EscapeDocumentation(doc string) string

EscapeDocumentation will add the required // in front of each line of documentation.

func (Operation) Generate

func (op Operation) Generate(w io.Writer) error

Generate creates the operation type and associated response types and writes them to w.

func (Operation) PackageName

func (op Operation) PackageName() string

PackageName returns the package name to use when generating the operation.

func (Operation) ResultType

func (op Operation) ResultType() string

ResultType returns the type to use as the result of running this operation.

func (Operation) ShortName

func (op Operation) ShortName() string

ShortName returns the receiver used for this operation.

func (Operation) Title

func (op Operation) Title(name string) string

Title wraps strings.Title for use in templates.

type Properties

type Properties struct {
	Disabled                       []Builtin
	Enabled                        []Builtin
	Retryable                      Retryable
	Batches                        string
	Legacy                         LegacyOperation
	MinimumWriteConcernWireVersion int
	MinimumReadConcernWireVersion  int
}

Properties represent general properties of the operation.

func (Properties) Builtins

func (p Properties) Builtins() []Builtin

Builtins returns a slice of built-ins that is the combination of the non-disabled default built-ins plus any enabled non-default built-ins.

func (Properties) BuiltinsMap

func (p Properties) BuiltinsMap() map[Builtin]bool

BuiltinsMap returns a map with the builtins that enabled.

func (Properties) ExecuteBuiltins

func (p Properties) ExecuteBuiltins() []Builtin

ExecuteBuiltins returns the builtins that need to be set on the driver.Operation for the properties set.

func (Properties) IsEnabled

func (p Properties) IsEnabled(builtin string) Builtin

IsEnabled returns a Builtin if the string that matches that built-in is enabled. If it's not, an empty string is returned.

func (Properties) LegacyOperationKind

func (p Properties) LegacyOperationKind() string

LegacyOperationKind returns the corresponding LegacyOperationKind value for an operation.

type RequestField

type RequestField struct {
	Type                   string
	Slice                  bool
	Constructor            bool
	Variadic               bool
	Skip                   bool
	Documentation          string
	MinWireVersion         int
	MinWireVersionRequired int
	KeyName                string
}

RequestField represents an individual operation field.

func (RequestField) Command

func (rf RequestField) Command(name, accessor string) string

Command returns a string function that sets the key to name and value to the RequestField type. It uses accessor to access the parameter. The accessor parameter should be the shortname of the operation and the name of the field of the property used for the command name. For example, if the shortname is "eo" and the field is "collection" then accessor should be "eo.collection".

func (RequestField) DeclarationType

func (rf RequestField) DeclarationType() string

DeclarationType returns this field's type for use in a struct type declaration.

func (RequestField) ParameterType

func (rf RequestField) ParameterType() string

ParameterType returns this field's type for use as a parameter argument.

func (RequestField) PointerType

func (rf RequestField) PointerType() bool

PointerType returns true if the request field is a pointer type and the setter should take the address when setting via a setter method.

type Response

type Response struct {
	Name  string
	Type  string
	Field map[string]ResponseField
}

Response represents a response type to generate.

func (Response) BuildMethod

func (r Response) BuildMethod() (string, error)

BuildMethod handles creating the body of a method to create a response from a BSON response document.

TODO(GODRIVER-1094): This method is hacky because we're not using nested templates like we should be. Each template should be registered and we should be calling the template to create it.

func (Response) ShortName

func (r Response) ShortName() string

ShortName returns the short name used when constructing a response.

type ResponseField

type ResponseField struct {
	Type          string
	Documentation string
}

ResponseField is an individual field of a response.

func (ResponseField) DeclarationType

func (rf ResponseField) DeclarationType() string

DeclarationType returns the field's type for use in a struct type declaration.

type Retryable

type Retryable struct {
	Mode RetryableMode
	Type RetryableType
}

Retryable represents retryable information for an operation.

type RetryableMode

type RetryableMode string

RetryableMode are the configuration representations of the retryability modes.

const (
	RetryableOnce           RetryableMode = "once"
	RetryableOncePerCommand RetryableMode = "once per command"
	RetryableContext        RetryableMode = "context"
)

These constants are the various retryability modes.

type RetryableType

type RetryableType string

RetryableType instances are the configuration representation of a kind of retryability.

const (
	RetryableWrites RetryableType = "writes"
	RetryableReads  RetryableType = "reads"
)

These constants are the various retryable types.

Jump to

Keyboard shortcuts

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