myfunc.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Public Domain Software
  3. *
  4. * I (Matthias Ladkau) am the author of the source code in this file.
  5. * I have placed the source code in this file in the public domain.
  6. *
  7. * For further information see: http://creativecommons.org/publicdomain/zero/1.0/
  8. */
  9. /*
  10. Example ECAL stdlib function plugin.
  11. The plugins must be valid Go plugins: https://golang.org/pkg/plugin
  12. ECAL usable functions imported via a plugin must conform to the following interface:
  13. type ECALPluginFunction interface {
  14. Run(args []interface{}) (interface{}, error) // Function execution with given arguments
  15. DocString() string // Returns some function description
  16. }
  17. */
  18. package main
  19. import "fmt"
  20. func init() {
  21. // Here goes some initialisation code
  22. Greeting = "Hello"
  23. ECALmyfunc = myfunc{"World"}
  24. }
  25. /*
  26. Greeting is first word in the output
  27. */
  28. var Greeting string
  29. type myfunc struct {
  30. place string
  31. }
  32. func (f *myfunc) Run(args []interface{}) (interface{}, error) {
  33. if len(args) == 0 {
  34. return "", fmt.Errorf("Need a name to greet as argument")
  35. }
  36. return fmt.Sprintf("%v %v for %v", Greeting, f.place, args[0]), nil
  37. }
  38. func (f *myfunc) DocString() string {
  39. return "Myfunc is an example function"
  40. }
  41. // Exported bits
  42. /*
  43. ECALmyfunc is the exported function which can be used by ECAL
  44. */
  45. var ECALmyfunc myfunc