apikey

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 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, apiKey *ApiKey) (int64, error)

This function deletes the account given in the function parameters.

It returns the count of deleted api keys, 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, apiKey *ApiKey, database string) error

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

Types

type ApiKey

type ApiKey struct {
	ID                    primitive.ObjectID `bson:"_id"`
	CreatedAt             time.Time          `bson:"created_at"`
	UpdatedAt             time.Time          `bson:"updated_at"`
	ExpiresAt             time.Time          `bson:"expires_at"`
	Key                   string             `bson:"key"`
	Namespace             string             `bson:"namespace"`
	AccessibleCollections []string           `bson:"accessible_collections"`
	CanRead               bool               `bson:"can_read"`
	CanWrite              bool               `bson:"can_write"`
}

This type represents an api key in the database

func FindAll

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

This function returns all api keys that are currently in the database.

func FindByID

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

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

func FindByKey

func FindByKey(client *mongo.Client, ctx context.Context, database string, key string) (*ApiKey, error)

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

func (*ApiKey) Delete

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

This function deletes the api key it is called upon.

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

func (*ApiKey) Insert

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

This function inserts the api key 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