-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add request reject handler on shutdown #1
- Loading branch information
Showing
6 changed files
with
44 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"server": { | ||
"port": 8080, | ||
"shutdown": { | ||
"gracetime": 1 | ||
"gracetime": 100 | ||
} | ||
}, | ||
"log": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package service | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type reject struct { | ||
h http.Handler | ||
done chan struct{} | ||
} | ||
|
||
func (rj *reject) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
select { | ||
case <-rj.done: | ||
// header: Retry-After | ||
w.WriteHeader(http.StatusServiceUnavailable) | ||
w.Write([]byte{}) | ||
default: | ||
rj.h.ServeHTTP(w, r) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package service | ||
|
||
// Service defines any service running within the app | ||
type Service interface { | ||
// Stop is to shut down the running service | ||
// Component defines any component running within the app | ||
type Component interface { | ||
// Stop is to shut down the running component | ||
Stop() error | ||
} |