session

package
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

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

Session represent a single session

func FromContext

func FromContext(ctx context.Context) (s *Session)

FromContext return the session from an context this works only if it was added before with AddToContext

func New

func New(remoteAddr string) (s Session)

func (*Session) AddToContext

func (s *Session) AddToContext(ctx context.Context) (newCtx context.Context)

AddToContext will add the session to the given context and return the new context

func (*Session) AuthenticatedSet

func (s *Session) AuthenticatedSet(authenticated bool)

AuthenticatedSet can set the authenticated-state to true/false ONLY ONCE

you can set it to false every time

but if its set to false, you can not set it to true again

func (*Session) Close

func (s *Session) Close()

close the channel and remove all data

func (*Session) CloseChannel

func (s *Session) CloseChannel()

close the channel to frontend

func (*Session) Data

func (s *Session) Data(name string) (data interface{}, err error)

Data will get data from the session that was set before with DataSet

func (*Session) DataSet

func (s *Session) DataSet(name string, data interface{}) (err error)

DataSet will set some data in the session that is identified with name

func (Session) ID

func (s Session) ID() string

ID will return the current sessionID

func (*Session) IDSet

func (s *Session) IDSet(newID string)

IDSet will set the id of an session only if no ID was set before

func (*Session) InternalSet

func (s *Session) InternalSet()

InternalSet mark this session as internal session

This is for internal stuff, like config changes on the hard drive or shutdown etc.

This should NEVER set when it comes from external request

func (Session) IsAuthenticated

func (s Session) IsAuthenticated() bool

func (Session) IsInternal

func (s Session) IsInternal() bool

func (Session) IsTimedOut

func (s Session) IsTimedOut(timeout time.Duration) bool

func (*Session) JWTNew

func (s *Session) JWTNew() (signedToken []byte, err error)

NewJWTToken

- store the sessionID in JWT-Token

- create new secret ( and overwrite an possible old secret !)

- create and sign the jwt

func (*Session) JWTVerify

func (s *Session) JWTVerify(signedToken []byte) (valid bool)

Verify check the JWT-token and return the sessionID

func (Session) MarshalZerologObject

func (s Session) MarshalZerologObject(event *zerolog.Event)

MarshalZerologObject implementation to use it with Object()

func (*Session) Refresh

func (s *Session) Refresh()

Refresh will refresh the timeout

func (*Session) Reset

func (s *Session) Reset(remoteAddr string)

Init just init an existing session to initial state

All data gets lost !

remoteAddr can be empty

func (*Session) Send

func (s *Session) Send(msg *message.Message)

Send will send an msg over server-sent-events ( if an client connected to it )

func (Session) SessionInfo

func (s Session) SessionInfo() (info SessionInfo)

GetSessionInfos return all sessions for an given user

func (*Session) ToFrontend

func (s *Session) ToFrontend() <-chan *message.Message

return the channel

func (Session) Username

func (s Session) Username() (username string)

func (*Session) UsernameSet

func (s *Session) UsernameSet(username string)

type SessionInfo

type SessionInfo struct {
	ID         string    `json:"id,omitempty"`
	CreatedAt  time.Time `json:"timestamp,omitempty"` // when the session was created
	UpdatedAt  time.Time `json:"updated,omitempty"`   // when the session was created
	Username   string    `json:"username,omitempty"`  // the username or "" if anonym
	RemoteAddr string    `json:"ip,omitempty"`
}

SessionInfo represent information about a single session

Jump to

Keyboard shortcuts

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