Documentation ¶
Overview ¶
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
This file is part of protoc-gen-elmer.
Protoc-gen-elmer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Protoc-gen-elmer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Protoc-gen-elmer. If not, see <https://www.gnu.org/licenses/>.
Index ¶
- func FormatFile(plugin *protogen.Plugin, path string, file *protogen.GeneratedFile) *protogen.GeneratedFile
- func GenerateCodec(m *Module, g *protogen.GeneratedFile) bool
- func GenerateFuzzTests(m *Module, g *protogen.GeneratedFile) bool
- func GenerateTwirp(m *Module, g *protogen.GeneratedFile) bool
- type CommentSet
- type Comments
- type ElmRef
- type ElmType
- type Field
- type Module
- type Oneof
- type OneofVariant
- type Oneofs
- type ProtoPackage
- type RPC
- type RPCs
- type Record
- type Records
- type Service
- type Services
- type Union
- type Unions
- type Variant
- type VariantAlias
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatFile ¶
func FormatFile(plugin *protogen.Plugin, path string, file *protogen.GeneratedFile) *protogen.GeneratedFile
Formats our Elm code and returns the replacement File. Errors are passed to plugin.Error. Assumes `elm-format` is in `$PATH`
func GenerateCodec ¶
func GenerateCodec(m *Module, g *protogen.GeneratedFile) bool
Generates Elm decoders and encoders (making a codec) to a file
func GenerateFuzzTests ¶
func GenerateFuzzTests(m *Module, g *protogen.GeneratedFile) bool
func GenerateTwirp ¶
func GenerateTwirp(m *Module, g *protogen.GeneratedFile) bool
Types ¶
type CommentSet ¶
Describes a set of comments from the Protobuf source
type Comments ¶
type Comments string
Specialised Elm comments. Has a stringer method that wraps itself in dash comments (--)
type ElmRef ¶
type ElmRef struct {
Module, ID string
}
Elm reference pointing an identifier e.g., a type or function in another module. Module is blank for local references.
type ElmType ¶
Speciality reference for a codegen type that has our derived functions. Refs are never nil. The fuzzer assumes a reference to another module with the "Tests" suffix (see `NewModule`)
type Field ¶
type Field struct { Label string Desc protoreflect.FieldDescriptor Oneof *Oneof Comments *CommentSet }
A record field. Desc may be nil if it's a non-synthetic Oneof.
type Module ¶
type Module struct { ProtoPackage string Name, Path string Imports []string Unions Unions Oneofs Oneofs Records Records Services Services // contains filtered or unexported fields }
Top-level structures describing an Elm Module
func NewModule ¶
func NewModule(suffix string, input *ProtoPackage) *Module
Entry point for elmgen. Builds an Elm module from a given proto File. The module name may be suffixed to allow for different derivative use cases e.g., a codec with no suffix and the suffix "Twirp" for a client could live alongside each other.
func (*Module) NewElmType ¶
Creates a new Elm type reference (uppercase first char) from a proto ident
func (*Module) NewElmValue ¶
Creates a new Elm value (lowercase first char) from a proto ident. Prefix must be non-empty
type Oneof ¶
type Oneof struct { Type *ElmType IsSynthetic bool Variants []*OneofVariant Comments *CommentSet }
Oneof is a sum type, similar to a Union, whose tags hold a reference to another data type. The data type can be complex (another type like a record or union) or simple (scalar data like a bool). Oneofs are used in records where a field should hold "one and only one" from a set of types. If IsSynthetic is set then it's an optional field with a single choice for its data type which can be present or missing.
type OneofVariant ¶
Describes a Oneof option. Very similar to Variant except it holds a data type as well.
type ProtoPackage ¶
type ProtoPackage struct { Name protoreflect.FullName Generate bool Enums []*protogen.Enum Messages []*protogen.Message Extensions []*protogen.Extension Services []*protogen.Service }
Describes our PB inputs, possibly from multiple files
func FilesToPackages ¶
func FilesToPackages(files []*protogen.File) []*ProtoPackage
Protobuf packages can be made up of multiple files. Merge them into their own packages
type RPC ¶
type RPC struct { ID *ElmRef In, Out *ElmType InStreaming, OutStreaming bool Service protoreflect.FullName Method protoreflect.Name Comments *CommentSet }
Describes an RPC method
type Record ¶
type Record struct { Type *ElmType Fields []*Field Comments *CommentSet }
A record is derived from a Protobuf message
type Service ¶
type Service struct { Label string Methods RPCs Comments *CommentSet }
Represents a grouping of RPC methods. Not necessarily important but used to retain comments
type Union ¶
type Union struct { Type *ElmType Variants []*Variant Aliases []*VariantAlias Comments *CommentSet }
Union is a sum type with simple tags that won't hold data. Always holds at least one variant with the first being the default. Derived from Protobuf enums.
type Variant ¶
type Variant struct { ID *ElmRef Label string Number protoreflect.EnumNumber Comments *CommentSet }
Describes a Union tag
type VariantAlias ¶
type VariantAlias struct { Alias *ElmRef Variant *Variant Comments *CommentSet }
VariantAlias is a Variant with an alternative name and the same wire number. First Variant seen is the real one, subsequent are alternate names.