-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoints.go
43 lines (34 loc) · 1.01 KB
/
endpoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package router
import (
"context"
"net/http"
"regexp"
// Packages
server "github.com/mutablelogic/go-server"
httpresponse "github.com/mutablelogic/go-server/pkg/httpresponse"
)
///////////////////////////////////////////////////////////////////////////////
// GLOBALS
const (
jsonIndent = 2
)
var (
reRoot = regexp.MustCompile(`^/?$`)
)
///////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS - ENDPOINTS
// Add endpoints to the router
func (service *router) AddEndpoints(ctx context.Context, r server.Router) {
// Path: /
// Methods: GET
// Scopes: read
// Description: Get router services
r.AddHandlerFuncRe(ctx, reRoot, service.GetScopes, http.MethodGet).(Route).
SetScope(service.ScopeRead()...)
}
///////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// Get registered scopes
func (service *router) GetScopes(w http.ResponseWriter, r *http.Request) {
httpresponse.JSON(w, service.Scopes(), http.StatusOK, jsonIndent)
}