8000 GitHub - s1xg0d/gahttp: Async / concurrent HTTP requests for Go
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ gahttp Public
forked from tomnomnom/gahttp

Async / concurrent HTTP requests for Go

Notifications You must be signed in to change notification settings

s1xg0d/gahttp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gahttp

Async/concurrent HTTP requests for Go with rate-limiting.

Work in progress.

Example

package main

import (
    "fmt"
    "net/http"
    "time"

    "github.com/tomnomnom/gahttp"
)

func printStatus(req *http.Request, resp *http.Response, err error) {
    if err != nil {
        return
    }
    fmt.Printf("%s: %s\n", req.URL, resp.Status)
}

func main() {
    p := gahttp.NewPipeline()
    p.SetConcurrency(20)
    p.SetRateLimit(time.Second * 1)

    urls := []string{
        "http://example.com",
        "http://example.com",
        "http://example.com",
        "http://example.net",
        "http://example.org",
    }

    for _, u := range urls {
        p.Get(u, gahttp.Wrap(printStatus, gahttp.CloseBody))
    }
    p.Done()

    p.Wait()
}

TODO

  • DoneAndWait() func?
  • Helper for writing responses to channel? (e.g. func ChanWriter() (chan *Response, procFn))
    • For when you don't want to do the work concurrently
  • Actually handle timeouts / provide context interface for cancellation etc?

About

Async / concurrent HTTP requests for Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%
0