util

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 27 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoError = NewError(0, "")
)

Functions

func FileExists

func FileExists(path string) bool

FileExists checks if file exists

func GrepFile

func GrepFile(patten string, filename string) (lines []string, err error)

GrepFile like command grep -E for example: GrepFile(`^hello`, "hello.txt") \n is striped while read

func InSliceInt

func InSliceInt(needle int, stack []int) bool

InSliceInt checks if needle is in the stack

func InSliceString added in v0.1.2

func InSliceString(needle string, stack []string) bool

func LeftPadding added in v0.1.2

func LeftPadding(str, pad string, length int) string

func MustGetTlsConfiguration

func MustGetTlsConfiguration(privateKeyFile, certificateFile, caFile string) *tls.Config

func MustLoadCertificates

func MustLoadCertificates(privateKeyFile, certificateFile, caFile string) (tls.Certificate, *x509.CertPool)

func NewHTTPReqeust

func NewHTTPReqeust(method, url string, queries, headers map[string]string, body []byte) (*http.Request, error)

NewHTTPReqeust makes a http request

func SearchFile

func SearchFile(filename string, paths ...string) (fullpath string, err error)

SearchFile Search a file in paths. this is often used in search config file in /etc ~/

func SelfDir

func SelfDir() string

SelfDir gets compiled executable file directory

func SelfPath

func SelfPath() string

SelfPath gets compiled executable file absolute path

func Slice

func Slice(s string) (b []byte)

Slice converts string to slice without copy. Use at your own risk.

func SliceIntDiff

func SliceIntDiff(s1 []int, s2 []int) []int

SliceIntDiff differences s1 against s2

func SliceIntToString

func SliceIntToString(s []int) []string

SliceIntToString convert []int to []string

func String

func String(b []byte) (s string)

String converts slice to string without copy. Use at your own risk.

func TryCache

func TryCache(c Cache, key string, call Callable) interface{}

Types

type Cache

type Cache interface {
	Set(key string, obj interface{}) bool
	Get(key string) (interface{}, bool)
	Del(key string) bool
}

type Callable

type Callable func() interface{}

type Error added in v0.1.2

type Error struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

func NewError added in v0.1.2

func NewError(code int, msg string) Error

func (*Error) Error added in v0.1.2

func (e *Error) Error() string

func (*Error) String added in v0.1.2

func (e *Error) String() string

type HTTPClient

type HTTPClient struct {
	Timeout int
	// contains filtered or unexported fields
}

func NewHTTPClient

func NewHTTPClient(timeout int, client *http.Client) *HTTPClient

func (*HTTPClient) Do

func (hc *HTTPClient) Do(req *http.Request) ([]byte, int, error)

func (*HTTPClient) DoParallel added in v0.1.2

func (hc *HTTPClient) DoParallel(reqs ...*http.Request) []*Response

DoParallel http requests, and get response list. Response could be nil

func (*HTTPClient) GetReadCloser

func (hc *HTTPClient) GetReadCloser(req *http.Request) (io.ReadCloser, string, int, error)

GetReadCloser for downloading file

type HTTPClientIface

type HTTPClientIface interface {
	Do(*http.Request) ([]byte, int, error)
	DoParallel(...*http.Request) []*Response
}

type JSON

type JSON map[string]interface{}

type Locker

type Locker interface {
	Lock(string, int) bool
	Unlock(string) bool
}

type Logger

type Logger = echo.Logger

func NewLogger

func NewLogger(appName string, level elog.Lvl, config cfg.LogConfig) Logger

NewLogger return a new

type RedisLocker

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

func NewRedisLocker

func NewRedisLocker(cli *redis.Client, expire int) *RedisLocker

func (*RedisLocker) Lock

func (l *RedisLocker) Lock(key string, expireSecond int) bool

func (*RedisLocker) Unlock

func (l *RedisLocker) Unlock(key string) bool

type Reply added in v0.1.2

type Reply struct {
	Error
	Content interface{} `json:"content"`
}

func NewReply added in v0.1.2

func NewReply(body interface{}) Reply

type Response added in v0.1.2

type Response struct {
	Response *http.Response
	Err      error
}

Directories

Path Synopsis
Goroutine池.
Goroutine池.

Jump to

Keyboard shortcuts

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