multipart

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2017 License: MIT Imports: 9 Imported by: 0

README

gentleman/multipart Build Status GoDoc Go Report Card

gentleman's plugin to easily define multipart/form-data bodies supporting files and string based fields.

Installation

go get -u gopkg.in/h2non/gentleman.v1/plugins/multipart

API

See godoc reference.

Example

package main

import (
  "fmt"
  "gopkg.in/h2non/gentleman.v1"
  "gopkg.in/h2non/gentleman.v1/plugins/multipart"
)

func main() {
  // Create a new client
  cli := gentleman.New()

  // Create a text based form fields
  fields := map[string]string{"foo": "bar", "bar": "baz"}
  cli.Use(multipart.Fields(fields))

  // Perform the request
  res, err := cli.Request().Method("POST").URL("http://httpbin.org/post").Send()
  if err != nil {
    fmt.Printf("Request error: %s\n", err)
    return
  }
  if !res.Ok {
    fmt.Printf("Invalid server response: %d\n", res.StatusCode)
    return
  }

  fmt.Printf("Status: %d\n", res.StatusCode)
  fmt.Printf("Body: %s", res.String())
}

License

MIT - Tomas Aparicio

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Data

func Data(data FormData) p.Plugin

Data creates custom form based on the given form data who can have files and string based fields.

func Fields

func Fields(fields DataFields) p.Plugin

Fields creates a new multipart form based on string based fields.

func File

func File(name string, reader io.Reader) p.Plugin

File creates a new multipart form based on a unique file field from the given io.ReadCloser stream.

func Files

func Files(files []FormFile) p.Plugin

Files creates a multipart form based on files fields.

Types

type DataFields

type DataFields map[string]Values

DataFields represents a map of text based fields.

type FormData

type FormData struct {
	Data  DataFields
	Files []FormFile
}

FormData represents the supported form fields by file and string data.

type FormFile

type FormFile struct {
	Name   string
	Reader io.Reader
}

FormFile represents the file form field data.

type Values added in v1.0.3

type Values []string

Values represents multiple multipart from values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL