etag

package module
v0.0.0-...-2dad0e6 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 2 Imported by: 5

README

go-etag

Package etag implements HTTP ETag and HTTP If-None-Match style HTTP conditional GET, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-etag

GoDoc

Example

Here is how package etag can be used:

import "github.com/reiver/go-etag"

func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {

	var eTag string = generateETag(bytes) // <--------- You would need to come up with the value of eTag yourself

	if etag.Handle(responseWriter, request, eTag) {
		return
	}

	responseWriter.Write(bytes)
}

For example, you might do:

func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {

	digest := md4.Sum(bytes)
	var eTag string = fmt.Sprintf("md4-0x%032X", digest)

	if etag.Handle(responseWriter, request, eTag) {
		return
	}

	responseWriter.Write(bytes)
}

Import

To import package etag use import code like the following:

import "github.com/reiver/go-etag"

Installation

To install package etag do the following:

GOPROXY=direct go get github.com/reiver/go-etag

Author

Package etag was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(responseWriter http.ResponseWriter, request *http.Request, eTag string) bool

Handle handles the HTTP ETag & HTTP If-None-Match — it return true if HTTP request was handled, and returns false if it wasn't.

Example usage:

func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {

	// ...

	var handled bool = etag.Handle(responseWriter, request, eTag)
	if handled {
		return
	}

	// ...

}

Types

This section is empty.

Jump to

Keyboard shortcuts

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