util.go 832 B

123456789101112131415161718192021222324252627
  1. // Copyright 2016 Michal Witkowski. All Rights Reserved.
  2. // See LICENSE for licensing terms.
  3. package grpc_prometheus
  4. import (
  5. "strings"
  6. "google.golang.org/grpc/codes"
  7. )
  8. var (
  9. allCodes = []codes.Code{
  10. codes.OK, codes.Canceled, codes.Unknown, codes.InvalidArgument, codes.DeadlineExceeded, codes.NotFound,
  11. codes.AlreadyExists, codes.PermissionDenied, codes.Unauthenticated, codes.ResourceExhausted,
  12. codes.FailedPrecondition, codes.Aborted, codes.OutOfRange, codes.Unimplemented, codes.Internal,
  13. codes.Unavailable, codes.DataLoss,
  14. }
  15. )
  16. func splitMethodName(fullMethodName string) (string, string) {
  17. fullMethodName = strings.TrimPrefix(fullMethodName, "/") // remove leading slash
  18. if i := strings.Index(fullMethodName, "/"); i >= 0 {
  19. return fullMethodName[:i], fullMethodName[i+1:]
  20. }
  21. return "unknown", "unknown"
  22. }