pine

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 30 Imported by: 24

README

pine

PineFramework 一个轻量级高性能GO语言开发框架. 支持mvc, di, 动态返回值, middleware 加载, 路由分组, 子域名路由注册管理. 大部分组件基于接口实现, 可以自行实现或定义组件.

动态返回值

此功能只能用于mvc模式, 根据方法自动兼容显示内容

  1. 如果没有返回值, 并且没有渲染过模板, 会自动调用模板渲染方法. 查找路径为 ControllerName/MethodName
  2. 如果返回inerface{} , 会自动打印部分能兼容的数据, 返回结果为字符串类型 text/html
  3. 如果返回一个非nil的错误, 会直接panic(不包括复合类型里的error)
  4. 如果返回 string,int 等类型,显示为text

di

(发现有些数据无法解析出来pkgPath, 现在只有类型名称)服务注册名称更为interface{}, 如果注册服务类型实例, 自动绑定字符串文件路径和pkgPath, controller自动解析参数是对比参数pkgPath,以确定是否为真实参数类型.

todo

  • session cache 组件重构
  • pprof组件迁移出框架

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON = "application/json; charset=utf-8"
	ContentTypeHTML = "text/html; charset=utf-8"
	ContentTypeText = "text/plain; charset=utf-8"
	ContentTypeXML  = "text/xml; charset=utf-8"
)
View Source
const ControllerSuffix = "Controller"
View Source
const Version = "dev 0.0.5"

Variables

View Source
var (
	DefaultErrTemplate = template.Must(template.New("ErrTemplate").Parse(`<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>{{.Code}} {{ .Message }}</title>
  <style>
    html {-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
    html, body {
      margin: 0;
      background-color: #fff;
      color: #636b6f;
      font-family: 'Open Sans', sans-serif;
      font-weight: 100;
      height: 80vh;
    }
    .container {
      align-items: center;
      display: flex;
      justify-content: center;
      position: relative;
      height: 85vh;
    }
    .content {
      text-align: center;
    }
    .title {
      font-size: 36px;
      font-weight: bold;
      padding: 20px;
    }
	.logo {
		text-align: left;
	}
	.footer {
		float:right;
		margin-right:10px;
	}
  </style>
  </head>
  <body>
    <div class="container">
      <div class="content">
        <div class="title">{{ .Code }} {{ .Message }} </div>
      </div>
    </div>
  </body>
</html>`))
)

Functions

func Logger

func Logger() logger.AbstractLogger

func Make

func Make(service interface{}, params ...interface{}) interface{}

func RegisterErrorCodeHandler

func RegisterErrorCodeHandler(status int, handler Handler)

func RegisterOnInterrupt

func RegisterOnInterrupt(handler func())

func RegisterViewEngine

func RegisterViewEngine(engine render.AbstractRenderer)

Types

type AbstractReadonlyConfiguration

type AbstractReadonlyConfiguration interface {
	GetServerName() string
	GetUseCookie() bool
	GetMaxMultipartMemory() int64
	GetAutoParseControllerResult() bool
	GetCookieTranscoder() cookie_transcoder.AbstractCookieTranscoder
}

type AbstractRouter

type AbstractRouter interface {
	AddRoute(method, path string, handle Handler, mws ...Handler)

	ANY(path string, handle Handler, mws ...Handler)
	GET(path string, handle Handler, mws ...Handler)
	POST(path string, handle Handler, mws ...Handler)
	HEAD(path string, handle Handler, mws ...Handler)
	OPTIONS(path string, handle Handler, mws ...Handler)
	PUT(path string, handle Handler, mws ...Handler)
	DELETE(path string, handle Handler, mws ...Handler)

	StaticFile(string, string, ...Handler)
	Static(string, string)
}

type Application

type Application struct {
	*Router

	ReadonlyConfiguration AbstractReadonlyConfiguration
	// contains filtered or unexported fields
}

func New

func New() *Application

func (*Application) Run

func (a *Application) Run(srv ServerHandler, opts ...Configurator)

func (*Application) SetNotFound

func (a *Application) SetNotFound(handler Handler)

func (*Application) SetRecoverHandler

func (a *Application) SetRecoverHandler(handler Handler)

type Configuration

type Configuration struct {
	CookieTranscoder cookie_transcoder.AbstractCookieTranscoder
	// contains filtered or unexported fields
}

