summaryrefslogtreecommitdiffstats
path: root/plugin/interface_generator
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-07-03 09:58:28 -0700
committerGitHub <noreply@github.com>2018-07-03 09:58:28 -0700
commit83a3ac089cff0d05559e6ba5c2c60b09f5cae176 (patch)
tree51cc53c0a77cf455cf9d700a453b6d57f1604fdb /plugin/interface_generator
parent3848cb7e79e019e2f0878d6e2377ad36b3c7ca43 (diff)
downloadchat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.tar.gz
chat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.tar.bz2
chat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.zip
MM-11029 Adding plugin logging functionality. (#9034)
* Capturing stdout, stderr of plugins in logs. * Cleanup go-plugin debug logs. * Adding logging to plugin API * Generating mocks. * godoc convention
Diffstat (limited to 'plugin/interface_generator')
-rw-r--r--plugin/interface_generator/main.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/plugin/interface_generator/main.go b/plugin/interface_generator/main.go
index 5f66506d3..8cbaf4249 100644
--- a/plugin/interface_generator/main.go
+++ b/plugin/interface_generator/main.go
@@ -76,12 +76,22 @@ func FieldListDestruct(structPrefix string, fieldList *ast.FieldList, fileset *t
}
nextLetter := 'A'
for _, field := range fieldList.List {
+ typeNameBuffer := &bytes.Buffer{}
+ err := printer.Fprint(typeNameBuffer, fileset, field.Type)
+ if err != nil {
+ panic(err)
+ }
+ typeName := typeNameBuffer.String()
+ suffix := ""
+ if strings.HasPrefix(typeName, "...") {
+ suffix = "..."
+ }
if len(field.Names) == 0 {
- result = append(result, structPrefix+string(nextLetter))
+ result = append(result, structPrefix+string(nextLetter)+suffix)
nextLetter += 1
} else {
for range field.Names {
- result = append(result, structPrefix+string(nextLetter))
+ result = append(result, structPrefix+string(nextLetter)+suffix)
nextLetter += 1
}
}
@@ -103,6 +113,9 @@ func FieldListToStructList(fieldList *ast.FieldList, fileset *token.FileSet) str
panic(err)
}
typeName := typeNameBuffer.String()
+ if strings.HasPrefix(typeName, "...") {
+ typeName = strings.Replace(typeName, "...", "[]", 1)
+ }
if len(field.Names) == 0 {
result = append(result, string(nextLetter)+" "+typeName)
nextLetter += 1
@@ -224,6 +237,8 @@ func (s *HooksRPCServer) {{.Name}}(args *{{.Name}}Args, returns *{{.Name}}Return
{{.Name}}{{funcStyle .Params}} {{funcStyle .Return}}
}); ok {
{{if .Return}}{{destruct "returns." .Return}} = {{end}}hook.{{.Name}}({{destruct "args." .Params}})
+ } else {
+ return fmt.Errorf("Hook {{.Name}} called but not implemented.")
}
return nil
}
@@ -253,6 +268,8 @@ func (s *APIRPCServer) {{.Name}}(args *{{.Name}}Args, returns *{{.Name}}Returns)
{{.Name}}{{funcStyle .Params}} {{funcStyle .Return}}
}); ok {
{{if .Return}}{{destruct "returns." .Return}} = {{end}}hook.{{.Name}}({{destruct "args." .Params}})
+ } else {
+ return fmt.Errorf("API {{.Name}} called but not implemented.")
}
return nil
}