kgo

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 41 Imported by: 0

README

kgo

Golang utils

Documentation

Index

Constants

View Source
const (
	BriefDateFormat = "20060102"
	FullDateFormat  = "02-01-2006"
)

Variables

View Source
var (
	ErrDecodeX509Fail = errors.New("decode x509 data to rsa key failed.")
)
View Source
var (
	// ErrInvalidDateStringValue ...
	ErrInvalidDateStringValue = errors.New("invalid date string value")
)
View Source
var (
	// ErrInvalidRecaptchaToken ...
	ErrInvalidRecaptchaToken = errors.New("invalid google recaptcha token")
)
View Source
var ErrNotFoundCloudFlareID = errors.New("not found cloudflare id")
View Source
var (
	ErrTooSmallSize = errors.New("the size of input value is small than requirement")
)
View Source
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

func BytesToPublicKey(pub []byte) (*rsa.PublicKey, error)

BytesToPublicKey bytes to public key

func ComputeChecksum added in v0.1.7

func ComputeChecksum(h hash.Hash, f io.Reader) (string, error)

func ComputeMD5Checksum added in v0.1.5

func ComputeMD5Checksum(filename string) (string, error)

ComputeMD5Checksum computes the MD5 checksum of the file 'filename'

func ComputeSHA1Checksum added in v0.1.5

func ComputeSHA1Checksum(filename string) (string, error)

ComputeSHA1Checksum computes the SHA1 checksum of the file 'filename'

func ConnectDB added in v0.1.4

func ConnectDB(uri string) (*mongo.Client, error)

ConnectDB connects to MongoDB server and returns the client object

func ContainsDotDot added in v0.1.1

func ContainsDotDot(v string) bool

ContainsDotDot ...

func ConvertDate added in v0.1.1

func ConvertDate(date, input_fmt, output_fmt string) string

ConvertDate ....

func CopyFile added in v0.1.1

func CopyFile(src, dst string) (int64, error)

CopyFile ...

func CorrectBackSlash added in v0.1.1

func CorrectBackSlash(str string) string

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 DirExists added in v0.1.1

func DirExists(path string) bool

DirExists ...

func EncryptWithPublicKey added in v0.1.1

func EncryptWithPublicKey(msg []byte, pub *rsa.PublicKey) ([]byte, error)

EncryptWithPublicKey encrypts data with public key

func Error added in v0.1.1

func Error(x ...interface{})

Error ...

func ExtractIP added in v0.1.1

func ExtractIP(address string) string

func Field added in v0.1.1

func Field(x map[string]interface{}, key string) interface{}

func FileExists added in v0.1.1

func FileExists(filename string) bool

FileExists ...

func FuncName added in v0.1.1

func FuncName(x interface{}) string

FuncName ...

func GenKey added in v0.1.1

func GenKey(n int) string

GenKey ...

func GenRawKey added in v0.1.1

func GenRawKey(n int) ([]byte, error)

GenRawKey ...

func GenerateKeyPair added in v0.1.1

func GenerateKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)

GenerateKeyPair generates a new key pair

func GetCloudFlareIdentifier added in v0.1.4

func GetCloudFlareIdentifier(email, apiKey, domain string) (string, error)

GetCloudFlareIdentifier ...

func GetIP added in v0.1.1

func GetIP(r *http.Request) string

GetIP gets a requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.

func GetJSON added in v0.1.1

func GetJSON(url string, out interface{}) error

func GetObjectID added in v0.1.1

func GetObjectID(x url.Values) (primitive.ObjectID, error)

GetObjectID ...

func HashPassword added in v0.1.1

func HashPassword(pw, uname string) string

HashPassword ...

func JSONParse added in v0.1.1

func JSONParse(r *http.Request, x interface{}) error

JSONParse parses the request body as JSON object

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 JoinString added in v0.1.1

func JoinString(sep string, s ...string) string

JoinString ...

func ListContainString added in v0.1.1

func ListContainString(v []string, s string) bool

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 Log added in v0.1.1

func Log(x ...interface{})

Log ...

func MD5ChecksumStream added in v0.1.7

func MD5ChecksumStream(f io.Reader) (string, error)

func ParseJSONString added in v0.1.1

func ParseJSONString(str string, x interface{}) error

func PostJSON added in v0.1.1

func PostJSON(url string, x interface{}) error

PostJson sends a POST request and return error if the status code is not equal 200

func PrintJSON added in v0.1.1

func PrintJSON(x interface{})

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

func PublicKeyToBytes(pub *rsa.PublicKey) ([]byte, error)

PublicKeyToBytes public key to bytes

func RandInt added in v0.1.1

func RandInt(min, max int) int

RandInt ...

func RandPassword added in v0.1.1

func RandPassword(length int) string

RandPassword generates password randomly

func ReadBody added in v0.1.1

func ReadBody(r *http.Request) ([]byte, error)

func ReadTextFile added in v0.1.1

func ReadTextFile(fname string) (string, error)

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

func RemoveJSONComment(s string) string

RemoveJSONComment ...

func RemoveSpace added in v0.1.1

func RemoveSpace(str string) string

RemoveSpace ...

func Reverse added in v0.1.1

func Reverse(s string) string

Reverse returns its argument string reversed rune-wise left to right.

func Run added in v0.1.1

func Run(addr string, handler http.Handler)

