Documentation
¶
Overview ¶
Copyright 2023 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2022 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2022 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2022 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2023 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2023 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- Constants
- Variables
- func ContextValue(c *Client) cli.Action
- func ExpandHeader(h http.Header) expr.Expander
- func ExpandResponse(r *Response) expr.Expander
- func FetchAndPrint() cli.Action
- func FlagsAndArgs() cli.Action
- func ListAuthenticators() cli.Action
- func ListCiphers() cli.Action
- func ListCurves() cli.Action
- func ListInterfaces() cli.Action
- func NewIntegrityDownloadMiddleware(i Integrity) func(Downloader) Downloader
- func PromptForCredentials() cli.Action
- func SetAuth(v ...*provider.Value) cli.Action
- func SetBaseURL(name ...*URLValue) cli.Action
- func SetBasicAuth() cli.Action
- func SetBindAddress(v ...string) cli.Action
- func SetBody(s ...string) cli.Action
- func SetBodyContent(s ...*ContentType) cli.Action
- func SetCACertFile(path ...string) cli.Action
- func SetCACertPath(path ...string) cli.Action
- func SetCiphers(v ...*CipherSuites) cli.Action
- func SetClientCertFile(path ...string) cli.Action
- func SetCurves(v ...*CurveIDs) cli.Action
- func SetDNSInterface(s ...string) cli.Action
- func SetDialKeepAlive(v ...time.Duration) cli.Action
- func SetDialTimeout(s ...time.Duration) cli.Action
- func SetDisableDialKeepAlive() cli.Action
- func SetDownload() cli.Action
- func SetFailFast(i ...bool) cli.Action
- func SetFillValue(s ...*cli.NameValue) cli.Action
- func SetFollowRedirects(s ...bool) cli.Action
- func SetHeader(s ...*HeaderValue) cli.Action
- func SetIncludeResponseHeaders(s ...bool) cli.Action
- func SetInsecureSkipVerify(v ...bool) cli.Action
- func SetIntegrity(i ...Integrity) cli.Action
- func SetInterface(v ...string) cli.Action
- func SetJSON() cli.Action
- func SetJSONContent() cli.Action
- func SetKeyFile(path ...string) cli.Action
- func SetMethod(s ...string) cli.Action
- func SetNextProtos(s ...[]string) cli.Action
- func SetNoOutput(b ...bool) cli.Action
- func SetOutputFile(f ...string) cli.Action
- func SetPreferGo() cli.Action
- func SetQueryString(s ...*cli.NameValue) cli.Action
- func SetRequestID(s ...string) cli.Action
- func SetServerName(s ...string) cli.Action
- func SetStrictErrorsDNS() cli.Action
- func SetStripComponents(i ...int) cli.Action
- func SetTLSv1() cli.Action
- func SetTLSv1_0() cli.Action
- func SetTLSv1_1() cli.Action
- func SetTLSv1_2() cli.Action
- func SetTLSv1_3() cli.Action
- func SetTime(s ...*cli.File) cli.Action
- func SetTraceLevel(s ...*TraceLevel) cli.Action
- func SetURITemplateVar(v ...*uritemplates.Var) cli.Action
- func SetURITemplateVars(v ...uritemplates.Vars) cli.Action
- func SetURLValue(i ...*URLValue) cli.Action
- func SetUser(s ...*UserInfo) cli.Action
- func SetUserAgent(s ...string) cli.Action
- func SetVerbose() cli.Action
- func SetWriteErr(w ...Expr) cli.Action
- func SetWriteOut(w ...Expr) cli.Action
- func SourceAnnotation() (string, string)
- type AuthMode
- func (m AuthMode) Authenticate(r *http.Request, ui *UserInfo) error
- func (m AuthMode) MarshalText() ([]byte, error)
- func (m AuthMode) RequiresUserInfo() bool
- func (m *AuthMode) Set(arg string) error
- func (m AuthMode) String() string
- func (*AuthMode) Synopsis() string
- func (m *AuthMode) UnmarshalText(b []byte) error
- type Authenticator
- type CipherSuites
- type Client
- func (c *Client) AddMiddleware(m Middleware)
- func (c *Client) AddTransportMiddleware(m TransportMiddleware)
- func (c *Client) Authenticator() Authenticator
- func (c *Client) DNSDialer() *net.Dialer
- func (c *Client) Dialer() *net.Dialer
- func (c *Client) Do(ctx context.Context) ([]*Response, error)
- func (c *Client) Execute(ctx context.Context) error
- func (c *Client) SetAuth(auth Authenticator) error
- func (c *Client) SetBaseURL(u *URLValue) error
- func (c *Client) SetBindAddress(value string) error
- func (c *Client) SetBody(body string) error
- func (c *Client) SetBodyContent(bodyContent Content) error
- func (c *Client) SetCACertFile(path string) error
- func (c *Client) SetCACertPath(path string) error
- func (c *Client) SetCiphers(ids *CipherSuites) error
- func (c *Client) SetClientCertFile(path string) error
- func (c *Client) SetCurves(ids *CurveIDs) error
- func (c *Client) SetDNSInterface(value string) error
- func (c *Client) SetDialKeepAlive(v time.Duration) error
- func (c *Client) SetDialTimeout(v time.Duration) error
- func (c *Client) SetDisableDialKeepAlive(v bool) error
- func (c *Client) SetDownloadFile(v Downloader) error
- func (c *Client) SetFailFast(v bool) error
- func (c *Client) SetFillValue(v *cli.NameValue) error
- func (c *Client) SetFollowRedirects(value bool) error
- func (c *Client) SetHeader(n *HeaderValue) error
- func (c *Client) SetIncludeResponseHeaders(v bool) error
- func (c *Client) SetInsecureSkipVerify(v bool) error
- func (c *Client) SetIntegrity(i Integrity) error
- func (c *Client) SetInterface(value string) error
- func (c *Client) SetKeyFile(path string) error
- func (c *Client) SetMethod(s string) error
- func (c *Client) SetNextProtos(s []string) error
- func (c *Client) SetNoOutput(b bool) error
- func (c *Client) SetOutputFile(f string) error
- func (c *Client) SetPreferGoDialer(v bool) error
- func (c *Client) SetQueryString(n *cli.NameValue) error
- func (c *Client) SetRequestID(s string) error
- func (c *Client) SetServerName(s string) error
- func (c *Client) SetStrictErrorsDNS(v bool) error
- func (c *Client) SetStripComponents(count int) error
- func (c *Client) SetTraceLevel(v TraceLevel) error
- func (c *Client) SetURITemplateVar(v *uritemplates.Var) error
- func (c *Client) SetURITemplateVars(v uritemplates.Vars) error
- func (c *Client) SetURL(u *url.URL) error
- func (c *Client) SetURLValue(u *URLValue) error
- func (c *Client) SetUser(user *UserInfo) error
- func (c *Client) SetUserAgent(value string) error
- func (c *Client) SetWriteErr(w Expr) error
- func (c *Client) SetWriteOut(w Expr) error
- func (c *Client) TLSConfig() *tls.Config
- func (c *Client) UseAuthMiddleware(fn func(Authenticator) Authenticator)
- func (c *Client) UseDownloadMiddleware(fn func(Downloader) Downloader)
- type Content
- type ContentType
- type CurveIDs
- type DownloadMode
- type Downloader
- type Expr
- type FormDataContent
- type HeaderValue
- type Integrity
- type InterfaceResolver
- type JSONContent
- type Location
- type LocationResolver
- type Middleware
- type MiddlewareFunc
- type MultipartFormDataContent
- func (c *MultipartFormDataContent) ContentType() string
- func (c *MultipartFormDataContent) Query() (url.Values, error)
- func (c *MultipartFormDataContent) Read() io.Reader
- func (c *MultipartFormDataContent) Set(name, value string) error
- func (c *MultipartFormDataContent) SetFile(name, file io.Reader) error
- type NameValue
- type Option
- type RawContent
- func (c *RawContent) ContentType() string
- func (c *RawContent) Query() (url.Values, error)
- func (c *RawContent) Read() io.Reader
- func (c *RawContent) Set(_, _ string) error
- func (c *RawContent) SetFile(_, _ io.Reader) error
- func (c *RawContent) Write(d []byte) (int, error)
- func (c *RawContent) WriteString(d string) (int, error)
- type Response
- type RoundTripperFunc
- type TraceLevel
- type TraceLogger
- type TransportMiddleware
- type URLEncodedFormDataContent
- func (c *URLEncodedFormDataContent) ContentType() string
- func (c *URLEncodedFormDataContent) Query() (url.Values, error)
- func (c *URLEncodedFormDataContent) Read() io.Reader
- func (c *URLEncodedFormDataContent) Set(name, value string) error
- func (c *URLEncodedFormDataContent) SetFile(name, file io.Reader) error
- type URLValue
- type UserInfo
- type VirtualPath
Constants ¶
const ( TraceConnections = TraceLevel(1 << iota) TraceRequestHeaders TraceDNS TraceTLS TraceHTTP1XX TraceRequestBody TraceResponseStatus TraceResponseHeaders TraceRedirects // TraceOff causes all tracing to be switched off TraceOff TraceLevel = 0 // TraceOn enables tracing of when connections are made and header TraceOn = TraceRequestHeaders | TraceResponseStatus | TraceResponseHeaders // TraceVerbose enables tracing of DNS, TLS, HTTP 1xx responses TraceVerbose = TraceOn | TraceConnections | TraceDNS | TraceTLS | TraceHTTP1XX | TraceRedirects TraceDebug = TraceVerbose | TraceRequestBody )
Trace level components, which enumerates the various parts of the roundtrip to trace
Variables ¶
var ( Authenticators = &provider.Registry{ Name: "authenticators", Providers: provider.Map{ "basic": {}, "none": {}, }, } )
Functions ¶
func ContextValue ¶
func ContextValue(c *Client) cli.Action
func ExpandResponse ¶
func FetchAndPrint ¶
func FetchAndPrint() cli.Action
func FlagsAndArgs ¶
func FlagsAndArgs() cli.Action
func ListAuthenticators ¶
func ListAuthenticators() cli.Action
ListAuthenticators provides an action which will list the providers
func ListCiphers ¶
func ListCiphers() cli.Action
func ListCurves ¶
func ListCurves() cli.Action
func ListInterfaces ¶
func ListInterfaces() cli.Action
func NewIntegrityDownloadMiddleware ¶
func NewIntegrityDownloadMiddleware(i Integrity) func(Downloader) Downloader
func PromptForCredentials ¶
func PromptForCredentials() cli.Action
PromptForCredentials will display prompts for user and/or password credentials if authentication is required.
func SetBaseURL ¶
func SetBaseURL(name ...*URLValue) cli.Action
func SetBasicAuth ¶
func SetBasicAuth() cli.Action
func SetBindAddress ¶
func SetBindAddress(v ...string) cli.Action
func SetBodyContent ¶
func SetBodyContent(s ...*ContentType) cli.Action
func SetCACertFile ¶
func SetCACertFile(path ...string) cli.Action
func SetCACertPath ¶
func SetCACertPath(path ...string) cli.Action
func SetCiphers ¶
func SetCiphers(v ...*CipherSuites) cli.Action
func SetClientCertFile ¶
func SetClientCertFile(path ...string) cli.Action
func SetDNSInterface ¶
func SetDNSInterface(s ...string) cli.Action
func SetDialKeepAlive ¶
func SetDialTimeout ¶
func SetDisableDialKeepAlive ¶
func SetDisableDialKeepAlive() cli.Action
func SetDownload ¶
func SetDownload() cli.Action
func SetFailFast ¶
func SetFailFast(i ...bool) cli.Action
func SetFillValue ¶
func SetFillValue(s ...*cli.NameValue) cli.Action
func SetFollowRedirects ¶
func SetFollowRedirects(s ...bool) cli.Action
func SetHeader ¶
func SetHeader(s ...*HeaderValue) cli.Action
func SetIncludeResponseHeaders ¶
func SetIncludeResponseHeaders(s ...bool) cli.Action
func SetInsecureSkipVerify ¶
func SetInsecureSkipVerify(v ...bool) cli.Action
func SetIntegrity ¶
func SetIntegrity(i ...Integrity) cli.Action
func SetInterface ¶
func SetInterface(v ...string) cli.Action
func SetJSONContent ¶
func SetJSONContent() cli.Action
func SetKeyFile ¶
func SetKeyFile(path ...string) cli.Action
func SetNextProtos ¶
func SetNextProtos(s ...[]string) cli.Action
func SetNoOutput ¶
func SetNoOutput(b ...bool) cli.Action
func SetOutputFile ¶
func SetOutputFile(f ...string) cli.Action
func SetPreferGo ¶
func SetPreferGo() cli.Action
func SetQueryString ¶
func SetQueryString(s ...*cli.NameValue) cli.Action
func SetRequestID ¶
func SetRequestID(s ...string) cli.Action
func SetServerName ¶
func SetServerName(s ...string) cli.Action
func SetStrictErrorsDNS ¶
func SetStrictErrorsDNS() cli.Action
func SetStripComponents ¶
func SetStripComponents(i ...int) cli.Action
func SetTLSv1_0 ¶
func SetTLSv1_0() cli.Action
func SetTLSv1_1 ¶
func SetTLSv1_1() cli.Action
func SetTLSv1_2 ¶
func SetTLSv1_2() cli.Action
func SetTLSv1_3 ¶
func SetTLSv1_3() cli.Action
func SetTraceLevel ¶
func SetTraceLevel(s ...*TraceLevel) cli.Action
SetTraceLevel provides the action for a flag which sets the trace level corresponding to the flag's value.
func SetURITemplateVar ¶
func SetURITemplateVar(v ...*uritemplates.Var) cli.Action
func SetURITemplateVars ¶
func SetURITemplateVars(v ...uritemplates.Vars) cli.Action
func SetURLValue ¶
func SetURLValue(i ...*URLValue) cli.Action
func SetUserAgent ¶
func SetUserAgent(s ...string) cli.Action
func SetVerbose ¶
func SetVerbose() cli.Action
func SetWriteErr ¶
func SetWriteErr(w ...Expr) cli.Action
func SetWriteOut ¶
func SetWriteOut(w ...Expr) cli.Action
func SourceAnnotation ¶
SourceAnnotation gets the name and value of the annotation added to the Data of all flags that are initialized from this package
Types ¶
type AuthMode ¶
type AuthMode int
AuthMode enumerates common authenticators
func (AuthMode) MarshalText ¶
MarshalText provides the textual representation
func (AuthMode) RequiresUserInfo ¶
func (*AuthMode) UnmarshalText ¶
UnmarshalText converts the textual representation
type Authenticator ¶
type Authenticator interface {
RequiresUserInfo() bool
Authenticate(r *http.Request, u *UserInfo) error
}
func NewAuthenticator ¶
func NewAuthenticator(name string, opts map[string]string) (Authenticator, error)
func WithPromptForCredentials ¶
func WithPromptForCredentials(auth Authenticator) Authenticator
type CipherSuites ¶
type CipherSuites []uint16
func (*CipherSuites) Set ¶
func (c *CipherSuites) Set(arg string) error
func (*CipherSuites) String ¶
func (c *CipherSuites) String() string
func (*CipherSuites) Synopsis ¶
func (c *CipherSuites) Synopsis() string
type Client ¶
type Client struct {
Transport http.RoundTripper
CheckRedirect func(*http.Request, []*http.Request) error
Request *http.Request
IncludeResponseHeaders bool
InterfaceResolver InterfaceResolver
BodyContent Content
UserInfo *UserInfo
LocationResolver LocationResolver
// FailFast causes no response output in the case of a failure
FailFast bool
// contains filtered or unexported fields
}
Client provides an HTTP client that can be accessed from commands, flags, and args within Joe applications. When you register the Client within a Uses pipeline, it also registers flags, templates, and other handlers to enable its configuration from the command line. The simplest action to use is FetchAndPrint(), which executes the request(s) and prints (or downloads) the results:
&cli.App{
Name: "gocurl",
Uses: &httpclient.New(),
Action: httpclient.FetchAndPrint(),
}
This simple app has numerous flags and its simplest invocation could be something like
gocurl https://example.com/
The cmd/wig package provides wig, which is a command line utility very similar to this.
If you only want to add the Client to the context (typically in advanced scenarios where you are deeply customizing the behavior), you only use the action httpclient.ContextValue() with the client you want to add instead of add the client to the pipeline directly.
func FromContext ¶
FromContext obtains the client stored in the context
func (*Client) AddMiddleware ¶
func (c *Client) AddMiddleware(m Middleware)
func (*Client) AddTransportMiddleware ¶
func (c *Client) AddTransportMiddleware(m TransportMiddleware)
func (*Client) Authenticator ¶
func (c *Client) Authenticator() Authenticator
func (*Client) SetAuth ¶
func (c *Client) SetAuth(auth Authenticator) error
func (*Client) SetBaseURL ¶
func (*Client) SetBindAddress ¶
func (*Client) SetBodyContent ¶
func (*Client) SetCACertFile ¶
func (*Client) SetCACertPath ¶
func (*Client) SetCiphers ¶
func (c *Client) SetCiphers(ids *CipherSuites) error
func (*Client) SetClientCertFile ¶
func (*Client) SetDNSInterface ¶
func (*Client) SetDisableDialKeepAlive ¶
func (*Client) SetDownloadFile ¶
func (c *Client) SetDownloadFile(v Downloader) error
func (*Client) SetFailFast ¶
func (*Client) SetFillValue ¶
func (*Client) SetFollowRedirects ¶
func (*Client) SetHeader ¶
func (c *Client) SetHeader(n *HeaderValue) error
func (*Client) SetIncludeResponseHeaders ¶
func (*Client) SetInsecureSkipVerify ¶
func (*Client) SetIntegrity ¶
func (*Client) SetInterface ¶
func (*Client) SetKeyFile ¶
func (*Client) SetNextProtos ¶
func (*Client) SetNoOutput ¶
func (*Client) SetOutputFile ¶
func (*Client) SetPreferGoDialer ¶
func (*Client) SetQueryString ¶
func (*Client) SetRequestID ¶
func (*Client) SetServerName ¶
func (*Client) SetStrictErrorsDNS ¶
func (*Client) SetStripComponents ¶
func (*Client) SetTraceLevel ¶
func (c *Client) SetTraceLevel(v TraceLevel) error
func (*Client) SetURITemplateVar ¶
func (c *Client) SetURITemplateVar(v *uritemplates.Var) error
func (*Client) SetURITemplateVars ¶
func (c *Client) SetURITemplateVars(v uritemplates.Vars) error
func (*Client) SetURLValue ¶
func (*Client) SetUserAgent ¶
func (*Client) SetWriteErr ¶
func (*Client) SetWriteOut ¶
func (*Client) UseAuthMiddleware ¶
func (c *Client) UseAuthMiddleware(fn func(Authenticator) Authenticator)
func (*Client) UseDownloadMiddleware ¶
func (c *Client) UseDownloadMiddleware(fn func(Downloader) Downloader)
type Content ¶
type Content interface {
Read() io.Reader
Query() (url.Values, error)
ContentType() string
Set(name, value string) error
SetFile(name, file io.Reader) error
}
Content implements the logic to build the body content of a request or to produce the query string if else.
func NewContent ¶
func NewContent(ct ContentType) Content
type ContentType ¶
type ContentType int
const ( // ContentTypeFormData is the content type associated with either URL-encoded or multipart form data // depending upon whether files are set ContentTypeFormData ContentType = iota // ContentTypeRaw is the content type associated with raw content ContentTypeRaw ContentType = iota // ContentTypeURLEncodedFormData is URL encoding form data body content ContentTypeURLEncodedFormData // ContentTypeMultipartFormData is multi-part form data body content ContentTypeMultipartFormData // ContentTypeJSON is JSON data body content ContentTypeJSON )
func (ContentType) MarshalText ¶
func (c ContentType) MarshalText() ([]byte, error)
func (*ContentType) Set ¶
func (c *ContentType) Set(arg string) error
func (ContentType) String ¶
func (c ContentType) String() string
func (ContentType) Synopsis ¶
func (ContentType) Synopsis() string
func (*ContentType) UnmarshalText ¶
func (c *ContentType) UnmarshalText(b []byte) error
type DownloadMode ¶
type DownloadMode int
DownloadMode enumerates common download methods. It implements Downloader
const ( PreserveRequestFile DownloadMode = iota PreserveRequestPath )
Download modes. PreserveRequestFile uses the remote file name. PreserveRequestPath uses the remote file path.
func (DownloadMode) FileName ¶
func (d DownloadMode) FileName(r *Response) string
func (DownloadMode) OpenDownload ¶
func (d DownloadMode) OpenDownload(ctx context.Context, resp *Response) (io.WriteCloser, error)
func (DownloadMode) WithStripComponents ¶
func (d DownloadMode) WithStripComponents(count int) Downloader
WithStripComponents returns a Downloader which strips the specified number of leading path elements from the resulting file name. This only pertains to PreserveRequestPath.
type Downloader ¶
type Downloader interface {
// OpenDownload saves the download from the response. This method can be
// called multiple times if multiple URLs were requested.
OpenDownload(context.Context, *Response) (io.WriteCloser, error)
}
Downloader provides the behavior for downloading a response
func NewDownloaderTo ¶
func NewDownloaderTo(w io.Writer) Downloader
NewDownloaderTo implements a basic downloader that copies to a writer
func NewFileDownloader ¶
func NewFileDownloader(f string, fileSystem fs.FS) Downloader
NewFileDownloader implements a downloader that copies to a file system. The f argument specifies the name of the file to copy to. It may contain "write out" variables that are expanded. By default, a suffix is added for successive downloads of the same file name.
func NewIntegrityDownloader ¶
func NewIntegrityDownloader(i Integrity, d Downloader) Downloader
type Expr ¶
type Expr string
Expr provides the expression used within the "write out" flag
func (*Expr) UnmarshalText ¶
type FormDataContent ¶
type FormDataContent struct {
// contains filtered or unexported fields
}
func (*FormDataContent) ContentType ¶
func (c *FormDataContent) ContentType() string
func (*FormDataContent) Set ¶
func (c *FormDataContent) Set(name, value string) error
type HeaderValue ¶
HeaderValue provides an instance of a value in a header
func (*HeaderValue) Copy ¶
func (v *HeaderValue) Copy() *HeaderValue
func (*HeaderValue) NewCounter ¶
func (v *HeaderValue) NewCounter() cli.ArgCounter
func (*HeaderValue) Reset ¶
func (v *HeaderValue) Reset()
func (*HeaderValue) Set ¶
func (v *HeaderValue) Set(arg string) error
func (*HeaderValue) String ¶
func (v *HeaderValue) String() string
String obtains the string representation of the name-value pair
type InterfaceResolver ¶
type InterfaceResolver interface {
// Resolve converts a location, typically an IP address
// or adapter name, into a TCP address
Resolve(string) (*net.TCPAddr, error)
}
InterfaceResolver resolves the network interface to use for connections
type JSONContent ¶
type JSONContent struct {
// contains filtered or unexported fields
}
func (*JSONContent) ContentType ¶
func (c *JSONContent) ContentType() string
func (*JSONContent) Read ¶
func (c *JSONContent) Read() io.Reader
func (*JSONContent) Set ¶
func (c *JSONContent) Set(name, value string) error
type Location ¶
type Location interface {
// URL derives a context that should be used for the client request for the
// given URL, the URL itself to use. An error can be returned, usually if the
// input context ctx is lacking a required service.
URL(ctx context.Context) (context.Context, *url.URL, error)
}
Location specifies the request location. A location comprises a URL that will be requested by the HTTP client and a context function that helps initialize any context values that might be needed such as by middleware. This is an indirection typically used to provide behavior dependent upon the request URL. If Location also implements client Middleware, it will be the first middleware function used when the client fetches the request
func URLLocation ¶
URLLocation provides a basic implementation of Location for a URL. It isn't dependent upon and makes no modifications to the context
type LocationResolver ¶
type LocationResolver interface {
// Add a location to be resolved. This is typically in the syntax
// of either a URL or a URI template.
Add(location string) error
// Add a variable that can be applied to templates.
AddVar(v *uritemplates.Var) error
// Set the base URL used for resolving relative URLs.
SetBase(base *url.URL) error
// Resolve the list of locations. Each location is represented
// as a URL and the context the client should use to issue the
// request.
Resolve(context.Context) ([]Location, error)
}
LocationResolver provides the logic of the how the URL to request is resolved.
func NewDefaultLocationResolver ¶
func NewDefaultLocationResolver() LocationResolver
NewDefaultLocationResolver provides a location resolver that supports relative addressing and URI templates
type Middleware ¶
Middleware provides logic that intercepts and processes each request. The next function should be called to continue the middleware pipeline.
func ComposeMiddleware ¶
func ComposeMiddleware(mw ...Middleware) Middleware
ComposeMiddleware creates middleware from a list
func NewRequestIDMiddleware ¶
func NewRequestIDMiddleware(v ...any) Middleware
NewRequestIDMiddleware generates a request ID for each request using the X-Request-ID header
func WithHeader ¶
func WithHeader(name string, value any) Middleware
WithHeader sets the specified header. The value may be:
- string
- []string
- func()string
- func()[]string.
- func(*http.Request)(string, error).
- func(*http.Request)([]string, error).
Other types using their default string format.
func WithHeaders ¶
func WithHeaders(headers http.Header) Middleware
WithHeaders sets the specified headers.
type MiddlewareFunc ¶
MiddlewareFunc implements Middleware as a function which implements the solitary corresponding method of the interface and automatically delegates to the next middleware.
type MultipartFormDataContent ¶
type MultipartFormDataContent struct {
// contains filtered or unexported fields
}
func (*MultipartFormDataContent) ContentType ¶
func (c *MultipartFormDataContent) ContentType() string
func (*MultipartFormDataContent) Query ¶
func (c *MultipartFormDataContent) Query() (url.Values, error)
func (*MultipartFormDataContent) Set ¶
func (c *MultipartFormDataContent) Set(name, value string) error
type Option ¶
type Option func(*Client)
Option is an option to configure the client
func WithDefaultUserAgent ¶
func WithLocationResolver ¶
func WithLocationResolver(r LocationResolver) Option
func WithMiddleware ¶
func WithMiddleware(m Middleware) Option
WithMiddleware adds a middleware function that will execute before the client request
func WithRequestID ¶
WithRequestID provides middleware to the client that adds a header X-Request-ID to the request. The optional argument defines how to generate the ID. When specified, it must be one of these types:
- string
- func()string
- func(context.Context)(string, error)
When unspecified, a cryptographically random string is generated for request IDs.
func WithTransport ¶
func WithTransport(t http.RoundTripper) Option
WithTransport sets the default transport
func WithTransportMiddleware ¶
func WithTransportMiddleware(m TransportMiddleware) Option
WithTransportMiddleware adds middleware to the transport
type RawContent ¶
type RawContent struct {
// contains filtered or unexported fields
}
func NewRawContent ¶
func NewRawContent(data []byte) *RawContent
NewRawContent provides body content that is formed from raw data
func NewStringContent ¶
func NewStringContent(data string) *RawContent
NewStringContent provides body content that is formed from a string
func (*RawContent) ContentType ¶
func (c *RawContent) ContentType() string
func (*RawContent) Set ¶
func (c *RawContent) Set(_, _ string) error
func (*RawContent) WriteString ¶
func (c *RawContent) WriteString(d string) (int, error)
type RoundTripperFunc ¶
type TraceLevel ¶
type TraceLevel int
TraceLevel indicates the amount of client tracing to generate
func (*TraceLevel) Set ¶
func (l *TraceLevel) Set(arg string) error
func (TraceLevel) String ¶
func (l TraceLevel) String() string
type TraceLogger ¶
type TraceLogger interface {
ConnectDone(network, addr string, err error)
ConnectStart(network, addr string)
DNSDone(httptrace.DNSDoneInfo)
DNSStart(httptrace.DNSStartInfo)
GetConn(hostPort string)
Got1xxResponse(code int, header textproto.MIMEHeader) error
GotConn(httptrace.GotConnInfo)
TLSHandshakeDone(tls.ConnectionState, error)
TLSHandshakeStart()
Wait100Continue()
WroteHeaderField(key string, value []string)
WroteRequest(httptrace.WroteRequestInfo)
StartRequest(req *http.Request)
ResponseDone(resp *http.Response, err error)
Redirected(req *http.Request, via []*http.Request, err error)
}
TraceLogger provides delegates from ClientTrace
type TransportMiddleware ¶
type TransportMiddleware func(context.Context, http.RoundTripper) http.RoundTripper
TransportMiddleware provides middleware to the roundtripper
type URLEncodedFormDataContent ¶
type URLEncodedFormDataContent struct {
// contains filtered or unexported fields
}
func (*URLEncodedFormDataContent) ContentType ¶
func (c *URLEncodedFormDataContent) ContentType() string
func (*URLEncodedFormDataContent) Query ¶
func (c *URLEncodedFormDataContent) Query() (url.Values, error)
func (*URLEncodedFormDataContent) Set ¶
func (c *URLEncodedFormDataContent) Set(name, value string) error
type URLValue ¶
type URLValue struct {
// contains filtered or unexported fields
}
URLValue provides ergonomics for entering URLs as values. When the text looks like a port (e.g. :8080), the URL is interpeted as localhost. When the text looks like a hostname, the prefix http:// is preprended.
func NewURLValue ¶
NewURLValue creates a new URLValue from a string
func (*URLValue) URITemplate ¶
func (u *URLValue) URITemplate() (*uritemplates.URITemplate, error)
URITemplate interprets the value as a URI Template
type VirtualPath ¶
type VirtualPath struct {
// RequestPath identifies the request path prefix to match
RequestPath string
// PhysicalPath identifies the real path that contains the resource to be served
PhysicalPath string
// Options encapsulates options about the virtual path
Options map[string]string
}
VirtualPath identifies the mapping between a request path and a real file system path
func ParseVirtualPath ¶
func ParseVirtualPath(v string) (VirtualPath, error)
func (*VirtualPath) Copy ¶
func (v *VirtualPath) Copy() *VirtualPath
func (*VirtualPath) NewCounter ¶
func (v *VirtualPath) NewCounter() cli.ArgCounter
func (*VirtualPath) Reset ¶
func (v *VirtualPath) Reset()
func (*VirtualPath) Set ¶
func (v *VirtualPath) Set(arg string) error
func (VirtualPath) String ¶
func (v VirtualPath) String() string