scylladb

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 5 Imported by: 0

README


id: scylladb title: ScyllaDb

Release Discord Test Security Linter

ScyllaDb

A ScyllaDb storage engine for Fiber using gocql.

Table of Contents

Signatures

func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, value []byte, expire time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() *gocql.Session

Installation

ScyllaDb is tested on the 2 last Go versions with support for modules. So make sure to initialize one first if you didn't do that yet:

go mod init github.com/<user>/<repo>

And then install the scylladb implementation:

go get github.com/gofiber/storage/scylladb

Examples

Import the storage package.

import "github.com/gofiber/storage/scylladb"

You can use the following possibilities to create a storage:

// Initialize default config
store := scylladb.New()

// Initialize custom config
store := scylladb.New(scylladb.Config{
    Keyspace:       "fiber",
    Hosts:          []string{"127.0.0.1"},
    Port:           9042,
    Table:          "fiber_storage",
    Consistency:    "ONE",
    Reset:          false,
})

// Initialize with support for TLS (SslOptions configures TLS use)
//  
//      InsecureSkipVerify and EnableHostVerification interact as follows:
//
//      |Config.InsecureSkipVerify | EnableHostVerification | Result             |
//      |--------------------------|------------------------|--------------------|
//      |Config is nil             | false                  | do not verify host |
//      |Config is nil             | true                   | verify host        |
//      |false                     | false                  | verify host        |
//      |true                      | false                  | do not verify host |
//      |false                     | true                   | verify host        |
//      |true                      | true                   | verify host        |
store := New(
    Config{
        Keyspace:    "fiber",
        Hosts:       []string{"127.0.0.1"},
        Port:        9042,
        Table:       "fiber_storage",
        Consistency: "ONE",
        SslOpts: &gocql.SslOptions{
            Config: &tls.Config{
                InsecureSkipVerify: false, // Set this too false to enable certificate verification
            },
                CertPath:               "/path/to/client_cert.pem", // Path to the client certificate
                KeyPath:                "/path/to/client_key.pem",  // Path to the client certificate's private key
                CaPath:                 "/path/to/ca_cert.pem",     // Path to the CA certificate
                EnableHostVerification: true,                       // Enable hostname verification
        },
        Reset: false,
    },
)

// Initialize custom config using scylladb connection
cluster, _ := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "fiber"
cluster.Port = 9042

session, _ := cluster.CreateSession()
store := scylladb.New(scylladb.Config{
    Session:         session,
    Keyspace:        "fiber",
    Table:           "fiber_storage",
    Reset:           false,
})

Config

type Config struct {
    // Session is provided by the user to use an existing ScyllaDb session
    // Session Will override Keyspace and all other authentication values if used
    //
    // Optional. Default is nil
    Session *gocql.Session

    // Keyspace name
    //
    // Optional. Default is "fiber"
    Keyspace string

    // Hosts are an array of network addresses for establishing initial connections
    // You have the flexibility to specify one or multiple addresses as needed
    //
    // Optional. Default is "127.0.0.1"
    Hosts []string

    // Port where the ScyllaDb cluster is listening on
    //
    // Optional. Default is 9042
    Port int

    // Username for ScyllaDb cluster
    //
    // Optional. Default is ""
    Username string

    // Password for ScyllaDb cluster
    //
    // Optional. Default is ""
    Password string

    // Table name
    //
    // Optional. Default is "fiber_storage"
    Table string

    // Level of the consistency
    //
    // Optional. Default is "LOCAL_ONE"
    Consistency string

    // SslOpts configures TLS use.
    //
    // Optional. Default is nil
    SslOpts *gocql.SslOptions
    
    // Reset clears any existing keys in existing Table
    //
    // Optional. Default is false
    Reset bool
}

Default Config

// ConfigDefault is the default config
var ConfigDefault = Config{
    Session:     nil,
    Keyspace:    "fiber",
    Hosts:       []string{"127.0.0.1"},
    Username:    "",
    Password:    "",
    Port:        9042,
    Table:       "fiber_storage",
    Consistency: "LOCAL_ONE",
    SslOpts:     nil,
    Reset:       false,
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Session:     nil,
	Keyspace:    "fiber",
	Hosts:       []string{"127.0.0.1"},
	Username:    "",
	Password:    "",
	Port:        9042,
	Table:       "fiber_storage",
	Consistency: "LOCAL_ONE",
	SslOpts:     nil,
	Reset:       false,
}

ConfigDefault is the default config

Functions

This section is empty.

Types

type Config

type Config struct {
	// Session is provided by the user to use an existing ScyllaDb session
	//
	// Optional. Default is nil
	Session *gocql.Session

	// Keyspace name
	//
	// Optional. Default is "fiber"
	Keyspace string

	// Hosts are an array of network addresses for establishing initial connections.
	// You have the flexibility to specify one or multiple addresses as needed.
	//
	// Optional. Default is "127.0.0.1"
	Hosts []string

	// Port where the ScyllaDb cluster is listening on
	//
	// Optional. Default is 9042
	Port int

	// Username for ScyllaDb cluster
	//
	// Optional. Default is ""
	Username string

	// Password for ScyllaDb cluster
	//
	// Optional. Default is ""
	Password string

	// Table name
	//
	// Optional. Default is "fiber_storage"
	Table string

	// Level of the consistency
	//
	// Optional. Default is "LOCAL_ONE"
	Consistency string

	// SslOpts configures TLS use.
	//
	// Optional. Default is nil
	SslOpts *gocql.SslOptions

	// Reset clears any existing keys in existing Table
	//
	// Optional. Default is false
	Reset bool
}

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage interface that is implemented by storage providers

func New

func New(config ...Config) *Storage

New creates a new storage

func (*Storage) Close

func (s *Storage) Close() error

Close closes the storage

func (*Storage) Conn

func (s *Storage) Conn() *gocql.Session

Conn returns the underlying gocql session

func (*Storage) Delete

func (s *Storage) Delete(key string) error

Delete removes a value by key

func (*Storage) Get

func (s *Storage) Get(key string) ([]byte, error)

Get retrieves a value by key

func (*Storage) Reset

func (s *Storage) Reset() error

Reset resets all values

func (*Storage) Set

func (s *Storage) Set(key string, value []byte, expire time.Duration) error

Set sets a value by key

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL