當前位置: 首頁>>代碼示例>>Golang>>正文


Golang logger.Error函數代碼示例

本文整理匯總了Golang中github.com/MG-RAST/Shock/shock-server/logger.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: PreAuthRequest

func PreAuthRequest(ctx context.Context) {
	id := ctx.PathValue("id")
	if p, err := preauth.Load(id); err != nil {
		err_msg := "err:@preAuth load: " + err.Error()
		logger.Error(err_msg)
		responder.RespondWithError(ctx, 500, err_msg)
		return
	} else {
		if n, err := node.LoadUnauth(p.NodeId); err == nil {
			switch p.Type {
			case "download":
				filename := n.Id
				if fn, has := p.Options["filename"]; has {
					filename = fn
				}
				streamDownload(ctx, n, filename)
				preauth.Delete(id)
				return
			default:
				responder.RespondWithError(ctx, 500, "Preauthorization type not supported: "+p.Type)
			}
		} else {
			err_msg := "err:@preAuth loadnode: " + err.Error()
			logger.Error(err_msg)
			responder.RespondWithError(ctx, 500, err_msg)
		}
	}
	return
}
開發者ID:narayandesai,項目名稱:Shock,代碼行數:29,代碼來源:preauth.go

示例2: Create

// POST: /node
func (cr *Controller) Create(cx *goweb.Context) {
	// Log Request and check for Auth
	request.Log(cx.Request)
	u, err := request.Authenticate(cx.Request)
	if err != nil && err.Error() != e.NoAuth {
		request.AuthError(err, cx)
		return
	}

	// Fake public user
	if u == nil {
		if conf.Bool(conf.Conf["anon-write"]) {
			u = &user.User{Uuid: ""}
		} else {
			cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
			return
		}
	}

	// Parse uploaded form
	params, files, err := request.ParseMultipartForm(cx.Request)
	if err != nil {
		// If not multipart/form-data it will create an empty node.
		// TODO: create another request parser for non-multipart request
		// to handle this cleaner.
		if err.Error() == "request Content-Type isn't multipart/form-data" {
			n, err := node.CreateNodeUpload(u, params, files)
			if err != nil {
				logger.Error("Error at create empty: " + err.Error())
				cx.RespondWithError(http.StatusInternalServerError)
				return
			}
			if n == nil {
				// Not sure how you could get an empty node with no error
				// Assume it's the user's fault
				cx.RespondWithError(http.StatusBadRequest)
				return
			} else {
				cx.RespondWithData(n)
				return
			}
		} else {
			// Some error other than request encoding. Theoretically
			// could be a lost db connection between user lookup and parsing.
			// Blame the user, Its probaby their fault anyway.
			logger.Error("Error parsing form: " + err.Error())
			cx.RespondWithError(http.StatusBadRequest)
			return
		}
	}
	// Create node
	n, err := node.CreateNodeUpload(u, params, files)
	if err != nil {
		logger.Error("[email protected]_CreateNodeUpload: " + err.Error())
		cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
		return
	}
	cx.RespondWithData(n)
	return
}
開發者ID:wtangiit,項目名稱:Shock,代碼行數:61,代碼來源:create.go

示例3: AclRequest

