client

package module
v9.0.0-...-e57e7b8 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "9.0.0"

Version of the client.

View Source
const VersionHeader = "X-Client-Version"

VersionHeader is sent with every request.

Variables

This section is empty.

Functions

func WithRetryPolicy

func WithRetryPolicy(ctx context.Context, retryPolicy RetryPolicy) context.Context

WithRetryPolicy returns a new context that overrides the client object's retry policy.

Types

type Client

type Client interface {

	// PostGradeFileForStudent makes a POST request to /students/{student_id}/gradeFile
	// Posts the grade file for the specified student
	// 200: nil
	// 400: *models.BadRequest
	// 500: *models.InternalError
	// default: client side HTTP errors, for example: context.DeadlineExceeded.
	PostGradeFileForStudent(ctx context.Context, i *models.PostGradeFileForStudentInput) error

	// GetSectionsForStudent makes a GET request to /students/{student_id}/sections
	// Gets the sections for the specified student
	// 200: []models.Section
	// 400: *models.BadRequest
	// 500: *models.InternalError
	// default: client side HTTP errors, for example: context.DeadlineExceeded.
	GetSectionsForStudent(ctx context.Context, studentID string) ([]models.Section, error)

	// PostSectionsForStudent makes a POST request to /students/{student_id}/sections
	// Posts the sections for the specified student
	// 200: []models.Section
	// 400: *models.BadRequest
	// 500: *models.InternalError
	// default: client side HTTP errors, for example: context.DeadlineExceeded.
	PostSectionsForStudent(ctx context.Context, i *models.PostSectionsForStudentInput) ([]models.Section, error)
}

Client defines the methods available to clients of the blog service.

type ExponentialRetryPolicy

type ExponentialRetryPolicy struct{}

ExponentialRetryPolicy defines an exponential retry policy

func (ExponentialRetryPolicy) Backoffs

func (ExponentialRetryPolicy) Backoffs() []time.Duration

Backoffs returns five backoffs with exponentially increasing wait times between requests: 100, 200, 400, 800, and 1600 milliseconds +/- up to 5% jitter.

func (ExponentialRetryPolicy) Retry

func (ExponentialRetryPolicy) Retry(req *http.Request, resp *http.Response, err error) bool

Retry will retry non-POST, non-PATCH requests that 5XX. TODO: It does not currently retry any errors returned by net/http.Client's `Do`.

type NoRetryPolicy

type NoRetryPolicy struct{}

NoRetryPolicy defines a policy of never retrying a request.

func (NoRetryPolicy) Backoffs

func (NoRetryPolicy) Backoffs() []time.Duration

Backoffs returns an empty slice.

func (NoRetryPolicy) Retry

Retry always returns false.

type RetryPolicy

type RetryPolicy interface {
	// Backoffs returns the number and timing of retry attempts.
	Backoffs() []time.Duration
	// Retry receives the http request, as well as the result of
	// net/http.Client's `Do` method.
	Retry(*http.Request, *http.Response, error) bool
}

RetryPolicy defines a retry policy.

type SingleRetryPolicy

type SingleRetryPolicy struct{}

SingleRetryPolicy defines a retry that retries a request once

func (SingleRetryPolicy) Backoffs

func (SingleRetryPolicy) Backoffs() []time.Duration

Backoffs returns that you should retry the request 1second after it fails.

func (SingleRetryPolicy) Retry

func (SingleRetryPolicy) Retry(req *http.Request, resp *http.Response, err error) bool

Retry will retry non-POST, non-PATCH requests that 5XX. TODO: It does not currently retry any errors returned by net/http.Client's `Do`.

type WagClient

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

WagClient is used to make requests to the blog service.

func New

func New(basePath string, logger wcl.WagClientLogger, transport *http.RoundTripper) *WagClient

New creates a new client. The base path, logger, and http transport are configurable. The logger provided should be specifically created for this wag client. If tracing is required, provide an instrumented transport using the wag clientconfig module. If no tracing is required, pass nil to use the default transport.

func NewFromDiscovery

func NewFromDiscovery(logger wcl.WagClientLogger, transport *http.RoundTripper) (*WagClient, error)

NewFromDiscovery creates a client from the discovery environment variables. This method requires the three env vars: SERVICE_BLOG_HTTP_(HOST/PORT/PROTO) to be set. Otherwise it returns an error. The logger provided should be specifically created for this wag client. If tracing is required, provide an instrumented transport using the wag clientconfig module. If no tracing is required, pass nil to use the default transport.

func (*WagClient) GetSectionsForStudent

func (c *WagClient) GetSectionsForStudent(ctx context.Context, studentID string) ([]models.Section, error)

GetSectionsForStudent makes a GET request to /students/{student_id}/sections Gets the sections for the specified student 200: []models.Section 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.

func (*WagClient) PostGradeFileForStudent

func (c *WagClient) PostGradeFileForStudent(ctx context.Context, i *models.PostGradeFileForStudentInput) error

PostGradeFileForStudent makes a POST request to /students/{student_id}/gradeFile Posts the grade file for the specified student 200: nil 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.

func (*WagClient) PostSectionsForStudent

func (c *WagClient) PostSectionsForStudent(ctx context.Context, i *models.PostSectionsForStudentInput) ([]models.Section, error)

PostSectionsForStudent makes a POST request to /students/{student_id}/sections Posts the sections for the specified student 200: []models.Section 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.

func (*WagClient) SetLogger

func (c *WagClient) SetLogger(l wcl.WagClientLogger)

SetLogger allows for setting a custom logger

func (*WagClient) SetRetryPolicy

func (c *WagClient) SetRetryPolicy(retryPolicy RetryPolicy)

SetRetryPolicy sets a the given retry policy for all requests.

func (*WagClient) SetTimeout

func (c *WagClient) SetTimeout(timeout time.Duration)

SetTimeout sets a timeout on all operations for the client. To make a single request with a shorter timeout than the default on the client, use context.WithTimeout as described here: https://godoc.org/golang.org/x/net/context#WithTimeout.

Jump to

Keyboard shortcuts

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