gock

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

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChocoKacang

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

func (*ChocoKacang) AuthToken

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

func (*ChocoKacang) Cookie

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

func (*ChocoKacang) JSON

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

func (*ChocoKacang) Next

func (gock *ChocoKacang) Next()

func (*ChocoKacang) Render

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

func (*ChocoKacang) SetCookie

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

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) 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

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