pluginutils

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldName added in v1.0.21

func FieldName(opt *TSOption) func(name string) string

func FindFieldByTextName added in v1.0.21

func FindFieldByTextName(msg *protogen.Message, name string) *protogen.Field

func FunctionCase_TSProto added in v1.0.21

func FunctionCase_TSProto(s string) string

TSProto Function Case

func GetModuleName added in v1.0.21

func GetModuleName(file protoreflect.FileDescriptor) string

GetModuleName returns module name = package name + base file name to be the unique identifier for source file in a ts file. Package name and base file name are converted to camel case, special characters like dot, dash and underscore are removed. packageName: memos.api.v1 fileName: memos.proto

func JSONCamelCase added in v1.0.21

func JSONCamelCase(s string) string

JSONCamelCase converts a snake_case identifier to a camelCase identifier, according to the protobuf JSON specification.

Copied from: google.golang.org/protobuf/internal/strs.

func TSImportPath added in v1.0.21

func TSImportPath(thisPath string, modulePath string) string

Types

type FileGenerator

type FileGenerator struct {
	W *protogen.GeneratedFile // The file to write to
	F *protogen.File          // The proto file descr
}

func (FileGenerator) P

func (opt FileGenerator) P(v ...any)

P is a shorthand for (*protogen.GeneratedFile).P()

func (FileGenerator) PComment added in v1.0.12

func (opt FileGenerator) PComment(comments ...string)

PComment allows multiple lines string as comment.

func (FileGenerator) PCommentf added in v1.0.12

func (opt FileGenerator) PCommentf(format string, args ...interface{})

PCommentf allows formatted string as comment.

func (FileGenerator) PTmpl added in v1.0.21

func (opt FileGenerator) PTmpl(tmpl *template.Template, data interface{}, funcs ...template.FuncMap)

func (FileGenerator) PTmplStr added in v1.0.21

func (opt FileGenerator) PTmplStr(tmpl string, data interface{}, funcs ...template.FuncMap)

func (FileGenerator) Pf

func (opt FileGenerator) Pf(format string, v ...any)

Pf is same as P, but with formatted string.

type ForEachFileRunner added in v1.0.12

type ForEachFileRunner interface {
	Run(fn func(genOpt GenerateOptions) error)
}

type GenerateOptions added in v1.0.12

type GenerateOptions struct {
	FileGenerator
	PluginInfo
}

func (GenerateOptions) PHeader added in v1.0.12

func (opt GenerateOptions) PHeader(p *protogen.Plugin)

func (GenerateOptions) PPackage added in v1.0.12

func (opt GenerateOptions) PPackage()

type PluginInfo added in v1.0.12

type PluginInfo struct {
	PluginName        string
	VersionStr        string
	GenFileSuffix     string
	SupportedFeatures uint64
}

type PreForEachFileRunner added in v1.0.12

type PreForEachFileRunner interface {
	ForEachFileThat(fn func(protoFile *protogen.File) bool) ForEachFileRunner
}

func NewForEachFileRunner added in v1.0.12

func NewForEachFileRunner(info PluginInfo) PreForEachFileRunner

ForEachFileRunner helps to generate one file for each file that is being generated

type TSIdent added in v1.0.21

type TSIdent struct {
	TSModule
	Name string
}

func TSIdent_TSProto_Message added in v1.0.21

func TSIdent_TSProto_Message(msg *protogen.Message) TSIdent

type TSModule added in v1.0.21

type TSModule struct {
	ModuleName string
	Path       string // path relative to the generate root, or the absolute path
	Relative   bool   // whether the path is relative to the current file
}

func TSModule_TSProto added in v1.0.21

func TSModule_TSProto(file protoreflect.FileDescriptor) TSModule

func (TSModule) Ident added in v1.0.21

func (m TSModule) Ident(name string) TSIdent

type TSOption added in v1.0.21

type TSOption struct {
	// TSImportRootParamsKey contains the key for common_import_root in parameters
	TSImportRoots string
	// TSImportRootAliasParamsKey contains the key for common_import_root_alias in parameters
	TSImportRootAliases string
	// UseProtoNames will generate field names the same as defined in the proto
	UseProtoNames bool
	// EmitUnpopulated mirrors the grpc gateway protojson configuration of the same name and allows
	// clients to differentiate between zero values and optional values that aren't set.
	EmitUnpopulated bool
	// EnableStylingCheck enables both eslint and tsc check for the generated code
	EnableStylingCheck bool
}

type TSRegistry added in v1.0.21

type TSRegistry struct {
	GenOpts      GenerateOptions
	ImportIdents map[string][]TSIdent // map<module_path, TSIdent>
	// contains filtered or unexported fields
}

func NewTSRegistry added in v1.0.21

func NewTSRegistry(opts GenerateOptions) *TSRegistry

func (*TSRegistry) Apply added in v1.0.21

func (g *TSRegistry) Apply(w io.Writer) error

func (*TSRegistry) ImportSegments added in v1.0.21

func (g *TSRegistry) ImportSegments() string

func (*TSRegistry) P added in v1.0.21

func (g *TSRegistry) P(v ...any)

func (*TSRegistry) PComment added in v1.0.21

func (opt *TSRegistry) PComment(comments ...string)

PComment allows multiple lines string as comment.

func (*TSRegistry) PCommentf added in v1.0.21

func (opt *TSRegistry) PCommentf(format string, args ...interface{})

PCommentf allows formatted string as comment.

func (*TSRegistry) PTmpl added in v1.0.21

func (opt *TSRegistry) PTmpl(tmpl *template.Template, data interface{}, funcs ...template.FuncMap)

func (*TSRegistry) PTmplStr added in v1.0.21

func (opt *TSRegistry) PTmplStr(tmpl string, data interface{}, funcs ...template.FuncMap)

func (*TSRegistry) Pf added in v1.0.21

func (opt *TSRegistry) Pf(format string, v ...any)

Pf is same as P, but with formatted string.

func (*TSRegistry) QualifiedTSIdent added in v1.0.21

func (r *TSRegistry) QualifiedTSIdent(ident TSIdent) string

func (*TSRegistry) ServiceFmap added in v1.0.21

func (r *TSRegistry) ServiceFmap() template.FuncMap

ServiceTemplate gets the template for the primary typescript file.

func (*TSRegistry) TsType added in v1.0.21

func (r *TSRegistry) TsType(def *protogen.Message, location protogen.Location) string

location: the location of the field or method that references the type

func (*TSRegistry) Write added in v1.0.21

func (g *TSRegistry) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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