func (*Configuration) GetAutoParseControllerResult

func (c *Configuration) GetAutoParseControllerResult() bool

func (*Configuration) GetCookieTranscoder

func (c *Configuration) GetCookieTranscoder() cookie_transcoder.AbstractCookieTranscoder

func (*Configuration) GetMaxMultipartMemory

func (c *Configuration) GetMaxMultipartMemory() int64

func (*Configuration) GetServerName

func (c *Configuration) GetServerName() string

func (*Configuration) GetUseCookie added in v0.0.4

func (c *Configuration) GetUseCookie() bool

type Configurator

type Configurator func(o *Configuration)

func WithAutoParseControllerResult

func WithAutoParseControllerResult(auto bool) Configurator

func WithCookie added in v0.0.4

func WithCookie(open bool) Configurator

func WithMaxMultipartMemory

func WithMaxMultipartMemory(mem int64) Configurator

func WithServerName

func WithServerName(srvName string) Configurator

func WithoutStartupLog

func WithoutStartupLog(hide bool) Configurator

type Context

type Context struct {
	*fasthttp.RequestCtx

	// Temporary recording error information
	Msg string
	// contains filtered or unexported fields
}

func (*Context) Abort

func (c *Context) Abort(statusCode int, msg ...string)

func (*Context) BindForm

func (c *Context) BindForm(rev interface{}) error

func (*Context) BindJSON

func (c *Context) BindJSON(rev interface{}) error

func (*Context) ClientIP

func (c *Context) ClientIP() string

func (*Context) Files

func (c *Context) Files(key string) (*multipart.FileHeader, error)

func (*Context) FormValue

func (c *Context) FormValue(key string) string

func (*Context) GetBool

func (c *Context) GetBool(key string, defaultVal ...bool) (val bool, err error)

func (*Context) GetCookie

func (c *Context) GetCookie(name string) string

func (*Context) GetData

func (c *Context) GetData() map[string][]string

func (*Context) GetFloat64

func (c *Context) GetFloat64(key string, defaultVal ...float64) (val float64, err error)

func (*Context) GetInt

func (c *Context) GetInt(key string, defaultVal ...int) (val int, err error)

func (*Context) GetInt64

func (c *Context) GetInt64(key string, defaultVal ...int64) (val int64, err error)

func (*Context) GetString

func (c *Context) GetString(key string, defaultVal ...string) string

func (*Context) Handle

func (c *Context) Handle()

skip all middleware to exec handler

func (*Context) Header

func (c *Context) Header(key string) string

func (*Context) IsAjax

func (c *Context) IsAjax() bool

func (*Context) IsStopped

func (c *Context) IsStopped() bool

func (*Context) Logger

func (c *Context) Logger() logger.AbstractLogger

func (*Context) Next

func (c *Context) Next()

func (*Context) Params

func (c *Context) Params() params

func (*Context) Path added in v0.0.4

func (c *Context) Path() string

func (*Context) PostData

func (c *Context) PostData() map[string][]string

func (*Context) PostFloat64

func (c *Context) PostFloat64(key string, defaultVal ...float64) (val float64, err error)

func (*Context) PostInt

func (c *Context) PostInt(key string, defaultVal ...int) (val int, err error)

func (*Context) PostInt64

func (c *Context) PostInt64(key string, defaultVal ...int64) (val int64, err error)

func (*Context) PostString

func (c *Context) PostString(key string, defaultVal ...string) string

func (*Context) PostValue

func (c *Context) PostValue(key string) string

func (*Context) Redirect

func (c *Context) Redirect(url string, statusHeader ...int)

func (*Context) RemoveCookie

func (c *Context) RemoveCookie(name string)

func (*Context) Render

func (c *Context) Render() *Render

func (*Context) SendFile

func (c *Context) SendFile(filepath string)

func (*Context) Session

func (c *Context) Session() sessions.AbstractSession

func (*Context) Set

func (c *Context) Set(key string, value interface{})

func (*Context) SetCookie

func (c *Context) SetCookie(name string, value string, maxAge int)

func (*Context) SetStatus

func (c *Context) SetStatus(statusCode int)

func (*Context) Stop

func (c *Context) Stop()

func (*Context) Value

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

func (*Context) Write added in v0.0.5

func (c *Context) Write(data []byte) error

