session

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(client *mongo.Client, ctx context.Context, database string, session *Session) (int64, error)

This function deletes the session given in the function parameters.

It returns the count of deleted sessions, which can be either 0 or 1, or an error when something went wrong while deleting the database entry.

func DeleteByID

func DeleteByID(client *mongo.Client, ctx context.Context, database string, sessionID primitive.ObjectID) (int64, error)

This function searches the database for a session with the specified ID and deletes it.

It returns the count of deleted sessions, which can be either 0 or 1, or an error when something went wrong while deleting the database entry.

func DeleteByToken

func DeleteByToken(client *mongo.Client, ctx context.Context, database string, sessionToken string) (int64, error)

This function searches the database for a session with the specified token and deletes it.

It returns the count of deleted sessions, which can be either 0 or 1, or an error when something went wrong while deleting the database entry.

func Insert

func Insert(client *mongo.Client, ctx context.Context, database string, session *Session) error

This function inserts the session given in the function parameters into the database. If anything went wrong during the insertion, returns an error.

Types

type Session

type Session struct {
	ID        primitive.ObjectID `bson:"_id"`
	CreatedAt time.Time          `bson:"created_at"`
	UpdatedAt time.Time          `bson:"updated_at"`
	ExpiresAt time.Time          `bson:"expires_at"`
	// The token used for identifying the session outside of the database.
	SessionToken string `bson:"session_token"`
	// The account whom this session belongs to.
	AccountID primitive.ObjectID `bson:"account_id"`
}

This type represents a session saved in the database.

func FindAll

func FindAll(client *mongo.Client, ctx context.Context, database string) ([]Session, error)

This function returns all sessions that are currently in the database.

func FindByID

func FindByID(client *mongo.Client, ctx context.Context, database string, ID primitive.ObjectID) (*Session, error)

This function searches the database for a session with the given ID and returns it if it was found. If no match was found, returns an error.

func FindByToken

func FindByToken(client *mongo.Client, ctx context.Context, database string, token string) (*Session, error)

This function searches the database for a session with the given token and returns it if it was found. If no match was found, returns an error.

func (*Session) Delete

func (session *Session) Delete(client *mongo.Client, ctx context.Context, database string) (int64, error)

This function deletes the session it is called upon.

It returns the count of deleted sessions, which can be either 0 or 1, or an error when something went wrong while deleting the database entry.

func (*Session) Insert

func (session *Session) Insert(client *mongo.Client, ctx context.Context, database string) error

This function inserts the session it is called upon into the database. If anything went wrong during the insertion, returns an error.

Jump to

Keyboard shortcuts

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