48 lines
946 B
Go
48 lines
946 B
Go
package queue
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"forge.cadoles.com/Cadoles/go-proxy"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/proxy/director"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/store"
|
|
"github.com/davecgh/go-spew/spew"
|
|
)
|
|
|
|
const LayerType store.LayerType = "queue"
|
|
|
|
type Queue struct {
|
|
repository Repository
|
|
}
|
|
|
|
// LayerType implements director.MiddlewareLayer
|
|
func (*Queue) LayerType() store.LayerType {
|
|
return LayerType
|
|
}
|
|
|
|
// Middleware implements director.MiddlewareLayer
|
|
func (*Queue) Middleware(layer *store.Layer) proxy.Middleware {
|
|
return func(h http.Handler) http.Handler {
|
|
fn := func(w http.ResponseWriter, r *http.Request) {
|
|
spew.Dump(layer)
|
|
|
|
h.ServeHTTP(w, r)
|
|
}
|
|
|
|
return http.HandlerFunc(fn)
|
|
}
|
|
}
|
|
|
|
func New(repository Repository, funcs ...OptionFunc) *Queue {
|
|
opts := defaultOptions()
|
|
for _, fn := range funcs {
|
|
fn(opts)
|
|
}
|
|
|
|
return &Queue{
|
|
repository: repository,
|
|
}
|
|
}
|
|
|
|
var _ director.MiddlewareLayer = &Queue{}
|