Skip to content

Commit

Permalink
improve testable example
Browse files Browse the repository at this point in the history
  • Loading branch information
jreisinger committed May 30, 2022
1 parent fadb323 commit 70dae93
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions checkip_test.go → checkip_check_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package checkip
package checkip_test

import (
"encoding/json"
"fmt"
"log"
"net"
)

// WellKnown implements checkip.Info.
type WellKnown bool

func (wk WellKnown) Json() ([]byte, error) {
return json.Marshal(wk)
}

func (wk WellKnown) Summary() string {
return fmt.Sprintf("%v", wk)
}
"github.com/jreisinger/checkip"
"github.com/jreisinger/checkip/cli"
)

// IsWellKnown implements checkip.Check.
func IsWellKnown(ipaddr net.IP) (Result, error) {
res := Result{Name: "well known"}
func IsWellKnown(ipaddr net.IP) (checkip.Result, error) {
res := checkip.Result{Name: "well known"}

wellKnown := []net.IP{
net.ParseIP("1.1.1.1"),
Expand All @@ -37,12 +28,20 @@ func IsWellKnown(ipaddr net.IP) (Result, error) {
return res, nil
}

// WellKnown implements checkip.Info.
type WellKnown bool

func (wk WellKnown) Json() ([]byte, error) {
return json.Marshal(wk)
}

func (wk WellKnown) Summary() string {
return fmt.Sprintf("%v", wk)
}

func Example() {
ipaddr := net.ParseIP("1.1.1.1")
result, err := IsWellKnown(ipaddr)
if err != nil {
log.Fatal(err)
}
fmt.Println(result)
// Output: {well known Info false true}
results, _ := cli.Run([]checkip.Check{IsWellKnown}, ipaddr)
results.PrintSummary()
// Output: well known true
}

0 comments on commit 70dae93

Please sign in to comment.