// GET, POST, PUT, DELETE: /node/{nid}/acl/
// GET is the only action implemented here.
func AclRequest(ctx context.Context) {
	nid := ctx.PathValue("nid")
	rmeth := ctx.HttpRequest().Method

	u, err := request.Authenticate(ctx.HttpRequest())
	if err != nil && err.Error() != e.NoAuth {
		request.AuthError(err, ctx)
		return
	}

	// public user (no auth) can perform a GET operation with the proper node permissions
	if u == nil {
		if rmeth == "GET" && conf.ANON_READ {
			u = &user.User{Uuid: "public"}
		} else {
			responder.RespondWithError(ctx, http.StatusUnauthorized, e.NoAuth)
			return
		}
	}

	// Load node by id
	n, err := node.Load(nid)
	if err != nil {
		if err == mgo.ErrNotFound {
			responder.RespondWithError(ctx, http.StatusNotFound, e.NodeNotFound)
			return
		} else {
			// In theory the db connection could be lost between
			// checking user and load but seems unlikely.
			err_msg := "[email protected]_Acl:LoadNode: " + nid + err.Error()
			logger.Error(err_msg)
			responder.RespondWithError(ctx, http.StatusInternalServerError, err_msg)
			return
		}
	}

	// Only the owner, an admin, or someone with read access can view acl's.
	//
	// NOTE: If the node is publicly owned, then anyone can view all acl's. The owner can only
	//       be "public" when anonymous node creation (ANON_WRITE) is enabled in Shock config.

	rights := n.Acl.Check(u.Uuid)
	if n.Acl.Owner != u.Uuid && u.Admin == false && n.Acl.Owner != "public" && rights["read"] == false {
		responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth)
		return
	}

	if rmeth == "GET" {
		query := ctx.HttpRequest().URL.Query()
		verbosity := ""
		if _, ok := query["verbosity"]; ok {
			verbosity = query.Get("verbosity")
		}
		responder.RespondWithData(ctx, n.Acl.FormatDisplayAcl(verbosity))
	} else {
		responder.RespondWithError(ctx, http.StatusNotImplemented, "This request type is not implemented.")
	}
	return
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:61,代碼來源:acl.go

示例4: AuthError

func AuthError(err error, ctx context.Context) error {
	if err.Error() == e.InvalidAuth {
		return responder.RespondWithError(ctx, http.StatusBadRequest, "Invalid authorization header or content")
	}
	err_msg := "Error at Auth: " + err.Error()
	logger.Error(err_msg)
	return responder.RespondWithError(ctx, http.StatusInternalServerError, err_msg)
}
開發者ID:paczian,項目名稱:Shock,代碼行數:8,代碼來源:request.go

示例5: Delete

// DELETE: /node/{id}
func (cr *NodeController) Delete(id string, ctx context.Context) error {
	u, err := request.Authenticate(ctx.HttpRequest())
	if err != nil && err.Error() != e.NoAuth {
		return request.AuthError(err, ctx)
	}

	// public user (no auth) can be used in some cases
	if u == nil {
		if conf.ANON_DELETE {
			u = &user.User{Uuid: "public"}
		} else {
			return responder.RespondWithError(ctx, http.StatusUnauthorized, e.NoAuth)
		}
	}

	// Load node by id
	n, err := node.Load(id)
	if err != nil {
		if err == mgo.ErrNotFound {
			return responder.RespondWithError(ctx, http.StatusNotFound, e.NodeNotFound)
		} else {
			// In theory the db connection could be lost between
			// checking user and load but seems unlikely.
			err_msg := "[email protected]_Delete:LoadNode: " + id + ":" + err.Error()
			logger.Error(err_msg)
			return responder.RespondWithError(ctx, http.StatusInternalServerError, err_msg)
		}
	}

	rights := n.Acl.Check(u.Uuid)
	prights := n.Acl.Check("public")
	if rights["delete"] == false && u.Admin == false && n.Acl.Owner != u.Uuid && prights["delete"] == false {
		return responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth)
	}

	if err := n.Delete(); err == nil {
		return responder.RespondOK(ctx)
	} else {
		err_msg := "[email protected]_Delete:Delete: " + err.Error()
		logger.Error(err_msg)
		return responder.RespondWithError(ctx, http.StatusInternalServerError, err_msg)
	}
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:44,代碼來源:delete.go

示例6: streamDownload

func streamDownload(ctx context.Context, n *node.Node, filename string) {
	nf, err := n.FileReader()
	defer nf.Close()
	if err != nil {
		// File not found or some sort of file read error.
		// Probably deserves more checking
		err_msg := "err:@preAuth node.FileReader: " + err.Error()
		logger.Error(err_msg)
		responder.RespondWithError(ctx, 500, err_msg)
		return
	}
	s := &request.Streamer{R: []file.SectionReader{nf}, W: ctx.HttpResponseWriter(), ContentType: "application/octet-stream", Filename: filename, Size: n.File.Size, Filter: nil}
	err = s.Stream()
	if err != nil {
		// causes "multiple response.WriteHeader calls" error but better than no response
		err_msg := "err:@preAuth: s.stream: " + err.Error()
		logger.Error(err_msg)
		responder.RespondWithError(ctx, 500, err_msg)
	}
}
開發者ID:narayandesai,項目名稱:Shock,代碼行數:20,代碼來源:preauth.go

