Documentation ¶
Index ¶
- Constants
- Variables
- type BasicRepo
- type DBRepo
- type IRepository
- type Service
- func (s Service) DeleteSession(ctx context.Context, cid string) error
- func (s Service) GenerateToken(uid string) (string, error)
- func (s Service) GetUIDFromToken(token string) (string, error)
- func (s Service) IsTokenExpired(token string) (bool, error)
- func (s Service) RestoreSession(ctx context.Context, cid string) (string, error)
- func (s Service) StoreSession(ctx context.Context, token string) (string, error)
Constants ¶
View Source
const ( CreateSessionTable = `CREATE TABLE IF NOT EXISTS sessions( cid VARCHAR(50), token VARCHAR(165), PRIMARY KEY (cid) )` DeleteSession = `DELETE FROM sessions WHERE cid = $1` GetSession = "SELECT token FROM sessions WHERE cid = $1" StoreSession = "INSERT INTO sessions(cid, token) VALUES ($1, $2) ON CONFLICT DO NOTHING RETURNING token" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type BasicRepo ¶
type BasicRepo struct {
// contains filtered or unexported fields
}
func NewBasicRepo ¶
func NewBasicRepo() *BasicRepo
func (*BasicRepo) DeleteSession ¶
func (*BasicRepo) GetSession ¶
type DBRepo ¶
type DBRepo struct {
// contains filtered or unexported fields
}
func (*DBRepo) DeleteSession ¶
func (*DBRepo) GetSession ¶
type IRepository ¶
type IRepository interface { DeleteSession(ctx context.Context, cid string) error GetSession(ctx context.Context, cid string) (string, error) StoreSession(ctx context.Context, cid, token string) error }
func NewRepo ¶
func NewRepo(repoURL string) (IRepository, error)
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
NewService returns an instance of the Service with the associated repository.
func (Service) DeleteSession ¶
DeleteSession deletes the client-associated session.
func (Service) GenerateToken ¶
GenerateToken generates a new JWT token with the specified expiry time.
func (Service) GetUIDFromToken ¶
GetUIDFromToken parses the token string and returns the UID from its claims.
func (Service) IsTokenExpired ¶
IsTokenExpired checks if the token had expired.
func (Service) RestoreSession ¶
RestoreSession gathers the stored client-associated token. If the token is expired, the method deletes it from the repository and returns an error.
Click to show internal directories.
Click to hide internal directories.