-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.go
55 lines (46 loc) · 1.29 KB
/
response.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
52
53
54
55
package audacity
import "encoding/json"
// Response is an output response from Audacity sent through the pipe from commands like GetInfo.
type Response struct {
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Params []Param `json:"params"`
Tip string `json:"tip"`
}
// Param is a parameter in a response.
type Param struct {
Key string `json:"key"`
Type string `json:"type"`
Default string `json:"default"`
Enum []string `json:"enum"`
}
func (r Response) String() string {
o, _ := json.Marshal(r)
return string(o)
// ps := ""
// k := len(r.Params) - 1
// for i, p := range r.Params {
// if k == i {
// ps += fmt.Sprintf(" %s ", p)
// } else {
// ps += fmt.Sprintf(" %s,", p)
// }
// }
// return fmt.Sprintf(`{"id": "%s", "name": "%s", "url": "%s", "params": [%s], "tip": "%s"}`, r.ID, r.Name, r.URL, ps, r.Tip)
}
// func (p param) String() string {
// s := fmt.Sprintf(`{ "Key": "%s", "Type": "%s", "Default": "%s"`, p.Key, p.Type, p.Default)
// if k := len(p.Enum) - 1; k > -1 {
// es := ""
// for i, e := range p.Enum {
// if k == i {
// es += fmt.Sprintf(` "%s" `, e)
// } else {
// es += fmt.Sprintf(` "%s",`, e)
// }
// }
// s += fmt.Sprintf(`, "Enum": [%s]`, es)
// }
// return s + " }"
// }