This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(roundtripper): simplify condition and add readme.md (#12)
* chore(roundtripper): simplify condition * docs: add documentations
- Loading branch information
Showing
5 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,4 @@ | |
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
.vscode | ||
sample | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,86 @@ | ||
# hache | ||
Cache on Go HTTP Client | ||
# Docs | ||
|
||
Howdy there!!! | ||
|
||
Usually when we want to integrate with cache (let's say Redis), we usually have to do many changes in our code. | ||
What if, we just inject the cache to the HTTP client. So we don't have to create many changes in each line of our code to get the data from Cache, do the validation etc. | ||
|
||
## Introduce Hache: Injecte-able HTTP Cache for Golang HTTP Client | ||
|
||
[![Build Status](https://travis-ci.org/bxcodec/hache.svg?branch=master)](https://travis-ci.org/bxcodec/hache) | ||
[![codecov](https://codecov.io/gh/bxcodec/hache/branch/master/graph/badge.svg)](https://codecov.io/gh/bxcodec/hache) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/bxcodec/hache)](https://goreportcard.com/report/github.com/bxcodec/hache) | ||
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/bxcodec/hache/blob/master/LICENSE) | ||
[![GoDoc](https://godoc.org/github.com/bxcodec/hache?status.svg)](https://godoc.org/github.com/bxcodec/hache) | ||
|
||
This package is used for caching your http request results from the server. Example how to use can be seen below. | ||
|
||
## Index | ||
|
||
* [Support](#support) | ||
* [Getting Started](#getting-started) | ||
* [Example](#example) | ||
* [Limitation](#limitation) | ||
* [Contribution](#contribution) | ||
|
||
|
||
## Support | ||
|
||
You can file an [Issue](https://github.com/bxcodec/hache/issues/new). | ||
See documentation in [Godoc](https://godoc.org/github.com/bxcodec/hache) | ||
|
||
|
||
## Getting Started | ||
|
||
#### Download | ||
|
||
```shell | ||
go get -u github.com/bxcodec/hache/v3 | ||
``` | ||
# Example | ||
|
||
--- | ||
|
||
Example how to use more details can be seen in the sample folder: [/sample](/sample) | ||
|
||
Short example: | ||
|
||
```go | ||
|
||
// Inject the HTTP Client with Hache | ||
client := &http.Client{} | ||
err := hache.NewWithInmemoryCache(client, time.Second*60) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// And your HTTP Client already supported for HTTP Cache | ||
// To verify you can run a request in a loop | ||
|
||
for i:=0; i< 10; i++ { | ||
startTime := time.Now() | ||
req, err := http.NewRequest("GET", "https://bxcodec.io", nil) | ||
if err != nil { | ||
log.Fatal((err)) | ||
} | ||
|
||
res, err := client.Do(req) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Response time: %vms\n", time.Since(startTime).Microseconds()) | ||
fmt.Println("Status Code", res.StatusCode) | ||
} | ||
// See the response time, it will different on each request and will go smaller. | ||
``` | ||
|
||
### Inject with your Redis Service | ||
//TODO(bxcodec) | ||
|
||
|
||
## Contribution | ||
|
||
--- | ||
|
||
To contrib to this project, you can open a PR or an issue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/bxcodec/hache | ||
|
||
go 1.12 | ||
go 1.13 | ||
|
||
require github.com/bxcodec/gotcha v1.0.0-beta.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/bxcodec/hache" | ||
) | ||
|
||
func main() { | ||
client := &http.Client{} | ||
err := hache.NewWithInmemoryCache(client, time.Second*60) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
for i := 0; i < 10; i++ { | ||
startTime := time.Now() | ||
req, err := http.NewRequest("GET", "https://bxcodec.io", nil) | ||
if err != nil { | ||
log.Fatal((err)) | ||
} | ||
res, err := client.Do(req) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Response time: %vms\n", time.Since(startTime).Microseconds()) | ||
fmt.Println("Status Code", res.StatusCode) | ||
} | ||
} |