mirror of
https://github.com/Luzifer/expose.git
synced 2024-11-08 14:20:04 +00:00
Add auto-close for serve command
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c5051d8724
commit
0b9ff9c731
1 changed files with 12 additions and 0 deletions
12
cmd/serve.go
12
cmd/serve.go
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/Luzifer/expose/ngrok2"
|
||||
http_helper "github.com/Luzifer/go_helpers/http"
|
||||
|
@ -50,6 +51,15 @@ var serveCmd = &cobra.Command{
|
|||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
|
||||
if d, err := cmd.Flags().GetDuration("timeout"); err == nil && d > 0 {
|
||||
fmt.Printf(" (automatic close in %s)", d)
|
||||
go func() {
|
||||
<-time.After(d)
|
||||
c <- os.Interrupt
|
||||
}()
|
||||
}
|
||||
|
||||
for range c {
|
||||
if err := client.StopTunnel(tun.Name); err != nil {
|
||||
return fmt.Errorf("Unable to stop tunnel %q: %s", tun.Name, err)
|
||||
|
@ -65,6 +75,8 @@ var serveCmd = &cobra.Command{
|
|||
func init() {
|
||||
RootCmd.AddCommand(serveCmd)
|
||||
|
||||
serveCmd.Flags().DurationP("timeout", "t", 0, "Automatically close tunnel after timeout")
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
|
|
Loading…
Reference in a new issue