Documentation
¶
Overview ¶
Example ¶
handle := func(ctx context.Context, s *Flow) error {
fmt.Println("M", s.Rest)
return s.Success(fmt.Sprintf("M %v", s.Rest))
}
Handle := func(ctx context.Context, req *api.Request, res *api.Response) error {
return REST(ctx, req, res).
Chain(LoadAuthService(func(ctx context.Context) (AuthService, bool) { return nil, false })).
Chain(JWTCheck()).
Chain(RoleCheck([]string{"admin"}, LogicalAND)).
// API
Action(POST).
Chain(PermCheck([]string{"user:insert"}, LogicalAND)).
Chain(handle).
Done().
// API
Action(DELETE).
Chain(PermCheck([]string{"user:delete"}, LogicalAND)).
Chain(handle).
Done().
// API
Action(GET).
Chain(PermCheck([]string{"user:select"}, LogicalAND)).
Chain(handle).
Done().
// API
Action(PUT).
Chain(PermCheck([]string{"user:update"}, LogicalAND)).
Chain(handle).
Done().
// Finsh
Final()
}
Handle(context.Background(),
&api.Request{},
&api.Response{},
)
Index ¶
- Variables
- func AInB(a []string, b []string) bool
- func CleanErrResponse(id string, e error, fn func(id, format string, a ...interface{}) error) error
- func GetJWT(r *api.Request) string
- func ItemInList(a string, b []string) bool
- func Pair2Str(pair *api.Pair) (v string, ok bool)
- func RoleLevel(roles []string) int
- func SetJWT(r *api.Response, jwt string)
- type AuthService
- type Flow
- type Logical
- type Middleware
- func JWTCheck() Middleware
- func LoadAuthService(loader func(ctx context.Context) (AuthService, bool)) Middleware
- func ParamAutoLoad(modify ParamModifyList, entity interface{}) Middleware
- func ParamCheck(pccs PCCS) Middleware
- func PermCheck(rules []string, logical Logical) Middleware
- func RoleCheck(rules []string, logical Logical) Middleware
- func RoleLevelCheck(id string) Middleware
- type PCC
- type PCCS
- type ParamModify
- type ParamModifyList
- type RESTful
- type RESTfulType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PccEmptyStr = &PCC{DefaultV: []string{""}} PccMust = &PCC{Must: true} )
PCC in common use
View Source
var ( PmInt = func(ps []string) (interface{}, error) { return strconv.Atoi(ps[0]) } )
ParamModify in common use
View Source
var ( RESTfulTypeDict = map[string]RESTfulType{ "GET": GET, "get": GET, "POST": POST, "post": POST, "delete": DELETE, "DELETE": DELETE, "put": PUT, "PUT": PUT, } )
dict
View Source
var (
SrvName = "starmap.api"
)
Configurable raw
Functions ¶
func CleanErrResponse ¶
CleanErrResponse to cancel circle Error
Types ¶
type AuthService ¶
type AuthService interface {
Check(ctx context.Context, in *auth.UserToken, opts ...client.CallOption) (*auth.UserToken, error)
Roles(ctx context.Context, in *auth.Identity, opts ...client.CallOption) (*auth.Result, error)
Perms(ctx context.Context, in *auth.Identity, opts ...client.CallOption) (*auth.Result, error)
}
AuthService needed to load
type Flow ¶
type Flow struct {
// req data (should not change by Middleware)
Ctx context.Context
Req *api.Request
Res *api.Response
Rest RESTfulType
Params map[string]*api.Pair
// cache
AuthUserClient AuthService
Token *auth.UserToken
Roles []string
Perms []string
// contains filtered or unexported fields
}
Flow for RESTful API
type Middleware ¶
Middleware for RESTful
func LoadAuthService ¶
func LoadAuthService(loader func(ctx context.Context) (AuthService, bool)) Middleware
LoadAuthService Wrapper
func ParamAutoLoad ¶
func ParamAutoLoad(modify ParamModifyList, entity interface{}) Middleware
ParamAutoLoad Wrapper
type PCC ¶
type PCC struct {
Must bool
Multi bool
DefaultV []string
Link string
LinkLogical Logical
Rename string
// contains filtered or unexported fields
}
PCC - ParamCheck Config
type ParamModify ¶
ParamModify for ParamAutoLoad
type ParamModifyList ¶
type ParamModifyList map[string]ParamModify
ParamModifyList for ParamAutoLoad
type RESTful ¶
type RESTful interface {
// flow
Action(RESTfulType) RESTful // build child
Chain(Middleware) RESTful // use Middleware
Done() RESTful // backto father
Final() error // error response (nil means success)
}
RESTful API
type RESTfulType ¶
type RESTfulType int
RESTfulType for API
const ( POST RESTfulType = 1 << iota // INSERT DELETE // DELETE GET // INSERT PUT // UPDATE )
RESTfulType(s)
Click to show internal directories.
Click to hide internal directories.