Documentation ¶
Overview ¶
Package http wraps net/http
Index ¶
- func NewDefaultClient() *http.Client
- func NewDefaultTransport() *http.Transport
- func NewLoggingHandler(h http.Handler, log *dlog.Logger) http.Handler
- type JsonFunc
- type JsonHandler
- type JsonHandlerMux
- type JsonHandlerRegister
- type Server
- func (srv *Server) GetLogger() *dlog.Logger
- func (srv *Server) LoggerIdentity(justCallMe func() dlog.Identity) dlog.Identity
- func (srv *Server) Port() int
- func (srv *Server) Run() error
- func (srv *Server) RunWithContext(ctx context.Context) error
- func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (srv *Server) SetLogger(logger *dlog.Logger)
- func (srv *Server) Shutdown(ctx context.Context) error
- type TrackedWriter
- func (tracker *TrackedWriter) CloseNotify() <-chan bool
- func (tracker *TrackedWriter) Flush()
- func (tracker *TrackedWriter) Header() http.Header
- func (tracker *TrackedWriter) Push(target string, opts *http.PushOptions) error
- func (tracker *TrackedWriter) Size() int
- func (tracker *TrackedWriter) Status() int
- func (tracker *TrackedWriter) Write(b []byte) (int, error)
- func (tracker *TrackedWriter) WriteHeader(status int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDefaultClient ¶
NewDefaultClient returns a client using NewDefaultTransport
func NewDefaultTransport ¶
Types ¶
type JsonHandler ¶
type JsonHandlerMux ¶
type JsonHandlerMux struct {
// contains filtered or unexported fields
}
func NewJsonHandlerMux ¶
func NewJsonHandlerMux() *JsonHandlerMux
func (*JsonHandlerMux) AddHandlerFunc ¶
func (m *JsonHandlerMux) AddHandlerFunc(path string, payloadFactory func() interface{}, f JsonFunc)
func (*JsonHandlerMux) MountToStd ¶
func (m *JsonHandlerMux) MountToStd(mux *http.ServeMux)
type JsonHandlerRegister ¶
type JsonHandlerRegister func(mux *JsonHandlerMux)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(cfg config.HttpServerConfig, h http.Handler, tracer opentracing.Tracer) (*Server, error)
TODO: check if there is any error in config and return error
func (*Server) LoggerIdentity ¶
type TrackedWriter ¶
type TrackedWriter struct {
// contains filtered or unexported fields
}
TrackedWriter keeps track of status code and bytes written so it can be used by logger. It proxies all the interfaces except Hijacker, since it is not supported by HTTP/2. Most methods comments are copied from net/http It is based on https://github.com/gorilla/handlers but put all interface on one struct
func (*TrackedWriter) CloseNotify ¶
func (tracker *TrackedWriter) CloseNotify() <-chan bool
CloseNotify returns nil if underlying ResponseWriter does not implement http.CloseNotifier
The CloseNotifier interface is implemented by ResponseWriters which allow detecting when the underlying connection has gone away
func (*TrackedWriter) Flush ¶
func (tracker *TrackedWriter) Flush()
Flush calls Flush on underlying ResponseWriter if it implemented http.Flusher
Flusher interface is implemented by ResponseWriters that allow an HTTP handler to flush buffered data to the client. The default HTTP/1.x and HTTP/2 ResponseWriter implementations support Flusher
func (*TrackedWriter) Header ¶
func (tracker *TrackedWriter) Header() http.Header
Header returns the header map of the underlying ResponseWriter
Changing the header map after a call to WriteHeader (or Write) has no effect unless the modified headers are trailers.
func (*TrackedWriter) Push ¶
func (tracker *TrackedWriter) Push(target string, opts *http.PushOptions) error
Push returns http.ErrNotSupported if underlying ResponseWriter does not implement http.Pusher
Push initiates an HTTP/2 server push, returns ErrNotSupported if the client has disabled push or if push is not supported on the underlying connection.
func (*TrackedWriter) Size ¶
func (tracker *TrackedWriter) Size() int
Size return number of bytes written through Write, returns 0 if Write has not been called
func (*TrackedWriter) Status ¶
func (tracker *TrackedWriter) Status() int
Status return the tracked status code, returns 0 if WriteHeader has not been called
func (*TrackedWriter) Write ¶
func (tracker *TrackedWriter) Write(b []byte) (int, error)
Write keeps track of bytes written of the underlying ResponseWriter
Write writes the data to the connection as part of an HTTP reply.
If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK) before writing the data. If the Header does not contain a Content-Type line, Write adds a Content-Type set to the result of passing the initial 512 bytes of written data to DetectContentType.
func (*TrackedWriter) WriteHeader ¶
func (tracker *TrackedWriter) WriteHeader(status int)
WriteHeader keep track of status code and call the underlying ResponseWriter
WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.