client

package
v0.0.0-...-b14b177 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package client contains the quotes server client, configured with the provided config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a client for the quotes server.

func NewClient

func NewClient(logger *zap.Logger, cfg *Config, client *http.Client) *Client

NewClient creates a new quotes server client.

func (*Client) Run

func (c *Client) Run()

Run runs the client.

func (*Client) SendRequest

func (c *Client) SendRequest(url string) error

SendRequest sends a request to the endpoint.

type Config

type Config struct {
	// Logging is the logging configuration.
	Logging struct {
		// LogLevel is the log level to use.
		Level string `envconfig:"LOG_LEVEL" default:"debug"`
		// LogFormat is the log format to use.
		Format string `envconfig:"LOG_FORMAT" default:"console"`
	}

	// Connection is the connection configuration.
	Connection struct {
		// ServerHost is the host of server, that client will connect to
		ServerHost string `envconfig:"SERVER_HOST" default:"localhost"`
		// ServerPort is the port of server that the client will connect to
		ServerPort int `envconfig:"SERVER_PORT" default:"8080"`
		// RequestPath is the path of request that client will send to server
		RequestPath string `envconfig:"REQUEST_PATH" default:"/v1/quotes/random"`
		// RequestRatePerSecond defines how many requests per second client will send to server
		RequestRatePerSecond int `envconfig:"REQUEST_RATE_PER_SECOND" default:"100"`
		// RequestCount defines how many requests client will send to server.
		// If RequestCount is 0, client will send requests infinitely
		RequestCount int `envconfig:"REQUEST_COUNT" default:"0"`
	}
}

Config is a configuration for client.

func NewConfig

func NewConfig() (*Config, error)

NewConfig returns a new Config instance, populated with environment variables and defaults.

Jump to

Keyboard shortcuts

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