示例7: streamDownload

// handle download and its options
func streamDownload(ctx context.Context, n *node.Node, options map[string]string) {
	nf, err := n.FileReader()
	defer nf.Close()
	if err != nil {
		// File not found or some sort of file read error.
		// Probably deserves more checking
		err_msg := "err:@preAuth node.FileReader: " + err.Error()
		logger.Error(err_msg)
		responder.RespondWithError(ctx, 500, err_msg)
		return
	}
	// set defaults
	filename := n.Id
	var filterFunc filter.FilterFunc = nil
	var compressionFormat string = ""
	// use options if exist
	if fn, has := options["filename"]; has {
		filename = fn
	}
	if fl, has := options["filter"]; has {
		if filter.Has(fl) {
			filterFunc = filter.Filter(fl)
		}
	}
	if cp, has := options["compression"]; has {
		if archive.IsValidCompress(cp) {
			compressionFormat = cp
		}
	}
	// stream it
	s := &request.Streamer{R: []file.SectionReader{nf}, W: ctx.HttpResponseWriter(), ContentType: "application/octet-stream", Filename: filename, Size: n.File.Size, Filter: filterFunc, Compression: compressionFormat}
	err = s.Stream(false)
	if err != nil {
		// causes "multiple response.WriteHeader calls" error but better than no response
		err_msg := "err:@preAuth: s.stream: " + err.Error()
		logger.Error(err_msg)
		responder.RespondWithError(ctx, 500, err_msg)
	}
	return
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:41,代碼來源:preauth.go

示例8: unZip

func unZip(filePath string, unpackDir string) (fileList []FormFile, err error) {
	// open file with unzip
	zipReader, err := zip.OpenReader(filePath)
	if err != nil {
		return
	}

	// extract archive
	for _, zf := range zipReader.File {
		// set names
		path := filepath.Join(unpackDir, zf.Name)
		baseName := filepath.Base(zf.Name)
		// skip hidden
		if strings.HasPrefix(baseName, ".") {
			continue
		}

		if zf.FileInfo().IsDir() {
			// handle directory
			if merr := os.MkdirAll(path, 0777); merr != nil {
				logger.Error("err:@node_untar: " + err.Error())
			}
		} else {
			// open output file
			writer, werr := os.Create(path)
			if werr != nil {
				return nil, werr
			}
			// open input stream
			zfh, zerr := zf.Open()
			if zerr != nil {
				writer.Close()
				return nil, zerr
			}
			// get md5
			md5h := md5.New()
			dst := io.MultiWriter(writer, md5h)
			// write it
			_, err = io.Copy(dst, zfh)
			writer.Close()
			zfh.Close()
			if err != nil {
				return
			}
			// add to filelist
			ffile := FormFile{Name: baseName, Path: path, Checksum: make(map[string]string)}
			ffile.Checksum["md5"] = fmt.Sprintf("%x", md5h.Sum(nil))
			fileList = append(fileList, ffile)
		}
	}
	return
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:52,代碼來源:archive.go

示例9: Delete

// DELETE: /node/{id}
func (cr *NodeController) Delete(id string, ctx context.Context) error {
	u, err := request.Authenticate(ctx.HttpRequest())
	if err != nil && err.Error() != e.NoAuth {
		return request.AuthError(err, ctx)
	}

	if u == nil {
		return responder.RespondWithError(ctx, http.StatusUnauthorized, e.NoAuth)
	}

	// Load node and handle user unauthorized
	n, err := node.Load(id, u.Uuid)
	if err != nil {
		if err.Error() == e.UnAuth {
			return responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth)
		} else if err.Error() == e.MongoDocNotFound {
			return responder.RespondWithError(ctx, http.StatusNotFound, "Node not found")
		} else {
			// In theory the db connection could be lost between
			// checking user and load but seems unlikely.
			err_msg := "[email protected]_Read:Delete: " + err.Error()
			logger.Error(err_msg)
			return responder.RespondWithError(ctx, http.StatusInternalServerError, err_msg)
		}
	}

	rights := n.Acl.Check(u.Uuid)
	if !rights["delete"] {
		return responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth)
	}

	if err := n.Delete(); err == nil {
		return responder.RespondOK(ctx)
	} else {
		err_msg := "[email protected]_Delete:Delete: " + err.Error()
		logger.Error(err_msg)
		return responder.RespondWithError(ctx, http.StatusInternalServerError, err_msg)
	}
}
開發者ID:paczian,項目名稱:Shock,代碼行數:40,代碼來源:delete.go

