Goril

package module
v0.0.0-...-56332da Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

Goril

A Small Go Web Framework for IoT and Cloud Projects

Fetures

  • Written in 800 lines
  • Fast
  • Powerful
  • Supports GET,POST
  • Supports HTTP and HTTPS

Install

go get github.com/KaspiElectronics/Goril

Create your first app

package main

import "Goril"

func main() {
    app := Goril.New()
    app.Get("/", func(ctx *Goril.Context){
        ctx.Body = []byte("Hello Goril !")
    })
    app.Run()
}

default runs on localhost:9001

About

Copyright (c) 2021 KaspiElectronics,
all rights reserved.

Documentation

Index

Constants

View Source
const (
	ROUTER_METHOD_GET    = "GET"
	ROUTER_METHOD_POST   = "POST"
	ROUTER_METHOD_PUT    = "PUT"
	ROUTER_METHOD_DELETE = "DELETE"
)

--------------------------Router----------------------

View Source
const (
	CONTEXT_RENDERED = "context_rendered"
	CONTEXT_END      = "context_end"
	CONTEXT_SEND     = "context_send"
)

-----------------------Context------------------------

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

---------------------------App------------------------

func New

func New() *App

func (*App) Config

func (app *App) Config() *Config

func (*App) Delete

func (app *App) Delete(key string, fn ...Handler)

func (*App) Get

func (app *App) Get(key string, fn ...Handler) string

func (*App) NotFound

func (app *App) NotFound(h Handler)

func (*App) Post

func (app *App) Post(key string, fn ...Handler)

func (*App) Put

func (app *App) Put(key string, fn ...Handler)

func (*App) Recover

func (app *App) Recover(h Handler)

func (*App) Route

func (app *App) Route(method string, key string, fn ...Handler)

Support GET,POST,PUT and DELETE methods. usage : app.Route("GET,POST","/test",handler)

func (*App) Run

func (app *App) Run()

func (*App) ServeHTTP

func (app *App) ServeHTTP(res http.ResponseWriter, req *http.Request)

func (*App) Set

func (app *App) Set(key string, v interface{})

func (*App) Static

func (app *App) Static(h Handler)

func (*App) Use

func (app *App) Use(h ...Handler)

func (*App) View

func (app *App) View() *View

type Config

type Config map[string]map[string]interface{}

--------------------Config-----------------------------

func NewConfig

func NewConfig(fileAbsPath string) (*Config, error)

func (*Config) Bool

func (cfg *Config) Bool(key string) bool

func (*Config) Float

func (cfg *Config) Float(key string) float64

func (*Config) FloatOr

func (cfg *Config) FloatOr(key string, def float64) float64

func (*Config) Int

func (cfg *Config) Int(key string) int

func (*Config) IntOr

func (cfg *Config) IntOr(key string, def int) int

func (*Config) Set

func (cfg *Config) Set(key string, value interface{})

func (*Config) String

func (cfg *Config) String(key string) string

func (*Config) StringOr

func (cfg *Config) StringOr(key string, def string) string

type Context

type Context struct {
	Request    *http.Request
	Base       string
	Url        string
	RequestUrl string
	Method     string
	Ip         string
	UserAgent  string
	Referer    string
	Host       string
	Ext        string
	IsSSL      bool
	IsAjax     bool

	Response http.ResponseWriter
	Status   int
	Header   map[string]string
	Body     []byte

	IsSend bool
	IsEnd  bool
	// contains filtered or unexported fields
}

func NewContext

func NewContext(app *App, res http.ResponseWriter, req *http.Request) *Context

func (*Context) App

func (ctx *Context) App() *App

func (*Context) Bool

func (ctx *Context) Bool(key string) bool

func (*Context) ContentType

func (ctx *Context) ContentType(contentType string)

func (*Context) Cookie

func (ctx *Context) Cookie(key string, value ...string) string

func (*Context) Do

func (ctx *Context) Do(e string, args ...interface{}) [][]interface{}

func (*Context) Download

func (ctx *Context) Download(file string)

func (*Context) End

func (ctx *Context) End()

func (*Context) Flash

func (ctx *Context) Flash(key string, v ...interface{}) interface{}

func (*Context) Float

func (ctx *Context) Float(key string) float64

func (*Context) FloatOr

func (ctx *Context) FloatOr(key string, def float64) float64

func (*Context) Func

func (ctx *Context) Func(name string, fn interface{})

func (*Context) GetHeader

func (ctx *Context) GetHeader(key string) string

func (*Context) Input

func (ctx *Context) Input() map[string]string

func (*Context) Int

func (ctx *Context) Int(key string) int

func (*Context) IntOr

func (ctx *Context) IntOr(key string, def int) int

func (*Context) Json

func (ctx *Context) Json(data interface{})

func (*Context) Layout

func (ctx *Context) Layout(str string)

func (*Context) On

func (ctx *Context) On(e string, fn interface{})

func (*Context) Param

func (ctx *Context) Param(key string) string

func (*Context) Redirect

func (ctx *Context) Redirect(url string, status ...int)

func (*Context) Render

func (ctx *Context) Render(tpl string, data map[string]interface{})

func (*Context) Send

func (ctx *Context) Send()

func (*Context) String

func (ctx *Context) String(key string) string

func (*Context) StringOr

func (ctx *Context) StringOr(key string, def string) string

func (*Context) Strings

func (ctx *Context) Strings(key string) []string

func (*Context) Throw

func (ctx *Context) Throw(status int, message ...interface{})

func (*Context) Tpl

func (ctx *Context) Tpl(tpl string, data map[string]interface{}) string

type Handler

type Handler func(context *Context)

type Route

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

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) Delete

func (rt *Router) Delete(pattern string, fn ...Handler)

func (*Router) Find

func (rt *Router) Find(url string, method string) (params map[string]string, fn []Handler)

func (*Router) Get

func (rt *Router) Get(pattern string, fn ...Handler)

func (*Router) Post

func (rt *Router) Post(pattern string, fn ...Handler)

func (*Router) Put

func (rt *Router) Put(pattern string, fn ...Handler)

type View

type View struct {
	Dir     string
	FuncMap template.FuncMap
	IsCache bool
	// contains filtered or unexported fields
}

--------------------------View------------------------

func NewView

func NewView(dir string) *View

func (*View) Has

func (v *View) Has(tpl string) bool

func (*View) NoCache

func (v *View) NoCache()

func (*View) Render

func (v *View) Render(tpl string, data map[string]interface{}) ([]byte, error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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