web

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2018 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthType        = "AuthType"
	AuthTypeDefault = ""
	AuthTypeAnon    = "anon"
	AuthTypeJwt     = "jwt"

	BeforeMethod = "Before"
	AfterMethod  = "After"
)

Variables

This section is empty.

Functions

func Add

func Add(controllers ...interface{})

Add add controller to controllers container

func DefaultConfiguration added in v0.3.0

func DefaultConfiguration() iris.Configuration

DefaultConfiguration returns the default configuration for an iris station, fills the main Configuration

func InitJwt

func InitJwt(wd string) error

InitJwt init JWT, it read config/ssl/rsa and config/ssl/rsa.pub

func NewApplication

func NewApplication(controllers ...interface{}) *application

NewApplication create new web application instance and init it

Types

type Application

type Application interface {
	Init(controllers ...interface{}) error
	Config() *starter.SystemConfiguration
	Run()
}

ApplicationInterface is the interface of web application

type ApplicationContext added in v0.2.0

type ApplicationContext interface {
	context.Context
	ExtendedContext
}

type Context

type Context struct {
	// Optional Part 1: embed (optional but required if you don't want to override all context's methods)
	// it's the context/context.go#context struct but you don't need to know it.
	context.Context
	ExtendedContext
}

Context Create your own custom Context, put any fields you wanna need.

func (*Context) Do

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

Do: The only one important if you will override the Context with an embedded context.Context inside it. Required in order to run the handlers via this "*Context".

func (*Context) HTML

func (ctx *Context) HTML(htmlContents string) (int, error)

HTML Override any context's method you want... [...]

func (*Context) Next

func (ctx *Context) Next()

Next: The second one important if you will override the Context with an embedded context.Context inside it. Required in order to run the chain of handlers via this "*Context".

func (*Context) RequestBody

func (ctx *Context) RequestBody(data interface{}) error

RequestBody get RequestBody

func (*Context) RequestEx added in v0.2.0

func (ctx *Context) RequestEx(data interface{}, cb func() error) error

RequestEx get RequestBody

func (*Context) RequestForm added in v0.2.0

func (ctx *Context) RequestForm(data interface{}) error

RequestForm get RequestFrom

func (*Context) RequestParams added in v0.2.0

func (ctx *Context) RequestParams(data interface{}) error

RequestParams get RequestParams

func (*Context) ResponseBody

func (ctx *Context) ResponseBody(message string, data interface{})

ResponseBody set response

func (*Context) ResponseError

func (ctx *Context) ResponseError(message string, code int)

Response Errorset response

func (*Context) ResponseString added in v0.2.0

func (ctx *Context) ResponseString(data string)

ResponseBody set response

func (*Context) Translate added in v0.3.0

func (ctx *Context) Translate(format string, args ...interface{}) string

Translate override base context method Translate to return format if i18n is not enabled

type Controller

type Controller struct {
	ContextMapping string
	Ctx            *Context
}

Controller is the web base controller

func (*Controller) AuthType

func (c *Controller) AuthType() string

type ExtendedContext added in v0.2.0

type ExtendedContext interface {
	RequestEx(data interface{}, cb func() error) error
	RequestBody(data interface{}) error
	RequestForm(data interface{}) error
	ResponseBody(message string, data interface{})
	ResponseError(message string, code int)
}

type Health

type Health struct {
	Status string `json:"status"`
}

Health is the health check struct

type JwtController added in v0.2.0

type JwtController struct {
	Controller
}

JwtController is the base web controller that enabled JWT

func (*JwtController) AuthType added in v0.2.0

func (c *JwtController) AuthType() string

func (*JwtController) ParseToken added in v0.2.0

func (c *JwtController) ParseToken(claims jwt.MapClaims, prop string) string

ParseToken is an util that parsing JWT token from jwt.MapClaims

type JwtMap

type JwtMap map[string]interface{}

JwtMap is the JWT map

type JwtMiddleware

type JwtMiddleware struct {
	mwjwt.Middleware
}

JwtMiddleware derrived from github.com/iris-contrib/middleware/jwt/Middleware

func NewJwtMiddleware added in v0.2.0

func NewJwtMiddleware(cfg ...mwjwt.Config) *JwtMiddleware

NewJwtMiddleware New constructs a new Secure instance with supplied options.

func (*JwtMiddleware) CheckJWT

func (m *JwtMiddleware) CheckJWT(ctx context.Context) error

CheckJWT the main functionality, checks for token

func (*JwtMiddleware) Serve

func (m *JwtMiddleware) Serve(ctx context.Context)

Serve the middleware's action

type TestApplication added in v0.2.0

type TestApplication interface {
	Application
	RunTestServer(t *testing.T) *httpexpect.Expect
	Request(method, path string, pathargs ...interface{}) *httpexpect.Request
	Post(path string, pathargs ...interface{}) *httpexpect.Request
	Get(path string, pathargs ...interface{}) *httpexpect.Request
	Put(path string, pathargs ...interface{}) *httpexpect.Request
	Delete(path string, pathargs ...interface{}) *httpexpect.Request
	Patch(path string, pathargs ...interface{}) *httpexpect.Request
}

TestApplicationInterface the test web application interface for unit test only

func NewTestApplication added in v0.2.0

func NewTestApplication(t *testing.T, controllers ...interface{}) TestApplication

NewTestApplication returns the new test application

type Token

type Token string

Token is the token string

func GenerateJwtToken

func GenerateJwtToken(payload JwtMap, expired int64, unit time.Duration) (*Token, error)

GenerateJwtToken generates JWT token with specified exired time

Jump to

Keyboard shortcuts

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