示例10: Delete

// DELETE: /node/{id}
func (cr *Controller) Delete(id string, cx *goweb.Context) {
	request.Log(cx.Request)
	u, err := request.Authenticate(cx.Request)
	if err != nil && err.Error() != e.NoAuth {
		request.AuthError(err, cx)
		return
	}
	if u == nil {
		cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
		return
	}

	// Load node and handle user unauthorized
	n, err := node.Load(id, u.Uuid)
	if err != nil {
		if err.Error() == e.UnAuth {
			cx.RespondWithError(http.StatusUnauthorized)
			return
		} else if err.Error() == e.MongoDocNotFound {
			cx.RespondWithNotFound()
			return
		} else {
			// In theory the db connection could be lost between
			// checking user and load but seems unlikely.
			logger.Error("[email protected]_Read:Delete: " + err.Error())
			cx.RespondWithError(http.StatusInternalServerError)
			return
		}
	}

	if err := n.Delete(); err == nil {
		cx.RespondWithOK()
		return
	} else {
		logger.Error("[email protected]_Delet:Delete: " + err.Error())
		cx.RespondWithError(http.StatusInternalServerError)
	}
	return
}
開發者ID:jaredwilkening,項目名稱:Shock,代碼行數:40,代碼來源:delete.go

示例11: AclRequest

// GET, POST, PUT, DELETE: /node/{nid}/acl/
// GET is the only action implemented here.
func AclRequest(ctx context.Context) {
	nid := ctx.PathValue("nid")

	u, err := request.Authenticate(ctx.HttpRequest())
	if err != nil && err.Error() != e.NoAuth {
		request.AuthError(err, ctx)
		return
	}

	// acl require auth even for public data
	if u == nil {
		responder.RespondWithError(ctx, http.StatusUnauthorized, e.NoAuth)
		return
	}

	// Load node and handle user unauthorized
	n, err := node.Load(nid, u.Uuid)
	if err != nil {
		if err.Error() == e.UnAuth {
			responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth)
			return
		} else if err.Error() == e.MongoDocNotFound {
			responder.RespondWithError(ctx, http.StatusNotFound, "Node not found")
			return
		} else {
			// In theory the db connection could be lost between
			// checking user and load but seems unlikely.
			err_msg := "[email protected]_Read:LoadNode: " + err.Error()
			logger.Error(err_msg)
			responder.RespondWithError(ctx, http.StatusInternalServerError, err_msg)
			return
		}
	}

	rights := n.Acl.Check(u.Uuid)
	if ctx.HttpRequest().Method == "GET" {
		if u.Uuid == n.Acl.Owner || rights["read"] {
			responder.RespondWithData(ctx, n.Acl)
		} else {
			responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth)
			return
		}
	} else {
		responder.RespondWithError(ctx, http.StatusNotImplemented, "This request type is not implemented.")
	}
	return
}
開發者ID:narayandesai,項目名稱:Shock,代碼行數:49,代碼來源:acl.go

示例12: Handle

