banjo: github.com/nsheremet/banjo Index | Files

package banjo

import "github.com/nsheremet/banjo"

Package banjo is main package file Banjo Package Allows you to create your own simple web application

See more in examples/example.go file

Index

Package Files

banjo.go config.go context.go logger.go parser.go routes.go

Constants

const DefaultHost = "127.0.0.1"

DefaultHost is default application host value

const DefaultPort = "4321"

DefaultPort is default application port value

const DubSeparator = "\r\n\r\n"

DubSeparator is a default duble separator in HTTP Requests

const HTTPVersion = "HTTP/1.1"

HTTPVersion it'a default HTTP version

const Separator = "\r\n"

Separator is a default separator in HTTP Requests

type Banjo Uses

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

Banjo struct Main package Struct

func Create Uses

func Create(config Config) Banjo

Create Constructor:

Initialize Banjo instance

Params: - config {Config} Banjo configuration

Response: - banjo {Banjo} Banjo configuration

func (Banjo) Delete Uses

func (banjo Banjo) Delete(url string, closure func(ctx *Context))

Delete function For handling DELETE Requests

Params: - url {string} HTTP Request URL - closure {func(r Request) Response} Closure for handling HTTP Request

Response: - None

func (Banjo) Get Uses

func (banjo Banjo) Get(url string, closure func(ctx *Context))

Get function For handling GET Requests

Params: - url {string} HTTP Request URL - closure {func(r Request) Response} Closure for handling HTTP Request

Response: - None

func (Banjo) Head Uses

func (banjo Banjo) Head(url string, closure func(ctx *Context))

Head function For handling HEAD Requests

Params: - url {string} HTTP Request URL - closure {func(r Request) Response} Closure for handling HTTP Request

Response: - None

func (Banjo) Options Uses

func (banjo Banjo) Options(url string, closure func(ctx *Context))

Options function For handling OPTIONS Requests

Params: - url {string} HTTP Request URL - closure {func(r Request) Response} Closure for handling HTTP Request

Response: - None

func (Banjo) Patch Uses

func (banjo Banjo) Patch(url string, closure func(ctx *Context))

Patch function For handling PATCH Requests

Params: - url {string} HTTP Request URL - closure {func(r Request) Response} Closure for handling HTTP Request

Response: - None

func (Banjo) Post Uses

func (banjo Banjo) Post(url string, closure func(ctx *Context))

Post function For handling POST Requests

Params: - url {string} HTTP Request URL - closure {func(r Request) Response} Closure for handling HTTP Request

Response: - None

func (Banjo) Put Uses

func (banjo Banjo) Put(url string, closure func(ctx *Context))

Put function For handling PUT Requests

Params: - url {string} HTTP Request URL - closure {func(r Request) Response} Closure for handling HTTP Request

Response: - None

func (Banjo) Run Uses

func (banjo Banjo) Run()

Run function

Application starts listening for the requests, Parse them and runs code save id routes fields as {map[string]func(r Request) Response} All closures should return Response, you can use banjo.JSON, banjo.HTML etc methods All return your own Response struct

This is last methods, that should called in the end of the application

Params: - None

Response: - None

type Config Uses

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

Config struct

Allows you to create configuration to your banjo application

func DefaultConfig Uses

func DefaultConfig() Config

DefaultConfig function

Returns default configurations for Banjo application

Params: - None

Response: - config {Config} Config struct

type Context Uses

type Context struct {
    Request  Request
    Response Response
}

Context struct

For easy cooperate with Requests & Response in action flow

func (*Context) HTML Uses

func (ctx *Context) HTML(data string)

HTML function

Prepared Headers to return HTML page

Params: - data {string} HTML content

Response: - None

func (*Context) InternalServerError Uses

func (ctx *Context) InternalServerError()

InternalServerError function

Modify Context struct with 500 Status error & Internal Server Error body

Params: - None

Response: - None

func (*Context) JSON Uses

func (ctx *Context) JSON(data map[string]interface{})

JSON function

This func allows you to easy returning a JSON response Example usage: app.JSON({"foo" : "bar"})

Params: - data {map[string]interface{}}

Response: - None

func (*Context) RedirectTo Uses

func (ctx *Context) RedirectTo(url string)

RedirectTo function

Allows you to redirect to another page

Params: - url {string} path to redirect

Response: - None

type Logger Uses

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

Logger struct

Provides logging with timestamps and different logging levels With saving all messages to log file

func CreateLogger Uses

func CreateLogger() Logger

CreateLogger function

Returns Logger with default filePath

func (Logger) Critical Uses

func (logger Logger) Critical(message string)

Critical function

Log message with log level CRITICAL

Params: - message {string}

Response: - None

func (Logger) Error Uses

func (logger Logger) Error(message string)

Error function

Log message with log level ERROR

Params: - message {string}

Response: - None

func (Logger) Info Uses

func (logger Logger) Info(message string)

Info function

Log message with log level INFO

Params: - message {string}

Response: - None

func (Logger) Warning Uses

func (logger Logger) Warning(message string)

Warning function

Log message with log level WARNING

Params: - message {string}

Response: - None

type M Uses

type M map[string]interface{}

M type is map[string]interface{} alias

type Parser Uses

type Parser struct{}

Parser struct

Used for easy access to ParserIntr functions, this is empty struct

func (Parser) Request Uses

func (p Parser) Request(rawData string) Request

Request function for parsing Raw HTTP Request to banjo.Request struct

Params: - data {string} Raw HTTP Request

Response: - request {banjo.Request}

func (Parser) Response Uses

func (p Parser) Response(data Response) string

Response prepared banjo.Response struct to Raw HTTP Response string

Params: - data {banjo.Response} prepared banjo.Response struct

Response: - response {string} Raw HTTP Response string

type Request Uses

type Request struct {
    Headers     map[string]string
    MapParams   map[string]string
    Files       []map[string]string
    Params      string
    Method      string
    URL         string
    HTTPVersion string
}

Request struct using for passing as parameter to callback functions.

type Response Uses

type Response struct {
    Headers map[string]string
    Body    string
    Status  int
}

Response struct Using as returned value for callback function

type Routes Uses

type Routes struct {
    GET     map[string]func(ctx *Context)
    POST    map[string]func(ctx *Context)
    PUT     map[string]func(ctx *Context)
    PATCH   map[string]func(ctx *Context)
    OPTIONS map[string]func(ctx *Context)
    HEAD    map[string]func(ctx *Context)
    DELETE  map[string]func(ctx *Context)
}

Routes struct

Used for storing users closures The struct have one map for each method table table type: map[string]func(ctx *Context)

func CreateRoutes Uses

func CreateRoutes() Routes

CreateRoutes function

Create Routes with empty method tables

Params: - None

Response: - routes {Routes} Routes struct with empty map fields

func (Routes) Block Uses

func (routes Routes) Block(method string, url string) func(ctx *Context)

Block function

Returns func(request Request) Response closure

Params: - method {string} HTTP Request Method - url {string} HTTP Request URL

Response: - closure {func(request Request) Response} Returns closure with user

func (Routes) Push Uses

func (routes Routes) Push(method string, url string, closure func(ctx *Context))

Push function

Adding new element to one of fields in Routes struct Element should be passed by url {string}, value type of {func(request Request) Response}

Params: - method {string} HTTP Request Method - url {string} HTTP Request URL - closure {func(request Request) Response}

Response: - None

Package banjo imports 10 packages (graph). Updated 2018-02-21. Refresh now. Tools for package owners.