...

Package proto

import "github.com/emicklei/proto"
Overview
Index

Overview ▾

Index ▾

func Walk(proto *Proto, handlers ...Handler)
type Comment
    func (c *Comment) Accept(v Visitor)
    func (c *Comment) Merge(other *Comment)
    func (c Comment) Message() string
type Documented
type Enum
    func (e *Enum) Accept(v Visitor)
    func (e *Enum) Doc() *Comment
type EnumField
    func (f *EnumField) Accept(v Visitor)
    func (f *EnumField) Doc() *Comment
    func (f *EnumField) IsDeprecated() bool
type Extensions
    func (e *Extensions) Accept(v Visitor)
type Field
    func (f *Field) IsDeprecated() bool
type Group
    func (g *Group) Accept(v Visitor)
    func (g *Group) Doc() *Comment
type Handler
    func WithEnum(apply func(*Enum)) Handler
    func WithImport(apply func(*Import)) Handler
    func WithMessage(apply func(*Message)) Handler
    func WithNormalField(apply func(*NormalField)) Handler
    func WithOneof(apply func(*Oneof)) Handler
    func WithOption(apply func(*Option)) Handler
    func WithPackage(apply func(*Package)) Handler
    func WithRPC(apply func(*RPC)) Handler
    func WithService(apply func(*Service)) Handler
type Import
    func (i *Import) Accept(v Visitor)
    func (i *Import) Doc() *Comment
type Literal
    func (l Literal) SourceRepresentation() string
type LiteralMap
    func (m LiteralMap) Get(key string) (*Literal, bool)
type MapField
    func (f *MapField) Accept(v Visitor)
    func (f *MapField) Doc() *Comment
type Message
    func (m *Message) Accept(v Visitor)
    func (m *Message) Doc() *Comment
type NamedLiteral
type NoopVisitor
    func (n NoopVisitor) VisitComment(e *Comment)
    func (n NoopVisitor) VisitEnum(e *Enum)
    func (n NoopVisitor) VisitEnumField(i *EnumField)
    func (n NoopVisitor) VisitExtensions(e *Extensions)
    func (n NoopVisitor) VisitGroup(g *Group)
    func (n NoopVisitor) VisitImport(i *Import)
    func (n NoopVisitor) VisitMapField(f *MapField)
    func (n NoopVisitor) VisitMessage(m *Message)
    func (n NoopVisitor) VisitNormalField(i *NormalField)
    func (n NoopVisitor) VisitOneof(o *Oneof)
    func (n NoopVisitor) VisitOneofField(o *OneOfField)
    func (n NoopVisitor) VisitOption(o *Option)
    func (n NoopVisitor) VisitPackage(p *Package)
    func (n NoopVisitor) VisitRPC(r *RPC)
    func (n NoopVisitor) VisitReserved(r *Reserved)
    func (n NoopVisitor) VisitService(v *Service)
    func (n NoopVisitor) VisitSyntax(s *Syntax)
type NormalField
    func (f *NormalField) Accept(v Visitor)
    func (f *NormalField) Doc() *Comment
type OneOfField
    func (o *OneOfField) Accept(v Visitor)
    func (o *OneOfField) Doc() *Comment
type Oneof
    func (o *Oneof) Accept(v Visitor)
    func (o *Oneof) Doc() *Comment
type Option
    func (o *Option) Accept(v Visitor)
    func (o *Option) Doc() *Comment
type Package
    func (p *Package) Accept(v Visitor)
    func (p *Package) Doc() *Comment
type Parser
    func NewParser(r io.Reader) *Parser
    func (p *Parser) Filename(f string)
    func (p *Parser) Parse() (*Proto, error)
type Proto
    func (proto *Proto) Accept(v Visitor)
type RPC
    func (r *RPC) Accept(v Visitor)
    func (r *RPC) Doc() *Comment
type Range
    func (r Range) SourceRepresentation() string
type Reserved
    func (r *Reserved) Accept(v Visitor)
type Service
    func (s *Service) Accept(v Visitor)
    func (s *Service) Doc() *Comment
type Syntax
    func (s *Syntax) Accept(v Visitor)
    func (s *Syntax) Doc() *Comment
type Visitee
type Visitor

Package files

comment.go enum.go extensions.go field.go group.go import.go message.go noop_visitor.go oneof.go option.go package.go parent_accessor.go parser.go proto.go range.go reserved.go service.go syntax.go token.go visitor.go walk.go

func Walk

func Walk(proto *Proto, handlers ...Handler)

Walk recursively pays a visit to all Visitees of a Proto and calls each handler with it.

type Comment

Comment one or more comment text lines, either in c- or c++ style.

type Comment struct {
    Position scanner.Position
    // Lines are comment text lines without prefixes //, ///, /* or suffix */
    Lines      []string
    Cstyle     bool // refers to /* ... */,  C++ style is using //
    ExtraSlash bool // is true if the comment starts with 3 slashes
}

