Giter VIP home page Giter VIP logo

Comments (11)

aofei avatar aofei commented on June 14, 2024

Sorry, there is a bug in Alibaba Cloud OSS (as far as I know, only they have this bug, see: minio/minio-go#1119 (comment)). I've reported it to Alibaba Cloud through a work order couple months ago and they've promised to fix it, but now it looks like they did nothing.

from goproxy.

bestneymarjr avatar bestneymarjr commented on June 14, 2024

Thank you very much for your reply. May I understand this? I cannot use oss unless I change the code.

from goproxy.

bestneymarjr avatar bestneymarjr commented on June 14, 2024

When I add the bucket name to the endpoint,there is a new error , The specified key does not exist.
This error return from m.client.PutObjectWithContext.

from goproxy.

aofei avatar aofei commented on June 14, 2024

May I understand this? I cannot use oss unless I change the code.

You can use Alibaba Cloud's OSS SDK to implement a goproxy.Cacher and a goproxy.Cache yourself. This's should be pretty easy. You can refer to this if you want (need to be refined).

from goproxy.

bestneymarjr avatar bestneymarjr commented on June 14, 2024

thank you

from goproxy.

aofei avatar aofei commented on June 14, 2024

Alibaba Cloud just told me that they're gradually releasing a new version of this bug that has been fixed. At present, only some regions have adopted the new version.

from goproxy.

aofei avatar aofei commented on June 14, 2024

They plan to cover all regions with the new version next month.

from goproxy.

bestneymarjr avatar bestneymarjr commented on June 14, 2024

I got it,thanks

from goproxy.

bestneymarjr avatar bestneymarjr commented on June 14, 2024

I use your oss cacher implement by Alibaba Cloud's OSS SDK, and I updated it,
now I can put the object to aliclould, but when I go get a project,there is a error: zip: not a valid zip file.

from goproxy.

bestneymarjr avatar bestneymarjr commented on June 14, 2024

when I use disk cacher, nothing is error.

from goproxy.

aofei avatar aofei commented on June 14, 2024

I said that this needs to be refined. I just refined a version for you, you can refer to the following code (untested):

// ossCache implements the `goproxy.Cache`. It is the cache unit of the `OSS`.
type ossCache struct {
	sync.Mutex

	bucket     *oss.Bucket
	objectName string
	readCloser io.ReadCloser
	offset     int64
	closed     bool
	name       string
	mimeType   string
	size       int64
	modTime    time.Time
	checksum   []byte
}

// resetReadCloser resets the `oc.readCloser`.
func (oc *ossCache) resetReadCloser() error {
	if oc.readCloser != nil {
		if err := oc.readCloser.Close(); err != nil {
			return err
		}
	}

	var err error
	oc.readCloser, err = oc.bucket.GetObject(
		oc.objectName,
		oss.Range(oc.offset, oc.size),
	)

	return err
}

// Read implements the `goproxy.Cache`.
func (oc *ossCache) Read(b []byte) (int, error) {
	oc.Lock()
	defer oc.Unlock()

	if oc.closed {
		return 0, os.ErrClosed
	} else if oc.offset >= oc.size {
		return 0, io.EOF
	}

	if oc.readCloser != nil {
		if err := oc.resetReadCloser(); err != nil {
			return 0, err
		}
	}

	n, err := oc.Read(b)
	oc.offset += int64(n)

	return n, err
}

// Seek implements the `goproxy.Cache`.
func (oc *ossCache) Seek(offset int64, whence int) (int64, error) {
	oc.Lock()
	defer oc.Unlock()

	if oc.closed {
		return 0, os.ErrClosed
	}

	switch whence {
	case io.SeekStart:
	case io.SeekCurrent:
		offset += oc.offset
	case io.SeekEnd:
		offset += oc.size
	default:
		return 0, errors.New("invalid whence")
	}

	if offset < 0 {
		return 0, errors.New("negative position")
	}

	oc.offset = offset
	if oc.offset < oc.size {
		if err := oc.resetReadCloser(); err != nil {
			return 0, err
		}
	}

	return oc.offset, nil
}

// Close implements the `goproxy.Cache`.
func (oc *ossCache) Close() error {
	oc.Lock()
	defer oc.Unlock()

	if oc.closed {
		return os.ErrClosed
	}

	if oc.readCloser != nil {
		if err := oc.readCloser.Close(); err != nil {
			return err
		}
	}

	oc.closed = true

	return nil
}

// Name implements the `goproxy.Cache`.
func (oc *ossCache) Name() string {
	return oc.name
}

// MIMEType implements the `goproxy.Cache`.
func (oc *ossCache) MIMEType() string {
	return oc.mimeType
}

// Size implements the `goproxy.Cache`.
func (oc *ossCache) Size() int64 {
	return oc.size
}

// ModTime implements the `goproxy.Cache`.
func (oc *ossCache) ModTime() time.Time {
	return oc.modTime
}

// Checksum implements the `goproxy.Cache`.
func (oc *ossCache) Checksum() []byte {
	return oc.checksum
}

from goproxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.