hcfilters

package module
Version: v1.3.2-0...-44c7e08 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: Apache-2.0, MIT Imports: 0 Imported by: 2

README ΒΆ

hcfilters

πŸ˜„ filters for github.com/gregjones/httpcache

CircleCI GoDoc License GitHub release Go Report Card CodeFactor codecov GolangCI Sourcegraph Made by Manfred Touron

Usage

$ go get -u moul.io/hcfilters
// before
client := &http.Client{
	Transport: httpcache.NewTransport(
		diskcache.New(diskcachePath),
	),
}

// after
client := &http.Client{
	Transport: httpcache.NewTransport(
		hcfilters.MaxSize( // skip caching results > 2Mb
			diskcache.New(diskcachePath),
			2*1024*1024,
		),
	),
}

License

Β© 2020 Manfred Touron

Licensed under the Apache License, Version 2.0 (LICENSE-APACHE) or the MIT license (LICENSE-MIT), at your option. See the COPYRIGHT file for more details.

SPDX-License-Identifier: (Apache-2.0 OR MIT)

Documentation ΒΆ

Overview ΒΆ

Package hcfilters provides filtering middlewares for github.com/gregjones/httpcache.

message from the author:

+--------------------------------------------------------------+
| * * * β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘  Hello  β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|
+--------------------------------------------------------------+
|                                                              |
|     ++              ______________________________________   |
|     ++++           /                                      \  |
|      ++++          |                                      |  |
|    ++++++++++      |   Feel free to contribute to this    |  |
|   +++       |      |       project or contact me on       |  |
|   ++         |     |    manfred.life if you like this     |  |
|   +  -==   ==|     |               project!               |  |
|  (   <*>   <*>     |                                      |  |
|   |          |    /|                  :)                  |  |
|   |         _)   / |                                      |  |
|   |      +++    /  \______________________________________/  |
|    \      =+   /                                             |
|     \      +                                                 |
|     |\++++++                                                 |
|     |  ++++      ||//                                        |
|  ___|   |___    _||/__                                     __|
| /    ---    \   \|  |||                   __ _  ___  __ __/ /|
|/  |       |  \    \ /                    /  ' \/ _ \/ // / / |
||  |       |  |    | |                   /_/_/_/\___/\_,_/_/  |
+--------------------------------------------------------------+

This is how to wrap an existing backend:

before:

    client := &http.Client{
        Transport: httpcache.NewTransport(
	       diskcache.New(diskcachePath),
        ),
    }

after:

client := &http.Client{
    Transport: httpcache.NewTransport(
        hcfilters.MaxSize( // skip caching results > 2Mb
            diskcache.New(diskcachePath),
            2*1024*1024,
        ),
    ),
}

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type Cache ΒΆ

type Cache interface {
	// Get returns the []byte representation of a cached response and a bool
	// set to true if the value isn't empty
	Get(key string) (responseBytes []byte, ok bool)
	// Set stores the []byte representation of a response against a key
	Set(key string, responseBytes []byte)
	// Delete removes the value associated with the key
	Delete(key string)
}

Cache is a clone of the httpcache.Cache struct to avoid having a dependency on the original repo

func MaxSize ΒΆ

func MaxSize(next Cache, limit int) Cache

MaxSize filters file that are too big to be cached

func MinSize ΒΆ

func MinSize(next Cache, limit int) Cache

MinSize filters file that are too small to be cached

Jump to

Keyboard shortcuts

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