Geben Sie eine signierte URL in Golang aus.
import sign "github.com/aws/aws-sdk-go/service/cloudfront/sign"
func main() {
type CFConfig struct {
KeyID string
Domain string
KeyPath string
}
// cloud front config
cfConf := &model.CFConfig{
KeyID: "xxxxxxxxxxxxCQ"
Domain: "http://xxx.cloudfront.net",
KeyPath: "key/xxxxxxxxxxxxCQ",
}
privKey, err := sign.LoadPEMPrivKeyFile(r.cfConf.KeyPath)
if err != nil {
log.Println("failed to load pem file:", err)
return "", err
}
keyID := r.cfConf.KeyID
signer := sign.NewURLSigner(keyID, privKey)
path := "s3 Pfad des Inhalts, auf den Sie Zugriff gewähren möchten"
signedURL, err := signer.Sign(r.cfConf.Domain+path, time.Now().Add(1*time.Hour))
if err != nil {
log.Fatalf("Failed to sign url, err: %s\n", err.Error())
}
return signedURL, err
}