utils

package
v0.0.0-...-9879e40 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CookieSession string = "SessionID"
	CookieToken   string = "Token"
)

const value for global use

Variables

This section is empty.

Functions

func AppendHTML

func AppendHTML(template, pattern string) (string, error)

AppendHTML append content the symbol is <!-- {{{ }}} -->

func AppendObj

func AppendObj(body interface{}, name, pattern string) (string, error)

AppendObj append obj into html and return by string

func AppendPage

func AppendPage(body interface{}, name, pattern string) error

AppendPage update html after append a obj

func CheckPanic

func CheckPanic(err error)

CheckPanic check err != nil panic

func DeleteHTML

func DeleteHTML(template, pattern string) (string, error)

DeleteHTML delete obj by pattern to string

func DeleteObj

func DeleteObj(body interface{}, name, pattern string) (string, error)

DeleteObj delete a struct obj by pattern to string

func DeletePage

func DeletePage(body interface{}, name, pattern string) error

DeletePage delete a obj in html

func Err

func Err(text string) error

Err is custom error custommed from string

func Errs

func Errs(text string, err error) error

Errs is to merge a err and a string

func IsDir

func IsDir(dir string) (bool, error)

IsDir check is Dir

func IsFile

func IsFile(name string) (bool, error)

IsFile check file exist

func ReadHTML

func ReadHTML(name string) (string, error)

ReadHTML read html file

func ReadLog

func ReadLog(logName string) (string, error)

ReadLog read log

func ReplaceHTML

func ReplaceHTML(template string, num int, pattern string) (string, error)

ReplaceHTML check replace template

func ReplacePattern

func ReplacePattern(pattern string, body interface{}) (string, error)

ReplacePattern replace {{{ num }}} in pattern by struct

func SaveHTML

func SaveHTML(name, html string) error

SaveHTML save html file from string

func WriteLog

func WriteLog(logger *log.Logger, logName string, logInfo interface{})

WriteLog write into log Println only

func WriteLogFunc

func WriteLogFunc(logger *log.Logger, logName string, logFunc LogActCallback)

WriteLogFunc write into log by func

Types

type CookieFunction

type CookieFunction interface {
	NewCookie()
	SetSession()
	SetToken()
	IsSession()
	IsToken()
}

CookieFunction define cookie

type CookieUtils

type CookieUtils struct {
	*sync.RWMutex // Read & Write locker
	// contains filtered or unexported fields
}

CookieUtils keep date in memory

func NewCookie

func NewCookie(defaultExpiration time.Duration) *CookieUtils

NewCookie create new in memory cookie storage save Cookie by default time

func (*CookieUtils) IsSession

func (c *CookieUtils) IsSession(sessionID string) bool

IsSession check sessionID

func (*CookieUtils) IsToken

func (c *CookieUtils) IsToken(token string) bool

IsToken check if is token then delete it

func (*CookieUtils) SetSession

func (c *CookieUtils) SetSession() string

SetSession generate client uuid and store in memory return session for setting cookie

func (*CookieUtils) SetToken

func (c *CookieUtils) SetToken() string

SetToken set token, use once only return token for setting cookie

type LogActCallback

type LogActCallback func(*log.Logger)

LogActCallback for log call back

type LogFunction

type LogFunction interface {
	// write log
	WriteLog()
	// write log by extra func
	WriteLogFunc()
	// read log
	ReadLog()
}

LogFunction for doing log action

Jump to

Keyboard shortcuts

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