Skip to content
This repository has been archived by the owner on Sep 3, 2018. It is now read-only.

truemagic-coder/gowrex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  go get github.com/bevanhunt/gowrex

Documentation

Example of JSON POST with connection timeout

// JSONReceive - json response
type JSONReceive struct {
	ID     int64  `json:"id"`
	Title  string `json:"title"`
	Body   string `json:"body"`
	UserID int64  `json:"userId"`
}

// JSONSend - json post
type JSONSend struct {
	Title  string `json:"title"`
	Body   string `json:"body"`
	UserID int64  `json:"userId"`
}

func main() {
	timeout := 10 * time.Second
	jsonData := &JSONSend{
		Title:  "fancy book",
		Body:   "this is a fancy book",
		UserID: 12,
	}
	req, err := gowrex.Request{
		URI:     "http://jsonplaceholder.typicode.com/posts",
		Timeout: timeout}.PostJSON(jsonData)
	if err != nil {
		log.Println(err)
	}
	res, err := req.Do()
	if err != nil {
		log.Println(err)
	}
	resp := &JSONReceive{}
	res.JSON(resp)
	// should print - this is a fancy book
	fmt.Println(resp.Body)
}

Similar libraries

TODO

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