redash

package module
v0.0.0-...-15b2299 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: MIT Imports: 12 Imported by: 0

README

Redash(for Go)

Redash(for Go) is a unofficial simple api client lib.

See Godoc at http://godoc.org/github.com/ynishi/redash

Redash is OSS BI tool. See more at https://redash.io/

Current status

  • Version 1.0(v1)

Example

set env
$ export REDASH_APIKEY="abc..."
$ export REDASH_URL="http://localhost"
code
package main

import (
	"fmt"
	"io/ioutil"
	"log"

	"github.com/ynishi/redash/v1"
)

func main() {
	response, err := redash.Get("/api/queries", nil)
	if err != nil {
		log.Fatal(err)
	}
	buf, err := ioutil.ReadAll(response.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v", string(buf))
}

Install

$ go get "github.com/ynishi/redash"

Development

Welcome to participate develop, send pull request, add issue(question, bugs, wants and so on).

Start develop
  • first, clone repository.
$ git clone https://github.com/ynishi/redash.git
$ cd redash
$ go test
  • and make pull request.

Credit and License

Copyright (c) 2017, Yutaka Nishimura. Licensed under MIT, see LICENSE.

Documentation

Overview

The redash package implements a simple client and wrapper library for Redash REST api.

GET/POST/DELETE is accepted.

Original client is made by implement Interface.

Summary of use case.

Case 1:

Get/Post/Delete directory.

Case 2:

implement your Interface and
GetInter/PostInter/DeleteInter with new Client.

Case 3:

Queries.GetQuery/(other func in Queries)

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultClient = NewDefaultClient()
)

Default Queries

Functions

func Delete

func Delete(sub string, params map[string]string) (resp *http.Response, err error)

Delete do Redash api DELETE and return result.

func DeleteInter

func DeleteInter(client Interface, sub string, params map[string]string) (resp *http.Response, err error)

DeleteInter do Redash DELETE with Interface and return result.

func Do

func Do(method, sub string, opts *Options) (resp *http.Response, err error)

Do do Redash apis and return result.

func DoInter

func DoInter(client Interface, method, sub string, opts *Options) (resp *http.Response, err error)

DoInter do Redash apis with Interface and return result.

func Get

func Get(sub string, params map[string]string) (resp *http.Response, err error)

Get do Redash api GET and return result.

func GetInter

func GetInter(client Interface, sub string, params map[string]string) (resp *http.Response, err error)

GetInter do Redash GET with Interface and return result.

func Post

func Post(sub string, jsonBody []byte) (resp *http.Response, err error)

Post do Redash api POST and return result.

func PostInter

func PostInter(client Interface, sub string, jsonBody []byte) (resp *http.Response, err error)

PostInter do Redash POST with Interface and return result.

func Request

func Request(method, sub string, opts *Options) (req *http.Request, err error)

Request make http.Request for Redash.

func RequestInter

func RequestInter(client Interface, method, sub string, opts *Options) (req *http.Request, err error)

RequestInter make request with Interface.

Types

type Apikeyer

type Apikeyer interface {
	Apikey() (string, error)
}

Apikey is Redash Apikey to connect primary.

type ClientData

type ClientData struct {
	*log.Logger
}

Default implemet of client include Logger.

type Column

type Column struct {
	FriendlyName string `json:"friendly_name"`
	Type         string `json:"type"`
	Name         string `json:"name"`
}

Wrap Redash column for result data.

type DefaultClientData

type DefaultClientData struct {
	ClientData
	// contains filtered or unexported fields
}

Default implement of client. This is provided as DefaultClient.

func NewDefaultClient

func NewDefaultClient() *DefaultClientData

Create a new defaultClient

func (DefaultClientData) Apikey

func (dc DefaultClientData) Apikey() (apikey string, err error)

Implementation of apikey for DefaultClient

func (DefaultClientData) DefaultOpts

func (dc DefaultClientData) DefaultOpts() *Options

Implementation of DefaultOpts for DefaultClient

func (DefaultClientData) HTTPClient

func (dc DefaultClientData) HTTPClient() *http.Client

Implementation of HTTPClient for DefaultClient

func (DefaultClientData) Url

func (dc DefaultClientData) Url() (u *url.URL, err error)

Implementation of Url for DefaultClient

type DefaultOptser

type DefaultOptser interface {
	DefaultOpts() *Options
}

DefaultOpts is default options for request.

type FormatQuery

type FormatQuery struct {
	Query string `json:"query"`
}

Wrap Redash format query.

type HTTPClienter

type HTTPClienter interface {
	HTTPClient() *http.Client
}

HTTPClient is HTTP client to do request.

type Interface

type Interface interface {
	Urler
	Apikeyer
	HTTPClienter
	DefaultOptser
}

A type, for original client, that sufisfies redash.Interface can use GetInter, PostInter, DeleteInter methods. If want to change apikey management, Httpclient and so on, just implement methods of this Interface.

type Job

type Job struct {
	Job JobInner `josn:"job"`
}

Wrap Redash job result.

type JobInner

type JobInner struct {
	Status        int    `json:"status"`
	Error         string `json:"error"`
	Id            string `json:"id"`
	QueryResultId int    `json:"query_result_id"`
	Updated_at    int    `json:"updated_at"`
}

Wrap Redash job detail.

type NewQuery

type NewQuery struct {
	DataSourceId int               `json:"data_source_id"`
	Query        string            `json:"query"`
	Name         string            `json:"name"`
	Description  string            `json:"description"`
	Schedule     string            `json:"schedule"`
	Options      map[string]string `json:"options"`
}

