seer

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 11 Imported by: 17

README

taubyte/go-seer

Release License Go Report Card GoDoc Discord

Go-seer is a tool to parse and edit YAML files in a directory as one structure.

Features

  • Preserves comments and formatting of original document
  • Creates non existing documents
  • Maps folders and files to objects

Note: Under the hood we use gopkg.in/yaml.v3 so YAML 1.1 & 1.2 are supported.

Installation

The import path for the package is github.com/taubyte/go-seer.

To install it, run:

go get github.com/taubyte/go-seer

Usage

First start by creating an instance of go-seer

s := New(SystemFS("config/"))

Note that you can also use a virtual file system.

import "github.com/spf13/afero"

vfs := afero.NewMemMapFs()

s := New(VirtualFS(vfs,"config/"))

Now, let's build a query that will create a YAML file representing a leaf object:

type EV struct {
    Battery int
    Range int
}

err = seer.Get("cars").Get("electric").Get("taumobile").Document().Set(EV{Battery: 100, Range:400}).Commit()

If you check the file system you will find

cars/
  electric/
    taumobile.yaml

Open taumobile.yaml

Battery: 100
Range: 400

To query a value

var battery int
seer.Get("cars").Get("electric").Get("taumobile").Get("Battery").Value(&battery)
fmt.Printf("Battery of %dKwh\n", battery)

Will print

Battery of 100Kwh

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

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

func (*Batch) Commit

func (b *Batch) Commit() error

type Document

type Document interface{}

type Option

type Option func(s *Seer) error

func SystemFS

func SystemFS(path string) Option

func VirtualFS

func VirtualFS(fs afero.Fs, path string) Option

type Query

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

func Fork

func Fork(n *Query) *Query

Helper

func (*Query) Clear

func (n *Query) Clear() *Query

func (*Query) Commit

func (n *Query) Commit() error

func (*Query) Delete

func (n *Query) Delete() *Query

func (*Query) Document

func (n *Query) Document() *Query

func (*Query) Errors

func (n *Query) Errors() []error

return a copy of the Stack Error

func (*Query) Fork

func (n *Query) Fork() *Query

Copy a query ... the conly way to reuse a query.

func (*Query) Get

func (n *Query) Get(name string) *Query

func (*Query) List

func (n *Query) List() ([]string, error)

func (*Query) Set

func (n *Query) Set(value interface{}) *Query

func (*Query) Value

func (n *Query) Value(dst interface{}) error

type Seer

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

func New

func New(options ...Option) (*Seer, error)

func (*Seer) Batch

func (s *Seer) Batch(queries ...*Query) *Batch

func (*Seer) Dump

func (s *Seer) Dump()

func (*Seer) Get

func (s *Seer) Get(name string) *Query

func (*Seer) List

func (s *Seer) List() ([]string, error)

func (*Seer) Query added in v1.0.7

func (s *Seer) Query() *Query

func (*Seer) Sync

func (s *Seer) Sync() error

Jump to

Keyboard shortcuts

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