mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-11 14:39:09 -06:00
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package svc
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi"
|
|
"github.com/go-chi/chi/middleware"
|
|
)
|
|
|
|
// Service defines the extension handlers.
|
|
type Service interface {
|
|
ServeHTTP(http.ResponseWriter, *http.Request)
|
|
GetMe(http.ResponseWriter, *http.Request)
|
|
GetUsers(http.ResponseWriter, *http.Request)
|
|
GetUser(http.ResponseWriter, *http.Request)
|
|
}
|
|
|
|
// NewService returns a service implementation for Service.
|
|
func NewService(opts ...Option) Service {
|
|
options := newOptions(opts...)
|
|
|
|
m := chi.NewMux()
|
|
m.Use(options.Middleware...)
|
|
|
|
svc := Graph{
|
|
config: options.Config,
|
|
mux: m,
|
|
logger: &options.Logger,
|
|
}
|
|
|
|
m.Route(options.Config.HTTP.Root, func(r chi.Router) {
|
|
r.Use(middleware.StripSlashes)
|
|
r.Route("/v1.0", func(r chi.Router) {
|
|
r.Route("/me", func(r chi.Router) {
|
|
r.Get("/", svc.GetMe)
|
|
r.Get("/drive/root/children", svc.GetRootDriveChildren)
|
|
})
|
|
r.Route("/users", func(r chi.Router) {
|
|
r.Get("/", svc.GetUsers)
|
|
r.Route("/{userID}", func(r chi.Router) {
|
|
r.Use(svc.UserCtx)
|
|
r.Get("/", svc.GetUser)
|
|
})
|
|
})
|
|
r.Route("/groups", func(r chi.Router) {
|
|
r.Get("/", svc.GetGroups)
|
|
r.Route("/{groupID}", func(r chi.Router) {
|
|
r.Use(svc.GroupCtx)
|
|
r.Get("/", svc.GetGroup)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
return svc
|
|
}
|