142}
143
144// UnmarshalTOML implements the `toml.Unmarshaler` interface to ensure the compatibility.
145func (t *RedactInfoLogType) UnmarshalTOML(data any) error {146 switch v := data.(type) {
147 case bool:
148 if v {
121const invalidRedactInfoLogTypeErrMsg = `the "redact-info-log" value is invalid; it should be either false, true, or "MARKER"`
122
123// UnmarshalJSON implements the `json.Marshaler` interface to ensure the compatibility.
124func (t *RedactInfoLogType) UnmarshalJSON(data []byte) error {125 var s string
126 err := json.Unmarshal(data, &s)
127 if err == nil && strings.ToUpper(s) == "MARKER" {
107)
108
109// MarshalJSON implements the `json.Marshaler` interface to ensure the compatibility.
110func (t RedactInfoLogType) MarshalJSON() ([]byte, error) {111 switch t {
112 case RedactInfoLogON:
113 return json.Marshal(true)
298 // no need to clear
299}
300
301func (s indices) find(k int) (index int, found bool) { 302 i := sort.SearchInts(s, k)
303 return i, s[i] == k
304}
293 return out
294}
295
296func (s *indices) truncate(index int) { 297 *s = (*s)[:index]
298 // no need to clear
299}
(Go's FAQ)[https://go.dev/doc/faq#methodsonvaluesorpointers] recommends that method receivers should be consistent. If some of the methods of the type must have pointer receivers, the rest should too, so the method set is consistent regardless of how the type is used. This is because value and pointer receivers have different method sets.
package main
type foo struct {
a int
}
func (f foo) a() {}
func (f *foo) b() {
f.a = 10
}
package main
type foo struct {
a int
}
func (f *foo) a() {}
func (f *foo) b() {
f.a = 10
}