Skip to main content
client := rest.NewClient(os.Getenv("SQUARECLOUD_API_KEY"))
defer client.Close()

api := rest.New(client)

Listing files in a directory

api.GetApplicationFiles(appID, path) returns the entries of a directory as a []squarecloud.FileInfo. An empty path lists the application root.
entries, err := api.GetApplicationFiles("abc123def456abc123def456", "")
if err != nil {
	panic(err)
}

for _, entry := range entries {
	fmt.Println(entry.Type, entry.Name, entry.Size, entry.LastModified)
}
FieldTypeDescription
Typestring"file" or "directory"
NamestringEntry name
SizeintSize in bytes — always 0 for directories
LastModifiedint64Last modification in Unix milliseconds

Reading a file

api.ReadApplicationFile(appID, path) returns a squarecloud.FileContent with the file bytes.
content, err := api.ReadApplicationFile("abc123def456abc123def456", "main.go")
if err != nil {
	panic(err)
}

fmt.Println(string(content.Data))
The API returns the content as a Node.js-style Buffer object ({"type": "Buffer", "data": [...]}). The SDK decodes it for you — content.Data is a plain []byte (the ByteArray type), ready to use.

Creating or overwriting a file

api.PutApplicationFile(appID, path, content) writes content at path, creating the file if it does not exist or overwriting it if it does. It returns a squarecloud.FileWritten.
written, err := api.PutApplicationFile(
	"abc123def456abc123def456",
	"config/settings.json",
	[]byte(`{"debug": false}`),
)
if err != nil {
	panic(err)
}

fmt.Println(written.Written) // true
The content is sent to the API as a UTF-8 string — binary file uploads are not supported yet. To ship binary files, use a commit instead.

Moving or renaming a file

api.MoveApplicationFile(appID, path, to) moves or renames a file.
err := api.MoveApplicationFile("abc123def456abc123def456", "main.go", "src/main.go")
if err != nil {
	panic(err)
}

Deleting a file or directory

Deleting a directory removes everything inside it. There is no way to recover deleted files unless you have a snapshot.
err := api.DeleteApplicationFile("abc123def456abc123def456", "src/old.go")
if err != nil {
	panic(err)
}