Skip to content

Commit

Permalink
Resolve many breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondl committed May 8, 2020
1 parent ed6cab8 commit 402e9f7
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 322 deletions.
3 changes: 0 additions & 3 deletions PACKAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ Thank you for your continued efforts.
* [github.com/stretchr/testify/require](https://github.com/stretchr/testify/require)
* [github.com/unrolled/render](https://github.com/unrolled/render)
* [github.com/volatiletech/sqlboiler](https://github.com/volatiletech/sqlboiler)
* [github.com/volatiletech/sqlboiler/v4/bdb](https://github.com/volatiletech/sqlboiler/v4/bdb)
* [github.com/volatiletech/sqlboiler/v4/bdb/drivers](https://github.com/volatiletech/sqlboiler/v4/bdb/drivers)
* [github.com/volatiletech/sqlboiler/v4/strmangle](https://github.com/volatiletech/sqlboiler/v4/strmangle)
* [github.com/volatiletech/abcweb/abcmiddleware](https://github.com/volatiletech/abcweb/abcmiddleware)
* [github.com/volatiletech/abcweb/abcrender](https://github.com/volatiletech/abcweb/abcrender)
* [github.com/volatiletech/abcweb/abcsessions](https://github.com/volatiletech/abcweb/abcsessions)
Expand Down
11 changes: 4 additions & 7 deletions abcdatabase/database.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package abcdatabase

import (
"bytes"
"database/sql"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/pkg/errors"
"github.com/volatiletech/abcweb/abcconfig"
"github.com/volatiletech/helpers/git"
"github.com/volatiletech/mig"
)

Expand Down Expand Up @@ -60,7 +57,7 @@ func RunMigrations(cfg abcconfig.DBConfig, migrationsPath string) (int, error) {
return 0, err
}

count, err := mig.Up(cfg.DB, connStr, migrationsPath)
count, err := mig.Up("postgres", connStr, migrationsPath)
if err != nil {
return count, err
}
Expand All @@ -82,7 +79,7 @@ func IsMigrated(cfg abcconfig.DBConfig) (bool, int64, error) {
return false, 0, err
}

version, err := mig.Version(cfg.DB, connStr)
version, err := mig.Version("postgres", connStr)
if err != nil {
return false, version, err
}
Expand Down Expand Up @@ -112,4 +109,4 @@ func isLatestVersion(dbVersion int64, files []os.FileInfo) bool {
}

return highestVersion == dbVersion
}
}
13 changes: 7 additions & 6 deletions abcmiddleware/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ type ErrorContainer struct {
Handler ErrorHandler
}

type errorManager struct {
// ErrorManager helps manage errors at the application level
type ErrorManager struct {
render abcrender.Renderer
errors []ErrorContainer
}

// NewErrorManager creates an error manager that can be used to
// create an error handler to wrap your controllers with
func NewErrorManager(render abcrender.Renderer) *errorManager {
return &errorManager{
func NewErrorManager(render abcrender.Renderer) *ErrorManager {
return &ErrorManager{
render: render,
errors: []ErrorContainer{},
}
Expand Down Expand Up @@ -67,7 +68,7 @@ func NewError(err error, code int, template string, handler ErrorHandler) ErrorC
}

// Remove a ErrorContainer from the error manager
func (m *errorManager) Remove(e ErrorContainer) {
func (m *ErrorManager) Remove(e ErrorContainer) {
for i, v := range m.errors {
if reflect.DeepEqual(v, e) {
m.errors = append(m.errors[:i], m.errors[i+1:]...)
Expand All @@ -76,7 +77,7 @@ func (m *errorManager) Remove(e ErrorContainer) {
}

// Add a new ErrorContainer to the error manager
func (m *errorManager) Add(e ErrorContainer) {
func (m *ErrorManager) Add(e ErrorContainer) {
m.errors = append(m.errors, e)
}

Expand All @@ -91,7 +92,7 @@ type ErrorHandler func(w http.ResponseWriter, r *http.Request, e ErrorContainer,
// errors directly in your controller is that it's all centralized to one
// location which simplifies adding notifiers (like slack and email).
// It also reduces a lot of controller boilerplate.
func (m *errorManager) Errors(ctrl AppHandler) http.HandlerFunc {
func (m *ErrorManager) Errors(ctrl AppHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
err := ctrl(w, r)
if err == nil {
Expand Down
9 changes: 0 additions & 9 deletions abcmiddleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@ package abcmiddleware

import (
"net/http"

"go.uber.org/zap"
)

// MiddlewareFunc is the function signature for Chi's Use() middleware
type MiddlewareFunc func(http.Handler) http.Handler

// Middleware exposes useful variables to every abcmiddleware handler
type Middleware struct {
// Log is used for logging in your middleware and to
// create a derived logger that includes the request ID.
Log *zap.Logger
}

// MW is an interface defining middleware wrapping
type MW interface {
Wrap(http.Handler) http.Handler
Expand Down
4 changes: 2 additions & 2 deletions abcserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewNotFoundHandler(manifest map[string]string) *NotFound {
func (n *NotFound) Handler(cfg abcconfig.ServerConfig, render abcrender.Renderer) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Get the Request ID scoped logger
log := abcmiddleware.Log(r)
log := abcmiddleware.Logger(r)

reqPath := r.URL.Path
// Ensure path is rooted at / to prevent path traversal
Expand Down Expand Up @@ -168,7 +168,7 @@ func (n *NotFound) Handler(cfg abcconfig.ServerConfig, render abcrender.Renderer
func (m *MethodNotAllowed) Handler(render abcrender.Renderer) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Get the Request ID scoped logger
log := abcmiddleware.Log(r)
log := abcmiddleware.Logger(r)

log.Warn("method not allowed",
zap.String("method", r.Method),
Expand Down
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type migrateConfig struct {

type newConfig struct {
AppPath string `toml:"app-path"`
TemplatePath string `toml:"template-path"`
ImportPath string `toml:"import-path"`
AppName string `toml:"app-name"`
AppEnvName string `toml:"app-env-name"`
Expand Down
Loading

0 comments on commit 402e9f7

Please sign in to comment.