36 lines
721 B
Go
Executable File
36 lines
721 B
Go
Executable File
package server
|
|
|
|
import (
|
|
"gitea.inhome.blapointe.com/local/notes-server/config"
|
|
"gitea.inhome.blapointe.com/local/notes-server/notes"
|
|
"gitea.inhome.blapointe.com/local/oauth2/oauth2client"
|
|
"gitea.inhome.blapointe.com/local/router"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
type Server struct {
|
|
*router.Router
|
|
Notes *notes.Notes
|
|
}
|
|
|
|
func New() *Server {
|
|
return &Server{
|
|
Router: router.New(),
|
|
Notes: notes.New(),
|
|
}
|
|
}
|
|
|
|
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, "notes-server", w, r)
|
|
if err != nil {
|
|
log.Println(err)
|
|
return
|
|
}
|
|
}
|
|
foo(w, r)
|
|
}
|
|
}
|