Skip to content

sunfmin/handlertransport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Provide to http.Client{Transport: handlertransport.New(my.HelloHandler)} to call to the http.Handler instead of remote network http call.

Here is an example, this can be used with http client library like https://github.com/machinebox/graphql to test a graphql handler.

	hf := func(w http.ResponseWriter, r *http.Request) {
	    w.Write([]byte("Hello world"))
	}
	
	client := &http.Client{
	    Transport: handlertransport.New(http.HandlerFunc(hf)),
	}
	
	resp, err := client.Get("/")
	if err != nil {
	    panic(err)
	}
	io.Copy(os.Stdout, resp.Body)
	// output:
	// Hello world

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages