gateway

package module
v0.0.0-...-2e7b282 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

cassandra-http-gateway

An HTTP data gateway framework for Apache Cassandra

See also: T294468

Usage

package main

import (
    "fmt"
    "os"

    "github.com/gocql/gocql"
    "github.com/julienschmidt/httprouter"
)

func main() {
    var cluster *gocql.ClusterConfig
    var err error
    var session *gocql.Session

    cluster = gocql.NewCluster("localhost")
    cluster.Consistency = gocql.One

    if session, err = cluster.CreateSession(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }

    var router = new httprouter.New()
    router.GET("/music/:artist/:album", func(w http ResponseWriter, r *http.Request, ps httprouter.Params) {
        SelectBuilder.
            From("music", "tracks").
            Bind(ps).Session(session).
            Build().
            Handle(w)
    })
}

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Field

type Field struct {
	Column string
	CastTo string
	Alias  string
}

Field correponds to a field in the projection of a CQL SELECT statement.

type FieldBuilderType

type FieldBuilderType builder.Builder

FieldBuilderType is a fluent DSL for constructing Fields

func Column

func Column(name string) FieldBuilderType

Column is convience function that returns a new Field builder with the supplied column name assigned.

func (FieldBuilderType) Alias

func (b FieldBuilderType) Alias(label string) FieldBuilderType

Alias assigns an alias for the Field, and returns the builder.

func (FieldBuilderType) CastTo

func (b FieldBuilderType) CastTo(kind string) FieldBuilderType

CastTo assigns the type to cast a Field value to, and returns the builder.

func (FieldBuilderType) Column

func (b FieldBuilderType) Column(name string) FieldBuilderType

Column assigns the column name attribute of a Field, and returns the builder.

func (FieldBuilderType) Get

func (b FieldBuilderType) Get() Field

Get constructs and returns a Field object

type Predicate

type Predicate struct {
	Column   string
	Relation Relation
	Value    interface{}
}

Predicate represents a predicate in the WHERE clause of a CQL SELECT.

type Relation

type Relation string

Relation types correspond to CQL statement relations.

const (
	EQ  Relation = "="
	GT  Relation = ">"
	LT  Relation = "<"
	GTE Relation = ">="
	LTE Relation = "<="
)

type SelectBuilderType

type SelectBuilderType builder.Builder

SelectBuilderType is a fluent DSL for constructing SelectStatements

func (SelectBuilderType) Bind

Bind creates predicates with an EQ ('=') relation for each of the parameters in the supplied httprouter.Params.

func (SelectBuilderType) Build

Build constructs and returns a SelectStatement.

func (SelectBuilderType) CounterVec

CounterVec assigns a Prometheus CounterVec object to the statement under construction. The object supplied will be used to count HTTP requests proccessed by Handle().

func (SelectBuilderType) From

func (b SelectBuilderType) From(keyspace, table string) SelectBuilderType

From assigns the keyspace and table name of the SELECT statement under construction.

func (SelectBuilderType) HistogramVec

func (b SelectBuilderType) HistogramVec(histogram *prometheus.HistogramVec) SelectBuilderType

HistogramVec assigns a Prometheus HistogramVec object to the statement under construction. The object supplied will be used to create a latency histogram of HTTP requests processed by Handle().

func (SelectBuilderType) Logger

func (b SelectBuilderType) Logger(logger *log.Logger) SelectBuilderType

Logger assigns a logger object to the statement under construction. The supplied object will be used to output logging information from HTTP requests processed by Handle().

func (SelectBuilderType) Select

func (b SelectBuilderType) Select(fields ...Field) SelectBuilderType

Select adds zero or more fields to the projection of the SELECT statement being constructed. If no fields are added (or if Select() is never invoked), then the projection will contain '*'.

func (SelectBuilderType) Session

func (b SelectBuilderType) Session(session *gocql.Session) SelectBuilderType

Session assigns a GoCQL Session object to the statement under construction. The Session supplied will be used to execute CQL queries against.

func (SelectBuilderType) Where

func (b SelectBuilderType) Where(column string, relation Relation, value interface{}) SelectBuilderType

Where adds a predicate to the SELECT statement under construction.

type SelectStatement

type SelectStatement struct {
	Keyspace   string
	Table      string
	Fields     []Field
	Predicates []Predicate

	Session      *gocql.Session
	CounterVec   *prometheus.CounterVec
	HistogramVec *prometheus.HistogramVec
	Logger       *log.Logger
	// contains filtered or unexported fields
}

SelectStatement represents a CQL SELECT statement

func (*SelectStatement) Handle

func (s *SelectStatement) Handle(w http.ResponseWriter, request *http.Request)

Handle processes an HTTP request, querying the database for results, and returning them as a JSON-formatted response.

func (*SelectStatement) String

func (s *SelectStatement) String() string

String returns the CQL query string for a SelectStatement

Jump to

Keyboard shortcuts

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