Friday, January 27, 2017

setting up Go/GoLang on Windows

1. Download and install at C:/go
2. It should set GOROOT at C:/go, if it doesn't setx GOROOT C:/go
3. setx GOPATH C:/projects/go
4. cd C:/projects/go
5. mkdir src; mkdir src/proj
6. cd src/proj
7. touch main.go
8. touch constants.go
9. go get ./...
10. cd ..
11. go build proj/
12. ./proj.exe

main.go
package main

import (
       "fmt"       "github.com/ChimeraCoder/anaconda"       "net/url")

func main() {
       fmt.Println("hi")
       anaconda.SetConsumerKey(CONSUMER_KEY)
       anaconda.SetConsumerSecret(CONSUMER_SECRET)
       api := anaconda.NewTwitterApi(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

       v := url.Values{}
       v.Set("track", "Kohli")
       twitterStream := api.PublicStreamFilter(v)
       for {
              x := <-twitterStream.C
              switch tweet := x.(type) {
              case anaconda.Tweet:
                     fmt.Println(tweet.Latitude())
                     fmt.Println(tweet.Text)
                     fmt.Println("-----------")
              case anaconda.StatusDeletionNotice:
              // pass              default:
                     fmt.Printf("unknown type(%T) : %v \n", x, x)
              }
       }
}
Constants.go
package main

const CONSUMER_KEY = ""const CONSUMER_SECRET = ""const ACCESS_TOKEN = ""const ACCESS_TOKEN_SECRET = ""


No comments:

Blog Archive