Documentation ¶
Overview ¶
Package gowebdav is a WebDAV client library with a command line tool included.
Index ¶
- Constants
- Variables
- func FixSlash(s string) string
- func FixSlashes(s string) string
- func IsErrCode(err error, code int) bool
- func IsErrNotFound(err error) bool
- func Join(path0 string, path1 string) string
- func NewPathError(op string, path string, statusCode int) error
- func NewPathErrorErr(op string, path string, err error) error
- func PathEscape(path string) string
- func ReadConfig(uri, netrc string) (string, string)
- func String(r io.Reader) string
- type AuthFactory
- type Authenticator
- type Authorizer
- type BasicAuth
- type Client
- func (c *Client) Connect() error
- func (c *Client) Copy(oldpath, newpath string, overwrite bool) error
- func (c *Client) Mkdir(path string, _ os.FileMode) (err error)
- func (c *Client) MkdirAll(path string, _ os.FileMode) (err error)
- func (c *Client) Read(path string) ([]byte, error)
- func (c *Client) ReadDir(path string) ([]os.FileInfo, error)
- func (c *Client) ReadStream(path string) (io.ReadCloser, error)
- func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error)
- func (c *Client) Remove(path string) error
- func (c *Client) RemoveAll(path string) error
- func (c *Client) Rename(oldpath, newpath string, overwrite bool) error
- func (c *Client) SetHeader(key, value string)
- func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request))
- func (c *Client) SetJar(jar http.CookieJar)
- func (c *Client) SetTimeout(timeout time.Duration)
- func (c *Client) SetTransport(transport http.RoundTripper)
- func (c *Client) Stat(path string) (os.FileInfo, error)
- func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error)
- func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error)
- type DigestAuth
- type File
- func (f File) ContentType() string
- func (f File) ETag() string
- func (f File) IsDir() bool
- func (f File) ModTime() time.Time
- func (f File) Mode() os.FileMode
- func (f File) Name() string
- func (f File) Path() string
- func (f File) Size() int64
- func (f File) String() string
- func (f File) Sys() interface{}
- type PassportAuth
- func (p *PassportAuth) Authorize(c *http.Client, rq *http.Request, path string) error
- func (p *PassportAuth) Clone() Authenticator
- func (p *PassportAuth) Close() error
- func (p *PassportAuth) String() string
- func (p *PassportAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error)
- type StatusError
Examples ¶
Constants ¶
const XInhibitRedirect = "X-Gowebdav-Inhibit-Redirect"
Variables ¶
var ErrAuthChanged = errors.New("authentication failed, change algorithm")
ErrAuthChanged must be returned from the Verify method as an error to trigger a re-authentication / negotiation with a new authenticator.
var ErrTooManyRedirects = errors.New("stopped after 10 redirects")
ErrTooManyRedirects will be used as return error if a request exceeds 10 redirects.
Functions ¶
func FixSlashes ¶
FixSlashes appends and prepends a / if they are missing
func IsErrCode ¶
IsErrCode returns true if the given error is an os.PathError wrapping a StatusError with the given status code.
func IsErrNotFound ¶
IsErrNotFound is shorthand for IsErrCode for status 404.
func PathEscape ¶
PathEscape escapes all segments of a given path
Example ¶
fmt.Println(PathEscape("")) fmt.Println(PathEscape("/")) fmt.Println(PathEscape("/web")) fmt.Println(PathEscape("/web/")) fmt.Println(PathEscape("/w e b/d a v/s%u&c#k:s/"))
Output: / /web /web/ /w%20e%20b/d%20a%20v/s%25u&c%23k:s/
func ReadConfig ¶
ReadConfig reads login and password configuration from ~/.netrc machine foo.com login username password 123456
Types ¶
type AuthFactory ¶
type AuthFactory func(c *http.Client, rs *http.Response, path string) (auth Authenticator, err error)
AuthFactory prototype function to create a new Authenticator
type Authenticator ¶
type Authenticator interface { // Authorizes a request. Usually by adding some authorization headers. Authorize(c *http.Client, rq *http.Request, path string) error // Verifies the response if the authorization was successful. // May trigger some round trips to pass the authentication. // May also trigger a new Authenticator negotiation by returning `ErrAuthChenged` Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) // Creates a copy of the underlying Authenticator. Clone() Authenticator io.Closer }
A Authenticator implements a specific way to authorize requests. Each request is bound to a separate Authenticator instance.
The authentication flow itself is broken down into `Authorize` and `Verify` steps. The former method runs before, and the latter runs after the `Request` is submitted. This makes it easy to encapsulate and control complex authentication challenges.
Some authentication flows causing authentication round trips, which can be archived by returning the `redo` of the Verify method. `True` restarts the authentication process for the current action: A new `Request` is spawned, which must be authorized, sent, and re-verified again, until the action is successfully submitted. The preferred way is to handle the authentication ping-pong within `Verify`, and then `redo` with fresh credentials.
The result of the `Verify` method can also trigger an `Authenticator` change by returning the `ErrAuthChanged` as an error. Depending on the `Authorizer` this may trigger an `Authenticator` negotiation.
Set the `XInhibitRedirect` header to '1' in the `Authorize` method to get control over request redirection. Attention! You must handle the incoming request yourself.
To store a shared session state the `Clone` method **must** return a new instance, initialized with the shared state.
func NewDigestAuth ¶
func NewDigestAuth(login, secret string, rs *http.Response) (Authenticator, error)
NewDigestAuth creates a new instance of our Digest Authenticator
func NewPassportAuth ¶
func NewPassportAuth(c *http.Client, user, pw, partnerURL string, header *http.Header) (Authenticator, error)
constructor for PassportAuth creates a new PassportAuth object and automatically authenticates against the given partnerURL
type Authorizer ¶
type Authorizer interface { // Creates a new Authenticator Shim per request. // It may track request related states and perform payload buffering // for authentication round trips. // The underlying Authenticator will perform the real authentication. NewAuthenticator(body io.Reader) (Authenticator, io.Reader) // Registers a new Authenticator factory to a key. AddAuthenticator(key string, fn AuthFactory) }
Authorizer our Authenticator factory which creates an `Authenticator` per action/request.
func NewAutoAuth ¶
func NewAutoAuth(login string, secret string) Authorizer
NewAutoAuth creates an auto Authenticator factory. It negotiates the default authentication method based on the order of the registered Authenticators and the remotely offered authentication methods. First In, First Out.
func NewEmptyAuth ¶
func NewEmptyAuth() Authorizer
NewEmptyAuth creates an empty Authenticator factory The order of adding the Authenticator matters. First In, First Out. It offers the `NewAutoAuth` features.
func NewPreemptiveAuth ¶
func NewPreemptiveAuth(auth Authenticator) Authorizer
NewPreemptiveAuth creates a preemptive Authenticator The preemptive authorizer uses the provided Authenticator for every request regardless of any `Www-Authenticate` header.
It may only have one authentication method, so calling `AddAuthenticator` **will panic**!
Look out!! This offers the skinniest and slickest implementation without any synchronisation!! Still applicable with `BasicAuth` within go routines.
type BasicAuth ¶
type BasicAuth struct {
// contains filtered or unexported fields
}
BasicAuth structure holds our credentials
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines our structure
func NewAuthClient ¶
func NewAuthClient(uri string, auth Authorizer) *Client
NewAuthClient creates a new client instance with a custom Authorizer
func (*Client) ReadStream ¶
func (c *Client) ReadStream(path string) (io.ReadCloser, error)
ReadStream reads the stream for a given path
func (*Client) ReadStreamRange ¶
ReadStreamRange reads the stream representing a subset of bytes for a given path, utilizing HTTP Range Requests if the server supports it. The range is expressed as offset from the start of the file and length, for example offset=10, length=10 will return bytes 10 through 19.
If the server does not support partial content requests and returns full content instead, this function will emulate the behavior by skipping `offset` bytes and limiting the result to `length`.
func (*Client) SetInterceptor ¶
SetInterceptor lets us set an arbitrary interceptor for a given client
func (*Client) SetTimeout ¶
SetTimeout exposes the ability to set a time limit for requests
func (*Client) SetTransport ¶
func (c *Client) SetTransport(transport http.RoundTripper)
SetTransport exposes the ability to define custom transports
type DigestAuth ¶
type DigestAuth struct {
// contains filtered or unexported fields
}
DigestAuth structure holds our credentials
func (*DigestAuth) Clone ¶
func (d *DigestAuth) Clone() Authenticator
Clone creates a copy of itself
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is our structure for a given file
func (File) ContentType ¶
ContentType returns the content type of a file
type PassportAuth ¶
type PassportAuth struct {
// contains filtered or unexported fields
}
PassportAuth structure holds our credentials
func (*PassportAuth) Clone ¶
func (p *PassportAuth) Clone() Authenticator
Clone creates a Copy of itself
type StatusError ¶
type StatusError struct {
Status int
}
StatusError implements error and wraps an erroneous status code.
func (StatusError) Error ¶
func (se StatusError) Error() string