Documentation ¶
Overview ¶
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 ¶
- Constants
- type Banjo
- func (banjo Banjo) Delete(url string, closure func(ctx *Context))
- func (banjo Banjo) Get(url string, closure func(ctx *Context))
- func (banjo Banjo) Head(url string, closure func(ctx *Context))
- func (banjo Banjo) Options(url string, closure func(ctx *Context))
- func (banjo Banjo) Patch(url string, closure func(ctx *Context))
- func (banjo Banjo) Post(url string, closure func(ctx *Context))
- func (banjo Banjo) Put(url string, closure func(ctx *Context))
- func (banjo Banjo) Run()
- type Config
- type Context
- type Logger
- type M
- type Parser
- type Request
- type Response
- type Routes
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
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Banjo ¶
type Banjo struct {
// contains filtered or unexported fields
}
Banjo struct Main package Struct
func Create ¶
Create Constructor:
Initialize Banjo instance ¶
Params: - config {Config} Banjo configuration
Response: - banjo {Banjo} Banjo configuration
func (Banjo) Delete ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
type Config struct {
// contains filtered or unexported fields
}
Config struct
Allows you to create configuration to your banjo application
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig function
Returns default configurations for Banjo application
Params: - None
Response: - config {Config} Config struct
type Context ¶
Context struct
For easy cooperate with Requests & Response in action flow
func (*Context) HTML ¶
HTML function
Prepared Headers to return HTML page ¶
Params: - data {string} HTML content
Response: - None
func (*Context) JSON ¶
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 ¶
RedirectTo function
Allows you to redirect to another page ¶
Params: - url {string} path to redirect
Response: - None
type Logger ¶
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 ¶
func CreateLogger() Logger
CreateLogger function
Returns Logger with default filePath
func (Logger) Critical ¶
Critical function
Log message with log level CRITICAL ¶
Params: - message {string}
Response: - None
func (Logger) Error ¶
Error function
Log message with log level ERROR ¶
Params: - message {string}
Response: - None
type Parser ¶
type Parser struct{}
Parser struct
Used for easy access to ParserIntr functions, this is empty struct
type Request ¶
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 Routes ¶
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 ¶
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 ¶
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 ¶
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