web

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestTimeOut http request timeout (second)
	RequestTimeOut = 30
)

Variables

This section is empty.

Functions

func GetRealIP

func GetRealIP(req *http.Request) (ip string)

GetRealIP get real IP from Request

func HTMLEscape

func HTMLEscape(url string) string

HTMLEscape html special char convert

space to &quot;, & to &amp;, < to &lt;, > to &gt;

func HTMLUnEscape

func HTMLUnEscape(url string) string

HTMLUnEscape html special char convert

&quot; to space, &amp; to &, &lt; to <, &gt; to >

func ListenAndServe

func ListenAndServe(addr string, router http.Handler)

ListenAndServe new server and start

func ListenAndServeTLS

func ListenAndServeTLS(addr, certFile, keyFile string, router http.Handler)

ListenAndServeTLS new server and start

func NotAllowedHandler

func NotAllowedHandler(w http.ResponseWriter, req *http.Request)

NotAllowedHandler 405

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, req *http.Request)

NotFoundHandler 404

func PanicHandler

func PanicHandler(w http.ResponseWriter, r *http.Request, err interface{})

PanicHandler panic router

func Redirect

func Redirect(w http.ResponseWriter, url string)

Redirect redirect

func ResponseJSON

func ResponseJSON(reply *tyr.ReplyData, req *http.Request, w http.ResponseWriter) error

ResponseJSON reply JSON

func SetCookie

func SetCookie(w http.ResponseWriter, name, value, path string, maxAge int)

SetCookie set http cookie

func WriteBytes

func WriteBytes(w http.ResponseWriter, response interface{}) error

WriteBytes response bytes

func WriteCtxBytes

func WriteCtxBytes(ctx context.Context, w http.ResponseWriter, response interface{}) error

WriteCtxBytes response text data.

func WriteCtxJSON

func WriteCtxJSON(ctx context.Context, w http.ResponseWriter, response interface{}) error

WriteCtxJSON response JSON data.

func WriteCtxXML

func WriteCtxXML(ctx context.Context, w http.ResponseWriter, response interface{}) error

WriteCtxXML response XML data.

func WriteJSON

func WriteJSON(w http.ResponseWriter, response interface{}) error

WriteJSON response JSON data.

func WriteXML

func WriteXML(w http.ResponseWriter, response interface{}) error

WriteXML response XML data.

Types

type Message

type Message struct {
	StatusCode int
	Body       []byte
	Header     http.Header
}

Message HTTP response

func Get

func Get(uri, certPath, keyPath string, header map[string]string) (msg Message, err error)

Get HTTP request GET

func Post

func Post(uri, certPath, keyPath string, header map[string]string, data io.Reader) (msg Message, err error)

Post HTTP request POST

Jump to

Keyboard shortcuts

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