Help us shape the future of Go! Take the 2026 Go Developer Survey

orgshare

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package orgshare plans organization file sharing without touching Git or LFS paths.

Index

Constants

View Source
const (
	// DefaultMaxBytes is the per-organization share cap, 100 GiB.
	DefaultMaxBytes int64 = 100 << 30
	// DefaultMaxFileBytes leaves room for a language or IDE installer inside that cap.
	DefaultMaxFileBytes int64 = 32 << 30
	// DefaultExpireDays removes a new object after 30 days unless it is marked permanent.
	DefaultExpireDays = 30
	// DefaultReserveBytes stays free on the share volume so the disk is not filled to zero.
	DefaultReserveBytes int64 = 1 << 30
	DefaultParallel           = 4
	MaxParallel               = 8
	DefaultChunkBytes   int64 = 8 << 20
	MaxChunkBytes       int64 = 32 << 20
)

Variables

View Source
var MeasureVolume = measureVolume

MeasureVolume reads free space for path. Tests may replace it.

Functions

func Admit

func Admit(input AdmitInput) error

Admit rejects an upload that would pass the organization cap or the disk reserve.

func CanDelete

func CanDelete(isOwner, isUploader bool) bool

CanDelete allows the uploader and organization owners to remove one object.

func CanRead

func CanRead(isMember bool) bool

CanRead is true for organization members.

func CanWrite

func CanWrite(isMember bool) bool

CanWrite is true for organization members.

func CheckQuota

func CheckQuota(input QuotaInput) error

CheckQuota rejects an object that would pass the organization or file cap.

func CleanJoin

func CleanJoin(parts []string) string

CleanJoin joins safe parts. The caller must pass parts from SafeParts.

func CoveredBytes

func CoveredBytes(spans []Span) int64

CoveredBytes is the number of bytes contained in spans.

func Deadline

func Deadline(now time.Time, days int, permanent bool) time.Time

Deadline returns when a new object expires. Permanent objects and a non-positive day count do not expire.

func Expired

func Expired(deadline, now time.Time) bool

Expired reports whether a stored deadline has passed. A zero deadline never expires.

func Expiry

func Expiry(now time.Time, days int) time.Time

Expiry returns the deadline for a new object. Zero days means it does not expire.

func NormalizeChunk

func NormalizeChunk(n int64) int64

NormalizeChunk clamps one request body. Zero uses the default.

func NormalizeParallel

func NormalizeParallel(n int) int

NormalizeParallel clamps a worker count.

func Open

func Open(filePath string) (*os.File, error)

Open returns the stored object for streaming. The caller closes it.

func Reserve

func Reserve(filePath string, size int64) (bool, error)

Reserve creates the upload file and asks the filesystem to keep size bytes when it can. The boolean is false when the file is only sparse, so later chunks must recheck free space.

func SafeParts

func SafeParts(raw string) ([]string, error)

SafeParts splits a relative upload path and rejects escapes.

func WriteAt

func WriteAt(filePath string, offset int64, data []byte) (int64, error)

WriteAt writes one chunk at an arbitrary offset.

func WriteAtReader

func WriteAtReader(filePath string, offset int64, r io.Reader, length int64) error

WriteAtReader writes length bytes from r at offset. The offset does not have to match the current size, so several chunks of one upload can land at the same time.

Types

type AdmitInput

type AdmitInput struct {
	Used      int64
	Incoming  int64
	MaxBytes  int64
	MaxFile   int64
	Available int64
	Reserve   int64
	DiskKnown bool
}

AdmitInput is the quota and disk check performed before bytes are accepted.

type ContentRange

type ContentRange struct {
	Start int64
	End   int64
	Total int64
}

ContentRange is an inclusive byte range.

func ParseContentRange

func ParseContentRange(header string) (ContentRange, error)

ParseContentRange reads "bytes START-END/TOTAL". The end byte is inclusive.

func (ContentRange) Length

func (r ContentRange) Length() int64

Length is the number of bytes in the inclusive range.

type HTTPClient

type HTTPClient struct {
	Client    *http.Client
	BaseURL   string
	Token     string
	Parallel  int
	ChunkSize int64
}

HTTPClient uploads and downloads share objects with parallel byte ranges.

func (HTTPClient) GetFile

func (c HTTPClient) GetFile(ctx context.Context, fileURL, dest string) error

GetFile downloads url with parallel Range requests into dest.

func (HTTPClient) PutFile

func (c HTTPClient) PutFile(ctx context.Context, filePath, name string, permanent bool) (HTTPItem, error)

PutFile splits a local file into chunks and uploads them concurrently.

type HTTPItem

type HTTPItem struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
	Size int64  `json:"size"`
	Link string `json:"link"`
}

HTTPItem is one object created by PutFile.

type LimitError

type LimitError struct {
	Code      string
	Used      int64
	Limit     int64
	Incoming  int64
	Available int64
	Reserve   int64
}

LimitError is a refusal that happened before any new chunk was stored.

func (*LimitError) Error

func (e *LimitError) Error() string

type QuotaInput

type QuotaInput struct {
	Used     int64
	Incoming int64
	MaxBytes int64
	MaxFile  int64
}

QuotaInput is the size check before a new object is accepted.

type Span

type Span struct {
	Start int64 `json:"start"`
	End   int64 `json:"end"`
}

Span is a half-open byte interval [Start, End).

func AddSpan

func AddSpan(spans []Span, start, end int64) ([]Span, error)

AddSpan merges a chunk into the covered set. A chunk that is already covered is ignored so a retry can be repeated. A partial overlap is rejected so two writers cannot tear the same bytes.

func Missing

func Missing(spans []Span, size int64) []Span

Missing returns the gaps before size. The result is empty when the file is complete.

func PlanChunks

func PlanChunks(size, chunk int64) []Span

PlanChunks splits size into chunks of chunk bytes. The last chunk is shorter.

type Volume

type Volume struct {
	CapacityBytes  int64
	AvailableBytes int64
}

Volume is the filesystem that holds organization share bytes.

Jump to

Keyboard shortcuts

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