本文介绍文件存储 vePFS Go SDK 的代码示例供您参考。
使用 Go SDK 调用文件存储 vePFS 的接口时,默认无超时时间设置。 您可以在初始化客户端时,通过 WithHTTPClient(&http.Client{Timeout: <超时时间> * time.Second})
来指定客户端的请求超时时间,若未在该时间内完成,请求即会终止并报超时错误。 例如,您可以通过如下代码将客户端的请求超时时间设置为 30 秒。
config = volcengine.NewConfig().WithCredentials(credentials.NewStaticCredentials(ak, sk, "")).WithRegion(region).WithHTTPClient(&http.Client{Timeout: 30 * time.Second})
说明
关于下述 SDK 代码中所使用参数的定义、取值范围等信息,请参见 CreateFileSystem。
package main import ( "fmt" "os" "github.com/volcengine/volcengine-go-sdk/service/vepfs" "github.com/volcengine/volcengine-go-sdk/volcengine" "github.com/volcengine/volcengine-go-sdk/volcengine/credentials" "github.com/volcengine/volcengine-go-sdk/volcengine/session" ) var client *vepfs.VEPFS func initClient() { // 详见初始化客户端部分 } func createFileSystem() { zoneId := "cn-beijing-a" fileSystemName := "go_sdk_test" fileSystemType := "VePFS" protocolType := "VePFS" chargeType := "PayAsYouGo" capacity := int32(6) storeType := "Advance_100" vpcId := "vpc-11w4ygf1zls7*************" subnetId := "subnet-11wlfzpho**************" // 调用 CreateFileSystem 接口创建文件系统 resp, err := client.CreateFileSystem(&vepfs.CreateFileSystemInput{ ZoneId: &zoneId, FileSystemName: &fileSystemName, FileSystemType: &fileSystemType, ProtocolType: &protocolType, ChargeType: &chargeType, Capacity: &capacity, StoreType: &storeType, SubnetId: &subnetId, VpcId: &vpcId, }) if err != nil { fmt.Printf("Error when calling CreateFileSystem, err: %v\n", err) os.Exit(1) } fmt.Println(resp) } func main() { initClient() createFileSystem() }
说明
关于下述 SDK 请求中所使用参数的定义、取值范围等信息,请参见 DescribeFileSystems。
package main import ( "fmt" "os" "github.com/volcengine/volcengine-go-sdk/service/vepfs" "github.com/volcengine/volcengine-go-sdk/volcengine" "github.com/volcengine/volcengine-go-sdk/volcengine/credentials" "github.com/volcengine/volcengine-go-sdk/volcengine/session" ) var client *vepfs.VEPFS func initClient() { // 详见初始化客户端部分 } func describeFileSystems() { // 指定要查询的文件系统 ID fileSystemId := "vepfs-cn**************" // 调用 DescribeFileSystems 接口列举文件系统 resp, err := client.DescribeFileSystems(&vepfs.DescribeFileSystemsInput{ FileSystemIds: &fileSystemId, }) if err != nil { fmt.Printf("Error when calling DescribeFileSystems, err: %v\n", err) os.Exit(1) } fmt.Println(resp) } func main() { initClient() describeFileSystems() }