netutil

package
v0.0.0-...-7b3ddb2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugPprofBlockHandler

func DebugPprofBlockHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofCmdlineHandler

func DebugPprofCmdlineHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofGoroutineHandler

func DebugPprofGoroutineHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofHandler

func DebugPprofHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofHeapHandler

func DebugPprofHeapHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofMutexHandler

func DebugPprofMutexHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofProfileHandler

func DebugPprofProfileHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofSymbolHandler

func DebugPprofSymbolHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofThreadcreateHandler

func DebugPprofThreadcreateHandler(w http.ResponseWriter, r *http.Request)

func DebugPprofTraceHandler

func DebugPprofTraceHandler(w http.ResponseWriter, r *http.Request)

func Error

func Error(w http.ResponseWriter, error string, code int)

Error replies to the request with the specified error message and HTTP code. It does not otherwise end the request; the caller should ensure no further writes are done to w. The error message should be plain text.

func ErrorRender

func ErrorRender(w http.ResponseWriter, code int, err error)

ErrorRender replies to the request with the specified error message and 500 code.

func GCHandler

func GCHandler(w http.ResponseWriter, _ *http.Request)

func GetPrivateIP

func GetPrivateIP() net.IP

GetPrivateIP returns a private IP address, or panics if no IP is available.

func GetPrivateIPByName

func GetPrivateIPByName(name string) net.IP

func GetReqBody

func GetReqBody(r *http.Request) ([]byte, error)

func GetUrlQuery

func GetUrlQuery(r *http.Request) map[string]string

func JSONRender

func JSONRender(w http.ResponseWriter, data interface{})

JSONRender serializes the given struct as JSON into the response body.

func LimitHandle

func LimitHandle(w http.ResponseWriter, r *http.Request)

func NewQuery

func NewQuery() *query

func PingPong

func PingPong(w http.ResponseWriter, _ *http.Request)

func SetMode

func SetMode(mode RouterMode)

func StartPprofService

func StartPprofService(addr string) (*http.ServeMux, error)

Types

type Handle

type Handle func(http.ResponseWriter, *http.Request, UriParams)

type HttpReply

type HttpReply struct {
	Code int64       `json:"code"`
	Msg  string      `json:"msg,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

http protocal

type Response

type Response struct {
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(respWriter http.ResponseWriter) *Response

func (*Response) SendJson

func (this *Response) SendJson(data interface{})

func (*Response) SendJsonBytes

func (this *Response) SendJsonBytes(bytes []byte)

func (*Response) SendJsonHttpReplyError

func (this *Response) SendJsonHttpReplyError(err error)

func (*Response) SendJsonHttpReplySuccess

func (this *Response) SendJsonHttpReplySuccess(data interface{})

func (*Response) SendText

func (this *Response) SendText(text string)

func (*Response) SetAllowMethod

func (this *Response) SetAllowMethod(method string) *Response

func (*Response) SetHttpStatus

func (this *Response) SetHttpStatus(httpStatus int) *Response

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter, writer io.Writer) *ResponseWriter

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(b []byte) (int, error)

type RouterMode

type RouterMode string
const (
	RouterModeHttpRouter RouterMode = "httprouter"
	RouterModeGorilla    RouterMode = "gorilla"
	StartTime                       = "__start_time"
)

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a http server

func NewServer

func NewServer(config *ServerConfig) *Server

NewUriServer creates the server with uri parsing

func (*Server) CatchPanicAndSendErrReply

func (s *Server) CatchPanicAndSendErrReply(w http.ResponseWriter)

func (*Server) Close

func (s *Server) Close()

Close closes the server.

func (*Server) Handle

func (s *Server) Handle(method string, path string, handle Handle)

func (*Server) Handles

func (s *Server) Handles(method string, path string, handles []HandleContinued)

process multiple handles

func (*Server) HandlesMethods

func (s *Server) HandlesMethods(methods []string, path string, handles []HandleContinued, end HandleContinued)

func (*Server) Name

func (s *Server) Name() string

func (*Server) Run

func (s *Server) Run() error

Run runs the server.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Shutdown

func (s *Server) Shutdown()

Graceful shutdown the server

type ServerConfig

type ServerConfig struct {
	Name         string
	Addr         string // ip:port
	Version      string
	ConnLimit    int
	CloseTimeout time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	RateLimit    ratelimit2.RateLimit
}

type UriParams

type UriParams interface {
	ByName(name string) string
	Put(name string, value string)
}

func NewMockUriParams

func NewMockUriParams(values map[string]string) UriParams

type UriParamsMap

type UriParamsMap struct {
	// contains filtered or unexported fields
}

func (*UriParamsMap) ByName

func (p *UriParamsMap) ByName(name string) string

func (*UriParamsMap) Put

func (p *UriParamsMap) Put(name, value string)

Jump to

Keyboard shortcuts

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