-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from islishude/refact-wait-http
refector wait.HTTPStrategy
- Loading branch information
Showing
8 changed files
with
262 additions
and
31 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
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,12 @@ | ||
FROM golang:1.15-alpine as builder | ||
WORKDIR /app | ||
COPY . . | ||
RUN mkdir -p dist | ||
RUN go build -o ./dist/server main.go | ||
|
||
FROM alpine | ||
WORKDIR /app | ||
COPY --from=builder /app/tls.pem /app/tls-key.pem ./ | ||
COPY --from=builder /app/dist/server . | ||
EXPOSE 6443 | ||
CMD ["/app/server"] |
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,3 @@ | ||
module httptest | ||
|
||
go 1.15 |
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,47 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func main() { | ||
mux := http.NewServeMux() | ||
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
}) | ||
|
||
mux.HandleFunc("/ping", func(w http.ResponseWriter, req *http.Request) { | ||
data, _ := ioutil.ReadAll(req.Body) | ||
if bytes.Equal(data, []byte("ping")) { | ||
w.WriteHeader(http.StatusOK) | ||
_, _ = w.Write([]byte("pong")) | ||
} else { | ||
w.WriteHeader(http.StatusBadRequest) | ||
} | ||
}) | ||
|
||
server := http.Server{Addr: ":6443", Handler: mux} | ||
go func() { | ||
log.Println("serving...") | ||
if err := server.ListenAndServeTLS("tls.pem", "tls-key.pem"); err != nil && err != http.ErrServerClosed { | ||
log.Fatal(err) | ||
} | ||
}() | ||
|
||
stopsig := make(chan os.Signal, 1) | ||
signal.Notify(stopsig, syscall.SIGINT, syscall.SIGTERM) | ||
<-stopsig | ||
|
||
log.Println("stopping...") | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
_ = server.Shutdown(ctx) | ||
} |
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,10 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIBVTCB/aADAgECAghLWuRKnTb4BjAKBggqhkjOPQQDAjAAMB4XDTIwMDgxOTEz | ||
MzUwOFoXDTMwMDgxNzEzNDAwOFowADBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA | ||
BP39G8oZK7JvdcJzSuEzoqe3KsWS7/4C7UKhdoGHkEuHED+I456v3O8x0gUTjqIv | ||
I9FmW3cq/eMoraPzzk3u7vajYTBfMA4GA1UdDwEB/wQEAwIBpjAdBgNVHSUEFjAU | ||
BggrBgEFBQcDAQYIKwYBBQUHAwIwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQU | ||
FdfV6PSYUlHs+lSQNouRwSfR2ZgwCgYIKoZIzj0EAwIDRwAwRAIgDAFtSEaFGuvP | ||
wJZhQv7zjIhCGzYzsZ8KSKUJ3YvdL/4CIBbgDFzEeQWFWUMFPeMaVVrmBmsflPIg | ||
cnC4yG76skGg | ||
-----END CERTIFICATE----- |
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,5 @@ | ||
-----BEGIN EC PRIVATE KEY----- | ||
MHcCAQEEIM8HuDwcZyVqBBy2C6db6zNb/dAJ69bq5ejAEz7qGOIQoAoGCCqGSM49 | ||
AwEHoUQDQgAEBL2ioRmfTc70WT0vyx+amSQOGbMeoMRAfF2qaPzpzOqpKTk0aLOG | ||
0735iy9Fz16PX4vqnLMiM/ZupugAhB//yA== | ||
-----END EC PRIVATE KEY----- |
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,12 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIBxTCCAWugAwIBAgIUWBLNpiF1o4r+5ZXwawzPOfBM1F8wCgYIKoZIzj0EAwIw | ||
ADAeFw0yMDA4MTkxMzM4MDBaFw0zMDA4MTcxMzM4MDBaMBkxFzAVBgNVBAMTDnRl | ||
c3Rjb250YWluZXJzMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBL2ioRmfTc70 | ||
WT0vyx+amSQOGbMeoMRAfF2qaPzpzOqpKTk0aLOG0735iy9Fz16PX4vqnLMiM/Zu | ||
pugAhB//yKOBqTCBpjAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUH | ||
AwEwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUTMdz5PIZ+Gix4jYUzRIHfByrW+Yw | ||
HwYDVR0jBBgwFoAUFdfV6PSYUlHs+lSQNouRwSfR2ZgwMQYDVR0RBCowKIIVdGVz | ||
dGNvbnRhaW5lci5nby50ZXN0gglsb2NhbGhvc3SHBH8AAAEwCgYIKoZIzj0EAwID | ||
SAAwRQIhAJznPNumi2Plf0GsP9DpC+8WukT/jUhnhcDWCfZ6Ini2AiBLhnhFebZX | ||
XWfSsdSNxIo20OWvy6z3wqdybZtRUfdU+g== | ||
-----END CERTIFICATE----- |