http

package
v0.6.12-v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

View Source
const ACCESS_KEY_USER = "__ACCESS_KEY"

Variables

This section is empty.

Functions

func CreateResponse

func CreateResponse(req simpleJSONRequestInterface, ch chan frames.Frame) (interface{}, error)

func SimpleJSONRequestFactory added in v0.3.6

func SimpleJSONRequestFactory(method string, request []byte) (simpleJSONRequestInterface, error)

Types

type Client

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

Client is v3io HTTP streaming client

Example
package main

import (
	"fmt"
	"time"

	"github.com/v3io/frames"
	"github.com/v3io/frames/pb"
)

func main() {
	tableName := "example_table"
	url := "http://localhost:8080"
	fmt.Println(">>> connecting")
	// nil, nil are session and logger
	client, err := NewClient(url, nil, nil)
	if err != nil {
		fmt.Printf("can't connect to %q - %s", url, err)
		return
	}

	frame, err := makeFrame()
	if err != nil {
		fmt.Printf("can't create frame - %s", err)
		return
	}

	fmt.Println(">>> writing")
	writeReq := &frames.WriteRequest{
		Backend: "weather",
		Table:   tableName,
	}

	appender, err := client.Write(writeReq)
	if err != nil {
		if err != nil {
			fmt.Printf("can't write - %s", err)
			return
		}
	}

	if err := appender.Add(frame); err != nil {
		fmt.Printf("can't write frame - %s", err)
		return
	}

	if err := appender.WaitForComplete(10 * time.Second); err != nil {
		fmt.Printf("can't wait - %s", err)
		return
	}

	fmt.Println(">>> reading")
	readReq := &pb.ReadRequest{
		Backend:      "weather",
		Table:        tableName,
		MessageLimit: 100,
	}

	it, err := client.Read(readReq)
	if err != nil {
		fmt.Printf("can't query - %s", err)
		return
	}

	for it.Next() {
		frame := it.At()
		fmt.Println(frame.Names())
		fmt.Printf("%d rows\n", frame.Len())
		fmt.Println("-----------")
	}

	if err := it.Err(); err != nil {
		fmt.Printf("error in iterator - %s", err)
		return
	}
}

func makeFrame() (frames.Frame, error) {
	size := 1027
	now := time.Now()
	idata := make([]int64, size)
	fdata := make([]float64, size)
	sdata := make([]string, size)
	tdata := make([]time.Time, size)

	for i := 0; i < size; i++ {
		idata[i] = int64(i)
		fdata[i] = float64(i)
		sdata[i] = fmt.Sprintf("val%d", i)
		tdata[i] = now.Add(time.Duration(i) * time.Second)
	}

	columns := map[string]interface{}{
		"ints":    idata,
		"floats":  fdata,
		"strings": sdata,
		"times":   tdata,
	}
	return frames.NewFrameFromMap(columns, nil)
}

func NewClient

func NewClient(url string, session *frames.Session, logger logger.Logger) (*Client, error)

NewClient returns a new HTTP client

func (*Client) Create

func (c *Client) Create(request *pb.CreateRequest) error

Create creates a table

func (*Client) Delete

func (c *Client) Delete(request *pb.DeleteRequest) error

Delete deletes data

func (*Client) Exec

func (c *Client) Exec(request *pb.ExecRequest) (frames.Frame, error)

Exec executes a command

func (*Client) Read

func (c *Client) Read(request *pb.ReadRequest) (frames.FrameIterator, error)

Read runs a query on the client

func (*Client) Write

func (c *Client) Write(request *frames.WriteRequest) (frames.FrameAppender, error)

Write writes data

type JSONColumn added in v0.3.0

type JSONColumn struct {
	Name string      `json:"name"`
	Data interface{} `json:"data"`
}

JSONColumn is JSON representation of a column

type JSONFrame added in v0.3.0

type JSONFrame struct {
	Columns []*JSONColumn `json:"columns"`
	Indices []*JSONColumn `json:"indices"`
}

JSONFrame is JSON representation of a frame

type Server

type Server struct {
	*frames.ServerBase
	// contains filtered or unexported fields
}

Server is HTTP server

Example
package main

import (
	"fmt"
	"time"

	"github.com/ghodss/yaml"
	"github.com/v3io/frames"
)

var configData = []byte(`
log:
  level: "info"

backends:
  - type: "kv"
  - type: "csv"
    rootDir = "/tmp"
`)

func main() {
	cfg := &frames.Config{}
	if err := yaml.Unmarshal(configData, cfg); err != nil {
		fmt.Printf("error: can't read config - %s", err)
		return
	}

	srv, err := NewServer(cfg, ":8080", nil)
	if err != nil {
		fmt.Printf("error: can't create server - %s", err)
		return
	}

	if err = srv.Start(); err != nil {
		fmt.Printf("error: can't start server - %s", err)
		return
	}

	fmt.Println("server running")
	for {
		time.Sleep(60 * time.Second)
	}
}

func NewServer

func NewServer(config *frames.Config, addr string, logger logger.Logger) (*Server, error)

NewServer creates a new server

func (*Server) Start

func (s *Server) Start() error

Start starts the server

Jump to

Keyboard shortcuts

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