-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathnull.go
49 lines (38 loc) · 1.02 KB
/
null.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
package data
import (
"fmt"
"google.golang.org/protobuf/types/known/structpb"
"github.com/instill-ai/pipeline-backend/pkg/data/format"
"github.com/instill-ai/pipeline-backend/pkg/data/path"
)
type nullData struct {
}
func NewNull() *nullData {
return &nullData{}
}
func (nullData) IsValue() {}
func (nullData) Omittable() {}
func (n *nullData) Get(p *path.Path) (v format.Value, err error) {
if p == nil || p.IsEmpty() {
return n, nil
}
return nil, fmt.Errorf("path not found: %s", p)
}
// Deprecated: ToStructValue() is deprecated and will be removed in a future
// version. structpb is not suitable for handling binary data and will be phased
// out gradually.
func (n nullData) ToStructValue() (v *structpb.Value, err error) {
return structpb.NewNullValue(), nil
}
func (n *nullData) Equal(other format.Value) bool {
if _, ok := other.(*nullData); ok {
return true
}
return false
}
func (n *nullData) String() string {
return "null"
}
func (n *nullData) ToJSONValue() (v any, err error) {
return nil, nil
}