field_check.go 632 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package check
  4. import (
  5. "adm-task/errors"
  6. "adm-task/utils"
  7. "context"
  8. "fmt"
  9. "google.golang.org/grpc/status"
  10. pb_v1 "adm-task/pb/v1"
  11. )
  12. func FieldCheck(ctx context.Context, req *pb_v1.FieldCheckRequest) (reply *pb_v1.FieldCheckReply, err error) {
  13. if req.Content == "" {
  14. return nil, errors.ParmsError
  15. }
  16. reply = &pb_v1.FieldCheckReply{}
  17. ok, fieldName := utils.CheckField(req.Content)
  18. if !ok {
  19. return reply, status.Error(20003, fmt.Sprintf("参数错误:字段%s不存在", fieldName))
  20. }
  21. return reply, nil
  22. }