util

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2015 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TemplateSuffix = ".tmpl"
)

Variables

View Source
var (
	// Now returns current time. This is for mock in tests.
	Now = func() time.Time { return time.Now() }

	// for test.
	ImportDir = build.ImportDir
)

Functions

func CopyTemplate

func CopyTemplate(srcPath, dstPath string, data map[string]interface{}) error

func DetectContentTypeByBody

func DetectContentTypeByBody(r io.Reader) (contentType string)

Get Content-Type by content body

func DetectContentTypeByExt

func DetectContentTypeByExt(path string) (contentType string)

Get Content-Type by extension of filename.

func FindAppDir

func FindAppDir() (string, error)

FindAppDir returns application directory. (aka import path) An application directory retrieves from current working directory. For example, if current working directory is "/path/to/gopath/src/github.com/naoina/myapp", FindAppDir returns "github.com/naoina/myapp".

func FindEnv added in v0.7.0

func FindEnv() (map[string]string, error)

FindEnv returns map of environment variables. Key of map is key of environment variable, Value of map is value of environment variable.

func GenerateRandomKey

func GenerateRandomKey(length int) []byte

Generate a random bytes.

func GoString

func GoString(i interface{}) string

GoString returns Go-syntax representation of the value. It returns compilable Go-syntax that different with "%#v" format for fmt package.

func Gunzip

func Gunzip(gz string) string

Gunzip returns unzipped string.

func Gzip

func Gzip(raw string) string

Gzip returns gzipped string.

func IsUnexportedField

func IsUnexportedField(field reflect.StructField) bool

IsUnexportedField returns whether the field is unexported. This function is to avoid the bug in versions older than Go1.3. See following links:

https://code.google.com/p/go/issues/detail?id=7247
http://golang.org/ref/spec#Exported_identifiers

func NormPath

func NormPath(p string) string

func PanicOnError

func PanicOnError(usager usager, format string, a ...interface{})

func PrintBlue

func PrintBlue(s string, a ...interface{})

func PrintConflict

func PrintConflict(path string)

func PrintCreate

func PrintCreate(path string)

func PrintCreateDirectory

func PrintCreateDirectory(path string)

func PrintCyan

func PrintCyan(s string, a ...interface{})

func PrintEnv added in v0.7.0

func PrintEnv() error

func PrintExist

func PrintExist(path string)

func PrintGreen

func PrintGreen(s string, a ...interface{})

func PrintIdentical

func PrintIdentical(path string)

func PrintMagenta

func PrintMagenta(s string, a ...interface{})

func PrintOverwrite

func PrintOverwrite(path string)

func PrintRed

func PrintRed(s string, a ...interface{})

func PrintSkip

func PrintSkip(path string)

func PrintYellow

func PrintYellow(s string, a ...interface{})

func RunCommand

func RunCommand(cmd Commander)

func SplitExt

func SplitExt(path string) (name, ext string)

SplitExt returns pair of file name and extension.

It will truncated a dot of extension. e.g. When the given path is "path/to/image.png", SplitExt returns ("path/to/image", "png").

func ToCamelCase

func ToCamelCase(s string) string

func ToSnakeCase

func ToSnakeCase(s string) string

Types

type Commander

type Commander interface {
	Run(args []string) error
	Name() string
	Usage() string
	Option() interface{}
}

type Error

type Error struct {
	Usager  usager
	Message string
}

func (Error) Error

func (e Error) Error() string

Jump to

Keyboard shortcuts

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