File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ package checkip
2+
3+ import (
4+ "encoding/json"
5+ "fmt"
6+ "log"
7+ "net"
8+ )
9+
10+ // WellKnown implements checkip.Info.
11+ type WellKnown bool
12+
13+ func (wk WellKnown ) Json () ([]byte , error ) {
14+ return json .Marshal (wk )
15+ }
16+
17+ func (wk WellKnown ) Summary () string {
18+ return fmt .Sprintf ("%v" , wk )
19+ }
20+
21+ // IsWellKnown implements checkip.Check.
22+ func IsWellKnown (ipaddr net.IP ) (Result , error ) {
23+ res := Result {Name : "well known" }
24+
25+ wellKnown := []net.IP {
26+ net .ParseIP ("1.1.1.1" ),
27+ net .ParseIP ("4.4.4.4" ),
28+ net .ParseIP ("8.8.8.8" ),
29+ }
30+
31+ for _ , wk := range wellKnown {
32+ if string (ipaddr ) == string (wk ) {
33+ res .Info = WellKnown (true )
34+ }
35+ }
36+
37+ return res , nil
38+ }
39+
40+ func Example () {
41+ ipaddr := net .ParseIP ("1.1.1.1" )
42+ result , err := IsWellKnown (ipaddr )
43+ if err != nil {
44+ log .Fatal (err )
45+ }
46+ fmt .Println (result )
47+ // Output: {well known Info false true}
48+ }
You can’t perform that action at this time.
0 commit comments