Fix lint issues
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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())
|
||||
|
||||
1
main.go
1
main.go
@@ -39,6 +39,7 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
// Hello is method here to be testable.
|
||||
func Hello() string {
|
||||
return "Hello, world!\n"
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user