fastgo

package module
v0.0.0-...-5baa266 Latest Latest
Warning

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

Go to latest
Published: May 24, 2018 License: MIT Imports: 17 Imported by: 0

README

logo

build godoc license go_Report release powered_by platforms

fastgo 是一个基于 fasthttp, fasthttprouter, fasthttpsession 搭建的快速的 Go Web 开发框架!

安装

要求是 Go 至少是 v1.7。

$ go get -u github.com/phachon/fastgo
$ go get ./...

使用

package main

import (
    "github.com/phachon/fastgo"
)


type AuthorController struct{
	fastgo.Controller
}

func (this *AuthorController) Index()  {
    
	this.ReturnJson(map[string]string{
		"data": "ok",
	})
}

func main() {
    author := &AuthorController{}
    fastgo.Route.GET("/author/index", author, "Index")

    fastgo.Run()
}

文档

文档地址: http://godoc.org/github.com/phachon/fastgo

示例

完整的 MVC 登录示例

组件

反馈

  • 如果您喜欢该项目,请 Start.
  • 如果在使用过程中有任何问题, 请提交 Issue.
  • 如果您发现并解决了bug,请提交 Pull Request.
  • 如果您想扩展 session 存储,欢迎 Fork and merge this rep.
  • 如果你想交个朋友,欢迎发邮件给 phachon@163.com.

License

MIT

Thanks

Create By phachon@163.com

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version = "v0.1"

	Conf = viper.New()

	Log = go_logger.NewLogger()

	AppPath = ""

	RootPath = ""

	ViewPath = ""

	StaticPath = ""

	TemplateSuffix = ".html"

	Session = fasthttpsession.NewSession(fasthttpsession.NewDefaultConfig())

	Route = NewRouter()
)

Functions

func ListenAndServe

func ListenAndServe(addr string, route *Router)

func Run

func Run()

func SetStaticPath

func SetStaticPath(static string)

func SetTemplateSuffix

func SetTemplateSuffix(suffix string)

func SetViewsPath

func SetViewsPath(view string)

Types

type Controller

type Controller struct {
	Ctx            *fasthttp.RequestCtx
	ControllerName string
	ActionName     string
	Data           map[string]interface{}
	Session        fasthttpsession.SessionStore
}

func NewController

func NewController() *Controller

func (*Controller) After

func (controller *Controller) After()

controller after

func (*Controller) Before

func (controller *Controller) Before()

controller before

func (*Controller) GetBool

func (controller *Controller) GetBool(key string) bool

get request ctx bool

func (*Controller) GetCookie

func (controller *Controller) GetCookie(key string) []byte

func (*Controller) GetCookieString

func (controller *Controller) GetCookieString(key string) string

func (*Controller) GetCtxFloat64

func (controller *Controller) GetCtxFloat64(key string, def float64) (float64, error)

get request content text float64

func (*Controller) GetFile

func (controller *Controller) GetFile(key string) (*multipart.FileHeader, error)

get form file by key

func (*Controller) GetInt

func (controller *Controller) GetInt(key string, def int) (int, error)

get request ctx int

func (*Controller) GetInt16

func (controller *Controller) GetInt16(key string, def int16) (int16, error)

get request ctx int16

func (*Controller) GetInt32

func (controller *Controller) GetInt32(key string, def int32) (int32, error)

get request ctx int32

func (*Controller) GetInt64

func (controller *Controller) GetInt64(key string, def int64) (int64, error)

get request ctx int64

func (*Controller) GetInt8

func (controller *Controller) GetInt8(key string, def int8) (int8, error)

get request ctx int8

func (*Controller) GetString

func (controller *Controller) GetString(key string, def string) string

get request ctx string

func (*Controller) GetUInt16

func (controller *Controller) GetUInt16(key string, def uint16) (uint16, error)

get request ctx uint16

func (*Controller) GetUInt32

func (controller *Controller) GetUInt32(key string, def uint32) (uint32, error)

get request ctx uint32

func (*Controller) GetUInt64

func (controller *Controller) GetUInt64(key string, def uint64) (uint64, error)

get request ctx uint64

func (*Controller) GetUInt8

func (controller *Controller) GetUInt8(key string, def uint8) (uint8, error)

get request ctx uint8

func (*Controller) Init

func (controller *Controller) Init(ctx *fasthttp.RequestCtx, controllerName string, actionName string)

init controller

func (*Controller) IsAjax

func (controller *Controller) IsAjax() bool

request is ajax

func (*Controller) LayoutRender

func (controller *Controller) LayoutRender(layout string, tpl string)

layout render view response

func (*Controller) Render

func (controller *Controller) Render(tpl string)

render view response

func (*Controller) ReturnError

func (controller *Controller) ReturnError(status int, message string)

return error

func (*Controller) ReturnJson

func (controller *Controller) ReturnJson(body interface{})

return json

func (*Controller) SetCookie

func (controller *Controller) SetCookie(name string, value string, others ...interface{})

func (*Controller) Static

func (controller *Controller) Static()

static file

func (*Controller) UserAgent

func (controller *Controller) UserAgent() string

type ControllerInterface

type ControllerInterface interface {
	Init(ctx *fasthttp.RequestCtx, controllerName string, actionName string)
	Before()
	After()
}

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) Add

func (r *Router) Add(requestMethod, path string, controller ControllerInterface, action string)

func (*Router) DELETE

func (r *Router) DELETE(path string, controller ControllerInterface, action string)

DELETE Request

func (*Router) GET

func (r *Router) GET(path string, controller ControllerInterface, action string)

GET Request

func (*Router) HEAD

func (r *Router) HEAD(path string, controller ControllerInterface, action string)

HEAD Request

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, controller ControllerInterface, action string)

OPTIONS Request

func (*Router) PATCH

func (r *Router) PATCH(path string, controller ControllerInterface, action string)

PATCH Request

func (*Router) POST

func (r *Router) POST(path string, controller ControllerInterface, action string)

POST Request

func (*Router) PUT

func (r *Router) PUT(path string, controller ControllerInterface, action string)

PUT Request

func (*Router) Request

func (r *Router) Request(requestMethod, path string, controller ControllerInterface, action string)

GET and POST

Directories

Path Synopsis
_example
mvc

Jump to

Keyboard shortcuts

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