本文整理匯總了Golang中github.com/minio/minio/pkg/probe.NewError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewError函數的具體用法?Golang NewError怎麽用?Golang NewError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Load
// Load - loads json config from filename for the a given struct data
func Load(filename string, data interface{}) (Config, *probe.Error) {
_, err := os.Stat(filename)
if err != nil {
return nil, probe.NewError(err)
}
fileData, err := ioutil.ReadFile(filename)
if err != nil {
return nil, probe.NewError(err)
}
if runtime.GOOS == "windows" {
fileData = []byte(strings.Replace(string(fileData), "\r\n", "\n", -1))
}
err = json.Unmarshal(fileData, &data)
if err != nil {
switch err := err.(type) {
case *json.SyntaxError:
return nil, probe.NewError(FormatJSONSyntaxError(bytes.NewReader(fileData), err))
default:
return nil, probe.NewError(err)
}
}
config, perr := New(data)
if perr != nil {
return nil, perr.Trace()
}
return config, nil
}
示例2: extractHTTPFormValues
func extractHTTPFormValues(reader *multipart.Reader) (io.Reader, map[string]string, *probe.Error) {
/// HTML Form values
formValues := make(map[string]string)
filePart := new(bytes.Buffer)
var err error
for err == nil {
var part *multipart.Part
part, err = reader.NextPart()
if part != nil {
if part.FileName() == "" {
buffer, err := ioutil.ReadAll(part)
if err != nil {
return nil, nil, probe.NewError(err)
}
formValues[http.CanonicalHeaderKey(part.FormName())] = string(buffer)
} else {
_, err := io.Copy(filePart, part)
if err != nil {
return nil, nil, probe.NewError(err)
}
}
}
}
return filePart, formValues, nil
}
示例3: initPresignedSignatureV4
// initPresignedSignatureV4 initializing presigned signature verification
func initPresignedSignatureV4(req *http.Request) (*signv4.Signature, *probe.Error) {
credentialElements := strings.Split(strings.TrimSpace(req.URL.Query().Get("X-Amz-Credential")), "/")
if len(credentialElements) != 5 {
return nil, probe.NewError(errCredentialTagMalformed)
}
accessKeyID := credentialElements[0]
if !IsValidAccessKey(accessKeyID) {
return nil, probe.NewError(errAccessKeyIDInvalid)
}
authConfig, err := LoadConfig()
if err != nil {
return nil, err.Trace()
}
signedHeaders := strings.Split(strings.TrimSpace(req.URL.Query().Get("X-Amz-SignedHeaders")), ";")
signature := strings.TrimSpace(req.URL.Query().Get("X-Amz-Signature"))
for _, user := range authConfig.Users {
if user.AccessKeyID == accessKeyID {
signature := &signv4.Signature{
AccessKeyID: user.AccessKeyID,
SecretAccessKey: user.SecretAccessKey,
Signature: signature,
SignedHeaders: signedHeaders,
Presigned: true,
Request: req,
}
return signature, nil
}
}
return nil, probe.NewError(errAccessKeyIDInvalid)
}
示例4: Match
func (sl *sortedList) Match(source *client.Content) (bool, *probe.Error) {
if len(sl.current.Name) == 0 {
// for the first time read
if err := sl.dec.Decode(&sl.current); err != nil {
if err != io.EOF {
return false, probe.NewError(err)
}
return false, nil
}
}
for {
compare := strings.Compare(source.Name, sl.current.Name)
if compare == 0 {
if source.Type.IsRegular() && sl.current.Type.IsRegular() && source.Size == sl.current.Size {
return true, nil
}
return false, nil
}
if compare < 0 {
return false, nil
}
// assign zero values to fields because if s.current's previous decode had non zero value
// fields it will not be over written if this loop's decode does not contain those fields
sl.current = client.Content{}
if err := sl.dec.Decode(&sl.current); err != nil {
return false, probe.NewError(err)
}
}
}
示例5: ShareUpload
func (c *s3Client) ShareUpload(recursive bool, expires time.Duration, contentType string) (map[string]string, *probe.Error) {
bucket, object := c.url2BucketAndObject()
p := minio.NewPostPolicy()
if err := p.SetExpires(time.Now().UTC().Add(expires)); err != nil {
return nil, probe.NewError(err)
}
if strings.TrimSpace(contentType) != "" || contentType != "" {
// No need to check for errors here, we have trimmed off the spaces
p.SetContentType(contentType)
}
if err := p.SetBucket(bucket); err != nil {
return nil, probe.NewError(err)
}
if recursive {
if err := p.SetKeyStartsWith(object); err != nil {
return nil, probe.NewError(err)
}
} else {
if err := p.SetKey(object); err != nil {
return nil, probe.NewError(err)
}
}
m, err := c.api.PresignedPostPolicy(p)
return m, probe.NewError(err)
}
示例6: printServerMsg
func printServerMsg(serverConf *http.Server) {
host, port, e := net.SplitHostPort(serverConf.Addr)
fatalIf(probe.NewError(e), "Unable to split host port.", nil)
var hosts []string
switch {
case host != "":
hosts = append(hosts, host)
default:
addrs, e := net.InterfaceAddrs()
fatalIf(probe.NewError(e), "Unable to get interface address.", nil)
for _, addr := range addrs {
if addr.Network() == "ip+net" {
host := strings.Split(addr.String(), "/")[0]
if ip := net.ParseIP(host); ip.To4() != nil {
hosts = append(hosts, host)
}
}
}
}
for _, host := range hosts {
if serverConf.TLSConfig != nil {
Printf(" https://%s:%s\n", host, port)
} else {
Printf(" http://%s:%s\n", host, port)
}
}
}
示例7: MakeBucket
// MakeBucket - PUT Bucket
func (fs API) MakeBucket(bucket, acl string) *probe.Error {
fs.lock.Lock()
defer fs.lock.Unlock()
// verify bucket path legal
if !IsValidBucket(bucket) {
return probe.NewError(BucketNameInvalid{Bucket: bucket})
}
// get bucket path
bucketDir := filepath.Join(fs.path, bucket)
// check if bucket exists
if _, err := os.Stat(bucketDir); err == nil {
return probe.NewError(BucketExists{
Bucket: bucket,
})
}
// make bucket
err := os.Mkdir(bucketDir, 0700)
if err != nil {
return probe.NewError(err)
}
return nil
}
示例8: GetObjectMetadata
// GetObjectMetadata - get object metadata.
func (fs Filesystem) GetObjectMetadata(bucket, object string) (ObjectMetadata, *probe.Error) {
// Input validation.
if !IsValidBucketName(bucket) {
return ObjectMetadata{}, probe.NewError(BucketNameInvalid{Bucket: bucket})
}
if !IsValidObjectName(object) {
return ObjectMetadata{}, probe.NewError(ObjectNameInvalid{Bucket: bucket, Object: bucket})
}
// Normalize buckets.
bucket = fs.denormalizeBucket(bucket)
bucketPath := filepath.Join(fs.path, bucket)
if _, e := os.Stat(bucketPath); e != nil {
if os.IsNotExist(e) {
return ObjectMetadata{}, probe.NewError(BucketNotFound{Bucket: bucket})
}
return ObjectMetadata{}, probe.NewError(e)
}
metadata, err := getMetadata(fs.path, bucket, object)
if err != nil {
return ObjectMetadata{}, err.Trace(bucket, object)
}
if metadata.Mode.IsDir() {
return ObjectMetadata{}, probe.NewError(ObjectNotFound{Bucket: bucket, Object: object})
}
return metadata, nil
}
示例9: deleteObjectPath
// deleteObjectPath - delete object path if its empty.
func deleteObjectPath(basePath, deletePath, bucket, object string) *probe.Error {
if basePath == deletePath {
return nil
}
// Verify if the path exists.
pathSt, e := os.Stat(deletePath)
if e != nil {
if os.IsNotExist(e) {
return probe.NewError(ObjectNotFound{Bucket: bucket, Object: object})
}
return probe.NewError(e)
}
if pathSt.IsDir() {
// Verify if directory is empty.
empty, e := ioutils.IsDirEmpty(deletePath)
if e != nil {
return probe.NewError(e)
}
if !empty {
return nil
}
}
// Attempt to remove path.
if e := os.Remove(deletePath); e != nil {
return probe.NewError(e)
}
// Recursively go down the next path and delete again.
if err := deleteObjectPath(basePath, filepath.Dir(deletePath), bucket, object); err != nil {
return err.Trace(basePath, deletePath, bucket, object)
}
return nil
}
示例10: Delete
// Delete removes all the session files.
func (s *sessionV8) Delete() *probe.Error {
s.mutex.Lock()
defer s.mutex.Unlock()
if s.DataFP != nil {
name := s.DataFP.Name()
// close file pro-actively before deleting
// ignore any error, it could be possibly that
// the file is closed already
s.DataFP.Close()
// Remove the data file.
if e := os.Remove(name); e != nil {
return probe.NewError(e)
}
}
// Fetch the session file.
sessionFile, err := getSessionFile(s.SessionID)
if err != nil {
return err.Trace(s.SessionID)
}
// Remove session file
if e := os.Remove(sessionFile); e != nil {
return probe.NewError(e)
}
// Remove session backup file if any, ignore any error.
os.Remove(sessionFile + ".old")
return nil
}
示例11: GetAuthKeys
// GetAuthKeys get access key id and secret access key
func GetAuthKeys(url string) ([]byte, *probe.Error) {
op := RPCOps{
Method: "Auth.Get",
Request: rpc.Args{Request: ""},
}
req, perr := NewRequest(url, op, http.DefaultTransport)
if perr != nil {
return nil, perr.Trace()
}
resp, perr := req.Do()
defer closeResp(resp)
if perr != nil {
return nil, perr.Trace()
}
var reply rpc.AuthReply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return nil, probe.NewError(err)
}
authConfig := &auth.Config{}
authConfig.Version = "0.0.1"
authConfig.Users = make(map[string]*auth.User)
user := &auth.User{}
user.Name = "testuser"
user.AccessKeyID = reply.AccessKeyID
user.SecretAccessKey = reply.SecretAccessKey
authConfig.Users[reply.AccessKeyID] = user
if err := auth.SaveConfig(authConfig); err != nil {
return nil, err.Trace()
}
jsonRespBytes, err := json.MarshalIndent(reply, "", "\t")
if err != nil {
return nil, probe.NewError(err)
}
return jsonRespBytes, nil
}
示例12: save
// save - wrapper for quick.Save and saves only if sessionHeader is
// modified.
func (s *sessionV8) save() *probe.Error {
sessionFile, err := getSessionFile(s.SessionID)
if err != nil {
return err.Trace(s.SessionID)
}
// Verify if sessionFile is modified.
modified, err := s.isModified(sessionFile)
if err != nil {
return err.Trace(s.SessionID)
}
// Header is modified, we save it.
if modified {
qs, e := quick.New(s.Header)
if e != nil {
return probe.NewError(e).Trace(s.SessionID)
}
// Save an return.
e = qs.Save(sessionFile)
if e != nil {
return probe.NewError(e).Trace(sessionFile)
}
}
return nil
}
示例13: isModified
// IsModified - returns if in memory session header has changed from
// its on disk value.
func (s *sessionV8) isModified(sessionFile string) (bool, *probe.Error) {
qs, e := quick.New(s.Header)
if e != nil {
return false, probe.NewError(e).Trace(s.SessionID)
}
var currentHeader = &sessionV8Header{}
currentQS, e := quick.Load(sessionFile, currentHeader)
if e != nil {
// If session does not exist for the first, return modified to
// be true.
if os.IsNotExist(e) {
return true, nil
}
// For all other errors return.
return false, probe.NewError(e).Trace(s.SessionID)
}
changedFields, e := qs.DeepDiff(currentQS)
if e != nil {
return false, probe.NewError(e).Trace(s.SessionID)
}
// Returns true if there are changed entries.
return len(changedFields) > 0, nil
}
示例14: Save
// Save this session.
func (s *sessionV8) Save() *probe.Error {
s.mutex.Lock()
defer s.mutex.Unlock()
if s.DataFP.dirty {
if err := s.DataFP.Sync(); err != nil {
return probe.NewError(err)
}
s.DataFP.dirty = false
}
qs, e := quick.New(s.Header)
if e != nil {
return probe.NewError(e).Trace(s.SessionID)
}
sessionFile, err := getSessionFile(s.SessionID)
if err != nil {
return err.Trace(s.SessionID)
}
e = qs.Save(sessionFile)
if e != nil {
return probe.NewError(e).Trace(sessionFile)
}
return nil
}
示例15: SetBucketMetadata
// SetBucketMetadata -
func (donut API) SetBucketMetadata(bucket string, metadata map[string]string, signature *Signature) *probe.Error {
donut.lock.Lock()
defer donut.lock.Unlock()
if signature != nil {
ok, err := signature.DoesSignatureMatch("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
if err != nil {
return err.Trace()
}
if !ok {
return probe.NewError(SignatureDoesNotMatch{})
}
}
if !IsValidBucket(bucket) {
return probe.NewError(BucketNameInvalid{Bucket: bucket})
}
if !donut.storedBuckets.Exists(bucket) {
return probe.NewError(BucketNotFound{Bucket: bucket})
}
if len(donut.config.NodeDiskMap) > 0 {
if err := donut.setBucketMetadata(bucket, metadata); err != nil {
return err.Trace()
}
}
storedBucket := donut.storedBuckets.Get(bucket).(storedBucket)
storedBucket.bucketMetadata.ACL = BucketACL(metadata["acl"])
donut.storedBuckets.Set(bucket, storedBucket)
return nil
}