func (nr *NodeReaper) Handle() {
	waitDuration := time.Duration(conf.EXPIRE_WAIT) * time.Minute
	for {
		// sleep
		time.Sleep(waitDuration)
		// query to get expired nodes
		nodes := Nodes{}
		query := nr.getQuery()
		nodes.GetAll(query)
		// delete expired nodes
		for _, n := range nodes {
			logger.Info("access", "Deleting expired node: "+n.Id)
			if err := n.Delete(); err != nil {
				err_msg := "err:@node_delete: " + err.Error()
				logger.Error(err_msg)
			}
		}
	}
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:19,代碼來源:expire.go

示例13: authToken

// authToken validiates token by fetching user information.
func authToken(t string) (u *user.User, err error) {
	client := &http.Client{
		Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
	}
	req, err := http.NewRequest("GET", conf.AUTH_MGRAST_OAUTH_URL, nil)
	if err != nil {
		return nil, err
	}
	req.Header.Add("Auth", t)
	if resp, err := client.Do(req); err == nil {
		defer resp.Body.Close()
		if resp.StatusCode == http.StatusOK {
			if body, err := ioutil.ReadAll(resp.Body); err == nil {
				u = &user.User{}
				c := &credentials{}
				if err = json.Unmarshal(body, &c); err != nil {
					return nil, err
				} else {
					if c.Uname == "" {
						return nil, errors.New(e.InvalidAuth)
					}
					u.Username = c.Uname
					u.Fullname = c.Fname + " " + c.Lname
					u.Email = c.Email
					if err = u.SetMongoInfo(); err != nil {
						return nil, err
					}
				}
			}
		} else if resp.StatusCode == http.StatusForbidden {
			return nil, errors.New(e.InvalidAuth)
		} else {
			err_str := "Authentication failed: Unexpected response status: " + resp.Status
			logger.Error(err_str)
			return nil, errors.New(err_str)
		}
	} else {
		return nil, err
	}
	return
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:42,代碼來源:mgrast.go

示例14: FilesFromArchive

func FilesFromArchive(format string, filePath string) (fileList []FormFile, unpackDir string, err error) {
	// set unpack dir
	unpackDir = fmt.Sprintf("%s/temp/%d%d", conf.PATH_DATA, rand.Int(), rand.Int())
	if merr := os.Mkdir(unpackDir, 0777); merr != nil {
		logger.Error("err:@node_unpack: " + err.Error())
	}

	// magic to unpack archive
	if format == "zip" {
		fileList, err = unZip(filePath, unpackDir)
	} else if format == "tar" {
		fileList, err = unTar(filePath, unpackDir, "")
	} else if format == "tar.gz" {
		fileList, err = unTar(filePath, unpackDir, "gzip")
	} else if format == "tar.bz2" {
		fileList, err = unTar(filePath, unpackDir, "bzip2")
	} else {
		return nil, unpackDir, errors.New("invalid archive format. must be one of: " + ArchiveList)
	}
	return
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:21,代碼來源:archive.go

示例15: fetchProfile

// fetchProfile validiates token by using it to fetch user profile
func fetchProfile(t string) (u *user.User, err error) {
	client := &http.Client{
		Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
	}
	req, err := http.NewRequest("GET", conf.AUTH_GLOBUS_PROFILE_URL+"/"+clientId(t), nil)
	if err != nil {
		return nil, err
	}
	req.Header.Add("Authorization", "Globus-Goauthtoken "+t)
	if resp, err := client.Do(req); err == nil {
		defer resp.Body.Close()
		if resp.StatusCode == http.StatusOK {
			if body, err := ioutil.ReadAll(resp.Body); err == nil {
				u = &user.User{}
				if err = json.Unmarshal(body, &u); err != nil {
					return nil, err
				} else {
					if u.Username == "" {
						return nil, errors.New(e.InvalidAuth)
					}
					if err = u.SetMongoInfo(); err != nil {
						return nil, err
					}
				}
			}
		} else if resp.StatusCode == http.StatusForbidden {
			return nil, errors.New(e.InvalidAuth)
		} else {
			err_str := "Authentication failed: Unexpected response status: " + resp.Status
			logger.Error(err_str)
			return nil, errors.New(err_str)
		}
	} else {
		return nil, err
	}
	return
}
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:38,代碼來源:globus.go


注:本文中的github.com/MG-RAST/Shock/shock-server/logger.Error函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。