Compare commits
2 Commits
4b8fd5d78a
...
403295b2b4
| Author | SHA1 | Date | |
|---|---|---|---|
|
403295b2b4
|
|||
|
1c00a06c10
|
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@@ -40,7 +40,7 @@ pipeline {
|
|||||||
PATH="${env.PATH}:${env.GOPATH}/bin"
|
PATH="${env.PATH}:${env.GOPATH}/bin"
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'golint ./...'
|
sh 'golint -set_exit_status ./...'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Key represents a particular config flag.
|
||||||
type Key string
|
type Key string
|
||||||
|
|
||||||
|
// These constants are the list of keys that can be used.
|
||||||
const (
|
const (
|
||||||
Environment Key = `app.environment`
|
Environment Key = `app.environment`
|
||||||
Port Key = `app.port`
|
Port Key = `app.port`
|
||||||
@@ -20,18 +22,17 @@ const (
|
|||||||
DBDatabase Key = `db.database`
|
DBDatabase Key = `db.database`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetString returns the string value of the provided config key.
|
||||||
func (k Key) GetString() string {
|
func (k Key) GetString() string {
|
||||||
return viper.GetString(string(k))
|
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(Environment), "local")
|
||||||
viper.SetDefault(string(Port), "8080")
|
viper.SetDefault(string(Port), "8080")
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func Init() {
|
|
||||||
log.Print("Initialising config...")
|
log.Print("Initialising config...")
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.SetConfigType("yaml")
|
viper.SetConfigType("yaml")
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import (
|
|||||||
"gitea.deepak.science/deepak/gogmagog/util"
|
"gitea.deepak.science/deepak/gogmagog/util"
|
||||||
"github.com/golang-migrate/migrate/v4"
|
"github.com/golang-migrate/migrate/v4"
|
||||||
"github.com/golang-migrate/migrate/v4/database/postgres"
|
"github.com/golang-migrate/migrate/v4/database/postgres"
|
||||||
|
|
||||||
|
// Blank imports to provide drivers.
|
||||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||||
_ "github.com/jackc/pgx/v4/stdlib"
|
_ "github.com/jackc/pgx/v4/stdlib"
|
||||||
)
|
)
|
||||||
@@ -20,7 +22,8 @@ type postgresStore struct {
|
|||||||
db *sqlx.DB
|
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" {
|
if config.DBType.GetString() != "postgres" {
|
||||||
log.Fatalf("Unsupported database type: " + config.DBType.GetString())
|
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 {
|
func Hello() string {
|
||||||
return "Hello, world!\n"
|
return "Hello, world!\n"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Action represents a single action item.
|
||||||
type Action struct {
|
type Action struct {
|
||||||
ActionID int64
|
ActionID int64
|
||||||
ActionDescription string
|
ActionDescription string
|
||||||
@@ -11,6 +12,7 @@ type Action struct {
|
|||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actions returns all actions from the model.
|
||||||
func (m *Model) Actions() ([]*Action, error) {
|
func (m *Model) Actions() ([]*Action, error) {
|
||||||
return m.SelectActions()
|
return m.SelectActions()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type store interface {
|
// Store represents the backing store.
|
||||||
|
type Store interface {
|
||||||
SelectActions() ([]*Action, error)
|
SelectActions() ([]*Action, error)
|
||||||
SelectPlans() ([]*Plan, error)
|
SelectPlans() ([]*Plan, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Model represents a current model item.
|
||||||
type Model struct {
|
type Model struct {
|
||||||
store
|
Store
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(store store) *Model {
|
// New creates an instance of the model using the passed in store.
|
||||||
return &Model{store: store}
|
func New(store Store) *Model {
|
||||||
|
return &Model{Store: store}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Plan represents a single day's agenda of actions.
|
||||||
type Plan struct {
|
type Plan struct {
|
||||||
PlanID int64
|
PlanID int64
|
||||||
PlanDate time.Time
|
PlanDate time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Plans returns all plans in the model.
|
||||||
func (m *Model) Plans() ([]*Plan, error) {
|
func (m *Model) Plans() ([]*Plan, error) {
|
||||||
return m.SelectPlans()
|
return m.SelectPlans()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package util
|
|||||||
|
|
||||||
import "unicode"
|
import "unicode"
|
||||||
|
|
||||||
|
// ToSnake converts CamelCase to snake_case.
|
||||||
func ToSnake(in string) string {
|
func ToSnake(in string) string {
|
||||||
runes := []rune(in)
|
runes := []rune(in)
|
||||||
length := len(runes)
|
length := len(runes)
|
||||||
|
|||||||
Reference in New Issue
Block a user