server

package
v0.0.0-...-8fed76b Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeUnknown = "UNKNOWN"
	ErrMsgUnknown  = "unknown error"
)

Variables

View Source
var (
	ErrBadRequest                  = NewStatusCodeHTTPError(http.StatusBadRequest)
	ErrUnauthorized                = NewStatusCodeHTTPError(http.StatusUnauthorized)
	ErrForbidden                   = NewStatusCodeHTTPError(http.StatusForbidden)
	ErrNotFound                    = NewStatusCodeHTTPError(http.StatusNotFound)
	ErrMethodNotAllowed            = NewStatusCodeHTTPError(http.StatusMethodNotAllowed)
	ErrRequestTimeout              = NewStatusCodeHTTPError(http.StatusRequestTimeout)
	ErrStatusRequestEntityTooLarge = NewStatusCodeHTTPError(http.StatusRequestEntityTooLarge)
	ErrUnsupportedMediaType        = NewStatusCodeHTTPError(http.StatusUnsupportedMediaType)
	ErrTooManyRequests             = NewStatusCodeHTTPError(http.StatusTooManyRequests)

	ErrInternalServerError = NewStatusCodeHTTPError(http.StatusInternalServerError)
	ErrBadGateway          = NewStatusCodeHTTPError(http.StatusBadGateway)
	ErrServiceUnavailable  = NewStatusCodeHTTPError(http.StatusServiceUnavailable)

	ErrRendererNotRegistered = NewMsgHTTPError("renderer not registered")
	ErrCookieNotFound        = NewMsgHTTPError("cookie not found")
)

Errors

View Source
var (
	OnlyLogReportTargets  = []ReportTarget{LogReportTarget}
	OnlyUserReportTargets = []ReportTarget{UserReportTarget}
	AllReportTargets      = []ReportTarget{LogReportTarget, UserReportTarget}
)

Functions

This section is empty.

Types

type App

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

App is the top-level web application instance.

func (*App) NewRouter

func (app *App) NewRouter() *R

type C

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

C represents the context of the current HTTP request.

func (*C) Attachment

func (c *C) Attachment(file, name string) error

func (*C) Blob

func (c *C) Blob(statusCode int, contentType string, b []byte) error

func (*C) ContentDisposition

func (c *C) ContentDisposition(file, name, dispositionType string) error

func (*C) Context

func (c *C) Context() context.Context

func (*C) Cookie

func (c *C) Cookie(name string) (*http.Cookie, error)

func (*C) Cookies

func (c *C) Cookies() []*http.Cookie

func (*C) File

func (c *C) File(path string) error

func (*C) FormFile

func (c *C) FormFile(name string) (*multipart.FileHeader, error)

func (*C) FormParams

func (c *C) FormParams() (url.Values, error)

func (*C) FormValue

func (c *C) FormValue(name string) (string, error)

func (*C) FormValues

func (c *C) FormValues(name string) ([]string, error)

func (*C) HTML

func (c *C) HTML(statusCode int, html string) error

func (*C) Inline

func (c *C) Inline(file, name string) error

func (*C) JSON

func (c *C) JSON(statusCode int, i interface{}) error

func (*C) JSONBlob

func (c *C) JSONBlob(statusCode int, b []byte) error

func (*C) JSONPretty

func (c *C) JSONPretty(statusCode int, i interface{}, indent string) error

func (*C) Logger

func (c *C) Logger() zerolog.Logger

func (*C) MultipartForm

func (c *C) MultipartForm() (*multipart.Form, error)

func (*C) QueryParam

func (c *C) QueryParam(name string) string

func (*C) QueryParams

func (c *C) QueryParams() url.Values

func (*C) QueryString

func (c *C) QueryString() string

func (*C) Render

func (c *C) Render(statusCode int, name string, data interface{}) error

func (*C) SetCookie

func (c *C) SetCookie(cookie *http.Cookie)

func (*C) Stream

func (c *C) Stream(statusCode int, contentType string, r io.Reader) error

func (*C) String

func (c *C) String(statusCode int, s string) error

func (*C) URLParam

func (c *C) URLParam(name string) string

type Error

type Error struct {
	ErrorCode  string
	StatusCode int
	Message    string
}

type ErrorHandler

type ErrorHandler interface {
	HandleError(c *C, err *Error)
}

type HTTPError

type HTTPError interface {
	error
	Code() string
	StatusCode() int
	ReportTargets() []ReportTarget
}

func NewMsgHTTPError

func NewMsgHTTPError(msg string) HTTPError

func NewStatusCodeHTTPError

func NewStatusCodeHTTPError(statusCode int) HTTPError

type Handler

type Handler interface {
	ServeHTTP(c *C) error
}

type HandlerFunc

type HandlerFunc func(c *C) error

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(c *C) error

type Middleware

type Middleware interface {
	Apply(h Handler) Handler
}

type MiddlewareFunc

type MiddlewareFunc func(h Handler) Handler

func (MiddlewareFunc) Apply

func (m MiddlewareFunc) Apply(h Handler) Handler

type R

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

func (*R) Any

func (r *R) Any(pattern string, h Handler)

func (*R) Connect

func (r *R) Connect(pattern string, h Handler)

func (*R) Delete

func (r *R) Delete(pattern string, h Handler)

func (*R) Get

func (r *R) Get(pattern string, h Handler)

func (*R) Head

func (r *R) Head(pattern string, h Handler)

func (*R) Options

func (r *R) Options(pattern string, h Handler)

func (*R) Patch

func (r *R) Patch(pattern string, h Handler)

func (*R) Post

func (r *R) Post(pattern string, h Handler)

func (*R) Put

func (r *R) Put(pattern string, h Handler)

func (*R) SetErrorHandler

func (r *R) SetErrorHandler(errHandler ErrorHandler)

func (*R) SubRouter

func (r *R) SubRouter(pattern string, sr *R)

func (*R) Trace

func (r *R) Trace(pattern string, h Handler)

func (*R) Use

func (r *R) Use(middlewares ...Middleware)

type ReportTarget

type ReportTarget uint8
const (
	LogReportTarget ReportTarget = iota
	UserReportTarget
)

type TemplateRenderer

type TemplateRenderer interface {
	Render(c *C, w io.Writer, name string, data interface{}) error
}

TemplateRenderer is an interface implemented by template engines.

Jump to

Keyboard shortcuts

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