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

feat: read targets from stdin #35

Merged
merged 1 commit into from
Mar 27, 2024
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
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