go.etcd.io/etcd@v3.3.27+incompatible/etcdserver/api/v2http/httptypes/member.go (about) 1 // Copyright 2015 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package httptypes defines how etcd's HTTP API entities are serialized to and 16 // deserialized from JSON. 17 package httptypes 18 19 import ( 20 "encoding/json" 21 22 "github.com/coreos/etcd/pkg/types" 23 ) 24 25 type Member struct { 26 ID string `json:"id"` 27 Name string `json:"name"` 28 PeerURLs []string `json:"peerURLs"` 29 ClientURLs []string `json:"clientURLs"` 30 } 31 32 type MemberCreateRequest struct { 33 PeerURLs types.URLs 34 } 35 36 type MemberUpdateRequest struct { 37 MemberCreateRequest 38 } 39 40 func (m *MemberCreateRequest) UnmarshalJSON(data []byte) error { 41 s := struct { 42 PeerURLs []string `json:"peerURLs"` 43 }{} 44 45 err := json.Unmarshal(data, &s) 46 if err != nil { 47 return err 48 } 49 50 urls, err := types.NewURLs(s.PeerURLs) 51 if err != nil { 52 return err 53 } 54 55 m.PeerURLs = urls 56 return nil 57 } 58 59 type MemberCollection []Member 60 61 func (c *MemberCollection) MarshalJSON() ([]byte, error) { 62 d := struct { 63 Members []Member `json:"members"` 64 }{ 65 Members: []Member(*c), 66 } 67 68 return json.Marshal(d) 69 }