Skip to content

Instantly share code, notes, and snippets.

View mstrYoda's full-sized avatar
🎧
Developing platform infrastructure. Microservices, CNCF, Kubernetes <3

Emre Savcı mstrYoda

🎧
Developing platform infrastructure. Microservices, CNCF, Kubernetes <3
View GitHub Profile
package main
import (
"fmt"
"net"
"os"
"sync"
"time"
)
package main
import (
"fmt"
"net"
"os"
"time"
)
func main() {
package main
import (
"fmt"
"net"
"os"
)
func main() {
listen, err := net.Listen("tcp", "127.0.0.1:8080")
package main
import (
"fmt"
"net"
"net/http"
)
type myHandler struct {
}
package main
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptrace"
"time"
)
type InMemListener struct {
connCh chan net.Conn
}
func newInMemListener() *InMemListener {
return &InMemListener{
connCh: make(chan net.Conn, 1),
}
}
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)
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 {
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()
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()