baningo

package module
v0.0.0-...-004ffd5 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MIT Imports: 6 Imported by: 0

README

baningo Build Status

Go client for apiban.org

Installation

go get github.com/cgrates/baningo

Support

Join CGRateS on Google Groups here.

License

baningo is released under the MIT License. Copyright (C) ITsysCOM GmbH. All Rights Reserved.

Sample usage code

package main

import (
	"fmt"

	"github.com/cgrates/baningo"
)

func main() {
	apikeys := []string{"APIKey1", "APIKey2"}

	// get all banned IPs
	bannedIps, err := baningo.GetBannedIPs(apikeys...)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(bannedIps)

	// check only one IP
	isBanned, err := baningo.CheckIP("127.168.56.203", apikeys...)
	if err != nil {
		fmt.Println(err)
		return
	}
	if isBanned {
		fmt.Println("The IP is banned")
	} else {
		fmt.Println("The IP is not banned")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRateLimit    = errors.New("rate limit exceeded")
	ErrBadRequest   = errors.New("bad request")
	ErrUnauthorized = errors.New("unauthorized")
	ErrEmptyID      = errors.New("empty ID received")
)

basic error returned by the API

View Source
var (
	RootURL = "https://apiban.org/api/"
)

RootURL the root URL for apiban server

Functions

func CheckIP

func CheckIP(ctx context.Context, IP string, apiKeys ...string) (banned bool, err error)

CheckIP this function will check if the IP is banned by apiban in case of a rate limit exceeded will continue with the next apiKey

func GetBannedIPs

func GetBannedIPs(ctx context.Context, apiKeys ...string) (IPs []string, err error)

GetBannedIPs this function will return all the IPs that are banned by apiban in case of a rate limit exceeded will continue with the next apiKey

Types

This section is empty.

Jump to

Keyboard shortcuts

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