Skip to content

Commit

Permalink
rewrote router using chi lib
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Jul 31, 2024
1 parent d4057d4 commit a15f8d3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 57 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/dolthub/go-mysql-server v0.14.0
github.com/gdexlab/go-render v1.0.1
github.com/glpatcern/go-mime v0.0.0-20221026162842-2a8d71ad17a9
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/chi/v5 v5.1.0
github.com/go-ldap/ldap/v3 v3.4.6
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,8 @@ github.com/go-asn1-ber/asn1-ber v1.5.5 h1:MNHlNMBDgEKD4TcKr36vQN68BA00aDfjIt3/bD
github.com/go-asn1-ber/asn1-ber v1.5.5/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g=
github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks=
github.com/go-fonts/liberation v0.1.1/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY=
Expand Down
82 changes: 26 additions & 56 deletions internal/http/services/owncloud/ocgraph/ocgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/rhttp/global"
"github.com/cs3org/reva/pkg/rhttp/router"
"github.com/cs3org/reva/pkg/sharedconf"
"github.com/cs3org/reva/pkg/utils/cfg"
"github.com/go-chi/chi/v5"
)

func init() {
Expand All @@ -47,7 +47,8 @@ func (c *config) ApplyDefaults() {
}

type svc struct {
c *config
c *config
router *chi.Mux
}

func New(ctx context.Context, m map[string]interface{}) (global.Service, error) {
Expand All @@ -59,68 +60,37 @@ func New(ctx context.Context, m map[string]interface{}) (global.Service, error)
s := &svc{
c: &c,
}
s.initRouter()

return s, nil
}

func (s *svc) initRouter() {
s.router = chi.NewRouter()

s.router.Route("/v1.0", func(r chi.Router) {
r.Route("/me", func(r chi.Router) {
r.Get("/", s.getMe)
r.Route("/drives", func(r chi.Router) {
r.Get("/", s.listMySpaces)

})
})
r.Route("/drives", func(r chi.Router) {
r.Get("/{space-id}", s.getSpace)
})
})
s.router.Route("/v1beta1", func(r chi.Router) {
r.Get("/me/drive/sharedWithMe", s.getSharedWithMe)
r.Get("/roleManagement/permissions/roleDefinitions", s.getRoleDefinitions)
})
}

func (s *svc) getClient() (gateway.GatewayAPIClient, error) {
return pool.GetGatewayServiceClient(pool.Endpoint(s.c.GatewaySvc))
}

func (s *svc) Handler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var head string
head, r.URL.Path = router.ShiftPath(r.URL.Path)

if head == "v1.0" {
head, r.URL.Path = router.ShiftPath(r.URL.Path)
switch head {
case "drives":
s.getSpace(w, r)
return
case "me":
head, r.URL.Path = router.ShiftPath(r.URL.Path)
switch head {
case "":
s.getMe(w, r)
return
case "drives":
s.listMySpaces(w, r)
return
}
}
} else if head == "v1beta1" {
head, r.URL.Path = router.ShiftPath(r.URL.Path)
// https://demo.owncloud.com/graph/v1beta1/me/drive/sharedWithMe
switch head {
case "me":
head, r.URL.Path = router.ShiftPath(r.URL.Path)
switch head {
case "drive":
head, r.URL.Path = router.ShiftPath(r.URL.Path)
switch head {
case "sharedWithMe":
s.getSharedWithMe(w, r)
return
}
}
case "roleManagement":
head, r.URL.Path = router.ShiftPath(r.URL.Path)
switch head {
case "permissions":
head, r.URL.Path = router.ShiftPath(r.URL.Path)
switch head {
case "roleDefinitions":
s.getRoleDefinitions(w, r)
return
}
}
}
}

w.WriteHeader(http.StatusNotFound)
})
}
func (s *svc) Handler() http.Handler { return s.router }

func (s *svc) Prefix() string { return "graph" }

Expand Down
4 changes: 4 additions & 0 deletions internal/http/services/owncloud/ocgraph/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,7 @@ func (s *svc) cs3GranteeToSharePointIdentitySet(ctx context.Context, grantee *pr

return p, nil
}

func (s *svc) getSharedByMe(w http.ResponseWriter, r *http.Request) {

}

0 comments on commit a15f8d3

Please sign in to comment.