@ -9,9 +9,9 @@ import (
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"github.com/mxschmitt/golang-url-shortener/handlers/tmpls"
"github.com/mxschmitt/golang-url-shortener/internal/ handlers/tmpls"
"github.com/mxschmitt/golang-url-shortener/stores"
"github.com/mxschmitt/golang-url-shortener/internal/ stores"
"github.com/mxschmitt/golang-url-shortener/util"
"github.com/mxschmitt/golang-url-shortener/internal/ util"
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
@ -145,13 +145,14 @@ func (h *Handler) setHandlers() error {
}
}
}
}
protected := h . engine . Group ( "/api/v1/protected" )
protected := h . engine . Group ( "/api/v1/protected" )
if util . GetConfig ( ) . AuthBackend == "oauth" {
switch util . GetConfig ( ) . AuthBackend {
logrus . Info ( "Using OAuth auth backend" )
case "oauth" :
logrus . Info ( "Using OAuth auth backend: oauth" )
protected . Use ( h . oAuthMiddleware )
protected . Use ( h . oAuthMiddleware )
} else if util . GetConfig ( ) . AuthBackend == "proxy" {
case "proxy" :
logrus . Info ( "Using proxy auth backend " )
logrus . Info ( "Using OAuth auth backend: proxy " )
protected . Use ( h . proxyAuthMiddleware )
protected . Use ( h . proxyAuthMiddleware )
} else {
default :
logrus . Fatalf ( "Auth backend method '%s' is not recognized" , util . GetConfig ( ) . AuthBackend )
logrus . Fatalf ( "Auth backend method '%s' is not recognized" , util . GetConfig ( ) . AuthBackend )
}
}
protected . POST ( "/create" , h . handleCreate )
protected . POST ( "/create" , h . handleCreate )