util

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2015 License: BSD-3-Clause Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset added in v0.0.3

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir added in v0.0.3

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo added in v0.0.3

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames added in v0.0.3

func AssetNames() []string

AssetNames returns the names of the assets.

func CutKey

func CutKey(key string) string

CutKey cuts key to 11words.

func Datestr2ch

func Datestr2ch(epoch int64) string

Datestr2ch converts unixtime str ecpochStr to the certain format string. e.g. 2006/01/02(日) 15:04:05.99

func EachFiles

func EachFiles(dir string, handler func(dir os.FileInfo) error) error

EachFiles iterates each dirs in dir and calls handler,not recirsively.

func EachIOLine

func EachIOLine(f io.ReadCloser, handler func(line string, num int) error) error

EachIOLine iterates each line to a ReadCloser ,calls func and close f.

func EachKeyValueLine

func EachKeyValueLine(path string, handler func(key string, value []string, num int) error) error

EachKeyValueLine calls func for each line which contains key and value separated with "<>"

func EachLine

func EachLine(path string, handler func(line string, num int) error) error

EachLine iterates each lines and calls a func.

func EmbedURL added in v0.0.3

func EmbedURL(url string) string

EmbedURL gets the url for embeding by using oEmbed API.

func Emoji added in v0.0.8

func Emoji(str string) string

Emoji converts :hoe: to a png pic link.

func Escape

func Escape(msg string) string

Escape is like a html.escapestring, except &#xxxx and \n

func EscapeSpace

func EscapeSpace(msg string) string

EscapeSpace converts spaces into html space.

func Fclose

func Fclose(f io.Closer)

Fclose closes io.Close, if err exists ,println err.

func FileDecode

func FileDecode(query string) string

FileDecode decodes filename.

>>> file_decode('foo_7E')
'~'

func FileEncode

func FileEncode(t, query string) string

FileEncode encodes filename.

>>> file_encode('foo', 'a')
'foo_61'
>>> file_encode('foo', '~')
'foo_7E'

func FileHash

func FileHash(query string) string

FileHash simply returns itself, because it does not implement other types except 'asis'.

func FileSize

func FileSize(path string) int64

FileSize returns file size of file. returns 0 if file is not found.

func FindString

func FindString(s []string, val string) int

FindString search the val in ary and returns index. it returns -1 if not found.

func FromSJIS

func FromSJIS(b string) string

FromSJIS converts an array of bytes (a valid ShiftJIS string) to a UTF-8 string

func GetBoard

func GetBoard(url string) string

GetBoard returns decoded board name.

func HasExt added in v0.0.3

func HasExt(fname, suffix string) bool

HasExt returns true if fname has prefix and not secret.

func HasString

func HasString(s []string, val string) bool

HasString returns true if ary has val.

func IsDir

func IsDir(path string) bool

IsDir returns true is path is an existing dir.

func IsFile

func IsFile(path string) bool

IsFile returns true is path is an existing file.

func IsValidImage

func IsValidImage(mimetype, path string) bool

IsValidImage checks type of path is same as mimetype or not.

func MD5digest

func MD5digest(dat string) string

MD5digest returns hex string of md5sum

func MakeThumbnail

func MakeThumbnail(encoded []byte, suffix, thumbnailSize string) []byte

MakeThumbnail makes thumbnail to suffix image format with thumbnailSize.

func MoveFile

func MoveFile(src, dst string) error

MoveFile moves a file from src to dest.

func MustAsset added in v0.0.3

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RegistToRouter

func RegistToRouter(s *mux.Router, path string, fn func(w http.ResponseWriter, r *http.Request))

RegistToRouter registers fn to s with path and returns the handler.

func RestoreAsset added in v0.0.3

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets added in v0.0.3

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func Shuffle

func Shuffle(slc Shufflable)

Shuffle shuffles shufflable ary.

func StrDecode

func StrDecode(query string) string

StrDecode decode from url query

func StrEncode

func StrEncode(query string) string

StrEncode returns enscaped string for url , including "~"

func ToSJIS

func ToSJIS(b string) string

ToSJIS converts an string (a valid UTF-8 string) to a ShiftJIS string

func Verify

func Verify(mesg, testsig, publicKey string) bool

Verify verifies testsig by publicKey.

func WriteFile

func WriteFile(path, data string) error

WriteFile writes date to path.

func WriteMap

func WriteMap(path string, ary map[string][]string) error

WriteMap write map into a path.

func WriteSlice

func WriteSlice(path string, ary []string) error

WriteSlice write ary into a path.

Types

type ConfList

type ConfList struct {
	// contains filtered or unexported fields
}

ConfList represents regexp list.

One regexp per one line.

func NewConfList

func NewConfList(path string, defaultList []string) *ConfList

NewConfList makes a confList instance from path.

func (*ConfList) GetData

func (r *ConfList) GetData() []string

GetData retuns a copy of lines in the file.

func (*ConfList) GetSplitData added in v0.0.12

func (r *ConfList) GetSplitData() [][]string

GetSplitData retuns a copy of splitted lines by ", " in the file.

type Htemplate

type Htemplate struct {
	*htmlTemplate.Template
}

Htemplate is for rendering html stuff.

func NewHtemplate

func NewHtemplate(templateDir string) *Htemplate

NewHtemplate adds funcmap to template var and parse files.

func (*Htemplate) ExecuteTemplate

func (t *Htemplate) ExecuteTemplate(file string, st interface{}) string

ExecuteTemplate executes template and returns it as string.

func (*Htemplate) RenderTemplate

func (t *Htemplate) RenderTemplate(file string, st interface{}, wr io.Writer)

RenderTemplate executes template and write to wr.

type PrivateKey

type PrivateKey struct {
	// contains filtered or unexported fields
}

PrivateKey reppresents private key,

func MakePrivateKey

func MakePrivateKey(keystr string) *PrivateKey

MakePrivateKey makes privatekey from keystr

func (*PrivateKey) GetKeys

func (p *PrivateKey) GetKeys() (string, string)

GetKeys returns base64 encoded private key

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(mesg string) string

Sign signs mesg by p.

type RegexpList

type RegexpList struct {
	*ConfList
	// contains filtered or unexported fields
}

RegexpList represents RegExp list.

One regexp per one line.

func NewRegexpList

func NewRegexpList(path string) *RegexpList

NewRegexpList makes a regexpList and regexp.comples each lines in the file.

func (*RegexpList) Check

func (r *RegexpList) Check(target string) bool

Check returns true if target matches one of all regexps or not.

type Shufflable

type Shufflable interface {
	Len() int
	Swap(i int, j int)
}

Shufflable interface is for shuffle ary.

type Ttemplate

type Ttemplate struct {
	*textTemplate.Template
}

Ttemplate is for rendering text rss template.

func NewTtemplate

func NewTtemplate(templateDir string) *Ttemplate

NewTtemplate adds funcmap to template var and parse files.

func (*Ttemplate) RenderTemplate

func (t *Ttemplate) RenderTemplate(file string, st interface{}, wr io.Writer)

RenderTemplate executes rss template and write to wr.

Jump to

Keyboard shortcuts

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