httpapi

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInternalServerError = errors.New("internal server error")

	ErrInvalidPagination = errors.New("invalid pagination type")
	ErrInvalidPage       = errors.New("invalid page number")
	ErrInvalidLimit      = errors.New("invalid page limit")

	ErrInvalidQuery = errors.New("invalid query parameter")
)

Functions

func BadRequest

func BadRequest(ctx *fasthttp.RequestCtx, errResp error)

func InternalServerError

func InternalServerError(ctx *fasthttp.RequestCtx)

func NotFound

func NotFound(ctx *fasthttp.RequestCtx)

func Success

func Success(ctx *fasthttp.RequestCtx, result interface{})

func SuccessWithPagination

func SuccessWithPagination(
	ctx *fasthttp.RequestCtx,
	result interface{},
	paginationResult *pagination_interface.PaginationResult,
)

Types

type PagedResponse

type PagedResponse struct {
	Response

	OffsetPagination *PaginationOffsetResponse `json:"pagination,omitempty"`
}

type PaginationOffsetResponse

type PaginationOffsetResponse struct {
	TotalRecord int64 `json:"total_record"`
	TotalPage   int64 `json:"total_page"`
	CurrentPage int64 `json:"current_page"`
	Limit       int64 `json:"limit"`
}

func OptPaginationOffsetResponseFromResult

func OptPaginationOffsetResponseFromResult(
	offsetResult *pagination_interface.PaginationOffsetResult,
) *PaginationOffsetResponse

type QueryArgs

type QueryArgs struct {
	*fasthttp.Args
}

QueryArgs is a helper on top of fasthttp.QueryArgs

func NewQueryArgs

func NewQueryArgs(args *fasthttp.Args) *QueryArgs

func (*QueryArgs) Get

func (args *QueryArgs) Get(key string) string

Return the arguments by key, empty string if not exist

func (*QueryArgs) Has

func (args *QueryArgs) Has(key string) bool

type Response

type Response struct {
	Result interface{} `json:"result"`
	Err    string      `json:"error,omitempty"`
}

type Server

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

func NewServer

func NewServer(listeningAddress string) *Server

func (*Server) DELETE

func (server *Server) DELETE(path string, handler fasthttp.RequestHandler) *Server

func (*Server) GET

func (server *Server) GET(path string, handler fasthttp.RequestHandler) *Server

func (*Server) ListenAndServe

func (server *Server) ListenAndServe() error

func (*Server) PATCH

func (server *Server) PATCH(path string, handler fasthttp.RequestHandler) *Server

func (*Server) POST

func (server *Server) POST(path string, handler fasthttp.RequestHandler) *Server

func (*Server) PUT

func (server *Server) PUT(path string, handler fasthttp.RequestHandler) *Server

func (*Server) Use

func (server *Server) Use(middleware Middleware) *Server

func (*Server) WithCors

func (server *Server) WithCors(options cors.Options) *Server

func (*Server) WithLogger

func (server *Server) WithLogger(logger applogger.Logger) *Server

func (*Server) WithPanicHandler

func (server *Server) WithPanicHandler(handler func(ctx *fasthttp.RequestCtx, err interface{})) *Server

func (*Server) WithPprof

func (server *Server) WithPprof(path string) *Server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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