docs: add usage description

master
Shengjing Zhu 2022-03-07 00:55:42 +08:00
parent 72493d4c3c
commit a85c08c1d3
2 changed files with 25 additions and 2 deletions

View File

@ -1,3 +1,12 @@
# wghttp
Turn WireGuard to an HTTP & SOCKS5 proxy.
Turn WireGuard to an HTTP & SOCKS5 proxies.
The HTTP & SOCKS5 proxies are served on same port. It runs in userspace,
without requirement of WireGuard kernel module or TUN device.
In remote exit mode, the proxy is served on local network, and the traffic
from proxy server goes to WireGuard network.
In local exit mode, the proxy is served on WireGuard network, and the traffic
from WireGuard goes to local network.

16
main.go
View File

@ -1,11 +1,14 @@
package main
import (
"bufio"
"context"
_ "embed"
"fmt"
"net"
"net/http"
"os"
"strings"
"github.com/jessevdk/go-flags"
"golang.zx2c4.com/wireguard/device"
@ -16,6 +19,9 @@ import (
"github.com/zhsj/wghttp/internal/third_party/tailscale/socks5"
)
//go:embed README.md
var readme string
var logger *device.Logger
type options struct {
@ -24,7 +30,7 @@ type options struct {
PrivateKey string `long:"private-key" env:"PRIVATE_KEY" required:"true" description:"WireGuard client private key in base64 format"`
ClientIPs []string `long:"client-ip" env:"CLIENT_IP" env-delim:"," required:"true" description:"WireGuard client IP address"`
Listen string `long:"listen" env:"LISTEN" default:"localhost:8080" description:"HTTP & SOCKS5 server address"`
DNS []string `long:"dns" env:"DNS" env-delim:"," default:"" description:"DNS server IP address, only used WireGuard"`
DNS []string `long:"dns" env:"DNS" env-delim:"," default:"" description:"DNS server IP address, only used in WireGuard"`
MTU int `long:"mtu" env:"MTU" default:"1280" description:"MTU"`
ExitMode string `long:"exit-mode" env:"EXIT_MODE" default:"remote" choice:"remote" choice:"local" description:"Exit mode"`
Verbose bool `short:"v" long:"verbose" description:"Show verbose debug information"`
@ -35,6 +41,14 @@ type options struct {
func main() {
opts := options{}
parser := flags.NewParser(&opts, flags.Default)
parser.Usage = `[OPTIONS]
Description:`
scanner := bufio.NewScanner(strings.NewReader(strings.TrimPrefix(readme, "# wghttp\n")))
for scanner.Scan() {
parser.Usage += " " + scanner.Text() + "\n"
}
parser.Usage = strings.TrimSuffix(parser.Usage, "\n")
if _, err := parser.Parse(); err != nil {
code := 1
if fe, ok := err.(*flags.Error); ok {