flow

package module
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: MIT Imports: 22 Imported by: 2

README

flow

golang web frame as like koajs(洋葱圈模型)

安装

  • go get -u github.com/funswe/flow

示例1

func main() {
	flow.ALL("/hello", func(ctx *flow.Context) {
		ctx.Body("hello,world")
	})
	fmt.Println("启动...")
	log.Fatal(flow.Run())
}

启动程序,在浏览器里访问http://localhost:9505/hello,可以看到浏览器返回hello,world

示例2

func main() {
	flow.GET("/test/:name", func(ctx *flow.Context) {
		fmt.Println("name===", ctx.GetParam("name"))
		ctx.Json(map[string]interface{}{
			"name": ctx.GetParam("name"),
		})
	})
	flow.Use(func(ctx *flow.Context, next flow.Next) {
		fmt.Println("mid1->start,time==", time.Now().UnixNano())
		next()
		fmt.Println("mid1->end,time===", time.Now().UnixNano())
	})
	fmt.Println("启动...")
	log.Fatal(flow.Run())
}

启动程序,在浏览器里访问http://localhost:9505/test/hello,可以看到浏览器返回{"name":"hello"},终端打印

mid1->start,time== 1550045289462400763
name=== hello
mid1->end,time=== 1550045289462472332

示例3

type request struct {
	Age  int    `json:"age,string"`
	Name string `json:"name"`
}

func main() {
	flow.GET("/test/:name", func(ctx *flow.Context) {
       	req := &request{}
       	ctx.Parse(req)
       	ctx.Json(map[string]interface{}{
       		"name": req.Name,
       		"age":  req.Age,
       	})
    })
	fmt.Println("启动...")
	log.Fatal(flow.Run())
}

启动程序,在浏览器里访问http://localhost:9505/test/hello?age=30,可以看到浏览器返回{"age":30,"name":"hello"}

更多例子

模板

使用的HTML模板pongo2

Documentation

Index

Constants

View Source
const (
	HttpMethodGet     = "GET"
	HttpMethodHead    = "HEAD"
	HttpMethodOptions = "OPTIONS"
	HttpMethodPost    = "POST"
	HttpMethodPut     = "PUT"
	HttpMethodPatch   = "PATCH"
	HttpMethodDelete  = "DELETE"
)
View Source
const (
	HttpHeaderContentType             = "Content-Type"
	HttpHeaderContentLength           = "Content-Length"
	HttpHeaderTransferEncoding        = "Transfer-Encoding"
	HttpHeaderContentDisposition      = "Content-Disposition"
	HttpHeaderContentTransferEncoding = "Content-Transfer-Encoding"
	HttpHeaderExpires                 = "Expires"
	HttpHeaderCacheControl            = "Cache-Control"
	HttpHeaderEtag                    = "Etag"
	HttpHeaderXForwardedHost          = "X-Forwarded-Host"
	HttpHeaderXForwardedProto         = "X-Forwarded-Proto"
	HttpHeaderIfModifiedSince         = "If-Modified-Since"
	HttpHeaderIfNoneMatch             = "If-None-Match"
	HttpHeaderLastModified            = "Last-Modified"
	HttpHeaderXContentTypeOptions     = "X-Content-Type-Options"
	HttpHeaderXPoweredBy              = "X-Powered-By"
)

Variables

This section is empty.

Functions

func ALL added in v1.0.3

func ALL(path string, handler Handler)

func DELETE added in v1.0.3

func DELETE(path string, handler Handler)

func GET added in v1.0.3

func GET(path string, handler Handler)
func HEAD(path string, handler Handler)

func OPTIONS added in v1.0.3

func OPTIONS(path string, handler Handler)

func PATCH added in v1.0.3

func PATCH(path string, handler Handler)

func POST added in v1.0.3

func POST(path string, handler Handler)

func PUT added in v1.0.3

func PUT(path string, handler Handler)

func Run added in v1.0.3

func Run() error

func SetLoggerConfig added in v1.2.0

func SetLoggerConfig(loggerConfig *LoggerConfig)

func SetNotFoundHandle added in v1.0.3

func SetNotFoundHandle(nfh NotFoundHandle)

func SetOrmConfig added in v1.2.0

func SetOrmConfig(ormConfig *OrmConfig)

func SetPanicHandler added in v1.0.3

func SetPanicHandler(ph PanicHandler)

func SetServerConfig added in v1.2.0

func SetServerConfig(serverConfig *ServerConfig)

func Use added in v1.0.3

func Use(m Middleware)

Types

type Application

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

type Context

type Context struct {
	Logger *log.Logger

	Orm *Orm
	// contains filtered or unexported fields
}

func (*Context) Body

func (c *Context) Body(body string)

func (*Context) Download

func (c *Context) Download(filePath string)

func (*Context) GetApp added in v1.2.0

func (c *Context) GetApp() *Application

