Skip to content

NdoleStudio/go-http-client

Repository files navigation

go-http-client

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides a generic go client template for an HTTP API

Installation

go-http-client is compatible with modern Go releases in module mode, with Go installed:

go get github.com/NdoleStudio/go-http-client

Alternatively the same can be achieved if you use import in a package:

import "github.com/NdoleStudio/go-http-client"

Implemented

Usage

Initializing the Client

An instance of the client can be created using New().

package main

import (
	"github.com/NdoleStudio/go-http-client"
)

func main()  {
	statusClient := client.New(client.WithDelay(200))
}

Error handling

All API calls return an error as the last return object. All successful calls will return a nil error.

status, response, err := statusClient.Status.Ok(context.Background())
if err != nil {
    //handle error
}

Status Codes

GET /200: OK

status, response, err := statusClient.Status.Ok(context.Background())

if err != nil {
    log.Fatal(err)
}

log.Println(status.Description) // OK

Testing

You can run the unit tests for this client from the root directory using the command below:

go test -v

License

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