Documentation
¶
Overview ¶
Package proto houses all logic for processing protocol buffers into an easy-to-use structure for creating diagrams outputFlag. The intention is to support a verity of diagram types such as Mermaid and Plant UML. Since Go does not support logical libraries, these are loaded via direction implementations. ToMermaid() and ToPlantUML(). Please note, since this is a Go implementation, the Plant UML diagrams are syntax only, and the Java diagram compiler is not currently used.
Index ¶
- Constants
- Variables
- func ComputeFormat(length int, value string) string
- func DashLine(length int) string
- func EnumToMarkdown(enum *Enum, wc *WriterConfig) (body string, diagram string)
- func EnumToMermaid(e *Enum) string
- func Execute()
- func FormatLine(in string) string
- func FormatParametersForMermaid(in []*Parameter) string
- func FormatRelationships(name string, in []*Parameter) string
- func FormatServiceParameter(parameters []*Parameter) string
- func HandleDefaultAttribute(out *Attribute, split []string)
- func HandleEnums(enums []*Enum, wc *WriterConfig) (body string)
- func HandleMap(out *Attribute, split []string)
- func HandleMessages(messages []*Message, wc *WriterConfig) (body string)
- func HandleOptional(out *Attribute, split []string)
- func HandleRepeated(out *Attribute, split []string)
- func Join(joinCharacter string, values ...string) string
- func MessageToMarkdown(message *Message, wc *WriterConfig) (body string, diagram string)
- func MessageToMermaid(m *Message) string
- func NormalizeName(in string) string
- func PackageFormatImports(p *Package) (body string)
- func PackageFormatOptions(p *Package) (body string)
- func PackageToMarkDown(p *Package, wc *WriterConfig) string
- func PackageToMermaid(p *Package) string
- func ParseInArgs(values []string, rpc *Rpc)
- func ParseOrdinal(in string) int
- func ParseReturnArgs(values []string, rpc *Rpc)
- func ReadFileToArray(file *os.File) []string
- func RemoveDoubleQuotes(in string) string
- func RemoveNameQualification(in string) string
- func RemoveSemicolon(in string) string
- func ServiceToMarkdown(s *Service, wc *WriterConfig) string
- func ServiceToMermaid(s *Service) string
- func SetDebug(debug bool)
- func ToMermaid(title string, rt interface{}) string
- type Annotation
- type Attribute
- type AttributeVisitor
- type Comment
- type CommentVisitor
- type Enum
- type EnumValue
- type EnumValueVisitor
- type EnumVisitor
- type Import
- type ImportVisitor
- type Line
- type Logger
- type MarkdownTable
- type Message
- type MessageVisitor
- type NamedValue
- type Option
- type OptionVisitor
- type Package
- type PackageVisitor
- type Parameter
- type ProtobufFileScanner
- func (sw ProtobufFileScanner) Buffer(buf []byte, max int)
- func (sw ProtobufFileScanner) Bytes() []byte
- func (sw ProtobufFileScanner) Err() error
- func (sw ProtobufFileScanner) ReadLine() *Line
- func (sw ProtobufFileScanner) Scan() bool
- func (sw ProtobufFileScanner) Split(splitFunction bufio.SplitFunc)
- func (sw ProtobufFileScanner) Text() string
- type Qualified
- type Reserved
- type ReservedVisitor
- type Rpc
- type RpcOption
- type RpcVisitor
- type Scanner
- type Service
- type ServiceVisitor
- type TestScanner
- type Validatable
- type Visitor
- type WriterConfig
Constants ¶
const ( Protobuf3Types = "double,float,int32,int64,uint32,uint64,sint32,sint64,fixed32,fixed64,sfixed32,sfixed64,bool,string,bytes" PrefixRepeated = "repeated" PrefixMap = "map" PrefixReserved = "reserved" PrefixOptional = "optional" SpaceRemovalRegex = `\s+` Period = "." Empty = "" Space = " " OpenBrace = "{" CloseBrace = "}" OpenBracket = "[" ClosedBracket = "]" Semicolon = ";" Comma = "," Pipe = "|" Hyphen = "-" InlineCommentPrefix = "//" MultiLineCommentInitiator = "/*" MultilineCommentTerminator = "*/" OpenMap = "map<" CloseMap = ">" DoubleQuote = `"` SingleQuote = `'` EndL = "\n" CommentNewLine = `:~:` )
Constants used for parsing and interpretation
const ( InfoColor = "\033[1;32mINFO: %s\033[0m" ErrorColor = "\033[1;31mERROR: %s\033[0m" DebugColor = "\033[1;36mDEBUG: %s\033[0m" )
From gist: https://gist.github.com/ik5/d8ecde700972d4378d87
const (
MarkdownPadding = 2
)
const (
ProtobufSuffix = ".proto"
)
Variables ¶
var InvalidImport = errors.New("invalid import")
InvalidImport = used during import sequence of files.
var Log = &Logger{}
Log is the Package Logger
var RegisteredVisitors []Visitor
var RpcLinePattern = `rpc\s+(.*?)\((.*?)\)\s+returns\s+\((.*?)\)(.*)`
var SpaceRemover *regexp.Regexp
Functions ¶
func ComputeFormat ¶
func EnumToMarkdown ¶
func EnumToMarkdown(enum *Enum, wc *WriterConfig) (body string, diagram string)
func EnumToMermaid ¶
EnumToMermaid formats an Enum into mermaid text.
func FormatLine ¶
func FormatParametersForMermaid ¶
FormatParametersForMermaid formats parameters for services
func FormatRelationships ¶
FormatRelationships formats a service relationship
func FormatServiceParameter ¶
func HandleDefaultAttribute ¶
HandleDefaultAttribute marshals a standard attribute type.
func HandleEnums ¶
func HandleEnums(enums []*Enum, wc *WriterConfig) (body string)
func HandleMap ¶
handleMap marshals the attribute into a Map type by using multiple types for key and value.
func HandleMessages ¶
func HandleMessages(messages []*Message, wc *WriterConfig) (body string)
func HandleOptional ¶
HandleOptional marshals the attribute into an optional representation
func HandleRepeated ¶
HandleRepeated marshals the attribute into a repeated representation, e.g. List.
func MessageToMarkdown ¶
func MessageToMarkdown(message *Message, wc *WriterConfig) (body string, diagram string)
func MessageToMermaid ¶
MessageToMermaid formats a Message into mermaid text
func NormalizeName ¶
func PackageFormatImports ¶
func PackageFormatOptions ¶
func PackageToMarkDown ¶
func PackageToMarkDown(p *Package, wc *WriterConfig) string
func PackageToMermaid ¶
PackageToMermaid formats a Package into Mermaid syntax
func ParseInArgs ¶
func ParseOrdinal ¶
func ParseReturnArgs ¶
func ReadFileToArray ¶
func RemoveDoubleQuotes ¶
func RemoveNameQualification ¶
RemoveNameQualification formats a parameter into a single name, this is due to a limitation in Mermaid that DOES NOT support fully qualified names.
func RemoveSemicolon ¶
func ServiceToMarkdown ¶
func ServiceToMarkdown(s *Service, wc *WriterConfig) string
func ServiceToMermaid ¶
Formats a Service into mermaid text
Types ¶
type Annotation ¶
Annotation is an inline structure applicable only to attributes
func NewAnnotation ¶
func NewAnnotation(name string, value any) *Annotation
NewAnnotation is the Annotation Constructor
func ParseAnnotations ¶
func ParseAnnotations(in string) []*Annotation
ParseAnnotations is used for reading the annotation line and marshalling it into the annotation structure.
type Attribute ¶
type Attribute struct { *Qualified Repeated bool Optional bool Map bool Kind []string Ordinal int Annotations []*Annotation }
An Attribute is a component in the message structure.
func NewAttribute ¶
NewAttribute is the Attribute constructor
type AttributeVisitor ¶
type AttributeVisitor struct { }
Visitor implementation for attributes
func NewAttributeVisitor ¶
func NewAttributeVisitor() *AttributeVisitor
NewAttributeVisitor - Constructor for the AttributeVisitor
func (*AttributeVisitor) CanVisit ¶
func (av *AttributeVisitor) CanVisit(in *Line) bool
CanVisit - Determines if the line is an attribute, it doesn't end in a brace, it's a map, repeated, optional, or can effectively be split
type Comment ¶
type Comment string
Comment is a string with additional methods
func (Comment) ToMarkdownBlockQuote ¶
func (Comment) ToMarkdownText ¶
type CommentVisitor ¶
type CommentVisitor struct { }
CommentVisitor is responsible for reading and recoding comment lines, it DOES NOT handle inline comments because of how the
func (*CommentVisitor) CanVisit ¶
func (cv *CommentVisitor) CanVisit(in *Line) bool
CanVisit Determines if the line is a coment
type EnumValueVisitor ¶
type EnumValueVisitor struct { }
EnumValueVisitor is responsible evaluating and processing Protobuf Enumerations.
func (EnumValueVisitor) CanVisit ¶
func (evv EnumValueVisitor) CanVisit(in *Line) bool
CanVisit determines if the line is an enumeration.
type EnumVisitor ¶
type EnumVisitor struct {
Visitors []Visitor
}
EnumVisitor is responsible for evaluation and marshalling of an Enum entity.
func (*EnumVisitor) CanVisit ¶
func (ev *EnumVisitor) CanVisit(in *Line) bool
CanVisit determines if the current line is an enumeration.
type ImportVisitor ¶
type ImportVisitor struct { }
func (*ImportVisitor) CanVisit ¶
func (iv *ImportVisitor) CanVisit(in *Line) bool
type Line ¶
Line is a split line for syntax, token, and comment
func (*Line) SplitSyntax ¶
SplitSyntax breaks the syntax line on Space the character
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a simplified logger for making the code and outputFlag readable.
type MarkdownTable ¶
func NewMarkdownTable ¶
func NewMarkdownTable() *MarkdownTable
func (*MarkdownTable) AddHeader ¶
func (mt *MarkdownTable) AddHeader(names ...string)
func (*MarkdownTable) EvaluateWidth ¶
func (mt *MarkdownTable) EvaluateWidth(i int, d string)
func (*MarkdownTable) Insert ¶
func (mt *MarkdownTable) Insert(data ...string)
func (*MarkdownTable) String ¶
func (mt *MarkdownTable) String() string
type Message ¶
type Message struct { *Qualified Attributes []*Attribute Messages []*Message Enums []*Enum Reserved []*Reserved }
Message represents a message / struct body
func (*Message) HasAttributes ¶
func (*Message) HasMessages ¶
type MessageVisitor ¶
type MessageVisitor struct { }
MessageVisitor is used for interpreting message text
func (*MessageVisitor) CanVisit ¶
func (mv *MessageVisitor) CanVisit(in *Line) bool
CanVisit visits if the line starts with 'message' and ends with an open brace '{'
type NamedValue ¶
NamedValue is super class to capture names and values for typed lines.
func (*NamedValue) GetAnchor ¶
func (namedValue *NamedValue) GetAnchor() string
type Option ¶
type Option struct {
*NamedValue
}
type OptionVisitor ¶
type OptionVisitor struct { }
func (*OptionVisitor) CanVisit ¶
func (ov *OptionVisitor) CanVisit(in *Line) bool
type Package ¶
type Package struct { Path string Name string Comment Comment Options []*Option Imports []*Import Messages []*Message Enums []*Enum Services []*Service }
Package is the top level structure of any protobuf
func NewPackage ¶
func (*Package) ToMarkdownWithDiagram ¶
type PackageVisitor ¶
type PackageVisitor struct { }
func (*PackageVisitor) CanVisit ¶
func (pv *PackageVisitor) CanVisit(in *Line) bool
type Parameter ¶
func NewParameter ¶
type ProtobufFileScanner ¶
type ProtobufFileScanner struct {
// contains filtered or unexported fields
}
ProtobufFileScanner is a specialized scanner for reading protobuf 3 files.
func (ProtobufFileScanner) Buffer ¶
func (sw ProtobufFileScanner) Buffer(buf []byte, max int)
Buffer is a delegate method to the underline scanner
func (ProtobufFileScanner) Bytes ¶
func (sw ProtobufFileScanner) Bytes() []byte
Bytes is a delegate method to the underline scanner
func (ProtobufFileScanner) Err ¶
func (sw ProtobufFileScanner) Err() error
Err is a delegate method to the underline scanner
func (ProtobufFileScanner) ReadLine ¶
func (sw ProtobufFileScanner) ReadLine() *Line
ReadLine is an addition to the buffered reader responsible for interpreting the line of the protobuf for the AST.
func (ProtobufFileScanner) Scan ¶
func (sw ProtobufFileScanner) Scan() bool
Scan is a delegate method to the underline scanner
func (ProtobufFileScanner) Split ¶
func (sw ProtobufFileScanner) Split(splitFunction bufio.SplitFunc)
Split is a delegate method to the underline scanner
func (ProtobufFileScanner) Text ¶
func (sw ProtobufFileScanner) Text() string
Text is a specialization of the Text function, ensuring the line read is ready for processing.
type Reserved ¶
func NewReserved ¶
type ReservedVisitor ¶
type ReservedVisitor struct { }
func (*ReservedVisitor) CanVisit ¶
func (rv *ReservedVisitor) CanVisit(line *Line) bool
type Rpc ¶
type Rpc struct { *Qualified InputParameters []*Parameter ReturnParameters []*Parameter Options []*RpcOption }
func (*Rpc) AddInputParameter ¶
func (*Rpc) AddReturnParameter ¶
func (*Rpc) AddRpcOption ¶
type RpcVisitor ¶
func NewRpcVisitor ¶
func NewRpcVisitor() *RpcVisitor
func (*RpcVisitor) CanVisit ¶
func (rv *RpcVisitor) CanVisit(line *Line) bool
type Scanner ¶
type Scanner interface { Scan() bool Text() string Split(splitFunction bufio.SplitFunc) Buffer(buf []byte, max int) Err() error Bytes() []byte ReadLine() *Line }
Scanner is an interface that SHOULD be a Go interface, but is only an implementation. Here, we can use the interface to wrap test cases with the same behavior of a bufio.Scanner
func NewProtobufFileScanner ¶
NewProtobufFileScanner is the constructor for ProtobufFileScanner
type ServiceVisitor ¶
type ServiceVisitor struct {
Visitors []Visitor
}
func NewServiceVisitor ¶
func NewServiceVisitor() *ServiceVisitor
func (*ServiceVisitor) CanVisit ¶
func (sv *ServiceVisitor) CanVisit(line *Line) bool
type TestScanner ¶
type TestScanner struct {
// contains filtered or unexported fields
}
func NewTestScanner ¶
func NewTestScanner(in string) *TestScanner
func (*TestScanner) Buffer ¶
func (ts *TestScanner) Buffer(buf []byte, max int)
func (*TestScanner) Bytes ¶
func (ts *TestScanner) Bytes() []byte
func (*TestScanner) Err ¶
func (ts *TestScanner) Err() error
func (*TestScanner) ReadLine ¶
func (ts *TestScanner) ReadLine() *Line
func (*TestScanner) Scan ¶
func (ts *TestScanner) Scan() bool
func (*TestScanner) Split ¶
func (ts *TestScanner) Split(splitFunction bufio.SplitFunc)
func (*TestScanner) Text ¶
func (ts *TestScanner) Text() string
type Validatable ¶
type Validatable interface {
IsValid() bool
}
Validatable is a reference interface for the validator pattern
type Visitor ¶
type Visitor interface { CanVisit(in *Line) bool Visit( scanner Scanner, in *Line, namespace string) interface{} }
Visitor is an interface used to determine if a line should be read, and if it should be, to read and interpret the line and subsequent lines as required.
type WriterConfig ¶
type WriterConfig struct {
// contains filtered or unexported fields
}
Source Files
¶
- annotation.go
- app.go
- attribute.go
- attribute_visitor.go
- comment.go
- comment_visitor.go
- constants.go
- enum.go
- enum_value.go
- enum_value_visitor.go
- enum_visitor.go
- import.go
- import_visitor.go
- interfaces.go
- line.go
- logger.go
- markdown.go
- message.go
- message_visitor.go
- model.go
- option_visitor.go
- package.go
- package_visitor.go
- protobuf_file_scanner.go
- reserved.go
- reserved_visitor.go
- rpc.go
- rpc_visitor.go
- service.go
- service_visitor.go
- test_scanner.go
- util.go
- variables.go
- writer_markdown.go
- writer_mermaid.go