diary

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: AGPL-3.0, BSD-2-Clause, ISC Imports: 6 Imported by: 0

Documentation

Overview

package resource holds non-overlapping bookings with arbitrary durations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Booking

type Booking struct {
	When interval.Interval
	Name string
}

Booking represents a booking. This is not used internally, it's just for returning booking info from GetBookings() and validating bookings with ValidateBooking()

type Diary

type Diary struct {
	*sync.RWMutex `json:"-"`
	Name          string // unique, persistant name
	// contains filtered or unexported fields
}

Diary represents the bookings of a resources

func New

func New(name string) *Diary

New creates a new resource with no bookings

func (*Diary) ClearBefore

func (d *Diary) ClearBefore(t time.Time)

ClearBefore removes all old bookings

func (*Diary) Delete

func (d *Diary) Delete(delete string) error

Delete removes a booking, if it exists

func (*Diary) GetBookings

func (d *Diary) GetBookings() ([]Booking, error)

GetBookings returns all bookings

func (*Diary) GetCount

func (d *Diary) GetCount() int

GetCount returns the number of live bookings

func (*Diary) IsAvailable

func (d *Diary) IsAvailable() (bool, string)

func (*Diary) Request

func (d *Diary) Request(when interval.Interval, name string) error

Request returns a booking, if it can be made name must be specified

func (*Diary) SetAvailable

func (d *Diary) SetAvailable(reason string)

func (*Diary) SetUnavailable

func (d *Diary) SetUnavailable(reason string)

func (*Diary) ValidateBooking

func (d *Diary) ValidateBooking(b Booking) (bool, error)

ValidateBooking checks if a given booking matches an existing booking Returns false if the resource is not available so that it can be used as a check on whether to supply connection info to user (don't if resource if not available)

Jump to

Keyboard shortcuts

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