~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/gopkg.in/juju/charmstore.v5-unstable/internal/router/singleinclude.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2014 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package router // import "gopkg.in/juju/charmstore.v5-unstable/internal/router"
 
5
 
 
6
import (
 
7
        "encoding/json"
 
8
        "net/http"
 
9
        "net/url"
 
10
 
 
11
        "gopkg.in/errgo.v1"
 
12
)
 
13
 
 
14
var _ BulkIncludeHandler = SingleIncludeHandler(nil)
 
15
 
 
16
// SingleIncludeHandler implements BulkMetaHander for a non-batching
 
17
// metadata retrieval function that can perform a GET only.
 
18
type SingleIncludeHandler func(id *ResolvedURL, path string, flags url.Values, req *http.Request) (interface{}, error)
 
19
 
 
20
// Key implements BulkMetadataHander.Key.
 
21
func (h SingleIncludeHandler) Key() interface{} {
 
22
        // Use a local type so that we are guaranteed that nothing
 
23
        // other than SingleIncludeHandler can generate that key.
 
24
        type singleMetaHandlerKey struct{}
 
25
        return singleMetaHandlerKey(singleMetaHandlerKey{})
 
26
}
 
27
 
 
28
// HandleGet implements BulkMetadataHander.HandleGet.
 
29
func (h SingleIncludeHandler) HandleGet(hs []BulkIncludeHandler, id *ResolvedURL, paths []string, flags url.Values, req *http.Request) ([]interface{}, error) {
 
30
        results := make([]interface{}, len(hs))
 
31
        for i, h := range hs {
 
32
                h := h.(SingleIncludeHandler)
 
33
                result, err := h(id, paths[i], flags, req)
 
34
                if err != nil {
 
35
                        // TODO(rog) include index of failed handler.
 
36
                        return nil, errgo.Mask(err, errgo.Any)
 
37
                }
 
38
                results[i] = result
 
39
        }
 
40
        return results, nil
 
41
}
 
42
 
 
43
var errPutNotImplemented = errgo.New("PUT not implemented")
 
44
 
 
45
// HandlePut implements BulkMetadataHander.HandlePut.
 
46
func (h SingleIncludeHandler) HandlePut(hs []BulkIncludeHandler, id *ResolvedURL, paths []string, values []*json.RawMessage, req *http.Request) []error {
 
47
        errs := make([]error, len(hs))
 
48
        for i := range hs {
 
49
                errs[i] = errPutNotImplemented
 
50
        }
 
51
        return errs
 
52
}