nats-config.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package comm
  2. import "time"
  3. type RequstConfigOption struct {
  4. ReqPayload interface{}
  5. Timeout time.Duration
  6. }
  7. type ReqConfiger struct {
  8. Name string
  9. }
  10. type SetConfiger struct {
  11. Name string
  12. Value string
  13. DevValue string
  14. }
  15. func (q *NatsBus) RequestConfig(key string, timoutOption ...interface{}) (string, error) {
  16. data := &ReqConfiger{
  17. Name: key,
  18. }
  19. timeout := 5 * time.Second
  20. for _, option := range timoutOption {
  21. if _, ok := option.(time.Duration); ok {
  22. timeout = option.(time.Duration)
  23. break
  24. }
  25. }
  26. result := ""
  27. err := q.RequestApi("request.configer", data, timeout, &result)
  28. return result, err
  29. }
  30. func (q *NatsBus) SetConfig(key string, Value string, timoutOption ...interface{}) (string, error) {
  31. data := &SetConfiger{
  32. Name: key,
  33. Value: Value,
  34. }
  35. timeout := 5 * time.Second
  36. for _, option := range timoutOption {
  37. if _, ok := option.(time.Duration); ok {
  38. timeout = option.(time.Duration)
  39. break
  40. }
  41. }
  42. result := ""
  43. err := q.RequestApi("set.configer", data, timeout, &result)
  44. return result, err
  45. }
  46. func (q *NatsBus) SetDevConfig(key string, Value string, timoutOption ...interface{}) (string, error) {
  47. data := &SetConfiger{
  48. Name: key,
  49. DevValue: Value,
  50. }
  51. timeout := 5 * time.Second
  52. for _, option := range timoutOption {
  53. if _, ok := option.(time.Duration); ok {
  54. timeout = option.(time.Duration)
  55. break
  56. }
  57. }
  58. result := ""
  59. err := q.RequestApi("set.configer", data, timeout, &result)
  60. return result, err
  61. }
  62. func (q *NatsBus) RequestConfigDev(key string, timoutOption ...interface{}) (string, error) {
  63. data := &ReqConfiger{
  64. Name: key,
  65. }
  66. timeout := 5 * time.Second
  67. for _, option := range timoutOption {
  68. if _, ok := option.(time.Duration); ok {
  69. timeout = option.(time.Duration)
  70. break
  71. }
  72. }
  73. result := ""
  74. err := q.RequestApi("request.configer.dev", data, timeout, &result)
  75. return result, err
  76. }