-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
50 lines (37 loc) · 1.02 KB
/
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
44
45
46
47
48
49
50
package main
import "encoding/json"
var (
skillStartTag = "<skill-start>"
skillEndTag = "<skill-end>"
resultStartTag = "<result-start>"
resultEndTag = "<result-end>"
formatterResult = "%s\n" + skillEndTag + "\n" +
resultStartTag + "\n%s\n" + resultEndTag + "\n" +
skillStartTag + "\n"
)
type skillInput struct {
Skill string `json:"skill"`
Description string `json:"description,omitempty"`
Args []string `json:"args,omitempty"`
Run func(args []string) (*skillOutput, error)
}
func (skill *skillInput) RunSkill() (*skillOutput, error) {
return skill.Run(skill.Args)
}
// Marshal returns the JSON encoding of the skillInput
func (a *skillInput) MarshalJSON() ([]byte, error) {
// create a map to store the fields of the skillInput
m := make(map[string]interface{})
m["skill"] = a.Skill
if a.Description != "" {
m["description"] = a.Description
}
if len(a.Args) > 0 {
m["args"] = a.Args
}
// use json.Marshal to encode the map
return json.Marshal(m)
}
type skillOutput struct {
Output string `json:"output"`
}