Skip to content

Commit

Permalink
feat: read targets from stdin (#35)
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Zeng <[email protected]>
  • Loading branch information
knight42 authored Mar 27, 2024
1 parent 0f439e3 commit 1e9ed18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ func (o *Options) Run(ctx context.Context, args []string) error {

var targets []target
if len(o.targetsFile) > 0 {
fin, err := os.Open(o.targetsFile)
if err != nil {
return err
var fin *os.File
if o.targetsFile == "-" {
fin = os.Stdin
} else {
fin, err = os.Open(o.targetsFile)
if err != nil {
return err
}
defer fin.Close()
}
defer fin.Close()
targets, err = parseTargetsFile(fin, ns)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions cmd/client/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func example() string {
# Create the agent in the kube-public namespace, and forward local port 5000 to "1.2.3.4:5000"
{{.Name}} --server.namespace kube-public ip/1.2.3.4 5000
# Forward traffic to multiple targets
echo 'ip/1.2.3.4 5000\nsvc/my-service 8080:80\n-n kube-system deploy/coredns 5353:53@udp' | {{.Name}} -f -
`
tpl, err := template.New("example").Parse(text)
if err != nil {
Expand Down

0 comments on commit 1e9ed18

Please sign in to comment.