Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup tools #103

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This app illustrates how to use different transports to fetch a URL in Go.
Direct fetch:

```sh
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest https://ipinfo.io
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch@latest https://ipinfo.io
{
...
"city": "Amsterdam",
Expand All @@ -18,7 +18,7 @@ $ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest http
Using a Shadowsocks server:

```sh
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -transport ss://[redacted]@[redacted]:80 https://ipinfo.io
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch@latest -transport ss://[redacted]@[redacted]:80 https://ipinfo.io
{
...
"region": "New Jersey",
Expand All @@ -31,7 +31,7 @@ $ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -tra
Using a SOCKS5 server:

```sh
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -transport socks5://[redacted]:5703 https://ipinfo.io
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch@latest -transport socks5://[redacted]:5703 https://ipinfo.io
{
...
"city": "Berlin",
Expand All @@ -44,7 +44,7 @@ $ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -tra
Using packet splitting:

```sh
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -transport split:3 https://ipinfo.io
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch@latest -transport split:3 https://ipinfo.io
{
...
"city": "Amsterdam",
Expand Down
26 changes: 25 additions & 1 deletion x/examples/outline-fetch/main.go → x/examples/fetch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,36 @@ import (
"net"
"net/http"
"os"
"path"
"strings"

"github.com/Jigsaw-Code/outline-sdk/x/config"
)

var debugLog log.Logger = *log.New(io.Discard, "", 0)

func init() {
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags...] <url>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
}

func main() {
verboseFlag := flag.Bool("v", false, "Enable debug output")
transportFlag := flag.String("transport", "", "Transport config")

flag.Parse()

if *verboseFlag {
debugLog = *log.New(os.Stderr, "[DEBUG] ", log.LstdFlags|log.Lmicroseconds|log.Lshortfile)
}

url := flag.Arg(0)
if url == "" {
log.Fatal("Need to pass the URL to fetch in the command-line")
log.Print("Need to pass the URL to fetch in the command-line")
flag.Usage()
os.Exit(1)
}

dialer, err := config.NewStreamDialer(*transportFlag)
Expand All @@ -55,6 +73,12 @@ func main() {
}
defer resp.Body.Close()

if *verboseFlag {
for k, v := range resp.Header {
debugLog.Printf("%v: %v", k, v)
}
}

_, err = io.Copy(os.Stdout, resp.Body)
if err != nil {
log.Fatalf("Read of page body failed: %v", err)
Expand Down
11 changes: 10 additions & 1 deletion x/examples/outline-connectivity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"log"
"net"
"os"
"path"
"strings"
"time"

Expand Down Expand Up @@ -83,12 +85,19 @@ func unwrapAll(err error) error {
}
}

func init() {
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags...]\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
}

func main() {
verboseFlag := flag.Bool("v", false, "Enable debug output")
transportFlag := flag.String("transport", "", "Transport config")
domainFlag := flag.String("domain", "example.com.", "Domain name to resolve in the test")
resolverFlag := flag.String("resolver", "8.8.8.8,2001:4860:4860::8888", "Comma-separated list of addresses of DNS resolver to use for the test")
protoFlag := flag.String("proto", "tcp,udp", "Comma-separated list of the protocols to test. Muse be \"tcp\", \"udp\", or a combination of them")
protoFlag := flag.String("proto", "tcp,udp", "Comma-separated list of the protocols to test. Must be \"tcp\", \"udp\", or a combination of them")

flag.Parse()
if *verboseFlag {
Expand Down