Documentation ¶
Overview ¶
Package name is a utility package that can derive the names of things.
Index ¶
- func EnvKey(parts ...string) string
- func OfFunc(v zero.Interface) string
- func OfFuncFull(v zero.Interface) string
- func OfMethod(v zero.Interface) string
- func OfType(v zero.Interface) string
- func OfTypeFull(v zero.Interface) string
- func PkgPathOf(v zero.Interface) string
- func SQLObject(parts ...string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvKey ¶
EnvKey derives the name of the environment key for a set of strings (which will be joined by underscores).
func OfFunc ¶
OfFunc returns the name of a function.
Example ¶
package main import ( "fmt" "go.stevenxie.me/gopkg/name" ) type SomeStruct struct { SomeField string } func (ss SomeStruct) SomeMethod() {} func ExampleOfFunc() { fmt.Println(name.OfFunc(SomeStruct.SomeMethod)) fmt.Println(name.OfFunc(ExampleOfFunc)) } func main() { fmt.Println(name.OfFunc(SomeStruct.SomeMethod)) fmt.Println(name.OfFunc(ExampleOfFunc)) }
Output: name_test.SomeStruct.SomeMethod name_test.ExampleOfFunc
func OfFuncFull ¶
OfFuncFull returns the full name of a function, within the context of its import path.
Example ¶
package main import ( "fmt" "go.stevenxie.me/gopkg/name" ) type SomeStruct struct { SomeField string } func (ss SomeStruct) SomeMethod() {} func ExampleOfFunc() { fmt.Println(name.OfFunc(SomeStruct.SomeMethod)) fmt.Println(name.OfFunc(ExampleOfFunc)) } func main() { fmt.Println(name.OfFuncFull(SomeStruct.SomeMethod)) fmt.Println(name.OfFuncFull(ExampleOfFunc)) }
Output: go.stevenxie.me/gopkg/name_test.SomeStruct.SomeMethod go.stevenxie.me/gopkg/name_test.ExampleOfFunc
func OfMethod ¶
OfMethod returns the name of a method on a struct or interface.
Example ¶
package main import ( "fmt" "go.stevenxie.me/gopkg/name" ) type SomeStruct struct { SomeField string } func (ss SomeStruct) SomeMethod() {} func main() { fmt.Println(name.OfMethod(SomeStruct.SomeMethod)) }
Output: SomeMethod
func OfType ¶
OfType returns the type name of a value.
Example ¶
package main import ( "fmt" "go.stevenxie.me/gopkg/name" "go.stevenxie.me/gopkg/zero" ) type SomeIface zero.Interface type SomeStruct struct { SomeField string } func (ss SomeStruct) SomeMethod() {} func main() { fmt.Println(name.OfType((*SomeStruct)(nil))) fmt.Println(name.OfType((*SomeIface)(nil))) }
Output: name_test.SomeStruct name_test.SomeIface
func OfTypeFull ¶
OfTypeFull returns the full type name of a value, including its import path.
Example ¶
package main import ( "fmt" "go.stevenxie.me/gopkg/name" "go.stevenxie.me/gopkg/zero" ) type SomeIface zero.Interface type SomeStruct struct { SomeField string } func (ss SomeStruct) SomeMethod() {} func main() { fmt.Println(name.OfTypeFull((*SomeStruct)(nil))) fmt.Println(name.OfTypeFull((*SomeIface)(nil))) }
Output: go.stevenxie.me/gopkg/name_test.SomeStruct go.stevenxie.me/gopkg/name_test.SomeIface
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.