โšก
LightningUserVault
  • Introduction
  • GETTING STARTED
    • Quickstart Guide
      • Docker Deployment
      • Local Deployment
    • Server Commands
  • Architecture
    • Overview
    • API Server
    • Data Storage:
      • Key-Value Databases
        • Pebbel DB
      • SQL Databases
        • PostgreSQL
    • Caching Mechanism:
      • MEMCACHE
  • Additional Features
    • Swagger
    • Postman Collection
    • Prometheus
    • Grafana
  • Releases
  • Contribution
Powered by GitBook
On this page
  1. Architecture

Data Storage:

At LightningUserVault, we value flexibility. With our Storage interface, you can easily integrate a variety of storage systems. We currently support Pebble for key-value storage and PostgreSQL for SQL, but the architecture allows for easy expansion.

โœ… Currently Supported:

  1. Pebble (Key-Value)

  2. PostgreSQL (SQL)

๐Ÿ”Œ Storage Interface:

If you're interested in adding more storage options, here's the interface to guide you:

type Storage interface {
	// Set stores a value and returns user ID and an error if any issue occurs during the operation
	Set(value string) (int64, error)

	// Get retrieves the value for a given user ID and returns an error if any issue occurs during the operation
	Get(key int64) (*common.User, error)

	// Close closes storage instance
	Close() error
}

๐Ÿงช Mock Implementations for Testing

For developers and testers, we offer mock implementation of database interface

package mocks

import "github.com/Aleksao998/LightningUserVault/core/common"

type (
	getDelegate   func(key int64) (*common.User, error)
	setDelegate   func(value string) (int64, error)
	closeDelegate func() error
)

type MockStorage struct {
	GetFn   getDelegate
	SetFn   setDelegate
	CloseFn closeDelegate
}

func (m *MockStorage) Get(key int64) (*common.User, error) {
	if m.GetFn != nil {
		return m.GetFn(key)
	}

	return nil, nil
}

func (m *MockStorage) Set(value string) (int64, error) {
	if m.SetFn != nil {
		return m.SetFn(value)
	}

	return 0, nil
}

func (m *MockStorage) Close() error {
	if m.CloseFn != nil {
		return m.CloseFn()
	}

	return nil
}

Usage example:

mockStorage := &storageMock.MockStorage{
	GetFn: func(key int64) (*common.User, error) {
		return nil, errUserNotFound
	},
	SetFn: func(value string) (int64, error) {
		return 0, errInternal
	},
}

PreviousAPI ServerNextKey-Value Databases

Last updated 1 year ago