Help us shape the future of Go! Take the 2026 Go Developer Survey

util

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 25 Imported by: 15

Documentation

Index

Constants

View Source
const ThriftgoMiniVersion = "v0.2.0"

Variables

This section is empty.

Functions

func AddImport

func AddImport(file, alias, impt string) ([]byte, error)

func AddImportForContent added in v0.5.1

func AddImportForContent(fileContent []byte, alias, impt string) ([]byte, error)

func AddSlashForComments

func AddSlashForComments(s string) string

AddSlashForComments can adjust the format of multi-line comments

func BaseName

func BaseName(include, subFixToTrim string) string

BaseName get base name for path. ex: "github.com/p.s.m" => "p.s.m"

func BaseNameAndTrim

func BaseNameAndTrim(include string) string

func Bytes2Str

func Bytes2Str(in []byte) (out string)

func CamelString

func CamelString(s string) string

CamelString converts the string 's' to PascalCase (upper camel case). Underscores before lowercase letters are removed and the following letter is capitalized. State flags: j = next char should be uppercased (after underscore), k = seen first letter already.

func CheckAndUpdateThriftgo

func CheckAndUpdateThriftgo() error

CheckAndUpdateThriftgo checks the version of thriftgo and updates the tool to the latest version if its version is less than v0.2.0.

func CheckCompiler

func CheckCompiler(tool string) (bool, error)

CheckCompiler will check if the tool exists.

func CopyString2StringMap

func CopyString2StringMap(from, to map[string]string)

func CopyStringSlice

func CopyStringSlice(from, to *[]string)

func GetBuildGoPaths

func GetBuildGoPaths() []string

GetBuildGoPaths returns the list of Go path directories.

func GetFirstKV

func GetFirstKV(m map[string][]string) (string, []string)

func GetGOPATH

func GetGOPATH() (gopath string, err error)

func GetHandlerPackageUniqueName

func GetHandlerPackageUniqueName(name string) (string, error)

func GetMiddlewareUniqueName

func GetMiddlewareUniqueName(name string) (string, error)

GetMiddlewareUniqueName can get a non-repeating variable name for middleware name

func GetPackageUniqueName

func GetPackageUniqueName(name string) (string, error)

GetPackageUniqueName can get a non-repeating variable name for package alias

func ImportToSanitizedPath added in v0.9.8

func ImportToSanitizedPath(path string) string

ImportToSanitizedPath converts import path to file system path and replaces dots with underscores in the last component. For example: "github.com/example/v1.2" becomes "github.com/example/v1_2" on Unix systems. NOTE: no idea about the background, it might caused go import package issues before?

func InitGoMod

func InitGoMod(module string) error

func InstallAndCheckThriftgo

func InstallAndCheckThriftgo() error

InstallAndCheckThriftgo will automatically install thriftgo and judge whether it is installed successfully.

func IsWindows

func IsWindows() bool

func MapForm

func MapForm(input []string) (map[string][]string, error)

func PackArgs

func PackArgs(c interface{}) (res []string, err error)

PackArgs serializes a struct into a flat list of "Key=Value" strings for passing arguments through the protoc/thriftgo plugin interface. Slices are joined with ";", maps are encoded as "k1=v1;k2=v2". Only exported, non-zero fields are included.

func PathExist

func PathExist(path string) (bool, error)

func QueryVersion

func QueryVersion(exe string) (version string, err error)

QueryVersion will query the version of the corresponding executable.

func RelativePath

func RelativePath(path string) (string, error)

func SearchGoMod

func SearchGoMod(cwd string, recurse bool) (moduleName, path string, found bool)

SearchGoMod searches go.mod from the given directory (which must be an absolute path) to the root directory. When the go.mod is found, its module name and path will be returned.

func ShouldUpdate

func ShouldUpdate(current, latest string) bool

ShouldUpdate will return "true" when current is lower than latest.

func SnakeString

func SnakeString(s string) string

SnakeString converts the string 's' to snake_case. Inserts '_' before uppercase letters that follow a lowercase letter or non-underscore. j tracks whether we've seen a non-underscore lowercase char (to avoid leading underscores).

func SplitGoTags

func SplitGoTags(input string) []string

SplitGoTags splits a Go struct tag string into individual key:"value" pairs, respecting quoted values that may contain spaces.

func SplitPackage

func SplitPackage(pkg, subFixToTrim string) string

func SplitPackageName

func SplitPackageName(pkg, subFixToTrim string) string

func Str2Bytes

func Str2Bytes(in string) (out []byte)

Str2Bytes performs a zero-copy string to byte slice conversion using unsafe pointer casting. The returned slice shares memory with the input string; do NOT modify it.

func SubDir

func SubDir(root, subPkg string) string

func SubPackage

func SubPackage(mod, dir string) string

func ToCamelCase

func ToCamelCase(name string) string

func ToGoFuncName added in v0.6.2

func ToGoFuncName(s string) string

ToGoFuncName converts a string to a function naming style for go

func ToSnakeCase

func ToSnakeCase(name string) string

func ToVarName

func ToVarName(paths []string) string

ToVarName joins path segments and converts them to a valid Go identifier. Non-alphanumeric characters are replaced with '_', and leading digits are dropped. Segments are joined with "__" (e.g. ["api","v1"] -> "api__v1").

func TrimLastChar

func TrimLastChar(s string) string

TrimLastChar can remove the last char for s

func UnpackArgs

func UnpackArgs(args []string, c interface{}) error

UnpackArgs deserializes a "Key=Value" string list (from PackArgs) back into a struct. This is the inverse of PackArgs, used by the plugin process to receive configuration.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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