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


Golang errors.Wrapf函數代碼示例

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


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

示例1: extract

func (s *Source) extract() (err error) {
	var cmd *exec.Cmd

	if strings.HasSuffix(s.Path, ".tar") {
		cmd = exec.Command("tar", "--no-same-owner", "-xf", s.Path)
	} else if strings.HasSuffix(s.Path, ".zip") {
		cmd = exec.Command("unzip", s.Path)
	} else {
		split := strings.Split(s.Path, ".")
		if len(split) > 2 && split[len(split)-2] == "tar" {
			cmd = exec.Command("tar", "--no-same-owner", "-xf", s.Path)
		} else {
			return
		}
	}

	cmd.Dir = s.Output
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	err = cmd.Run()
	if err != nil {
		err = &GetError{
			errors.Wrapf(err, "builder: Failed to extract source '%s'",
				s.Source),
		}
		return
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:31,代碼來源:source.go

示例2: Init

func (p *Project) Init() (err error) {
	p.MirrorRoot = filepath.Join(p.Root, "mirror")
	p.BuildRoot = filepath.Join(p.Root, "mirror.tmp")
	p.confPath = filepath.Join(p.Root, "pacur.json")

	exists, err := utils.Exists(p.confPath)
	if err != nil {
		return
	}

	if exists {
		dataByt, e := utils.ReadFile(p.confPath)
		if e != nil {
			err = e
			return
		}

		data := conf{}

		err = json.Unmarshal(dataByt, &data)
		if err != nil {
			err = &ParseError{
				errors.Wrapf(err,
					"project: Failed to parse project conf '%s'", p.confPath),
			}
			return
		}

		p.Name = data.Name
	} else {
		p.Name = "pacur"
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:35,代碼來源:project.go

示例3: Page

func Page(q PageQuery) (*PageResponse, error) {

	if q.ID == 0 {
		return nil, errors.New("a page id is required")
	}

	resp, err := http.Get(q.urlString())
	if err != nil {
		return nil, errors.Wrap(err, "could not get http response")
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return nil, errors.Wrapf(errors.New(resp.Status), "StatusCode: %d; URL: %s", resp.StatusCode, q.urlString())
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, errors.Wrap(err, "could not read http response body")
	}

	var response PageResponse
	if err := json.Unmarshal(body, &response); err != nil {
		return nil, errors.Wrap(err, "could not unmarshal http response")
	}

	return &response, nil

}
開發者ID:heindl,項目名稱:eol,代碼行數:29,代碼來源:pages.go

示例4: Project

func Project() (err error) {
	path, err := os.Getwd()
	if err != nil {
		err = &FileError{
			errors.Wrapf(err, "cmd: Failed to get working directory"),
		}
		return
	}

	proj := &project.Project{
		Root: path,
	}
	err = proj.Init()
	if err != nil {
		return
	}

	cmd := flag.Arg(1)
	switch cmd {
	case "init":
		err = proj.InitProject()
	case "build":
		err = proj.Build(flag.Arg(2))
	case "repo":
		err = proj.Repo(flag.Arg(2))
	default:
		err = &UnknownCommand{
			errors.Newf("cmd: Unknown cmd '%s'", cmd),
		}
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:33,代碼來源:project.go

示例5: ExecInput

func ExecInput(dir, input, name string, arg ...string) (err error) {
	cmd := exec.Command(name, arg...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	stdin, err := cmd.StdinPipe()
	if err != nil {
		err = &ExecError{
			errors.Wrapf(err, "utils: Failed to get stdin in exec '%s'", name),
		}
		return
	}
	defer stdin.Close()

	if dir != "" {
		cmd.Dir = dir
	}

	err = cmd.Start()
	if err != nil {
		err = &ExecError{
			errors.Wrapf(err, "utils: Failed to exec '%s'", name),
		}
		return
	}

	_, err = io.WriteString(stdin, input)
	if err != nil {
		err = &ExecError{
			errors.Wrapf(err, "utils: Failed to write stdin in exec '%s'",
				name),
		}
		return
	}

	err = cmd.Wait()
	if err != nil {
		err = &ExecError{
			errors.Wrapf(err, "utils: Failed to exec '%s'", name),
		}
		return
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:45,代碼來源:proc.go

示例6: connectionError

func (c *ShardedClient) connectionError(shard int, err error) error {
	if err == nil {
		return errors.Newf(
			"Connection unavailable for memcache shard %d", shard)
	}
	return errors.Wrapf(
		err,
		"Connection unavailable for memcache shard %d", shard)
}
開發者ID:pasin30055,項目名稱:godropbox,代碼行數:9,代碼來源:sharded_client.go

示例7: request

func request(url string, tokens []string) ([]byte, error) {

	if len(tokens) == 0 {
		return nil, errors.New("a NOAA token is required to draw data from the API. Request one here: http://www.ncdc.noaa.gov/cdo-web/token.")
	}

	client := &http.Client{}

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, errors.Wrapf(err, "could not build request for url[%s]", url)
	}

	req.Header.Set("token", tokens[0])

	response, err := client.Do(req)
	if err != nil {
		return nil, errors.Wrapf(err, "could not do request for url[%s]", url)
	}
	defer response.Body.Close()

	// "status" : "429", "message" : "This token has reached its temporary request limit of 1000 per day."
	// Rotate through tokens to try and find another.
	if response.StatusCode == 429 {

		if len(tokens) == 1 {
			return nil, errors.New("All NOAA API tokens have reached their request limit for today. Add more or come back tomorrow.")
		}

		tokens = tokens[1:]

		return request(url, tokens)

	}

	if response.StatusCode != 200 {
		return nil, errors.Newf("NOAA API response statusCode is %d", response.StatusCode)
	}

	return ioutil.ReadAll(response.Body)

}
開發者ID:heindl,項目名稱:raincollector,代碼行數:42,代碼來源:request.go

示例8: RemoveAll

func RemoveAll(path string) (err error) {
	err = os.RemoveAll(path)
	if err != nil {
		err = &WriteError{
			errors.Wrapf(err, "utils: Failed to remove '%s'", path),
		}
		return
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:11,代碼來源:file.go

示例9: Chmod

func Chmod(path string, perm os.FileMode) (err error) {
	err = os.Chmod(path, perm)
	if err != nil {
		err = &WriteError{
			errors.Wrapf(err, "utils: Failed to chmod '%s'", path),
		}
		return
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:11,代碼來源:file.go

示例10: Open

func Open(path string) (file *os.File, err error) {
	file, err = os.Open(path)
	if err != nil {
		err = &ReadError{
			errors.Wrapf(err, "utils: Failed to open file '%s'", path),
		}
		return
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:11,代碼來源:file.go

示例11: ReadDir

func ReadDir(path string) (items []os.FileInfo, err error) {
	items, err = ioutil.ReadDir(path)
	if err != nil {
		err = &ReadError{
			errors.Wrapf(err, "utils: Failed to read dir '%s'", path),
		}
		return
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:11,代碼來源:file.go

示例12: ReadFile

func ReadFile(path string) (data []byte, err error) {
	data, err = ioutil.ReadFile(path)
	if err != nil {
		err = &ReadError{
			errors.Wrapf(err, "utils: Failed to read file '%s'", path),
		}
		return
	}

	return
}
開發者ID:pacur,項目名稱:pacur,代碼行數:11,代碼來源:file.go

示例13: MkdirAll

func MkdirAll(path string) (err error) {
	err = os.MkdirAll(path, 0755)
	if err != nil {
		err = &constants.WriteError{
			errors.Wrapf(err, "utils: Failed to create '%s'", path),
		}
		return
	}

	return
}
開發者ID:postfix,項目名稱:pritunl-auth,代碼行數:11,代碼來源:file.go

示例14: Create

func Create(path string) (file *os.File, err error) {
	file, err = os.Create(path)
	if err != nil {
		err = &constants.WriteError{
			errors.Wrapf(err, "utils: Failed to create '%s'", path),
		}
		return
	}

	return
}
開發者ID:postfix,項目名稱:pritunl-auth,代碼行數:11,代碼來源:file.go

示例15: Read

func Read(path string) (data string, err error) {
	dataByt, err := ioutil.ReadFile(path)
	if err != nil {
		err = &constants.ReadError{
			errors.Wrapf(err, "utils: Failed to read '%s'", path),
		}
		return
	}
	data = string(dataByt)

	return
}
開發者ID:postfix,項目名稱:pritunl-auth,代碼行數:12,代碼來源:file.go


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