sessions

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeySessions = "Api.Sessions"
)
View Source
const (
	SessionDuration = 3 * time.Minute
)

Variables

View Source
var (
	ErrInternalError = errors.New("InternalError")

	ErrInvalidDuration   = errors.New("Invalid Duration")
	ErrInvalidUserID     = errors.New("Invalid UserID")
	ErrInvalidRemoteAddr = errors.New("Invalid RemoteAddr")
	ErrRemoteAddrChanged = errors.New("RemoteAddr Changed")
	ErrInvalidSessionID  = errors.New("Invalid SessionID")
	ErrSessionExpired    = errors.New("Session Expired")
	ErrEncode            = errors.New("Encode Error")
	ErrDecode            = errors.New("Decode Error")
	ErrCache             = errors.New("Cache Error")

	ErrInvalidCrendential    = errors.New("InvalidCredentials")
	ErrMissingCookie         = errors.New("MissingCookie")
	ErrInvalidCookie         = errors.New("ErrInvalidCookie")
	ErrSessionCreationFailed = errors.New("SessionCreationFailed")
	ErrTooManyOpenSession    = errors.New("TooManyOpenSession")
	ErrSessionClose          = errors.New("SessionCloseFailed")
)

Functions

func CreateSessionWithCookie

func CreateSessionWithCookie(ctx context.Context, r *http.Request, w http.ResponseWriter, userID uint64) error

func GetSessionCookie

func GetSessionCookie(r *http.Request) string

func IsSessionValid

func IsSessionValid(sessionID SessionID) bool

func IsUserValid

func IsUserValid(userID uint64) bool

func OpenSessionAllowed

func OpenSessionAllowed(ctx context.Context, userID uint64) bool

func VerifySession

func VerifySession(ctx context.Context, subject string, message *messaging.Message) (*messaging.Message, error)

Types

type CookieCodec

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

func NewCookieCodec

func NewCookieCodec(ctx context.Context) *CookieCodec

func (*CookieCodec) NewRequest

func (p *CookieCodec) NewRequest(r *http.Request) rpc.CodecRequest

type CookieCodecRequest

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

func (*CookieCodecRequest) Method

func (p *CookieCodecRequest) Method() (string, error)

func (*CookieCodecRequest) ReadRequest

func (p *CookieCodecRequest) ReadRequest(args interface{}) error

func (*CookieCodecRequest) WriteError

func (p *CookieCodecRequest) WriteError(w http.ResponseWriter, status int, err error)

func (*CookieCodecRequest) WriteResponse

func (p *CookieCodecRequest) WriteResponse(w http.ResponseWriter, args interface{})

type Session

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

func ContextSession

func ContextSession(ctx context.Context) (*Session, error)

func NewSession

func NewSession(ctx context.Context) *Session

func (*Session) Count

func (s *Session) Count(ctx context.Context) (int, error)

func (*Session) CreateSession

func (s *Session) CreateSession(ctx context.Context, userID uint64, remoteAddr string, duration time.Duration) (SessionID, error)

func (*Session) ExtendSession

func (s *Session) ExtendSession(ctx context.Context, remoteAddr string, sessionID SessionID, duration time.Duration) (uint64, error)

func (*Session) InvalidateSession

func (s *Session) InvalidateSession(ctx context.Context, sessionID SessionID) error

func (*Session) IsSessionValid

func (s *Session) IsSessionValid(ctx context.Context, sessionID SessionID) bool

func (*Session) UserSession

func (s *Session) UserSession(ctx context.Context, sessionID SessionID) uint64

type SessionArgs

type SessionArgs struct {
	SessionID string `json:"-"` // SessionID is transmit to client via cookie
}

SessionArgs holds SessionID for operation requests and repls

type SessionID

type SessionID string

func NewSessionID

func NewSessionID() SessionID

type SessionInfo

type SessionInfo struct {
	UserID     uint64
	RemoteAddr string
	SessionID  SessionID
	Expiration time.Time
}

func (*SessionInfo) Decode

func (s *SessionInfo) Decode(data []byte) error

Decode return SessionInfo from bytes. Decoded with gob

func (*SessionInfo) Encode

func (s *SessionInfo) Encode() ([]byte, error)

Encode return bytes from Message. Encoded with gob

func (*SessionInfo) Expired

func (s *SessionInfo) Expired() bool

type SessionReply

type SessionReply struct {
	SessionArgs
	Status     string `json:"status"`
	ValidUntil int64  `json:"valid_until"`
}

SessionReply holds session informations for operation replies

func OpenUserSession

func OpenUserSession(ctx context.Context, session *Session, r *http.Request, userID uint64) (SessionReply, error)

Jump to

Keyboard shortcuts

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