123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package main
- import (
- "fmt"
- "log"
- "time"
- fho "git.mokkon.com/sainw/fho_forward.git/client"
- )
- const (
- address = "fhogrpc-test.seinmaungengineering.com:7091"
- // address = "localhost:7090"
- )
- type RegionProduct struct {
- ProductID string
- Name string
- Color string
- Variant float32
- }
- func RegionProductFromMap(m map[string]interface{}) *RegionProduct {
- return &RegionProduct{ProductID: fho.ToString(m["product_id"]),
- Name: fho.ToString(m["name"]),
- Color: fho.ToString(m["color"]),
- Variant: fho.ToFloat32(m["variant"])}
- }
- func main() {
- client, err := fho.NewClient(address, "da910506-4bdc-4dc2-9481-58a4e3e3c8bf", "1adf4633-7e9e-4bd0-b512-7b087d9c9719")
- // client, err := fho.NewClient(address, "bd38e9ac-210a-4e85-865c-401270c07220", "8c95f7fa-3071-427d-a27a-6f96e1d9590e")
- if err != nil {
- panic(err)
- }
- go listenProducts(client)
- products, err := fho.QueryProducts(client, time.Now().Add(time.Hour*-114))
- if err != nil {
- log.Println("Error query:", err.Error())
- }
- for _, product := range products {
- fmt.Println("Query=====>")
- printProduct(product)
- }
- select {}
- }
- func listenProducts(client *fho.FhoClient) error {
- err := fho.ListenOnProducts(client, time.Now().Add(time.Hour*-114), func(products []*fho.Product) {
- for _, p := range products {
- fmt.Println("Listening=====>")
- printProduct(p)
- }
- })
- return err
- }
- func printProduct(p *fho.Product) {
- fmt.Printf("ID : %v\n", p.ID)
- fmt.Printf("Name : %v\n", p.Name)
- fmt.Printf("Color : %v\n", p.Color)
- fmt.Printf("IsCreated : %v\n", p.IsCreated)
- fmt.Printf("IsUpdated : %v\n", p.IsUpdated)
- fmt.Printf("IsDeleted : %v\n", p.IsDeleted)
- fmt.Printf("LatestUpdatedTime : %v\n", p.LatestUpdatedTime)
- }
|