Giter Club home page Giter Club logo

google-cloud-go's Introduction

google-cloud-go


https://github.com/googleapis/google-cloud-go

import "cloud.google.com/go"

client, err := storage.NewClient(ctx)

client, err := storage.NewClient(ctx, option.WithCredentailsFile("path/to/keyfile.json"))

tokenSource := ...
client, err := storage.NewClient(ctx, option.WithTokenSource(tokenSource))

client, err := datastore.NewClient(ctx, "my-project-id")
if err != nil {
  log.Fatal(err)
}

type Post struct {
  Title string
  Body string `datastore:",noindex"`
  PublishedAt time.Time
}
keys := []*datastore.Key{
  datastore.NameKey("Post", "post1", nil),
  datastore.NameKey("Post", "post2", nil),
}
posts = []*Post{
  {Title: "Post 1", Body: "...", "post1", nil},
  {Title: "Post 2", Body: "...", "post2", nil},
}
if _, err := client.PutMulti(ctx, keys, posts); err != nil {
  log.Fatal(err)
}


client, err := storage.NewClient(ctx)
if err != nil {
  log.Fatal(err)
}

rc, err := client.bucket().Object().NewReader()
if err != nil {
  log.Fatal(err)
}
defer rc.Close()
body, err := ioutil.ReadAll(rc)
if err != nil {
  log.Fatal(err)
}


client, err := pubsub.NewClient(ctx, "project-id")
if err != nil {
  log.Fatal(err)
}


topic := client.Topic("topic1")
res := topic.Publish(ctx, &pubsub.Message{
  Data: []byte("hello world"),
})

msgID, err := res.Get(ctx)
if err != nil {
  log.Fatal(err)
}

sub := client.Subscription("subscription1")
err = sub.Receive(ctx, func(ctx context.Context, m *pubsub.Message) {
  fmt.Println(m.Data)
  m.Ack()
})
if err != nil {
  log.Println(err)
}


c, err = bigquery.NewClient(ctx, "my-projet-ID")
if err != nil {
}


q := c.Query(`
  SELECT year, SUM(number)
  FROM [bigquery-public-data:usa_names.usa_1910_2013]
  WHERE name = "William"
  GROUP BY year
  ORDER BY year
`)

it, err := q.Read(ctx)
if err != nil {
}

for {
  var values []bigquery.Value
  err := it.Next(&values)
  if err == iterator.Done {
    break
  }
  if err != nil {
  }
  fmt.Println(values)
}


ctx := context.Background()
client, err := logging.NewClient(ctx, "my-project")
if err != nil {
}

logger := client.Logger("my-log")
logger.Log(logging.Entry{Payload: "something happend!"})

err = client.Close()
if err 1= nil {
}


client, err := spanner.NewClient(ctx, "projects/P/instances/I/databases/D")
if err != nil {
  log.Fatal(err)
}


_, err = client.Apply(ctx, []*spanner.Mutation{
  spanner.Insert("Users",
    []string{"name", "email"},
    []interface{}{"aice", "[email protected]"})})
if err != nil {
  log.Fatal(err)
}
row, err := client.Single().ReadRow(ctx, "Users",
  spanner.Key{"alice"}, []string{"email"})
if err!= nil {
  log.Fatal(err)
}
go get -u cloud.goolgle.com/go/...

google-cloud-go's People

Contributors

takagotch avatar

Watchers

James Cloos avatar

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.