Skip to content

Commit

Permalink
chore: cleanup tools (#103)
Browse files Browse the repository at this point in the history
- More outline-fetch to fetch. `outline-` is redundant and makes commands longer
- Add response headers to verbose output
- Fix and improve usage strings
  • Loading branch information
fortuna authored Oct 16, 2023
1 parent b0f7b4f commit 57e7a68
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
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

0 comments on commit 57e7a68

Please sign in to comment.