irisx

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: MIT Imports: 30 Imported by: 0

README

irisx


Example

import (
	"github.com/RocksonZeta/irisx"
	"github.com/RocksonZeta/wrap/wraps"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/context"
)
func main() {
	app := iris.New()
	sidUidMap := make(map[string]int)
	sidUidMap["abc"] = 100
	irisx.CookieSid2Uid = func(sid string) interface{} {
		return sidUidMap[sid]
	}
	app.ContextPool.Attach(func() context.Context {
		return &irisx.Context{
			Context:  context.NewContext(app),
			PageSize: 20,
		}
	})
	app.Use(irisx.SidFilter)
	app.Get("/", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		c.Ok(c.Uid())
	})
	app.Get("/setuid", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		sidUidMap[c.Sid()] = 123
		c.Ok(c.Uid())
	})
	app.Get("/settoken", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		c.SetCookieToken("abc", 3600*24*10)
		c.Ok(c.Sid())
	})
	app.Get("/uid", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		c.Ok(c.Uid())
	})

	app.Listen(":9000")
}

Documentation

Index

Constants

View Source
const (
	RequestKeyParamErrors = "ParamErrors"
	RequestKeyScripts     = "Scripts"
)
View Source
const (
	TypeCastError = 1 + iota
)

Variables

This section is empty.

Functions

func ComputePages

func ComputePages(current int, totalPage int64) []int

func Enhance

func Enhance(app *view.HTMLEngine)

Enhance Template

func GetPageUrl

func GetPageUrl(url string, index, pageCount int, siName string) string

func Index

func Index(arr, value interface{}) int

func Page

func Page(ctx *Context, ps int, total int64, showTotal bool, classes string) string

func ParseTimeLocal

func ParseTimeLocal(format, date string) (time.Time, error)

func Render

func Render(app iris.Party, path string, html string, param ...interface{})

param: can be struct or map[string]interface{}

func Rewrite

func Rewrite(app iris.Party, from string, to string, statusCode ...int)

func SendHtml

func SendHtml(app iris.Party, path string, html string) error

func SidFilter added in v0.0.2

func SidFilter(ctx iris.Context)

Types

type Context

type Context struct {
	context.Context
	BeforeView      func(ctx *Context, tplFile string)
	SessionProvider SessionProvider
}

type H map[string]interface{}

func (*Context) AddParamError

func (ctx *Context) AddParamError(key, msg string)

func (*Context) AddScript

func (ctx *Context) AddScript(js string) string

func (*Context) AppendViewData

func (ctx *Context) AppendViewData(key string, values ...string)

func (*Context) CheckBody

func (ctx *Context) CheckBody(field string) *Validator

func (*Context) CheckBodyValues

func (ctx *Context) CheckBodyValues(field string) *ValidatorValues

func (*Context) CheckFile

func (ctx *Context) CheckFile(field string) *ValidatorFile

func (*Context) CheckPath

func (ctx *Context) CheckPath(field string) *Validator

func (*Context) CheckQuery

func (ctx *Context) CheckQuery(field string) *Validator

func (*Context) Css

func (ctx *Context) Css(css ...string)

func (*Context) Do

func (ctx *Context) Do(handlers context.Handlers)

func (*Context) Err

func (ctx *Context) Err(status int, data interface{})
func (ctx *Context) Fail() {
	ctx.JSON(ctx.Error)
}

func (*Context) GetUid added in v0.0.3

func (ctx *Context) GetUid(uid interface{}) error

func (*Context) GetUidInt added in v0.0.3

func (ctx *Context) GetUidInt() int

func (*Context) GetUidInt64 added in v0.0.3

func (ctx *Context) GetUidInt64() int64

func (*Context) GetUidString added in v0.0.3

func (ctx *Context) GetUidString() string

func (*Context) HasSignin added in v0.0.2

func (ctx *Context) HasSignin() bool

func (*Context) Js

func (ctx *Context) Js(js ...string) string

func (*Context) Next

func (ctx *Context) Next()

func (*Context) Ok

func (ctx *Context) Ok(data interface{})

func (*Context) ParamErrors

func (ctx *Context) ParamErrors() map[string]string

func (*Context) PathIndex

func (ctx *Context) PathIndex(i int) string

func (*Context) PathLeft

func (ctx *Context) PathLeft(count int) string

func (*Context) PathMatch

func (ctx *Context) PathMatch(pattern string) bool

func (*Context) PathMid

