mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-14 11:44:42 +00:00
187 lines
3.5 KiB
Markdown
Executable File
187 lines
3.5 KiB
Markdown
Executable File
# Space
|
|
|
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Space/api](https://m3o.com/Space/api).
|
|
|
|
Endpoints:
|
|
|
|
## Create
|
|
|
|
Create an object. Returns error if object with this name already exists. If you want to update an existing object use the `Update` endpoint
|
|
You need to send the request as a multipart/form-data rather than the usual application/json
|
|
with each parameter as a form field.
|
|
|
|
|
|
[https://m3o.com/space/api#Create](https://m3o.com/space/api#Create)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/space"
|
|
)
|
|
|
|
// Create an object. Returns error if object with this name already exists. If you want to update an existing object use the `Update` endpoint
|
|
// You need to send the request as a multipart/form-data rather than the usual application/json
|
|
// with each parameter as a form field.
|
|
func CreateAnObject() {
|
|
spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := spaceService.Create(&space.CreateRequest{
|
|
Name: "images/file.jpg",
|
|
Object: "<file bytes>",
|
|
Visibility: "public",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## Update
|
|
|
|
Update an object. If an object with this name does not exist, creates a new one.
|
|
You need to send the request as a multipart/form-data rather than the usual application/json
|
|
with each parameter as a form field.
|
|
|
|
|
|
[https://m3o.com/space/api#Update](https://m3o.com/space/api#Update)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/space"
|
|
)
|
|
|
|
// Update an object. If an object with this name does not exist, creates a new one.
|
|
// You need to send the request as a multipart/form-data rather than the usual application/json
|
|
// with each parameter as a form field.
|
|
func UpdateAnObject() {
|
|
spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := spaceService.Update(&space.UpdateRequest{
|
|
Name: "images/file.jpg",
|
|
Object: "<file bytes>",
|
|
Visibility: "public",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## Delete
|
|
|
|
Delete an object from space
|
|
|
|
|
|
[https://m3o.com/space/api#Delete](https://m3o.com/space/api#Delete)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/space"
|
|
)
|
|
|
|
// Delete an object from space
|
|
func DeleteAnObject() {
|
|
spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := spaceService.Delete(&space.DeleteRequest{
|
|
Name: "images/file.jpg",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## List
|
|
|
|
List the objects in space
|
|
|
|
|
|
[https://m3o.com/space/api#List](https://m3o.com/space/api#List)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/space"
|
|
)
|
|
|
|
// List the objects in space
|
|
func ListObjectsWithPrefix() {
|
|
spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := spaceService.List(&space.ListRequest{
|
|
Prefix: "images/",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## Head
|
|
|
|
Retrieve meta information about an object
|
|
|
|
|
|
[https://m3o.com/space/api#Head](https://m3o.com/space/api#Head)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/space"
|
|
)
|
|
|
|
// Retrieve meta information about an object
|
|
func HeadAnObject() {
|
|
spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := spaceService.Head(&space.HeadRequest{
|
|
Name: "images/file.jpg",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## Read
|
|
|
|
Read an object in space. Use for private objects.
|
|
|
|
|
|
[https://m3o.com/space/api#Read](https://m3o.com/space/api#Read)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/space"
|
|
)
|
|
|
|
// Read an object in space. Use for private objects.
|
|
func ReadAnObject() {
|
|
spaceService := space.NewSpaceService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := spaceService.Read(&space.ReadRequest{
|
|
Name: "images/file.jpg",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|