Skip to content

Instantly share code, notes, and snippets.

@ripienaar
Created September 24, 2019 16:48
Show Gist options
  • Save ripienaar/1ba4d5cf4792ef1ea0fac33fc4e26d3a to your computer and use it in GitHub Desktop.
Save ripienaar/1ba4d5cf4792ef1ea0fac33fc4e26d3a to your computer and use it in GitHub Desktop.
#!/usr/sbin/choria yaegi
package main
import (
external "github.com/choria-io/go-external-agent"
)
type echoRequest struct {
Message string `json:"message"`
}
func echoAction(request *external.Request, reply *external.Reply, config map[string]string) {
req := &echoRequest{}
// parse the received request, sets appropriate errors on reply on failure
if !request.ParseRequestData(req, reply) {
return
}
reply.Data = map[string]string{
"message": req.Message,
}
}
func main() {
agent := external.NewAgent("parrot")
defer agent.ProcessRequest()
// action will be invoked on demand
agent.MustRegisterAction("ping", echoAction)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment