Documentation ¶
Index ¶
- Variables
- func AddCommandList()
- func AddParameterToUrl(urls string, key string, value string) (urlout string, err error)
- func AddUriProxyToDefaultServer(uri, targetUrl string)
- func ClearHttpDefaultServer()
- func CompressHandler(fn http.Handler) http.Handler
- func CompressHandlerFunc(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request)
- func CompressWriteByte(r *http.Request, w http.ResponseWriter, b []byte)
- func CompressWriteHtml(req *http.Request, w http.ResponseWriter, html []byte)
- func DumpResponseToBytes(resp *http.Response) (b []byte, err error)
- func FormatHttpsCertOrKey(inS string) string
- func GetDomainName(url string) (domainName string, protocol string)
- func GetHttpsCertNotCheckClient() *http.Client
- func GoListenAndServeTLSWithCertContent(addr string, certS string, keyS string, handler http.Handler) error
- func HeaderToString(header http.Header) (s string)
- func HttpHandleCompressFlateWrap(fn http.Handler) http.Handler
- func HttpHandleCompressGzipWrap(fn http.Handler) http.Handler
- func HttpProxyToWriter(w http.ResponseWriter, req *http.Request) (err error)
- func HttpRequestClone(in *http.Request) (out *http.Request, err error)
- func HttpResponseToWrite(resp *http.Response, w http.ResponseWriter)
- func HttpRoundTrip(req *http.Request) (resp *http.Response, err error)
- func MustAddContentToDefaultServer(uri string, content []byte)
- func MustAddFileToHttpPathToDefaultServer(httpPath string, localFilePath string)
- func MustAddFileToHttpPathToServeMux(mux *http.ServeMux, httpPath string, localFilePath string)
- func MustAddUriProxyRefToUriToDefaultServer(uri, targetUrl string)
- func MustGoHttpAsyncListenAndServeWithCloser(addr string, handler http.Handler) (closer func() error)
- func MustGoHttpsAsyncListenAndServeWithCloser(addr string, tlsConfig *tls.Config, handler http.Handler) (closer func() error)
- func MustHttpRequestClone(in *http.Request) *http.Request
- func MustNewHttpNetServerV2(Addr string, handler http.Handler) func() error
- func MustNewTestClientWithHttpProxy(httpProxy string) *http.Client
- func MustRequestFromString(reqString string) (req *http.Request)
- func MustRequestToStringCanRead(req *http.Request) (s string)
- func MustResponseReadAllBody(resp *http.Response) (b []byte)
- func MustSetParameterMapToUrl(urls string, row map[string]string) (urlout string)
- func MustSetParameterToUrl(urls string, key string, value string) (urlout string)
- func MustUrlGetContent(url string) (b []byte)
- func MustUrlGetContentProcess(url string) (b []byte)
- func NewHttpNetServer(Addr string, handler http.Handler) kmgNet.Server
- func NewHttpsCertNotCheckClient() *http.Client
- func NewRequestFromByte(r []byte) (req *http.Request, err error)
- func NewResponseFromBytes(r []byte) (resp *http.Response, err error)
- func NewTimeoutHttpClient(dur time.Duration) *http.Client
- func NewTimeoutNoKeepAliveHttpClient(dur time.Duration) *http.Client
- func Redirect301ToNewHost(w http.ResponseWriter, req *http.Request, scheme string, host string)
- func RequestReadAllBody(req *http.Request) (b []byte, err error)
- func ResponseReadAllBody(resp *http.Response) (b []byte, err error)
- func SetParameterMapToUrl(urls string, row map[string]string) (urlout string, err error)
- func SetParameterToUrl(urls string, key string, value string) (urlout string, err error)
- func SortUrlQuery(vurl *url.URL)
- func UrlGetContent(url string) (b []byte, err error)
- type Context
- func (c *Context) DeleteInMap(key string)
- func (c *Context) Error(err error)
- func (c *Context) GetClientIpStringIgnoreError() string
- func (c *Context) GetDataStr(key string) string
- func (c *Context) GetInMap() map[string]string
- func (c *Context) GetRedirectUrl() string
- func (c *Context) GetRequest() *http.Request
- func (c *Context) GetRequestUrl() string
- func (c *Context) GetResponseByteList() []byte
- func (c *Context) GetResponseCode() int
- func (c *Context) GetResponseHeader(key string) string
- func (c *Context) GetResponseString() string
- func (c *Context) GetResponseWriter() io.Writer
- func (c *Context) InHas(key string) bool
- func (c *Context) InNum(key string) int
- func (c *Context) InStr(key string) string
- func (c *Context) InStrDefault(key string, def string) string
- func (c *Context) IsGet() bool
- func (c *Context) IsPost() bool
- func (c *Context) Log() *ContextLog
- func (c *Context) MustFirstInFile() *multipart.FileHeader
- func (c *Context) MustGetClientIp() net.IP
- func (c *Context) MustInFile(key string) *multipart.FileHeader
- func (c *Context) MustInJson(key string, obj interface{})
- func (c *Context) MustInNum(key string) int
- func (c *Context) MustInStr(key string) string
- func (c *Context) MustPost()
- func (c *Context) NewTestContextWithSession() *Context
- func (c *Context) NotFound(msg string)
- func (c *Context) Redirect(url string)
- func (c *Context) SessionClear() *Context
- func (c *Context) SessionGetJson(key string, obj interface{}) (err error)
- func (c *Context) SessionGetStr(key string) string
- func (c *Context) SessionSetJson(key string, value interface{}) *Context
- func (c *Context) SessionSetStr(key string, value string) *Context
- func (c *Context) SetDataStr(key string, value string)
- func (c *Context) SetInMap(data map[string]string) *Context
- func (c *Context) SetInStr(key string, value string) *Context
- func (c *Context) SetPost() *Context
- func (c *Context) SetRequestUrl(url string) *Context
- func (c *Context) SetResponseCode(code int)
- func (c *Context) SetResponseHeader(key string, value string)
- func (c *Context) WriteAttachmentFile(b []byte, fileName string)
- func (c *Context) WriteByte(s []byte)
- func (c *Context) WriteJson(obj interface{})
- func (c *Context) WriteString(s string)
- func (c *Context) WriteToResponseWriter(w http.ResponseWriter, req *http.Request)
- type ContextLog
- type LogStruct
- type ResponseWriterWraper
Constants ¶
This section is empty.
Variables ¶
var SessionCookieName = "kmgSession"
var SessionPsk = [32]byte{0xd8, 0x51, 0xea, 0x81, 0xb9, 0xe, 0xf, 0x2f, 0x8c, 0x85, 0x5f, 0xb6, 0x14, 0xb2}
Functions ¶
func AddCommandList ¶
func AddCommandList()
func AddParameterToUrl ¶
@deprecated
func AddUriProxyToDefaultServer ¶
func AddUriProxyToDefaultServer(uri, targetUrl string)
url明文反向代理. uri表示,以此uri作为前缀可以进入这个地方,此处代理不会修改用户的uri 例如: 注册 AddUriProxyToDefaultServer("/data/upload/","http://b.com/") 用户访问 http://xxx.com/data/upload/745dfc0e7d24b9232a0226116e115967.jpg 此处会去访问 http://b.com/data/upload/745dfc0e7d24b9232a0226116e115967.jpg
func CompressHandlerFunc ¶
func CompressHandlerFunc(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request)
func CompressWriteByte ¶
func CompressWriteByte(r *http.Request, w http.ResponseWriter, b []byte)
如果使用了这个,golang的猜测返回类型的东西会挂掉.请设置输出的内容的类型 这个地方返回错误没有什么意义,(调用者无法处理)
func CompressWriteHtml ¶
func CompressWriteHtml(req *http.Request, w http.ResponseWriter, html []byte)
func DumpResponseToBytes ¶
sometimes it is hard to remember how to dump response to bytes
func GetDomainName ¶
@deprecated
func HeaderToString ¶
func HttpHandleCompressFlateWrap ¶
a flate(DEFLATE) compress wrap around http request and response, !!not handle any http header!!
func HttpHandleCompressGzipWrap ¶
a flate(DEFLATE) compress wrap around http request and response, !!not handle any http header!!
func HttpProxyToWriter ¶
func HttpProxyToWriter(w http.ResponseWriter, req *http.Request) (err error)
进行http代理,并且代理到writer上面去 调用时,请修改req的参数,避免自己调用自己 如果出现错误,(对方服务器连不上之类的,不会修改w,会返回一个error 不跟踪redirect(跟踪redirect会导致redirect的请求的内容被返回)
func HttpRequestClone ¶
会把request里面的东西全部都读出来(body)
func HttpResponseToWrite ¶
func HttpResponseToWrite(resp *http.Response, w http.ResponseWriter)
func MustAddFileToHttpPathToDefaultServer ¶
向http默认服务器加入一个本地文件或目录
func MustAddUriProxyRefToUriToDefaultServer ¶
func MustAddUriProxyRefToUriToDefaultServer(uri, targetUrl string)
url明文反向代理. uri 是否以/开头和结束无所谓, targetUrl 是否以/结束无所谓. uri表示,以此path作为前缀可以进入这个地方,此处代理可能会修改请求的path 例如: 注册 MustAddUriProxyRefToUriToDefaultServer("/data/upload/","http://b.com/") 用户访问 http://xxx.com/data/upload/745dfc0e7d24b9232a0226116e115967.jpg 此处会去访问 http://b.com/745dfc0e7d24b9232a0226116e115967.jpg
func MustGoHttpAsyncListenAndServeWithCloser ¶
func MustGoHttpAsyncListenAndServeWithCloser(addr string, handler http.Handler) (closer func() error)
异步开启一个http服务器,这个服务器可以使用返回的closer关闭
func MustNewHttpNetServerV2 ¶
一个可以关闭的http服务器
func MustNewTestClientWithHttpProxy ¶
一个不验证证书,并且使用http代理的http客户端 httpProxy look like http://127.0.0.1:9876
func MustRequestFromString ¶
func MustRequestToStringCanRead ¶
把request转换成[]byte,并且使body可以被再次读取
func MustResponseReadAllBody ¶
func MustSetParameterToUrl ¶
func MustUrlGetContent ¶
func NewHttpNetServer ¶
一个http的满足 kmgNet.Server接口的服务器
func NewResponseFromBytes ¶
sometimes it is hard to remember how to get response from bytes ...
func Redirect301ToNewHost ¶
func SetParameterMapToUrl ¶
func SetParameterToUrl ¶
func SortUrlQuery ¶
sort url query to unique it 这个东西是做什么用的? @deprecated
func UrlGetContent ¶
Types ¶
type Context ¶
type Context struct { DataMap map[string]string //上下文里面可以携带一些信息 // contains filtered or unexported fields }
该对象上的方法不应该被并发调用.
func NewContextFromHttp ¶
func NewContextFromHttp(w http.ResponseWriter, req *http.Request) *Context
func (*Context) DeleteInMap ¶
func (*Context) GetClientIpStringIgnoreError ¶
func (*Context) GetDataStr ¶
func (*Context) GetRedirectUrl ¶
func (*Context) GetRequest ¶
func (*Context) GetRequestUrl ¶
func (*Context) GetResponseByteList ¶
func (*Context) GetResponseCode ¶
func (*Context) GetResponseHeader ¶
func (*Context) GetResponseString ¶
func (*Context) GetResponseWriter ¶
func (*Context) Log ¶
func (c *Context) Log() *ContextLog
func (*Context) MustFirstInFile ¶
func (c *Context) MustFirstInFile() *multipart.FileHeader
func (*Context) MustGetClientIp ¶
func (*Context) MustInFile ¶
func (c *Context) MustInFile(key string) *multipart.FileHeader
func (*Context) MustInJson ¶
func (*Context) NewTestContextWithSession ¶
仅把Session传递过去的上下文,其他东西都恢复默认值
func (*Context) SessionClear ¶
清除Session里面的内容. 更换Session的Id.
func (*Context) SessionGetJson ¶
func (*Context) SessionGetStr ¶
从Session里面获取一个字符串
func (*Context) SessionSetJson ¶
func (*Context) SessionSetStr ¶
向Session里面设置一个字符串
func (*Context) SetDataStr ¶
func (*Context) SetRequestUrl ¶
func (*Context) SetResponseCode ¶
func (*Context) SetResponseHeader ¶
func (*Context) WriteAttachmentFile ¶
func (*Context) WriteString ¶
func (*Context) WriteToResponseWriter ¶
func (c *Context) WriteToResponseWriter(w http.ResponseWriter, req *http.Request)
type ContextLog ¶
type ContextLog struct { Method string `json:",omitempty"` ResponseCode int `json:",omitempty"` Url string `json:",omitempty"` RemoteAddr string `json:",omitempty"` UA string `json:",omitempty"` Refer string `json:",omitempty"` RedirectUrl string `json:",omitempty"` InMap map[string]string `json:",omitempty"` ProcessTime string `json:",omitempty"` RequestSize int `json:",omitempty"` ResponseSize int `json:",omitempty"` ResponseContent string `json:",omitempty"` }
type LogStruct ¶
type LogStruct struct { Method string Url string RemoteAddr string UA string `json:",omitempty"` Refer string `json:",omitempty"` Host string `json:",omitempty"` }
func NewLogStruct ¶
type ResponseWriterWraper ¶
type ResponseWriterWraper struct { io.Writer http.ResponseWriter }