A symbolic link is a special object that maps to an object similar to a shortcut used in Windows. You can configure user-defined Object Meta for symbolic links.

Run the following code to create a symbolic link:

package main

import (
	"fmt"
	"os"
	"strings"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Create an OSSClient instance.
	client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	bucketName := "<yourBucketName>"
	// The symbolic link.
	objectName := "<yourSymlinkName>"
	// The target object that the symbolic link directs to
	targetObjectName := "<yourSymlinkTargetName>"

	// Obtain the bucket.
	bucket, err := client.Bucket(bucketName)
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Create a symbolic link.
	err = bucket.PutSymlink(objectName, targetObjectName)
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Upload a file to the object that the symbolic link directs to.
	err = bucket.PutObject(targetObjectName, strings.NewReader("target"))
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	err = bucket.PutSymlink(objectName, targetObjectName)
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Obtain the content of the object that the symbolic link directs to.
	meta, err := bucket.GetSymlink(objectName)
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	fmt.Println(meta.Get(oss.HTTPHeaderOssSymlinkTarget))
}

For more information about creating symbolic links, see PutSymlink.

Obtain object content for a symbolic link

To obtain a symbolic link, you must have the read permission on it. Run the following code to obtain the object content for a symbolic link:

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Create an OSSClient instance.
	client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	bucketName := "<yourBucketName>"
	// Symbolic Link name.
	objectName := "<yourSymlinkObjectName>"

	// Obtain the bucket.
	bucket, err := client.Bucket(bucketName)
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Obtain the content of the object that the symbolic link directs to.
	meta, err := bucket.GetSymlink(objectName)
	if err ! = nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	fmt.Println(meta.Get(oss.HTTPHeaderOssSymlinkTarget))
}

For more information about obtaining symbolic links, see GetSymlink.