lib

package
v0.0.0-...-924f437 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

lib holds the core logic for working with tasks and connecting to the underlying taks database.

Index

Constants

View Source
const (
	ConfigDirName = ".taks/"
)
View Source
const CurrentMetadataVersion int = 0
View Source
const TaskPrefix = "task-"

Variables

View Source
var MetadataID = []byte("_metadata")

Functions

func GetConfigDir

func GetConfigDir(p string) (string, error)

GetConfigDir returns the path to the config directory where the database should be stored. `p` is the path to the parent directory, in which the config directory will be named after `ConfigDirName`. If `p` is empty, the config directory will be created in the user's home directory (per `os.UserHomeDir()`).

Types

type AppMetadata

type AppMetadata struct {
	Version int
}

AppMetadata stores metadata about the

func MetadataFromBytes

func MetadataFromBytes(b []byte) (*AppMetadata, error)

func NewMetadata

func NewMetadata() *AppMetadata

func (*AppMetadata) MarshalBytes

func (m *AppMetadata) MarshalBytes() (id []byte, body []byte, err error)

type TaksDB

type TaksDB struct {
	Path string
	DB   *badger.DB
}

TaksDB manages the connection to the task DB

func OpenDB

func OpenDB(path string) (*TaksDB, error)

func (*TaksDB) Close

func (db *TaksDB) Close() error

func (*TaksDB) DeleteMetadata

func (db *TaksDB) DeleteMetadata() error

func (*TaksDB) DeleteTask

func (db *TaksDB) DeleteTask(id string) error

func (*TaksDB) GetMetadata

func (db *TaksDB) GetMetadata() (*AppMetadata, error)

func (*TaksDB) GetTask

func (db *TaksDB) GetTask(id string) (*Task, error)

func (*TaksDB) ListTasks

func (db *TaksDB) ListTasks() ([]*Task, error)

func (*TaksDB) NewTaskID

func (db *TaksDB) NewTaskID() (uint64, error)

func (*TaksDB) PutMetadata

func (db *TaksDB) PutMetadata(m *AppMetadata) error

func (*TaksDB) PutTask

func (db *TaksDB) PutTask(t *Task) error

func (*TaksDB) Validate

func (db *TaksDB) Validate() error

type Task

type Task struct {
	ID          string       `json:"id"`                    // Unique ID for the task, used as the DB key
	Name        string       `json:"name"`                  // Name of the task & main text
	Details     string       `json:"details,omitempty"`     // Optional task details
	Project     string       `json:"project,omitempty"`     // Optional project name associated with the task
	Status      string       `json:"status,omitempty"`      // Optional task status
	Priority    TaskPriority `json:"priority,omitempty"`    // Optional task priority (Priority scale: 1-5; 1 is the highest; 0 means not set)
	CreatedAt   time.Time    `json:"createdAt"`             // Timestamp of the task creation
	DueAt       *time.Time   `json:"dueAt,omitempty"`       // Optional due date for the task
	CompletedAt *time.Time   `json:"completedAt,omitempty"` // Optional completion timestamp
	Tags        []string     `json:"tags"`                  // Optional list of tags associated with the task
}

Task stores data connected to a single task in the user's task list.

func NewTask

func NewTask(name string) *Task

NewTask creates a new Task with the supplied name, an auto-generated ID and creation timestamp, and nil values for the remaining fields.

func TaskFromBytes

func TaskFromBytes(b []byte) (*Task, error)

TaskFromBytes unmarshals the given byte slices into a Task.

func (*Task) IsComplete

func (t *Task) IsComplete() bool

func (*Task) MarshalBytes

func (t *Task) MarshalBytes() (id []byte, task []byte, err error)

MarshalBytes returns the the task's ID and JSON-encoded data as byte slices.

func (*Task) String

func (t *Task) String() string

type TaskPriority

type TaskPriority uint32

TaskPriority is an enum for the priority of a task.

const (
	TaskPriorityNotSet   TaskPriority = iota // An unset priority.
	TaskPriorityVeryHigh                     // Very high priority.
	TaskPriorityHigh                         // High priority.
	TaskPriorityMedium                       // Medium priority.
	TaskPriorityLow                          // Low priority.
	TaskPriorityVeryLow                      // Very low priority.
)

Jump to

Keyboard shortcuts

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