MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / Interface

Function Interface

pkg/goproto/struct.go:103–120  ·  view source on GitHub ↗

Interface returns the Value proto as an interface{}.

(v *structpb.Value, opts ...Option)

Source from the content-addressed store, hash-verified

101
102// Interface returns the Value proto as an interface{}.
103func Interface(v *structpb.Value, opts ...Option) (any, error) {
104 switch v := v.GetKind().(type) {
105 case *structpb.Value_NullValue:
106 return nil, nil
107 case *structpb.Value_NumberValue:
108 return v.NumberValue, nil
109 case *structpb.Value_StringValue:
110 return v.StringValue, nil
111 case *structpb.Value_BoolValue:
112 return v.BoolValue, nil
113 case *structpb.Value_StructValue:
114 return Map(v.StructValue, opts...)
115 case *structpb.Value_ListValue:
116 return Slice(v.ListValue, opts...)
117 default:
118 return nil, fmt.Errorf("unmatched structpb type: %T", v)
119 }
120}
121
122// Struct returns the map as a Struct proto.
123func Struct(m map[string]any, opts ...Option) (*structpb.Struct, error) {

Callers 5

FromProtoFunction · 0.92
TestStructProtoFunction · 0.92
TestRecursiveStructuresFunction · 0.92
MapFunction · 0.70
SliceFunction · 0.70

Calls 3

SliceFunction · 0.85
MapFunction · 0.70
ErrorfMethod · 0.65

Tested by 2

TestStructProtoFunction · 0.74
TestRecursiveStructuresFunction · 0.74