main.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "time"
  6. fho "git.mokkon.com/sainw/fho_forward.git/client"
  7. )
  8. const (
  9. address = "fhogrpc-test.seinmaungengineering.com:7091"
  10. // address = "localhost:7090"
  11. )
  12. type RegionProduct struct {
  13. ProductID string
  14. Name string
  15. Color string
  16. Variant float32
  17. }
  18. func RegionProductFromMap(m map[string]interface{}) *RegionProduct {
  19. return &RegionProduct{ProductID: fho.ToString(m["product_id"]),
  20. Name: fho.ToString(m["name"]),
  21. Color: fho.ToString(m["color"]),
  22. Variant: fho.ToFloat32(m["variant"])}
  23. }
  24. func main() {
  25. client, err := fho.NewClient(address, "da910506-4bdc-4dc2-9481-58a4e3e3c8bf", "1adf4633-7e9e-4bd0-b512-7b087d9c9719")
  26. // client, err := fho.NewClient(address, "bd38e9ac-210a-4e85-865c-401270c07220", "8c95f7fa-3071-427d-a27a-6f96e1d9590e")
  27. if err != nil {
  28. panic(err)
  29. }
  30. go listenProducts(client)
  31. products, err := fho.QueryProducts(client, time.Now().Add(time.Hour*-114))
  32. if err != nil {
  33. log.Println("Error query:", err.Error())
  34. }
  35. for _, product := range products {
  36. fmt.Println("Query=====>")
  37. printProduct(product)
  38. }
  39. select {}
  40. }
  41. func listenProducts(client *fho.FhoClient) error {
  42. err := fho.ListenOnProducts(client, time.Now().Add(time.Hour*-114), func(products []*fho.Product) {
  43. for _, p := range products {
  44. fmt.Println("Listening=====>")
  45. printProduct(p)
  46. }
  47. })
  48. return err
  49. }
  50. func printProduct(p *fho.Product) {
  51. fmt.Printf("ID : %v\n", p.ID)
  52. fmt.Printf("Name : %v\n", p.Name)
  53. fmt.Printf("Color : %v\n", p.Color)
  54. fmt.Printf("IsCreated : %v\n", p.IsCreated)
  55. fmt.Printf("IsUpdated : %v\n", p.IsUpdated)
  56. fmt.Printf("IsDeleted : %v\n", p.IsDeleted)
  57. fmt.Printf("LatestUpdatedTime : %v\n", p.LatestUpdatedTime)
  58. }