Documentation ¶
Index ¶
- Constants
- Variables
- func AbsInt32(src int32) int32
- func Addr(sv reflect.Value) reflect.Value
- func AppendString(strs ...string) string
- func BoolPtr(v bool) *bool
- func ByteCastString(b []byte) string
- func ClientIP(req *http.Request) string
- func CompressStringToString(content string) string
- func ConvertToStringKV(i map[interface{}]interface{}) map[string]interface{}
- func DecodeMap(decoder *json.Decoder) (map[string]interface{}, error)
- func DecodeMapString(s string) (map[string]interface{}, error)
- func DecompressStringToString(compressedContent string) (string, error)
- func DeepCopyObject(st interface{}, dst interface{}) error
- func ElemType(v interface{}) reflect.Type
- func FindField(st interface{}, ks []string) (reflect.Value, error)
- func FindFieldByTag(rv reflect.Value, tagType, key string) (reflect.Value, bool)
- func FixHTTPUrl(url string) string
- func FloatRound(f float64, n int) float64
- func GetFieldElemValue(st interface{}, fullKey string) (interface{}, error)
- func GetFieldValue(st interface{}, fullKey string) (interface{}, error)
- func GetLocalIP() (string, error)
- func GetMapFieldValue(kvs map[string]interface{}, fullKey string) (interface{}, error)
- func GetMaxLengthCommonString(str1, str2 string) string
- func GetMaxLengthSubRepeatString(str string) string
- func GobDeepCopy(src interface{}, dst interface{}) error
- func HTTPRecover(panicReason interface{}, httpWriter http.ResponseWriter)
- func HashString64(b []byte) uint64
- func Indirect(v reflect.Value) reflect.Value
- func Int32Ptr(v int32) *int32
- func Int64Ptr(v int64) *int64
- func IsEmptyValue(v reflect.Value) bool
- func IsFieldZero(st interface{}, fullKey string) error
- func IsFieldsZero(st interface{}, fullKeys []string) error
- func IsSimpleType(t reflect.Type) bool
- func IsZero(v reflect.Value) bool
- func JSONDeepCopy(st interface{}, dst interface{}) error
- func ObjJSON(o interface{}) string
- func PProfHandlers() map[string]http.Handler
- func ParseJSONResp(resp *http.Response, err error, result interface{}) error
- func ParseRespToString(resp *http.Response, err error) (string, error)
- func RenderJSON(w http.ResponseWriter, code int, data interface{}) error
- func RenderPlain(w http.ResponseWriter, code int, format string, args ...interface{}) error
- func ReplaceStderr(name string, writeHeader bool) error
- func SetFieldValue(st interface{}, fullKey string, value interface{}) error
- func SetFieldValueFromJSON(st interface{}, fullKey string, decoder *json.Decoder) (interface{}, error)
- func SetMaxStdFileSize(size int64)
- func Signature(ins ...interface{}) (string, error)
- func SignatureShort(ins ...interface{}) (string, error)
- func SignatureWithMD5(ins ...interface{}) (string, error)
- func Stack(skip int) string
- func StringCastByte(s string) []byte
- func StringPtr(v string) *string
- func StripJSONNullValue(kv map[string]interface{})
- func ToSlice(arr interface{}) []interface{}
- func ValidateJsonizeValue(i interface{}) interface{}
- func ValidateStringKV(is map[string]interface{}) map[string]interface{}
- func WriteHistoryRecord(path string, key string, suffix string, keepCnt int, totalCnt int, ...) error
- type AsyncExecutor
- func (p *AsyncExecutor) ActiveCount() int
- func (p *AsyncExecutor) Close()
- func (p *AsyncExecutor) CreateRunFunc(run interface{}) func(params ...interface{}) (results []interface{}, err error)
- func (p *AsyncExecutor) Do(ctx context.Context, try bool, run interface{}, params ...interface{}) ([]interface{}, error)
- func (p *AsyncExecutor) GetTicket(ctx context.Context) (*struct{}, error)
- func (p *AsyncExecutor) Go(ctx context.Context, try bool, run interface{}, params ...interface{}) (*Command, error)
- func (p *AsyncExecutor) Queue(ctx context.Context, try bool, f simpaleRunFunc) error
- func (p *AsyncExecutor) Return(ticket *struct{})
- func (p *AsyncExecutor) TryGetTicket(ctx context.Context, try bool) (*struct{}, error)
- type Batcher
- type Command
- type DNSClient
- type DiffLogger
- type DirtyObject
- type Errors
- type FreqLimiter
- type GracefulSigHandler
- type HTTPClient
- type HTTPClientOptions
- type LiteHTTPClient
- func (c *LiteHTTPClient) Delete(url string) (*LiteHTTPResp, error)
- func (c *LiteHTTPClient) Get(url string) (*LiteHTTPResp, error)
- func (c *LiteHTTPClient) Post(url string, body string) (*LiteHTTPResp, error)
- func (c *LiteHTTPClient) ProxyRequest(host string, wr http.ResponseWriter, r *http.Request) error
- func (c *LiteHTTPClient) Put(url string, body string) (*LiteHTTPResp, error)
- func (c *LiteHTTPClient) Request(ctx context.Context, url string, body string, method string, ...) (*LiteHTTPResp, error)
- type LiteHTTPResp
- func SendFormRequest(ctx context.Context, method, urls string, reqForm map[string]string, ...) (*LiteHTTPResp, error)
- func SendJSONRequest(ctx context.Context, method, url string, req interface{}, ...) (*LiteHTTPResp, error)
- func SendRawRequest(ctx context.Context, url string, body string, method string, ...) (*LiteHTTPResp, error)
- type LoggerWriter
- type LoopJob
- type Version
Constants ¶
const ( HTTPContentTypeWWW = "application/x-www-form-urlencoded" HTTPContentTypeJSON = "application/json" HTTPContentTypeXML = "application/xml" HTTPContentTypePLAIN = "text/plain" HTTPContentTypeHTML = "text/html" )
HttpContentTypes
const FieldSep = "/"
FieldSep is the seperator for object property full key.
Variables ¶
var ( ErrTimeout = fmt.Errorf("get ticket timeout") ErrExeTimeout = fmt.Errorf("execute timeout") ErrStoped = fmt.Errorf("executor stoped") ErrNoTicket = fmt.Errorf("no ticket right now") )
Err defines
Functions ¶
func CompressStringToString ¶
CompressStringToString compress string to base64String used gzip
func ConvertToStringKV ¶
func ConvertToStringKV(i map[interface{}]interface{}) map[string]interface{}
ConvertToStringKV convert map[interface{}]interface{} to map[string]interface{}
func DecodeMapString ¶
DecodeMapString ...
func DecompressStringToString ¶
DecompressStringToString decompress base64String to string used gzip
func DeepCopyObject ¶
func DeepCopyObject(st interface{}, dst interface{}) error
DeepCopyObject deepcopy by reflect copy
func FindFieldByTag ¶
FindFieldByTag find field by name or json tag
func GetFieldElemValue ¶
GetFieldElemValue return the elem Value of field
func GetFieldValue ¶
GetFieldValue return the Value of field
func GetMapFieldValue ¶
GetMapFieldValue GetMapFieldValue
func GetMaxLengthCommonString ¶
GetMaxLengthCommonString GetMaxLengthCommonString
func GetMaxLengthSubRepeatString ¶
GetMaxLengthSubRepeatString GetMaxLengthSubRepeatString
func GobDeepCopy ¶
func GobDeepCopy(src interface{}, dst interface{}) error
GobDeepCopy deepcopy by gob marshal and unmarshal
func HTTPRecover ¶
func HTTPRecover(panicReason interface{}, httpWriter http.ResponseWriter)
HTTPRecover send 500 code response when panic
func Indirect ¶
Indirect returns the value that v points to,or the interface contains If v is a nil pointer, Indirect returns a zero Value. If v is not a pointer, Indirect returns v.
func IsEmptyValue ¶
IsEmptyValue copy from https://github.com/golang/go/blob/master/src/encoding/json/encode.go#L621
func IsFieldZero ¶
IsFieldZero find field from st and check if it is zero
func IsFieldsZero ¶
IsFieldsZero find fields from st and check if they are zero
func IsSimpleType ¶
IsSimpleType return is the type is simple type
func JSONDeepCopy ¶
func JSONDeepCopy(st interface{}, dst interface{}) error
JSONDeepCopy deepcopy by json marshal and unmarshal
func ObjJSON ¶
func ObjJSON(o interface{}) string
ObjJSON get obj json string. easy to use but not safety, used for log
func PProfHandlers ¶
PProfHandlers get all pprof path and handlers to new http handler
func ParseJSONResp ¶
ParseJSONResp parse http json resp to interface
func ParseRespToString ¶
ParseRespToString parse http resp to string
func RenderJSON ¶
func RenderJSON(w http.ResponseWriter, code int, data interface{}) error
RenderJSON send json response
func RenderPlain ¶
func RenderPlain(w http.ResponseWriter, code int, format string, args ...interface{}) error
RenderPlain send plain response
func ReplaceStderr ¶
ReplaceStderr replaces os.Stderr by a custom file. Usually to write panics
func SetFieldValue ¶
SetFieldValue set value to field
func SetFieldValueFromJSON ¶
func SetFieldValueFromJSON(st interface{}, fullKey string, decoder *json.Decoder) (interface{}, error)
SetFieldValueFromJSON SetFieldValueFromJSON
func SignatureShort ¶
SignatureShort compute signature for objs and return a short signature
func SignatureWithMD5 ¶
SignatureWithMD5 compute signature for objs with md5
func StripJSONNullValue ¶
func StripJSONNullValue(kv map[string]interface{})
StripJSONNullValue strip "some-key": null
func ToSlice ¶
func ToSlice(arr interface{}) []interface{}
ToSlice change interface{} to []interface{}
func ValidateJsonizeValue ¶
func ValidateJsonizeValue(i interface{}) interface{}
ValidateJsonizeValue used when you want to marshal map[interface{}]interface{}
func ValidateStringKV ¶
ValidateStringKV ValidateStringKV
Types ¶
type AsyncExecutor ¶
type AsyncExecutor struct { Max int Tickets chan *struct{} sync.RWMutex // contains filtered or unexported fields }
AsyncExecutor is groutine pool
func (*AsyncExecutor) ActiveCount ¶
func (p *AsyncExecutor) ActiveCount() int
ActiveCount get active count
func (*AsyncExecutor) CreateRunFunc ¶
func (p *AsyncExecutor) CreateRunFunc(run interface{}) func(params ...interface{}) (results []interface{}, err error)
CreateRunFunc from run func
func (*AsyncExecutor) Do ¶
func (p *AsyncExecutor) Do(ctx context.Context, try bool, run interface{}, params ...interface{}) ([]interface{}, error)
Do runs your function in a synchronous manner,
func (*AsyncExecutor) GetTicket ¶
func (p *AsyncExecutor) GetTicket(ctx context.Context) (*struct{}, error)
GetTicket from pool
func (*AsyncExecutor) Go ¶
func (p *AsyncExecutor) Go(ctx context.Context, try bool, run interface{}, params ...interface{}) (*Command, error)
Go call run
func (*AsyncExecutor) Queue ¶
func (p *AsyncExecutor) Queue(ctx context.Context, try bool, f simpaleRunFunc) error
Queue add a func to pool. in this condition, all user logic must be in f.
func (*AsyncExecutor) Return ¶
func (p *AsyncExecutor) Return(ticket *struct{})
Return ticket to pool
func (*AsyncExecutor) TryGetTicket ¶
func (p *AsyncExecutor) TryGetTicket(ctx context.Context, try bool) (*struct{}, error)
TryGetTicket with no wait
type Batcher ¶
Batcher exectue f batch and wait result together
func NewBatcherWithExecutor ¶
func NewBatcherWithExecutor(executor *AsyncExecutor) *Batcher
NewBatcherWithExecutor create batcher
type Command ¶
type Command struct { sync.Mutex Start time.Time End time.Time ExecutorError error FuncError error Results []interface{} // contains filtered or unexported fields }
Command is the return model, for user to get results and errinfo
type DiffLogger ¶
type DiffLogger struct {
// contains filtered or unexported fields
}
DiffLogger write logs/record files if object content is different.
func NewDiffLogger ¶
func NewDiffLogger(size int, writer LoggerWriter, keyKeepCount, totalKeepCount int) (*DiffLogger, error)
NewDiffLogger create a new diff logger.
func (*DiffLogger) Log ¶
func (l *DiffLogger) Log(key string, format string, args ...interface{})
Log writes log if log message different.
func (*DiffLogger) WriteHistoryFile ¶
func (l *DiffLogger) WriteHistoryFile(path string, key string, suffix string, obj interface{}, cmpFn func(prev, obj interface{}) (bool, error)) error
WriteHistoryFile write a history record file for object.
type DirtyObject ¶
DirtyObject tracks its state which expected to persist. When the state changed, it's dirty, and after it's committed, it's not dirty.
func (*DirtyObject) GetRoot ¶
func (d *DirtyObject) GetRoot() *DirtyObject
GetRoot get the root dirty object.
func (*DirtyObject) IsDirty ¶
func (d *DirtyObject) IsDirty() bool
IsDirty check if this object is dirty.
func (*DirtyObject) LinkDirty ¶
func (d *DirtyObject) LinkDirty(child *DirtyObject)
LinkDirty links 2 dirty objects.
func (*DirtyObject) TransactDirty ¶
func (d *DirtyObject) TransactDirty(fn func() error) error
TransactDirty transact commit if you want to persist dirty object state into db or somewhere...
type FreqLimiter ¶
type FreqLimiter struct {
// contains filtered or unexported fields
}
FreqLimiter limits to run a function.
type GracefulSigHandler ¶
type GracefulSigHandler struct {
// contains filtered or unexported fields
}
GracefulSigHandler GracefulSigHandler
func NewGracefulSigHandler ¶
func NewGracefulSigHandler(pctx context.Context) (*GracefulSigHandler, context.Context)
NewGracefulSigHandler NewGracefulSigHandler
func (*GracefulSigHandler) NotifySigs ¶
func (g *GracefulSigHandler) NotifySigs(signals ...os.Signal)
NotifySigs NotifySigs
type HTTPClient ¶
type HTTPClient interface { Get(url string) (*LiteHTTPResp, error) Post(url string, body string) (*LiteHTTPResp, error) Put(url string, body string) (*LiteHTTPResp, error) Delete(url string) (*LiteHTTPResp, error) }
HTTPClient HTTPClient
type HTTPClientOptions ¶
type HTTPClientOptions struct { Timeout time.Duration Headers map[string]string TransportMaxIdleConns int TransportMaxIdleConnsPerHost int }
HTTPClientOptions is options of client scop
type LiteHTTPClient ¶
type LiteHTTPClient struct {
// contains filtered or unexported fields
}
LiteHTTPClient LiteHTTPClient
func NewLiteHTTPClient ¶
func NewLiteHTTPClient(timeout time.Duration) *LiteHTTPClient
NewLiteHTTPClient create new LiteHTTPClient
func NewLiteHTTPClientOpts ¶
func NewLiteHTTPClientOpts(opts *HTTPClientOptions) *LiteHTTPClient
NewLiteHTTPClientOpts create new LiteHTTPClient
func NewLiteHTTPClientWithClient ¶
func NewLiteHTTPClientWithClient(httpClient *http.Client) *LiteHTTPClient
NewLiteHTTPClientWithClient create new LiteHTTPClient
func (*LiteHTTPClient) Delete ¶
func (c *LiteHTTPClient) Delete(url string) (*LiteHTTPResp, error)
Delete query with DELETE method
func (*LiteHTTPClient) Get ¶
func (c *LiteHTTPClient) Get(url string) (*LiteHTTPResp, error)
Get query with GET method
func (*LiteHTTPClient) Post ¶
func (c *LiteHTTPClient) Post(url string, body string) (*LiteHTTPResp, error)
Post query with POST method
func (*LiteHTTPClient) ProxyRequest ¶
func (c *LiteHTTPClient) ProxyRequest(host string, wr http.ResponseWriter, r *http.Request) error
ProxyRequest proxy request to target url
func (*LiteHTTPClient) Put ¶
func (c *LiteHTTPClient) Put(url string, body string) (*LiteHTTPResp, error)
Put query with PUT method
type LiteHTTPResp ¶
LiteHTTPResp contain resp body and status
func SendFormRequest ¶
func SendFormRequest(ctx context.Context, method, urls string, reqForm map[string]string, headers map[string]string) (*LiteHTTPResp, error)
SendFormRequest send http request with form format
func SendJSONRequest ¶
func SendJSONRequest(ctx context.Context, method, url string, req interface{}, headers map[string]string) (*LiteHTTPResp, error)
SendJSONRequest send http request with json format
type LoggerWriter ¶
type LoggerWriter func(msg string)
LoggerWriter is a function to write logs, e.g: glog.Infof
type LoopJob ¶
type LoopJob struct {
// contains filtered or unexported fields
}
LoopJob do job periodic