config.go 5.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. )
  6. import (
  7. "google.golang.org/grpc/codes"
  8. "google.golang.org/grpc/metadata"
  9. "google.golang.org/grpc/status"
  10. )
  11. import (
  12. pb "resource-server/rpc_idl/dr_resource_pb"
  13. )
  14. type ConfigServer struct {
  15. pb.UnimplementedConfigServer
  16. }
  17. func (s *ConfigServer) ConfigOptionList(ctx context.Context, in *pb.ConfigOptionListRequest) (*pb.ConfigOptionListReply, error) {
  18. md, ok := metadata.FromIncomingContext(ctx)
  19. if ok {
  20. fmt.Printf("Received metadata: %v\n", md)
  21. }
  22. res := pb.ConfigOptionListReply{}
  23. switch in.GetFlag() {
  24. case "TimeFormat":
  25. //res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{})
  26. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH:mm:ss", Value: "HH:mm:ss", Order: 1, IsEnabled: true})
  27. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH:mm", Value: "HH:mm", Order: 2, IsEnabled: true})
  28. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HH-mm-ss", Value: "HH-mm-ss", Order: 3, IsEnabled: true})
  29. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "HHmmss", Value: "HHmmss", Order: 4, IsEnabled: true})
  30. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "hh:mm:ss tt", Value: "hh:mm:ss tt", Order: 5, IsEnabled: true})
  31. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "TimeFormat", Text: "h:mm:ss tt", Value: "h:mm:ss tt", Order: 6, IsEnabled: true})
  32. case "DateFormat":
  33. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy.MM.dd", Value: "yyyy.MM.dd", Order: 1, IsEnabled: true})
  34. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/M/d", Value: "yyyy/M/d", Order: 2, IsEnabled: true})
  35. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "M-d-yyyy", Value: "M-d-yyyy", Order: 3, IsEnabled: true})
  36. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/M/dd", Value: "yyyy/M/dd", Order: 4, IsEnabled: true})
  37. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy-MM-dd", Value: "yyyy-MM-dd", Order: 5, IsEnabled: true})
  38. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "M-dd-yyyy", Value: "M-dd-yyyy", Order: 6, IsEnabled: true})
  39. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy.M.dd", Value: "yyyy.M.dd", Order: 7, IsEnabled: true})
  40. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy/MM/dd", Value: "yyyy/MM/dd", Order: 8, IsEnabled: true})
  41. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "MMM-dd-yyyy", Value: "MMM-dd-yyyy", Order: 9, IsEnabled: true})
  42. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "yyyy-MMM-dd", Value: "yyyy-MMM-dd", Order: 10, IsEnabled: true})
  43. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "dd-MMM-yyyy", Value: "dd-MMM-yyyy", Order: 11, IsEnabled: true})
  44. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DateFormat", Text: "dd.MM.yyyy", Value: "dd.MM.yyyy", Order: 12, IsEnabled: true})
  45. case "DoseUnit":
  46. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DoseUnit", Text: "rad", Value: "rad", Order: 1, IsEnabled: true})
  47. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "DoseUnit", Text: "mGy", Value: "mGy", Order: 2, IsEnabled: true})
  48. case "WeightUnit":
  49. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "WeightUnit", Text: "kg", Value: "kg", Order: 1, IsEnabled: true})
  50. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "WeightUnit", Text: "pound", Value: "pound", Order: 2, IsEnabled: true})
  51. case "LengthUnit":
  52. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "LengthUnit", Text: "cm", Value: "cm", Order: 1, IsEnabled: true})
  53. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "LengthUnit", Text: "inch", Value: "inch", Order: 2, IsEnabled: true})
  54. case "FontFamily":
  55. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "FontFamily", Text: "Arial Unicode MS", Value: "Arial Unicode MS", Order: 1, IsEnabled: true})
  56. res.ConfigOption = append(res.ConfigOption, &pb.ConfigOption{Flag: "FontFamily", Text: "Arial", Value: "Arial", Order: 2, IsEnabled: true})
  57. default:
  58. return &res, status.Errorf(codes.NotFound, "flag %s not found", in.GetFlag())
  59. }
  60. return &res, nil
  61. }
  62. func (s *ConfigServer) ConfigList(ctx context.Context, in *pb.ConfigListRequest) (*pb.ConfigListResponse, error) {
  63. return nil, status.Errorf(codes.Unimplemented, "method ConfigList not implemented")
  64. }
  65. //func GetConfigList() ([]*dto.ConfigResp, error) {
  66. // res := []*dto.ConfigResp{}
  67. // var items []*models.ConfigItem
  68. // query := models.DB.Model(&models.ConfigItem{})
  69. // err := query.Order("id").Find(&items).Error
  70. // if err != nil {
  71. // return res, err
  72. // }
  73. // for _, c := range items {
  74. // res = append(res, &dto.ConfigResp{
  75. // Key: c.Key,
  76. // Value: c.Value,
  77. // OptionKey: c.OptionKey,
  78. // ValueType: c.ValueType,
  79. // Description: c.Description,
  80. // Order: c.Order,
  81. // IsEnabled: c.IsEnabled,
  82. // Uri: c.Uri,
  83. // })
  84. // }
  85. // return res, nil
  86. //}