1 // Copyright 2015 go-swagger maintainers
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 // ResolutionCache a cache for resolving urls
20 type ResolutionCache interface {
21 Get(string) (interface{}, bool)
22 Set(string, interface{})
25 type simpleCache struct {
27 store map[string]interface{}
30 // Get retrieves a cached URI
31 func (s *simpleCache) Get(uri string) (interface{}, bool) {
32 debugLog("getting %q from resolution cache", uri)
35 debugLog("got %q from resolution cache: %t", uri, ok)
42 func (s *simpleCache) Set(uri string, data interface{}) {
48 var resCache ResolutionCache
51 resCache = initResolutionCache()
54 // initResolutionCache initializes the URI resolution cache
55 func initResolutionCache() ResolutionCache {
56 return &simpleCache{store: map[string]interface{}{
57 "http://swagger.io/v2/schema.json": MustLoadSwagger20Schema(),
58 "http://json-schema.org/draft-04/schema": MustLoadJSONSchemaDraft04(),