28 lines
686 B
Go
28 lines
686 B
Go
package tailscale
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const cli = "/Applications/Tailscale.app/Contents/MacOS/Tailscale"
|
|
|
|
func Serve(ctx context.Context, port int) error {
|
|
return run(ctx, "serve", "--bg", "--https="+strconv.Itoa(port), "http://127.0.0.1:"+strconv.Itoa(port))
|
|
}
|
|
|
|
func Off(ctx context.Context, port int) error {
|
|
return run(ctx, "serve", "--https="+strconv.Itoa(port), "off")
|
|
}
|
|
|
|
func run(ctx context.Context, args ...string) error {
|
|
out, err := exec.CommandContext(ctx, cli, args...).CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("tailscale %s: %w: %s", strings.Join(args, " "), err, strings.TrimSpace(string(out)))
|
|
}
|
|
return nil
|
|
}
|