httpheader

package module
v0.0.0-...-c4997e5 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: MIT Imports: 2 Imported by: 2

README

Documentation

HTTP Header

Golang library to bind HTTP headers into struct values.

Example

package main

import (
	"fmt"
	"github.com/dennisstritzke/httpheader"
	"net/http"
)

type GitHubResponse struct {
	Date string `header:"Date"`
}

func main() {
	resp, _ := http.Get("https://github.com/")

	var githubResponse GitHubResponse
	err := httpheader.Bind(resp.Header, &githubResponse)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("Date: %s\n", githubResponse.Date)
}

Documentation

Overview

Package httpheader provides a Bind function, which binds HTTP header values to struct fields.

Example:

package main

import (
    "fmt"
    "github.com/dennisstritzke/httpheader"
    "net/http"
)

type GitHubResponse struct {
    Date string `header:"Date"`
}

func main() {
    resp, _ := http.Get("https://github.com/")

    var githubResponse GitHubResponse
    err := httpheader.Bind(resp.Header, &githubResponse)
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Printf("Date: %s\n", githubResponse.Date)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(header http.Header, v interface{}) error

Bind processes the HTTP header fields and stores the result in the value pointed to by v.

Types

type InvalidBindError

type InvalidBindError struct {
	Type reflect.Type
}

An InvalidBindError describes an invalid argument passed to Bind. (The argument to Bind must be a non-nil pointer.)

func (*InvalidBindError) Error

func (e *InvalidBindError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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