Skip to content

Commit

Permalink
Merge pull request #17 from bradtumy/release/v1.0.3-rc1
Browse files Browse the repository at this point in the history
refactored source code to separate code into smaller files
  • Loading branch information
bradtumy authored Jul 28, 2024
2 parents 1da0700 + c756055 commit b0e79f7
Show file tree
Hide file tree
Showing 5 changed files with 477 additions and 469 deletions.
29 changes: 29 additions & 0 deletions config.go
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)
}
}
23 changes: 23 additions & 0 deletions database.go
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
}
Loading

0 comments on commit b0e79f7

Please sign in to comment.