-
Notifications
You must be signed in to change notification settings - Fork 6
/
types.go
43 lines (32 loc) · 920 Bytes
/
types.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 restli
import (
"strings"
"github.com/PapaCharlie/go-restli/restlicodec"
)
type ResourcePath interface {
RootResource() string
ResourcePath() (path string, err error)
}
type ResourcePathUnmarshaler[T any] interface {
NewInstance() T
UnmarshalResourcePath(segments []restlicodec.Reader) error
}
func UnmarshalResourcePath[T ResourcePathUnmarshaler[T]](segments []restlicodec.Reader) (t T, err error) {
t = t.NewInstance()
return t, t.UnmarshalResourcePath(segments)
}
type ResourcePathString string
func (s ResourcePathString) RootResource() string {
root, _, _ := strings.Cut(string(s[1:]), "/")
return root
}
func (s ResourcePathString) ResourcePath() (string, error) {
return string(s), nil
}
type QueryParamsEncoder interface {
EncodeQueryParams() (string, error)
}
type QueryParamsString string
func (q QueryParamsString) EncodeQueryParams() (string, error) {
return string(q), nil
}