Documentation
¶
Index ¶
- Constants
- Variables
- func AccessAllowOriginBy(category int, origins string)
- func AccessAllowOriginByLocal(category int)
- func CopyFile(src string, dest string) (bool, error)
- func CopyFileTo(src string, dir string) (bool, error)
- func DayDiff(start, end time.Time) (int, int, int, int)
- func DeleteFile(file string) error
- func DeletePath(dirpath string) error
- func DurDays(start, end time.Time, format ...string) string
- func DurHours(start, end time.Time, format ...string) string
- func EncodeUrl(rawurl string) string
- func EnsurePath(filepath string) error
- func FileMD5(file string) (string, error)
- func FixPath(input string) string
- func FormatUnix(layout string, unixsec int64, unixnsec ...int64) string
- func GetKeyWords(str string) []string
- func GetSortKey(str string) string
- func HourDiff(start, end time.Time) (int, int, int)
- func HttpClientGet(tagurl string, useTLS bool, params ...interface{}) ([]byte, error)
- func HttpClientGetStruct(tagurl string, useTLS bool, out interface{}, params ...interface{}) error
- func HttpClientPost(tagurl string, useTLS bool, postdata ...interface{}) ([]byte, error)
- func HttpClientPostStruct(tagurl string, useTLS bool, out interface{}, postdata ...interface{}) error
- func HttpGet(tagurl string, params ...interface{}) ([]byte, error)
- func HttpGetString(tagurl string, params ...interface{}) (string, error)
- func HttpGetStruct(tagurl string, out interface{}, params ...interface{}) error
- func HttpPost(tagurl string, postdata interface{}, contentType ...string) ([]byte, error)
- func HttpPostString(tagurl string, postdata interface{}, contentType ...string) (string, error)
- func HttpPostStruct(tagurl string, postdata, out interface{}, contentType ...string) error
- func HumanReadable(len int64, during int64) string
- func IgnoreSysSignalPIPE()
- func IsDir(dirpath string) bool
- func IsDir2(file *os.File) bool
- func IsExistFile(filepath string) bool
- func IsFile(filepath string) bool
- func IsFile2(file *os.File) bool
- func IsSameDay(src string, des string) bool
- func IsSameTime(src string, des string) bool
- func IsToday(des string) bool
- func IsTodayUnix(des int64) bool
- func MakeDirs(dirpath string, perm ...os.FileMode) error
- func MonthUnix() int64
- func NextMonth() int64
- func NextQuarter() int64
- func NextTime(duration time.Duration) int64
- func NextUnix(duration time.Duration) int64
- func NextUnix2(years, months, days int) int64
- func NextWeek() int64
- func NextYear() int64
- func OpenFileTrunc(filepath string, perm ...os.FileMode) (*os.File, error)
- func OpenFileWrite(filepath string, perm ...os.FileMode) (*os.File, error)
- func QuarterUnix() int64
- func ReadPropFile(path string) (map[string]string, error)
- func RemoveDuplicate(oldArr []string) []string
- func SaveB64File(filepath, filename string, b64data string) error
- func SaveFile(filepath, filename string, data []byte) error
- func Ternary(condition bool, trueResult interface{}, falseResult interface{}) interface{}
- func To2Digits(input interface{}) string
- func To3Digits(input interface{}) string
- func ToNDigits(input interface{}, n int) string
- func Today() int64
- func TodayUnix() int64
- func Tommorrow() int64
- func TommorrowUnix() int64
- func Try(do func(), catcher func(error), finaly ...func())
- func VerifyFile(fh *multipart.FileHeader, maxBytes ...int64) (string, error)
- func VerifyFileFormat(fh *multipart.FileHeader, format string, size int64) (string, error)
- func WeekUnix() int64
- func YearDiff(start, end time.Time) (int, int, int)
- func YearUnix() int64
- func Yesterday() int64
- func YesterdayUnix() int64
- type EmailContent
- type MailAgent
- func (a *MailAgent) SendAttach(email EmailContent, mailto, attach string, format ...map[string]string) error
- func (a *MailAgent) SendCode(email EmailContent, mailto string, code string) error
- func (a *MailAgent) SendFormat(email EmailContent, mailto string, format ...map[string]string) error
- func (a *MailAgent) SendMail(to []string, subject, body string, attach ...string) error
- type Queue
- type SmsContent
- type SmsSender
- type Stack
- type Task
- type TaskCallback
Constants ¶
const ( // ContentTypeJson json content type ContentTypeJson = "application/json;charset=UTF-8" // ContentTypeForm form content type ContentTypeForm = "application/x-www-form-urlencoded" )
const ( Day = time.Hour * 24 Week = Day * 7 Month = Day * 30 Quarter = Month * 3 Year = Day * 365 )
Day, week, month, quarter, year duration on nanosecond
const ( DayMs = Day / time.Millisecond WeekMs = Week / time.Millisecond MonthMs = Month / time.Millisecond QuarterMs = Quarter / time.Millisecond YearMs = Year / time.Millisecond )
Day, week, month, quarter, year duration on millisecond
const ( DaySeconds = Day / time.Second WeekSeconds = Week / time.Second MonthSeconds = Month / time.Second QuarterSeconds = Quarter / time.Second YearSeconds = Year / time.Second )
Day, week, month, quarter, year duration on second
const ( // DateLayout standery date layout format at day minimum DateLayout = "2006-01-02" // TimeLayout standery time layout format at second minimum TimeLayout = "2006-01-02 15:04:05" // HourLayout standery time layout format as hour HourLayout = "15:04:05" // MSLayout standery time layout format at million second minimum MSLayout = "2006-01-02 15:04:05.000" // DateNoneHyphen standery time layout format at second minimum without hyphen char DateNoneHyphen = "20060102" // TimeNoneHyphen standery time layout format at second minimum without hyphen char TimeNoneHyphen = "20060102150405" // HourNoneHyphen standery time layout format as hour without hyphen char HourNoneHyphen = "150405" // MSNoneHyphen standery time layout format at million second minimum without hyphen char MSNoneHyphen = "20060102150405000" )
Variables ¶
var Segmenter sego.Segmenter
Variables of Sego
Functions ¶
func AccessAllowOriginBy ¶
AccessAllowOriginBy allow cross domain access for the given origins
func AccessAllowOriginByLocal ¶
func AccessAllowOriginByLocal(category int)
AccessAllowOriginByLocal allow cross domain access for localhost
func CopyFileTo ¶
CopyFileTo copy source file to given dir.
func DurDays ¶
DurDays return readable time during start to end: 2d 6h 25m 48s, you can set the format string, but it must contain 4 %0xd to parse numbers
func DurHours ¶
DurHours return readable time during start to end: 06:25:48, you can se the format string, but it must contain 3 %0xd to parse numbers
func EnsurePath ¶
EnsurePath check the given file path, or create new one if unexist
func FixPath ¶
FixPath fix path, ep:
/aaa/aa\\bb\\cc/d///// -> /aaa/aa/bb/cc/d E:/aaa/aa\\bb\\cc/d////e/ -> E:/aaa/aa/bb/cc/d/e "" -> . / -> /
func FormatUnix ¶ added in v1.0.13
FormatUnix format unix time to given time layout
func HttpClientGet ¶
HttpClientGet handle get by http.Client, you can set useTLS to enable TLS or not
func HttpClientGetStruct ¶
HttpClientGetStruct handle http get method and unmarshal data to struct object
func HttpClientPost ¶
HttpClientGet handle post by http.Client, you can set useTLS to enable TLS or not
func HttpClientPostStruct ¶
func HttpClientPostStruct(tagurl string, useTLS bool, out interface{}, postdata ...interface{}) error
HttpClientPostStruct handle http post method and unmarshal data to struct object
func HttpGetString ¶
HttpGetString call HttpGet and trim " char both begin and end
func HttpGetStruct ¶
HttpGetStruct handle http get method and unmarshal data to struct object
func HttpPost ¶
HttpPost handle http post method, you can set content type as comm.ContentTypeJson or comm.ContentTypeForm, or other you need set. [CODE:]
// set post data as json string data := struct {"key": "Value", "id": "123"} resp, err := comm.HttpPost(tagurl, data) // set post data as form string data := "key=Value&id=123" resp, err := comm.HttpPost(tagurl, data, comm.ContentTypeForm)
[CODE]
func HttpPostString ¶
HttpPostString call HttpPost and trim " char both begin and end.
func HttpPostStruct ¶
HttpPostStruct handle http post method and unmarshal data to struct object
func HumanReadable ¶
HumanReadable format the size number of len.
func IsExistFile ¶
IsExistFile check whether the file exists.
func IsSameTime ¶
IsSameTime equal given time string based on TimeLayout
func IsTodayUnix ¶
IsTodayUnix check the given time string if today
func NextQuarter ¶
func NextQuarter() int64
NextQuarter return next quarter unix time start from current
func OpenFileTrunc ¶
OpenFileTrunc create new file for trunc content, by default perm is 0666.
func OpenFileWrite ¶
OpenFileWrite create new file for write content, by default perm is 0666.
func ReadPropFile ¶
ReadPropFile read properties file on filesystem.
func RemoveDuplicate ¶
RemoveDuplicate remove duplicate data from array
func SaveB64File ¶
SaveB64File save base64 encoded buffer to target file
func Ternary ¶
func Ternary(condition bool, trueResult interface{}, falseResult interface{}) interface{}
Ternary ternary operation
func To2Digits ¶
func To2Digits(input interface{}) string
To2Digits fill zero if input digit not enough 2
func To3Digits ¶
func To3Digits(input interface{}) string
To2Digits fill zero if input digit not enough 3
func VerifyFile ¶
func VerifyFile(fh *multipart.FileHeader, maxBytes ...int64) (string, error)
VerifyFile verify upload file and size, it support jpg/jpeg/JPG/JPEG/png/PNG/mp3/mp4 suffix.
func VerifyFileFormat ¶
VerifyFileFormat verify upload file and size in MB.
Types ¶
type EmailContent ¶
type EmailContent struct { Subject string // email title or subject Body string // email body content }
EmailContent email template
type MailAgent ¶
type MailAgent struct { Acc string `json:"acc"` // username - mail address Pwd string `json:"pwd"` // account password Host string `json:"host"` // stmp/pop3 host Port int `json:"port"` // stmp/pop3 port }
MailAgent mail agent informations..
func (*MailAgent) SendAttach ¶
func (a *MailAgent) SendAttach(email EmailContent, mailto, attach string, format ...map[string]string) error
SendAttach send mail with formated map and attach file
func (*MailAgent) SendCode ¶
func (a *MailAgent) SendCode(email EmailContent, mailto string, code string) error
* SendCode send verify email with code * * The SMS templetes same as: * [CODE:] * TplEmailRegister = EmailContent{"Account Verify Of XXX", ` * <html> * <body> * <h3> Dear NAME </h3> * <p> Thank you for register XXX, the registration verification code is : <h3> TOKEN </h3>, please activate your account in time.</br> * Please DO NOT forward this code to others. If not myself, please delete this email.</p> * </br> * <h5>XXX Technology Co., Ltd</h5> * </body> * </html>`} * [CODE]
func (*MailAgent) SendFormat ¶
func (a *MailAgent) SendFormat(email EmailContent, mailto string, format ...map[string]string) error
SendFormat send mail with formated map
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue the type of queue with sync lock
func (*Queue) Dump ¶
func (q *Queue) Dump()
Dump print out the queue data. this method maybe just use for debug to out put queue items
func (*Queue) Pick ¶
Pick pick but not remove the front data of queue, it will return invar.ErrEmptyData error if the queue is empty
type SmsContent ¶
type SmsContent struct { SignName string TemplateCode string TemplatePrefix string TemplateSuffix string TemplateContent string }
SmsContent sms template
type SmsSender ¶
type SmsSender struct {
// contains filtered or unexported fields
}
SmsSender sender, including smtp authtication and user info
func NewSmsSender ¶
NewSmsSender create a sms sender for given cloud service
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack the type of stack with sync lock
func (*Stack) Dump ¶
func (s *Stack) Dump()
Dump print out the stack data. this method maybe just use for debug to out put stack items
func (*Stack) Pick ¶
Pick pick but not remove the top data of stack, it will return invar.ErrEmptyData error if the stack is empty
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task the type of task
func GenTask ¶
func GenTask(callback TaskCallback, configs ...int) *Task
GenTask generat a new task instance, you can set the interval duration and interrupt flag as the follow format: [CODE:]
interrupt := 1 // interrupt to execut the remain tasks when case error interval := 500 // sleep interval between tasks in microseconds task := comm.GenTask(callback, interrupt, interval) task.Post(taskdata)
[CODE]
func (*Task) SetInterrupt ¶
SetInterrupt set interrupt flag
func (*Task) SetInterval ¶
setInterval set wait interval between tasks in microseconds, and it must > 0.