forked from hcarriz/go-bookstack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.go
More file actions
115 lines (94 loc) · 2.32 KB
/
Copy pathmodels.go
File metadata and controls
115 lines (94 loc) · 2.32 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package bookstack
import (
"encoding/json"
"fmt"
"io"
"net/url"
"strconv"
"time"
)
type Response struct {
Data json.RawMessage `json:"data,omitempty"`
Total int `json:"total,omitempty"`
Err struct {
Code int `json:"code,omitempty"`
Message string `json:"message,omitempty"`
} `json:"error,omitempty"`
}
func (r Response) Error() error {
switch {
case r.Err.Code != 0 || r.Err.Message != "":
return fmt.Errorf("%d %s", r.Err.Code, r.Err.Message)
default:
return nil
}
}
type QueryParams struct {
Count int
Offset int
SortField string
SortDescending bool
FilterField string
FilterValue string
}
func (q *QueryParams) String(l string) string {
if q == nil {
return l
}
u := url.Values{}
if q.Count != 0 {
u.Add("count", strconv.Itoa(q.Count))
}
if q.Offset != 0 {
u.Add("offset", strconv.Itoa(q.Offset))
}
if q.SortField != "" {
v := "+"
if q.SortDescending {
v = "-"
}
u.Add("sort", fmt.Sprintf("%s%s", v, q.SortField))
}
if q.FilterField != "" && q.FilterValue != "" {
u.Add(fmt.Sprintf("filter[%s]", q.FilterField), q.FilterValue)
}
return fmt.Sprintf("%s?%s", l, u.Encode())
}
type Tag struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
Order int `json:"order,omitempty"`
}
type TagParams struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}
type CreatedBy struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
type UpdatedBy struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
type OwnedBy struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
type Cover struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
CreatedBy int `json:"created_by,omitempty"`
UpdatedBy int `json:"updated_by,omitempty"`
Path string `json:"path,omitempty"`
Type string `json:"type,omitempty"`
UploadedTo int `json:"uploaded_to,omitempty"`
}
type blank struct{}
func (b blank) Form() (string, io.Reader, error) {
return "", nil, nil
}