http_client

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxTryTimes = 3
View Source
const DefaultMethod = http.MethodGet
View Source
const DefaultUserAgent = "selefra-cli"

Variables

This section is empty.

Functions

func DownloadToDirectory

func DownloadToDirectory(ctx context.Context, saveDirectory, targetUrl string, progressListener getter.ProgressTracker, options ...getter.ClientOption) error

func GetBytes

func GetBytes(ctx context.Context, targetUrl string, options ...*Options[any, []byte]) ([]byte, error)

func GetJson

func GetJson[Response any](ctx context.Context, targetUrl string, options ...*Options[any, Response]) (Response, error)

func GetString

func GetString(ctx context.Context, targetUrl string, options ...*Options[any, []byte]) (string, error)

func GetYaml

func GetYaml[Response any](ctx context.Context, targetUrl string, options ...*Options[any, Response]) (Response, error)

func MyUserAgent added in v0.0.11

func MyUserAgent() string

func PostJson

func PostJson[Request any, Response any](ctx context.Context, targetUrl string, request Request, options ...*Options[Request, Response]) (Response, error)

func SendRequest

func SendRequest[Request any, Response any](ctx context.Context, options *Options[Request, Response]) (Response, error)

SendRequest Sending requests is a low-level API

Types

type Detector

type Detector struct {
	Name     string
	Detector getter.Detector
}

type GitHubRepoCacheMeta

type GitHubRepoCacheMeta struct {
	// The last download time of the repo
	DownloadTime time.Time `json:"download-time"`
}

GitHubRepoCacheMeta Cache information from the github repository

type GitHubRepoDownloader

type GitHubRepoDownloader struct {
}

func NewGitHubRepoDownloader

func NewGitHubRepoDownloader() *GitHubRepoDownloader

func (*GitHubRepoDownloader) BuildCacheMetaFilePath

func (x *GitHubRepoDownloader) BuildCacheMetaFilePath(downloadDirectory string) string

BuildCacheMetaFilePath The root path of the downloaded repository is followed by a cache metadata-related file

func (*GitHubRepoDownloader) Download

func (*GitHubRepoDownloader) ReadCacheMeta

func (x *GitHubRepoDownloader) ReadCacheMeta(downloadDirectory string) (*GitHubRepoCacheMeta, error)

ReadCacheMeta the github repository cache

func (*GitHubRepoDownloader) Save

func (x *GitHubRepoDownloader) Save(downloadDirectory string, meta *GitHubRepoCacheMeta) error

Save the github repository cache information

type GitHubRepoDownloaderOptions

type GitHubRepoDownloaderOptions struct {

	// Who owns the warehouse, org name or username
	Owner string

	// Name of warehouse
	Repo string

	// Which directory to download it to
	DownloadDirectory string

	// Whether to use a cache, using a cache can avoid repeat download in a short time
	// Open is suitable for large warehouse, when the warehouse itself is not large, you can download it directly
	CacheTime *time.Duration

	// It may take a while, but some messages will be sent to you if needed
	MessageChannel chan *schema.Diagnostics

	ProgressListener getter.ProgressTracker
}

GitHubRepoDownloaderOptions download github

type Options

type Options[Request any, Response any] struct {
	MaxTryTimes         int
	TargetURL           string
	Method              string
	Body                []byte
	RequestSettingSlice []RequestSetting
	ResponseHandler     ResponseHandler[Response]
	MessageChannel      chan *schema.Diagnostics
}

func NewOptions

func NewOptions[Request any, Response any](targetUrl string, responseHandler ResponseHandler[Response]) *Options[Request, Response]

func (*Options[Request, Response]) AppendRequestSetting

func (x *Options[Request, Response]) AppendRequestSetting(requestSetting RequestSetting) *Options[Request, Response]

func (*Options[Request, Response]) SendMessage

func (x *Options[Request, Response]) SendMessage(message *schema.Diagnostics) *Options[Request, Response]

func (*Options[Request, Response]) WithBody

func (x *Options[Request, Response]) WithBody(body []byte) *Options[Request, Response]

func (*Options[Request, Response]) WithJsonResponseHandler

func (x *Options[Request, Response]) WithJsonResponseHandler() *Options[Request, Response]

func (*Options[Request, Response]) WithMaxTryTimes

func (x *Options[Request, Response]) WithMaxTryTimes(maxTryTimes int) *Options[Request, Response]

func (*Options[Request, Response]) WithMessageChannel

func (x *Options[Request, Response]) WithMessageChannel(messageChannel chan *schema.Diagnostics) *Options[Request, Response]

func (*Options[Request, Response]) WithMethod

func (x *Options[Request, Response]) WithMethod(method string) *Options[Request, Response]

func (*Options[Request, Response]) WithRequestSettingSlice

func (x *Options[Request, Response]) WithRequestSettingSlice(requestSettingSlice []RequestSetting) *Options[Request, Response]

func (*Options[Request, Response]) WithResponseHandler

func (x *Options[Request, Response]) WithResponseHandler(responseHandler ResponseHandler[Response]) *Options[Request, Response]

func (*Options[Request, Response]) WithTargetURL

func (x *Options[Request, Response]) WithTargetURL(targetURL string) *Options[Request, Response]

func (*Options[Request, Response]) WithYamlResponseHandler

func (x *Options[Request, Response]) WithYamlResponseHandler() *Options[Request, Response]

type RequestSetting

type RequestSetting func(httpRequest *http.Request) error

func DefaultUserAgentRequestSetting

func DefaultUserAgentRequestSetting() RequestSetting

type ResponseHandler

type ResponseHandler[Response any] func(httpResponse *http.Response) (Response, error)

ResponseHandler A component used to process http responses

func BytesResponseHandler

func BytesResponseHandler(readResponseOnStatusCodeIn ...int) ResponseHandler[[]byte]

BytesResponseHandler The default response handler, automatically reads the response body when the response code is a given value

func JsonResponseHandler

func JsonResponseHandler[Response any](readResponseOnStatusCodeIn ...int) ResponseHandler[Response]

func StringResponseHandler

func StringResponseHandler(readResponseOnStatusCodeIn ...int) ResponseHandler[string]

func YamlResponseHandler

func YamlResponseHandler[Response any](readResponseOnStatusCodeIn ...int) ResponseHandler[Response]

Jump to

Keyboard shortcuts

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