files

package
v2.214.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 12 Imported by: 12

README

Static File Upload Client

Usage

Setup

Local:

c := files.NewAPIClient("http://localhost:26900")

If using a healthcheck client, it can be instantiated as follows:

import "github.com/ONSdigital/dp-api-clients-go/v2/health"

hcClient := health.NewClient("api-router", "http://localhost:26900")
c := files.NewWithHealthClient(hcClient)
c.Version = "v1"

Here you will notice that the version has been set for the files client. This is important as it will prepend this to GetFile requests. I.e. /{.Version}/files/*.

Remote:

c := files.NewAPIClient("http://localhost:12700")
Set collection ID
err := c.SetCollectionID(context.Background(), "testing/test.txt", "123456789")

if err != nil {
	...
}
Publish Collection
err := c.PublishCollection(context.Background(), "123456789")

if err != nil {
    ...
}
Get File by Path
result, err := client.GetFile(context.Background(), "test/testing.csv", "AUTH TOKEN")

if err != nil {
    ...
}

if result.IsPublshable {
	...
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotFound            = errors.New("file not found on dp-files-api")
	ErrFileAlreadyInCollection = errors.New("file collection ID already set")
	ErrNoFilesInCollection     = errors.New("no file in the collection")
	ErrInvalidState            = errors.New("file is in an invalid state for this action")
	ErrNotPublishable          = errors.New("file is not set as publishable")
	ErrNotAuthorized           = errors.New("you are not authorized for this action")
	ErrServer                  = errors.New("internal server error")
	ErrUnexpectedStatus        = errors.New("unexpected response status code")
	ErrBadRequest              = errors.New("bad request")
	ErrFileAlreadyRegistered   = fmt.Errorf("%w: file already registered", ErrBadRequest)
	ErrValidationError         = fmt.Errorf("%w: validation error", ErrBadRequest)
	ErrUnknown                 = fmt.Errorf("%w: unknown error", ErrBadRequest)
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Version string
	// contains filtered or unexported fields
}

Client is an files API client which can be used to make requests to the server. It extends the generic healthcheck Client structure.

func NewAPIClient

func NewAPIClient(filesAPIURL, authToken string) *Client

NewAPIClient creates a new instance of files Client with a given image API URL

func NewWithHealthClient added in v2.132.0

func NewWithHealthClient(hcCli *healthcheck.Client) *Client

NewWithHealthClient creates a new instances of files Client using healthcheck client

func (*Client) Checker

func (c *Client) Checker(ctx context.Context, check *health.CheckState) error

Checker calls image api health endpoint and returns a check object to the caller.

func (*Client) GetFile added in v2.127.0

func (c *Client) GetFile(ctx context.Context, path string, authToken string) (FileMetaData, error)

func (*Client) MarkFileDecrypted added in v2.162.0

func (c *Client) MarkFileDecrypted(ctx context.Context, path string, etag string) error

func (*Client) MarkFilePublished added in v2.162.0

func (c *Client) MarkFilePublished(ctx context.Context, path string, etag string) error

func (*Client) MarkFileUploaded added in v2.162.0

func (c *Client) MarkFileUploaded(ctx context.Context, path string, etag string) error

func (*Client) PatchFile added in v2.162.0

func (c *Client) PatchFile(ctx context.Context, path string, patch FilePatch) error

func (*Client) PublishCollection

func (c *Client) PublishCollection(ctx context.Context, collectionID string) error

func (*Client) RegisterFile added in v2.162.0

func (c *Client) RegisterFile(ctx context.Context, metadata FileMetaData) error

func (*Client) SetCollectionID

func (c *Client) SetCollectionID(ctx context.Context, filepath, collectionID string) error

type FileMetaData added in v2.127.0

type FileMetaData struct {
	Path          string  `json:"path"`
	IsPublishable bool    `json:"is_publishable"`
	CollectionID  *string `json:"collection_id,omitempty"`
	Title         string  `json:"title"`
	SizeInBytes   uint64  `json:"size_in_bytes"`
	Type          string  `json:"type"`
	Licence       string  `json:"licence"`
	LicenceUrl    string  `json:"licence_url"`
	State         string  `json:"state,omitempty"`
	Etag          string  `json:"etag,omitempty"`
}

type FilePatch added in v2.162.0

type FilePatch struct {
	State        string `json:"state,omitempty"`
	ETag         string `json:"etag,omitempty"`
	CollectionID string `json:"collection_id,omitempty"`
}

Jump to

Keyboard shortcuts

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