Spin up instances in a capacity to use your available compute.
- List - List instances
- Create - Create instance
- Fetch - Get instance
- Delete - Delete instance
- GetLogsForInstance - Get instance logs
- GetSSHInfoForInstance - Get instance SSH info
- TerminateInstance - Terminate instance
List all instances.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Instances.List(ctx, operations.ListInstancesRequest{
Workspace: "wksp_k3R-nX9vLm7Qp2Yw5Jd8F",
ID: []string{
"i",
"n",
"s",
"t",
"_",
"k",
"3",
"R",
"-",
"n",
"X",
"9",
"v",
"L",
"m",
"7",
"Q",
"p",
"2",
"Y",
"w",
"5",
"J",
"d",
"8",
"F",
},
Capacity: sfc.Pointer("cap_k3R-nX9vLm7Qp2Yw5Jd8F"),
StartingAfter: sfc.Pointer("nodec_gqXR7s0Kj5mHvE2wNpLc4Q"),
EndingBefore: sfc.Pointer("nodec_gqXR7s0Kj5mHvE2wNpLc4Q"),
})
if err != nil {
log.Fatal(err)
}
if res.ListInstancesResponse != nil {
for {
// handle items
res, err = res.Next()
if err != nil {
// handle error
}
if res == nil {
break
}
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
operations.ListInstancesRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.ListInstancesResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Create an instance.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/optionalnullable"
"github.com/sfcompute/sfc-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Instances.Create(ctx, components.CreateInstanceRequest{
Name: optionalnullable.From(sfc.Pointer("my-resource-name")),
Capacity: "cap_k3R-nX9vLm7Qp2Yw5Jd8F",
Image: "image_k3R-nX9vLm7Qp2Yw5Jd8F",
CloudInitUserData: sfc.Pointer("IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo="),
Tags: optionalnullable.From(sfc.Pointer(map[string]string{
"env": "prod",
"team": "infra",
})),
})
if err != nil {
log.Fatal(err)
}
if res.InstanceResponse != nil {
switch res.InstanceResponse.Capacity.Type {
case components.ExpandableCapacityIDCapacitySummaryUnionTypeStr:
// res.InstanceResponse.Capacity.Str is populated
case components.ExpandableCapacityIDCapacitySummaryUnionTypeExpandableCapacityIDCapacitySummary:
// res.InstanceResponse.Capacity.ExpandableCapacityIDCapacitySummary is populated
default:
// Unknown type - use res.InstanceResponse.Capacity.GetUnknownRaw() for raw JSON
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.CreateInstanceRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CreateInstanceResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.ForbiddenError | 403 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Retrieve an instance by ID or name.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
"github.com/sfcompute/sfc-go/models/components"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Instances.Fetch(ctx, "inst_k3R-nX9vLm7Qp2Yw5Jd8F", nil)
if err != nil {
log.Fatal(err)
}
if res.InstanceResponse != nil {
switch res.InstanceResponse.Capacity.Type {
case components.ExpandableCapacityIDCapacitySummaryUnionTypeStr:
// res.InstanceResponse.Capacity.Str is populated
case components.ExpandableCapacityIDCapacitySummaryUnionTypeExpandableCapacityIDCapacitySummary:
// res.InstanceResponse.Capacity.ExpandableCapacityIDCapacitySummary is populated
default:
// Unknown type - use res.InstanceResponse.Capacity.GetUnknownRaw() for raw JSON
}
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | inst_k3R-nX9vLm7Qp2Yw5Jd8F |
expand |
[]operations.FetchInstanceExpand | ➖ | N/A | |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FetchInstanceResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Delete an instance.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Instances.Delete(ctx, "inst_k3R-nX9vLm7Qp2Yw5Jd8F")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | inst_k3R-nX9vLm7Qp2Yw5Jd8F |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.DeleteInstanceResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.ConflictError | 409 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Retrieve logs for an instance.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Instances.GetLogsForInstance(ctx, operations.GetInstanceLogsRequest{
ID: "inst_k3R-nX9vLm7Qp2Yw5Jd8F",
RealtimeTimestampBefore: sfc.Pointer[int64](1738972800),
RealtimeTimestampAfter: sfc.Pointer[int64](1738972800),
})
if err != nil {
log.Fatal(err)
}
if res.InstanceLogsResponse != nil {
// handle response
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
operations.GetInstanceLogsRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.GetInstanceLogsResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Retrieve SSH connection details for an instance.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Instances.GetSSHInfoForInstance(ctx, "inst_k3R-nX9vLm7Qp2Yw5Jd8F")
if err != nil {
log.Fatal(err)
}
if res.InstanceSSHInfo != nil {
// handle response
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | inst_k3R-nX9vLm7Qp2Yw5Jd8F |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.GetInstanceSSHResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Terminates a running instance. Terminated instances can not be restarted.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
"github.com/sfcompute/sfc-go/models/components"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Instances.TerminateInstance(ctx, "inst_k3R-nX9vLm7Qp2Yw5Jd8F")
if err != nil {
log.Fatal(err)
}
if res.InstanceResponse != nil {
switch res.InstanceResponse.Capacity.Type {
case components.ExpandableCapacityIDCapacitySummaryUnionTypeStr:
// res.InstanceResponse.Capacity.Str is populated
case components.ExpandableCapacityIDCapacitySummaryUnionTypeExpandableCapacityIDCapacitySummary:
// res.InstanceResponse.Capacity.ExpandableCapacityIDCapacitySummary is populated
default:
// Unknown type - use res.InstanceResponse.Capacity.GetUnknownRaw() for raw JSON
}
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | inst_k3R-nX9vLm7Qp2Yw5Jd8F |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.TerminateInstanceResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |