Documentation
¶
Index ¶
- Constants
- Variables
- func BindJSON(r *http.Request, data interface{}) error
- func CheckPath(path string) string
- func CheckPattern(pattern string) string
- func CreateConfigFile(path string, c *Config)
- func CreateFolder(path string) error
- func GetRealIP(req *http.Request) string
- func GzipJSON(w http.ResponseWriter, data interface{})
- func JSON(w http.ResponseWriter, data interface{})
- func JsonErr(w http.ResponseWriter, err error)
- func JsonOK(w http.ResponseWriter, data interface{})
- func JsonResp(w http.ResponseWriter, code int, res string)
- func JsonWrong(w http.ResponseWriter, res string)
- func LoadJSON(name string, data interface{}) error
- func LoadOrCreateJSON(name string, data interface{}) error
- func LogErr(err error, msg string)
- func MD5(src string) []byte
- func RandomString(n int) string
- func SaveJSON(name string, data interface{}) error
- func StrTime(timestamp int64, timeLayout string) string
- func ToJsonStr(data interface{}) string
- func Trace(msg string) func()
- func UUID() string
- func UnixTime(timeStr, layout string) int64
- type Client
- func (c *Client) GetJSON(url string, data interface{}) (err error)
- func (c *Client) GetJSONAuth(url, un, pa string, data interface{}) (err error)
- func (c *Client) PostFormJSON(url string, vals url.Values, data interface{}) (err error)
- func (c *Client) PostFormJSONAuth(url, un, pa string, vals url.Values, data interface{}) (err error)
- func (c *Client) PostJSON(url string, src, data interface{}) (err error)
- func (c *Client) PostJSONAuth(url, un, pa string, src, data interface{}) (err error)
- type ClientConfig
- type Config
- type Dealer
- type Dealers
- type HttpHandler
- func GETHandler(p string, h func(w http.ResponseWriter, r *http.Request), m ...Dealer) *HttpHandler
- func NewHandler(p string, h func(w http.ResponseWriter, r *http.Request), m ...Dealer) *HttpHandler
- func POSTHandler(p string, h func(w http.ResponseWriter, r *http.Request), m ...Dealer) *HttpHandler
- type Queue
- type Resp
- type Serial
- type Server
- type ServerConfig
- type StmtDB
- type TStamp
- type XmlMap
Constants ¶
const ( CodeOK = iota CodeErr )
Resp Code option values
const ( // TimeLayout1 2006-01-02 15:04:05 TimeLayout1 = "2006-01-02 15:04:05" // TimeLayout2 2006-01-02 TimeLayout2 = "2006-01-02" // TimeLayout3 15:04:05 TimeLayout3 = "15:04:05" // TimeLayout4 20060102150405 TimeLayout4 = "20060102150405" // TimeLayout5 20060102 TimeLayout5 = "20060102" // TimeLayout6 150405 TimeLayout6 = "150405" // TimeLayout7 2006.01.02 TimeLayout7 = "2006.01.02" // TimeLayout8 2006/01/02 TimeLayout8 = "2006/01/02" )
timestamp format layout
Variables ¶
var DefaultConfig = &Config{ Name: "config.short.json", Server: &ServerConfig{ Addr: ":8080", ReadTimeout: 5, WriteTimeout: 30, IdleTimeout: 3, }, Client: &ClientConfig{ Timeout: 15, KeepAlive: 30, ResponseHeaderTimeout: 30, ExpectContinueTimeout: 3, MaxIdleConns: 50, IdleConnTimeout: 60, }, }
DefaultConfig default configuration
Functions ¶
func CheckPattern ¶
CheckPattern check pattern, make sure to start with '/'
func CreateConfigFile ¶
CreateConfigFile create config file
func CreateFolder ¶
CreateFolder create folders according to path
func GzipJSON ¶
func GzipJSON(w http.ResponseWriter, data interface{})
GzipJSON write json data with gzip
func LoadOrCreateJSON ¶
LoadOrCreateJSON load json file, if not, create json file
Types ¶
type Client ¶
Client contain http.Client, add some methods
func NewConfigClient ¶
func NewConfigClient(c *ClientConfig) *Client
NewClient new client with custom config
func (*Client) GetJSONAuth ¶
GetJSONAuth get request with basic auth, json response parse to struct
func (*Client) PostFormJSON ¶
PostFormJSON json post form request, json response parse to struct
func (*Client) PostFormJSONAuth ¶
func (c *Client) PostFormJSONAuth(url, un, pa string, vals url.Values, data interface{}) (err error)
PostFormJSONAuth json post form request with basic auth, json response parse to struct
func (*Client) PostJSONAuth ¶
PostJSONAuth json post request with basic auth, json response parse to struct
type ClientConfig ¶
type ClientConfig struct { Timeout time.Duration `json:"timeout"` KeepAlive time.Duration `json:"keepAlive"` ResponseHeaderTimeout time.Duration `json:"responseHeaderTimeout"` ExpectContinueTimeout time.Duration `json:"expectContinueTimeout"` MaxIdleConns int `json:"maxIdleConns"` IdleConnTimeout time.Duration `json:"idleConnTimeout"` }
ClientConfig client configuration
type Config ¶
type Config struct { Name string `json:"name"` Server *ServerConfig `json:"server"` Client *ClientConfig `json:"client"` }
Config - configuration
type Dealer ¶
Dealer middleware function
type HttpHandler ¶
type HttpHandler struct { Pattern string Handler func(w http.ResponseWriter, r *http.Request) Middleware Dealers }
HttpHandler http handler
func GETHandler ¶
func GETHandler(p string, h func(w http.ResponseWriter, r *http.Request), m ...Dealer) *HttpHandler
GETHandler new a http method GET HttpHandler
func NewHandler ¶
func NewHandler(p string, h func(w http.ResponseWriter, r *http.Request), m ...Dealer) *HttpHandler
NewHandler new a HttpHandler
func POSTHandler ¶
func POSTHandler(p string, h func(w http.ResponseWriter, r *http.Request), m ...Dealer) *HttpHandler
POSTHandler new a http method POST HttpHandler
type Resp ¶
type Resp struct { Code int `json:"code"` Result string `json:"result"` Data interface{} `json:"data,omitempty"` }
Resp http request response
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server short server
func NewConfigServer ¶
func NewConfigServer(c *ServerConfig) *Server
NewConfigServer new http server with custom config
func (*Server) FileServer ¶
FileServer handle file server
func (*Server) Handlers ¶
func (s *Server) Handlers(list []*HttpHandler) *Server
Handlers set http handlers
type ServerConfig ¶
type ServerConfig struct { Addr string `bson:"addr"` ReadTimeout time.Duration `bson:"readTimeout"` WriteTimeout time.Duration `bson:"writeTimeout"` IdleTimeout time.Duration `bson:"idleTimeout"` }
ServerConfig server configuration
type StmtDB ¶
StmtDB package sqlx.DB with sqlx.Stmt, sqlx.NamedStmt map, and a sync.Mutex
func (*StmtDB) DeferLock ¶
func (s *StmtDB) DeferLock() func()
DeferLock execute mutex Lock() and return mutex.Unlock for defer example: defer s.DeferLock()()
type TStamp ¶
type TStamp int64
TStamp custom type for int64
func (TStamp) MarshalJSON ¶
MarshalJSON implement Marshaler
func (*TStamp) UnmarshalJSON ¶
UnmarshalJSON implement Unmarshaler
type XmlMap ¶
XmlMap xml转换map
func (XmlMap) MarshalXML ¶
MarshalXML marshals the map to XML
func (*XmlMap) UnmarshalXML ¶
UnmarshalXML unmarshals the XML into a map of string to strings