func (ctx *Context) PathMid(start, length int) string

func (*Context) PathParent

func (ctx *Context) PathParent() string

func (*Context) PathRight

func (ctx *Context) PathRight(count int) string

func (*Context) ProxyPass

func (ctx *Context) ProxyPass(proxy, path string) error

func (*Context) QueryString

func (ctx *Context) QueryString() string

func (*Context) ReadValidate

func (ctx *Context) ReadValidate(form interface{}) bool

func (*Context) Redirect

func (ctx *Context) Redirect(urlToRedirect string, statusHeader ...int)

func (*Context) RedirectSignin

func (ctx *Context) RedirectSignin(signinUrl string, needRedirectFrom bool)

func (*Context) RedirectWithFrom

func (ctx *Context) RedirectWithFrom(uri string)

func (*Context) RemoveCookieLocal

func (ctx *Context) RemoveCookieLocal(key string)

func (*Context) Scripts

func (ctx *Context) Scripts() []string

func (*Context) SetCookieLocal

func (ctx *Context) SetCookieLocal(key, value string, maxAge int, httpOnly bool, domain string)

func (*Context) SetUid added in v0.0.2

func (ctx *Context) SetUid(uid interface{}, secs int)

func (*Context) Sid added in v0.0.2

func (ctx *Context) Sid() string

func (*Context) Title

func (ctx *Context) Title(title string)

func (*Context) View

func (ctx *Context) View(filename string, optionalViewModel ...interface{}) error

type SessionProvider added in v0.0.3

type SessionProvider interface {
	GetSessionId(ctx *Context) string
	SetSessionId(ctx *Context)
	Set(key string, value interface{}, secs int) error
	Get(key string, result interface{}) error
	Refresh(key string, secs int) error
	Remove(key string) error
	UidKey() string
}

type Validator

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

func NewValidator

func NewValidator(ctx *Context, key string, value string, exists bool) *Validator

func (*Validator) Bool

func (v *Validator) Bool(dv bool, msg ...string) bool

func (*Validator) ByteLen

func (v *Validator) ByteLen(min, max int, msg ...string) *Validator

func (*Validator) Date

func (v *Validator) Date(dv time.Time, msg ...string) time.Time

func (*Validator) DateFormat

func (v *Validator) DateFormat(format string, dv time.Time, msg ...string) time.Time

func (*Validator) DateTime

func (v *Validator) DateTime(dv time.Time, msg ...string) time.Time

func (*Validator) DateTimeShort

func (v *Validator) DateTimeShort(dv time.Time, msg ...string) time.Time

func (*Validator) Empty

func (v *Validator) Empty(msg ...string) *Validator

func (*Validator) Ensure

func (v *Validator) Ensure(assertion, shouldBail bool, msg ...string) *Validator

func (*Validator) EnsureNot

func (v *Validator) EnsureNot(assertion, shouldBail bool, msg ...string) *Validator

func (*Validator) Exist

func (v *Validator) Exist(msg ...string) *Validator

func (*Validator) Float

func (v *Validator) Float(dv float64, msg ...string) float64

func (*Validator) Float32

func (v *Validator) Float32(dv float32, msg ...string) float32

func (*Validator) In

func (v *Validator) In(values []string, msg ...string) *Validator

func (*Validator) InInts

func (v *Validator) InInts(values []int, msg ...string) *Validator

func (*Validator) Int

func (v *Validator) Int(dv int, msg ...string) int

func (*Validator) Int64

func (v *Validator) Int64(dv int64, msg ...string) int64

func (*Validator) IsASCII

func (v *Validator) IsASCII(msg ...string) *Validator

func (*Validator) IsAlpha

func (v *Validator) IsAlpha(msg ...string) *Validator

func (*Validator) IsAlphanumeric

func (v *Validator) IsAlphanumeric(msg ...string) *Validator

func (*Validator) IsBool

func (v *Validator) IsBool(msg ...string) *Validator

func (*Validator) IsEmail

func (v *Validator) IsEmail(msg ...string) *Validator

func (*Validator) IsFilePath

func (v *Validator) IsFilePath(msg ...string) *Validator

func (*Validator) IsFloat

func (v *Validator) IsFloat(msg ...string) *Validator

func (*Validator) IsIP

func (v *Validator) IsIP(msg ...string) *Validator

func (*Validator) IsInt

func (v *Validator) IsInt(msg ...string) *Validator

func (*Validator) IsJSON

func (v *Validator) IsJSON(msg ...string) *Validator

