aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2019-02-05 11:51:41 +0100
committerValentin Rothberg <rothberg@redhat.com>2019-02-06 11:14:06 +0100
commit9ac0ebb0791851aea81ecc847802db5a39bfb6e7 (patch)
tree30ad98bcc2c2dd1136f46a48cbc44d422adfa184 /vendor/github.com/varlink/go/cmd/varlink-go-interface-generator
parent51714d5da7aaa19014fd67b48b79dfbd5f69c1f0 (diff)
downloadpodman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.gz
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.bz2
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.zip
Cirrus: add vendor_check_task
* Make sure that all vendored dependencies are in sync with the code and the vendor.conf by running `make vendor` with a follow-up status check of the git tree. * Vendor ginkgo and gomega to include the test dependencies. Signed-off-by: Chris Evic <cevich@redhat.com> Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/varlink/go/cmd/varlink-go-interface-generator')
-rw-r--r--vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go45
1 files changed, 36 insertions, 9 deletions
diff --git a/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go b/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go
index 6be01f580..98a983c5e 100644
--- a/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go
+++ b/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/main.go
@@ -109,6 +109,36 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("\n\n")
}
+ for _, a := range midl.Errors {
+ writeDocString(&b, a.Doc)
+ b.WriteString("type " + a.Name + " ")
+ writeType(&b, a.Type, true, 0)
+ b.WriteString("\nfunc (e " + a.Name + ") Error() string {\n")
+ b.WriteString("\treturn \"" + midl.Name + "." + a.Name + "\"\n")
+ b.WriteString("}\n\n")
+ }
+
+ b.WriteString("func Dispatch_Error(err error) error {\n")
+ b.WriteString("\tif e, ok := err.(*varlink.Error); ok {\n")
+ b.WriteString("\t\tswitch e.Name {\n")
+ for _, a := range midl.Errors {
+ b.WriteString("\t\tcase \"" + midl.Name + "." + a.Name + "\":\n")
+ b.WriteString("\t\t\terrorRawParameters := e.Parameters.(*json.RawMessage)\n")
+ b.WriteString("\t\t\tif errorRawParameters == nil {\n")
+ b.WriteString("\t\t\t\treturn e\n")
+ b.WriteString("\t\t\t}\n")
+ b.WriteString("\t\t\tvar param " + a.Name + "\n")
+ b.WriteString("\t\t\terr := json.Unmarshal(*errorRawParameters, &param)\n")
+ b.WriteString("\t\t\tif err != nil {\n")
+ b.WriteString("\t\t\t\treturn e\n")
+ b.WriteString("\t\t\t}\n")
+ b.WriteString("\t\t\treturn &param\n")
+ }
+ b.WriteString("\t\t}\n")
+ b.WriteString("\t}\n")
+ b.WriteString("\treturn err\n")
+ b.WriteString("}\n\n")
+
b.WriteString("// Generated client method calls\n\n")
for _, m := range midl.Methods {
@@ -175,9 +205,9 @@ func generateTemplate(description string) (string, []byte, error) {
} else {
b.WriteString("\treceive, err := c.Send(\"" + midl.Name + "." + m.Name + "\", nil, flags)\n")
}
- b.WriteString("if err != nil {\n" +
- "\treturn nil, err\n" +
- "}\n")
+ b.WriteString("\tif err != nil {\n" +
+ "\t\treturn nil, err\n" +
+ "\t}\n")
b.WriteString("\treturn func() (")
for _, field := range m.Out.Fields {
b.WriteString(field.Name + "_out_ ")
@@ -194,6 +224,7 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("\t\tflags, err = receive(nil)\n")
}
b.WriteString("\t\tif err != nil {\n" +
+ "\t\t\terr = Dispatch_Error(err)\n" +
"\t\t\treturn\n" +
"\t\t}\n")
for _, field := range m.Out.Fields {
@@ -242,10 +273,8 @@ func generateTemplate(description string) (string, []byte, error) {
writeType(&b, field.Type, false, 1)
}
b.WriteString(") error {\n")
+ b.WriteString("\tvar out " + e.Name + "\n")
if len(e.Type.Fields) > 0 {
- b.WriteString("\tvar out ")
- writeType(&b, e.Type, true, 1)
- b.WriteString("\n")
for _, field := range e.Type.Fields {
switch field.Type.Kind {
case idl.TypeStruct, idl.TypeArray, idl.TypeMap:
@@ -257,10 +286,8 @@ func generateTemplate(description string) (string, []byte, error) {
b.WriteString("\tout." + strings.Title(field.Name) + " = " + field.Name + "_\n")
}
}
- b.WriteString("\treturn c.ReplyError(\"" + midl.Name + "." + e.Name + "\", &out)\n")
- } else {
- b.WriteString("\treturn c.ReplyError(\"" + midl.Name + "." + e.Name + "\", nil)\n")
}
+ b.WriteString("\treturn c.ReplyError(\"" + midl.Name + "." + e.Name + "\", &out)\n")
b.WriteString("}\n\n")
}