Skip to content

Commit

Permalink
Update "varlink" module
Browse files Browse the repository at this point in the history
  • Loading branch information
kaysievers committed May 30, 2018
1 parent 84851c2 commit bfd4573
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
28 changes: 18 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ func defaultValue(i *idl.IDL, t *idl.Type) interface{} {
return v

case idl.TypeAlias:
alias := i.Aliases[t.Alias]
if alias == nil {
return nil
for _, alias := range i.Aliases {
if alias.Name == t.Alias {
return defaultValue(i, alias.Type)
}
}
return defaultValue(i, alias.Type)
return nil
}

return nil
Expand Down Expand Up @@ -211,7 +212,7 @@ func serveInterface(writer http.ResponseWriter, request *http.Request) {
return
}

idl, err := idl.New(desc)
i, err := idl.New(desc)
if err != nil {
http.Error(writer, "Internal server error", http.StatusInternalServerError)
log.Print(err.Error())
Expand All @@ -222,26 +223,33 @@ func serveInterface(writer http.ResponseWriter, request *http.Request) {
case 1:
if strings.HasSuffix(parts[0], ".varlink") {
writer.Header().Set("Content-Type", "text/plain")
io.WriteString(writer, idl.Description)
io.WriteString(writer, i.Description)
} else {
templates.ExecuteTemplate(writer, "interface.html", idl)
templates.ExecuteTemplate(writer, "interface.html", i)
}
case 2:
method := idl.Methods[parts[1]]
var method *idl.Method

for _, m := range i.Methods {
if m.Name == parts[1] {
method = m
break
}
}
if method == nil {
http.Error(writer, "Method does not exist: "+parts[1], http.StatusNotFound)
return
}

value, err := json.MarshalIndent(defaultValue(idl, method.In), "", " ")
value, err := json.MarshalIndent(defaultValue(i, method.In), "", " ")
if err != nil {
http.Error(writer, "Internal server error", http.StatusInternalServerError)
log.Print(err.Error())
return
}

templates.ExecuteTemplate(writer, "method.html", map[string]interface{}{
"Interface": idl,
"Interface": i,
"Method": method,
"DefaultInArgs": string(value),
})
Expand Down
8 changes: 4 additions & 4 deletions vendor/github.com/varlink/go/varlink/call.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 25 additions & 14 deletions vendor/github.com/varlink/go/varlink/idl/idl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/varlink/go/varlink/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bfd4573

Please sign in to comment.