A symbolic link provides a convenient way to access frequently used files in a bucket, similar to a shortcut on Windows. This topic describes how to use the OSS SDK for Go to create and retrieve symbolic links.
Notes
The sample code in this topic uses the China (Hangzhou) region (
cn-hangzhou) as an example. By default, a public endpoint is used. If you want to access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about the regions and endpoints that OSS supports, see OSS regions and endpoints.The examples in this topic show how to use access credentials that are read from environment variables. For more information about how to configure access credentials, see Configure access credentials.
To create a symbolic link, you must have the
oss:PutObjectpermission. To retrieve a symbolic link, you must have theoss:GetObjectpermission. For more information, see Grant custom access policies to RAM users.
Method definitions
Create a symbolic link
func (c *Client) PutSymlink(ctx context.Context, request *PutSymlinkRequest, optFns ...func(*Options)) (*PutSymlinkResult, error)Get a symbolic link
func (c *Client) GetSymlink(ctx context.Context, request *GetSymlinkRequest, optFns ...func(*Options)) (*GetSymlinkResult, error)Request parameters
Parameter | Type | Description |
ctx | context.Context | The context of the request. You can use this parameter to set the total time limit for the request. |
request | *PutSymlinkRequest | The request parameters for the API operation to create a symbolic link. For more information, see PutSymlinkRequest. |
*GetSymlinkRequest | The request parameters for the API operation to get a symbolic link. For more information, see GetSymlinkRequest. | |
optFns | ...func(*Options) | (Optional) The operation-level configuration parameters. For more information, see Options. |
Return values
Return value | Type | Description |
result | *PutSymlinkResult | The return value of the API operation to create a symbolic link. This parameter is valid when err is nil. For more information, see RestoreObjectResult. |
*GetSymlinkResult | The return value of the API operation to get a symbolic link. This parameter is valid when err is nil. For more information, see GetSymlinkResult. | |
err | error | The status of the request. If the request fails, the value of err is not nil. |
Sample code
References
For the complete sample code for symbolic links, see the GitHub examples put_symlink.go and get_symlink.go.
For more information about operations on symbolic links, see Symbolic links.
For more information about the API operation that you can call to create a symbolic link, see PutSymlink.
For more information about the API operation that you can call to retrieve a symbolic link, see GetSymlink.