buf

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryMinimal  = "MINIMAL"
	CategoryBasic    = "BASIC"
	CategoryStandard = "STANDARD"
	CategoryComments = "COMMENTS"
)

Lint rule categories

Variables

This section is empty.

Functions

func FindProtoFiles

func FindProtoFiles(dir string, excludePaths []string) ([]string, error)

FindProtoFiles finds all .proto files in a directory

func FormatProto

func FormatProto(source string) string

FormatProto formats a proto file content

func OutputResults

func OutputResults(w io.Writer, results []LintResult, format string) error

OutputResults outputs results in the specified format

func RunBreaking

func RunBreaking(w io.Writer, dir string, opts BreakingOptions) error

RunBreaking checks for breaking changes

func RunBuild

func RunBuild(w io.Writer, dir string, opts BuildOptions) error

RunBuild builds proto files

func RunDepUpdate

func RunDepUpdate(w io.Writer, dir string) error

RunDepUpdate updates dependencies (placeholder)

func RunFormat

func RunFormat(w io.Writer, dir string, opts FormatOptions) error

RunFormat formats proto files

func RunGenerate

func RunGenerate(w io.Writer, dir string, opts GenerateOptions) error

RunGenerate generates code from proto files

func RunInit

func RunInit(w io.Writer, dir string, moduleName string) error

RunInit initializes a new buf module

func RunLint

func RunLint(w io.Writer, dir string, opts LintOptions) error

RunLint runs lint on proto files

func RunLsFiles

func RunLsFiles(w io.Writer, dir string) error

RunLsFiles lists proto files in the module

Types

type BreakingConfig

type BreakingConfig struct {
	Use    []string `yaml:"use,omitempty"`
	Except []string `yaml:"except,omitempty"`
	Ignore []string `yaml:"ignore,omitempty"`
}

BreakingConfig represents breaking change configuration

type BreakingOptions

type BreakingOptions struct {
	Options

	Against        string // Source to compare against
	ExcludeImports bool   // Don't check imported files
}

BreakingOptions configures buf breaking

type BuildOptions

type BuildOptions struct {
	Options

	Output string // Output file path
}

BuildOptions configures buf build

type BuildResult

type BuildResult struct {
	Success bool     `json:"success"`
	Files   []string `json:"files"`
	Errors  []string `json:"errors,omitempty"`
}

BuildResult represents build output

type Config

type Config struct {
	Version  string         `yaml:"version"`
	Name     string         `yaml:"name,omitempty"`
	Deps     []string       `yaml:"deps,omitempty"`
	Lint     LintConfig     `yaml:"lint,omitempty"`
	Breaking BreakingConfig `yaml:"breaking,omitempty"`
}

Config represents buf.yaml configuration

func LoadConfig

func LoadConfig(dir string) (*Config, error)

LoadConfig loads buf.yaml from a directory

type FormatOptions

type FormatOptions struct {
	Write    bool // Rewrite files in place
	Diff     bool // Display diff
	ExitCode bool // Exit with non-zero if files unformatted
}

FormatOptions configures buf format

type FormatResult

type FormatResult struct {
	File      string `json:"file"`
	Formatted bool   `json:"formatted"`
	Diff      string `json:"diff,omitempty"`
	BytesDiff int    `json:"bytes_diff,omitempty"`
}

FormatResult represents format output

type GenerateConfig

type GenerateConfig struct {
	Version string         `yaml:"version"`
	Plugins []PluginConfig `yaml:"plugins"`
	Clean   bool           `yaml:"clean,omitempty"`
	Managed ManagedConfig  `yaml:"managed,omitempty"`
}

GenerateConfig represents buf.gen.yaml configuration

func LoadGenerateConfig

func LoadGenerateConfig(dir string) (*GenerateConfig, error)

LoadGenerateConfig loads buf.gen.yaml from a directory

type GenerateOptions

type GenerateOptions struct {
	Template       string // Alternate buf.gen.yaml location
	Output         string // Base output directory
	IncludeImports bool   // Include imported files
}

GenerateOptions configures buf generate

type GoPackagePrefix

type GoPackagePrefix struct {
	Default string `yaml:"default"`
}

GoPackagePrefix represents go_package_prefix configuration

type Lexer

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

Lexer tokenizes proto source

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new lexer

func (*Lexer) Tokenize

func (l *Lexer) Tokenize() []Token

Tokenize returns all tokens from the input

type LintConfig

type LintConfig struct {
	Use        []string            `yaml:"use,omitempty"`
	Except     []string            `yaml:"except,omitempty"`
	Ignore     []string            `yaml:"ignore,omitempty"`
	IgnoreOnly map[string][]string `yaml:"ignore_only,omitempty"`
}

LintConfig represents lint configuration

