Skip to content

Commit

Permalink
logout from tailscale on signal
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamg795 committed Jun 9, 2023
1 parent 02be4a6 commit 35783ca
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions golink.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package golink
import (
"bufio"
"bytes"
"context"
"embed"
"encoding/json"
"errors"
Expand All @@ -20,11 +21,13 @@ import (
"net/http"
"net/url"
"os"
"os/signal"
"path/filepath"
"regexp"
"sort"
"strings"
"sync"
"syscall"
texttemplate "text/template"
"time"

Expand Down Expand Up @@ -183,6 +186,16 @@ func Run() error {
}
localClient, _ = srv.LocalClient()

signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)

go func() {
<-signals
if localClient != nil {
localClient.Logout(context.Background())
}
}()

l80, err := srv.Listen("tcp", ":80")
if err != nil {
return err
Expand Down

0 comments on commit 35783ca

Please sign in to comment.