kira

package module
v0.0.0-...-9f41b84 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: MIT Imports: 23 Imported by: 1

README

Kira

Minimal web framework.

Features | Installation | Getting Started | Examples | Docs
Build Status Code Coverage


Kira web framework. Simply a minimal web framework.

Features

  • Simplicity kira is simple. You will find yourself familiar with it quickly.
  • Fast simplicity comes with speed. Kira is super fast.

Installation

go get -u github.com/go-kira/kira

Getting Started

package main

import "github.com/go-kira/kira"

func main() {
    app := kira.New()

    app.Get("/", func (c *kira.Context) {
        c.String("Hello, Kira :)")
    })

    app.Run()
}

License

MIT License

Copyright (c) 2019 Rachid Lafriakh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	KB = 1 << 10
	MB = 1 << 20
	GB = 1 << 30
)

some bytes :)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Routes      []*Route
	Middlewares []Middleware
	Router      *httprouter.Router
	Configs     *config.Config
	Env         string
	// Not found handler
	NotFoundHandler HandlerFunc
	// contains filtered or unexported fields
}

App hold the framework options

func New

func New() *App

New init the framework

func (*App) Delete

func (app *App) Delete(path string, ctx HandlerFunc, middlewares ...Middleware) *Route

Delete Handle DELETE requests.

func (*App) Get

func (app *App) Get(path string, ctx HandlerFunc, middlewares ...Middleware) *Route

Get Handle GET requests.

func (*App) GracefullyShutdown

func (app *App) GracefullyShutdown(server *http.Server)

GracefullyShutdown the server

func (*App) Group

func (app *App) Group(prefix string, group GroupFunc, mds ...Middleware)

Group adds a prefix to the given routes.

func (*App) Head

func (app *App) Head(path string, ctx HandlerFunc, middlewares ...Middleware) *Route

Head Handle HEAD requests.

func (*App) Middleware

func (app *App) Middleware(middlewares ...Middleware)

Middleware - add the middleware

func (*App) NotFound

func (app *App) NotFound(ctx HandlerFunc)

NotFound custom not found handler.

func (*App) Options

func (app *App) Options(path string, ctx HandlerFunc, middlewares ...Middleware) *Route

Options Handle OPTIONS requests.

func (*App) Patch

func (app *App) Patch(path string, ctx HandlerFunc, middlewares ...Middleware) *Route

Patch Handle PATCH requests.

func (*App) Post

func (app *App) Post(path string, ctx HandlerFunc, middlewares ...Middleware) *Route

Post Handle POST requests.

func (*App) Put

func (app *App) Put(path string, ctx HandlerFunc, middlewares ...Middleware) *Route

Put Handle PUT requests.

func (*App) RegisterRoutes

func (app *App) RegisterRoutes() *httprouter.Router

RegisterRoutes it's simply register the routes into the router.

func (*App) Run

func (app *App) Run(args ...interface{}) *App

Run the framework

func (*App) ServeFiles

func (app *App) ServeFiles(path string, root http.FileSystem)

ServeFiles serve files in the given root.

func (*App) StartServer

func (app *App) StartServer(server *http.Server)

StartServer - Start kira server

func (*App) StartTLSServer

func (app *App) StartTLSServer(server *http.Server)

StartTLSServer - start an TLS server provided by: Let's Encrypt. To generate keys:

  • openssl genrsa -out server.key 2048
  • openssl ecparam -genkey -name secp384r1 -out server.key
  • openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650

func (*App) Use

func (app *App) Use(middlewares ...Middleware)

Use is an alias of Middleware method.

type Context

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

Context ...

func (*Context) Config

func (c *Context) Config() *config.Config

Config gets the application configs.

func (*Context) DecodeJSON

func (c *Context) DecodeJSON(dst interface{}) error

DecodeJSON - convert json from request body to interface.

func (*Context) Env

func (c *Context) Env() string

Env gets the application environment.

func (*Context) Err

func (c *Context) Err(err error)

Err checks if the error not empty. It's will redirect the error to Error method if there an error.

func (*Context) Error

func (c *Context) Error(msg interface{})

Error stop the request with panic

func (*Context) File

func (c *Context) File(name string)

File send a file with the HTTP reply.

func (*Context) GetData

func (c *Context) GetData(key string) interface{}

GetData ...

func (*Context) HasData

func (c *Context) HasData(key string) bool

HasData ...

func (*Context) HasQuery

func (c *Context) HasQuery(key string) bool

HasQuery checks if the request has the given query.

func (*Context) JSON

func (c *Context) JSON(data interface{}, code ...int)

JSON - Send response as json.

func (*Context) Log

func (c *Context) Log() *log.Logger

Log gets the Log instance.

func (*Context) Param

func (c *Context) Param(param string) string

Param is an alias of var method.

func (*Context) ParseMultipartForm

func (c *Context) ParseMultipartForm() error

ParseMultipartForm pars

func (*Context) Query

func (c *Context) Query(param string) string

Query get request query value

func (*Context) Redirect

func (c *Context) Redirect(url string, code int)

Redirect replies to the request with a redirect to url,

func (*Context) Request

func (c *Context) Request() *http.Request

Request a Request represents an HTTP request received by a server.

func (*Context) RequestID

func (c *Context) RequestID() string

Code gets response status statusCode.

func (*Context) Response

func (c *Context) Response() http.ResponseWriter

Response is used by an HTTP handler to construct an HTTP response.

