batch

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, config Config) error

Run processes the GraphQL requests using the provided configuration.

func RunWith

func RunWith(ctx context.Context, client *Client, input *json.Decoder, output *json.Encoder, errOutput *json.Encoder, stats Stats, connections int) error

RunWith processes the GraphQL requests using the configured dependencies.

Types

type Client

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

Client is used for making GraphQL requests via HTTP using pre-configured url, query, header and login information.

Client is thread-safe.

func NewClient

func NewClient(config Config, query string) (*Client, error)

NewClient creates a new Client using the provided configuration and query.

func (*Client) Do

func (c *Client) Do(variables map[string]any) (io.ReadCloser, error)

Do sends the GraphQL request using the configured query and the provided variables.

For successful requests it will return the response body and no error. For unsuccessful requests it will return an error and if possible the response body.

If the client was configured with OAuth credentials, it will follow a client_credentials flow to receive a valid authorization token. The token will automatically be renewed before its expiry.

For any authorization other flow you can provide the required authorization headers during client creation.

type Config

type Config struct {
	URL         string
	Connections int
	Verbose     bool
	Headers     []string
	BearerToken string
	OAuth       OAuthConfig
	QueryFile   string
	InputFile   string
	OutputFile  string
	ErrorFile   string
}

Config holds the run configuration.

type OAuthConfig

type OAuthConfig struct {
	URL          string
	ClientID     string
	ClientSecret string
	Scope        string
}

OAuthConfig holds the credentials for the OAuth 2.0 client credentials flow.

type SilentStats

type SilentStats struct{}

SilentStats can be used when the statistics should not be collected.

func (*SilentStats) AddError

func (s *SilentStats) AddError()

AddError is a no-op.

func (*SilentStats) AddProcessed

func (s *SilentStats) AddProcessed()

AddProcessed is a no-op.

func (*SilentStats) Values

func (s *SilentStats) Values() (int, int)

Values always returns zero for the counter values.

type Stats

type Stats interface {
	AddProcessed()
	AddError()
	Values() (int, int)
}

Stats can be used for counting processed and erroneous requests.

func PrintStats

func PrintStats(verbose bool, d time.Duration) Stats

PrintStats creates an instance of Stats and if verbose is true starts printing these stats to stdout regularly.

Currently there is no way to stop printing the stats.

type VerboseStats

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

VerboseStats counts the processed and erroneous requests.

VerboseStats is thread-safe with regards to incrementing the counter values.

func (*VerboseStats) AddError

func (s *VerboseStats) AddError()

AddError increases the erroneous requests counter by one.

func (*VerboseStats) AddProcessed

func (s *VerboseStats) AddProcessed()

AddProcessed increases the processed requests counter by one.

func (*VerboseStats) Values

func (s *VerboseStats) Values() (int, int)

Values returns the current counter values (processed and erroneous requests).

Values does not lock the counters while reading them, potentially resulting in situations where each counter value is correct at the time it was read, but not correct when looking at both values.

Jump to

Keyboard shortcuts

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