MCPcopy Create free account
hub / github.com/couchbase/cbft / UnmarshalJSON

Method UnmarshalJSON

pindex_bleve_doc.go:58–117  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

56}
57
58func (b *BleveDocumentConfig) UnmarshalJSON(data []byte) error {
59 docIDRegexp := ""
60 if b.DocIDRegexp != nil {
61 docIDRegexp = b.DocIDRegexp.String()
62 }
63 if b.CollPrefixLookup == nil {
64 b.CollPrefixLookup = make(map[uint32]*collMetaField, 1)
65 }
66 tmp := struct {
67 Mode string `json:"mode"`
68 TypeField string `json:"type_field"`
69 DocIDPrefixDelim string `json:"docid_prefix_delim"`
70 DocIDRegexp string `json:"docid_regexp"`
71 CollPrefixLookup map[uint32]*collMetaField
72 }{
73 Mode: b.Mode,
74 TypeField: b.TypeField,
75 DocIDPrefixDelim: b.DocIDPrefixDelim,
76 DocIDRegexp: docIDRegexp,
77 CollPrefixLookup: b.CollPrefixLookup,
78 }
79 err := json.Unmarshal(data, &tmp)
80 if err != nil {
81 return err
82 }
83 b.Mode = tmp.Mode
84 switch tmp.Mode {
85 case "scope.collection":
86 return nil
87 case "scope.collection.type_field":
88 fallthrough
89 case "type_field":
90 b.TypeField = tmp.TypeField
91 if b.TypeField == "" {
92 return fmt.Errorf("with mode type_field, type_field cannot be empty")
93 }
94 case "scope.collection.docid_prefix":
95 fallthrough
96 case "docid_prefix":
97 b.DocIDPrefixDelim = tmp.DocIDPrefixDelim
98 if b.DocIDPrefixDelim == "" {
99 return fmt.Errorf("with mode docid_prefix, docid_prefix_delim cannot be empty")
100 }
101 case "scope.collection.docid_regexp":
102 fallthrough
103 case "docid_regexp":
104 if tmp.DocIDRegexp != "" {
105 b.DocIDRegexp, err = regexp.Compile(tmp.DocIDRegexp)
106 if err != nil {
107 return err
108 }
109 } else {
110 return fmt.Errorf("with mode docid_regexp, docid_regexp cannot be empty")
111 }
112 default:
113 return fmt.Errorf("unknown mode: %s", tmp.Mode)
114 }
115

Callers

nothing calls this directly

Calls 2

UnmarshalMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected