github.com/Mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/metadata/client.go (about)

     1  /*
     2  Copyright 2016 Mirantis
     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.
    15  */
    16  
    17  package metadata
    18  
    19  import (
    20  	"github.com/boltdb/bolt"
    21  )
    22  
    23  type boltClient struct {
    24  	db *bolt.DB
    25  }
    26  
    27  // NewStore is a factory function for Store interface
    28  func NewStore(path string) (Store, error) {
    29  	db, err := bolt.Open(path, 0600, nil)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	client := &boltClient{db: db}
    35  	return client, nil
    36  }
    37  
    38  // Close releases all database resources
    39  func (b boltClient) Close() error {
    40  	return b.db.Close()
    41  }