Git Product home page Git Product logo

myhttp's Introduction

MyHttp

Easy to use API to make timeout supported http GET requests in Go.

Go Report Card Coverage Status

MyHttp is for coders who don't want to write timeout support logic and don't want to deal with heavy APIs, just to make http GET request in Go.

It's battle-tested in production and has tests which even verifies connection leaking issues.

I'd been dealing with this issue myself, I read many documents, and saw that there are no simple and lightweight APIs to do http GET request with timeout logic. So, I created MyHttp in one of my projects and wanted to move it here.

Installation

go get github.com/inancgumus/myhttp

Documentation

See MyHttp GoDoc for the documentation.

Usage example

Get

Get simply gets the url and returns an http.Response.

import (
	"time"
	"github.com/inancgumus/myhttp"
)

mh := myhttp.New(time.Second * 10) // timeout after 10 seconds

res, err := mh.Get("http://www.domain.com/foo")
if err != nil {
	panic(err)
}

// use res here...

WrapGet

WrapGet accepts a function in its second argument and runs it after getting the http.Response from the url and automatically closes the http.Response.Body, in case you may forget to close it.

import (
	"time"
	"github.com/inancgumus/myhttp"
)

mh := myhttp.New(time.Second * 10) // timeout after 10 seconds

err := mh.WrapGet("http://www.domain.com/foo", func(r *http.Response) error {
	// use res here...
	// MyHttp will automatically close http.Response.Body for you after this func ends.
})

if err != nil {
	panic(err)
}

Author

Inanc Gumus โ€“ @inancgumus โ€“ [email protected]

Distributed under the MIT license. See LICENSE for more information.

Contributing

  1. Fork it (https://github.com/inancgumus/myhttp/fork)
  2. Create your feature branch (git checkout -b feature/foo)
  3. Commit your changes (git commit -am 'add: foo')
  4. Push to the branch (git push origin feature/foo)
  5. Create a new Pull Request

myhttp's People

Contributors

inancgumus avatar

Watchers

DeanLJ 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.