func (*Context) WriteHTMLBytes added in v0.0.5

func (c *Context) WriteHTMLBytes(data []byte) error

func (*Context) WriteJSON added in v0.0.5

func (c *Context) WriteJSON(v interface{}) error

func (*Context) WriteString

func (c *Context) WriteString(str string) error

type Controller

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

func (*Controller) Ctx

func (c *Controller) Ctx() *Context

func (*Controller) Logger

func (c *Controller) Logger() logger.AbstractLogger

func (*Controller) Render

func (c *Controller) Render() *Render

func (*Controller) Session

func (c *Controller) Session() sessions.AbstractSession

func (*Controller) View

func (c *Controller) View(name string)

func (*Controller) ViewData

func (c *Controller) ViewData(key string, val interface{})

type H

type H map[string]interface{}

type Handler

type Handler func(ctx *Context)

type IController

type IController interface {
	Ctx() *Context

	Render() *Render

	Logger() logger.AbstractLogger
	Session() sessions.AbstractSession
}

type IRegisterHandler

type IRegisterHandler interface {
	RegisterRoute(IRouterWrapper)
}

type IRouterWrapper

type IRouterWrapper interface {
	ANY(path string, handle string, mws ...Handler)
	GET(path string, handle string, mws ...Handler)
	POST(path string, handle string, mws ...Handler)
	PUT(path string, handle string, mws ...Handler)
	HEAD(path string, handle string, mws ...Handler)
	DELETE(path string, handle string, mws ...Handler)
	OPTIONS(path string, handle string, mws ...Handler)
	// contains filtered or unexported methods
}

type Pool

type Pool struct {
	sync.Pool
}

func NewPool

func NewPool(builder func() interface{}) *Pool

func (*Pool) Acquire

func (p *Pool) Acquire() interface{}

func (*Pool) Release

func (p *Pool) Release(val interface{})

type Render

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

func (*Render) Bytes

func (c *Render) Bytes(v []byte) error

func (*Render) ContentType

func (c *Render) ContentType(typ string)

func (*Render) GetEngine

func (c *Render) GetEngine(ext string) render.AbstractRenderer

func (*Render) GetViewData

func (c *Render) GetViewData() map[string]interface{}

func (*Render) HTML

func (c *Render) HTML(viewPath string)

func (*Render) JSON

func (c *Render) JSON(v interface{}) error

func (*Render) JSONP

func (c *Render) JSONP(callback string, v interface{}) error

func (*Render) Text

func (c *Render) Text(v string) error

func (*Render) ViewData

func (c *Render) ViewData(key string, val interface{})

func (*Render) XML

func (c *Render) XML(v interface{}) error

type RouteEntry

type RouteEntry struct {
	Method            string
	Middleware        []Handler
	ExtendsMiddleWare []Handler
	Handle            Handler

	Param   []string
	Pattern string
	// contains filtered or unexported fields
}

type Router

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

func (*Router) ANY

func (r *Router) ANY(path string, handle Handler, mws ...Handler)

func (*Router) AddRoute

func (r *Router) AddRoute(method, path string, handle Handler, mws ...Handler)

func (*Router) DELETE

func (r *Router) DELETE(path string, handle Handler, mws ...Handler)

func (*Router) GET

func (r *Router) GET(path string, handle Handler, mws ...Handler)

func (*Router) Group

func (r *Router) Group(prefix string, middleWares ...Handler) *Router

func (*Router) HEAD

func (r *Router) HEAD(path string, handle Handler, mws ...Handler)

func (*Router) Handle

func (r *Router) Handle(c IController) *Router

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, handle Handler, mws ...Handler)

func (*Router) POST

func (r *Router) POST(path string, handle Handler, mws ...Handler)

func (*Router) PUT

func (r *Router) PUT(path string, handle Handler, mws ...Handler)

func (*Router) Static

func (r *Router) Static(urlPath, dir string)

注意: 会走全局中间件

func (*Router) StaticFile

func (r *Router) StaticFile(path, file string, mws ...Handler)

func (*Router) Subdomain

func (r *Router) Subdomain(subdomain string) *Router

func (*Router) Use

func (r *Router) Use(middleWares ...Handler)

type ServerHandler

type ServerHandler func(*Application) error

func Addr

func Addr(addr string) ServerHandler

Jump to

Keyboard shortcuts

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