Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithUser(ctx context.Context, user *User) context.Context
- func Middleware(opts ...OptFunc) func(next http.Handler) http.Handler
- func Signin(user Encoder, w http.ResponseWriter) error
- func Signout(w http.ResponseWriter)
- func TokenFrom(args ...interface{}) string
- func WithRedirect(uri string) func(next http.Handler) http.Handler
- type Authorizer
- type Cookier
- type Encoder
- type FormValuer
- type Getter
- type Names
- type OptFunc
- type User
- func (u *User) Decode(s string) (err error)
- func (u User) Encode() (s string, err error)
- func (u User) GetName() string
- func (u User) GetUID() string
- func (u *User) IsExpired() bool
- func (z *User) MarshalMsg(b []byte) (o []byte, err error)
- func (z *User) Msgsize() (s int)
- func (u *User) NeedRefresh() bool
- func (u *User) Refresh()
- func (user *User) Signin(w http.ResponseWriter) error
- func (z *User) UnmarshalMsg(bts []byte) (o []byte, err error)
Constants ¶
View Source
const (
UserKey ctxKey = iota
)
consts
Variables ¶
View Source
var ( UserLifetime int64 = 3600 Guest = &User{} )
vars
View Source
var (
ErrNoTokenInRequest = errors.New("no token present in request")
)
vars
Functions ¶
func ContextWithUser ¶ added in v0.1.1
ContextWithUser ...
func Middleware ¶ added in v0.1.0
Middleware ...
func Signin ¶
func Signin(user Encoder, w http.ResponseWriter) error
Signin write user encoded string into cookie, Deprecated
Types ¶
type Authorizer ¶ added in v0.1.4
type Authorizer interface { Middleware() func(next http.Handler) http.Handler MiddlewareWordy(redir bool) func(next http.Handler) http.Handler UserFromRequest(r *http.Request) (user *User, err error) TokenFromRequest(r *http.Request) (s string, err error) TokenFrom(args ...interface{}) string Cooking(value string) *http.Cookie Signin(user Encoder, w http.ResponseWriter) error Signout(w http.ResponseWriter) With(opts ...OptFunc) }
Authorizer ...
func NewOption ¶ added in v0.1.1
func NewOption(opts ...OptFunc) Authorizer
NewOption ..., Deprecated by New()
type FormValuer ¶ added in v0.1.3
FormValuer ex: http.Request
type Names ¶
type Names []string
Names ...
func (Names) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type OptFunc ¶ added in v0.1.0
type OptFunc func(opt *option)
OptFunc ...
func WithCookie ¶ added in v0.1.4
WithCookie set cookie 1-3 options: name, path, domain, see also http.Cookie
func WithMaxAge ¶ added in v0.1.4
WithMaxAge set cookie max age: >= 0, default 3600, see also http.Cookie
func WithRefresh ¶ added in v0.1.0
func WithRefresh() OptFunc
WithRefresh The option with auto refresh
type User ¶
type User struct { UID string `json:"uid" msg:"u"` Name string `json:"name" msg:"n"` Avatar string `json:"avatar,omitempty" msg:"a"` LastHit int64 `json:"hit,omitempty" msg:"h"` TeamID int64 `json:"tid,omitempty" msg:"t"` Roles Names `json:"roles,omitempty" msg:"r"` Watchings Names `json:"watching,omitempty" msg:"w"` }
User 在线用户
func UserFromRequest ¶
UserFromRequest get user from cookie, Deprecated
func (*User) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*User) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
Click to show internal directories.
Click to hide internal directories.