Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package api import "encoding/json" // This file implements json marshaling/unmarshaling interfaces on objects that are currently marshaled into annotations // to prevent anyone from marshaling these internal structs. var _ = json.Marshaler(Taint{}) var _ = json.Unmarshaler(&Taint{}) func (Taint) MarshalJSON() ([]byte, error) { panic("do not marshal internal struct") } func (*Taint) UnmarshalJSON([]byte) error { panic("do not unmarshal to internal struct") } var _ = json.Marshaler(Toleration{}) var _ = json.Unmarshaler(&Toleration{}) func (Toleration) MarshalJSON() ([]byte, error) { panic("do not marshal internal struct") } func (*Toleration) UnmarshalJSON([]byte) error { panic("do not unmarshal to internal struct") } var _ = json.Marshaler(&AvoidPods{}) var _ = json.Unmarshaler(&AvoidPods{}) func (AvoidPods) MarshalJSON() ([]byte, error) { panic("do not marshal internal struct") } func (*AvoidPods) UnmarshalJSON([]byte) error { panic("do not unmarshal to internal struct") }
} func (m *canMarshal) UnmarshalJSON(b []byte) error { parts := strings.SplitN(string(b), " ", 2) if len(parts) > 1 { m.name = parts[1] } else { m.name = parts[0] } return nil } // make sure canMarshal type implements json.Marshaler and json.Unmarshaler // interfaces var _ = json.Marshaler((*canMarshal)(nil)) var _ = json.Unmarshaler((*canMarshal)(nil)) type DummyMsg struct { String string `json:"str" endpoints:"req,desc=A string field"` Int int `json:"i" endpoints:"min=-200,max=200,d=-100"` Uint uint `endpoints:"min=0,max=100"` Int64 int64 `endpoints:"d=123"` Uint64 uint64 `endpoints:"d=123"` Float32 float32 `endpoints:"d=123.456"` Float64 float64 `endpoints:"d=123.456"` BoolField bool `json:"bool_field" endpoints:"d=true"` Bytes []byte Internal string `json:"-"` Marshal *canMarshal }
// Field does not have mutable state, it is considered read-only. // // In order to keep fields and their names separate, Field is not responsible for writing its name, and should not // attempt to write a name, only its value. type Field interface { Dup() Field io.WriterTo } // Bool is a Field that stores an InfluxDB boolean value. When written, it is encoded as either T or F, depending on its // value. Its zero value is false. type Bool uint32 var _ = Field((*Bool)(nil)) var _ = json.Marshaler((*Bool)(nil)) var _ = json.Unmarshaler((*Bool)(nil)) func (b *Bool) ptr() *uint32 { return (*uint32)(b) } func (b *Bool) sample() bool { return atomic.LoadUint32(b.ptr()) != 0 } // Set sets the Bool's value to new. func (b *Bool) Set(new bool) { var i uint32 if new { i = 1 }