Documentation ¶
Index ¶
- Constants
- Variables
- func AccessDenied(w http.ResponseWriter, r *http.Request, reason ...interface{})
- func AppendList(ls []interface{}, x ...interface{}) []interface{}
- func BytesToPrivateKey(priv []byte) (*rsa.PrivateKey, error)
- func BytesToPublicKey(pub []byte) (*rsa.PublicKey, error)
- func ComputeChecksum(h hash.Hash, f io.Reader) (string, error)
- func ComputeMD5Checksum(filename string) (string, error)
- func ComputeSHA1Checksum(filename string) (string, error)
- func ConnectDB(uri string) (*mongo.Client, error)
- func ContainsDotDot(v string) bool
- func ConvertDate(date, input_fmt, output_fmt string) string
- func CopyFile(src, dst string) (int64, error)
- func CorrectBackSlash(str string) string
- func CreateList(x ...interface{}) []interface{}
- func DecryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey) ([]byte, error)
- func DirExists(path string) bool
- func EncryptWithPublicKey(msg []byte, pub *rsa.PublicKey) ([]byte, error)
- func Error(x ...interface{})
- func ExtractIP(address string) string
- func Field(x map[string]interface{}, key string) interface{}
- func FileExists(filename string) bool
- func FuncName(x interface{}) string
- func GenKey(n int) string
- func GenRawKey(n int) ([]byte, error)
- func GenerateKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func GetCloudFlareIdentifier(email, apiKey, domain string) (string, error)
- func GetIP(r *http.Request) string
- func GetJSON(url string, out interface{}) error
- func GetObjectID(x url.Values) (primitive.ObjectID, error)
- func HashPassword(pw, uname string) string
- func JSONParse(r *http.Request, x interface{}) error
- func JSONReply(w http.ResponseWriter, x interface{}) error
- func JoinString(sep string, s ...string) string
- func ListContainString(v []string, s string) bool
- func LocalRedirect(w http.ResponseWriter, r *http.Request, newPath string)
- func Log(x ...interface{})
- func MD5ChecksumStream(f io.Reader) (string, error)
- func ParseJSONString(str string, x interface{}) error
- func PostJSON(url string, x interface{}) error
- func PrintJSON(x interface{})
- func PrintString(x interface{}) string
- func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte
- func PublicKeyToBytes(pub *rsa.PublicKey) ([]byte, error)
- func RandInt(min, max int) int
- func RandPassword(length int) string
- func ReadBody(r *http.Request) ([]byte, error)
- func ReadTextFile(fname string) (string, error)
- func Redirect(w http.ResponseWriter, r *http.Request, newPath string)
- func RedirectHandler(newPath string) http.HandlerFunc
- func RemoveJSONComment(s string) string
- func RemoveSpace(str string) string
- func Reverse(s string) string
- func Run(addr string, handler http.Handler)
- func RunMongoSession(c *mongo.Client, ctx context.Context, ...) (interface{}, error)
- func SHA1ChecksumStream(f io.Reader) (string, error)
- func SHA256(data string) string
- func SafeAt(a interface{}, index int) interface{}
- func StringsToInterfaces(s []string) []interface{}
- func ToArray(x interface{}) []interface{}
- func ToBool(x interface{}) bool
- func ToFloat(x interface{}) float64
- func ToInt(x interface{}) int
- func ToJSONString(x interface{}) string
- func ToString(x interface{}) string
- func ToXLink(path string) string
- func URLFirstTwoPath(url string) (string, string)
- func URLSplit2(url string) (string, string)
- func URLSplit3(url string) (string, string, string)
- func UnmarshalJSONFile(fname string, x interface{}) error
- func VerifyBriefDate(s string) bool
- func Wait(shutdownFunc ...func())
- type AESCipher
- type CronJob
- type Date
- func (d *Date) Add(years, months, days int) error
- func (d *Date) Format(layout string) (string, error)
- func (d *Date) FullFormat() (string, error)
- func (d *Date) ParseString(s string) error
- func (d *Date) Set(year, month, day int)
- func (d *Date) String() string
- func (d *Date) Time() (time.Time, error)
- type HTTPFS
- type RecaptchaResponse
- type TempMan
- type TempMap
Constants ¶
const ( BriefDateFormat = "20060102" FullDateFormat = "02-01-2006" )
Variables ¶
var (
ErrDecodeX509Fail = errors.New("decode x509 data to rsa key failed.")
)
var ( // ErrInvalidDateStringValue ... ErrInvalidDateStringValue = errors.New("invalid date string value") )
var ( // ErrInvalidRecaptchaToken ... ErrInvalidRecaptchaToken = errors.New("invalid google recaptcha token") )
var ErrNotFoundCloudFlareID = errors.New("not found cloudflare id")
var (
ErrTooSmallSize = errors.New("the size of input value is small than requirement")
)
var FMap = template.FuncMap{ "w3": w3, "w3x": w3x, "inc": inc, "dec": dec, "mod": mod, "fmul": fmul, "fdiv": fdiv, "fadd": fadd, "fsub": fsub, "mul": mul, "div": div, "add": add, "sub": sub, "toInt": ToInt, "toFloat": ToFloat, "toBool": ToBool, "toArray": ToArray, "toMap": ToMap, "toString": ToString, "newObjectID": primitive.NewObjectID, "hashPassword": HashPassword, "randPassword": RandPassword, "noPrint": noPrint, "correctBackSlash": CorrectBackSlash, "now": time.Now, "map": CreateMap, "log": xlog, "list": CreateList, "append": AppendList, "field": Field, "split": strings.Split, "toLower": strings.ToLower, "title": strings.ToTitle, "toUpper": strings.ToUpper, "toJSON": ToJSONString, "reverse": Reverse, "at": SafeAt, "convertDate": ConvertDate, "joinString": JoinString, }
FMap ...
Functions ¶
func AccessDenied ¶ added in v0.1.1
func AccessDenied(w http.ResponseWriter, r *http.Request, reason ...interface{})
func AppendList ¶ added in v0.1.1
func AppendList(ls []interface{}, x ...interface{}) []interface{}
func BytesToPrivateKey ¶ added in v0.1.1
func BytesToPrivateKey(priv []byte) (*rsa.PrivateKey, error)
BytesToPrivateKey bytes to private key
func BytesToPublicKey ¶ added in v0.1.1
BytesToPublicKey bytes to public key
func ComputeChecksum ¶ added in v0.1.7
func ComputeMD5Checksum ¶ added in v0.1.5
ComputeMD5Checksum computes the MD5 checksum of the file 'filename'
func ComputeSHA1Checksum ¶ added in v0.1.5
ComputeSHA1Checksum computes the SHA1 checksum of the file 'filename'
func ConvertDate ¶ added in v0.1.1
ConvertDate ....
func CorrectBackSlash ¶ added in v0.1.1
func CreateList ¶ added in v0.1.1
func CreateList(x ...interface{}) []interface{}
func DecryptWithPrivateKey ¶ added in v0.1.1
func DecryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey) ([]byte, error)
DecryptWithPrivateKey decrypts data with private key
func EncryptWithPublicKey ¶ added in v0.1.1
EncryptWithPublicKey encrypts data with public key
func GenerateKeyPair ¶ added in v0.1.1
GenerateKeyPair generates a new key pair
func GetCloudFlareIdentifier ¶ added in v0.1.4
GetCloudFlareIdentifier ...
func GetIP ¶ added in v0.1.1
GetIP gets a requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.
func GetObjectID ¶ added in v0.1.1
GetObjectID ...
func JSONReply ¶ added in v0.1.1
func JSONReply(w http.ResponseWriter, x interface{}) error
JSONReply writes reponse with the body is JSON of variable x
func ListContainString ¶ added in v0.1.1
ListContainString ...
func LocalRedirect ¶ added in v0.1.1
func LocalRedirect(w http.ResponseWriter, r *http.Request, newPath string)
LocalRedirect redirects current path to new path
func ParseJSONString ¶ added in v0.1.1
func PostJSON ¶ added in v0.1.1
PostJson sends a POST request and return error if the status code is not equal 200
func PrintString ¶ added in v0.1.1
func PrintString(x interface{}) string
PrintString converts an interface object to string
func PrivateKeyToBytes ¶ added in v0.1.1
func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte
PrivateKeyToBytes private key to bytes
func PublicKeyToBytes ¶ added in v0.1.1
PublicKeyToBytes public key to bytes
func RandPassword ¶ added in v0.1.1
RandPassword generates password randomly
func ReadTextFile ¶ added in v0.1.1
ReadTextFile ...
func Redirect ¶ added in v0.1.1
func Redirect(w http.ResponseWriter, r *http.Request, newPath string)
func RedirectHandler ¶ added in v0.1.1
func RedirectHandler(newPath string) http.HandlerFunc
func RemoveJSONComment ¶ added in v0.1.1
RemoveJSONComment ...
func Reverse ¶ added in v0.1.1
Reverse returns its argument string reversed rune-wise left to right.
func RunMongoSession ¶ added in v0.1.4
func RunMongoSession(c *mongo.Client, ctx context.Context, fx func(mongo.SessionContext) (interface{}, error)) (interface{}, error)
RunMongoSession calls function fx in a MongoDB session
func StringsToInterfaces ¶ added in v0.1.1
func StringsToInterfaces(s []string) []interface{}
StringsToInterfaces ...
func ToJSONString ¶ added in v0.1.1
func ToJSONString(x interface{}) string
func URLFirstTwoPath ¶ added in v0.1.1
URLFirstTwoPath ...
func UnmarshalJSONFile ¶ added in v0.1.1
UnmarshalJSONFile ...
Types ¶
type AESCipher ¶ added in v0.1.1
type AESCipher struct {
// contains filtered or unexported fields
}
func CreateAESCipher ¶ added in v0.1.1
type CronJob ¶ added in v0.1.1
type CronJob struct { TimeThreshold time.Duration Period time.Duration // contains filtered or unexported fields }
CronJob ...
type Date ¶ added in v0.1.1
type Date int32
Date ...
const DateNil Date = 0
DateNil ...
func InterfaceToDate ¶ added in v0.1.1
func (*Date) FullFormat ¶ added in v0.1.1
FullFormat formats date using FullDateFormat layout
func (*Date) ParseString ¶ added in v0.1.1
ParseString converts string to date
type HTTPFS ¶ added in v0.1.1
type HTTPFS struct {
FS http.FileSystem
}
HTTPFS returns the index.html of directory instead of file list
type RecaptchaResponse ¶ added in v0.1.4
type RecaptchaResponse struct { Success bool `json:"success"` Score float64 `json:"score"` Action string `json:"action"` ChallengeTS time.Time `json:"challenge_ts"` Hostname string `json:"hostname"` ErrorCodes []string `json:"error-codes"` }
RecaptchaResponse ...
func VerifyRecaptcha ¶ added in v0.1.4
func VerifyRecaptcha(ip, token, key string) (*RecaptchaResponse, error)
VerifyRecaptcha ...
func VerifyRecaptchaV2 ¶ added in v0.1.4
func VerifyRecaptchaV2(ip, token, secretKey string) (*RecaptchaResponse, error)
VerifyRecaptchaV2 ...
func VerifyRecaptchaV3 ¶ added in v0.1.4
func VerifyRecaptchaV3(ip, token, secretKey string) (*RecaptchaResponse, error)
VerifyRecaptchaV3 ...
type TempMan ¶ added in v0.1.1
TempMan ...
func (*TempMan) HasTemplate ¶ added in v0.1.1
HasTemplate ...