-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pr-test] add exist 0 for Jenkins pipeline (#142)
* [pr-test] add exist 0 for Jekins pipeline * [pr-test] change to use echo.go for only listen 9095 port
- Loading branch information
Showing
3 changed files
with
88 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"time" | ||
) | ||
|
||
// TeeWriter is an io.Writer wapper. | ||
type TeeWriter struct { | ||
writers []io.Writer | ||
} | ||
|
||
// NewTeeWriter returns a TeeWriter. | ||
func NewTeeWriter(writers ...io.Writer) *TeeWriter { | ||
return &TeeWriter{writers: writers} | ||
} | ||
|
||
// Write writes the data. | ||
func (tw *TeeWriter) Write(p []byte) (n int, err error) { | ||
for _, w := range tw.writers { | ||
w.Write(p) | ||
} | ||
return len(p), nil | ||
} | ||
|
||
func main() { | ||
echoHandler := func(w http.ResponseWriter, req *http.Request) { | ||
time.Sleep(10 * time.Millisecond) | ||
body, err := io.ReadAll(req.Body) | ||
if err != nil { | ||
body = []byte(fmt.Sprintf("<read failed: %v>", err)) | ||
} | ||
|
||
tw := NewTeeWriter(w, os.Stdout) | ||
|
||
url := req.URL.Path | ||
if req.URL.Query().Encode() != "" { | ||
url += "?" + req.URL.Query().Encode() | ||
} | ||
|
||
fmt.Fprintln(tw, "Your Request") | ||
fmt.Fprintln(tw, "==============") | ||
fmt.Fprintln(tw, "Method:", req.Method) | ||
fmt.Fprintln(tw, "URL :", url) | ||
|
||
fmt.Fprintln(tw, "Header:") | ||
for k, v := range req.Header { | ||
fmt.Fprintf(tw, " %s: %v\n", k, v) | ||
} | ||
|
||
fmt.Fprintln(tw, "Body :", string(body)) | ||
} | ||
|
||
http.HandleFunc("/", echoHandler) | ||
http.HandleFunc("/pipeline", echoHandler) | ||
|
||
http.ListenAndServe(":9095", nil) | ||
fmt.Println("listen and serve failed") | ||
} |
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