2020-10-13 05:24:11 +00:00
|
|
|
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}}
|
2021-02-02 10:09:24 +00:00
|
|
|
func (r *{{$action.Request}}) Submit(conn *signald.Signald) ({{if ne $action.Response ""}}response {{$action.Response}}, {{end}}err error) {
|
2020-10-13 05:24:11 +00:00
|
|
|
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 == "") {
|
2021-01-31 05:36:35 +00:00
|
|
|
r.ID = signald.GenerateID()
|
2020-10-13 05:24:11 +00:00
|
|
|
}
|
|
|
|
err = conn.RawRequest(r)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("signald-go: error submitting request to signald")
|
2021-02-02 10:09:24 +00:00
|
|
|
return
|
2020-10-13 05:24:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2021-02-02 10:09:24 +00:00
|
|
|
|
|
|
|
{{if ne $action.Response ""}}
|
2020-10-13 05:24:11 +00:00
|
|
|
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))
|
2021-02-02 10:09:24 +00:00
|
|
|
return
|
2020-10-13 05:24:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
{{else}}
|
2021-02-02 10:09:24 +00:00
|
|
|
return err
|
2020-10-13 05:24:11 +00:00
|
|
|
{{end}}
|
|
|
|
}
|
2021-01-31 05:36:35 +00:00
|
|
|
{{end}}
|