gock

package module
v0.0.0-...-4a34f05 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Default400Body = "Bad Request"
	Default403Body = "Forbidden"
	Default404Body = "Not Found"
	Default405Body = "Method Not Allowed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChocoKacang

type ChocoKacang struct {
	Config  config.Config
	Logger  *log.Logger
	DB      *Database
	Session any
	Request *http.Request
	Writer  Writer
	Params  Params
	// contains filtered or unexported fields
}

func (*ChocoKacang) AuthToken

func (gock *ChocoKacang) AuthToken() (token string)

func (*ChocoKacang) BadRequest

func (gock *ChocoKacang) BadRequest() Response

Return 400 response

func (*ChocoKacang) BindRequestBody

func (gock *ChocoKacang) BindRequestBody(contentType string, v any) (err error)

func (*ChocoKacang) Cookie

func (gock *ChocoKacang) Cookie(name string) (string, error)

Get cookie

func (*ChocoKacang) Header

func (gock *ChocoKacang) Header(key string) string

Get response header

func (*ChocoKacang) JSON

func (gock *ChocoKacang) JSON(code int, data any) Response

func (*ChocoKacang) MethodNotAllowed

func (gock *ChocoKacang) MethodNotAllowed() Response

Return 405 response

func (*ChocoKacang) Next

func (gock *ChocoKacang) Next()

func (*ChocoKacang) NotFound

func (gock *ChocoKacang) NotFound() Response

Return 404 response

func (*ChocoKacang) Render

func (gock *ChocoKacang) Render(code int, r render.Render) Response

func (*ChocoKacang) RequestMimeType

func (gock *ChocoKacang) RequestMimeType() string

Get request mime type

func (*ChocoKacang) Response

func (gock *ChocoKacang) Response(code int, data string) Response

Return response with requested mime type

func (*ChocoKacang) SetCookie

func (gock *ChocoKacang) SetCookie(cookie *http.Cookie)

Set cookie

func (*ChocoKacang) SetHeader

func (gock *ChocoKacang) SetHeader(key, value string)

Set response header

func (*ChocoKacang) Text

func (gock *ChocoKacang) Text(code int, format string, v ...any) Response

type CustomHandler

type CustomHandler func(serve *ChocoKacang, data Data) Response

type DB

type DB interface {
	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

type Data

type Data map[string]any

type Database

type Database struct {
	*sql.DB
	// contains filtered or unexported fields
}

func (*Database) Close

func (db *Database) Close() error

func (*Database) Cr

func (db *Database) Cr(name string) *sql.DB

type Handler

type Handler func(serve *ChocoKacang) Response

type Handlers

type Handlers []Handler

type Param

type Param struct {
	Name  string
	Value string
}

type Params

type Params []Param

func (Params) ByName

func (ps Params) ByName(name string) (value string)

func (Params) Get

func (ps Params) Get(name string) (string, bool)

type Pool

type Pool map[string]*sql.DB

type Response

type Response interface {
	Next()
}

type Route

type Route interface {
	Get(path string, handlers ...Handler)
}

Route defines all router register function

type RouteGroup

type RouteGroup interface {
	Route
	Group() *Router
}

RouteGroup defines all router register functin inclide grouping function

type Router

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

Router help framework to register route path, handlers and middlewares

func (*Router) Any

func (r *Router) Any(path string, handlers ...Handler)

Get adds route with any HTTP methods

func (*Router) Delete

func (r *Router) Delete(path string, handlers ...Handler)

Get adds route with DELETE HTTP method

func (*Router) Get

func (r *Router) Get(path string, handlers ...Handler)

Get adds route with GET HTTP method

func (*Router) Group

func (r *Router) Group(path string, handlers ...Handler) *Router

Grouping the router

func (*Router) Match

func (r *Router) Match(methods []string, path string, handlers ...Handler)

Get adds route with mathing HTTP method that already set.

func (*Router) Options

func (r *Router) Options(path string, handlers ...Handler)

Get adds route with OPTIONS HTTP method

func (*Router) Patch

func (r *Router) Patch(path string, handlers ...Handler)

Get adds route with Patch HTTP method

func (*Router) Post

func (r *Router) Post(path string, handlers ...Handler)

Get adds route with POST HTTP method

func (*Router) Put

func (r *Router) Put(path string, handlers ...Handler)

Get adds route with PUT HTTP method

func (*Router) Use

func (r *Router) Use(handlers ...Handler) Route

Use adds handlers or middlewares to the router

type Server

type Server struct {
	Router
	DB                  *Database
	Config              config.Config
	Logger              *log.Logger
	ServerErrorHandler  CustomHandler
	PageNotFoundHandler CustomHandler
	// contains filtered or unexported fields
}

Server is a framework instance contains configuration, router and logger instance. Create an instance of framework, by New()

func New

func New() *Server

New returns a framework instance without any middleware attached

func (*Server) Database

func (srv *Server) Database(name, driver, dsn string)

func (*Server) Handler

func (srv *Server) Handler() http.Handler

Handler returns http.Handler

func (*Server) Route

func (srv *Server) Route(method, path string, handlers ...Handler)

Route register new route path to the framework

func (*Server) Run

func (srv *Server) Run()

Run web server framework

func (*Server) ServeHTTP

func (srv *Server) ServeHTTP(rsw http.ResponseWriter, rq *http.Request)

ServeHTTP use for handle HTTP request from the clients

func (*Server) Use

func (srv *Server) Use(handlers ...Handler) Route

Use register global middleware

type Writer

type Writer interface {
	http.ResponseWriter
	Status() int
	Size() int
	Written() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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