util

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2017 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 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 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) Get

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

Get returns http response body in []byte, timeout in second

func (*HTTPClient) GetReadCloser

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

GetReadCloser for downloading file

func (*HTTPClient) Post

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

Post do http post

type HTTPClientIface

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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