name

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package name is a utility package that can derive the names of things.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvKey

func EnvKey(parts ...string) string

EnvKey derives the name of the environment key for a set of strings (which will be joined by underscores).

func OfFunc

func OfFunc(v zero.Interface) string

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

func OfFuncFull(v zero.Interface) string

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

func OfMethod(v zero.Interface) string

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

func OfType(v zero.Interface) string

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

func OfTypeFull(v zero.Interface) string

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

func PkgPathOf added in v0.4.4

func PkgPathOf(v zero.Interface) string

PkgPathOf returns the package path of v.

Example
fmt.Println(name.PkgPathOf((*SomeStruct)(nil)))
fmt.Println(name.PkgPathOf(ExamplePkgPathOf))
Output:

go.stevenxie.me/gopkg/name_test
go.stevenxie.me/gopkg/name_test

func SQLObject added in v0.4.8

func SQLObject(parts ...string) string

SQLObject snake-cases the given parts to derive an SQLObject object name.

Types

This section is empty.

Jump to

Keyboard shortcuts

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