api

package
v0.0.0-...-ae31a8f Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package api provides interfaces to interact with external services.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongGeneration = errors.New("wrong generation")
	ErrNotFound        = errors.New("not found")

	ErrUnauthorized = errors.New("401 Unauthorized")
	ErrConflict     = errors.New("409 Conflict")
)

Functions

func AuthenticateHTTP

func AuthenticateHTTP(httpClientCtx *HTTPClientCtx, reAuth bool) error

func ClearTokens

func ClearTokens() error

func CreateCacheTree

func CreateCacheTree(blobStorage BlobEMConfigHolder) (*sync15.HashTree, error)

func GetNodeByPath

func GetNodeByPath(blobStorage BlobEMConfigHolder, path string) (*model.Node, error)

func GetNodeByPathFromCache

func GetNodeByPathFromCache(ct *sync15.HashTree, path string) (*model.Node, error)

func LoadTokens

func LoadTokens() (*authToken, error)

func SaveTree

func SaveTree(tree *sync15.HashTree) error

Types

type AuthType

type AuthType int
const (
	EmptyBearer AuthType = iota
	DeviceBearer
	UserBearer

	HeaderGeneration = "x-goog-generation"
	EmptyBody        = ""
)

type BlobEMConfigHolder

type BlobEMConfigHolder interface {
	model.EMConfigHolder
	GetBlobStorage() *BlobStorage
}

type BlobStorage

type BlobStorage struct {
	// contains filtered or unexported fields
}

func NewBlobStorage

func NewBlobStorage(http *HTTPClientCtx) *BlobStorage

func (*BlobStorage) GetBlobStorage

func (b *BlobStorage) GetBlobStorage() *BlobStorage

GetBlobStorage returns the BlobStorage instance and implements the BlobEMContextStorer interface

func (*BlobStorage) GetEMConfig

func (b *BlobStorage) GetEMConfig() (*model.EMConfig, error)

GetEMConfig returns the EMConfig and implements the BlobEMContextStorer interface

func (*BlobStorage) GetReader

func (b *BlobStorage) GetReader(hash string) (io.ReadCloser, error)

func (*BlobStorage) GetRootIndex

func (b *BlobStorage) GetRootIndex() (string, int64, error)

func (*BlobStorage) GetURL

func (b *BlobStorage) GetURL(hash string) (string, error)

func (*BlobStorage) GetURLProvider

func (b *BlobStorage) GetURLProvider() (model.URLProvider, error)

GetURLProvider returns the URLProvider and implements the URLProviderHolder interface

type BodyString

type BodyString struct {
	Content string
}

type DocumentFetcher

type DocumentFetcher struct {
	// contains filtered or unexported fields
}

func (*DocumentFetcher) Fetch

func (d *DocumentFetcher) Fetch(docID, dstPath string) error

type Fetcher

type Fetcher interface {
	Fetch(docID, dstPath string) error
}

func NewDocumentFetcher

func NewDocumentFetcher(blobStorage *BlobStorage, hashTree *sync15.HashTree) Fetcher

type HTTPClientCtx

type HTTPClientCtx struct {
	Client  *http.Client
	Token   *authToken
	Context context.Context
}

func CreateHTTPClientCtx

func CreateHTTPClientCtx(token *authToken, ctx context.Context) (*HTTPClientCtx, error)

func EnsureAuthenticated

func EnsureAuthenticated(ctx context.Context) (*HTTPClientCtx, error)

EnsureAuthenticated ensures that the tokens are loaded, valid, and not expired. If the tokens are missing or expired, it re-authenticates.

func (HTTPClientCtx) Delete

func (ctx HTTPClientCtx) Delete(authType AuthType, url string, reqBody, resp interface{}) error

func (HTTPClientCtx) Get

func (ctx HTTPClientCtx) Get(authType AuthType, url string, body interface{}, target interface{}) error

func (HTTPClientCtx) GetBlobStream

func (ctx HTTPClientCtx) GetBlobStream(url string) (io.ReadCloser, int64, error)

func (*HTTPClientCtx) GetEMConfig

func (ctx *HTTPClientCtx) GetEMConfig() (*model.EMConfig, error)

func (HTTPClientCtx) GetStream

func (ctx HTTPClientCtx) GetStream(authType AuthType, url string) (io.ReadCloser, error)

func (*HTTPClientCtx) GetURLProvider

func (ctx *HTTPClientCtx) GetURLProvider() (model.URLProvider, error)

func (HTTPClientCtx) Post

func (ctx HTTPClientCtx) Post(authType AuthType, url string, reqBody, resp interface{}) error

func (HTTPClientCtx) Put

func (ctx HTTPClientCtx) Put(authType AuthType, url string, reqBody, resp interface{}) error

func (HTTPClientCtx) PutStream

func (ctx HTTPClientCtx) PutStream(authType AuthType, url string, reqBody io.Reader) error

func (HTTPClientCtx) Request

func (ctx HTTPClientCtx) Request(authType AuthType, verb, url string, body io.Reader) (*http.Response, error)

type UserTokenJWT

type UserTokenJWT struct {
	Auth0 struct {
		UserID string
		Email  string
	} `json:"auth0-profile"`
	Scopes string
	*jwt.StandardClaims
}

Jump to

Keyboard shortcuts

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