gor

package module
v0.0.0-...-62155c2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2018 License: MIT Imports: 14 Imported by: 0

README

gor

Fast, minimalist web framework for Golang

CircleCI

package main

import (
	"fmt"
	"log"

	"github.com/Chyroc/gor"
)

func main() {
	app := gor.NewGor()

	app.Get("/", func(req *gor.Req, res *gor.Res) {
		res.Send("Hello World")
	})

	log.Fatal(app.Listen(":3000"))
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is not found error.
	ErrNotFound = errors.New("not found page")
	// ErrResponseTypeUnsupported is response type unsupported error.
	ErrResponseTypeUnsupported = errors.New("response type unsupported")
	// ErrJSONMarshal is json marshal error.
	ErrJSONMarshal = errors.New("json marshal err")
	// ErrHTTPStatusCodeInvalid is given http status code is invalid error.
	ErrHTTPStatusCodeInvalid = errors.New("http status code is invalid")
)

Functions

This section is empty.

Types

type Cookie struct {
	Path       string    // optional
	Domain     string    // optional
	Expires    time.Time // optional
	RawExpires string    // for reading cookies only

	// MaxAge=0 means no 'Max-Age' attribute specified.
	// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
	// MaxAge>0 means Max-Age attribute present and given in seconds
	MaxAge   int
	Secure   bool
	HTTPOnly bool
	Raw      string
	Unparsed []string // Raw text of unparsed attribute-value pairs
}

Cookie like http.Cookie but remove name and value

type Gor

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

Gor gor framework core struct

func NewGor

func NewGor() *Gor

NewGor return Gor struct

func (*Gor) Listen

func (g *Gor) Listen(addr string) error

Listen bind port and start server

func (*Gor) ServeHTTP

func (g *Gor) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP use to start server

func (*Gor) SetRenderDir

func (g *Gor) SetRenderDir(dir string)

SetRenderDir set rendir tmpl dir

func (*Gor) SetStaticPath

func (g *Gor) SetStaticPath(path string)

SetStaticPath set static url path start string

func (*Gor) Static

func (g *Gor) Static(dir string)

Static start static file server

type HandlerFunc

type HandlerFunc func(*Req, *Res)

HandlerFunc gor handler func like http.HandlerFunc func(ResponseWriter, *Request)

type HandlerFuncNext

type HandlerFuncNext func(*Req, *Res, Next)

HandlerFuncNext gor handler func like http.HandlerFunc func(ResponseWriter, *Request), but return HandlerFunc to do somrthing at defer time

type Middleware

type Middleware interface {
	// contains filtered or unexported methods
}

Middleware mid

type Next

type Next func(...string)

Next exec next handler or mid

type Req

type Req struct {
	Protocol string
	Secure   bool
	Method   string
	Query    map[string][]string
	Headers  map[string][]string
	Hostname string

	BaseURL     string
	OriginalURL string

	Params map[string]string
	Body   *bodyData
	// contains filtered or unexported fields
}

Req is http Request struct <scheme>://<username>:<password>@<host>:<port>/<path>;<parameters>?<query>#<fragment>

func (*Req) AddContext

func (req *Req) AddContext(key, val interface{})

AddContext add value to gor context

func (*Req) BindJSON

func (req *Req) BindJSON(v interface{}) error

BindJSON body to json

func (*Req) GetContext

func (req *Req) GetContext(key interface{}) interface{}

GetContext get context from gor by key

type Res

type Res struct {
	Response   interface{}
	StatusCode int
	// contains filtered or unexported fields
}

Res is http ResponseWriter and some gor Response method

func (*Res) AddHeader

func (res *Res) AddHeader(key, val string)

AddHeader append (key, val) to headers

func (*Res) End

func (res *Res) End()

End end the request

func (*Res) Error

func (res *Res) Error(v string)

Error send erroe Response

func (*Res) HTML

func (res *Res) HTML(v string, data interface{})

HTML render HTML

func (*Res) JSON

func (res *Res) JSON(v interface{})

JSON Send json Response

func (*Res) Redirect

func (res *Res) Redirect(path string)

Redirect Redirect to another url

func (*Res) Send

func (res *Res) Send(v interface{})

Send Send a Response

func (*Res) SendStatus

func (res *Res) SendStatus(code int)

SendStatus set Response http status code with its text

func (*Res) SetCookie

func (res *Res) SetCookie(key, val string, option ...Cookie)

SetCookie set cookie

func (*Res) Status

func (res *Res) Status(code int) *Res

Status set Response http status code

func (*Res) Write

func (res *Res) Write(data []byte) (int, error)

type Route

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

Route route

func NewRoute

func NewRoute() *Route

NewRoute return *Router

func (*Route) All

func (r *Route) All(hs ...interface{})

All http trace method

func (*Route) Connect

func (r *Route) Connect(pattern string, h HandlerFunc)

Connect http connect method

func (*Route) Delete

func (r *Route) Delete(pattern string, h HandlerFunc)

Delete http delete method

func (*Route) Get

func (r *Route) Get(pattern string, h HandlerFunc)

Get http get method

func (*Route) Group

func (r *Route) Group(pattern string, app func(group *Router))

Group like all but donnot new a router

func (*Route) Head

func (r *Route) Head(pattern string, h HandlerFunc)

Head http head method

func (*Route) Options

func (r *Route) Options(pattern string, h HandlerFunc)

Options http options method

func (*Route) Patch

func (r *Route) Patch(pattern string, h HandlerFunc)

Patch http patch method

func (*Route) Post

func (r *Route) Post(pattern string, h HandlerFunc)

Post http post method

func (*Route) Put

func (r *Route) Put(pattern string, h HandlerFunc)

Put http put method

func (*Route) Trace

func (r *Route) Trace(pattern string, h HandlerFunc)

Trace http trace method

func (*Route) Use

func (r *Route) Use(hs ...interface{})

Use http trace method

must belong one of below type string type HandlerFunc func(*Req, *Res) type HandlerFuncNext func(*Req, *Res, Next) type Middleware interface

type RouteInterface

type RouteInterface interface {
	Use(...interface{})
	All(...interface{})
	Group(string, func(group *Router))

	Middleware
	// contains filtered or unexported methods
}

RouteInterface define Route Interface

type Router

type Router struct {
	*Route
}

Router router

func NewRouter

func NewRouter() *Router

NewRouter return *Router

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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