Run ...

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 SHA1ChecksumStream added in v0.1.7

func SHA1ChecksumStream(f io.Reader) (string, error)

func SHA256 added in v0.1.1

func SHA256(data string) string

SHA256 creates hash value of data

func SafeAt added in v0.1.1

func SafeAt(a interface{}, index int) interface{}

func StringsToInterfaces added in v0.1.1

func StringsToInterfaces(s []string) []interface{}

StringsToInterfaces ...

func ToArray added in v0.1.1

func ToArray(x interface{}) []interface{}

func ToBool added in v0.1.1

func ToBool(x interface{}) bool

func ToFloat added in v0.1.1

func ToFloat(x interface{}) float64

func ToInt added in v0.1.1

func ToInt(x interface{}) int

func ToJSONString added in v0.1.1

func ToJSONString(x interface{}) string

func ToString added in v0.1.1

func ToString(x interface{}) string
func ToXLink(path string) string

ToXLink converts path to style 'a/b/c'

func URLFirstTwoPath added in v0.1.1

func URLFirstTwoPath(url string) (string, string)

URLFirstTwoPath ...

func URLSplit2 added in v0.1.1

func URLSplit2(url string) (string, string)

URLSplit2 splits url into two paths

func URLSplit3 added in v0.1.1

func URLSplit3(url string) (string, string, string)

URLSplit3 splits url into three paths

func UnmarshalJSONFile added in v0.1.1

func UnmarshalJSONFile(fname string, x interface{}) error

UnmarshalJSONFile ...

func VerifyBriefDate added in v0.1.1

func VerifyBriefDate(s string) bool

VerifyBriefDate ...

func Wait added in v0.1.1

func Wait(shutdownFunc ...func())

Wait ...

Types

type AESCipher added in v0.1.1

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

func CreateAESCipher added in v0.1.1

func CreateAESCipher(key []byte) (*AESCipher, error)

func (*AESCipher) Decrypt added in v0.1.1

func (ac *AESCipher) Decrypt(value []byte) ([]byte, error)

func (*AESCipher) Encrypt added in v0.1.1

func (ac *AESCipher) Encrypt(value []byte) ([]byte, error)

type CronJob added in v0.1.1

type CronJob struct {
	TimeThreshold time.Duration
	Period        time.Duration
	// contains filtered or unexported fields
}

CronJob ...

func (*CronJob) Start added in v0.1.1

func (cj *CronJob) Start(fx func())

Start ...

func (*CronJob) Stop added in v0.1.1

func (cj *CronJob) Stop()

Stop ...

type Date added in v0.1.1

type Date int32

Date ...

const DateNil Date = 0

DateNil ...

func InterfaceToDate added in v0.1.1

func InterfaceToDate(x interface{}) (Date, bool)

func StringToDate added in v0.1.1

func StringToDate(s string) (Date, error)

StringToDate ...

func TimeToDate added in v0.1.1

func TimeToDate(t time.Time) Date

TimeToDate ...

func (*Date) Add added in v0.1.1

func (d *Date) Add(years, months, days int) error

Add ...

func (*Date) Format added in v0.1.1

func (d *Date) Format(layout string) (string, error)

Format converts date to string using format 'layout'

func (*Date) FullFormat added in v0.1.1

func (d *Date) FullFormat() (string, error)

FullFormat formats date using FullDateFormat layout

func (*Date) ParseString added in v0.1.1

func (d *Date) ParseString(s string) error

ParseString converts string to date

func (*Date) Set added in v0.1.1

func (d *Date) Set(year, month, day int)

Set ...

func (*Date) String added in v0.1.1

func (d *Date) String() string

String converts date to string

func (*Date) Time added in v0.1.1

func (d *Date) Time() (time.Time, error)

Time convert date to time.Time

type HTTPFS added in v0.1.1

type HTTPFS struct {
	FS http.FileSystem
}

HTTPFS returns the index.html of directory instead of file list

func (HTTPFS) Open added in v0.1.1

func (fs HTTPFS) Open(path string) (http.File, error)

Open ...

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

type TempMan struct {
	TPL *template.Template
}

TempMan ...

func (*TempMan) Build added in v0.1.1

func (tm *TempMan) Build(tempPath string) error

Build ...

func (*TempMan) HasTemplate added in v0.1.1

func (tm *TempMan) HasTemplate(name string) bool

HasTemplate ...

func (*TempMan) Render added in v0.1.1

func (tm *TempMan) Render(w io.Writer, name string, data interface{}) error

Render ...

func (*TempMan) ToString added in v0.1.1

func (tm *TempMan) ToString(name string, data interface{}) (string, error)

ToString ...

type TempMap added in v0.1.1

type TempMap map[string]interface{}

TempMap ...

func CreateMap added in v0.1.1

func CreateMap(x ...interface{}) TempMap

func ToMap added in v0.1.1

func ToMap(x interface{}) TempMap

func (TempMap) Get added in v0.1.1

func (tm TempMap) Get(key string) interface{}

Get ...

func (TempMap) Has added in v0.1.1

func (tm TempMap) Has(key string) bool

Has ...

func (TempMap) Set added in v0.1.1

func (tm TempMap) Set(key string, value interface{}) string

Set ...

func (TempMap) ToJSON added in v0.1.1

func (tm TempMap) ToJSON() string

ToJSON ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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