jsonbox: github.com/peteretelej/jsonbox Index | Files

package jsonbox

import "github.com/peteretelej/jsonbox"

Package jsonbox wraps jsonbox API calls.

Create a new Client for use

cl,err := jsonbox.NewClient("https://jsonbox.io/")

Create or add a record

val := []byte(`{"name": "Jon Snow", "age": 25}`)
out, err := cl.Create("demobox_6d9e326c183fde7b",val)

Read record(s)

out, err := cl.Read("demobox_6d9e326c183fde7b")
fmt.Printf("%s",out)

Query records

out, err := cl.Read("demobox_6d9e326c183fde7b?query_key=name&query_value=arya%20stark")
fmt.Printf("%s",out)

Update record

val := []byte(`{"name": "Arya Stark", "age": 18}`)
out, err := cl.Update("demobox_6d9e326c183fde7b","5d776b75fd6d3d6cb1d45c53",val)
fmt.Printf("%s",out)

Delete record

err := cl.Delete("demobox_6d9e326c183fde7b","5d776b75fd6d3d6cb1d45c53")

Delete All Records

err := cl.Delete(BOX_ID)

List IDs for all records

ids,err := cl.IDs("demobox_6d9e326c183fde7b")
fmt.Printf("%s",ids)

Index

Package Files

doc.go jsonbox.go

Variables

var (
    ErrTODO = errors.New("functionality not implemented")
    ErrName = errors.New("invalid name for either BOX_ID or COLLECTION")
)

Errors returned when working with jsonbox package

var NameRegExp = regexp.MustCompile("^[a-zA-Z0-9_]*$")

NameRegExp defines valid BOX_ID or COLLECTION names reges

func GetRecordID Uses

func GetRecordID(dat []byte) (string, error)

GetRecordID returns the id of a record, or the first ID if multiple records

type Client Uses

type Client struct {
    URL     *url.URL
    Timeout time.Duration
    // contains filtered or unexported fields
}

Client defines the structure of a jsonbox client

func NewClient Uses

func NewClient(baseURL string) (*Client, error)

NewClient returns a new jsonbox client

func (Client) Create Uses

func (c Client) Create(boxID string, val []byte) ([]byte, error)

Create creates or adds a record to a boxId

func (Client) Delete Uses

func (c Client) Delete(boxID string, recordID string) error

Delete deletes a boxID record given the record Id

func (Client) DeleteAll Uses

func (c Client) DeleteAll(boxID string) error

DeleteAll deletes all records for boxID

func (Client) IDs Uses

func (c Client) IDs(boxID string) ([]string, error)

IDs returns all IDs in a BoxID collection

func (Client) Read Uses

func (c Client) Read(boxID string) ([]byte, error)

Read reads records for a boxId or boxId with query

func (Client) Request Uses

func (c Client) Request(method, urlPath string, dat []byte) ([]byte, error)

Request makes a request to json box url

func (Client) Update Uses

func (c Client) Update(boxID string, recordID string, val []byte) ([]byte, error)

Update updates a boxID record given the record key and new value

type Meta Uses

type Meta struct {
    ID        string `json:"_id"`
    CreatedOn string `json:"_createdOn"`
}

Meta defines metadata for json stored

func GetRecordMetas Uses

func GetRecordMetas(dat []byte) ([]Meta, error)

GetRecordMetas returns a list of record Metas, fails for single record

Package jsonbox imports 10 packages (graph). Updated 2019-09-19. Refresh now. Tools for package owners.