-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from bradtumy/release/v1.0.3-rc1
refactored source code to separate code into smaller files
- Loading branch information
Showing
5 changed files
with
477 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func processError(err error) { | ||
fmt.Println(err) | ||
os.Exit(2) | ||
} | ||
|
||
func readFile(cfg *Config) { | ||
f, err := os.Open("resources/properties.yml") | ||
if err != nil { | ||
fmt.Println("ERROR: I couldn't read the properties file.") | ||
processError(err) | ||
} | ||
defer f.Close() | ||
|
||
decoder := yaml.NewDecoder(f) | ||
err = decoder.Decode(cfg) | ||
if err != nil { | ||
fmt.Println("ERROR: I couldn't decode the YAML.") | ||
processError(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
) | ||
|
||
func initializeDatabase(cfg Config) error { | ||
var err error | ||
dbConnectString := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", | ||
cfg.Database.Username, cfg.Database.Password, | ||
cfg.Database.Host, cfg.Database.Port, | ||
cfg.Database.Name) | ||
|
||
db, err = sql.Open("mysql", dbConnectString) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println("MySQL DB Connection Established") | ||
return nil | ||
} |
Oops, something went wrong.