auth

package
v2.0.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 2 Imported by: 0

README

gentleman/auth Build Status GoDoc API Go Report Card

gentleman's plugin to easily define HTTP authorization headers based on multiple schemas.

Installation

go get -u gopkg.in/h2non/gentleman.v2/plugins/auth

API

See godoc reference.

Example

package main

import (
  "fmt"
  "gopkg.in/h2non/gentleman.v2"
  "gopkg.in/h2non/gentleman.v2/plugins/auth"
)

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

  // Attach the plugin at client level
  cli.Use(auth.Basic("user", "pas$w0rd"))

  // Perform the request
  res, err := cli.Request().Method().URL("http://httpbin.org/headers").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 Basic

func Basic(username, password string) p.Plugin

Basic defines an authorization basic header in the outgoing request

func Bearer

func Bearer(token string) p.Plugin

Bearer defines an authorization bearer token header in the outgoing request

func Custom

func Custom(value string) p.Plugin

Custom defines a custom authorization header field in the outgoing request

Types

This section is empty.

Jump to

Keyboard shortcuts

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