type LintOptions

type LintOptions struct {
	Options
}

LintOptions configures buf lint

type LintResult

type LintResult struct {
	File    string `json:"file"`
	Line    int    `json:"line"`
	Column  int    `json:"column"`
	Rule    string `json:"rule"`
	Message string `json:"message"`
}

LintResult represents a lint issue

type LintRule

type LintRule struct {
	ID       string
	Category string
	Check    func(*ProtoFile, string) []LintResult
}

LintRule represents a lint rule

type ManagedConfig

type ManagedConfig struct {
	Enabled         bool            `yaml:"enabled"`
	GoPackagePrefix GoPackagePrefix `yaml:"go_package_prefix,omitempty"`
}

ManagedConfig represents managed mode configuration

type Options

type Options struct {
	ErrorFormat string   // Output format: text, json, github-actions
	ExcludePath []string // Paths to exclude
	Path        []string // Specific paths to process
	Config      string   // Custom config file path
}

Options configures common buf options

type Parser

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

Parser parses proto tokens into a ProtoFile

func NewParser

func NewParser(tokens []Token) *Parser

NewParser creates a new parser

func (*Parser) Parse

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

Parse parses the tokens into a ProtoFile

type PluginConfig

type PluginConfig struct {
	Remote string   `yaml:"remote,omitempty"`
	Local  string   `yaml:"local,omitempty"`
	Out    string   `yaml:"out"`
	Opt    []string `yaml:"opt,omitempty"`
}

PluginConfig represents a plugin configuration

type ProtoComment

type ProtoComment struct {
	Text string
	Line int
}

ProtoComment represents a comment in the proto file

type ProtoEnum

type ProtoEnum struct {
	Name    string
	Values  []ProtoEnumValue
	Options []ProtoOption
	Line    int
}

ProtoEnum represents a proto enum

type ProtoEnumValue

type ProtoEnumValue struct {
	Name    string
	Number  int
	Options []ProtoOption
	Line    int
}

ProtoEnumValue represents a proto enum value

type ProtoField

type ProtoField struct {
	Name     string
	Type     string
	Number   int
	Label    string // optional, required, repeated
	Options  []ProtoOption
	Line     int
	Comments []string
}

ProtoField represents a proto field

type ProtoFile

type ProtoFile struct {
	Syntax   string
	Package  string
	Options  []ProtoOption
	Imports  []ProtoImport
	Messages []ProtoMessage
	Enums    []ProtoEnum
	Services []ProtoService
	Comments []ProtoComment
}

ProtoFile represents a parsed proto file

func ParseProtoFile

func ParseProtoFile(source string) (*ProtoFile, error)

ParseProtoFile parses a proto file from source

type ProtoImage

type ProtoImage struct {
	Files []ProtoImageFile `json:"files"`
}

ProtoImage represents a compiled protobuf image

type ProtoImageFile

type ProtoImageFile struct {
	Name     string            `json:"name"`
	Package  string            `json:"package"`
	Syntax   string            `json:"syntax"`
	Messages []string          `json:"messages,omitempty"`
	Enums    []string          `json:"enums,omitempty"`
	Services []string          `json:"services,omitempty"`
	Imports  []string          `json:"imports,omitempty"`
	Options  map[string]string `json:"options,omitempty"`
}

ProtoImageFile represents a file in the image

type ProtoImport

type ProtoImport struct {
	Path   string
	Public bool
	Weak   bool
	Line   int
}

ProtoImport represents a proto import

type ProtoMessage

type ProtoMessage struct {
	Name     string
	Fields   []ProtoField
	Nested   []ProtoMessage
	Enums    []ProtoEnum
	Options  []ProtoOption
	Reserved []string
	Line     int
	Comments []string
}

ProtoMessage represents a proto message

type ProtoMethod

type ProtoMethod struct {
	Name            string
	InputType       string
	OutputType      string
	ClientStreaming bool
	ServerStreaming bool
	Options         []ProtoOption
	Line            int
}

ProtoMethod represents a proto RPC method

type ProtoOption

type ProtoOption struct {
	Name  string
	Value string
	Line  int
}

ProtoOption represents a proto option

type ProtoService

type ProtoService struct {
	Name    string
	Methods []ProtoMethod
	Options []ProtoOption
	Line    int
}

ProtoService represents a proto service

type Token

type Token struct {
	Type   TokenType
	Value  string
	Line   int
	Column int
}

Token represents a proto token

type TokenType

type TokenType int

TokenType represents the type of a proto token

const (
	TokenEOF TokenType = iota
	TokenIdent
	TokenString
	TokenNumber
	TokenKeyword
	TokenSymbol
	TokenComment
	TokenWhitespace
	TokenNewline
)

Jump to

Keyboard shortcuts

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