its

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

README

Go Storage Client

This is a simple cloud storage client made with Go.

Prerequisites

You need to have Go installed on your machine. You can download it here.

Installation

go get github.com/dptsi/go-storage

Usage

Using Base Go by DPTSI
// Instantiate storage client
config := storageapi.Config{
    ClientID:        os.Getenv("OIDC_CLIENT_ID"),
    ClientSecret:    os.Getenv("OIDC_CLIENT_SECRET"),
    OidcProviderURL: os.Getenv("OIDC_PROVIDER"),
    StorageApiURL:   os.Getenv("STORAGE_API_URL"),
}
storageApi, err := storageapi.NewStorageApi(ctx, config)

// Example upload file
r.POST("/ping", func(c *gin.Context) {
    file, err := c.FormFile("file")
    if err != nil {
        // Handle error
    }
    uploadResponse, err := storageApi.Upload(c, file)
    if err != nil {
        // Handle error
    }
    // Handle success
})

// Example get file
r.GET("/ping/:id", func(c *gin.Context) {
    id := c.Param("id")
    getFileByIdResponse, err := storageApi.Get(c, id)
    if err != nil {
        // Handle error
    }
    // Handle success
})

// Example delete file
r.DELETE("/ping/:id", func(c *gin.Context) {
    id := c.Param("id")
    deleteFileByIdResponse, err := storageApi.Delete(c, id)
    if err != nil {
        // Handle error
    }
    // Handle success
})

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

GNU GPLv3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ClientID is the application's ID.
	ClientID string

	// ClientSecret is the application's secret.
	ClientSecret string

	// OidcProviderURL is the OpenID Connect Provider's
	// URL. This is a constant specific to each server.
	OidcProviderURL string

	// StorageApiURL is the Storage API's URL.
	StorageApiURL string
}

type DeleteResponse

type DeleteResponse struct {
	FileID  string         `json:"file_id"`
	Info    FileInfo       `json:"info"`
	Message string         `json:"message,omitempty"`
	Status  responseStatus `json:"status"`
}

func (DeleteResponse) IsOk

func (u DeleteResponse) IsOk() bool

type FileInfo

type FileInfo struct {
	FileExt      string `json:"file_ext"`
	FileID       string `json:"file_id"`
	FileMimetype string `json:"file_mimetype"`
	FileName     string `json:"file_name"`
	FileSize     int    `json:"file_size"`
	PublicLink   string `json:"public_link"`
	Tag          string `json:"tag"`
	Timestamp    string `json:"timestamp"`
}

type GetResponse

type GetResponse struct {
	Data    string         `json:"data"`
	Info    FileInfo       `json:"info"`
	Message string         `json:"message,omitempty"`
	Status  responseStatus `json:"status"`
}

func (GetResponse) IsOk

func (u GetResponse) IsOk() bool

type StorageApi

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

func NewStorageApi

func NewStorageApi(ctx context.Context, config Config) (*StorageApi, error)

func (*StorageApi) Delete

func (s *StorageApi) Delete(ctx context.Context, fileId string) (DeleteResponse, error)

func (*StorageApi) Get

func (s *StorageApi) Get(ctx context.Context, fileId string) (GetResponse, error)

func (*StorageApi) Upload

func (s *StorageApi) Upload(ctx context.Context, fileHeader *multipart.FileHeader) (UploadResponse, error)

type UploadBody

type UploadBody struct {
	FileName      string `json:"file_name"`
	FileExt       string `json:"file_ext"`
	FileMimetype  string `json:"mime_type"`
	BinaryDataB64 string `json:"binary_data_b64"`
}

type UploadResponse

type UploadResponse struct {
	FileID  string         `json:"file_id"`
	Info    FileInfo       `json:"info"`
	Message string         `json:"message,omitempty"`
	Status  responseStatus `json:"status"`
}

func (UploadResponse) IsOk

func (u UploadResponse) IsOk() bool

Jump to

Keyboard shortcuts

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