main.go 770 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "flow/registry"
  4. "flowserver"
  5. "io/ioutil"
  6. "math"
  7. "net/http"
  8. "strings"
  9. )
  10. func main() {
  11. r := registry.New()
  12. r.Add("hello", func() string {
  13. return "hello world"
  14. })
  15. r.Add(strings.Split, strings.Join)
  16. fns := r.Add(math.Exp, math.Sin, math.Cos)
  17. //Describing groups of functions
  18. fns.Tags("math")
  19. fns.Extra("style", registry.M{"color": "#F00"})
  20. // Describing a function
  21. registry.Describer(
  22. r.Add(http.Get).Inputs("url"),
  23. r.Add(responseReader).Inputs("response"),
  24. ).Tags("http").Extra("style", registry.M{"color": "#00F"})
  25. http.ListenAndServe(":5000", flowserver.New(r, "storename"))
  26. }
  27. func responseReader(r *http.Response) (string, error) {
  28. defer r.Body.Close()
  29. res, err := ioutil.ReadAll(r.Body)
  30. return string(res), err
  31. }