func (*Comment) Accept

func (c *Comment) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Comment) Merge

func (c *Comment) Merge(other *Comment)

Merge appends all lines from the argument comment.

func (Comment) Message

func (c Comment) Message() string

Message returns the first line or empty if no lines.

type Documented

Documented is for types that may have an associated comment (not inlined).

type Documented interface {
    Doc() *Comment
}

type Enum

Enum definition consists of a name and an enum body.

type Enum struct {
    Position scanner.Position
    Comment  *Comment
    Name     string
    Elements []Visitee
    Parent   Visitee
}

func (*Enum) Accept

func (e *Enum) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Enum) Doc

func (e *Enum) Doc() *Comment

Doc is part of Documented

type EnumField

EnumField is part of the body of an Enum.

type EnumField struct {
    Position scanner.Position
    Comment  *Comment
    Name     string
    Integer  int
    // ValueOption is deprecated, use Elements instead
    ValueOption   *Option
    Elements      []Visitee // such as Option and Comment
    InlineComment *Comment
    Parent        Visitee
}

func (*EnumField) Accept

func (f *EnumField) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*EnumField) Doc

func (f *EnumField) Doc() *Comment

Doc is part of Documented

func (*EnumField) IsDeprecated

func (f *EnumField) IsDeprecated() bool

IsDeprecated returns true if the option "deprecated" is set with value "true".

type Extensions

Extensions declare that a range of field numbers in a message are available for third-party extensions. proto2 only

type Extensions struct {
    Position      scanner.Position
    Comment       *Comment
    Ranges        []Range
    InlineComment *Comment
    Parent        Visitee
}

func (*Extensions) Accept

func (e *Extensions) Accept(v Visitor)

Accept dispatches the call to the visitor.

type Field

Field is an abstract message field.

type Field struct {
    Position      scanner.Position
    Comment       *Comment
    Name          string
    Type          string
    Sequence      int
    Options       []*Option
    InlineComment *Comment
    Parent        Visitee
}

func (*Field) IsDeprecated

func (f *Field) IsDeprecated() bool

IsDeprecated returns true if the option "deprecated" is set with value "true".

type Group

Group represents a (proto2 only) group. https://developers.google.com/protocol-buffers/docs/reference/proto2-spec#group_field

type Group struct {
    Position scanner.Position
    Comment  *Comment
    Name     string
    Optional bool
    Repeated bool
    Required bool
    Sequence int
    Elements []Visitee
    Parent   Visitee
}

func (*Group) Accept

func (g *Group) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Group) Doc

func (g *Group) Doc() *Comment

Doc is part of Documented

type Handler

Handler is a type of function that accepts a Visitee.

type Handler func(v Visitee)

func WithEnum

func WithEnum(apply func(*Enum)) Handler

WithEnum returns a Handler that will call the apply function when the Visitee is a Enum.

func WithImport

func WithImport(apply func(*Import)) Handler

WithImport returns a Handler that will call the apply function when the Visitee is an Import.

func WithMessage

func WithMessage(apply func(*Message)) Handler

WithMessage returns a Handler that will call the apply function when the Visitee is a Message.

func WithNormalField

func WithNormalField(apply func(*NormalField)) Handler

WithNormalField returns a Handler that will call the apply function when the Visitee is a NormalField.

func WithOneof

func WithOneof(apply func(*Oneof)) Handler

WithOneof returns a Handler that will call the apply function when the Visitee is a Oneof.

func WithOption

func WithOption(apply func(*Option)) Handler

WithOption returns a Handler that will call the apply function when the Visitee is a Option.

func WithPackage

func WithPackage(apply func(*Package)) Handler

WithPackage returns a Handler that will call the apply function when the Visitee is a Package.

func WithRPC

func WithRPC(apply func(*RPC)) Handler

WithRPC returns a Handler that will call the apply function when the Visitee is a RPC.

func WithService

func WithService(apply func(*Service)) Handler

WithService returns a Handler that will call the apply function when the Visitee is a Service.

type Import

Import holds a filename to another .proto definition.

type Import struct {
    Position      scanner.Position
    Comment       *Comment
    Filename      string
    Kind          string // weak, public, <empty>
    InlineComment *Comment
    Parent        Visitee
}

func (*Import) Accept

func (i *Import) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Import) Doc

func (i *Import) Doc() *Comment

Doc is part of Documented

type Literal

Literal represents intLit,floatLit,strLit or boolLit or a nested structure thereof.

type Literal struct {
    Position scanner.Position
    Source   string
    IsString bool

    // It not nil then the entry is actually a comment with line(s)
    // modelled this way because Literal is not an elementContainer
    Comment *Comment

    // The rune use to delimit the string value (only valid iff IsString)
    QuoteRune rune

    // literal value can be an array literal value (even nested)
    Array []*Literal

    // literal value can be a map of literals (even nested)
    // DEPRECATED: use OrderedMap instead
    Map map[string]*Literal

    // literal value can be a map of literals (even nested)
    // this is done as pairs of name keys and literal values so the original ordering is preserved
    OrderedMap LiteralMap
}

func (Literal) SourceRepresentation

func (l Literal) SourceRepresentation() string

SourceRepresentation returns the source (use the same rune that was used to delimit the string).

type LiteralMap

LiteralMap is like a map of *Literal but preserved the ordering. Can be iterated yielding *NamedLiteral values.

type LiteralMap []*NamedLiteral

func (LiteralMap) Get

func (m LiteralMap) Get(key string) (*Literal, bool)

Get returns a Literal from the map.

type MapField

MapField represents a map entry in a message.

type MapField struct {
    *Field
    KeyType string
}

func (*MapField) Accept

func (f *MapField) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*MapField) Doc

func (f *MapField) Doc() *Comment

Doc is part of Documented

type Message

Message consists of a message name and a message body.

type Message struct {
    Position scanner.Position
    Comment  *Comment
    Name     string
    IsExtend bool
    Elements []Visitee
    Parent   Visitee
}

func (*Message) Accept

func (m *Message) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Message) Doc

func (m *Message) Doc() *Comment

Doc is part of Documented

type NamedLiteral

NamedLiteral associates a name with a Literal

type NamedLiteral struct {
    *Literal
    Name string
    // PrintsColon is true when the Name must be printed with a colon suffix
    PrintsColon bool
}

type NoopVisitor

NoopVisitor is a no-operation visitor that can be used when creating your own visitor that is interested in only one or a few types. It implements the Visitor interface.

type NoopVisitor struct{}

func (NoopVisitor) VisitComment

func (n NoopVisitor) VisitComment(e *Comment)

VisitComment is part of Visitor interface

func (NoopVisitor) VisitEnum

func (n NoopVisitor) VisitEnum(e *Enum)

VisitEnum is part of Visitor interface

func (NoopVisitor) VisitEnumField

func (n NoopVisitor) VisitEnumField(i *EnumField)

VisitEnumField is part of Visitor interface

func (NoopVisitor) VisitExtensions

func (n NoopVisitor) VisitExtensions(e *Extensions)

VisitExtensions is part of Visitor interface

func (NoopVisitor) VisitGroup

func (n NoopVisitor) VisitGroup(g *Group)

VisitGroup is part of Visitor interface

func (NoopVisitor) VisitImport

func (n NoopVisitor) VisitImport(i *Import)

VisitImport is part of Visitor interface

func (NoopVisitor) VisitMapField

func (n NoopVisitor) VisitMapField(f *MapField)

VisitMapField is part of Visitor interface

func (NoopVisitor) VisitMessage

func (n NoopVisitor) VisitMessage(m *Message)

VisitMessage is part of Visitor interface

func (NoopVisitor) VisitNormalField

func (n NoopVisitor) VisitNormalField(i *NormalField)

VisitNormalField is part of Visitor interface

func (NoopVisitor) VisitOneof

func (n NoopVisitor) VisitOneof(o *Oneof)

VisitOneof is part of Visitor interface

func (NoopVisitor) VisitOneofField

func (n NoopVisitor) VisitOneofField(o *OneOfField)

VisitOneofField is part of Visitor interface

func (NoopVisitor) VisitOption

func (n NoopVisitor) VisitOption(o *Option)

VisitOption is part of Visitor interface

func (NoopVisitor) VisitPackage

func (n NoopVisitor) VisitPackage(p *Package)

VisitPackage is part of Visitor interface

func (NoopVisitor) VisitRPC

func (n NoopVisitor) VisitRPC(r *RPC)

VisitRPC is part of Visitor interface

func (NoopVisitor) VisitReserved

func (n NoopVisitor) VisitReserved(r *Reserved)

VisitReserved is part of Visitor interface

func (NoopVisitor) VisitService

func (n NoopVisitor) VisitService(v *Service)

VisitService is part of Visitor interface

func (NoopVisitor) VisitSyntax

func (n NoopVisitor) VisitSyntax(s *Syntax)

VisitSyntax is part of Visitor interface

type NormalField

NormalField represents a field in a Message.

type NormalField struct {
    *Field
    Repeated bool
    Optional bool // proto2
    Required bool // proto2
}

func (*NormalField) Accept

func (f *NormalField) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*NormalField) Doc

func (f *NormalField) Doc() *Comment

Doc is part of Documented

type OneOfField

OneOfField is part of Oneof.

type OneOfField struct {
    *Field
}

func (*OneOfField) Accept

func (o *OneOfField) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*OneOfField) Doc

func (o *OneOfField) Doc() *Comment

Doc is part of Documented Note: although Doc() is defined on Field, it must be implemented here as well.

type Oneof

Oneof is a field alternate.

type Oneof struct {
    Position scanner.Position
    Comment  *Comment
    Name     string
    Elements []Visitee
    Parent   Visitee
}

func (*Oneof) Accept

func (o *Oneof) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Oneof) Doc

func (o *Oneof) Doc() *Comment

Doc is part of Documented

type Option

Option is a protoc compiler option

type Option struct {
    Position   scanner.Position
    Comment    *Comment
    Name       string
    Constant   Literal
    IsEmbedded bool
    // AggregatedConstants is DEPRECATED. These Literals are populated into Constant.OrderedMap
    AggregatedConstants []*NamedLiteral
    InlineComment       *Comment
    Parent              Visitee
}

func (*Option) Accept

func (o *Option) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Option) Doc

func (o *Option) Doc() *Comment

Doc is part of Documented

type Package

Package specifies the namespace for all proto elements.

type Package struct {
    Position      scanner.Position
    Comment       *Comment
    Name          string
    InlineComment *Comment
    Parent        Visitee
}

func (*Package) Accept

func (p *Package) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Package) Doc

func (p *Package) Doc() *Comment

Doc is part of Documented

type Parser

Parser represents a parser.

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

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser.

func (*Parser) Filename

func (p *Parser) Filename(f string)

Filename is for reporting. Optional.

func (*Parser) Parse

func (p *Parser) Parse() (*Proto, error)

Parse parses a proto definition. May return a parse or scanner error.

type Proto

Proto represents a .proto definition

type Proto struct {
    Filename string
    Elements []Visitee
}

func (*Proto) Accept

func (proto *Proto) Accept(v Visitor)

Accept dispatches the call to the visitor.

type RPC

RPC represents an rpc entry in a message.

type RPC struct {
    Position       scanner.Position
    Comment        *Comment
    Name           string
    RequestType    string
    StreamsRequest bool
    ReturnsType    string
    StreamsReturns bool
    Elements       []Visitee
    InlineComment  *Comment
    Parent         Visitee

    // Options field is DEPRECATED, use Elements instead.
    Options []*Option
}

func (*RPC) Accept

func (r *RPC) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*RPC) Doc

func (r *RPC) Doc() *Comment

Doc is part of Documented

type Range

Range is to specify number intervals (with special end value "max")

type Range struct {
    From, To int
    Max      bool
}

func (Range) SourceRepresentation

func (r Range) SourceRepresentation() string

SourceRepresentation return a single number if from = to. Returns <from> to <to> otherwise unless Max then return <from> to max.

type Reserved

Reserved statements declare a range of field numbers or field names that cannot be used in a message.

type Reserved struct {
    Position      scanner.Position
    Comment       *Comment
    Ranges        []Range
    FieldNames    []string
    InlineComment *Comment
    Parent        Visitee
}

func (*Reserved) Accept

func (r *Reserved) Accept(v Visitor)

Accept dispatches the call to the visitor.

type Service

Service defines a set of RPC calls.

type Service struct {
    Position scanner.Position
    Comment  *Comment
    Name     string
    Elements []Visitee
    Parent   Visitee
}

func (*Service) Accept

func (s *Service) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Service) Doc

func (s *Service) Doc() *Comment

Doc is part of Documented

type Syntax

Syntax should have value "proto"

type Syntax struct {
    Position      scanner.Position
    Comment       *Comment
    Value         string
    InlineComment *Comment
    Parent        Visitee
}

func (*Syntax) Accept

func (s *Syntax) Accept(v Visitor)

Accept dispatches the call to the visitor.

func (*Syntax) Doc

func (s *Syntax) Doc() *Comment

Doc is part of Documented

type Visitee

Visitee is implemented by all Proto elements.

type Visitee interface {
    Accept(v Visitor)
    // contains filtered or unexported methods
}

type Visitor

Visitor is for dispatching Proto elements.

type Visitor interface {
    //VisitProto(p *Proto)
    VisitMessage(m *Message)
    VisitService(v *Service)
    VisitSyntax(s *Syntax)
    VisitPackage(p *Package)
    VisitOption(o *Option)
    VisitImport(i *Import)
    VisitNormalField(i *NormalField)
    VisitEnumField(i *EnumField)
    VisitEnum(e *Enum)
    VisitComment(e *Comment)
    VisitOneof(o *Oneof)
    VisitOneofField(o *OneOfField)
    VisitReserved(r *Reserved)
    VisitRPC(r *RPC)
    VisitMapField(f *MapField)
    // proto2
    VisitGroup(g *Group)
    VisitExtensions(e *Extensions)
}