Top Related Projects
A curated list of awesome Go frameworks, libraries and software
The Go programming language
Go development plugin for Vim
A standard library for microservices.
A Commander for modern Go CLI interactions
Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
Quick Overview
ChimeraCoder/anaconda is a Go library for the Twitter API. It provides a simple and efficient way to interact with Twitter's REST and streaming APIs, allowing developers to easily integrate Twitter functionality into their Go applications.
Pros
- Comprehensive coverage of Twitter API endpoints
- Support for both REST and streaming APIs
- Easy-to-use and well-documented
- Actively maintained with regular updates
Cons
- Limited to Twitter API functionality only
- Requires Twitter API credentials to use
- May be affected by Twitter API changes and rate limits
- Learning curve for developers new to Go or Twitter API
Code Examples
- Posting a tweet:
anaconda.SetConsumerKey("your-consumer-key")
anaconda.SetConsumerSecret("your-consumer-secret")
api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret")
tweet, err := api.PostTweet("Hello, Twitter!", nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Tweet posted: %s\n", tweet.Text)
- Searching for tweets:
searchResult, err := api.GetSearch("golang", nil)
if err != nil {
log.Fatal(err)
}
for _, tweet := range searchResult.Statuses {
fmt.Printf("@%s: %s\n", tweet.User.ScreenName, tweet.Text)
}
- Streaming tweets:
v := url.Values{}
v.Set("track", "golang")
stream := api.PublicStreamFilter(v)
for tweet := range stream.C {
t, ok := tweet.(anaconda.Tweet)
if ok {
fmt.Printf("@%s: %s\n", t.User.ScreenName, t.Text)
}
}
Getting Started
To start using ChimeraCoder/anaconda, follow these steps:
-
Install the library:
go get github.com/ChimeraCoder/anaconda
-
Import the library in your Go code:
import "github.com/ChimeraCoder/anaconda"
-
Set up your Twitter API credentials:
anaconda.SetConsumerKey("your-consumer-key") anaconda.SetConsumerSecret("your-consumer-secret") api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret")
-
Start using the API methods as shown in the code examples above.
Competitor Comparisons
A curated list of awesome Go frameworks, libraries and software
Pros of awesome-go
- Comprehensive curated list of Go libraries, tools, and resources
- Regularly updated with community contributions
- Covers a wide range of categories and use cases
Cons of awesome-go
- Not a functional library or package itself
- Requires manual exploration to find specific tools or libraries
Code comparison
Not applicable, as awesome-go is a curated list and not a functional library.
Pros of anaconda
- Ready-to-use Go library for Twitter API integration
- Provides structured types and methods for Twitter-specific operations
- Handles authentication and rate limiting
Cons of anaconda
- Limited to Twitter API functionality
- May require updates to keep up with Twitter API changes
Code comparison
anaconda:
api := anaconda.NewTwitterApiWithCredentials(accessToken, accessTokenSecret, consumerKey, consumerSecret)
tweet, err := api.PostTweet("Hello, Twitter!", nil)
awesome-go:
No code comparison available as it's a curated list, not a functional library.
The Go programming language
Pros of go
- Official Go programming language repository with extensive documentation and resources
- Larger community and more frequent updates/releases
- Comprehensive standard library and tooling
Cons of go
- Much larger codebase, potentially more complex to navigate for newcomers
- Broader scope, not focused on a specific API or service like Anaconda
Code comparison
go:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Anaconda:
api := anaconda.NewTwitterApiWithCredentials(accessToken, accessTokenSecret, consumerKey, consumerSecret)
tweet, err := api.PostTweet("Hello, World!", nil)
Summary
go is the official repository for the Go programming language, offering a comprehensive ecosystem for Go development. Anaconda is a Go client library for the Twitter API, providing a more focused toolset for Twitter-related tasks. While go offers a broader range of features and resources, Anaconda simplifies Twitter API interactions for Go developers.
Go development plugin for Vim
Pros of vim-go
- Specifically designed for Go development, offering deep language integration
- Provides advanced features like code completion, refactoring, and linting
- Actively maintained with frequent updates and improvements
Cons of vim-go
- Limited to Go language support, unlike Anaconda's multi-language capabilities
- Requires Vim editor, which may have a steeper learning curve for some users
- May have more complex setup and configuration compared to Anaconda
Code Comparison
vim-go:
:GoDef
:GoImplements
:GoRename
:GoTest
:GoCoverage
Anaconda:
import anaconda_mode
anaconda_mode.start()
anaconda_mode.complete()
anaconda_mode.goto_definitions()
anaconda_mode.find_usages()
Summary
vim-go is a powerful plugin specifically tailored for Go development in Vim, offering deep language integration and advanced features. However, it's limited to Go and requires Vim proficiency. Anaconda, on the other hand, provides multi-language support and works with various editors but may lack some of the Go-specific features offered by vim-go. The choice between the two depends on the user's preferred editor, language focus, and desired level of language-specific functionality.
A standard library for microservices.
Pros of kit
- More comprehensive microservices toolkit with support for various patterns
- Active development and larger community (10k+ stars on GitHub)
- Extensive documentation and examples
Cons of kit
- Steeper learning curve due to more complex architecture
- Potentially overkill for smaller projects or simple APIs
- Requires more setup and configuration
Code Comparison
kit:
import (
"github.com/go-kit/kit/endpoint"
"github.com/go-kit/kit/transport/http"
)
func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(uppercaseRequest)
v, err := svc.Uppercase(req.S)
return uppercaseResponse{v, err}, nil
}
}
anaconda:
import (
"github.com/ChimeraCoder/anaconda"
)
api := anaconda.NewTwitterApiWithCredentials(accessToken, accessTokenSecret, consumerKey, consumerSecret)
searchResult, _ := api.GetSearch("golang", nil)
for _, tweet := range searchResult.Statuses {
fmt.Println(tweet.Text)
}
Summary
kit is a more comprehensive microservices toolkit, while anaconda is specifically designed for Twitter API integration. kit offers more flexibility and patterns for building complex systems, but may be overkill for simpler projects. anaconda provides a straightforward way to interact with Twitter's API, making it easier to use for Twitter-specific tasks.
A Commander for modern Go CLI interactions
Pros of Cobra
- More actively maintained with frequent updates
- Extensive documentation and examples
- Supports nested subcommands and flag inheritance
Cons of Cobra
- Steeper learning curve for beginners
- More complex setup for simple CLI applications
- Larger codebase and dependencies
Code Comparison
Anaconda:
cli := anaconda.NewCliApp()
cli.AddCommand("greet", "Greet someone", func(args []string) {
fmt.Println("Hello,", args[0])
})
cli.Run()
Cobra:
var rootCmd = &cobra.Command{
Use: "greet [name]",
Short: "Greet someone",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Hello,", args[0])
},
}
func main() {
rootCmd.Execute()
}
Both Anaconda and Cobra are Go libraries for building command-line interfaces. Anaconda offers a simpler API and is easier to get started with for small projects. Cobra, on the other hand, provides more advanced features and is better suited for complex CLI applications with multiple subcommands and flags. Cobra's extensive documentation and active community make it a popular choice for larger projects, while Anaconda's simplicity may be preferred for quick prototypes or smaller tools.
Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
Pros of Gin
- Higher performance and lower memory usage
- More extensive middleware ecosystem
- Better suited for building RESTful APIs
Cons of Gin
- Less focus on database integration
- Steeper learning curve for beginners
- Fewer built-in utilities for common web development tasks
Code Comparison
Gin example:
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
r.Run()
Anaconda example:
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
})
http.ListenAndServe(":8080", nil)
Gin is a high-performance web framework for Go, focusing on speed and minimalism. It's well-suited for building RESTful APIs and microservices. Anaconda, on the other hand, is a simpler web framework that provides a more straightforward approach to building web applications in Go.
Gin offers better performance and a rich ecosystem of middleware, making it ideal for complex applications. However, it may have a steeper learning curve for beginners. Anaconda is easier to get started with and provides more built-in utilities for common web development tasks, but it may not be as performant or flexible as Gin for larger-scale applications.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Anaconda
Anaconda is a simple, transparent Go package for accessing version 1.1 of the Twitter API.
Successful API queries return native Go structs that can be used immediately, with no need for type assertions.
Examples
Authentication
If you already have the access token (and secret) for your user (Twitter provides this for your own account on the developer portal), creating the client is simple:
api := anaconda.NewTwitterApiWithCredentials("your-access-token", "your-access-token-secret", "your-consumer-key", "your-consumer-secret")
Queries
Queries are conducted using a pointer to an authenticated TwitterApi
struct. In v1.1 of Twitter's API, all requests should be authenticated.
searchResult, _ := api.GetSearch("golang", nil)
for _ , tweet := range searchResult.Statuses {
fmt.Println(tweet.Text)
}
Certain endpoints allow separate optional parameter; if desired, these can be passed as the final parameter.
//Perhaps we want 30 values instead of the default 15
v := url.Values{}
v.Set("count", "30")
result, err := api.GetSearch("golang", v)
(Remember that url.Values
is equivalent to a map[string][]string
, if you find that more convenient notation when specifying values). Otherwise, nil
suffices.
Streaming
Anaconda supports the Streaming APIs. You can use PublicStream*
or UserStream
API methods.
A go loop is started an gives you an stream that sends interface{}
objects through it's chan
C
Objects which you can cast into a tweet, event and more.
v := url.Values{}
s := api.UserStream(v)
for t := range s.C {
switch v := t.(type) {
case anaconda.Tweet:
fmt.Printf("%-15s: %s\n", v.User.ScreenName, v.Text)
case anaconda.EventTweet:
switch v.Event.Event {
case "favorite":
sn := v.Source.ScreenName
tw := v.TargetObject.Text
fmt.Printf("Favorited by %-15s: %s\n", sn, tw)
case "unfavorite":
sn := v.Source.ScreenName
tw := v.TargetObject.Text
fmt.Printf("UnFavorited by %-15s: %s\n", sn, tw)
}
}
}
Endpoints
Anaconda implements most of the endpoints defined in the Twitter API documentation. For clarity, in most cases, the function name is simply the name of the HTTP method and the endpoint (e.g., the endpoint GET /friendships/incoming
is provided by the function GetFriendshipsIncoming
).
In a few cases, a shortened form has been chosen to make life easier (for example, retweeting is simply the function Retweet
)
Error Handling, Rate Limiting, and Throttling
Error Handling
Twitter errors are returned as an ApiError
, which satisfies the error
interface and can be treated as a vanilla error
. However, it also contains the additional information returned by the Twitter API that may be useful in deciding how to proceed after encountering an error.
If you make queries too quickly, you may bump against Twitter's rate limits. If this happens, anaconda
automatically retries the query when the rate limit resets, using the X-Rate-Limit-Reset
header that Twitter provides to determine how long to wait.
In other words, users of the anaconda
library should not need to handle rate limiting errors themselves; this is handled seamlessly behind-the-scenes. If an error is returned by a function, another form of error must have occurred (which can be checked by using the fields provided by the ApiError
struct).
(If desired, this feature can be turned off by calling ReturnRateLimitError(true)
.)
Throttling
Anaconda now supports automatic client-side throttling of queries to avoid hitting the Twitter rate-limit.
This is currently off by default; however, it may be turned on by default in future versions of the library, as the implementation is improved.
To set a delay between queries, use the SetDelay
method:
api.SetDelay(10 * time.Second)
Delays are set specific to each TwitterApi
struct, so queries that use different users' access credentials are completely independent.
To turn off automatic throttling, set the delay to 0
:
api.SetDelay(0 * time.Second)
Query Queue Persistence
If your code creates a NewTwitterApi in a regularly called function, you'll need to call .Close()
on the API struct to clear the queryQueue and allow the goroutine to exit. Otherwise you could see goroutine and therefor heap memory leaks in long-running applications.
Google App Engine
Since Google App Engine doesn't make the standard http.Transport
available, it's necessary to tell Anaconda to use a different client context.
api = anaconda.NewTwitterApi("", "")
c := appengine.NewContext(r)
api.HttpClient.Transport = &urlfetch.Transport{Context: c}
License
Anaconda is free software licensed under the MIT/X11 license. Details provided in the LICENSE file.
Top Related Projects
A curated list of awesome Go frameworks, libraries and software
The Go programming language
Go development plugin for Vim
A standard library for microservices.
A Commander for modern Go CLI interactions
Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot