-
Notifications
You must be signed in to change notification settings - Fork 67
/
index.go
33 lines (28 loc) · 869 Bytes
/
index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"net/http"
"time"
"github.com/elastic/package-registry/internal/util"
)
type indexData struct {
ServiceName string `json:"service.name"`
Version string `json:"service.version"`
}
func indexHandler(cacheTime time.Duration) (func(w http.ResponseWriter, r *http.Request), error) {
data := indexData{
ServiceName: serviceName,
Version: version,
}
body, err := util.MarshalJSONPretty(&data)
if err != nil {
return nil, err
}
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
cacheHeaders(w, cacheTime)
w.Write(body)
}, nil
}