gomato

package module
v0.0.0-...-f7a6b88 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

gomato

A pomodoro library written in Go.

Getting Started

You can initialize a timer in one of two ways:

  1. Using default settings

Default settings use the standard library log package and a cache with no expiration or cleanup.

pomodoro := gomato.NewDefaultTimeKeeper()
  1. Using custom settings

You can use your own standard log implementation and cache with custom cleanup. If you leave the cache nil, then it will create a cache with no expiration or cleanup. If you leave the logger nil, it will use a no-op logger.

import (
        "log"
        "time"

        gcache "github.com/patrickmn/go-cache"
        "github.com/bethanyj28/gomato"
)

logger := log.New(os.Stdout, "GOMATO: ", log.Lshortfile)
cache := gcache.New(5 * time.Minute, 5 * time.Minute)

pomodoro := gomato.NewTimeKeeper(logger, cache)

Starting a timer is simple:

pomodoro := gomato.NewDefaultTimeKeeper()
uID, err := pomodoro.Start("userID", 25 * time.Minute, action1(), action2())

The userID is optional. If you opt to not use your own, then one will be generated and returned. With StartWithTime you can optionally provide a starting time if it is not whatever time.Now() returns. If you enter a zero duration, it will be set to the typical 25 minutes that pomodoros are set. Actions are variadic, so you can enter as many or as few as you'd like, just make sure that there's nothing passed into them and they do not return anything. Feel free to look at the tests for an example on how to still pass in variables to the functions.

Pausing, Resuming, and Stopping simply require a userID.

Testing

For simple testing, this package abides by the following interface:

type PomodoroManager interface {
	StartWithTime(uID string, start time.Time, duration time.Duration, actions ...func()) (string, error)
	Start(uID string, duration time.Duration, actions ...func()) (string, error)
	Pause(uID string) error
	Resume(uID string) error
	Stop(uID string) error
}

Planned use cases

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PomodoroManager

type PomodoroManager interface {
	StartWithTime(uID string, start time.Time, duration time.Duration, actions ...func()) (string, error)
	Start(uID string, duration time.Duration, actions ...func()) (string, error)
	Resume(uID string) error
	Pause(uID string) error
	Stop(uID string) error
}

PomodoroManager represents the methods necessary to implement gomato for easy testing

type TimeKeeper

type TimeKeeper struct {
	// contains filtered or unexported fields
}

TimeKeeper represents the necessary components to manage pomodoros

func NewDefaultTimeKeeper

func NewDefaultTimeKeeper() *TimeKeeper

NewDefaultTimeKeeper instantiates a TimeKeeper with default logging and cache options

func NewTimeKeeper

func NewTimeKeeper(l *log.Logger, c *gcache.Cache) *TimeKeeper

NewTimeKeeper instantiates a TimeKeeper object

func (*TimeKeeper) Pause

func (t *TimeKeeper) Pause(uID string) error

Pause pauses a timer with the given user ID

func (*TimeKeeper) Resume

func (t *TimeKeeper) Resume(uID string) error

Resume resumes a paused timer with the given user ID

func (*TimeKeeper) Start

func (t *TimeKeeper) Start(uID string, duration time.Duration, actions ...func()) (string, error)

Start begins a new pomodoro without the need to pass in a start time A user identifier should be passed through, but if it is not then it will be generated and returned

func (*TimeKeeper) StartWithTime

func (t *TimeKeeper) StartWithTime(uID string, start time.Time, duration time.Duration, actions ...func()) (string, error)

StartWithTime begins a new pomodoro A user identifier should be passed through, but if it is not then it will be generated and returned

func (*TimeKeeper) Stop

func (t *TimeKeeper) Stop(uID string) error

Stop stops a timer (running or paused) and deletes it from the cache

Jump to

Keyboard shortcuts

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