Skip to content

Commit d4bda65

Browse files
authored
Refactor interruption (#79)
1 parent 404f381 commit d4bda65

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

internal/oauth2/oauth2.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import (
99
"log"
1010
"net/http"
1111
"net/url"
12-
"os"
13-
"os/signal"
1412
"strconv"
1513
"strings"
16-
"syscall"
1714
"time"
1815

1916
"github.com/go-jose/go-jose/v3"
@@ -280,14 +277,9 @@ func WaitForCallback(clientConfig ClientConfig, serverConfig ServerConfig, hc *h
280277
}
281278
}()
282279

283-
signalChan := make(chan os.Signal, 1)
284-
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
285-
286280
timeout := time.After(clientConfig.BrowserTimeout)
287281

288282
select {
289-
case <-signalChan:
290-
return request, errors.New("interrupted")
291283
case <-timeout:
292284
return request, errors.New("timeout")
293285
case <-done:

main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,24 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"os/signal"
7+
"syscall"
68

79
"github.com/cloudentity/oauth2c/cmd"
10+
"github.com/pterm/pterm"
811
)
912

13+
func init() {
14+
c := make(chan os.Signal, 1)
15+
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
16+
17+
go func() {
18+
<-c
19+
pterm.Error.Println("Interrupted")
20+
os.Exit(1)
21+
}()
22+
}
23+
1024
func main() {
1125
if err := cmd.NewOAuth2Cmd().Execute(); err != nil {
1226
fmt.Fprintln(os.Stderr, err)

0 commit comments

Comments
 (0)