github.com/letsencrypt/trillian@v1.1.2-0.20180615153820-ae375a99d36a/server/memory_storage_provider.go (about)

     1  // Copyright 2018 Google Inc. All Rights Reserved.
     2  //
     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
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     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.
    14  
    15  package server
    16  
    17  import (
    18  	"github.com/golang/glog"
    19  	"github.com/google/trillian/monitoring"
    20  	"github.com/google/trillian/storage"
    21  	"github.com/google/trillian/storage/memory"
    22  )
    23  
    24  func init() {
    25  	if err := RegisterStorageProvider("memory", newMemoryStorageProvider); err != nil {
    26  		glog.Fatalf("Failed to register storage provider memory: %v", err)
    27  	}
    28  }
    29  
    30  type memProvider struct {
    31  	mf monitoring.MetricFactory
    32  	ls storage.LogStorage
    33  	as storage.AdminStorage
    34  }
    35  
    36  func newMemoryStorageProvider(mf monitoring.MetricFactory) (StorageProvider, error) {
    37  	ls := memory.NewLogStorage(mf)
    38  	return &memProvider{
    39  		mf: mf,
    40  		ls: ls,
    41  		as: memory.NewAdminStorage(ls),
    42  	}, nil
    43  }
    44  
    45  func (s *memProvider) LogStorage() storage.LogStorage {
    46  	return s.ls
    47  }
    48  
    49  func (s *memProvider) MapStorage() storage.MapStorage {
    50  	return nil
    51  }
    52  
    53  func (s *memProvider) AdminStorage() storage.AdminStorage {
    54  	return s.as
    55  }
    56  
    57  func (s *memProvider) Close() error {
    58  	return nil
    59  }