Giter Club home page Giter Club logo

td-client-go's Introduction

Treasure Data API client for Go

Build Status

Build

  • make
    • To build code and run all the tests
  • make test-verbose
    • To run tests verbosely
  • make help
    • To describe targets
  • make clean
    • To cleanup locally

Synopsis

package main

import (
	td_client "github.com/treasure-data/td-client-go"
)

func main() {
	client, err := td_client.NewTDClient(td_client.Settings {
		ApiKey: "YOUR-API-KEY-HERE",
	})
	if err != nil { ... }
	jobId, err := client.SubmitQuery("mydatabase", td_client.Query {
		Type: "hive",
		Query: "SELECT * FROM mytable WHERE value >= 500",
	})
	if err != nil { ... }
	for {
		status, err := client.JobStatus(jobId)
		if err != nil { ... }
		if status != "queued" && status != "running" { break }
		time.Sleep(1000000000)
	}
	err = client.JobResultEach(jobId, func(v interface{}) error {
		fmt.Printf("Result:%v\n", v)
		return nil
	})
	if err != nil { ... }
}

License

Copyright (C) 2014 Treasure Data, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

td-client-go's People

Contributors

akito19 avatar cspicer avatar hkdnet avatar imnutz avatar kaorimatz avatar ken11 avatar moriyoshi avatar nirmalay12 avatar nurse avatar swapnil-bhasale-td avatar takuti avatar teraken0509 avatar yui-knk avatar yyuu avatar zaimy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

td-client-go's Issues

The call to showAccount fails

The code to reproduce

package main
import (
        td_client "github.com/treasure-data/td-client-go"
        "os"
        "fmt"
        "bytes"
        "compress/gzip"
)
func CompressWithGzip(b []byte) []byte {
        retval := bytes.Buffer {}
        w := gzip.NewWriter(&retval)
        w.Write(b)
        w.Close()
        return retval.Bytes()
}
func main() {
        apiKey := os.Getenv("TD_CLIENT_API_KEY")
        client, err := td_client.NewTDClient(td_client.Settings {
                ApiKey: apiKey,
        })
        account, err := client.ShowAccount()
        if err != nil {
                fmt.Println(err.Error())
                return
        }
        fmt.Printf("id=%d\n", account.Id);
}

When you run the above program, the output is as follows:

$ go run main.go
GenericError: failed to parse response: unknown key presto_plan under /account

td-api update breaks listResults

Code to reproduce

package main

import (
    "fmt"
    td_client "github.com/treasure-data/td-client-go"
    "os"
)

func main() {
    apiKey := os.Getenv("TD_CLIENT_API_KEY")
    client, err := td_client.NewTDClient(td_client.Settings{
        ApiKey: apiKey,
    })
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    results, err := client.ListResults()
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    fmt.Printf("%d results\n", len(*results))
}
$ TD_CLIENT_API_KEY=`td apikey:show` go run test_result.go
GenericError: failed to parse response: unknown key organization under /results[0]

Make HTTPS access for Treasure Data endpoints as default

Treasure Data will abolish HTTP access for Treasure Data endpoints in this August.
Therefore, any accesses via HTTP raise error such as "Server not found".

Since td-client-go uses HTTP access as default, all users who don't use ssl option must be required their code fixed to avoid the errors. Thus, I believe that it's better to enable HTTPS access without ssl option.

https://github.com/treasure-data/td-client-go/blob/master/td_client.go#L233

Currently CI fails on v1.5 and v1.6

td-client-go depends on github.com/ugorji/go/codec.
Currently (2019-06-14), github.com/ugorji/go/codec cannot be built by Go 1.5 and 1.6 because of the missing of the definition of func mapRange.

$ go get github.com/ugorji/go/codec
# github.com/ugorji/go/codec
../../ugorji/go/codec/encode.go:587: undefined: mapRange

https://travis-ci.org/treasure-data/td-client-go/jobs/545596286

This has been caused since ugorji/go@31b118d.
I don't know whether it is intentional or not.

ListJobs method returns an error

With example.go as below

package main
import (
    td_client "github.com/treasure-data/td-client-go"
    "fmt"
    "os"
)

func main() {
    apiKey := os.Getenv("TD_CLIENT_API_KEY")
    client, err := td_client.NewTDClient(td_client.Settings{
        ApiKey: apiKey,
    })

    jobs, err := client.ListJobs()

    if err != nil {
        fmt.Printf("%s\n", err.Error())
    } else {
        fmt.Printf("num jobs:%d\n", len(*jobs))
    }
    return
}

I get the following error consistently.

$ TD_CLIENT_API_KEY=`td apikey:show` go run example.go
NotFoundError: List jobs failed:

Develop a build strategy

The code currently does not have an easy way to build

At the minimum, add a Makefile to build and run tests easily.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.