beegoHelper

package module
v0.0.0-...-46ecaf1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2015 License: MIT Imports: 19 Imported by: 0

README

beegoHelper

创建beego控制器时候的一个辅助控制器,方便开发.

使用方法: 直接嵌入即可,即

import (
	"github.com/doomsplayer/beegoHelper"
)

type MainController struct {
	beegoHelper.Base
}

func (this *MainController) Get() {
	.........
}

内容包括: Parse 系列:

this.GetInts 函数, 返回一个[]int

this.ParseJson 直接将body当成一个json,parse到对象中。方便api交互(尤其是angular)

this.GetParamString, this.GetParamIntthis.Ctx.Input.Param() 的缩短版

this.ParseFormAndValid, 直接解析内容到结构体,并且按照valid的tag来验证struct,详细请查看beego文档form验证一节

this.ParseQuery, 实验函数,解析query直接返回一个orm的Cond

Paginator系列:分页器 使用以后会在url最后加一个?p=xxx表示页码

this.Paginator(每页几个元素,一共有几个元素) 生成一个分页器,方便数据库查询以及分页,有以下方法:

Pages() []int 返回页码数组

PageLink(page int) string 根据页码生成某一页的链接

PageLinkPrev() (link string)

PageLinkLast() (link string)

HasPrev() bool

HasNext() bool

IsActive(page int) bool

Offset() int

HasPages() bool

End() int

Auth系列:HTTPBaseAuth

CheckBaseAuth(cred string) bool cred是验证字符串,格式 用户名:密码 只要使用了这个函数会自动加载authorization的头.

Check,Ok 系列 to be continue

Documentation

Index

Constants

View Source
const DefaultClientCacheSize = 1000

Default values for ClientCacheSize and ClientCacheTolerance for DigestAuth

View Source
const DefaultClientCacheTolerance = 100

Variables

View Source
var DigestAuthor = NewDigestAuthenticator()

Functions

func DigestAuthParams

func DigestAuthParams(c *context.Context) map[string]string

Parse Authorization header from the http.Request. Returns a map of auth parameters or nil if the header is not a valid parsable Digest auth header.

func H

func H(data string) string

H function for MD5 algorithm (returns a lower-case hex MD5 digest)

func InfoPrepend

func InfoPrepend(s string) func(err error) string

func RandomKey

func RandomKey() string

Return a random 16-byte base64 alphabet string

Types

type Base

type Base struct {
	beego.Controller
}

func (*Base) CheckBasicAuth

func (this *Base) CheckBasicAuth(cred string, realm string) bool

func (*Base) CheckDigestAuth

func (this *Base) CheckDigestAuth(cred string, realm string) bool

func (*Base) CheckFlash

func (this *Base) CheckFlash(condition interface{}, mapping interface{}, to string)

func (*Base) CheckHtml

func (this *Base) CheckHtml(condition interface{}, code int, mapping interface{}, jmp ...string)

func (*Base) CheckJson

func (this *Base) CheckJson(condition interface{}, code int, mapping interface{})

func (*Base) GetInts

func (this *Base) GetInts(field string) []int

func (*Base) GetParamBool

func (this *Base) GetParamBool(field string) (bool, error)

func (*Base) GetParamInt

func (this *Base) GetParamInt(field string) (int, error)

func (*Base) GetParamString

func (this *Base) GetParamString(field string) string

func (*Base) NewPaginator

func (this *Base) NewPaginator(per, nums int) *Paginator

func (*Base) OkFlash

func (this *Base) OkFlash(info interface{}, to string)

func (*Base) OkHtml

func (this *Base) OkHtml(info interface{}, jmp ...string)

func (*Base) OkJson

func (this *Base) OkJson(info interface{})

func (*Base) ParseFormAndValid

func (this *Base) ParseFormAndValid(form interface{}) (err error)

func (*Base) ParseFormAndValidCheckJson

func (this *Base) ParseFormAndValidCheckJson(form interface{}, mapping interface{})

func (*Base) ParseJson

func (this *Base) ParseJson(obj interface{}) (err error)

func (*Base) ParseQuery

func (this *Base) ParseQuery(fields ...string) *orm.Condition

func (*Base) Prepare

func (b *Base) Prepare()

type DigestAuth

type DigestAuth struct {
	Opaque           string
	PlainTextSecrets bool

	/*
	   Approximate size of Client's Cache. When actual number of
	   tracked client nonces exceeds
	   ClientCacheSize+ClientCacheTolerance, ClientCacheTolerance*2
	   older entries are purged.
	*/
	ClientCacheSize      int
	ClientCacheTolerance int
	// contains filtered or unexported fields
}

func NewDigestAuthenticator

func NewDigestAuthenticator() *DigestAuth

func (*DigestAuth) AddHeader

func (a *DigestAuth) AddHeader(ctx *context.Context, realm string)

func (*DigestAuth) CheckAuth

func (da *DigestAuth) CheckAuth(ctx *context.Context, se SecretProvider, realm string) (username string, authinfo *string)

Check if request contains valid authentication data. Returns a pair of username, authinfo where username is the name of the authenticated user or an empty string and authinfo is the contents for the optional Authentication-Info response header.

func (*DigestAuth) Purge

func (a *DigestAuth) Purge(count int)

Remove count oldest entries from DigestAuth.clients

type ErrMap

type ErrMap map[error]string

type Paginator

type Paginator struct {
	Request     *http.Request
	PerPageNums int
	MaxPages    int
	// contains filtered or unexported fields
}

func NewPaginator

func NewPaginator(req *http.Request, per int, nums int) *Paginator

func (*Paginator) End

func (p *Paginator) End() int

func (*Paginator) HasNext

func (p *Paginator) HasNext() bool

func (*Paginator) HasPages

func (p *Paginator) HasPages() bool

func (*Paginator) HasPrev

func (p *Paginator) HasPrev() bool

func (*Paginator) IsActive

func (p *Paginator) IsActive(page int) bool

func (*Paginator) Nums

func (p *Paginator) Nums() int

func (*Paginator) Offset

func (p *Paginator) Offset() int

func (*Paginator) Page

func (p *Paginator) Page() int
func (p *Paginator) PageLink(page int) string

func (*Paginator) PageLinkFirst

func (p *Paginator) PageLinkFirst() (link string)

func (*Paginator) PageLinkLast

func (p *Paginator) PageLinkLast() (link string)

func (*Paginator) PageLinkNext

func (p *Paginator) PageLinkNext() (link string)

func (*Paginator) PageLinkPrev

func (p *Paginator) PageLinkPrev() (link string)

func (*Paginator) PageNums

func (p *Paginator) PageNums() int

func (*Paginator) Pages

func (p *Paginator) Pages() []int

func (*Paginator) SetNums

func (p *Paginator) SetNums(nums int)

type SecretProvider

type SecretProvider func(string, string) string

Jump to

Keyboard shortcuts

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