reminders

package
v0.0.0-...-c60ef1b Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package reminders holds the application logic to manage reminders (tasks one seeks to remember).

Copyright 2015-2019 VMware, Inc. All Rights Reserved. Author: Tom Hite (thite@vmware.com)

SPDX-License-Identifier: https://spdx.org/licenses/MIT.html

This software is licensed to you under the MIT license (the "License"). You may not use this product except in compliance with the MIT License.

Package reminders holds the application logic to manage reminders (tasks one seeks to remember).

Copyright 2015-2019 VMware, Inc. All Rights Reserved. Author: Tim Green (greent@vmware.com)

SPDX-License-Identifier: https://spdx.org/licenses/MIT.html

Package reminders holds the application logic to manage reminders (tasks one seeks to remember).

Copyright 2015-2019 VMware, Inc. All Rights Reserved. Author: Tom Hite (thite@vmware.com)

SPDX-License-Identifier: https://spdx.org/licenses/MIT.html

Package reminders holds the application logic to manage reminders (tasks one seeks to remember).

Copyright 2015-2019 VMware, Inc. All Rights Reserved. Author: Tom Hite (thite@vmware.com)

SPDX-License-Identifier: https://spdx.org/licenses/MIT.html

Package reminders holds the application logic to manage reminders (tasks one seeks to remember).

Copyright 2015-2019 VMware, Inc. All Rights Reserved. Copyright (c) 2013-2015 Antoine Imbert Author: Tom Hite (thite@vmware.com)

SPDX-License-Identifier: https://spdx.org/licenses/MIT.html

Copyright 2015-2019 VMware, Inc. All Rights Reserved. Copyright (c) 2013-2015 Antoine Imbert Author: Tom Hite (thite@vmware.com)

SPDX-License-Identifier: https://spdx.org/licenses/MIT.html

Copyright 2015-2019 VMware, Inc. All Rights Reserved. Author: Tom Hite (thite@vmware.com)

SPDX-License-Identifier: https://spdx.org/licenses/MIT.html

Copyright 2015-2019 VMware, Inc. All Rights Reserved. Author: Tom Hite (thite@vmware.com)

SPDX-License-Identifier: https://spdx.org/licenses/MIT.html

Index

Constants

View Source
const (
	//MySQL is the name of the driver to use
	MySQL = "mysql"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuth

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

func NewVro

func NewVro(c DBCreds, insecure bool) BasicAuth

func (*BasicAuth) GetDBCredsBasicAuth

func (a *BasicAuth) GetDBCredsBasicAuth(db *DBCreds) error

type Connection

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

Connection holds the connection information to etcd

func NewEtcd

func NewEtcd(host string) Connection

NewEtcd initializes a new instance of the Connection struct

func (*Connection) GetDBCreds

func (conn *Connection) GetDBCreds(d *DBCreds) error

GetDBCreds gets the database credentials from etcd and stores them in the DBCreds struct

func (*Connection) SetDBCreds

func (conn *Connection) SetDBCreds(d *DBCreds)

SetDBCreds stores database credentials from the DBCreds struct in Etcd

type DBCreds

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

DBCreds holds database credentials and connection information.

func (*DBCreds) Address

func (db *DBCreds) Address() string

Address is a getter for the databse host in the DBCreds struct.

func (*DBCreds) Admin

func (db *DBCreds) Admin() string

Admin is a getter for the database user in the DBCreds struct.

func (*DBCreds) CfgSrc

func (db *DBCreds) CfgSrc() string

CfgSrc is a getter for the cfgsrc field in the DBCreds struct.

func (*DBCreds) DBType

func (db *DBCreds) DBType() string

DBType is a getter for the database type in the DBCreds struct.

func (*DBCreds) Extra

func (db *DBCreds) Extra() string

Extra is a getter for the extra field in the DBCreds struct.

func (*DBCreds) FetchCredentials

func (db *DBCreds) FetchCredentials(insecure bool) error

FetchCredentials obtains the database credentials from either Etcd or vRO if not provided on the command line [NOTE]: credentials should be pre-populated at config source.

func (*DBCreds) Init

func (db *DBCreds) Init(host string, port int, admin string, passwd string, dbtype string, dbname string, cfgsrc string, extra string)

Init initializes the DBCreds struct.

func (*DBCreds) Name

func (db *DBCreds) Name() string

Name is a getter for the database name in the DBCreds struct.

func (*DBCreds) Passwd

func (db *DBCreds) Passwd() string

Passwd is a getter for the database password in the DBCreds struct.

func (*DBCreds) Port

func (db *DBCreds) Port() int

Port is a getter for the database host port in the DBCreds struct.

func (*DBCreds) SetAddress

func (db *DBCreds) SetAddress(host string)

SetAddress is a setter for the database host in the DBCreds struct.

func (*DBCreds) SetAdmin

func (db *DBCreds) SetAdmin(admin string)

SetAdmin is a setter for the database user in the DBCreds struct.

func (*DBCreds) SetCfgSrc

func (db *DBCreds) SetCfgSrc(src string)

SetCfgSrc is a setter for the cfgsrc field in the DBCreds struct.

func (*DBCreds) SetDBType

func (db *DBCreds) SetDBType(t string)

SetDBType is a setter for the database type in the DBCreds struct. Acceptable values are "mem" or "mysql".

func (*DBCreds) SetExtra

func (db *DBCreds) SetExtra(e string)

SetExtra is a setter for the extra field in the DBCreds struct.

func (*DBCreds) SetName

func (db *DBCreds) SetName(name string)

SetName is a setter for the database name in the DBCreds struct.

func (*DBCreds) SetPasswd

func (db *DBCreds) SetPasswd(passwd string)

SetPasswd is a setter for the database password in the DBCreds struct.

func (*DBCreds) SetPort

func (db *DBCreds) SetPort(port int)

SetPort is a setter for the database host port in the DBCreds struct.

type MemDB

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

MemDB emulates an in-memory database to store reminders.

func (*MemDB) Close

func (db *MemDB) Close() error

Close terminates the connection to the database.

func (*MemDB) DeleteGUID

func (db *MemDB) DeleteGUID(guid string) (Reminder, error)

DeleteGUID removes the reminder with the given GUID from the database

func (*MemDB) DeleteID

func (db *MemDB) DeleteID(id int64) (Reminder, error)

DeleteID removes the reminder with the given ID from the database.

func (*MemDB) Drop

func (db *MemDB) Drop() error

Drop the database represented by DB.

func (*MemDB) GetAll

func (db *MemDB) GetAll() (*[]Reminder, error)

GetAll returns a list of all reminders in the database

func (*MemDB) GetGUID

func (db *MemDB) GetGUID(guid string) (Reminder, error)

GetGUID returns the reminder stored in the database specified by the given GUID

func (*MemDB) GetID

func (db *MemDB) GetID(id int64) (Reminder, error)

GetID returns the reminder stored in the database specified by the given ID

func (*MemDB) InitDB

func (db *MemDB) InitDB() error

InitDB initialize the database and open it.

func (*MemDB) Save

func (db *MemDB) Save(r Reminder) error

Save stores the given reminder in the database

type MySQLDB

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

MySQLDB holds connection information and credentials for the MySQL database.

func (*MySQLDB) Close

func (db *MySQLDB) Close() error

Close terminates the connection to the database.

func (*MySQLDB) DeleteGUID

func (db *MySQLDB) DeleteGUID(guid string) (Reminder, error)

DeleteGUID removes the reminder with the given GUID from the database.

func (*MySQLDB) DeleteID

func (db *MySQLDB) DeleteID(id int64) (Reminder, error)

DeleteID removes the reminder with the given ID from the database.

func (*MySQLDB) Drop

func (db *MySQLDB) Drop() error

Drop the database represented by DB.

func (*MySQLDB) GetAll

func (db *MySQLDB) GetAll() (*[]Reminder, error)

GetAll returns a list of all reminders in the database.

func (*MySQLDB) GetGUID

func (db *MySQLDB) GetGUID(guid string) (Reminder, error)

GetGUID returns the reminder with the given UUID. If not found, it will return a not found error.

func (*MySQLDB) GetID

func (db *MySQLDB) GetID(id int64) (Reminder, error)

GetID returns the reminder with the given ID. If not found, it will return a not found error.

func (*MySQLDB) InitDB

func (db *MySQLDB) InitDB() error

InitDB Initialize the database and open it.

func (*MySQLDB) Save

func (db *MySQLDB) Save(r Reminder) error

Save stores the given reminder in the database.

type Reminder

type Reminder struct {
	ID        int64     `json:"id"`
	GUID      string    `sql:"size:48;unique_index:idx_guid;size=32" json:"guid"`
	Message   string    `json:"message"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
	DeletedAt time.Time `json:"-"`
}

Reminder is serializable as json (tagged) and also SQL tags provide for best fit database storage (see the Go sql provider for details).

func ArrayFromJson

func ArrayFromJson(jsonData []byte) ([]Reminder, error)

Convert a JSON array of Reminders to Go slice and return.

func FromJson

func FromJson(jsonData []byte) (Reminder, error)

Convert a JSON Reminder to Go struct and return.

type Reminders

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

Reminders holds the Storage and Stats structs.

func NewReminders

func NewReminders(creds DBCreds, stats stats.Stats, insecure bool) (Reminders, error)

NewReminders initialize and returns a new Reminders struct.

func (*Reminders) Delete

func (rem *Reminders) Delete(w rest.ResponseWriter, r *rest.Request)

Handle REST Delete request, which presumes Id as the identifying key.

func (*Reminders) DeleteGuid

func (rem *Reminders) DeleteGuid(w rest.ResponseWriter, r *rest.Request)

Handle REST Delete request using Guid as the identifying key.

func (*Reminders) GetAll

func (rem *Reminders) GetAll(w rest.ResponseWriter, r *rest.Request)

Retrieve all Reminders via REST Get request.

func (*Reminders) GetGuid

func (rem *Reminders) GetGuid(w rest.ResponseWriter, r *rest.Request)

Retrieve one Reminder via REST Get request using guid as key.

func (*Reminders) GetId

func (rem *Reminders) GetId(w rest.ResponseWriter, r *rest.Request)

Retrieve one Reminder via REST Get request using id as key.

func (*Reminders) Post

func (rem *Reminders) Post(w rest.ResponseWriter, r *rest.Request)

Create a new Reminder (REST Post request). This also injects a guid.

func (*Reminders) Put

func (rem *Reminders) Put(w rest.ResponseWriter, r *rest.Request)

Update (REST Put) a Reminder using id as the key.

func (*Reminders) PutGuid

func (rem *Reminders) PutGuid(w rest.ResponseWriter, r *rest.Request)

Update (REST Put) a Reminder using guid as the key.

type Storage

type Storage interface {
	InitDB() error
	Close() error
	Drop() error
	DeleteID(int64) (Reminder, error)
	DeleteGUID(string) (Reminder, error)
	GetAll() (*[]Reminder, error)
	GetID(int64) (Reminder, error)
	GetGUID(string) (Reminder, error)
	Save(r Reminder) error
}

func NewMemDB

func NewMemDB() (Storage, error)

NewMemDB initialize and returns a new storage.

func NewMySQL

func NewMySQL(c DBCreds) (Storage, error)

NewMySQL Initialize and returns a new storage.

Jump to

Keyboard shortcuts

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