forked from puppetlabs-toy-chest/wash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.go
41 lines (37 loc) · 903 Bytes
/
info.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
34
35
36
37
38
39
40
41
package api
import (
"encoding/json"
"fmt"
"net/http"
apitypes "github.com/puppetlabs/wash/api/types"
)
// swagger:route GET /fs/info info entryInfo
//
// Info about entry at path
//
// Returns an Entry object describing the given path.
//
// Produces:
// - application/json
//
// Schemes: http
//
// Responses:
// 200: Entry
// 400: errorResp
// 404: errorResp
// 500: errorResp
var infoHandler = handler{fn: func(w http.ResponseWriter, r *http.Request) *errorResponse {
entry, path, errResp := getEntryFromRequest(r)
if errResp != nil {
return errResp
}
jsonEncoder := json.NewEncoder(w)
// TODO: Include the entry's full metadata?
apiEntry := apitypes.NewEntry(entry)
apiEntry.Path = path
if err := jsonEncoder.Encode(&apiEntry); err != nil {
return unknownErrorResponse(fmt.Errorf("Could not marshal %v: %v", path, err))
}
return nil
}}