func (*Validator) IsLowerCase

func (v *Validator) IsLowerCase(msg ...string) *Validator

func (*Validator) IsNumeric

func (v *Validator) IsNumeric(msg ...string) *Validator

func (*Validator) IsTime

func (v *Validator) IsTime(format string, msg ...string) *Validator

func (*Validator) IsUpperCase

func (v *Validator) IsUpperCase(msg ...string) *Validator

func (*Validator) IsUrl

func (v *Validator) IsUrl(msg ...string) *Validator

func (*Validator) Json

func (v *Validator) Json(r interface{}, msg ...string)

func (*Validator) Len

func (v *Validator) Len(min, max int, msg ...string) *Validator

func (*Validator) Match

func (v *Validator) Match(reg string, msg ...string) *Validator

func (*Validator) NotBlank

func (v *Validator) NotBlank(msg ...string) *Validator

func (*Validator) NotEmpty

func (v *Validator) NotEmpty(msg ...string) *Validator

func (*Validator) NotMatch

func (v *Validator) NotMatch(reg string, msg ...string) *Validator

func (*Validator) Optional

func (v *Validator) Optional() *Validator

func (*Validator) Present

func (v *Validator) Present() bool

func (*Validator) SanitizeHtml

func (v *Validator) SanitizeHtml() string

Int to int value

func (*Validator) String

func (v *Validator) String(dv ...string) string

Int to int value

func (*Validator) Time

func (v *Validator) Time(dv time.Time, msg ...string) time.Time

func (*Validator) TimeShort

func (v *Validator) TimeShort(dv time.Time, msg ...string) time.Time

func (*Validator) Trim

func (v *Validator) Trim() *Validator

type ValidatorFile

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

func NewValidatorFile

func NewValidatorFile(ctx *Context, key string, file multipart.File, header *multipart.FileHeader, exists bool) *ValidatorFile

func (*ValidatorFile) Copy

func (v *ValidatorFile) Copy(dstFile string)

func (*ValidatorFile) Empty

func (v *ValidatorFile) Empty(msg ...string) *ValidatorFile

func (*ValidatorFile) ExtIn

func (v *ValidatorFile) ExtIn(exts []string, msg ...string) *ValidatorFile

ExtIn exts {"jpg","png"}

func (*ValidatorFile) IsImage

func (v *ValidatorFile) IsImage(msg ...string) *ValidatorFile

func (*ValidatorFile) Len

func (v *ValidatorFile) Len(min, max int64, msg ...string) *ValidatorFile

func (*ValidatorFile) NotEmpty

func (v *ValidatorFile) NotEmpty(msg ...string) *ValidatorFile

func (*ValidatorFile) Optional

func (v *ValidatorFile) Optional() *ValidatorFile

type ValidatorValues

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

func NewValidatorValues

func NewValidatorValues(ctx *Context, key string, values []string, exists bool) *ValidatorValues

func (*ValidatorValues) Empty

func (v *ValidatorValues) Empty(msg ...string) *ValidatorValues

func (*ValidatorValues) Ensure

func (v *ValidatorValues) Ensure(assertion, shouldBail bool, msg ...string) *ValidatorValues

func (*ValidatorValues) EnsureNot

func (v *ValidatorValues) EnsureNot(assertion, shouldBail bool, msg ...string) *ValidatorValues

func (*ValidatorValues) Float32

func (v *ValidatorValues) Float32(dv []float32, msg ...string) []float32

func (*ValidatorValues) Floats

func (v *ValidatorValues) Floats(dv []float64, msg ...string) []float64

func (*ValidatorValues) Ints

func (v *ValidatorValues) Ints(dv []int, msg ...string) []int

func (*ValidatorValues) Len

func (v *ValidatorValues) Len(min, max int, msg ...string) *ValidatorValues

func (*ValidatorValues) Match

func (v *ValidatorValues) Match(reg string, msg ...string) *ValidatorValues

func (*ValidatorValues) NotEmpty

func (v *ValidatorValues) NotEmpty(msg ...string) *ValidatorValues

func (*ValidatorValues) NotMatch

func (v *ValidatorValues) NotMatch(reg string, msg ...string) *ValidatorValues

func (*ValidatorValues) Optional

func (v *ValidatorValues) Optional() *ValidatorValues

func (*ValidatorValues) Strings

func (v *ValidatorValues) Strings(dv []string, msg ...string) []string

Jump to

Keyboard shortcuts

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