Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move middlewares into handlers package (#204)
* Add NewEndpoints method * Move middlewares to handlers package * Move package handler to handlers * Combine endpoint and service middlewares into one file
- Loading branch information
Showing
24 changed files
with
178 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gengokit/handler/handler_test.go → gengokit/handlers/handler_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package handler | ||
package handlers | ||
|
||
import ( | ||
"go/ast" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package handlers | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/TuneLab/truss/gengokit" | ||
"github.com/TuneLab/truss/gengokit/handlers/templates" | ||
) | ||
|
||
// MiddlewaresPath is the path to the middleware gotemplate file. | ||
const MiddlewaresPath = "handlers/middlewares.gotemplate" | ||
|
||
// NewMiddleware returns a Renderable that renders the middlewares.go file. | ||
func NewMiddlewares() *Middlewares { | ||
var m Middlewares | ||
|
||
return &m | ||
} | ||
|
||
// Middlewares satisfies the gengokit.Renderable interface to render | ||
// middlewares. | ||
type Middlewares struct { | ||
prev io.Reader | ||
} | ||
|
||
// Load loads the previous version of the middleware file. | ||
func (m *Middlewares) Load(prev io.Reader) { | ||
m.prev = prev | ||
} | ||
|
||
// Render creates the middlewares.go file. With no previous version it renders | ||
// the templates, if there was a previous version loaded in, it passes that | ||
// through. | ||
func (m *Middlewares) Render(path string, data *gengokit.Data) (io.Reader, error) { | ||
if path != MiddlewaresPath { | ||
return nil, errors.Errorf("cannot render unknown file: %q", path) | ||
} | ||
if m.prev != nil { | ||
return m.prev, nil | ||
} | ||
return data.ApplyTemplate(templates.Middlewares, "Middlewares") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.