-
Notifications
You must be signed in to change notification settings - Fork 2
/
endpoint.go
40 lines (33 loc) · 995 Bytes
/
endpoint.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
package rest
import (
"fmt"
"net/http"
)
const apiRootAppPath = "/api/"
const healthCheckPath = "/_ah/"
const backupPath = "backups"
const bucketsPath = "buckets"
const datasetsPath = "datasets"
const restorePath = "restore"
const tasksPath = "tasks"
const userPath = "users"
// Endpoint for a HTTP requests
type Endpoint struct {
root string
path string
authEnabled bool
handler http.HandlerFunc
methods []string
}
func newAPIEndpoint(path string, authEnabled bool, handler http.HandlerFunc, methods []string) *Endpoint {
return &Endpoint{apiRootAppPath, path, authEnabled, handler, methods}
}
func newCustomEndpoint(root string, path string, authEnabled bool, handler http.HandlerFunc, methods []string) *Endpoint {
return &Endpoint{root, path, authEnabled, handler, methods}
}
func (a *Endpoint) pathWithoutTrailingSlash() string {
return fmt.Sprintf("%s%s", a.root, a.path)
}
func (a *Endpoint) String() string {
return a.pathWithoutTrailingSlash()
}