-
Notifications
You must be signed in to change notification settings - Fork 0
/
callmeta.go
36 lines (30 loc) · 866 Bytes
/
callmeta.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) The go-grpc-middleware Authors.
// Licensed under the Apache License 2.0.
package interceptors
import (
"fmt"
"strings"
"connectrpc.com/connect"
)
func splitFullMethodName(fullMethod string) (string, string) {
fullMethod = strings.TrimPrefix(fullMethod, "/") // remove leading slash
if i := strings.Index(fullMethod, "/"); i >= 0 {
return fullMethod[:i], fullMethod[i+1:]
}
return "unknown", "unknown"
}
type CallMeta struct {
ReqOrNil any
Typ connect.StreamType
Service string
Method string
IsClient bool
}
func NewServerCallMeta(spec connect.Spec, reqOrNil any) CallMeta {
c := CallMeta{IsClient: spec.IsClient, ReqOrNil: reqOrNil, Typ: spec.StreamType}
c.Service, c.Method = splitFullMethodName(spec.Procedure)
return c
}
func (c CallMeta) FullMethod() string {
return fmt.Sprintf("/%s/%s", c.Service, c.Method)
}