main.go 677 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "git.nspix.com/golang/micro"
  6. )
  7. type (
  8. Math struct{}
  9. mathRequest struct {
  10. NumA int `json:"num_a"`
  11. NumB int `json:"num_b"`
  12. }
  13. mathResponse struct {
  14. Value int `json:"value"`
  15. }
  16. )
  17. func main() {
  18. s := micro.New(
  19. micro.WithName("aa", "1.0.1"),
  20. )
  21. req, err := s.CreateRequest("test", "math.add", &mathRequest{
  22. NumA: 100,
  23. NumB: 221,
  24. })
  25. if err != nil {
  26. fmt.Println(err)
  27. return
  28. }
  29. if res, err := req.Do(context.Background()); err != nil {
  30. fmt.Println(err)
  31. } else {
  32. if res.Error() != nil {
  33. fmt.Println(err)
  34. } else {
  35. rr := &mathResponse{}
  36. res.Decode(rr)
  37. fmt.Println(rr)
  38. }
  39. }
  40. fmt.Println(s.Run())
  41. }