/
extoptions.go
38 lines (27 loc) · 1.04 KB
/
extoptions.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
package optparse
import (
kvstoreProto "github.com/ehsundar/kvstore/protobuf/kvstore"
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
)
func ExtractKeyOptions(msg *protogen.Message) *kvstoreProto.KVStoreKeyOptions {
logrus.Debugf("extracting key options from message: %s", msg.Desc.Name())
if !proto.HasExtension(msg.Desc.Options(), kvstoreProto.E_KeyOptions) {
return nil
}
ext := proto.GetExtension(msg.Desc.Options(), kvstoreProto.E_KeyOptions)
logrus.Debugf("message options: %+v", ext)
o, _ := ext.(*kvstoreProto.KVStoreKeyOptions)
return o
}
func ExtractValueOptions(msg *protogen.Message) *kvstoreProto.KVStoreValueOptions {
logrus.Debugf("extracting value options from message: %s", msg.Desc.Name())
if !proto.HasExtension(msg.Desc.Options(), kvstoreProto.E_ValueOptions) {
return nil
}
ext := proto.GetExtension(msg.Desc.Options(), kvstoreProto.E_ValueOptions)
logrus.Debugf("message options: %+v", ext)
o, _ := ext.(*kvstoreProto.KVStoreValueOptions)
return o
}