db

package
v0.0.0-...-26b0df5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateContainer

func CreateContainer(client *azcosmos.Client, databaseName, containerName, partitionKeyPath string) (*azcosmos.ContainerClient, error)

func CreateDatabase

func CreateDatabase(client *azcosmos.Client, databaseName string) (*azcosmos.DatabaseClient, error)

func DecodeContent

func DecodeContent(content ItemContent) (string, error)

func GetCostmosClient

func GetCostmosClient(cfg *CosmosConfig) (*azcosmos.Client, error)

func GetCurrentTime

func GetCurrentTime() time.Time

func ParseTime

func ParseTime(t string) (time.Time, error)

func StartCleaner

func StartCleaner(h *CosmosHandler, opts *CleanerOpts)

Types

type CleanerOpts

type CleanerOpts struct {
	// How often to run the cleaner
	Interval time.Duration
}

func NewCleanerOpts

func NewCleanerOpts(intervalMinutes int) *CleanerOpts

type CosmosConfig

type CosmosConfig struct {
	Endpoint      string
	Key           string
	DatabaseName  string
	ContainerName string
	Partition     string
}

func GetDBConfig

func GetDBConfig() (*CosmosConfig, error)

type CosmosHandler

type CosmosHandler struct {
	// Cosmos Client
	Client *azcosmos.Client
	// Cosmos database client
	DatabaseClient *azcosmos.DatabaseClient
	// Cosmos container client
	ContainerClient *azcosmos.ContainerClient
	// Data
	DatabaseName  string
	ContainerName string
	Partition     string
}

func NewCosmosHandler

func NewCosmosHandler(cfg *CosmosConfig) (*CosmosHandler, error)

func (*CosmosHandler) CreateItem

func (h *CosmosHandler) CreateItem(itemID ItemID, item *Item) error

func (*CosmosHandler) DeleteItem

func (h *CosmosHandler) DeleteItem(itemID ItemID) error

func (*CosmosHandler) GetAllItems

func (h *CosmosHandler) GetAllItems() ([]Item, error)

func (*CosmosHandler) Init

func (h *CosmosHandler) Init() error

func (*CosmosHandler) NewItem

func (h *CosmosHandler) NewItem(content string, lifetimeHours int, password string, deleteOnRead bool) *Item

func (*CosmosHandler) ReadItem

func (h *CosmosHandler) ReadItem(itemID ItemID) (*Item, error)

type Item

type Item struct {
	Id            ItemID      `json:"id"`
	Partition     string      `json:"partition"`
	LifetimeHours int         `json:"lifetimeHours"`
	Content       ItemContent `json:"content"`
	Password      ItemContent `json:"password"`
	DeleteOnRead  bool        `json:"deleteOnRead"`
	Created       time.Time   `json:"created"`
}

type ItemContent

type ItemContent string

func EncodeContent

func EncodeContent(content string) ItemContent

type ItemID

type ItemID string

func GetRandomID

func GetRandomID() ItemID

Jump to

Keyboard shortcuts

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