Created
September 24, 2019 16:48
-
-
Save ripienaar/1ba4d5cf4792ef1ea0fac33fc4e26d3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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