github.com/uber/kraken@v0.1.4/tracker/trackerserver/metainfo.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, Inc. 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 package trackerserver 15 16 import ( 17 "fmt" 18 "net/http" 19 20 "github.com/uber/kraken/utils/handler" 21 "github.com/uber/kraken/utils/httputil" 22 ) 23 24 func (s *Server) getMetaInfoHandler(w http.ResponseWriter, r *http.Request) error { 25 namespace, err := httputil.ParseParam(r, "namespace") 26 if err != nil { 27 return err 28 } 29 d, err := httputil.ParseDigest(r, "digest") 30 if err != nil { 31 return handler.Errorf("parse digest: %s", err).Status(http.StatusBadRequest) 32 } 33 34 timer := s.stats.Timer("get_metainfo").Start() 35 mi, err := s.originCluster.GetMetaInfo(namespace, d) 36 if err != nil { 37 if serr, ok := err.(httputil.StatusError); ok { 38 // Propagate errors received from origin. 39 return handler.Errorf("origin: %s", serr.ResponseDump).Status(serr.Status) 40 } 41 return err 42 } 43 timer.Stop() 44 45 b, err := mi.Serialize() 46 if err != nil { 47 return fmt.Errorf("serialize metainfo: %s", err) 48 } 49 w.Header().Set("Content-Type", "application/json") 50 w.Write(b) 51 return nil 52 }