helper

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package helper exposes the service-scoped S3MinIO SDK contracts.

Index

Constants

View Source
const CodeOK uint32 = 0

CodeOK is the gRPC status code for success (google.golang.org/grpc/codes.OK == 0).

Variables

View Source
var (
	ErrNilDownloadResponse = errors.New("s3minio download response is nil")
	ErrNilUploadResponse   = errors.New("s3minio upload response is nil")
	ErrNilUploadData       = errors.New("s3minio upload response data is nil")
	ErrNilHealthResponse   = errors.New("s3minio health response is nil")
	ErrNilReadyResponse    = errors.New("s3minio ready response is nil")
	ErrNilFileResponse     = errors.New("s3minio download file response is nil")
)
View Source
var ProbeObserveFunc func(started time.Time, probeName string, transport string, code uint32)

ProbeObserveFunc is an optional hook for health/readiness probe latency and outcomes. Services may assign this at init (e.g. to emit metrics or structured logs) without importing the concrete gRPC adapter. When nil, probes incur no extra work.

Functions

func GetPresignedURL

func GetPresignedURL(ctx context.Context, d Downloader, object string, userID, merchantID int64, args ...interface{}) (string, error)

func GetViewURL

func GetViewURL(ctx context.Context, v Viewer, object string, userID, merchantID int64, args ...interface{}) (string, error)

func ObserveProbe

func ObserveProbe(started time.Time, probeName, transport string, code uint32) error

ObserveProbe invokes ProbeObserveFunc when set. Always returns nil so adapters keep a stable (result, error) signature for Health/Ready.

Types

type Client

Client groups all supported S3MinIO helper capabilities.

type DownloadRequest

type DownloadRequest struct {
	Object     string
	Path       string
	Bucket     string
	Expires    int32
	UserID     int64
	MerchantID int64
}

DownloadRequest mirrors common s3minio DownloadRequest fields used by PayCloud services.

func BuildDownloadRequest

func BuildDownloadRequest(object string, userID, merchantID int64, args ...interface{}) DownloadRequest

BuildDownloadRequest builds a download/presigned request from object, ids, and optional args. args[0]: path string; args[1]: bucket string; args[2]: expires int (>0).

type DownloadResponse

type DownloadResponse struct {
	Code    uint32
	Status  string
	Message string
	Data    string
}

DownloadResponse mirrors a unary Download RPC result (code/message/data).

type Downloader

type Downloader interface {
	Download(ctx context.Context, req *DownloadRequest) (*DownloadResponse, error)
}

Downloader abstracts the download/presigned operation.

type FileDownloadResponse

type FileDownloadResponse struct {
	Code        uint32
	Message     string
	Status      string
	Data        []byte
	ContentType string
	Filename    string
}

FileDownloadResponse represents HTTP download-file style payload.

type FileDownloader

type FileDownloader interface {
	DownloadFile(ctx context.Context, req *DownloadRequest) (*FileDownloadResponse, error)
}

FileDownloader abstracts download_file behavior.

type HealthProber

type HealthProber interface {
	Health(ctx context.Context, req *HealthRequest) (*HealthResponse, error)
}

HealthProber abstracts service liveness checks.

type HealthRequest

type HealthRequest struct{}

HealthRequest is a transport-neutral liveness probe request.

func BuildHealthRequest

func BuildHealthRequest() HealthRequest

BuildHealthRequest returns a default health probe request.

type HealthResponse

type HealthResponse struct {
	Code    uint32
	Message string
	Status  string
}

HealthResponse represents liveness output from a provider or adapter.

func CheckHealth

func CheckHealth(ctx context.Context, p HealthProber) (*HealthResponse, error)

type ReadinessProber

type ReadinessProber interface {
	Ready(ctx context.Context, req *ReadyRequest) (*ReadyResponse, error)
}

ReadinessProber abstracts dependency-readiness checks.

type ReadyRequest

type ReadyRequest struct{}

ReadyRequest is a transport-neutral readiness probe request.

func BuildReadyRequest

func BuildReadyRequest() ReadyRequest

BuildReadyRequest returns a default readiness probe request.

type ReadyResponse

type ReadyResponse struct {
	Code         uint32
	Message      string
	Status       string
	Dependencies map[string]string
}

ReadyResponse represents readiness output and optional dependency map.

func CheckReady

func CheckReady(ctx context.Context, p ReadinessProber) (*ReadyResponse, error)

type StreamViewer

type StreamViewer interface {
	View(ctx context.Context, req *ViewRequest) (*ViewResponse, error)
}

StreamViewer abstracts HTTP stream view behavior.

type UploadRequest

type UploadRequest struct {
	Filename    string
	Size        uint64
	ContentType string
	Content     []byte
	Bucket      string
	Path        string
	Expires     uint32
	UserID      int64
	MerchantID  int64
}

UploadRequest mirrors common s3minio UploadRequest fields.

func BuildUploadRequestForFile

func BuildUploadRequestForFile(userID, merchantID int64, path, fileLocation string, args ...interface{}) (UploadRequest, error)

BuildUploadRequestForFile reads a file from disk and builds an upload request. Optional args use the same convention as legacy merchant services: first string at index 0 is bucket; int at index 1 is expires.

func BuildUploadRequestForMultipart

func BuildUploadRequestForMultipart(userID, merchantID int64, path string, file multipart.File, fileHeader *multipart.FileHeader, args ...interface{}) (UploadRequest, error)

BuildUploadRequestForMultipart builds an upload request from a multipart file. args[0]: bucket string; args[1]: expires int (>0) as uint32.

type UploadResponse

type UploadResponse struct {
	Code    uint32
	Status  string
	Message string
	Data    *UploadResult
}

UploadResponse mirrors an Upload RPC result (code/message + optional data).

type UploadResult

type UploadResult struct {
	Filename     string
	URL          string
	PresignedURL string
}

UploadResult is the payload returned on successful upload.

func UploadByFile

func UploadByFile(ctx context.Context, u Uploader, userID, merchantID int64, path, fileLocation string, args ...interface{}) (*UploadResult, error)

func UploadByMultipart

func UploadByMultipart(ctx context.Context, u Uploader, userID, merchantID int64, path string, file multipart.File, fileHeader *multipart.FileHeader, args ...interface{}) (*UploadResult, error)

func UploadByRequest

func UploadByRequest(ctx context.Context, u Uploader, req *UploadRequest) (*UploadResult, error)

type Uploader

type Uploader interface {
	Upload(ctx context.Context, req *UploadRequest) (*UploadResponse, error)
}

Uploader abstracts the upload operation.

type ViewRequest

type ViewRequest struct {
	Path string
}

ViewRequest represents HTTP stream view request semantics.

func BuildViewRequest

func BuildViewRequest(path string) ViewRequest

BuildViewRequest builds a view-stream request from path.

type ViewResponse

type ViewResponse struct {
	Code        uint32
	Message     string
	Status      string
	Data        []byte
	ContentType string
}

ViewResponse represents HTTP stream view response semantics.

type Viewer

type Viewer interface {
	GenerateViewURL(ctx context.Context, req *DownloadRequest) (*DownloadResponse, error)
}

Viewer abstracts generate-view-url operation.

Jump to

Keyboard shortcuts

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