-
Notifications
You must be signed in to change notification settings - Fork 11
/
placement.go
92 lines (74 loc) · 2.72 KB
/
placement.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package storj
import (
"database/sql/driver"
"strconv"
"github.com/zeebo/errs"
)
// PlacementConstraint is the ID of the placement/geofencing rule.
type PlacementConstraint uint16
const (
// DefaultPlacement placement is used, when no specific placement rule is defined.
DefaultPlacement PlacementConstraint = 0
// EveryCountry includes all countries.
// Deprecated: use DefaultPlacement, which may exclude some nodes based on placement configuration.
EveryCountry PlacementConstraint = 0
// EU includes only the 27 members of European Union.
// Deprecated: placement definitions depend on the configuration.
EU PlacementConstraint = 1
// EEA defines the European Economic Area (EU + 3 countries), the area where GDPR is valid.
// Deprecated: placement definitions depend on the configuration.
EEA PlacementConstraint = 2
// US filters nodes only from the United States.
// Deprecated: placement definitions depend on the configuration.
US PlacementConstraint = 3
// DE placement uses nodes only from Germany.
// Deprecated: placement definitions depend on the configuration.
DE PlacementConstraint = 4
// InvalidPlacement is used when there is no information about the stored placement.
// Deprecated: placement definitions depend on the configuration.
InvalidPlacement PlacementConstraint = 5
// NR placement uses nodes that are not in RU or other countries sanctioned because of the RU/UA War.
// Deprecated: placement definitions depend on the configuration.
NR PlacementConstraint = 6
)
// Value implements the driver.Valuer interface.
func (p PlacementConstraint) Value() (driver.Value, error) {
return int64(p), nil
}
// Scan implements the sql.Scanner interface.
func (p *PlacementConstraint) Scan(value interface{}) error {
if value == nil {
*p = DefaultPlacement
return nil
}
if _, isInt64 := value.(int64); !isInt64 {
return errs.New("unable to scan %T into PlacementConstraint", value)
}
code, err := driver.Int32.ConvertValue(value)
if err != nil {
return errs.Wrap(err)
}
*p = PlacementConstraint(uint16(code.(int64)))
return nil
}
// EncodeSpanner implements spanner.Encoder.
func (p PlacementConstraint) EncodeSpanner() (any, error) {
return p.Value()
}
// DecodeSpanner implements spanner.Decoder.
func (p *PlacementConstraint) DecodeSpanner(input any) error {
if sVal, ok := input.(string); ok {
iVal, err := strconv.ParseInt(sVal, 10, 64)
if err != nil {
return err
}
if int64(PlacementConstraint(iVal)) != iVal {
return errs.New("value out of bounds for PlacementConstraint: %d", iVal)
}
*p = PlacementConstraint(iVal)
return nil
}
return errs.New("unable to decode %q to PlacementConstraint", input)
}