Documentation ¶
Overview ¶
Package h5ailist retrieves a directory listing from a remote h5ai list.
Example ¶
package main import ( "context" "fmt" "github.com/kenshaw/h5ailist" ) func main() { var items []h5ailist.Item if err := h5ailist.Walk(context.Background(), "https://larsjung.de/h5ai/demo/file preview", func(n string, item *h5ailist.Item, err error) error { switch { case err != nil: return err } items = append(items, *item) return nil }); err != nil { panic(err) } var directories, files int64 for i, item := range items { fmt.Printf("%d: %q\n", i, item.Href) if item.IsDir() { directories++ } else { files++ } } fmt.Printf("items: %d directories: %d files: %d\n", len(items), directories, files) }
Output: 0: "/h5ai/demo/file%20preview/" 1: "/h5ai/demo/file preview/class_cli.py" 2: "/h5ai/demo/file preview/image-1.jpg" 3: "/h5ai/demo/file preview/image-2.jpg" 4: "/h5ai/demo/file preview/image-3.jpg" 5: "/h5ai/demo/file preview/modulejs-1.14.0.js" 6: "/h5ai/demo/file preview/options.css" 7: "/h5ai/demo/file preview/text.md" items: 8 directories: 1 files: 7
Index ¶
- func Get(ctx context.Context, urlstr string, opts ...Option) ([]byte, error)
- func Walk(ctx context.Context, urlstr string, f WalkFunc, opts ...Option) error
- type Client
- func (cl *Client) BuildRequest(method, urlstr string, body io.Reader) (*http.Request, error)
- func (cl *Client) Do(ctx context.Context, method, urlstr string, request, v interface{}) error
- func (cl *Client) Get(ctx context.Context, urlstr string) ([]byte, error)
- func (cl *Client) Href(paths ...string) (string, string, error)
- func (cl *Client) Items(ctx context.Context, paths ...string) ([]Item, error)
- func (cl *Client) JoinGet(ctx context.Context, paths ...string) ([]byte, error)
- func (cl *Client) List(ctx context.Context, paths ...string) ([]Item, error)
- func (cl *Client) Walk(ctx context.Context, root string, fn WalkFunc) error
- type Error
- type Item
- type Option
- type Time
- type WalkFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct { URL string UserAgent string Transport http.RoundTripper Jar http.CookieJar // contains filtered or unexported fields }
Client is a h5ai client.
func (*Client) BuildRequest ¶
BuildRequest builds a http request.
type Item ¶
type Item struct { Fetched bool `json:"fetched,omitempty"` Href string `json:"href,omitempty"` Managed bool `json:"managed,omitempty"` Size *int64 `json:"size,omitempty"` Time Time `json:"time,omitempty"` URL string `json:"-"` }
Item is a item.
type Option ¶
type Option func(*Client)
Option is a client option.
func WithHTTPClient ¶
WithHTTPClient is a client option to set the underlying http.Client used.
func WithTransport ¶
func WithTransport(transport http.RoundTripper) Option
WithTransport is a client option to set the transport.
func WithUserAgent ¶
WithUserAgent is a client option to set the transport.
type Time ¶
Time is a wrapped time.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface.
Click to show internal directories.
Click to hide internal directories.