1// @author Couchbase <info@couchbase.com> 2// @copyright 2015 Couchbase, Inc. 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15package main 16 17import ( 18 "encoding/json" 19 20 "github.com/couchbase/cbauth/metakv" 21 log "github.com/couchbase/clog" 22) 23 24func MetakvGet(path string, v interface{}) bool { 25 raw, _, err := metakv.Get(path) 26 if err != nil { 27 log.Fatalf("Failed to fetch %s from metakv: %s", path, err.Error()) 28 } 29 30 if raw == nil { 31 return false 32 } 33 34 err = json.Unmarshal(raw, v) 35 if err != nil { 36 log.Fatalf("Failed unmarshalling value for %s: %s\n%s", 37 path, err.Error(), string(raw)) 38 } 39 40 return true 41} 42 43func MetakvSet(path string, v interface{}) { 44 raw, err := json.Marshal(v) 45 if err != nil { 46 log.Fatalf("Failed to marshal value for %s: %s\n%v", 47 path, err.Error(), v) 48 } 49 50 err = metakv.Set(path, raw, nil) 51 if err != nil { 52 log.Fatalf("Failed to set %s: %s", path, err.Error()) 53 } 54} 55