-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcallmeta.go
67 lines (53 loc) · 1.65 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2024 The Concerto Contributors.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// Copyright (c) The go-grpc-middleware Authors.
// Licensed under the Apache License 2.0.
package concerto
import (
"context"
"github.com/gorhythm/concerto/transport"
)
type contextKey int
const (
contextKeyCallMeta contextKey = iota
)
var (
// NilCallMeta is empty CallMeta, all zero values.
NilCallMeta CallMeta
)
// ContextWithCallMeta returns a copy of ctx with v set as the call meta value.
func ContextWithCallMeta(ctx context.Context, v CallMeta) context.Context {
return context.WithValue(ctx, contextKeyCallMeta, v)
}
// CallMetaFromContext returns the call meta from ctx.
func CallMetaFromContext(ctx context.Context) CallMeta {
if ctx == nil {
return NilCallMeta
}
if v, ok := ctx.Value(contextKeyCallMeta).(CallMeta); ok {
return v
}
return NilCallMeta
}
// MethodInfo represents information about a specific method.
type MethodInfo struct {
// Name is the name of the method.
Name string
// FullName is the fully qualified name of the method.
FullName string
}
// CallMeta contains metadata related to a method call.
type CallMeta struct {
// Service is the name of the service containing the method.
Service string
// Method is the name of the specific method.
Method string
// Transport is the transport used for the call.
Transport transport.Transport
}
// FullMethod returns the fully qualified method name (service/method).
// Example: "concerto.test.v1.TestService/Ping".
func (c CallMeta) FullMethod() string {
return c.Service + "/" + c.Method
}