http

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package http provides the utility for balancer on http protocol with consul.

Index

Constants

View Source
const (
	DEFAULT_TIMEOUT_SECONDS_4_READY   = 5  // Default value for TimeoutSeconds4Ready
	DEFAULT_TIMEOUT_SECONDS_4_REQUEST = 10 // Default value for timeoutSeconds4Request
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpBalancer

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

the object for http balancer, it use fasthttp.LBClient to do the process of balance.

func NewHttpBalancer

func NewHttpBalancer(config *ServiceConfig) (*HttpBalancer, error)

NewHttpBalancer init an instance of HttpBalancer

func (*HttpBalancer) Do

func (balancer *HttpBalancer) Do(req *fasthttp.Request, res *fasthttp.Response) error

Do a http request with fasthttp's Request object . It will overwirtes the header of HOST to `balancer.serviceName + ".service.consul"`. It call `DoTimeout` with the value of `balancer.timeoutSeconds4Request`.

type ServiceConfig

type ServiceConfig struct {
	ServiceName          string   // The name for the serivce
	Tags                 []string // The tags used for registering the service
	TimeoutSeconds4Ready uint32   // The max time wait for the service's ready in consul, default value is DEFAULT_TIMEOUT_SECONDS_4_READY

	ConsulConfig *api.Config // The consul's config, it can be nil
	// contains filtered or unexported fields
}

the config used for initial HttpBalancer

Jump to

Keyboard shortcuts

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