github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/obs/callback.go (about) 1 // Copyright 2019 Huawei Technologies Co.,Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use 3 // this file except in compliance with the License. You may obtain a copy of the 4 // License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software distributed 9 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 10 // CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 // specific language governing permissions and limitations under the License. 12 13 package obs 14 15 import ( 16 "errors" 17 "io" 18 ) 19 20 type ICallbackReadCloser interface { 21 setCallbackReadCloser(body io.ReadCloser) 22 } 23 24 func (output *PutObjectOutput) setCallbackReadCloser(body io.ReadCloser) { 25 output.CallbackBody.data = body 26 } 27 28 func (output *CompleteMultipartUploadOutput) setCallbackReadCloser(body io.ReadCloser) { 29 output.CallbackBody.data = body 30 } 31 32 // define CallbackBody 33 type CallbackBody struct { 34 data io.ReadCloser 35 } 36 37 func (output CallbackBody) ReadCallbackBody(p []byte) (int, error) { 38 if output.data == nil { 39 return 0, errors.New("have no callback data") 40 } 41 return output.data.Read(p) 42 } 43 44 func (output CallbackBody) CloseCallbackBody() error { 45 if output.data == nil { 46 return errors.New("have no callback data") 47 } 48 return output.data.Close() 49 }