forked from jreisinger/checkip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkip.go
47 lines (40 loc) · 1.23 KB
/
checkip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Package checkip defines how to Check an IP address.
package checkip
import (
"net"
)
// Existing Check types.
const (
TypeInfo Type = iota // generic information about the IP address
TypeSec // whether the IP address is considered malicious
TypeInfoSec // both of the above
)
// Type is the type of a Check.
type Type int32
// String returns the name of the Check type: Info, Sec or InfoSec.
func (t Type) String() string {
switch t {
case TypeInfo:
return "Info"
case TypeSec:
return "Sec"
case TypeInfoSec:
return "InfoSec"
default:
return "Unknown check type"
}
}
// Check provides generic and/or security information about an IP address.
type Check func(ipaddr net.IP) (Result, error)
// Result is the information provided by a Check.
type Result struct {
Name string `json:"name"` // check name
Type Type `json:"type"` // check type
Info Info `json:"info"` // provided by TypeInfo and TypeInfoSec check
Malicious bool `json:"malicious"` // provided by TypeSec check
}
// Info is generic information provided by a TypeInfo or TypeInfoSec Check.
type Info interface {
Summary() string // summary info
Json() ([]byte, error) // all info in JSON format
}