secretstorage

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 9 Imported by: 2

README

Secret Storage

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

A library for storing and retrieving secrets.

Prerequisites

  • Go >= 1.21

Install

go get go.nhat.io/secretstorage

Usage

package main

import (
    "fmt"

    "go.nhat.io/secretstorage"
)

func main() {
    ss := secretstorage.NewKeyringStorage[string]()

    err := ss.Set("service", "key", "value")
    if err != nil {
        panic(err)
    }

    value, err := ss.Get("service", "key")
    if err != nil {
        panic(err)
    }

    fmt.Println(value)
}

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this

Documentation

Overview

Package secretstorage provides a generic interface for storing and retrieving data from a secret storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is a not found error.
	ErrNotFound = keyring.ErrNotFound
	// ErrUnsupportedType is an unsupported type error.
	ErrUnsupportedType = errors.New("unsupported type")
)

Functions

This section is empty.

Types

type KeyringStorage

type KeyringStorage[V any] struct {
	// contains filtered or unexported fields
}

KeyringStorage is a storage implementation that uses the OS keyring.

func NewKeyringStorage

func NewKeyringStorage[V any](opts ...KeyringStorageOption) *KeyringStorage[V]

NewKeyringStorage creates a new KeyringStorage that uses the OS keyring.

func (*KeyringStorage[V]) Delete

func (ss *KeyringStorage[V]) Delete(service string, key string) error

Delete deletes the value for the given key.

func (*KeyringStorage[V]) Get

func (ss *KeyringStorage[V]) Get(service string, key string) (V, error)

Get gets the value for the given key.

func (*KeyringStorage[V]) Set

func (ss *KeyringStorage[V]) Set(service string, key string, value V) error

Set sets the value for the given key.

type KeyringStorageOption

type KeyringStorageOption interface {
	// contains filtered or unexported methods
}

KeyringStorageOption is an option to configure KeyringStorage.

func WithKeyring

func WithKeyring(k keyring.Keyring) KeyringStorageOption

WithKeyring sets the keyring to use.

type Storage

type Storage[V any] interface {
	Set(service string, key string, value V) error
	Get(service string, key string) (V, error)
	Delete(service string, key string) error
}

Storage is a generic interface for storing and retrieving data.

Directories

Path Synopsis
Package mock provides mocks for secretstorage package.
Package mock provides mocks for secretstorage package.

Jump to

Keyboard shortcuts

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