httpmama

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2023 License: MIT Imports: 3 Imported by: 0

README ΒΆ

HTTP Mama

Utility library for various HTTP related task in Golang





Usage

go get github.com/shahariaazam/httpmama
package main

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"github.com/shahariaazam/httpmama"
)

func main() {
	endpoint1 := httpmama.TestEndpoint{
		Path:           "/foo",
		ResponseString: "hello, world!",
		ResponseHeader: http.Header{"Content-Type": []string{"text/plain"}},
	}

	endpoint2 := httpmama.TestEndpoint{
		Path:           "/bar",
		ResponseString: "goodbye, world!",
		ResponseHeader: http.Header{"Content-Type": []string{"text/plain"}},
	}

	config := httpmama.ServerConfig{
		TestEndpoints: []httpmama.TestEndpoint{endpoint1, endpoint2},
	}

	// Create the server
	server := httpmama.NewTestServer(config)
	defer server.Close()

	// Start making request to the server
	resp, err := http.Get(server.URL + "/foo")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(body)) // Output: "hello, world!"
}

Documentation

Full documentation is available on pkg.go.dev/github.com/shahariaazam/httpmama

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation ΒΆ

Overview ΒΆ

Package httpmama provides a set of utility to work with HTTP

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func NewTestServer ΒΆ

func NewTestServer(config ServerConfig) *httptest.Server

NewTestServer create new HTTP server for testing

Types ΒΆ

type ServerConfig ΒΆ

type ServerConfig struct {
	TestEndpoints []TestEndpoint
}

ServerConfig store server configuration

type TestEndpoint ΒΆ

type TestEndpoint struct {
	Path           string
	ResponseString string
	ResponseHeader http.Header
	QueryParams    url.Values
}

TestEndpoint store the endpoint specific configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL