https://github.com/alauda/kube-rest
Making http request using client-go
https://github.com/alauda/kube-rest
back-off client client-go forhumans golang http kubernetes rate-limiting rest
Last synced: 11 months ago
JSON representation
Making http request using client-go
- Host: GitHub
- URL: https://github.com/alauda/kube-rest
- Owner: alauda
- License: mit
- Created: 2019-07-16T02:48:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T00:25:24.000Z (about 3 years ago)
- Last Synced: 2024-12-26T05:23:47.728Z (over 1 year ago)
- Topics: back-off, client, client-go, forhumans, golang, http, kubernetes, rate-limiting, rest
- Language: Go
- Homepage:
- Size: 64.5 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kube-rest
[](https://github.com/alauda/kube-rest/blob/master/LICENSE)
[](https://goreportcard.com/report/github.com/alauda/kube-rest)
Kube-Rest implement a http client for making restful request with kubernetes client-go.
## Why
Client-go is not just a client for talking to kubernetes cluster, it is also a good rest client for go:
* multi serilizers: json, portobuf and other serilizers could be added by user
* rate-limiting support: you can specify your QPS for local client
* back-off manager: a back-off manager for unexpected network failover
* human readable/ writeable restful interfaces: the interface is easy to read and write
## How to use
For example, if we want to make a `POST` request to httpbin.org:
```golang
import (
"context"
"fmt"
"log"
"net/url"
"github.com/alauda/kube-rest/pkg/config"
"github.com/alauda/kube-rest/pkg/http"
"github.com/alauda/kube-rest/pkg/types"
)
func main() {
address := "http://httpbin.org"
client, err := http.NewForConfig(config.GetConfigOrDie(address))
if nil != err {
log.Fatal(err)
}
v := url.Values{}
v.Set("Content-Type", "application/json")
option := &types.Options{
Header: v,
}
bt, err := client.Create(context.TODO(), "post", nil, option)
if nil != err {
log.Fatal(err)
}
fmt.Println(fmt.Sprintf("%s", bt))
}
```
Check the [examples](https://github.com/alauda/kube-rest/tree/master/exmaples/https) for more examples.