func (*Context) GetHeader

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

func (*Context) GetHeaders

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

func (*Context) GetHost

func (c *Context) GetHost() string

func (*Context) GetHostname

func (c *Context) GetHostname() string

func (*Context) GetHref

func (c *Context) GetHref() string

func (*Context) GetLength

func (c *Context) GetLength() int

func (*Context) GetMethod

func (c *Context) GetMethod() string

func (*Context) GetOrigin

func (c *Context) GetOrigin() string

func (*Context) GetParam

func (c *Context) GetParam(key string) (value string)

func (*Context) GetParamDefault

func (c *Context) GetParamDefault(key, defaultValue string) (value string)

func (*Context) GetProtocol

func (c *Context) GetProtocol() string

func (*Context) GetQuery

func (c *Context) GetQuery() url.Values

func (*Context) GetQuerystring

func (c *Context) GetQuerystring() string

func (*Context) GetStatusCode added in v1.0.8

func (c *Context) GetStatusCode() int

func (*Context) GetUri

func (c *Context) GetUri() string

func (*Context) GetUserAgent added in v1.0.2

func (c *Context) GetUserAgent() string

func (*Context) IsSecure

func (c *Context) IsSecure() bool

func (*Context) Json added in v1.0.2

func (c *Context) Json(data map[string]interface{})

func (*Context) Parse added in v1.0.2

func (c *Context) Parse(object interface{}) error

func (*Context) Redirect

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

func (*Context) Render added in v1.0.2

func (c *Context) Render(tmpFile string, data map[string]interface{})

func (*Context) SetHeader

func (c *Context) SetHeader(key, value string) *Context

func (*Context) SetLength

func (c *Context) SetLength(length int) *Context

func (*Context) SetStatus

func (c *Context) SetStatus(code int) *Context

type Handler

type Handler func(ctx *Context)

type LoggerConfig added in v1.2.0

type LoggerConfig struct {
	LoggerLevel string
	LoggerPath  string
}

type Middleware

type Middleware func(ctx *Context, next Next)

type Next

type Next func()

type NotFoundHandle added in v1.0.2

type NotFoundHandle func(w http.ResponseWriter, r *http.Request)

func (NotFoundHandle) ServeHTTP added in v1.0.2

func (f NotFoundHandle) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Orm added in v1.2.0

type Orm struct {
	Op *OrmOp
	// contains filtered or unexported fields
}

func (*Orm) Count added in v1.2.6

func (orm *Orm) Count(count *int64, fromTable *OrmFromTable, conditions map[string]interface{}) error

func (*Orm) DB added in v1.2.6

func (orm *Orm) DB() *gorm.DB

func (*Orm) Query added in v1.2.6

func (orm *Orm) Query(dest interface{}, fields []*OrmColumn, fromTable *OrmFromTable, conditions map[string]interface{}, orderBy []*OrmOrderBy, limit *OrmLimit, groupBy *OrmGroupBy) error

type OrmColumn added in v1.2.6

type OrmColumn struct {
	Table  string
	Column string
	Alias  string
}

type OrmConfig added in v1.2.0

type OrmConfig struct {
	Enable   bool
	UserName string
	Password string
	DbName   string
	Host     string
	Port     int
	Pool     *OrmPool
}

type OrmFromTable added in v1.2.6

type OrmFromTable struct {
	Table string
	Alias string
	Joins []*OrmJoin
}

type OrmGroupBy added in v1.2.6

type OrmGroupBy struct {
	Columns []*OrmColumn
	Having  []*OrmWhere
}

type OrmJoin added in v1.2.6

type OrmJoin struct {
	Type  string
	Table string
	Alias string
	ON    []*OrmWhere
}

type OrmLimit added in v1.2.6

type OrmLimit struct {
	Limit  int
	Offset int
}

type OrmOp added in v1.2.6

type OrmOp struct {
	Eq   string
	Gt   string
	Gte  string
	Lt   string
	Lte  string
	IN   string
	Like string
	Or   string
}

type OrmOrderBy added in v1.2.6

type OrmOrderBy struct {
	Column *OrmColumn
	Desc   bool
}

type OrmPool added in v1.2.0

type OrmPool struct {
	MaxIdle         int
	MaxOpen         int
	ConnMaxLifeTime int64
	ConnMaxIdleTime int64
}

type OrmWhere added in v1.2.6

type OrmWhere struct {
	Column *OrmColumn
	Opt    string
	// contains filtered or unexported fields
}

type PanicHandler added in v1.0.2

type PanicHandler func(http.ResponseWriter, *http.Request, interface{})

type ServerConfig added in v1.2.0

type ServerConfig struct {
	AppName    string
	Proxy      bool
	Host       string
	Port       int
	ViewPath   string
	StaticPath string
}

Directories

Path Synopsis
utils

Jump to

Keyboard shortcuts

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