Documentation
¶
Index ¶
- Constants
- Variables
- func FilterKeep(objs []s2.Object) []s2.Object
- func RegisterHandleFunc(pattern string, handler HandlerFunc)
- func RegisterTemplate(name string)
- func Run(args []string) error
- type Buckets
- func (bs *Buckets) Create(ctx context.Context, name string) error
- func (bs *Buckets) CreateFolder(ctx context.Context, bucket, key string) error
- func (bs *Buckets) CreatedAt(ctx context.Context, name string) time.Time
- func (bs *Buckets) Delete(ctx context.Context, name string) error
- func (bs *Buckets) Exists(name string) (bool, error)
- func (bs *Buckets) Get(ctx context.Context, name string) (s2.Storage, error)
- func (bs *Buckets) Names() ([]string, error)
- type Config
- type ErrBucketNotFound
- type Flags
- type HandlerFunc
- type Server
Constants ¶
const ( EnvS2ServerConfig = "S2_SERVER_CONFIG" EnvS2ServerListen = "S2_SERVER_LISTEN" EnvS2ServerType = "S2_SERVER_TYPE" EnvS2ServerRoot = "S2_SERVER_ROOT" EnvS2ServerMaxUploadSize = "S2_SERVER_MAX_UPLOAD_SIZE" EnvS2ServerMaxPreviewSize = "S2_SERVER_MAX_PREVIEW_SIZE" EnvS2ServerUser = "S2_SERVER_USER" EnvS2ServerPassword = "S2_SERVER_PASSWORD" // #nosec G101 -- env var name, not a credential EnvS2ServerBuckets = "S2_SERVER_BUCKETS" )
const ( DefaultMaxUploadSize = 5 << 30 // 5 GiB — default for osfs/s3 backends. DefaultMemfsMaxUploadSize = 16 << 20 // 16 MiB — conservative default for the in-memory backend. DefaultMaxPreviewSize = 10 << 20 // 10 MiB )
Variables ¶
var DefaultRoot = "data"
DefaultRoot is the default storage root path used by DefaultConfig when the user does not supply one via -root, -f, or S2_SERVER_ROOT.
It is intentionally a var (not a const) so that binaries can be built with a different default via linker flags, matching the same idiom used for version injection:
go build -ldflags "-X github.com/mojatter/s2/server.DefaultRoot=/var/lib/s2" ./cmd/s2-server
This lets the stock "go install" binary default to a relative "data" directory (so a new user can run s2-server in any directory and immediately see where data lands) while the Docker image is built with /var/lib/s2 baked in.
var StaticFS embed.FS
Functions ¶
func FilterKeep ¶
FilterKeep removes .keep marker files from a list of objects.
func RegisterHandleFunc ¶
func RegisterHandleFunc(pattern string, handler HandlerFunc)
func RegisterTemplate ¶
func RegisterTemplate(name string)
Types ¶
type Buckets ¶
type Buckets struct {
// contains filtered or unexported fields
}
func (*Buckets) CreateFolder ¶
type Config ¶
type Config struct {
s2.Config
// Listen is the address to listen on.
Listen string `json:"listen"`
// MaxUploadSize is the maximum upload size in bytes. When 0, a backend-specific
// default is used (see EffectiveMaxUploadSize): 5 GiB for osfs/s3, 16 MiB for
// memfs. The conservative memfs default protects the host from accidental
// OOM when a large upload targets the in-memory backend; set an explicit
// value here to override.
MaxUploadSize int64 `json:"max_upload_size"`
// MaxPreviewSize is the maximum file size for text preview in bytes (0 = default 10MB).
MaxPreviewSize int64 `json:"max_preview_size"`
// User is the username for authentication (Basic Auth for Web Console, Access Key ID for S3 API).
// When empty, authentication is disabled.
User string `json:"user"`
// Password is the password for authentication (Basic Auth password for Web Console, Secret Access Key for S3 API).
Password string `json:"password"`
// Buckets is a list of bucket names to create on startup if they don't already exist.
Buckets []string `json:"buckets"`
}
Config is a configuration for the server.
func DefaultConfig ¶
func DefaultConfig() *Config
func (*Config) EffectiveMaxUploadSize ¶ added in v0.2.0
EffectiveMaxUploadSize returns the upload size limit to enforce for this configuration. When MaxUploadSize is explicitly set (> 0) it is returned as-is; otherwise a backend-specific default is chosen so that switching Type to memfs does not silently inherit the 5 GiB default.
type ErrBucketNotFound ¶
type ErrBucketNotFound struct {
Name string
}
ErrBucketNotFound is returned when a bucket does not exist.
func (*ErrBucketNotFound) Error ¶
func (e *ErrBucketNotFound) Error() string
type Flags ¶
type Flags struct {
// contains filtered or unexported fields
}
Flags holds the parsed command-line arguments for s2-server. Pointer-typed fields distinguish "explicitly set" from "left at default"; only explicitly set flags override values loaded from file/env.
type HandlerFunc ¶
type HandlerFunc func(srv *Server, w http.ResponseWriter, r *http.Request)
type Server ¶
type Server struct {
Config *Config
Template *template.Template
Buckets *Buckets
StartedAt time.Time // server start time, used as epoch for upload ID generation
}
Server is a web server that provides a Web Console and S3-compatible API for S2.