Documentation ¶
Index ¶
- Variables
- func EmployeeDelete(db interface{ ... }, employee *Employee) error
- func GenerateID() string
- func Initialize(config *Configuration) (*sql.DB, error)
- func Main(pwd string, args []string, envs map[string]string, osSignal chan os.Signal) error
- func RowsAffected(result sql.Result, errorString string) error
- func TimerDelete(db interface{ ... }, timerID string) error
- type Configuration
- type DB
- type Employee
- type Timer
Constants ¶
This section is empty.
Variables ¶
var ( Version string GitCommit string GitBranch string )
These variables are populated at build time REFERENCE: https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications to find where the variables are...
go tool nm ./app | grep app
Functions ¶
func EmployeeDelete ¶
func EmployeeDelete(db interface { Exec(query string, args ...interface{}) (sql.Result, error) }, employee *Employee) error
EmployeeDelete can be used to delete a specific employee or all employees
func GenerateID ¶
func GenerateID() string
GenerateID can be used to generate a v4 uuid and return it as a string, if it's unable to, it'll panic
func Initialize ¶
func Initialize(config *Configuration) (*sql.DB, error)
Initialize can be used to create a database pointer with the provided configuration
func RowsAffected ¶
RowsAffected can be used to return a pre-determined error via errorString in the event no rows are affected; this function assumes that in the event no error is returned and rows were supposed to be affected, an error will be returned
Types ¶
type Configuration ¶
type Configuration struct { Hostname string `json:"hostname"` //hostame to user to access the database Port string `json:"port"` //port to connect to Username string `json:"username"` //username to authenticate with Password string `json:"password"` //password to authenticate with Database string `json:"database"` //database to connect to ParseTime bool `json:"parse_time"` //whether or not to parse time }
Configuration provides the different items we can use to configure how we connect to the database
func ConfigFromEnv ¶
func ConfigFromEnv(envs map[string]string) *Configuration
ConfigFromEnv can be used to generate a configuration pointer from a list of environments, it'll set the default configuraton as well
type DB ¶
type DB interface { Begin() (*sql.Tx, error) Exec(query string, args ...interface{}) (sql.Result, error) QueryRow(query string, args ...interface{}) *sql.Row Query(query string, args ...interface{}) (*sql.Rows, error) }
DB provides an interface that implements all functions required by the DB
type Employee ¶
type Employee struct { ID string `json:"id"` FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` EmailAddress string `json:"email_address"` Version int `json:"version"` LastUpdated int64 `json:"last_updated"` }
Employee models the information that describes an employee
func EmployeeCreate ¶
func EmployeeCreate(db interface { QueryRow(query string, args ...interface{}) *sql.Row }, employee *Employee) (*Employee, error)
EmployeeCreate can be used to upsert an employee, if the employee exists via its candidate keys, it'll return that employee rather than create its own
func EmployeeRead ¶
type Timer ¶
type Timer struct { ID string `json:"id"` Comment string `json:"comment"` Start int64 `json:"start"` Finish int64 `json:"finish"` ElapsedTime int64 `json:"elapsed_time"` Completed bool `json:"completed"` Version int `json:"version"` EmployeeID string `json:"employee_id"` }
Timer models a given timer with a start/stop time, its specifically used to show the relationship between timers and employees
func TimerCreate ¶
TimerCreate can be used to create a timer, if the timer already exists it'll return that timer and update that timer