func (*Context) SetData

func (c *Context) SetData(key string, data interface{})

SetData ...

func (*Context) SetRequest

func (c *Context) SetRequest(r *http.Request)

SetRequest change the current request with the given one.

func (*Context) SetRequestID

func (c *Context) SetRequestID(id string)

Code sets response status statusCode.

func (*Context) SetResponse

func (c *Context) SetResponse(w http.ResponseWriter)

SetResponse change the current response with the given one.

func (*Context) SetStatusCode

func (c *Context) SetStatusCode(code int)

Code sets response status statusCode.

func (*Context) Status

func (c *Context) Status(code int)

Status send a specific status with the HTTP reply.

func (*Context) StatusCode

func (c *Context) StatusCode() int

Code gets response status statusCode.

func (*Context) View

func (c *Context) View(temps string, data ...interface{}) error

View send an html/template with an HTTP reply.

func (*Context) ViewExists

func (c *Context) ViewExists(tmp string) bool

ViewExists Validate if the view exists.

func (*Context) ViewToString

func (c *Context) ViewToString(temps string, data ...interface{}) (string, error)

ViewToString parse a template and return the parsed template as a string.

func (*Context) WantsJSON

func (c *Context) WantsJSON() bool

WantsJSON - validate if the request wants a json response.

func (*Context) Write

func (c *Context) Write(b []byte)

Write writes the slice of bytes as an HTTP reply.

func (*Context) WriteHTML

func (c *Context) WriteHTML(html string)

WriteHTML send content of html with the HTTP reply as an HTML content.

func (*Context) WriteStatus

func (c *Context) WriteStatus(code int)

WriteStatus Write HTTP header to the response and also write the status message to the body.

func (*Context) WriteString

func (c *Context) WriteString(s string)

WriteString writes the content of s to the request response.

func (*Context) WriteStringf

func (c *Context) WriteStringf(format string, a ...interface{})

WriteStringf formats according to a format specifier and writes the resulting to the request response.

type ErrorFrame

type ErrorFrame struct {
	File string `json:"file"`
	Func string `json:"func"`
	Line int    `json:"line"`
}

ErrorFrame ...

type ErrorJSON

type ErrorJSON struct {
	Message string       `json:"message"`
	Frames  []ErrorFrame `json:"frames,omitempty"`
}

ErrorJSON ...

type Group

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

Group represent routes group.

func (Group) Delete

func (g Group) Delete(path string, handler HandlerFunc, middlewares ...Middleware)

Delete is a shortcut for app.Delete with the group prefix.

func (Group) Get

func (g Group) Get(path string, handler HandlerFunc, middlewares ...Middleware)

Get is a shortcut for app.Get with the group prefix.

func (Group) Group

func (g Group) Group(prefix string, group GroupFunc, middlewares ...Middleware)

Group adds ap refix to another grouped routes.

func (Group) Head

func (g Group) Head(path string, handler HandlerFunc, middlewares ...Middleware)

Head is a shortcut for app.Head with the group prefix.

func (Group) Options

func (g Group) Options(path string, handler HandlerFunc, middlewares ...Middleware)

Options is a shortcut for app.Delete with the group prefix.

func (Group) Patch

func (g Group) Patch(path string, handler HandlerFunc, middlewares ...Middleware)

Patch is a shortcut for app.Patch with the group prefix.

func (Group) Post

func (g Group) Post(path string, handler HandlerFunc, middlewares ...Middleware)

Post is a shortcut for app.Post with the group prefix.

func (Group) Put

func (g Group) Put(path string, handler HandlerFunc, middlewares ...Middleware)

Put is a shortcut for app.Put with the group prefix.

func (Group) ServeFiles

func (g Group) ServeFiles(path string, root http.FileSystem)

ServeFiles is a shortcut for app.ServeFiles with the group prefix.

type GroupFunc

type GroupFunc func(Group)

GroupFunc represent Group function.

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc - Type to define context function

type Log

type Log struct{}

Log - log middleware

func NewLogger

func NewLogger() *Log

New ...

func (*Log) Middleware

func (l *Log) Middleware(ctx *Context, next HandlerFunc)

Middleware handler.

type Map

type Map map[string]interface{}

Map a type to represent map, this will be used alot in the internal statusCode.

type Middleware

type Middleware interface {
	// Name() string
	Middleware(*Context, HandlerFunc)
}

Middleware interface

type RequestID

type RequestID struct{}

RequestID struct

func NewRequestID

func NewRequestID() *RequestID

new instance of RequestID.

func (*RequestID) Middleware

func (rq *RequestID) Middleware(ctx *Context, next HandlerFunc)

Middleware handler.

type Route

type Route struct {
	Method      string
	Path        string
	HandlerFunc HandlerFunc
	Middlewares []Middleware
}

Route represent a route.

func (*Route) Middleware

func (r *Route) Middleware(midd ...Middleware)

Middleware add a middleware to the route.

func (*Route) Use

func (r *Route) Use(midd ...Middleware)

Use is an alias of Middleware method.

Directories

Path Synopsis
modules
log
Package log implements a simple logging package.
Package log implements a simple logging package.
middlewares/csrf
We will re-write this based on this resource: https://astaxie.gitbooks.io/build-web-application-with-golang/content/en/09.1.html
We will re-write this based on this resource: https://astaxie.gitbooks.io/build-web-application-with-golang/content/en/09.1.html

Jump to

Keyboard shortcuts

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