对象存储标准的接口有:

  • put
  • get
  • delete
  • list

对象存储适合的文件类型:短视频,音频文件、照片、图标、pdf、word文档、电子票据。

对于超大文件的存储,有时候索引其中某一个扇区例如:"file1.txt"文件的4096偏移量处的4个字节,总不能把整个文件get下来再访问吧。 需要一个扩展的接口:

package main

import "fmt"

type myoss interface {
	read(key string, offset, size int64) ([]byte, error)
	put(src, key string) (int64, error)
	get(key, dst string) (int64, error)
	list(bucket, user, passwd string) []string
	del(key string) ([]byte, error)
}

type myossc struct {
	host           []string
	bucket         string
	part           int64
	up_concurrency int64
	access_key     string
	secret_key     string
}

func (c *myossc) read(key string, offset, size int64) ([]byte, error) {
	fmt.Println("i am hlm oss read interface")
	return nil, nil
}

func (c *myossc) put(src, key string) (int64, error) {
	return 0, nil
}

func (c *myossc) get(key, dst string) (int64, error) {
	return 0, nil
}

func (c *myossc) list(bucket, user, passwd string) []string {
	return []string{}
}

func (c *myossc) del(key string) ([]byte, error) {
	return nil, nil
}

func main() {
	fmt.Println("ext-client-minio")
	client := &myossc{
		host:           []string{"http://182.168.31.100/data{1..100}", "http://182.168.31.103/data{1..100}"},
		bucket:         "test",
		part:           32,
		up_concurrency: 8,
		access_key:     "minio123",
		secret_key:     "minio123",
	}

	client.read("/data/dir1/dir2/dir4", 10240, 2048)
}