utils

package
v0.0.0-...-6a7966f Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2018 License: MIT Imports: 14 Imported by: 10

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(source string, dest string) (err error)

CopyDir recursively copies a directory tree, attempting to preserve permissions. The source directory must exist, but destination directory must *not* exist.

func CopyFile

func CopyFile(source string, dest string) (err error)

CopyFile copies the source file to the destination file. If the destination file does not yet exist, it will create a new file there.

func DateFormat

func DateFormat(t *time.Time, format string) string

DateFormat implements formatted printing for time.Time values. It is similar to fmt's printf utility, although the verbs are different.

The verbs:

%B		the full month, ex: "January"
%b		an abbreviation of the month, ex: "Jan"
%m 		the month as a number, with the leading zero included, ex: "01"
%A		the full weekday, ex: "Monday"
%a		an abbreviation of the weekday, ex: "Mon"
%d		the day, with the leading zero included, ex: "31"
%H		the hour, in 24 hour time, with the leading zero included, ex: "15"
%I		the hour, in 12 hour time, with the leading zero included, ex: "08"
%M		the minute, with the leading zero included, ex: "42"
%S		the second, with the leading zero included, ex: "58"
%Y		the full year, ex: "2016"
%y		the last two digits of the year, ex: "16"
%p		the meridiem, or more simply put, AM or PM, ex: "AM"
%Z		letters representing the timezone, ex: "MST"
%z		numbers representing the timezone, ex: "-0700"
%L		milliseconds, ex: ".000"
Example
t := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
fmt.Println(DateFormat(&t, "%Y-%m-%d %H:%M"))
Output:

2009-11-10 23:00

func FailOnError

func FailOnError(err error, msg string, appendErr ...bool)

func FileSize

func FileSize(size int64) string

FileSize returns the file size as a string, formatted in the way people usually see filenames, ex: "1MB", "3KB", "60B".

func Gravatar

func Gravatar(email string, size string) string

Gravatar generates a Gravatar link with a given email and size. Images are always square, so we only accept a single argument for the size.

func Html2Excerpt

func Html2Excerpt(html string, length int) string

Html2Excerpt returns the string from the given HTML that is "length" long.

func Html2Str

func Html2Str(html string) string

Html2Str converts the given HTML to a string, removing all HTML tags, scripts, and styles, and removing continuous newline characters.

func IsASCII

func IsASCII(str string) bool

IsASCII returns whether or not the string contains only ASCII characters.

func IsContain

func IsContain(str string, contain string) bool

IsContain returns whether or not the second string exists within the first string.

func IsDir

func IsDir(path string) bool

IsDir returns whether or not a given path name has a corresponding directory name.

func IsEmail

func IsEmail(str string) bool

IsEmail returns whether or not a string resembles an email.

func IsEmptyString

func IsEmptyString(str string) bool

IsEmptyString returns whether or not a string is empty.

func IsEnglish

func IsEnglish(str string) bool

IsEnglish returns whether or not the string is in English by looking at the character set.

func IsFile

func IsFile(path string) bool

IsFile returns whether or not a given path name has a corresponding file name.

func IsLonger

func IsLonger(str string, length int) bool

IsLonger returns whether or not the string is longer than the given length.

func IsShorter

func IsShorter(str string, length int) bool

IsShorter returns whether or not the string is shorter than the given length.

func IsURL

func IsURL(str string) bool

IsURL returns whether or not a string is a URL.

func LogOnEither

func LogOnEither(err error, successMsg, errorMsg string, appendErr ...bool)

func LogOnError

func LogOnError(err error, msg string, appendErr ...bool)

func LogOnSuccess

func LogOnSuccess(err error, msg string)

func Markdown2Html

func Markdown2Html(text string) string

Markdown2Html returns the given text as Markdown, using BlackFriday as a markdown compiler.

func Markdown2HtmlTemplate

func Markdown2HtmlTemplate(text string) template.HTML

Markdown2HtmlTemplate returns the given text as Markdown, as the template package's HTML type.

func Now

func Now() *time.Time

Now returns the current time.

func Output

func Output(s string)

func ReadMemStats

func ReadMemStats() *monitorStats

ReadMemStats reads and returns various stats from the runtime. Used for displaying runtime info is the admin dashboard.

func Sha1

func Sha1(raw string) string

Sha1 creates a SHA1 checksum of the given string.

func SubString

func SubString(str string, begin, length int) (substr string)

SubString returns a substring of the given string from "begin" that is of "length" characters long.

Types

type Pager

type Pager struct {
	Current   int64
	Size      int64
	Total     int64
	Pages     int64
	PageSlice []int64
	Begin     int64
	End       int64
	Prev      int64
	Next      int64
	IsPrev    bool
	IsNext    bool
	IsValid   bool
}

A Pager contains info used to handle pagination.

func NewPager

func NewPager(page, size, total int64) *Pager

NewPager returns a new Pager, with the given options. It will panic if the pager size is less than zero.

Jump to

Keyboard shortcuts

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