Skip to content

Commit 843bde8

Browse files
committed
switch to consts for content-type
1 parent 40365dd commit 843bde8

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

main.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ func findUnpackPB(req *http.Request, responses []serverResponse) ([]*pb.GlobMatc
278278
return metrics, paths
279279
}
280280

281+
const (
282+
contentTypeJSON = "application/json"
283+
contentTypeProtobuf = "application/x-protobuf"
284+
contentTypePickle = "application/pickle"
285+
)
286+
281287
func findHandler(w http.ResponseWriter, req *http.Request) {
282288

283289
logger.Debugln("request: ", req.URL.RequestURI())
@@ -320,19 +326,19 @@ func findHandler(w http.ResponseWriter, req *http.Request) {
320326

321327
switch format {
322328
case "protobuf":
323-
w.Header().Set("Content-Type", "application/protobuf")
329+
w.Header().Set("Content-Type", contentTypeProtobuf)
324330
var result pb.GlobResponse
325331
query := req.FormValue("query")
326332
result.Name = &query
327333
result.Matches = metrics
328334
b, _ := result.Marshal()
329335
w.Write(b)
330336
case "json":
331-
w.Header().Set("Content-Type", "application/json")
337+
w.Header().Set("Content-Type", contentTypeJSON)
332338
jEnc := json.NewEncoder(w)
333339
jEnc.Encode(metrics)
334340
case "", "pickle":
335-
w.Header().Set("Content-Type", "application/pickle")
341+
w.Header().Set("Content-Type", contentTypePickle)
336342

337343
var result []map[string]interface{}
338344

@@ -397,19 +403,19 @@ func renderHandler(w http.ResponseWriter, req *http.Request) {
397403

398404
switch format {
399405
case "protobuf":
400-
w.Header().Set("Content-Type", "application/protobuf")
406+
w.Header().Set("Content-Type", contentTypeProtobuf)
401407
b, _ := metrics.Marshal()
402408
w.Write(b)
403409

404410
case "json":
405411
presponse := createRenderResponse(metrics, nil)
406-
w.Header().Set("Content-Type", "application/json")
412+
w.Header().Set("Content-Type", contentTypeJSON)
407413
e := json.NewEncoder(w)
408414
e.Encode(presponse)
409415

410416
case "", "pickle":
411417
presponse := createRenderResponse(metrics, pickle.None{})
412-
w.Header().Set("Content-Type", "application/pickle")
418+
w.Header().Set("Content-Type", contentTypePickle)
413419
e := pickle.NewEncoder(w)
414420
e.Encode(presponse)
415421
}
@@ -597,7 +603,7 @@ func infoHandler(w http.ResponseWriter, req *http.Request) {
597603

598604
switch format {
599605
case "protobuf":
600-
w.Header().Set("Content-Type", "application/protobuf")
606+
w.Header().Set("Content-Type", contentTypeProtobuf)
601607
var result pb.ZipperInfoResponse
602608
result.Responses = make([]*pb.ServerInfoResponse, len(infos))
603609
for s, i := range infos {
@@ -609,7 +615,7 @@ func infoHandler(w http.ResponseWriter, req *http.Request) {
609615
b, _ := result.Marshal()
610616
w.Write(b)
611617
case "", "json":
612-
w.Header().Set("Content-Type", "application/json")
618+
w.Header().Set("Content-Type", contentTypeJSON)
613619
jEnc := json.NewEncoder(w)
614620
jEnc.Encode(infos)
615621
}

0 commit comments

Comments
 (0)