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
package main | |
import ( | |
"fmt" | |
"net" | |
"os" | |
"sync" | |
"time" | |
) |
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
package main | |
import ( | |
"fmt" | |
"net" | |
"os" | |
"time" | |
) | |
func main() { |
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
package main | |
import ( | |
"fmt" | |
"net" | |
"os" | |
) | |
func main() { | |
listen, err := net.Listen("tcp", "127.0.0.1:8080") |
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
package main | |
import ( | |
"fmt" | |
"net" | |
"net/http" | |
) | |
type myHandler struct { | |
} |
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
package main | |
import ( | |
"context" | |
"fmt" | |
"io" | |
"net/http" | |
"net/http/httptrace" | |
"time" | |
) |
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
type InMemListener struct { | |
connCh chan net.Conn | |
} | |
func newInMemListener() *InMemListener { | |
return &InMemListener{ | |
connCh: make(chan net.Conn, 1), | |
} | |
} |
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
func TestHttpServer(t *testing.T) { | |
mux := http.NewServeMux() | |
mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte("OK")) | |
}) | |
srv := httptest.NewUnstartedServer(mux) | |
srv.Start() | |
time.Sleep(1 * time.Second) |
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
func newLocalListener() net.Listener { | |
if serveFlag != "" { | |
l, err := net.Listen("tcp", serveFlag) | |
if err != nil { | |
panic(fmt.Sprintf("httptest: failed to listen on %v: %v", serveFlag, err)) | |
} | |
return l | |
} | |
l, err := net.Listen("tcp", "127.0.0.1:0") | |
if err != nil { |
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
func NewServer() { | |
srv := http.Server{ | |
Addr: ":8080", | |
} | |
mux := http.NewServeMux() | |
mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte("OK")) | |
}) | |
srv.Handler = mux | |
go srv.ListenAndServe() |
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
func TestFasthttpServer(t *testing.T) { | |
fSv := fasthttp.Server{} | |
fSv.Handler = func(ctx *fasthttp.RequestCtx) { | |
if string(ctx.Path()) == "/test" && string(ctx.Method()) == "GET" { | |
ctx.WriteString("OK") | |
} | |
} | |
ln := fasthttputil.NewInmemoryListener() |
NewerOlder