jsonstore

package module
v0.0.0-...-8e1a0bc Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2018 License: MIT Imports: 12 Imported by: 0

README

jsonstore

Build Status Go Report Card GoDoc

A client for the https://www.jsonstore.io API (backend source code is available at https://github.com/bluzi/jsonstore)

Installation

go get -u github.com/peterhellberg/jsonstore

Usage example

package main

import (
	"context"
	"fmt"

	"github.com/peterhellberg/jsonstore"
)

const secret = "3ba7860f742fc15d5b6e1508e2de1e0cde2c396f7c52a877905befb4e970eaaf"

type example struct {
	Number int
	Bool   bool
	String string
}

func main() {
	ctx := context.Background()

	store := jsonstore.New(jsonstore.Secret(secret))

	store.Post(ctx, "key", example{1234, true, "initial"})
	store.Put(ctx, "key/String", "modified")
	store.Delete(ctx, "key/Bool")

	var e example

	store.Get(ctx, "key", &e)

	fmt.Printf("%s -> %+v\n", store.URL("key"), e)
}

License (MIT)

Copyright (c) 2018 Peter Hellberg

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package jsonstore is a client for the https://www.jsonstore.io API

Installation

go get -u github.com/peterhellberg/jsonstore

Usage

package main

import (
	"context"
	"fmt"

	"github.com/peterhellberg/jsonstore"
)

const secret = "3ba7860f742fc15d5b6e1508e2de1e0cde2c396f7c52a877905befb4e970eaaf"

type example struct {
	Number int
	Bool   bool
	String string
}

func main() {
	ctx := context.Background()

	store := jsonstore.New(jsonstore.Secret(secret))

	store.Post(ctx, "key", example{1234, true, "initial"})
	store.Put(ctx, "key/String", "modified")
	store.Delete(ctx, "key/Bool")

	var e example

	store.Get(ctx, "key", &e)

	fmt.Printf("%s -> %+v\n", store.URL("key"), e)
}

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSecret            = fmt.Errorf("no secret")
	ErrNotFound            = fmt.Errorf("not found")
	ErrInternalServerError = fmt.Errorf("internal server error")
	ErrUnexpectedStatus    = fmt.Errorf("unexpected status")
)

Errors

Functions

func NewSecret

func NewSecret() (string, error)

NewSecret generates a new secret based on 64 random bytes

Types

type Client

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

Client for the www.jsonstore.io API

func New

func New(options ...Option) *Client

New creates a www.jsonstore.io Client

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) error

Delete from jsonstore

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, v interface{}) error

Get response from jsonstore

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, v interface{}) error

Post to jsonstore

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, v interface{}) error

Put update to jsonstore

func (*Client) Secret

func (c *Client) Secret() string

Secret returns the client secret

func (*Client) URL

func (c *Client) URL(segments ...string) *url.URL

URL returns the URL used by the client

type Option

type Option func(*Client)

Option is a type of function used to configure the client

func BaseURL

func BaseURL(rawurl string) Option

BaseURL changes the base URL used by the client to the URL parsed from rawurl

func HTTPClient

func HTTPClient(hc *http.Client) Option

HTTPClient changes the HTTP client used by the client to the provided *http.Client

func Secret

func Secret(s string) Option

Secret sets the secret used by the client to the provided string

Jump to

Keyboard shortcuts

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