proxy

package
v0.0.0-...-fa1c796 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package proxy implements a HTTP caching proxy for Node package registry (NPM). See https://github.com/pkgems/npm-cache-proxy/ for more information about proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Get(key string) (string, error)
	Set(key string, value string, ttl time.Duration) error
	Delete(key string) error
	Keys(prefix string) ([]string, error)
	Health() error
}

Database provides interface for data storage.

type DatabaseRedis

type DatabaseRedis struct {
	Client *redis.Client
}

DatabaseRedis implements Database interface for Redis database.

func (DatabaseRedis) Delete

func (db DatabaseRedis) Delete(key string) error

Delete deletes data by key.

func (DatabaseRedis) Get

func (db DatabaseRedis) Get(key string) (string, error)

Get returns data by key.

func (DatabaseRedis) Health

func (db DatabaseRedis) Health() error

Health returns an error if database connection cannot be estabilished.

func (DatabaseRedis) Keys

func (db DatabaseRedis) Keys(prefix string) ([]string, error)

Keys returns stored keys filtered by prefix.

func (DatabaseRedis) Set

func (db DatabaseRedis) Set(key string, value string, expiration time.Duration) error

Set stores value identified by key with expiration timeout.

type Options

type Options struct {
	DatabasePrefix     string
	DatabaseExpiration time.Duration
	UpstreamAddress    string
}

Options provides dynamic options for Proxy. This can be used for namespace separation, allowing multiple users use the same proxy instance simultaneously.

type Proxy

type Proxy struct {
	Database   Database
	HttpClient *http.Client
}

Proxy is the proxy instance, it contains Database and HttpClient as static options and GetOptions as dynamic options provider

func (Proxy) GetCachedPath

func (proxy Proxy) GetCachedPath(options Options, path string, request *http.Request) ([]byte, error)

GetCachedPath returns cached upstream response for a given url path.

func (Proxy) ListCachedPaths

func (proxy Proxy) ListCachedPaths(options Options) ([]string, error)

ListCachedPaths returns list of all cached url paths.

func (Proxy) PurgeCachedPaths

func (proxy Proxy) PurgeCachedPaths(options Options) error

PurgeCachedPaths deletes all cached url paths.

func (Proxy) Server

func (proxy Proxy) Server(options ServerOptions) *http.Server

Server creates http proxy server

type ServerOptions

type ServerOptions struct {
	ListenAddress string
	Silent        bool

	GetOptions func() (Options, error)
}

ServerOptions provides configuration for Server method

Jump to

Keyboard shortcuts

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