datastore

package
v0.0.0-...-2a7283e Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BasicRateLimitID represents the basic tier rate limit
	BasicRateLimitID uint32 = 1
	// StandardRateLimitID represents the standard tier rate limit
	StandardRateLimitID uint32 = 2
	// PremiumRateLimitID represents the premium tier rate limit
	PremiumRateLimitID uint32 = 3
)

Default rate limit IDs

View Source
const (
	DefaultPageLimit = 10
)

Variables

View Source
var ErrNotExists = errors.New("resource does not exist")

Functions

func GetDefaultPermissionDefinitions

func GetDefaultPermissionDefinitions() []model.Permission

GetDefaultPermissionDefinitions returns the predefined permission configurations

func GetDefaultRateLimitDefinitions

func GetDefaultRateLimitDefinitions() []model.RateLimit

GetDefaultRateLimitDefinitions returns the predefined rate limit configurations

func GetDefaultRateLimitID

func GetDefaultRateLimitID() uint32

GetDefaultRateLimitID returns the default rate limit ID for new users

Types

type CursorPagination

type CursorPagination struct {
	// Cursor represents the ID of the last item from the previous page
	// If empty, starts from the beginning
	Cursor     string `json:"cursor"`
	Limit      int    `json:"limit"`       // Number of items to retrieve
	HasMore    bool   `json:"has_more"`    // Indicates if there are more items (populated by the store)
	NextCursor string `json:"next_cursor"` // Cursor for the next page (populated by the store)
}

CursorPagination contains parameters for cursor-based pagination

type Datastore

type Datastore interface {
	// Permission
	CreatePermission(ctx context.Context, permission *model.Permission) error
	GetPermission(ctx context.Context, id uint32) (*model.Permission, error)
	GetAllPermissions(ctx context.Context) ([]model.Permission, error)
	UpdatePermission(ctx context.Context, permission *model.Permission) error
	DeletePermission(ctx context.Context, id uint32) error
	GetDefaultPermissions(ctx context.Context) ([]model.Permission, error)
	SetPermissionAsDefault(ctx context.Context, id uint32, isDefault bool) error

	// Rate Limit
	CreateRateLimit(ctx context.Context, rl *model.RateLimit) error
	GetRateLimit(ctx context.Context, id uint32) (*model.RateLimit, error)
	GetAllRateLimits(ctx context.Context) ([]model.RateLimit, error)
	UpdateRateLimit(ctx context.Context, rl *model.RateLimit) error
	DeleteRateLimit(ctx context.Context, id uint32) error

	// User
	CreateUser(ctx context.Context, user *model.User) error
	GetUser(ctx context.Context, id uint64) (*model.User, error)
	GetAllUsers(ctx context.Context, pagination *CursorPagination) ([]model.User, error)
	UpdateUser(ctx context.Context, user *model.User) error
	DeleteUser(ctx context.Context, id uint64) error
	AddPermissionToUser(ctx context.Context, userID uint64, permissionID uint32) error
	RemovePermissionFromUser(ctx context.Context, userID uint64, permissionID uint32) error

	// Application
	CreateApplication(ctx context.Context, app *model.Application) error
	GetApplication(ctx context.Context, id uint32) (*model.Application, error)
	GetApplicationByAPIKey(ctx context.Context, apiKey string) (*model.Application, error)
	GetAllApplications(ctx context.Context) ([]model.Application, error)
	GetApplicationsForUser(ctx context.Context, userID uint64) ([]model.Application, error)
	UpdateApplication(ctx context.Context, app *model.Application) error
	DeleteApplication(ctx context.Context, id uint32) error
	AddPermissionToApplication(ctx context.Context, appID, permissionID uint32) error
	RemovePermissionFromApplication(ctx context.Context, appID, permissionID uint32) error
	GetApplicationCountForUser(ctx context.Context, userID uint64) (uint32, error)

	// Request
	CreateRequest(ctx context.Context, req *model.Request) error
	GetRequest(ctx context.Context, id uint32) (*model.Request, error)
	GetAllRequests(ctx context.Context) ([]model.Request, error)
	UpdateRequest(ctx context.Context, req *model.Request) error
	DeleteRequest(ctx context.Context, id uint32) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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