2020-10-13 05:24:11 +00:00
|
|
|
package {{.Version}}
|
|
|
|
|
2021-09-30 07:41:56 +00:00
|
|
|
// {{ .Banner }}
|
2020-10-13 05:24:11 +00:00
|
|
|
|
|
|
|
import ({{if .Responses}}
|
|
|
|
"encoding/json"
|
|
|
|
"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
|
|
|
}
|
2022-04-09 23:46:46 +00:00
|
|
|
responseChannel := conn.GetResponseListener(r.ID)
|
|
|
|
defer conn.CloseResponseListener(r.ID)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
rawResponse := <- responseChannel
|
2021-09-30 07:39:54 +00:00
|
|
|
if rawResponse.Error != nil {
|
|
|
|
err = mkerr(rawResponse)
|
|
|
|
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}}
|