web

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: Apache-2.0 Imports: 32 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 InitJwt

func InitJwt(wd string) error

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

Types

type Application

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

Application is the struct of web Application TODO: application should be singleton and private

func NewApplication

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

NewApplication create new web application instance and init it

func (*Application) Config

func (wa *Application) Config() *starter.SystemConfiguration

Config returns application config

func (*Application) Init

func (wa *Application) Init(controllers ...interface{}) error

Init init web application

func (*Application) Run

func (wa *Application) Run()

Run run web application

type ApplicationContext added in v0.2.0

type ApplicationContext interface {
	context.Context
	ExtendedContext
}

type ApplicationInterface

type ApplicationInterface interface {
	Init()
	Config() *starter.SystemConfiguration
	Run()
}

ApplicationInterface is the interface of web application

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

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 struct {
	Application
	// contains filtered or unexported fields
}

TestApplication the test web application 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

func (*TestApplication) Delete added in v0.2.0

func (ta *TestApplication) Delete(path string, pathargs ...interface{}) *httpexpect.Request

Delete wrap of Request with Delete method

func (*TestApplication) Get added in v0.2.0

func (ta *TestApplication) Get(path string, pathargs ...interface{}) *httpexpect.Request

Get wrap of Request with Get method

func (*TestApplication) Patch added in v0.2.0

func (ta *TestApplication) Patch(path string, pathargs ...interface{}) *httpexpect.Request

Patch wrap of Request with Patch method

func (*TestApplication) Post added in v0.2.0

func (ta *TestApplication) Post(path string, pathargs ...interface{}) *httpexpect.Request

Post wrap of Request with POST method

func (*TestApplication) Put added in v0.2.0

func (ta *TestApplication) Put(path string, pathargs ...interface{}) *httpexpect.Request

Put wrap of Request with Put method

func (*TestApplication) Request added in v0.2.0

func (ta *TestApplication) Request(method, path string, pathargs ...interface{}) *httpexpect.Request

Request request for unit test

func (*TestApplication) RunTestServer added in v0.2.0

func (ta *TestApplication) RunTestServer(t *testing.T) *httpexpect.Expect

RunTestServer run the test server

type TestApplicationInterface added in v0.2.0

type TestApplicationInterface interface {
	ApplicationInterface
	NewTestServer(t *testing.T) *httpexpect.Expect
}

TestApplicationInterface the test web application interface for unit test only

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