protoutil

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append added in v0.0.13

func Append(s *string, args ...string)

func Camel2Case

func Camel2Case(name string) string

Camel2Case 驼峰式写法转为下划线写法

func CamelCase added in v0.0.13

func CamelCase(s string) string

CamelCase returns the CamelCased name. If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ generator lowercases names, it's extremely unlikely to have two fields with different capitalizations. In short, _my_field_name_2 becomes XMyFieldName_2.

func CodeFormat added in v0.0.13

func CodeFormat(buf *bytes.Buffer) (string, error)

CodeFormat go code format

func DefaultAPIOptions added in v0.0.13

func DefaultAPIOptions(pkg, srv, mth string) *options.HttpRule

DefaultAPIOptions This generates an HttpRule that matches the gRPC mapping to HTTP/2 described in https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests i.e.:

  • method is POST
  • path is "<pkg name>/<service name>/<method name>"
  • body should contain the serialized request message

func ExtractAPIOptions added in v0.0.13

func ExtractAPIOptions(mth protoreflect.MethodDescriptor) (*options.HttpRule, error)

func ExtractHttpMethod added in v0.0.13

func ExtractHttpMethod(opts *options.HttpRule) (method, path string)

func Gen added in v0.0.13

func Gen(g *protogen.GeneratedFile, tpl string, m pongo.Context)

func ID added in v0.0.13

func ID(s string) string

ID is a NameTransformer that does not mutate the string.

func Import added in v0.0.13

func Import(name string) func(id string) protogen.GoIdent

func IsHelp added in v0.0.13

func IsHelp() bool

func Template added in v0.0.13

func Template(tpl string, m pongo.Context) string

func UnExport added in v0.0.13

func UnExport(s string) string

Types

type Context

type Context = pongo.Context

type FilePath added in v0.0.13

type FilePath string

A FilePath describes the name of a file or directory. This type simplifies path related operations.

func JoinPaths added in v0.0.13

func JoinPaths(elem ...string) FilePath

JoinPaths is an convenient alias around filepath.Join, to easily create FilePath types.

func (FilePath) Base added in v0.0.13

func (n FilePath) Base() string

Base returns the base of the current FilePath (the last element in the path). This method is an alias around filepath.Base.

func (FilePath) BaseName added in v0.0.13

func (n FilePath) BaseName() string

BaseName returns the Base of the current FilePath without Ext.

func (FilePath) Dir added in v0.0.13

func (n FilePath) Dir() FilePath

Dir returns the parent directory of the current FilePath. This method is an alias around filepath.Dir.

func (FilePath) Ext added in v0.0.13

func (n FilePath) Ext() string

Ext returns the extension of the current FilePath (starting at and including the last '.' in the FilePath). This method is an alias around filepath.Ext.

func (FilePath) Pop added in v0.0.13

func (n FilePath) Pop() FilePath

Pop returns a new FilePath with the last element removed. Pop is an alias for the Dir method.

func (FilePath) Push added in v0.0.13

func (n FilePath) Push(elem string) FilePath

Push returns a new FilePath with elem added to the end

func (FilePath) SetBase added in v0.0.13

func (n FilePath) SetBase(base string) FilePath

SetBase returns a new FilePath with the base element replaced with base.

func (FilePath) SetExt added in v0.0.13

func (n FilePath) SetExt(ext string) FilePath

SetExt returns a new FilePath with the extension replaced with ext.

func (FilePath) String added in v0.0.13

func (n FilePath) String() string

String satisfies the strings.Stringer interface.

type Name added in v0.0.13

type Name string

A Name describes an identifier of an Entity (Message, Field, Enum, Service, Field). It can be converted to multiple forms using the provided helper methods, or a custom transform can be used to modify its behavior.

func (Name) LowerCamelCase added in v0.0.13

func (n Name) LowerCamelCase() Name

LowerCamelCase converts Name n to lower camelcase, where each part is title-cased and concatenated with no separator except the first which is lower-cased.

func (Name) LowerDotNotation added in v0.0.13

func (n Name) LowerDotNotation() Name

LowerDotNotation converts Name n to lower dot notation, where each part is lower-cased and concatenated with periods.

func (Name) LowerSnakeCase added in v0.0.13

func (n Name) LowerSnakeCase() Name

LowerSnakeCase converts Name n to lower-snake-case, where each part is lower-cased and concatenated with underscores.

func (Name) ScreamingSnakeCase added in v0.0.13

func (n Name) ScreamingSnakeCase() Name

ScreamingSnakeCase converts Name n to screaming-snake-case, where each part is all-caps and concatenated with underscores.

func (Name) SnakeCase added in v0.0.13

func (n Name) SnakeCase() Name

SnakeCase converts Name n to snake-case, where each part preserves its capitalization and concatenated with underscores.

func (Name) Split added in v0.0.13

func (n Name) Split() (parts []string)

Split breaks apart Name n into its constituent components. Precedence follows dot notation, then underscores (excluding underscore prefixes), then camelcase. Numbers are treated as standalone components.

func (Name) String added in v0.0.13

func (n Name) String() string

String satisfies the strings.Stringer interface.

func (Name) Transform added in v0.0.13

func (n Name) Transform(mod, first NameTransformer, sep string) Name

Transform applies a transformation to the parts of Name n, returning a new Name. Transformer first is applied to the first part, with mod applied to all subsequent ones. The parts are then concatenated with the separator sep. For optimal efficiency, multiple NameTransformers should be Chained together before calling Transform.

func (Name) UpperCamelCase added in v0.0.13

func (n Name) UpperCamelCase() Name

UpperCamelCase converts Name n to upper camelcase, where each part is title-cased and concatenated with no separator.

func (Name) UpperDotNotation added in v0.0.13

func (n Name) UpperDotNotation() Name

UpperDotNotation converts Name n to upper dot notation, where each part is title-cased and concatenated with periods.

func (Name) UpperSnakeCase added in v0.0.13

func (n Name) UpperSnakeCase() Name

UpperSnakeCase converts Name n to upper-snake-case, where each part is title-cased and concatenated with underscores.

type NameTransformer added in v0.0.13

type NameTransformer func(string) string

NameTransformer is a function that mutates a string. Many of the methods in the standard strings package satisfy this signature.

func (NameTransformer) Chain added in v0.0.13

Chain combines the behavior of two Transformers into one. If multiple transformations need to be performed on a Name, this method should be used to reduce it to a single transformation before applying.

Jump to

Keyboard shortcuts

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