trafficquota

module
v0.0.0-...-e48efe8 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: Apache-2.0

README

Traffic Quota

Build Status Go Report Card codecov FOSSA Status GoDoc Docker Pulls packagecloud deb packagecloud rpm

Token bucket server to control web API requests. You can check whether the request conforms to defined limits on rate and burstiness by querying this service at the beginning of your API.

Quick Start

Starting trafficquotad
go run ./cmd/trafficquotad
Using trafficquotad from Your Application

After go get github.com/orgplace/trafficquota/client or dep ensure -add github.com/orgplace/trafficquota/client:

import "github.com/orgplace/trafficquota/client"

c, _ := client.NewInsecureClient("localhost:3895")
allowed, _ := c.Take("key")

Please see examples directory and godoc for more detail.

Installation

Docker

Pull image from Docker Hub and run:

docker run -it --rm -p3895:3895 orgplace/trafficquota:latest

In your docker-compose.yml:

services:
  trafficquota:
    image: orgplace/trafficquota
    ports:
    - "3895:3895"
DEB/RPM Repository

You can use DEB/RPM repository (packagecloud). Currently, Ubuntu 18.04, Ubuntu 18.10, Debian 9, Fedora 29 and RHEL 7 are supprted.

To register repository, follow packagecloud instruction (deb, rpm). After registration:

# Ubuntu/Debian
apt-get install trafficquota
# Fedora
dnf install trafficquota
# RHEL
yum install trafficquota

When you use the package, systemd unit file for trafficquotad is also installed.

# Start
sudo systemctl start trafficquotad
# Enable
sudo systemctl enable trafficquotad
# Customize
sudo systemctl edit trafficquotad
# Log
journalctl -xeu trafficquotad
From tarball/Build Source

Download tarball form GitHub Releases or build from source:

go build -o trafficquotad ./cmd/trafficquotad

Monitoring

Health Check

trafficquotad supports gRPC Health Checking Protocol. You can query health of the server using grpc-health-probe.

grpc-health-probe -addr=localhost:3895

Directories

Path Synopsis
Package client provides a client to access to token bucket server.
Package client provides a client to access to token bucket server.
cmd
examples
Package proto contains proto files and generated code.
Package proto contains proto files and generated code.
Package server implements a TrafficQuotaServer.
Package server implements a TrafficQuotaServer.
Package tokenbucket provides an interface of token bucket and its implementation.
Package tokenbucket provides an interface of token bucket and its implementation.

Jump to

Keyboard shortcuts

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