Documentation ¶
Index ¶
- func FieldName(opt *TSOption) func(name string) string
- func FindFieldByTextName(msg *protogen.Message, name string) *protogen.Field
- func FunctionCase_TSProto(s string) string
- func GetModuleName(file protoreflect.FileDescriptor) string
- func JSONCamelCase(s string) string
- func TSImportPath(thisPath string, modulePath string) string
- type FileGenerator
- func (opt FileGenerator) P(v ...any)
- func (opt FileGenerator) PComment(comments ...string)
- func (opt FileGenerator) PCommentf(format string, args ...interface{})
- func (opt FileGenerator) PTmpl(tmpl *template.Template, data interface{}, funcs ...template.FuncMap)
- func (opt FileGenerator) PTmplStr(tmpl string, data interface{}, funcs ...template.FuncMap)
- func (opt FileGenerator) Pf(format string, v ...any)
- type ForEachFileRunner
- type GenerateOptions
- type PluginInfo
- type PreForEachFileRunner
- type TSIdent
- type TSModule
- type TSOption
- type TSRegistry
- func (g *TSRegistry) Apply(w io.Writer) error
- func (g *TSRegistry) ImportSegments() string
- func (g *TSRegistry) P(v ...any)
- func (opt *TSRegistry) PComment(comments ...string)
- func (opt *TSRegistry) PCommentf(format string, args ...interface{})
- func (opt *TSRegistry) PTmpl(tmpl *template.Template, data interface{}, funcs ...template.FuncMap)
- func (opt *TSRegistry) PTmplStr(tmpl string, data interface{}, funcs ...template.FuncMap)
- func (opt *TSRegistry) Pf(format string, v ...any)
- func (r *TSRegistry) QualifiedTSIdent(ident TSIdent) string
- func (r *TSRegistry) ServiceFmap() template.FuncMap
- func (r *TSRegistry) TsType(def *protogen.Message, location protogen.Location) string
- func (g *TSRegistry) Write(p []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindFieldByTextName ¶ added in v1.0.21
func FunctionCase_TSProto ¶ added in v1.0.21
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
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
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 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
func TSIdent_TSProto_Message ¶ added in v1.0.21
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
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) 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.