Documentation
¶
Overview ¶
没必要针对result配置sync.Pool,频繁操作可能会减慢性能
Index ¶
- Constants
- Variables
- func Bind(keys string, ret interface{}) (bool, error)
- func BindWith(keys string, f BindFunc) (interface{}, bool, error)
- func Elem(val interface{}, key string) (ret interface{}, ok bool)
- func ElemBool(val interface{}, key string) (ret bool, ok bool)
- func ElemDuration(val interface{}, key string) (ret time.Duration, ok bool)
- func ElemFloat64(val interface{}, key string) (ret float64, ok bool)
- func ElemInt(val interface{}, key string) (ret int, ok bool)
- func ElemInt64(val interface{}, key string) (ret int64, ok bool)
- func ElemMap(val interface{}, key string) (ret map[string]interface{}, ok bool)
- func ElemSlice(val interface{}, key string) (ret []interface{}, ok bool)
- func ElemString(val interface{}, key string) (ret string, ok bool)
- func ElemStringMap(val interface{}, key string) (ret map[string]string, ok bool)
- func ElemStringSlice(val interface{}, key string) (ret []string, ok bool)
- func ElemTime(val interface{}, key string) (ret time.Time, ok bool)
- func Evaluate(val string) string
- func FirstPrivIpv4() string
- func FormatDate(t time.Time) string
- func FormatDateTime(t time.Time) string
- func FormatTime(t time.Time) string
- func Get(keys string) (interface{}, bool)
- func GetBool(keys string) (bool, bool)
- func GetDuration(keys string) (time.Duration, bool)
- func GetFloat64(keys string) (float64, bool)
- func GetInt(keys string) (int, bool)
- func GetInt64(keys string) (int64, bool)
- func GetMap(keys string) (map[string]interface{}, bool)
- func GetSlice(keys string) ([]interface{}, bool)
- func GetString(keys string) (string, bool)
- func GetStringMap(keys string) (map[string]string, bool)
- func GetStringSlice(keys string) ([]string, bool)
- func GetTime(keys string) (time.Time, bool)
- func HttpJson(method string, url string, header map[string]string, reqobj interface{}, ...) (status int, err error)
- func HttpJsonRequest(method string, url string, header map[string]string, body io.Reader) (state int, content string, err error)
- func HttpProxy(rurl string, writer http.ResponseWriter, request *http.Request) (err error)
- func HttpProxyHandler(rurl string) *httputil.ReverseProxy
- func HttpRequest(method string, url string, header map[string]string, body io.Reader) (state int, content string, err error)
- func If(c bool, v1 interface{}, v2 interface{}) interface{}
- func IfBool(c bool, v1 bool, v2 bool) bool
- func IfFloat64(c bool, v1 float64, v2 float64) float64
- func IfInt(c bool, v1 int, v2 int) int
- func IfInt64(c bool, v1 int64, v2 int64) int64
- func IfString(c bool, v1 string, v2 string) string
- func InitConf(vs map[string]interface{})
- func InitHttp(c *HttpConfig)
- func JoinQuery(rurl string, params map[string]string) string
- func Json(v interface{}) string
- func LoadConf(env string, name string) (bs []byte, path string, err error)
- func MMHash32(data []byte) uint32
- func MarshalToml(vl interface{}) (bs []byte, err error)
- func MustBind(keys string, ret interface{})
- func MustBool(keys string) bool
- func MustDuration(keys string) time.Duration
- func MustFloat64(keys string) float64
- func MustInt(keys string) int
- func MustInt64(keys string) int64
- func MustMap(keys string) map[string]interface{}
- func MustSlice(keys string) []interface{}
- func MustString(keys string) string
- func MustStringMap(keys string) map[string]string
- func MustStringSlice(keys string) []string
- func MustTime(keys string) time.Time
- func NewBuilderPool(cap int) *sync.Pool
- func OptiBool(keys string, def bool) bool
- func OptiDuration(keys string, def time.Duration) time.Duration
- func OptiFloat64(keys string, def float64) float64
- func OptiInt(keys string, def int) int
- func OptiInt64(keys string, def int64) int64
- func OptiMap(keys string, def map[string]interface{}) map[string]interface{}
- func OptiSlice(keys string, def []interface{}) []interface{}
- func OptiString(keys string, def string) string
- func OptiStringMap(keys string, def map[string]string) map[string]string
- func OptiStringSlice(keys string, def []string) []string
- func OptiTime(keys string, def time.Time) time.Time
- func ParseDate(v string) (ret time.Time)
- func ParseDateTime(v string) (ret time.Time)
- func ParseDateTimeExt(v string) (ret time.Time)
- func ParseTime(v string) (ret time.Time)
- func Stack(all bool) []byte
- func ToBool(val interface{}) bool
- func ToDuration(val interface{}) time.Duration
- func ToFloat64(val interface{}) float64
- func ToInt(val interface{}) int
- func ToInt64(val interface{}) int64
- func ToMap(val interface{}) map[string]interface{}
- func ToSlice(val interface{}) []interface{}
- func ToString(val interface{}) string
- func ToStringMap(val interface{}) map[string]string
- func ToStringSlice(val interface{}) []string
- func ToTime(val interface{}) time.Time
- func UnsafeString(buf []byte) string
- type BaseConfig
- type BindFunc
- type Builder
- func (b *Builder) Back(n int)
- func (b *Builder) Cap() int
- func (b *Builder) Grow(n int)
- func (b *Builder) Len() int
- func (b *Builder) Reset() *Builder
- func (b *Builder) String() string
- func (b *Builder) UnsafeString() string
- func (b *Builder) Write(p []byte) (int, error)
- func (b *Builder) WriteByte(c byte) error
- func (b *Builder) WriteRune(r rune) (int, error)
- func (b *Builder) WriteString(s string) (int, error)
- type Cycle
- type HttpBufferPool
- type HttpConfig
- type IParallel
- type Level
- type Logger
- func (lg *Logger) Debug(args ...interface{})
- func (lg *Logger) Debugf(format string, args ...interface{})
- func (lg *Logger) Error(args ...interface{})
- func (lg *Logger) ErrorStack(format string, args ...interface{})
- func (lg *Logger) Errorf(format string, args ...interface{})
- func (lg *Logger) Fatal(args ...interface{})
- func (lg *Logger) FatalStack(format string, args ...interface{})
- func (lg *Logger) Fatalf(format string, args ...interface{})
- func (lg *Logger) Info(args ...interface{})
- func (lg *Logger) Infof(format string, args ...interface{})
- func (lg *Logger) Warn(args ...interface{})
- func (lg *Logger) Warnf(format string, args ...interface{})
- type Result
Constants ¶
View Source
const ( CONF_TOML_FILE string = "conf.toml" PATH_STEP_SEP byte = '.' CONF_TOML_ENV string = "CONF_TOML" LAYOUT_DATE string = "2006-01-02" LAYOUT_TIME string = "15:04:05" LAYOUT_DATETIME string = "2006-01-02 15:04:05" LAYOUT_DATETIME_T string = "2006-01-02T15:04:05" LENGTH_DATETIME = len(LAYOUT_DATETIME) )
View Source
const ( ProxyBufferPool_None = "none" // 没有缓存池 ProxyBufferPool_Sync = "sync" // 采用sync.Pool ProxyErrorHandler_None = "none" // 没有错误处理 ProxyErrorHandler_Body = "body" // 将错误写到body REVERSE_SCHEME = "x-r-scheme" REVERSE_HOST = "x-r-host" REVERSE_PATH = "x-r-path" HTTP_BUFF_SIZE = 32 * 1024 )
View Source
const ( STDOUT = "stdout" STDERR = "stderr" )
View Source
const ( StatusApplyResult = 200 StatusErrorResult = 210 // 勿占用RFC常用status CodeAppErr = 1 // 未知业务错误, 不需预警! CodeSysErr = -1 // 未知系统错误, 需要预警! )
View Source
const Ckey = "base"
Variables ¶
View Source
var ( DefaultHttpTransport *http.Transport DefaultHttpClient *http.Client DefaultHttpProxy *httputil.ReverseProxy )
View Source
var LevelNames = [5]string{"DEBUG", "INFO", "WARN", "ERROR", "FATAL"}
View Source
var ZERO_TIME = time.Unix(0, 0)
Functions ¶
func ElemFloat64 ¶
func ElemString ¶
func ElemStringMap ¶
func ElemStringSlice ¶
func FirstPrivIpv4 ¶
func FirstPrivIpv4() string
func FormatDate ¶
func FormatDateTime ¶
func FormatTime ¶
func GetFloat64 ¶
func GetStringSlice ¶
func HttpJsonRequest ¶
func HttpJsonRequest(method string, url string, header map[string]string, body io.Reader) (state int, content string, err error)
适用于大多数情况下的ContentType都是application/json,如果不需要请用HttpRawRequest
func HttpProxyHandler ¶
func HttpProxyHandler(rurl string) *httputil.ReverseProxy
func HttpRequest ¶
func InitHttp ¶
func InitHttp(c *HttpConfig)
func MarshalToml ¶
需要对称marshal为toml才能进行对称解析, 否则tag里面的toml:...会失败
func MustDuration ¶
func MustFloat64 ¶
func MustString ¶
func MustStringMap ¶
func MustStringSlice ¶
func OptiFloat64 ¶
func OptiString ¶
func OptiStringSlice ¶
func ParseDateTime ¶
func ParseDateTimeExt ¶
func Stack ¶
stacks is a wrapper for runtime.Stack that attempts to recover the data for all goroutines.
func ToDuration ¶
func ToStringMap ¶
func ToStringSlice ¶
func ToStringSlice(val interface{}) []string
func UnsafeString ¶
Types ¶
type BaseConfig ¶
type BaseConfig struct {
Http HttpConfig `json:"http" toml:"http"`
}
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
模仿strings.Builder,但底层使用copy更直接
func NewBuilder ¶
func (*Builder) Cap ¶
Cap returns the capacity of the StringBuilder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.
func (*Builder) UnsafeString ¶
String returns the accumulated string.
func (*Builder) Write ¶
Write appends the contents of p to b's buffer. Write always returns len(p), nil.
func (*Builder) WriteByte ¶
WriteByte appends the byte c to b's buffer. The returned error is always nil.
type HttpBufferPool ¶
func (*HttpBufferPool) Get ¶
func (s *HttpBufferPool) Get() []byte
func (*HttpBufferPool) Put ¶
func (s *HttpBufferPool) Put(v []byte)
type HttpConfig ¶
type HttpConfig struct {
// Timeout is the maximum amount of time a dial will wait for
// a connect to complete. If Deadline is also set, it may fail
// earlier.
//
// The default is no timeout.
//
// When using TCP and dialing a host name with multiple IP
// addresses, the timeout may be divided between them.
//
// With or without a timeout, the operating system may impose
// its own earlier timeout. For instance, TCP timeouts are
// often around 3 minutes.
ConnectTimeout time.Duration `json:"connect_timeout" toml:"connect_timeout"`
// KeepAlive specifies the keep-alive period for an active
// network connection.
// If zero, keep-alives are enabled if supported by the protocol
// and operating system. Network protocols or operating systems
// that do not support keep-alives ignore this field.
// If negative, keep-alives are disabled.
KeepAlive time.Duration `json:"keep_alive" toml:"keep_alive"`
// MaxIdleConns controls the maximum number of idle (keep-alive)
// connections across all hosts. Zero means no limit.
MaxIdleConns int `json:"max_idle_conns" toml:"max_idle_conns"`
// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
// (keep-alive) connections to keep per-host. If zero,
// DefaultMaxIdleConnsPerHost is used.
MaxIdleConnsPerHost int `json:"max_idle_conns_per_host" toml:"max_idle_conns_per_host"`
// MaxConnsPerHost optionally limits the total number of
// connections per host, including connections in the dialing,
// active, and idle states. On limit violation, dials will block.
//
// Zero means no limit.
//
// For HTTP/2, this currently only controls the number of new
// connections being created at a time, instead of the total
// number. In practice, hosts using HTTP/2 only have about one
// idle connection, though.
MaxConnsPerHost int `json:"max_conns_per_host" toml:"max_conns_per_host"`
// IdleConnTimeout is the maximum amount of time an idle
// (keep-alive) connection will remain idle before closing
// itself.
// Zero means no limit.
IdleConnTimeout time.Duration `json:"idle_conn_timeout" toml:"idle_conn_timeout"`
// TLSHandshakeTimeout specifies the maximum amount of time waiting to
// wait for a TLS handshake. Zero means no timeout.
TLSHandshakeTimeout time.Duration `json:"tls_handshake_timeout" toml:"tls_handshake_timeout"`
// DisableCompression, if true, prevents the Transport from
// requesting compression with an "Accept-Encoding: gzip"
// request header when the Request contains no existing
// Accept-Encoding value. If the Transport requests gzip on
// its own and gets a gzipped response, it's transparently
// decoded in the Response.Body. However, if the user
// explicitly requested gzip it is not automatically
// uncompressed.
DisableCompression bool `json:"disable_compression" toml:"disable_compression"`
// ResponseHeaderTimeout, if non-zero, specifies the amount of
// time to wait for a server's response headers after fully
// writing the request (including its body, if any). This
// time does not include the time to read the response body.
ResponseHeaderTimeout time.Duration `json:"response_header_timeout" toml:"response_header_timeout"`
// ExpectContinueTimeout, if non-zero, specifies the amount of
// time to wait for a server's first response headers after fully
// writing the request headers if the request has an
// "Expect: 100-continue" header. Zero means no timeout and
// causes the body to be sent immediately, without
// waiting for the server to approve.
// This time does not include the time to send the request header.
ExpectContinueTimeout time.Duration `json:"expect_continue_timeout" toml:"expect_continue_timeout"`
// MaxResponseHeaderBytes specifies a limit on how many
// response bytes are allowed in the server's response
// header.
//
// Zero means to use a default limit.
MaxResponseHeaderBytes int64 `json:"max_response_header_bytes" toml:"max_response_header_bytes"`
// WriteBufferSize specifies the size of the write buffer used
// when writing to the transport.
// If zero, a default (currently 4KB) is used.
WriteBufferSize int `json:"write_buffer_size" toml:"write_buffer_size"`
// ReadBufferSize specifies the size of the read buffer used
// when reading from the transport.
// If zero, a default (currently 4KB) is used.
ReadBufferSize int `json:"read_buffer_size" toml:"read_buffer_size"`
// ForceAttemptHTTP2 controls whether HTTP/2 is enabled when a non-zero
// Dial, DialTLS, or DialContext func or TLSClientConfig is provided.
// By default, use of any those fields conservatively disables HTTP/2.
// To use a custom dialer or TLS config and still attempt HTTP/2
// upgrades, set this to true.
ForceAttemptHTTP2 bool `json:"force_attempt_http_2" toml:"force_attempt_http_2"`
// Timeout specifies a time limit for requests made by this
// Client. The timeout includes connection time, any
// redirects, and reading the response body. The timer remains
// running after Get, Head, Post, or Do return and will
// interrupt reading of the Response.Body.
//
// A Timeout of zero means no timeout.
//
// The Client cancels requests to the underlying Transport
// as if the Request's Context ended.
//
// For compatibility, the Client will also use the deprecated
// CancelRequest method on Transport if found. New
// RoundTripper implementations should use the Request's Context
// for cancelation instead of implementing CancelRequest.
RequestTimeout time.Duration `json:"request_timeout" toml:"request_timeout"`
// FlushInterval specifies the flush interval
// to flush to the client while copying the
// response body.
// If zero, no periodic flushing is done.
// A negative value means to flush immediately
// after each write to the client.
// The FlushInterval is ignored when ReverseProxy
// recognizes a response as a streaming response;
// for such responses, writes are flushed to the client
// immediately.
ProxyFlushInterval time.Duration `json:"proxy_flush_interval" toml:"proxy_flush_interval"`
// BufferPool optionally specifies a buffer pool to
// get byte slices for use by io.CopyBuffer when copying HTTP response bodies.
// Values: none, sync
ProxyBufferPool string `json:"proxy_buffer_pool" toml:"proxy_buffer_pool"`
// ErrorHandler is an optional function that handles errors
// reaching the backend or errors from ModifyResponse.
// Values: none, body
ProxyErrorHandler string `json:"proxy_error_handler" toml:"proxy_error_handler"`
// 用于proxyBufferPool的init size
HttpBuffSize int `json:"http_buff_size" toml:"http_buff_size"`
}
type Logger ¶
type Logger struct {
Level Level
Log func(level Level, args ...interface{})
Logf func(level Level, format string, args ...interface{})
Flush func()
Close func()
// contains filtered or unexported fields
}
var DefaultLogger *Logger = newLogImpl()
默认采用go内部的log实现, 建议使用其他相关实现替换, 例如: github.com/fasgo/log
func (*Logger) ErrorStack ¶
func (*Logger) FatalStack ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.