package NatsServer import ( "Yunlot/lib" "Yunlot/logs" "Yunlot/models/Product" "github.com/nats-io/nats.go" "github.com/vmihailenco/msgpack/v5" ) func NatsServer_Product() { // 产品类型 - 获取 _, _ = lib.Nats.Subscribe("/Product/ProductType/Get", func(m *nats.Msg) { logs.Println("Nats /Product/ProductType/List: %s\n", string(m.Data)) var ProductType_r Product.ProductType err := msgpack.Unmarshal(m.Data, &ProductType_r) if err != nil { logs.PrintlnError("Nats:", err) b, _ := msgpack.Marshal(&lib.JSONR{Code: lib.Error, Msg: "解析错误!"}) _ = lib.Nats.Publish(m.Reply, b) return } if !ProductType_r.Read() { b, _ := msgpack.Marshal(&lib.JSONR{Code: lib.Error, Msg: "ProductID E!"}) _ = lib.Nats.Publish(m.Reply, b) return } b, _ := msgpack.Marshal(&lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductType_r}) _ = lib.Nats.Publish(m.Reply, b) }) // 产品类型 - 列表 _, _ = lib.Nats.Subscribe("/Product/ProductType/List", func(m *nats.Msg) { logs.Println("Nats /Product/ProductType/List: %s\n", string(m.Data)) var ProductType_r Product.ProductType err := msgpack.Unmarshal(m.Data, &ProductType_r) if err != nil { logs.PrintlnError("Nats:", err) b, _ := msgpack.Marshal([]Product.ProductType{}) _ = lib.Nats.Publish(m.Reply, b) return } ProductType_list := ProductType_r.Lists_All() b, _ := msgpack.Marshal(ProductType_list) _ = lib.Nats.Publish(m.Reply, b) }) // 网关 - 列表 _, _ = lib.Nats.Subscribe("/Product/ProductModeLists/List", func(m *nats.Msg) { logs.Println("Nats /Product/ProductModeLists/List: %s\n", string(m.Data)) ProductModeLists_list, _ := Product.ProductModeLists() b, _ := msgpack.Marshal(ProductModeLists_list) _ = lib.Nats.Publish(m.Reply, b) }) // 产品协议 - 获取 _, _ = lib.Nats.Subscribe("/Product/ProductProt/Get", func(m *nats.Msg) { logs.Println("Nats /Product/ProductProt/Get: %s\n", string(m.Data)) var ProductProt Product.ProductProt err := msgpack.Unmarshal(m.Data, &ProductProt) if err != nil { logs.PrintlnError("Nats:", err) b, _ := msgpack.Marshal(&lib.JSONR{Code: lib.Error, Msg: "解析错误!"}) _ = lib.Nats.Publish(m.Reply, b) return } if !ProductProt.Read() { b, _ := msgpack.Marshal(&lib.JSONR{Code: lib.Error, Msg: "ID E!"}) _ = lib.Nats.Publish(m.Reply, b) return } b, _ := msgpack.Marshal(&lib.JSONR{Code: lib.Success, Msg: "ok!", Data: ProductProt}) _ = lib.Nats.Publish(m.Reply, b) }) // 产品协议 - 列表 _, _ = lib.Nats.Subscribe("/Product/ProductProt/List", func(m *nats.Msg) { logs.Println("Nats /Product/ProductProt/List: %s\n", string(m.Data)) var ProductProt Product.ProductProt err := msgpack.Unmarshal(m.Data, &ProductProt) if err != nil { logs.PrintlnError("Nats:", err) b, _ := msgpack.Marshal([]Product.ProductProt{}) _ = lib.Nats.Publish(m.Reply, b) return } ProductProt_list := ProductProt.Lists_All() b, _ := msgpack.Marshal(ProductProt_list) _ = lib.Nats.Publish(m.Reply, b) }) }