ksyun-ks3-go-sdk

command module
v1.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 4 Imported by: 0

README

Ksyun Cloud KS3 SDK for Go

README in Chinese

About

  • This Go SDK is based on the official APIs of Ksyun Cloud KS3.
  • Ksyun Cloud Object Storage Service (KS3) is a cloud storage service provided by Ksyun Cloud, featuring massive capacity, security, a low cost, and high reliability.
  • The KS3 can store any type of files and therefore applies to various websites, development enterprises and developers.
  • With this SDK, you can upload, download and manage data on any app anytime and anywhere conveniently.

Version

  • Current version: v0.0.1

Running Environment

  • Go 1.5 or above.

Installing

Install the SDK through GitHub
  • Run the 'go get github.com/wilac-pv/ksyun-ks3-go-sdk/ks3' command to get the remote code package.
  • Use 'import "github.com/wilac-pv/ksyun-ks3-go-sdk/ks3"' in your code to introduce KS3 Go SDK package.

Getting Started

List Bucket
    client, err := ks3.New("Endpoint", "AccessKeyId", "AccessKeySecret")
    if err != nil {
        // HandleError(err)
    }
    
    lsRes, err := client.ListBuckets()
    if err != nil {
        // HandleError(err)
    }
    
    for _, bucket := range lsRes.Buckets {
        fmt.Println("Buckets:", bucket.Name)
    }
Create Bucket
    client, err := ks3.New("Endpoint", "AccessKeyId", "AccessKeySecret")
    if err != nil {
        // HandleError(err)
    }
    
    err = client.CreateBucket("my-bucket")
    if err != nil {
        // HandleError(err)
    }
Delete Bucket
    client, err := ks3.New("Endpoint", "AccessKeyId", "AccessKeySecret")
    if err != nil {
        // HandleError(err)
    }
    
    err = client.DeleteBucket("my-bucket")
    if err != nil {
        // HandleError(err)
    }
Put Object
    client, err := ks3.New("Endpoint", "AccessKeyId", "AccessKeySecret")
    if err != nil {
        // HandleError(err)
    }
    
    bucket, err := client.Bucket("my-bucket")
    if err != nil {
        // HandleError(err)
    }
    
    err = bucket.PutObjectFromFile("my-object", "LocalFile")
    if err != nil {
        // HandleError(err)
    }
Get Object
    client, err := ks3.New("Endpoint", "AccessKeyId", "AccessKeySecret")
    if err != nil {
        // HandleError(err)
    }
    
    bucket, err := client.Bucket("my-bucket")
    if err != nil {
        // HandleError(err)
    }
    
    err = bucket.GetObjectToFile("my-object", "LocalFile")
    if err != nil {
        // HandleError(err)
    }
List Objects
    client, err := ks3.New("Endpoint", "AccessKeyId", "AccessKeySecret")
    if err != nil {
        // HandleError(err)
    }
    
    bucket, err := client.Bucket("my-bucket")
    if err != nil {
        // HandleError(err)
    }
    
    lsRes, err := bucket.ListObjects()
    if err != nil {
        // HandleError(err)
    }
    
    for _, object := range lsRes.Objects {
        fmt.Println("Objects:", object.Key)
    }
Delete Object
    client, err := ks3.New("Endpoint", "AccessKeyId", "AccessKeySecret")
    if err != nil {
        // HandleError(err)
    }
    
    bucket, err := client.Bucket("my-bucket")
    if err != nil {
        // HandleError(err)
    }
    
    err = bucket.DeleteObject("my-object")
    if err != nil {
        // HandleError(err)
    }

Complete Example

More example projects can be found at 'src\github.com\ksyun\ksyun-ks3-go-sdk\sample' under the installation path of the KS3 Go SDK (the first path of the GOPATH variable). The directory contains example projects. Or you can refer to the example objects in the sample directory under 'https://github.com/wilac-pv/ksyun-ks3-go-sdk'.

Running Example
  • Copy the example file. Go to the installation path of KS3 Go SDK (the first path of the GOPATH variable), enter the code directory of the KS3 Go SDK, namely 'src\github.com\ksyun\ksyun-ks3-go-sdk', and copy the sample directory and sample.go to the src directory of your test project.
  • Modify the endpoint, AccessKeyId, AccessKeySecret and BucketName configuration settings in sample/config.go.
  • Run 'go run src/sample.go' under your project directory.

Contacting us

License

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package ks3 implements functions for access ks3 service.
Package ks3 implements functions for access ks3 service.
Package sample examples
Package sample examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL