diff --git a/config/config.go b/config/config.go index b8924b6..f48d341 100644 --- a/config/config.go +++ b/config/config.go @@ -7,8 +7,10 @@ import ( "github.com/spf13/viper" ) +// Key represents a particular config flag. type Key string +// These constants are the list of keys that can be used. const ( Environment Key = `app.environment` Port Key = `app.port` @@ -20,18 +22,17 @@ const ( DBDatabase Key = `db.database` ) +// GetString returns the string value of the provided config key. func (k Key) GetString() string { return viper.GetString(string(k)) } -func InitDefault() { +// Init sets all of the viper config parameters. +func Init() { viper.SetDefault(string(Environment), "local") viper.SetDefault(string(Port), "8080") -} - -func Init() { log.Print("Initialising config...") viper.SetConfigName("config") viper.SetConfigType("yaml") diff --git a/db/postgres.go b/db/postgres.go index 1fe4413..33a40fe 100644 --- a/db/postgres.go +++ b/db/postgres.go @@ -12,6 +12,8 @@ import ( "gitea.deepak.science/deepak/gogmagog/util" "github.com/golang-migrate/migrate/v4" "github.com/golang-migrate/migrate/v4/database/postgres" + + // Blank imports to provide drivers. _ "github.com/golang-migrate/migrate/v4/source/file" _ "github.com/jackc/pgx/v4/stdlib" ) @@ -20,7 +22,8 @@ type postgresStore struct { db *sqlx.DB } -func GetStore() *postgresStore { +// GetStore provides a store to back the model based on a postgres connection. +func GetStore() models.Store { if config.DBType.GetString() != "postgres" { log.Fatalf("Unsupported database type: " + config.DBType.GetString()) diff --git a/main.go b/main.go index 3c2374a..92bab00 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ func main() { } +// Hello is method here to be testable. func Hello() string { return "Hello, world!\n" } diff --git a/models/action.go b/models/action.go index e45e6c7..3e2962b 100644 --- a/models/action.go +++ b/models/action.go @@ -4,6 +4,7 @@ import ( "time" ) +// Action represents a single action item. type Action struct { ActionID int64 ActionDescription string @@ -11,6 +12,7 @@ type Action struct { UpdatedAt time.Time } +// Actions returns all actions from the model. func (m *Model) Actions() ([]*Action, error) { return m.SelectActions() } diff --git a/models/models.go b/models/models.go index 68cf2c5..87d2194 100644 --- a/models/models.go +++ b/models/models.go @@ -1,14 +1,17 @@ package models -type store interface { +// Store represents the backing store. +type Store interface { SelectActions() ([]*Action, error) SelectPlans() ([]*Plan, error) } +// Model represents a current model item. type Model struct { - store + Store } -func New(store store) *Model { - return &Model{store: store} +// New creates an instance of the model using the passed in store. +func New(store Store) *Model { + return &Model{Store: store} } diff --git a/models/plan.go b/models/plan.go index 9080663..fff145b 100644 --- a/models/plan.go +++ b/models/plan.go @@ -4,11 +4,13 @@ import ( "time" ) +// Plan represents a single day's agenda of actions. type Plan struct { PlanID int64 PlanDate time.Time } +// Plans returns all plans in the model. func (m *Model) Plans() ([]*Plan, error) { return m.SelectPlans() } diff --git a/util/snake.go b/util/snake.go index cb368bf..68d5ca0 100644 --- a/util/snake.go +++ b/util/snake.go @@ -2,6 +2,7 @@ package util import "unicode" +// ToSnake converts CamelCase to snake_case. func ToSnake(in string) string { runes := []rune(in) length := len(runes)