check

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: MIT Imports: 15 Imported by: 2

Documentation

Overview

Package check defines how to check an IP address. It provides types and functions that are useful when writing checks.

Index

Constants

This section is empty.

Variables

View Source
var DefaultHttpClient = HttpClient{/* contains filtered or unexported fields */}

DefaultHttpClient is reused by checks that make HTTP requests.

Functions

func GetConfigValue

func GetConfigValue(key string) (string, error)

GetConfigValue tries to get value for key first from an environment variable then from a configuration file at $HOME/.checkip.yaml.

func Na

func Na(s string) string

Na returns "n/a" if s is empty.

func NonEmpty

func NonEmpty(strings ...string) []string

NonEmpty returns strings that are not empty.

func UpdateFile

func UpdateFile(file, url string, compressFmt string) error

UpdateFile updates file from url if the file is older than a week. If file does not exist it downloads and creates it. compressFmt is the compression format of the file to download; gz or tgz. Empty string means no compression.

Types

type Check

type Check func(ipaddr net.IP) (Result, error)

Check checks an IP address providing generic and/or security information.

type EmptyInfo added in v0.10.1

type EmptyInfo struct {
}

EmptyInfo is returned by checks that don't provide generic information about an IP address.

func (EmptyInfo) JsonString added in v0.10.1

func (EmptyInfo) JsonString() (string, error)

func (EmptyInfo) String added in v0.10.1

func (EmptyInfo) String() string

type Error added in v0.10.1

type Error struct {
	ErrString string `json:"error"`
	// contains filtered or unexported fields
}

Error is an error returned by a check.

func NewError added in v0.10.1

func NewError(err error) *Error

func (*Error) Error added in v0.10.1

func (e *Error) Error() string

type HttpClient

type HttpClient struct {
	// contains filtered or unexported fields
}

func (HttpClient) Get

func (c HttpClient) Get(apiUrl string, headers map[string]string, queryParams map[string]string) ([]byte, error)

func (HttpClient) GetJson

func (c HttpClient) GetJson(apiUrl string, headers map[string]string, queryParams map[string]string, response interface{}) error

type Info added in v0.10.1

type Info interface {
	String() string
	JsonString() (string, error)
}

Info is some generic information provided by an Info check.

type Result

type Result struct {
	Name            string // check name
	Type            Type   // check type
	Info            Info   // provided by Info check
	IPaddrMalicious bool   // provided by Sec check
}

Result is the results of a check.

type Type

type Type string

Type is the type of a check.

const (
	TypeInfo    Type = "Info" // provides generic information about the IP address
	TypeSec     Type = "Sec"  // says whether the IP address is considered malicious
	TypeInfoSec Type = "InfoSec"
)

Jump to

Keyboard shortcuts

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