cardiacsociety / web-services

MappCPD API and other services
0 stars 1 forks source link

datastore pkg: remove dependence on env vars #35

Closed mikedonnici closed 6 years ago

mikedonnici commented 6 years ago

The datastore package is directly tied to env vars - time to clean this up.

mikedonnici commented 6 years ago

Trying to keep this simple, and in most cases, a datastore will be set up from the env vars. Here's an example of setting up the datastore with only MySQL:

func main() {

    envr.New("testEnv", []string{
        "MAPPCPD_MYSQL_DESC",
        "MAPPCPD_MYSQL_URL",
    }).Auto()

    ds := datastore.New()
    ds.MySQL = datastore.MySQLConnection{
        DSN:         os.Getenv("MAPPCPD_MYSQL_URL"),
        Description: os.Getenv("MAPPCPD_MYSQL_DESC"),
    }

    err := ds.ConnectMySQL()
    if err != nil {
        fmt.Println(err)
    }

    err = ds.MySQL.Session.Ping()
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println("Connected!")
}
mikedonnici commented 6 years ago

Have completed this one - still need to refactor alg', fixr etc, and write up the datastore README