canned

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 8 Imported by: 0

README

Canned

Github Status GoDoc

Stores your secrets.

Usage

package main

import (
	"fmt"

	"github.com/jpedro/canned"
)

func main() {
	file := "/tmp/example.can"
	password := "test123"
	name := "hello"
	value := "world"

	can, _ := canned.InitCan(file, password)
	can.SetItem(name, value)
	can.Save()

	can, _ = canned.OpenCan(file, password)
	item, _ := can.GetItem(name)

	fmt.Printf("Item '%s' content: '%s'.\n", name, item.Content)
}

CLI

Check cli/canned for your terminal needs.

Documentation

Index

Constants

View Source
const (
	VERSION   = "v1"
	ALGORITHM = "GCM"
	SEPARATOR = "\n\n"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Can

type Can struct {
	Version  string           `json:"version"   yaml:"version"`
	Metadata Metadata         `json:"metadata"  yaml:"metadata"`
	Items    map[string]*Item `json:"items"     yaml:"items"`
	// contains filtered or unexported fields
}

Can struct

func InitCan

func InitCan(file string, password string) (*Can, error)

Initializes a new can file This will overwrite any existing file.

func NewCan

func NewCan(file string, password string) (*Can, error)

Creates a new can object

func OpenCan

func OpenCan(file string, password string) (*Can, error)

Opens a can file If the file doesn't exist, it will fail to load

func (*Can) AddTag

func (can *Can) AddTag(name string, tag string) error

AddTag appends a tag to an item

func (*Can) DelItem

func (can *Can) DelItem(name string) error

DelItem deletes an existing item

func (*Can) DelTag

func (can *Can) DelTag(name string, tag string) error

DelTag removes a tag from an item

func (*Can) GetItem

func (can *Can) GetItem(name string) (*Item, error)

GetItem retrieves an existing item

func (*Can) RenameItem

func (can *Can) RenameItem(name string, newName string) error

RenameItem renames an existing item

func (*Can) Save

func (can *Can) Save() error

Save stores a can to file

func (*Can) SetItem

func (can *Can) SetItem(name string, value string) error

SetItem stores an item's name and value

type Item

type Item struct {
	Content  string   `json:"content" yaml:"content"`
	Metadata Metadata `json:"metadata" yaml:"metadata"`
	Tags     []string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

Item struct

func NewItem

func NewItem(name string, content string) (*Item, error)

Creates a new item object

type Metadata

type Metadata struct {
	CreatedAt time.Time `json:"createdAt" yaml:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"`
}

Metadata struct

Jump to

Keyboard shortcuts

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