Skip to content

Commit

Permalink
add types for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
travisjeffery committed Oct 19, 2016
1 parent 9f0cb7f commit af87a57
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@ type Store interface {
Join(addr []byte) error
}

type MetadataRequest struct {
Topics []string `json:"topics"`
}

type Broker struct {
ID int `json:"id"`
Host string `json:"host"`
Port int `json:"port"`
}

type PartitionMetadata struct {
ErrorCode int `json:"error_code"`
ID int `json:"id"`
Leader int `json:"leader"`
Replicas []int `json:"replicas"`
}

type TopicMetadata struct {
ErrorCode int `json:"error_code"`
Topic string `json:"topic"`
PartitionMetadata []PartitionMetadata `json:"partition_metadata"`
}

type MetadataResponse struct {
Brokers []Broker `json:"brokers"`
ControllerID int `json:"controller_id"`
TopicMetadata []TopicMetadata `json:"topic_metadata"`
}

type Server struct {
addr string
ln net.Listener
Expand Down Expand Up @@ -69,6 +98,8 @@ func (s *Server) Close() {
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/join" {
s.handleJoin(w, r)
} else if r.URL.Path == "/metadata" {
s.handleMetadata(w, r)
} else {
w.WriteHeader(http.StatusNotFound)
}
Expand Down Expand Up @@ -98,6 +129,14 @@ func (s *Server) handleJoin(w http.ResponseWriter, r *http.Request) {
}
}

func (s *Server) handleMetadata(w http.ResponseWriter, r *http.Request) {
m := new(MetadataRequest)
if err := json.NewDecoder(r.Body).Decode(m); err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
}

// Addr returns the address on which the Server is listening
func (s *Server) Addr() net.Addr {
return s.ln.Addr()
Expand Down

0 comments on commit af87a57

Please sign in to comment.