storage

package
v0.0.0-...-801542d Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Storage

One interface to connect many of database, This package is aimed not only used for codenoid/file.io

Installation

go get -u github.com/codenoid/file.io/storage

Storage Support

  • Redis
  • MongoDB
  • MySQL
  • PostgreSQL
  • Cloud Storage (Google)
  • File

Example Usage


import "github.com/codenoid/file.io/storage"

// type://user:pass@host:port/database
stg, err := storage.Connect("redis://127.0.0.1:6379/0")

// then you can call this function
stg.Set()
stg.Get()
Stg.Del()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Badger

type Badger struct {
	Conn *badger.DB
}

Badger storage

func (*Badger) Connect

func (r *Badger) Connect(database string)

Connect will start redis connection

func (*Badger) Del

func (r *Badger) Del(key string)

Del uwu

func (*Badger) Get

func (r *Badger) Get(key string) ([]byte, error)

Get get bytes from redis and write bytes as response (file)

func (*Badger) Set

func (r *Badger) Set(key string, value []byte, expired time.Duration) error

Set set bytes file to redis using unique id as key

type Redis

type Redis struct {
	Conn *redis.Client
}

Redis storage

func (*Redis) Connect

func (r *Redis) Connect(addr, password, database string)

Connect will start redis connection

func (*Redis) Del

func (r *Redis) Del(key string)

Del uwu

func (*Redis) Get

func (r *Redis) Get(key string) ([]byte, error)

Get get bytes from redis and write bytes as response (file)

func (*Redis) Set

func (r *Redis) Set(key string, value []byte, expired time.Duration) error

Set set bytes file to redis using unique id as key

type StorageHandler

type StorageHandler interface {
	Set(key string, value []byte, expired time.Duration) error
	Get(key string) ([]byte, error)
	Del(key string)
}

func Connect

func Connect(database string) (StorageHandler, error)

Connect to specified `database`, return error if given `database` are invalid or unknown or panic if failed to connect

Jump to

Keyboard shortcuts

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