net

package
v2.0.0-beta.8 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxRetries int           = 5
	DefaultBackoff    time.Duration = 150 * time.Millisecond
)
View Source
const (
	ContentTypeJSON            = "application/json"
	ContentTypeJSONAlternative = "application/vnd.api+json"
	ContentTypeOctetStream     = "application/octet-stream"
	ContentEncodingGzip        = "gzip"
	HeaderContentType          = "Content-Type"
	HeaderContentEncoding      = "Content-Encoding"
	HeaderAcceptEncoding       = "Accept-Encoding"
	HeaderRateLimitReset       = "x-ratelimit-reset"
	HTTPStatusTooManyRequests  = 429
	FormatJSON                 = "json"
)

Constants for common strings

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	GetSettings() (*SettingsResponseData, error)
	GetEarlyFlakeDetectionData() (*EfdResponseData, error)
	GetCommits(localCommits []string) ([]string, error)
	SendPackFiles(packFiles []string) (bytes int64, err error)
}

func NewClient

func NewClient() Client

func NewClientWithServiceName

func NewClientWithServiceName(serviceName string) Client

type EfdRequestData

type EfdRequestData struct {
	Service        string             `json:"service"`
	Env            string             `json:"env"`
	RepositoryURL  string             `json:"repository_url"`
	Configurations testConfigurations `json:"configurations"`
}

type EfdResponseData

type EfdResponseData struct {
	Tests EfdResponseDataModules `json:"tests"`
}

type EfdResponseDataModules

type EfdResponseDataModules map[string]EfdResponseDataSuites

type EfdResponseDataSuites

type EfdResponseDataSuites map[string][]string

type FormFile

type FormFile struct {
	FieldName   string      // The name of the form field
	FileName    string      // The name of the file
	Content     interface{} // The content of the file (can be []byte, map, struct, etc.)
	ContentType string      // The MIME type of the file (e.g., "application/json", "application/octet-stream")
}

FormFile represents a file to be uploaded in a multipart form request.

type RequestConfig

type RequestConfig struct {
	Method     string            // HTTP method: GET or POST
	URL        string            // Request URL
	Headers    map[string]string // Additional HTTP headers
	Body       interface{}       // Request body for JSON, MessagePack, or raw bytes
	Format     string            // Format: "json" or "msgpack"
	Compressed bool              // Whether to use gzip compression
	Files      []FormFile        // Files to be uploaded in a multipart form data request
	MaxRetries int               // Maximum number of retries
	Backoff    time.Duration     // Initial backoff duration for retries
}

RequestConfig holds configuration for a request.

type RequestHandler

type RequestHandler struct {
	Client *http.Client
}

RequestHandler handles HTTP requests with retries and different formats.

func NewRequestHandler

func NewRequestHandler() *RequestHandler

NewRequestHandler creates a new RequestHandler with a default HTTP client.

func NewRequestHandlerWithClient

func NewRequestHandlerWithClient(client *http.Client) *RequestHandler

NewRequestHandlerWithClient creates a new RequestHandler with a custom http.Client

func (*RequestHandler) SendRequest

func (rh *RequestHandler) SendRequest(config RequestConfig) (*Response, error)

SendRequest sends an HTTP request based on the provided configuration.

type Response

type Response struct {
	Body         []byte // Response body in raw format
	Format       string // Format of the response (json or msgpack)
	StatusCode   int    // HTTP status code
	CanUnmarshal bool   // Whether the response body can be unmarshalled
}

Response represents the HTTP response with deserialization capabilities and status code.

func (*Response) Unmarshal

func (r *Response) Unmarshal(target interface{}) error

Unmarshal deserializes the response body into the provided target based on the response format.

type SettingsRequestData

type SettingsRequestData struct {
	Service        string             `json:"service,omitempty"`
	Env            string             `json:"env,omitempty"`
	RepositoryURL  string             `json:"repository_url,omitempty"`
	Branch         string             `json:"branch,omitempty"`
	Sha            string             `json:"sha,omitempty"`
	Configurations testConfigurations `json:"configurations,omitempty"`
}

type SettingsResponseData

type SettingsResponseData struct {
	CodeCoverage        bool `json:"code_coverage"`
	EarlyFlakeDetection struct {
		Enabled         bool `json:"enabled"`
		SlowTestRetries struct {
			TenS    int `json:"10s"`
			ThirtyS int `json:"30s"`
			FiveM   int `json:"5m"`
			FiveS   int `json:"5s"`
		} `json:"slow_test_retries"`
		FaultySessionThreshold int `json:"faulty_session_threshold"`
	} `json:"early_flake_detection"`
	FlakyTestRetriesEnabled bool `json:"flaky_test_retries_enabled"`
	ItrEnabled              bool `json:"itr_enabled"`
	RequireGit              bool `json:"require_git"`
	TestsSkipping           bool `json:"tests_skipping"`
}

Jump to

Keyboard shortcuts

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