-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsrequest.go
51 lines (44 loc) · 1.31 KB
/
wsrequest.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
44
45
46
47
48
49
50
51
package cutil
import (
"context"
"fmt"
"path/filepath"
"github.com/valyala/fasthttp"
"admini.dev/admini/app/action"
"admini.dev/admini/app/lib/schema"
"admini.dev/admini/app/project"
"admini.dev/admini/app/source"
)
type WorkspaceRequest struct {
T string `json:"t"`
K string `json:"k"`
RC *fasthttp.RequestCtx `json:"-"`
PS *PageState `json:"-"`
Item any `json:"item,omitempty"`
Path []string `json:"path,omitempty"`
Project *project.Project `json:"-"`
Sources source.Sources `json:"-"`
Schemata schema.Schemata `json:"-"`
Context context.Context `json:"-"`
}
func (r *WorkspaceRequest) Route(path ...string) string {
url := fmt.Sprintf("/%s/%s", r.T, r.K)
if len(path) > 0 {
url += "/" + filepath.Join(path...)
}
return url
}
func (r *WorkspaceRequest) RouteAct(act *action.Action, drop int, path ...string) string {
end := len(r.Path) - drop
if end < 0 {
end = 0
}
return r.Route(append(append(act.Path(), r.Path[:end]...), path...)...)
}
func (r *WorkspaceRequest) Clone() *WorkspaceRequest {
return &WorkspaceRequest{
T: r.T, K: r.K, RC: r.RC, PS: r.PS,
Item: r.Item, Path: r.Path, Project: r.Project,
Sources: r.Sources, Schemata: r.Schemata, Context: r.Context,
}
}