originFSKit

package module
v0.0.0-...-6363e36 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 16 Imported by: 0

README

OriginFSKit API Reference

Go client for OriginFS file system at https://api.rotur.dev

Quick Start

client := originFSKit.NewClient("your-token")
client.CreateFile("/file.txt", "content")
client.Commit() // Required to push changes to the account

Types

FileEntry []any

Array with 14 elements containing file/folder metadata.

Index Constant Type Description
0 IdxType string Extension or ".folder"
1 IdxName string Name without extension
2 IdxLocation string Parent directory path
3 IdxData string/[]any Content or children
8 IdxCreated int64 Unix timestamp (ms)
9 IdxEdited int64 Unix timestamp (ms)
11 IdxSize int Bytes
13 IdxUUID string Unique identifier
Client struct

Thread-safe client with local caching. All write operations are batched until Commit().


Initialization

NewClient(token string) *Client

Creates client with 30s timeout.


File Operations

ReadFile(p string) (FileEntry, error)

Returns complete entry with metadata and content.

ReadFileContent(p string) (string, error)

Returns only file content as string.

WriteFile(p string, data string) error

Updates existing file. Auto-updates edited time and size. Requires Commit().

CreateFile(p string, data string) error

Creates new file. Auto-creates parent directories. Requires Commit().

Remove(p string) error

Deletes file or folder. Requires Commit().

Rename(oldPath, newPath string) error

Moves/renames file or folder. Requires Commit().

Exists(p string) bool

Checks if path exists.


Directory Operations

CreateFolder(p string) error

Creates folder. Auto-creates parents. Requires Commit().

ListDir(p string) []string

Returns immediate children names (not full paths).

ListPaths() ([]string, error)

Returns all paths in file system.


Path Utilities

JoinPath(elem ...string) string

Joins and normalizes path (lowercase, leading slash).

GetUuid(p string) (string, error)

Returns UUID for path.

GetPath(uuid string) (string, error)

Returns path for UUID.

StatUUID(uuid string) (FileEntry, error)

Returns entry metadata by UUID.


Synchronization

Commit() error

Persists all pending changes to server. Must be called after writes, creates, deletes, or renames.


Common Patterns

// Read
content, _ := client.ReadFileContent("/file.txt")

// Write (requires commit)
client.WriteFile("/file.txt", "new content")
client.Commit()

// Create (requires commit)
client.CreateFile("/new.txt", "data")
client.Commit()

// Batch operations
client.CreateFolder("/backup")
client.CreateFile("/backup/1.txt", "data1")
client.CreateFile("/backup/2.txt", "data2")
client.Commit() // Single commit for all

// Check existence
if client.Exists("/file.txt") {
    client.Remove("/file.txt")
    client.Commit()
}

// Directory listing
children := client.ListDir("/documents")
for _, child := range children {
    path := client.JoinPath("/documents", child)
    // ...
}

// Access metadata
entry, _ := client.ReadFile("/file.txt")
name := entry[IdxName].(string)
size := entry[IdxSize].(int)
created := entry[IdxCreated].(int64)

Key Behaviors

  • Paths: Case-insensitive, normalized to lowercase, auto-prefixed with /
  • Caching: Index loaded lazily on first use, entries cached locally
  • Batching: All writes batched until Commit() called
  • Thread-safety: Mutex-protected, safe for concurrent use
  • Timeouts: 30-second HTTP timeout on all requests
  • Auto-creation: Parent directories created automatically for files/folders

Documentation

Index

Constants

View Source
const (
	IdxType     = 0
	IdxName     = 1
	IdxLocation = 2
	IdxData     = 3
	IdxCreated  = 8
	IdxEdited   = 9
	IdxSize     = 11
	IdxUUID     = 13
)
View Source
const BaseURL = "https://api.rotur.dev"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Token string
	HTTP  *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(token string) *Client

func (*Client) Commit

func (c *Client) Commit() error

func (*Client) CreateFile

func (c *Client) CreateFile(p string, data string) error

func (*Client) CreateFolder

func (c *Client) CreateFolder(p string) error

func (*Client) Exists

func (c *Client) Exists(p string) bool

func (*Client) GetPath

func (c *Client) GetPath(uuid string) (string, error)

func (*Client) GetUuid

func (c *Client) GetUuid(p string) (string, error)

func (*Client) JoinPath

func (c *Client) JoinPath(elem ...string) string

func (*Client) ListDir

func (c *Client) ListDir(p string) []string

func (*Client) ListPaths

func (c *Client) ListPaths() ([]string, error)

func (*Client) ReadFile

func (c *Client) ReadFile(p string) (FileEntry, error)

func (*Client) ReadFileContent

func (c *Client) ReadFileContent(p string) (string, error)

func (*Client) Remove

func (c *Client) Remove(p string) error

func (*Client) Rename

func (c *Client) Rename(oldPath, newPath string) error

func (*Client) StatUUID

func (c *Client) StatUUID(uuid string) (FileEntry, error)

func (*Client) WriteFile

func (c *Client) WriteFile(p string, data string) error

type FileEntry

type FileEntry []any

type GetFilesRequest

type GetFilesRequest struct {
	UUIDs []string `json:"uuids"`
}

type GetFilesResponse

type GetFilesResponse struct {
	Files map[string]FileEntry `json:"files"`
}

type UpdateChange

type UpdateChange struct {
	Command string `json:"command"`
	UUID    string `json:"uuid"`
	Dta     any    `json:"dta,omitempty"`
	Idx     any    `json:"idx,omitempty"`
}

type UpdateFileRequest

type UpdateFileRequest struct {
	Updates []UpdateChange `json:"updates"`
}

type UpdateResult

type UpdateResult struct {
	Payload string `json:"payload"`
}

Jump to

Keyboard shortcuts

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