Wrap Redash new query.

type Options

type Options struct {
	Params map[string]string
	Header map[string]string
	Body   io.Reader
}

Options is option value container.

type PagingResponseQuery

type PagingResponseQuery struct {
	Count    int             `json:"count"`
	Page     int             `json:"page"`
	PageSize int             `json:"page_size"`
	Results  []ResponseQuery `json:"results"`
}

Wrap Redash paging response query.

type QueriesS

type QueriesS struct {
	Client Interface
}

Default struct for queries.

func (QueriesS) DeleteJog

func (qs QueriesS) DeleteJog(jobId string) (r io.Reader, err error)

Wrap Redash api DELETE jobs.

func (QueriesS) DeleteQuery

func (qs QueriesS) DeleteQuery(queryId int) (r io.Reader, err error)

Wrap Redash api DELETE queries.

func (QueriesS) GetJob

func (qs QueriesS) GetJob(jobId string) (r io.Reader, err error)

Wrap Redash api GET jobs.

func (QueriesS) GetMy

func (qs QueriesS) GetMy(pageSize, page int) (r io.Reader, err error)

Wrap Redash api GET my.

func (QueriesS) GetQuery

func (qs QueriesS) GetQuery(pageSize, page int) (r io.Reader, err error)

Wrap Redash api GET queries.

func (QueriesS) GetQueryId

func (qs QueriesS) GetQueryId(queryId int) (r io.Reader, err error)

Wrap Redash api GET queries/${query id}.

func (QueriesS) GetQueryResults

func (qs QueriesS) GetQueryResults(queryResultId int) (r io.Reader, err error)

Wrap Redash api GET querie_results.

func (QueriesS) GetRecent

func (qs QueriesS) GetRecent() (r io.Reader, err error)

Wrap Redash api GET recent.

func (QueriesS) GetResultsById

func (qs QueriesS) GetResultsById(queryId, queryResultId int, filetype string) (r io.Reader, err error)

Wrap Redash api GET ${query id}/results/${query resut id}.${filetype}

func (QueriesS) GetResultsByQueryId

func (qs QueriesS) GetResultsByQueryId(queryId int, filetype string) (r io.Reader, err error)

Wrap Redash api GET ${query id}/results.${filetype}.

func (QueriesS) GetSearch

func (qs QueriesS) GetSearch(q string) (r io.Reader, err error)

Wrap Redash api GET search.

func (QueriesS) PostFork

func (qs QueriesS) PostFork(queryId int) (r io.Reader, err error)

Wrap Redash api POST fork.

func (QueriesS) PostFormat

func (qs QueriesS) PostFormat(sql string) (r io.Reader, err error)

Wrap Redash api POST format.

func (QueriesS) PostQuery

func (qs QueriesS) PostQuery(newQuery NewQuery) (res io.Reader, err error)

Wrap Redash api POST queries.

func (QueriesS) PostQueryId

func (qs QueriesS) PostQueryId(queryId int, newQuery NewQuery) (r io.Reader, err error)

Wrap Redash api POST queries.

func (QueriesS) PostQueryResult

func (qs QueriesS) PostQueryResult(query string, maxAge, dataSourceId int) (r io.Reader, err error)

Wrap Redash api POST query_results.

func (QueriesS) PostRefresh

func (qs QueriesS) PostRefresh(queryId int) (r io.Reader, err error)

Wrap Redash api POST refresh.

func (QueriesS) Queries

func (q QueriesS) Queries(s string) (rs string)

Default implement of Queries.

type Querieser

type Querieser interface {
	Queries(string) string
}

interface of make Queries endpoint.

type QueryResult

type QueryResult struct {
	RetrievedAt  string     `json:"retrieved_at"`
	QueryHash    string     `json:"query_hash"`
	Query        string     `json:"query"`
	Runtime      float64    `json:"runtime"`
	Data         ResultData `json:"data"`
	Id           int        `json:"id"`
	DataSourceId int        `json:"data_source_id"`
}

Wrap Redash query result.

type ResponseQuery

type ResponseQuery struct {
	Id                int     `json:"id"`
	LatestQueryDataId int     `json:"latest_query_data_id"`
	Name              string  `json:"name"`
	Description       string  `json:"description"`
	Query             string  `json:"query"`
	QueryHash         string  `json:"query_hash"`
	Schedule          string  `json:"schedule"`
	ApiKey            string  `json:"api_key"`
	IsArchived        bool    `json:"is_archived"`
	IsDraft           bool    `json:"is_draft"`
	UpdatedAt         string  `json:"updated_at"`
	CreatedAt         string  `json:"created_at"`
	DataSourceId      int     `json:"data_source_id"`
	Options           Options `json:"options"`
	Version           int     `json:"version"`
	UserId            int     `json:"user_id"`
	LastModifiedById  int     `json:"last_modified_by_id"`
	RetrivedAt        string  `json:"retrieved_at"`
	Runtime           int     `json:"runtime"`
}

Wrap Redash response query.

type Result

type Result struct {
	QueryResult QueryResult `json:"query_result"`
}

Wrap Redash result.

type ResultData

type ResultData struct {
	Rows    []Row    `json:"rows"`
	Columns []Column `json:"columns"`
}

Wrap Redash result data.

type Row

type Row struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

Wrap Redash row for result data.

type Urler

type Urler interface {
	Url() (*url.URL, error)
}

Url is Redash server's endpoint.

Directories

Path Synopsis
The redash package implements a simple client and wrapper library for Redash REST api.
The redash package implements a simple client and wrapper library for Redash REST api.

Jump to

Keyboard shortcuts

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