Write docs!

This commit is contained in:
nemunaire 2018-03-09 19:07:08 +01:00
commit bcc598ebd5
37 changed files with 478 additions and 188 deletions

View file

@ -8,8 +8,10 @@ import (
_ "github.com/go-sql-driver/mysql"
)
// db stores the connection to the database
var db *sql.DB
// DSNGenerator returns DSN filed with values from environment
func DSNGenerator() string {
db_user := "fic"
db_password := "fic"
@ -35,6 +37,7 @@ func DSNGenerator() string {
return db_user + ":" + db_password + "@" + db_host + "/" + db_db
}
// DBInit establishes the connection to the database
func DBInit(dsn string) (err error) {
if db, err = sql.Open("mysql", dsn + "?parseTime=true&foreign_key_checks=1"); err != nil {
return
@ -51,6 +54,7 @@ func DBInit(dsn string) (err error) {
return
}
// DBCreate creates all necessary tables used by the package
func DBCreate() error {
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS events(
@ -284,6 +288,7 @@ CREATE TABLE IF NOT EXISTS claim_descriptions(
return nil
}
// DBClose closes the connection to the database
func DBClose() error {
return db.Close()
}