Skip to content

Commit

Permalink
chore: add default todo context
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy committed Aug 30, 2022
1 parent 51c5c22 commit 51bcee9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions autotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"golang.org/x/sync/errgroup"
)

type tlsContextKey string

var ctxKey = tlsContextKey("autls")

func run(ctx context.Context, r http.Handler, domain ...string) error {
var g errgroup.Group

Expand All @@ -29,9 +33,10 @@ func run(ctx context.Context, r http.Handler, domain ...string) error {
})

g.Go(func() error {
if ctx == nil {
if v := ctx.Value(ctxKey); v != nil {
return nil
}

<-ctx.Done()

var gShutdown errgroup.Group
Expand All @@ -54,7 +59,8 @@ func RunWithContext(ctx context.Context, r http.Handler, domain ...string) error

// Run support 1-line LetsEncrypt HTTPS servers
func Run(r http.Handler, domain ...string) error {
return run(nil, r, domain...)
ctx := context.WithValue(context.Background(), ctxKey, "done")
return run(ctx, r, domain...)
}

// RunWithManager support custom autocert manager
Expand Down

0 comments on commit 51bcee9

Please sign in to comment.