-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f149ac0
commit 96e5318
Showing
2 changed files
with
53 additions
and
49 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
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,53 @@ | ||
/* | ||
Package gjrc offers generic utilities to work with JSON-based RESTful API. | ||
Sample usage: | ||
package main | ||
import ( | ||
"fmt" | ||
"github.com/btnguyen2k/consu/gjrc" | ||
"github.com/btnguyen2k/consu/reddo" | ||
) | ||
func main() { | ||
// // pre-build a http.Client | ||
// httpClient := &http.Client{} | ||
// client := NewGjrc(httpClient, 0) | ||
// or, a new http.Client is created with 10 seconds timeout | ||
client := NewGjrc(nil, 10*time.Second) | ||
url := "https://httpbin.org/post" | ||
resp := client.PostJson(url, map[string]interface{}{"key1": "value", "key2": 1, "key3": true}) | ||
val1, err := resp.GetValueAsType("json.key1", reddo.TypeString) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("%#v\n", val1) // output: "value" | ||
val2, err := resp.GetValueAsType("json.key2", reddo.TypeInt) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("%#v\n", val2) // output: 2 | ||
val3, err := resp.GetValueAsType("json.key3", reddo.TypeBool) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("%#v\n", val3) // output: true | ||
} | ||
*/ | ||
package gjrc | ||
|
||
const ( | ||
// Version defines version number of this package | ||
Version = "0.2.1" | ||
) | ||
|
||
// This file contains module's metadata only, which is package level documentation and module Version string. | ||
// Module's code should go into other files. |