Skip to content

Commit

Permalink
change JsonString to Json
Browse files Browse the repository at this point in the history
  • Loading branch information
jreisinger committed Apr 19, 2022
1 parent ffd9104 commit c4b12c8
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 41 deletions.
5 changes: 2 additions & 3 deletions check/abuseipdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ func (a abuseIPDB) Summary() string {
return fmt.Sprintf("domain: %s, usage type: %s", na(a.Domain), na(a.UsageType))
}

func (a abuseIPDB) JsonString() (string, error) {
b, err := json.Marshal(a)
return string(b), err
func (a abuseIPDB) Json() ([]byte, error) {
return json.Marshal(a)
}

// AbuseIPDB uses https://api.abuseipdb.com/ to get generic information about
Expand Down
5 changes: 2 additions & 3 deletions check/dbip.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ func (d dbip) Summary() string {
na(d.Country), na(d.IsoCode), na(d.City), d.IsInEU)
}

func (d dbip) JsonString() (string, error) {
b, err := json.Marshal(d)
return string(b), err
func (d dbip) Json() ([]byte, error) {
return json.Marshal(d)
}

// DBip gets geolocation data from https://db-ip.com/db/download/ip-to-city-lite
Expand Down
12 changes: 6 additions & 6 deletions check/dnsmx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package check

import (
"bytes"
"encoding/json"
"net"
"strings"
Expand All @@ -27,9 +28,8 @@ func (mx MX) Summary() string {
return na(s)
}

func (mx MX) JsonString() (string, error) {
b, err := json.Marshal(mx)
return string(b), err
func (mx MX) Json() ([]byte, error) {
return json.Marshal(mx)
}

// DnsMX performs reverse lookup and consults AbuseIPDB to get domain names fo
Expand Down Expand Up @@ -59,12 +59,12 @@ func DnsMX(ipaddr net.IP) (checkip.Result, error) {
if r.Info == nil {
return result, nil
}
j, err := r.Info.JsonString()
j, err := r.Info.Json()
if err != nil {
return result, newCheckError(err)
}
sr := strings.NewReader(j)
decoder := json.NewDecoder(sr)
b := bytes.NewReader(j)
decoder := json.NewDecoder(b)
var a abuseIPDB
if err := decoder.Decode(&a); err != nil {
return result, newCheckError(err)
Expand Down
5 changes: 2 additions & 3 deletions check/dnsname.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ func (n Names) Summary() string {
return na(strings.Join(n, ", "))
}

func (n Names) JsonString() (string, error) {
b, err := json.Marshal(n)
return string(b), err
func (n Names) Json() ([]byte, error) {
return json.Marshal(n)
}

// DnsName does a reverse lookup for a given IP address to get its names.
Expand Down
5 changes: 2 additions & 3 deletions check/iptoasn.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ func (a AutonomousSystem) Summary() string {
return fmt.Sprintf("AS description: %s", na(a.Description))
}

func (a AutonomousSystem) JsonString() (string, error) {
b, err := json.Marshal(a)
return string(b), err
func (a AutonomousSystem) Json() ([]byte, error) {
return json.Marshal(a)
}

// IPtoASN gets info about autonomous system (IPtoASN) of the ipaddr. The data
Expand Down
5 changes: 2 additions & 3 deletions check/maxmind.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ func (m maxmind) Summary() string {
na(m.Country), na(m.IsoCode), na(m.City), m.IsInEU)
}

func (m maxmind) JsonString() (string, error) {
b, err := json.Marshal(m)
return string(b), err
func (m maxmind) Json() ([]byte, error) {
return json.Marshal(m)
}

// MaxMind gets geolocation data from maxmind.com's GeoLite2-City.mmdb.
Expand Down
5 changes: 2 additions & 3 deletions check/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (s stats) Summary() string {
return fmt.Sprintf("%.0f%% packet loss, sent %d, recv %d, avg round-trip %d ms", s.PacketLoss, s.PacketsSent, s.PacketsRecv, s.AvgRtt.Milliseconds())
}

func (s stats) JsonString() (string, error) {
b, err := json.Marshal(s)
return string(b), err
func (s stats) Json() ([]byte, error) {
return json.Marshal(s)
}
5 changes: 2 additions & 3 deletions check/shodan.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func (s shodan) Summary() string {
return fmt.Sprintf("OS: %s, %d open %s %s", na(s.OS), len(portInfo), portStr, strings.Join(portInfo, ", "))
}

func (s shodan) JsonString() (string, error) {
b, err := json.Marshal(s)
return string(b), err
func (s shodan) Json() ([]byte, error) {
return json.Marshal(s)
}
5 changes: 2 additions & 3 deletions check/tcpports.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ func (t OpenTcpPorts) Summary() string {
return strings.Join(out, ", ")
}

func (t OpenTcpPorts) JsonString() (string, error) {
b, err := json.Marshal(t)
return string(b), err
func (t OpenTcpPorts) Json() ([]byte, error) {
return json.Marshal(t)
}

// TcpPorts tries to connect to the 1000 TCP ports that are most often found
Expand Down
5 changes: 2 additions & 3 deletions check/urlscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func (u urlscan) Summary() string {
}
}

func (u urlscan) JsonString() (string, error) {
b, err := json.Marshal(u)
return string(b), err
func (u urlscan) Json() ([]byte, error) {
return json.Marshal(u)
}
5 changes: 2 additions & 3 deletions check/virustotal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ func (v virusTotal) Summary() string {
return fmt.Sprintf("network: %s, SAN: %s", na(v.Data.Attributes.Network), na(strings.Join(v.Data.Attributes.LastHTTPScert.Extensions.SAN, ", ")))
}

func (v virusTotal) JsonString() (string, error) {
b, err := json.Marshal(v)
return string(b), err
func (v virusTotal) Json() ([]byte, error) {
return json.Marshal(v)
}

// VirusTotal gets generic information and security reputation about the ippaddr
Expand Down
10 changes: 5 additions & 5 deletions checkip.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type Result struct {

// Info is some generic information provided by an Info or InfoSec Check.
type Info interface {
Summary() string // summary info
JsonString() (string, error) // all info in JSON format
Summary() string // summary info
Json() ([]byte, error) // all info in JSON format
}

// EmptyInfo is returned by TypeSec Checks that don't provide generic
Expand All @@ -57,7 +57,7 @@ func (EmptyInfo) Summary() string {
return ""
}

// JsonString returns empty JSON string.
func (EmptyInfo) JsonString() (string, error) {
return "{}", nil
// JsonString returns empty JSON.
func (EmptyInfo) Json() ([]byte, error) {
return nil, nil
}

0 comments on commit c4b12c8

Please sign in to comment.