Pass things around via query params

This commit is contained in:
bel
2019-10-20 16:39:26 -06:00
parent fb02cc994a
commit da6eaca26f
2 changed files with 27 additions and 8 deletions

View File

@@ -2,7 +2,10 @@ package server
import (
"fmt"
"local/notes-server/config"
"local/oauth2/oauth2client"
"local/router"
"log"
"net/http"
)
@@ -14,19 +17,19 @@ func (s *Server) Routes() error {
}{
{
path: fmt.Sprintf("notes/%s%s", wildcard, wildcard),
handler: s.notes,
handler: s.authenticate(s.notes),
},
{
path: fmt.Sprintf("edit/%s%s", wildcard, wildcard),
handler: s.edit,
handler: s.authenticate(s.edit),
},
{
path: fmt.Sprintf("submit/%s%s", wildcard, wildcard),
handler: s.submit,
handler: s.authenticate(s.submit),
},
{
path: fmt.Sprintf("create/%s%s", wildcard, wildcard),
handler: s.create,
handler: s.authenticate(s.create),
},
}
@@ -37,3 +40,16 @@ func (s *Server) Routes() error {
}
return nil
}
func (s *Server) authenticate(foo http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if config.OAuthServer != "" {
err := oauth2client.Authenticate(config.OAuthServer, w, r)
if err != nil {
log.Println(err)
return
}
}
foo(w, r)
}
}