ksatriya

package module
v0.0.0-...-c9644f5 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: MIT Imports: 4 Imported by: 1

README

ksatriya

GoDoc wercker status

a tiny web application framework for Go

$ go get github.com/m0t0k1ch1/ksatriya

Example

ref. https://github.com/m0t0k1ch1/ksatriya-sample

package main

import (
	"fmt"
	"net/http"

	"github.com/m0t0k1ch1/ksatriya"
)

func Ping (ctx ksatriya.Ctx) {
	ctx.RenderText(http.StatusOK, "pong")
}

func main() {
	k := ksatriya.New()
	k.GET("/ping", Ping)
	k.Run(":8080")
}

Dependencies

Documentation

Index

Constants

View Source
const (
	RootPathDefault = "/static"
	RootDirDefault  = "static"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args struct {
	httprouter.Params
}

type Context

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

func (*Context) Arg

func (ctx *Context) Arg(name string) string

func (*Context) Args

func (ctx *Context) Args() Args

func (*Context) Finalize

func (ctx *Context) Finalize()

func (*Context) Param

func (ctx *Context) Param(name string) ([]string, bool)

func (*Context) ParamSingle

func (ctx *Context) ParamSingle(name string) string

func (*Context) Params

func (ctx *Context) Params() Params

func (*Context) Redirect

func (ctx *Context) Redirect(uri string)

func (*Context) RenderJSON

func (ctx *Context) RenderJSON(stat int, data interface{})

func (*Context) RenderText

func (ctx *Context) RenderText(stat int, text string)

func (*Context) Req

func (ctx *Context) Req() *Request

func (*Context) Res

func (ctx *Context) Res() *Response

func (*Context) View

func (ctx *Context) View() *View

func (*Context) WriteResponse

func (ctx *Context) WriteResponse(w http.ResponseWriter) error

type Controller

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

func NewController

func NewController() *Controller

func (*Controller) AddRoute

func (c *Controller) AddRoute(method, path string, hf HandlerFunc)

func (*Controller) DELETE

func (c *Controller) DELETE(path string, hf HandlerFunc)

func (*Controller) GET

func (c *Controller) GET(path string, hf HandlerFunc)

func (*Controller) PATCH

func (c *Controller) PATCH(path string, hf HandlerFunc)

func (*Controller) POST

func (c *Controller) POST(path string, hf HandlerFunc)

func (*Controller) PUT

func (c *Controller) PUT(path string, hf HandlerFunc)

func (*Controller) Routes

func (c *Controller) Routes() []*Handler

type Ctx

type Ctx interface {
	Req() *Request
	Res() *Response
	View() *View
	Args() Args
	Arg(string) string
	Params() Params
	Param(string) ([]string, bool)
	ParamSingle(string) string
	RenderText(int, string)
	RenderJSON(int, interface{})
	Redirect(string)
	WriteResponse(http.ResponseWriter) error
	Finalize()
}

func NewContext

func NewContext(w http.ResponseWriter, req *http.Request, args Args) Ctx

type CtxBuilder

type CtxBuilder func(w http.ResponseWriter, req *http.Request, args Args) Ctx

type Dispacher

type Dispacher interface {
	Routes() []*Handler
}

type Handler

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

func (*Handler) HandlerFunc

func (h *Handler) HandlerFunc() HandlerFunc

func (*Handler) Method

func (h *Handler) Method() string

func (*Handler) Path

func (h *Handler) Path() string

type HandlerFunc

type HandlerFunc func(Ctx)

type JSONRenderer

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

func NewJSONRenderer

func NewJSONRenderer(data interface{}) *JSONRenderer

func (*JSONRenderer) Render

func (r *JSONRenderer) Render() (string, error)

type Ksatriya

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

func New

func New() *Ksatriya

func (*Ksatriya) AddRoute

func (k *Ksatriya) AddRoute(method, path string, hf HandlerFunc)

func (*Ksatriya) DELETE

func (k *Ksatriya) DELETE(path string, hf HandlerFunc)

func (*Ksatriya) GET

func (k *Ksatriya) GET(path string, hf HandlerFunc)

func (*Ksatriya) PATCH

func (k *Ksatriya) PATCH(path string, hf HandlerFunc)

func (*Ksatriya) POST

func (k *Ksatriya) POST(path string, hf HandlerFunc)

func (*Ksatriya) PUT

func (k *Ksatriya) PUT(path string, hf HandlerFunc)

func (*Ksatriya) RegisterController

func (k *Ksatriya) RegisterController(d Dispacher)

func (*Ksatriya) Root

func (k *Ksatriya) Root() *Root

func (*Ksatriya) Router

func (k *Ksatriya) Router() *Router

func (*Ksatriya) Run

func (k *Ksatriya) Run(addr string)

func (*Ksatriya) ServeFiles

func (k *Ksatriya) ServeFiles()

func (*Ksatriya) ServeHTTP

func (k *Ksatriya) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Ksatriya) SetCtxBuilder

func (k *Ksatriya) SetCtxBuilder(f CtxBuilder)

type Params

type Params map[string][]string

type Renderer

type Renderer interface {
	Render() (string, error)
}

type Request

type Request struct {
	*http.Request
}

func NewRequest

func NewRequest(req *http.Request) *Request

func (*Request) BodyJSON

func (req *Request) BodyJSON(v interface{}) error

type Response

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

func NewResponse

func NewResponse() *Response

func (*Response) Body

func (res *Response) Body() string

func (*Response) Header

func (res *Response) Header() http.Header

func (*Response) SetBody

func (res *Response) SetBody(val string)

func (*Response) SetContentType

func (res *Response) SetContentType(val string)

func (*Response) SetHeader

func (res *Response) SetHeader(key, val string)

func (*Response) SetStatusCode

func (res *Response) SetStatusCode(val int)

func (*Response) StatusCode

func (res *Response) StatusCode() int

func (*Response) WriteBody

func (res *Response) WriteBody(w http.ResponseWriter)

func (*Response) WriteHeader

func (res *Response) WriteHeader(w http.ResponseWriter)

func (*Response) WriteHeaderAndBody

func (res *Response) WriteHeaderAndBody(w http.ResponseWriter)

type Root

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

func NewRoot

func NewRoot() *Root

func (*Root) Dir

func (root *Root) Dir() http.FileSystem

func (*Root) Path

func (root *Root) Path() string

func (*Root) SetDir

func (root *Root) SetDir(val string)

func (*Root) SetPath

func (root *Root) SetPath(val string)

type Router

type Router struct {
	*httprouter.Router
}

func NewRouter

func NewRouter() *Router

type TextRenderer

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

func NewTextRenderer

func NewTextRenderer(text string) *TextRenderer

func (*TextRenderer) Render

func (r *TextRenderer) Render() (string, error)

type View

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

func NewView

func NewView() *View

func (*View) Render

func (v *View) Render() (string, error)

func (*View) Renderer

func (v *View) Renderer() Renderer

func (*View) SetRenderer

func (v *View) SetRenderer(val Renderer)

Jump to

Keyboard shortcuts

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