http

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const AccessKeyUser = "__ACCESS_KEY"

Variables

This section is empty.

Functions

func CreateResponse

func CreateResponse(req simpleJSONRequestInterface, ch chan frames.Frame) (interface{}, 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)
}
Output:

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 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, 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)
	}
}
Output:

func NewServer

func NewServer(config *frames.Config, addr string, logger logger.Logger, historyServer *utils.HistoryServer, version string) (*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