123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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)
- })
- }
|