项目作者: bevanhunt

项目描述 :
Golang Multipart File Upload Library
高级语言: Go
项目地址: git://github.com/bevanhunt/gowrex.git
创建时间: 2016-06-27T17:12:04Z
项目社区:https://github.com/bevanhunt/gowrex

开源协议:MIT License

下载


Gowrex - Golang Multipart File Upload Library

Go Report Card
GoDoc
Build Status
CodeCov

Why Gowrex?

Easily create multipart form/file uploads and JSON requests.

Currently this is the only public Go library that supports multiform file uploads out of the box.

Features:

  • Simple, stable, and idomatic Go API
  • Multipart file & form uploading
  • JSON RESTful Requests
  • Supports httptest for local router testing
  • Add Custom Headers
  • Connection Timeout
  • Basic Auth

Install

  1. go get github.com/bevanhunt/gowrex

Documentation

Example of JSON POST with connection timeout

  1. // JSONReceive - json response
  2. type JSONReceive struct {
  3. ID int64 `json:"id"`
  4. Title string `json:"title"`
  5. Body string `json:"body"`
  6. UserID int64 `json:"userId"`
  7. }
  8. // JSONSend - json post
  9. type JSONSend struct {
  10. Title string `json:"title"`
  11. Body string `json:"body"`
  12. UserID int64 `json:"userId"`
  13. }
  14. func main() {
  15. timeout := 10 * time.Second
  16. jsonData := &JSONSend{
  17. Title: "fancy book",
  18. Body: "this is a fancy book",
  19. UserID: 12,
  20. }
  21. req, err := gowrex.Request{
  22. URI: "http://jsonplaceholder.typicode.com/posts",
  23. Timeout: timeout}.PostJSON(jsonData)
  24. if err != nil {
  25. log.Println(err)
  26. }
  27. res, err := req.Do()
  28. if err != nil {
  29. log.Println(err)
  30. }
  31. resp := &JSONReceive{}
  32. res.JSON(resp)
  33. // should print - this is a fancy book
  34. fmt.Println(resp.Body)
  35. }

Similar libraries

TODO

  • self-hosted JSON tests
  • multipart tests
  • basic auth tests
  • cookies
  • more examples