utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Appname string
View Source
var Appversion string
View Source
var DB *sql.DB

create a global db handle - so can be used across functions

View Source
var DbName string
View Source
var DebugSwitch bool

Global variables injected from main package

View Source
var RecCount int64

Functions

func AddRecord

func AddRecord()

addRecord function adds a new record to the acronym table held in the SQLite database It does not take any parameters. It does not return any information, and exits the program on completion. The application will exit of there is an error attempting to insert the new record into the database.

The SQL insert statement used is:

insert into ACRONYMS(Acronym, Definition, Description, Source)
values(?,?,?,?)

func CheckContinue

func CheckContinue() bool

checkContinue function asks the user if they would like to continue with the currently running part of the application.

checkContinue function reads input from the users console to see if they provide a 'y' or 'n' response.

The function returns a bool depending on the user's response. If the response contains the letter 'y' it returns 'true'. Any other response will return 'false'.

func CheckCount

func CheckCount() int64

CheckCount provides the current total record count in the acronym table. The function takes no inputs. CheckCount function returns the record count as an int64 variable. If an error occurs obtaining the record count from the database it will be printed to stderr.

func CheckDB

func CheckDB() (err error)

checkDB is used to verify if a valid database file name and path has been provided by the user.

The database file name can be provided to the program via the command line or via an environment variable named: ACRODB.

The function checks to ensure the database file name provided exists, obtains its size on disk and checks it file permissions. These items are output to stdout by the function.

The checkDB function returns an error if it fails to find a valid database file or one that can not be opened successfully. If the function fails for any reason the function returns with information summarising the error encountered.

If successful the checkDB function sets the global variable 'Dbname' to the valid path and file name of the SQLite database to be used.

func GetInput

func GetInput(question string) string

getInput function asks the user a question and returns their answer. The question is provided to the function as a string 'question' and the users response is returned by the function as a string 'response'.

func GetSources

func GetSources() string

getSources provide the current 'sources' held in the acronym table getSources function takes no parameters. The getSources functions returns a string contain a list of distinct 'source' records such as "General ICT"

func LastAcronym

func LastAcronym() string

LastAcronym obtains the last acronym entered into the acronym table. The LastAcronym function takes not inputs. The LastAcronym function returns the last acronym entered into the table as a string variable. If an error occurs obtaining the last acronym entered from the database it will be printed to stderr.

SQL statement run is:

SELECT Acronym FROM acronyms Order by rowid DESC LIMIT 1;

func MyUsage

func MyUsage()

myUsage function replaces the standard flag.Usage() function from Go. The function takes no parameters, but outputs the command line flags that can be used when running the program.

func OpenDB

func OpenDB() (err error)

openDB is the function used to open the database and obtain initial information confirming the connection is working, the acronym record count in the database, and the last new acronym record entered.

The openDB function returns an error and error message to explain the problem encountered, or 'nil' if no errors occurred. The function returns no other information as the handle to the database is a global variable.

func OpenDataBase

func OpenDataBase() (err error)

func PopNewDB

func PopNewDB() (err error)

popNewDB function used to open the database and obtain initial information confirming the connection is working, the acronym record count in the database, and the last new acronym record entered.

The openDB function returns an error and error message to explain the problem encountered, or 'nil' if no errors occurred. The function returns no other information as the handle to the database is a global variable.

func PrintBanner

func PrintBanner()

printBanner function is used to print out a small program banner which displays the application name.

func RemoveRecord

func RemoveRecord(rmid string) (err error)

RemoveRecord function is used to remove (ie delete) a record from the Acronyms database. The record to be removed is identified by its 'rowid' number. The record to be removed is first displayed to allow the user to check it is the correct one, and on confirmation the record if removed from the ACRONYMS table.

The 'rowid' of the record is obtained from the user via the command line switch '-r'. This 'rowid' is held in the global variable 'rmid'. The 'rowid' is provided to the function when called as a string value named 'rmid'.

The RemoveRecord function returns either 'nil' as an err value or type error, or details of any actual error that occurs when it runs.

The SQL delete statement used is:

delete from ACRONYMS where rowid = ?;

func SearchRecord

func SearchRecord(searchTerm string)

searchRecord function obtains a string from the users and search for it in the SQLite acronyms database. It does not take any parameters. It does not return any information, and exits the program on completion. The application will exit of there is an error.

The SQL select statement used is:

select rowid,Acronym,Definition,Description,Source from ACRONYMS where
Acronym like ? ORDER BY Source;

func SqlVersion

func SqlVersion() string

SqlVersion provides the version of SQLite library that is being used by the program. The function take no parameters. The SqlVersion function returns a string with a version number obtained by running the SQLite3 statement:

SELECT SQLITE_VERSION();

func VersionInfo

func VersionInfo()

versionInfo function collects details of the program being run and displays it on stdout

Types

This section is empty.

Jump to

Keyboard shortcuts

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