octoclient

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 11 Imported by: 0

README

OctoClient

The OctoClient is a simple, lightweight Go library that is used to interact with external services via HTTP requests. The client encapsulates the complexity of HTTP requests and provides a neat, clean, and easy-to-use interface to users.

Installation

Use the go get command to install the OctoClient.

go get github.com/finbox-in/octoclient

Usage

Below is a brief explanation of the functions provided by the OctoClient.

Creating a new client To create a new OctoClient, use the New function. This function requires the baseURL of the service you will interact with.

baseUrl := "http://localhost:8000"
client := octoclient.New(baseUrl)
Invoking a Service

The ServiceInvoke function is used to invoke a service. It requires a clientID and payload which includes serviceID and the data to be sent. It returns an OctoResponse which includes a message, requestID and the data returned by the service.

payload := octoclient.OctoPayload{
    ServiceID: uuid.New(), // Replace with your service ID
    Data: map[string]interface{}{
        "key1": "value1",
        "key2": "value2",
    },
}

clientID := "your-client-id"
response, err := client.ServiceInvoke(clientID, payload)

if err != nil {
    log.Fatalf("Error: %v", err)
}

fmt.Printf("Message: %s\nRequestID: %s\nData: %v\n", 
    response.Message, response.RequestID, response.Data)

License MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertStructToJSON

func ConvertStructToJSON(obj OctoPayload) (*strings.Reader, error)

Types

type OctoClient

type OctoClient struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func New

func New(options Options) *OctoClient

func (*OctoClient) ServiceInvoke

func (o *OctoClient) ServiceInvoke(ctx context.Context, payload OctoPayload) (*OctoResponse, error)

func (*OctoClient) ServiceInvokeForm added in v0.2.0

func (o *OctoClient) ServiceInvokeForm(ctx context.Context, payload OctoPayloadForm) (*OctoResponse, error)

type OctoFileField added in v0.2.0

type OctoFileField struct {
	FieldName string
	FilePath  string
}

type OctoHeader added in v0.2.1

type OctoHeader struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type OctoPayload

type OctoPayload struct {
	ServiceID      string                 `json:"serviceID"`
	QueryParams    []OctoQueryParam       `json:"queryParameters"`
	DynamicHeaders []OctoHeader           `json:"dynamicHeaders"`
	Data           map[string]interface{} `json:"data"`
	RequestID      string                 `json:"requestID"` // Acts as unique identifier for each request.
}

type OctoPayloadForm added in v0.2.0

type OctoPayloadForm struct {
	ServiceID  string          `json:"serviceID"`
	TextFields []OctoTextField `json:"textFields"`
	FileFields []OctoFileField `json:"fileFields"`
}

type OctoQueryParam added in v0.2.1

type OctoQueryParam struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Usage:

  • Create object of OctoConfig with clientID/access-token, baseURL of Octopus & others
  • Create instance of Octo-Client once using this object
  • call the service-invoke using the payload.
  • The other features like pathParams will be included in payload

type OctoResponse

type OctoResponse struct {
	Message   string                 `json:"msg"`
	RequestID uuid.UUID              `json:"requestId"`
	Data      map[string]interface{} `json:"data"`
}

func ConvertByteToStruct

func ConvertByteToStruct(body []byte) (OctoResponse, error)

type OctoTextField added in v0.2.0

type OctoTextField struct {
	FieldName  string
	FieldValue string
}

type Options

type Options struct {
	// Other options in http.Client will be added here e.g, custom timeout
	BaseURL       string
	Token         string // Use AccessToken in place of clientID
	Authorization string // Auth Token
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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