package {{.Version}} // DO NOT EDIT: this file is automatically generated by ./tools/generator in this repo import ({{if .Responses}} "encoding/json" "fmt" "log"{{end}} "gitlab.com/signald/signald-go/signald" ) {{range $type, $action := .Actions}} {{if ne $action.Request ""}} {{if ne $action.Doc ""}}// Submit: {{$action.Doc}}{{end}} func (r *{{$action.Request}}) Submit(conn *signald.Signald) ({{if ne $action.Response ""}}response {{$action.Response}}, {{end}}err error) { r.Version = "{{$.Version}}" {{else}} {{if ne $action.Doc ""}}// {{$action.FnName}}: {{$action.Doc}}{{end}} func {{$action.FnName}}(conn *signald.Signald) ({{if ne $action.Response ""}}response {{$action.Response}}, {{end}}err error) { r := Request{Version: "{{.Version}}"} {{end}} r.Type = "{{$type}}" if(r.ID == "") { r.ID = signald.GenerateID() } err = conn.RawRequest(r) if err != nil { log.Println("signald-go: error submitting request to signald") return } responseChannel := conn.GetResponseListener(r.ID) defer conn.CloseResponseListener(r.ID) rawResponse := <- responseChannel if rawResponse.Error != nil { err = fmt.Errorf("signald error: %s", string(rawResponse.Error)) return } {{if ne $action.Response ""}} err = json.Unmarshal(rawResponse.Data, &response) if err != nil { rawResponseJson, _ := rawResponse.Data.MarshalJSON() log.Println("signald-go: error unmarshalling response from signald of type", rawResponse.Type, string(rawResponseJson)) return } return response, nil {{else}} return err {{end}} } {{end}}