Skip to content

Commit

Permalink
chore: bring updates from branch v2 to branch main (v3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Sep 1, 2024
2 parents 7568e51 + 82ae758 commit 0953f5a
Show file tree
Hide file tree
Showing 32 changed files with 739 additions and 72 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ on:
- v2
paths-ignore:
- '**.md'
- '**.bazel'
- 'WORKSPACE'
pull_request:
branches:
- main
- v2
paths-ignore:
- '**.md'
- '**.bazel'
- 'WORKSPACE'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -21,7 +25,7 @@ jobs:
name: Build
strategy:
matrix:
go: [ '1.21.x']
go: [ 'stable', '1.19.x' ]
os: [ ubuntu-latest ]

runs-on: ${{ matrix.os }}
Expand All @@ -43,7 +47,7 @@ jobs:
run: diff -u <(echo -n) <(go fmt $(go list ./...))

- name: Test
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/label-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ name: 'Label'
on:
pull_request:
types: [labeled]
paths-ignore:
- '**.md'
- '**.bazel'
- 'WORKSPACE'

jobs:
build:
strategy:
matrix:
go: [ '1.21.x']
go: [ 'stable', '1.19.x' ]
os: [ ubuntu-latest ]

name: Run Build
Expand All @@ -28,8 +32,13 @@ jobs:
cache: true
cache-dependency-path: go.sum

- name: Format
run: diff -u <(echo -n) <(go fmt $(go list ./...))

- name: Test
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...

- name: Coverage
run: bash <(curl -s https://codecov.io/bash)
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ _testmain.go
coverage.out
coverage.txt

# Exclude intellij IDE folders
# Exclude IDE folders
.idea/*
.vscode/*
14 changes: 11 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

# gazelle:prefix github.com/go-resty/resty/v2
# gazelle:go_naming_convention import_alias
Expand All @@ -20,10 +20,14 @@ go_library(
"transport_js.go",
"transport_other.go",
"util.go",
"util_curl.go",
],
importpath = "github.com/go-resty/resty/v2",
visibility = ["//visibility:public"],
deps = ["@org_golang_x_net//publicsuffix:go_default_library"],
deps = [
"//shellescape",
"@org_golang_x_net//publicsuffix:go_default_library",
],
)

go_test(
Expand All @@ -32,14 +36,18 @@ go_test(
"client_test.go",
"context_test.go",
"example_test.go",
"middleware_test.go",
"request_test.go",
"resty_test.go",
"retry_test.go",
"util_test.go",
],
data = glob([".testdata/*"]),
embed = [":resty"],
deps = ["@org_golang_x_net//proxy:go_default_library"],
deps = [
"@org_golang_x_net//proxy:go_default_library",
"@org_golang_x_time//rate:go_default_library",
],
)

alias(
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2023 Jeevanandam M., https://myjeeva.com <[email protected]>
Copyright (c) 2015-2024 Jeevanandam M., https://myjeeva.com <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
52 changes: 35 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p align="center"><a href="#features">Features</a> section describes in detail about Resty capabilities</p>
</p>
<p align="center">
<p align="center"><a href="https://github.com/go-resty/resty/actions/workflows/ci.yml?query=branch%3Amaster"><img src="https://github.com/go-resty/resty/actions/workflows/ci.yml/badge.svg" alt="Build Status"></a> <a href="https://codecov.io/gh/go-resty/resty/branch/master"><img src="https://codecov.io/gh/go-resty/resty/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/go-resty/resty"><img src="https://goreportcard.com/badge/go-resty/resty" alt="Go Report Card"></a> <a href="https://github.com/go-resty/resty/releases/latest"><img src="https://img.shields.io/badge/version-2.13.0-blue.svg" alt="Release Version"></a> <a href="https://pkg.go.dev/github.com/go-resty/resty/v2"><img src="https://pkg.go.dev/badge/github.com/go-resty/resty" alt="GoDoc"></a> <a href="LICENSE"><img src="https://img.shields.io/github/license/go-resty/resty.svg" alt="License"></a> <a href="https://github.com/avelino/awesome-go"><img src="https://awesome.re/mentioned-badge.svg" alt="Mentioned in Awesome Go"></a></p>
<p align="center"><a href="https://github.com/go-resty/resty/actions/workflows/ci.yml?query=branch%3Amaster"><img src="https://github.com/go-resty/resty/actions/workflows/ci.yml/badge.svg" alt="Build Status"></a> <a href="https://codecov.io/gh/go-resty/resty/branch/master"><img src="https://codecov.io/gh/go-resty/resty/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/go-resty/resty"><img src="https://goreportcard.com/badge/go-resty/resty" alt="Go Report Card"></a> <a href="https://github.com/go-resty/resty/releases/latest"><img src="https://img.shields.io/badge/version-2.14.0-blue.svg" alt="Release Version"></a> <a href="https://pkg.go.dev/github.com/go-resty/resty/v2"><img src="https://pkg.go.dev/badge/github.com/go-resty/resty" alt="GoDoc"></a> <a href="LICENSE"><img src="https://img.shields.io/github/license/go-resty/resty.svg" alt="License"></a> <a href="https://github.com/avelino/awesome-go"><img src="https://awesome.re/mentioned-badge.svg" alt="Mentioned in Awesome Go"></a></p>
</p>
<p align="center">
<h4 align="center">Resty Communication Channels</h4>
Expand All @@ -13,7 +13,7 @@

## News

* v2.13.0 [released](https://github.com/go-resty/resty/releases/tag/v2.13.0) and tagged on May 08, 2024.
* v2.14.0 [released](https://github.com/go-resty/resty/releases/tag/v2.14.0) and tagged on Aug 04, 2024.
* v2.0.0 [released](https://github.com/go-resty/resty/releases/tag/v2.0.0) and tagged on Jul 16, 2019.
* v1.12.0 [released](https://github.com/go-resty/resty/releases/tag/v1.12.0) and tagged on Feb 27, 2019.
* v1.0 released and tagged on Sep 25, 2017. - Resty's first version was released on Sep 15, 2015 then it grew gradually as a very handy and helpful library. Its been a two years since first release. I'm very thankful to Resty users and its [contributors](https://github.com/go-resty/resty/graphs/contributors).
Expand Down Expand Up @@ -62,6 +62,7 @@
* goroutine concurrent safe
* Resty Client trace, see [Client.EnableTrace](https://pkg.go.dev/github.com/go-resty/resty/v2#Client.EnableTrace) and [Request.EnableTrace](https://pkg.go.dev/github.com/go-resty/resty/v2#Request.EnableTrace)
* Since v2.4.0, trace info contains a `RequestAttempt` value, and the `Request` object contains an `Attempt` attribute
* Supports `GenerateCurlCommand`(**You should turn on `EnableTrace`**, otherwise the curl command will not contain the body)
* Debug mode - clean and informative logging presentation
* Gzip - Go does it automatically also resty has fallback handling too
* Works fine with `HTTP/2` and `HTTP/1.1`
Expand Down Expand Up @@ -122,15 +123,21 @@ The following samples will assist you to become as comfortable as possible with
import "github.com/go-resty/resty/v2"
```

#### Simple GET
#### Simple POST
>Refer: [debug_curl_test.go](https://github.com/go-resty/resty/blob/v2/examples/debug_curl_test.go)
```go
// Create a Resty Client
client := resty.New()

resp, err := client.R().
EnableTrace().
Get("https://httpbin.org/get")
EnableTrace(). // You should turn on `EnableTrace`, otherwise the curl command will not contain the body
SetBody(map[string]string{"name": "Alex"}).
Post("https://httpbin.org/post")
curlCmdExecuted := resp.Request.GenerateCurlCommand()

// Explore curl command
fmt.Println("Curl Command:\n ", curlCmdExecuted+"\n")

// Explore response object
fmt.Println("Response Info:")
Expand Down Expand Up @@ -160,25 +167,36 @@ fmt.Println(" RequestAttempt:", ti.RequestAttempt)
fmt.Println(" RemoteAddr :", ti.RemoteAddr.String())

/* Output
Curl Command:
curl -X POST -H 'Content-Type: application/json' -H 'User-Agent: go-resty/2.14.0 (https://github.com/go-resty/resty)' -d '{"name":"Alex"}' https://httpbin.org/post
Response Info:
Error : <nil>
Status Code: 200
Status : 200 OK
Proto : HTTP/2.0
Time : 457.034718ms
Received At: 2020-09-14 15:35:29.784681 -0700 PDT m=+0.458137045
Received At: 2024-08-09 13:02:57.187544 +0800 CST m=+1.304888501
Body :
{
"args": {},
"headers": {
"Accept-Encoding": "gzip",
"Host": "httpbin.org",
"User-Agent": "go-resty/2.4.0 (https://github.com/go-resty/resty)",
"X-Amzn-Trace-Id": "Root=1-5f5ff031-000ff6292204aa6898e4de49"
},
"origin": "0.0.0.0",
"url": "https://httpbin.org/get"
}
{
"args": {},
"data": "{\"name\":\"Alex\"}",
"files": {},
"form": {},
"headers": {
"Accept-Encoding": "gzip",
"Content-Length": "15",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "go-resty/2.14.0 (https://github.com/go-resty/resty)",
"X-Amzn-Trace-Id": "Root=1-66b5a301-567c83c86562abd3092f5e19"
},
"json": {
"name": "Alex"
},
"origin": "0.0.0.0",
"url": "https://httpbin.org/post"
}
Request Trace Info:
DNSLookup : 4.074657ms
Expand Down
8 changes: 4 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_go",
sha256 = "69de5c704a05ff37862f7e0f5534d4f479418afc21806c887db544a316f3cb6b",
sha256 = "80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",
],
)

Expand All @@ -24,7 +24,7 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe

go_rules_dependencies()

go_register_toolchains(version = "1.16")
go_register_toolchains(version = "1.19")

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

Expand Down
Loading

0 comments on commit 0953f5a

Please sign in to comment.