protomapper

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 8 Imported by: 0

README

protomapper

Genrates code for mapping between proto messages and plane go structs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FilepathResolver = func(path ...string) FileResolver {
	return func(s string) (string, error) {
		path := append(path, s)
		return filepath.Join(path...), nil
	}
}

FilepathResolver resolver for files in directory path.

Functions

func ScalarGoTypeName

func ScalarGoTypeName(t ProtoScalar) string

ScalarGoTypeName get corresponding go type for protobuf scalar type.

Types

type Config

type Config struct {
	// AppName - app name to include in generated comment.
	AppName string
	// TypesDir - folder, where types will be generated.
	TypesDir string
	// TypesGoPackage - go package name for generated types.
	TypesGoPackage string
	// ConvertersDir - folder, where type converters will be generated.
	ConvertersDir string
	// ConvertersGoPkg - go package for converters.
	ConvertersGoPkg string
	// TypesImport - import types package in converters.
	TypesImport string
	// PbImport - import protobuf generated package in converters.
	PbImport string
}

Config protomapper configuration.

type Field

type Field = types.Field

type FileResolver

type FileResolver func(string) (string, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithExcludeMessageFields

func WithExcludeMessageFields(exclude func(field ProtoField) bool) Option

func WithFieldMapper

func WithFieldMapper(field Field, fromProto, toProto ProtoMapperFunc) Option

type ProtoField

type ProtoField = ast.Field

type ProtoMapper added in v0.0.2

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

func NewProtoMapper

func NewProtoMapper(cfg *Config) *ProtoMapper

NewProtoMapper setup new protomapper.

func (*ProtoMapper) ConvertersRenderer added in v0.0.2

func (p *ProtoMapper) ConvertersRenderer() Renderer

ConvertersRenderer get converters renderer.

func (*ProtoMapper) Fields added in v0.0.2

func (p *ProtoMapper) Fields() *dicts.FieldDict

Fields get fields.

func (*ProtoMapper) ResolveTypes added in v0.0.2

func (p *ProtoMapper) ResolveTypes(resolver FileResolver, fileNames ...string) error

ResolveTypes resolver *.proto files and collect defined types.

func (*ProtoMapper) TypeMapper added in v0.0.2

func (p *ProtoMapper) TypeMapper() TypeMapper

TypeMapper get type mapper.

func (*ProtoMapper) TypeRenderer added in v0.0.2

func (p *ProtoMapper) TypeRenderer() Renderer

TypeRenderer get type renderer.

func (*ProtoMapper) Types added in v0.0.2

func (p *ProtoMapper) Types() *dicts.TypeDict

Types get types.

func (*ProtoMapper) WithOptions added in v0.0.2

func (p *ProtoMapper) WithOptions(opts ...Option) *ProtoMapper

WithOptions add options for protomapper.

type ProtoMapperFunc

type ProtoMapperFunc func(protoField ProtoField) func(src, dest string) string

type ProtoOption

type ProtoOption = ast.Option

type ProtoScalar

type ProtoScalar = ast.ScalarNode

type ProtoType

type ProtoType = ast.Type

type Renderer

type Renderer interface {
	Render(t Type) error
	SetTypeNameResolver(func(t Type) string)
}

Renderer renderer for types.

type Type

type Type = types.Type

type TypeMapper

type TypeMapper interface {
	FromProtoType(t ProtoType) (Type, error)
	FromProtoField(f ProtoField) (Field, error)
}

TypeMapper mapper for protobuf types.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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