当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.Newf函数代码示例

本文整理汇总了Golang中gate/core/errors.Newf函数的典型用法代码示例。如果您正苦于以下问题:Golang Newf函数的具体用法?Golang Newf怎么用?Golang Newf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Newf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Merge

func (self *serverImpl) Merge(args server.MergeArgs, reply *bool) (err error) {
	log.Printf("Merge(vault='%s', master='***')", args.Vault)
	if !self.vault.IsOpen() {
		return errors.Newf("Vault is not open: cannot merge")
	}
	vault := newVault(args.Vault)
	err = vault.Open(args.Master, self.config)
	if err != nil {
		return
	}
	if !vault.IsOpen() {
		return errors.Newf("Merge vault is not open: cannot merge")
	}
	err = self.vault.Merge(vault)
	if err != nil {
		vault.Close(self.config)
		return
	}
	err = vault.Close(self.config)
	if err != nil {
		return
	}
	*reply = true
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:25,代码来源:server.go

示例2: Run

func (self *cmd_master) Run(line []string) (err error) {
	pass1, err := self.mmi.ReadPassword("Please enter the new master password")
	if err != nil {
		return
	}
	if pass1 == "" {
		err = errors.Newf("Cancelled")
		return
	}

	pass2, err := self.mmi.ReadPassword("Please enter the new master password (again)")
	if err != nil {
		return
	}

	if pass1 != pass2 {
		err = errors.Newf("Passwords don't match")
		return
	}

	var changed bool
	err = self.server.SetMaster(pass1, &changed)
	if err != nil {
		return
	}

	if !changed {
		err = errors.Newf("Could not change master")
	}

	return
}
开发者ID:cadrian,项目名称:gate,代码行数:32,代码来源:cmd_master.go

示例3: rawValue

func (self *config) rawValue(file string, section string, key string) (result string, err error) {
	f, err := self.findFile(file)
	if err != nil {
		return
	}

	var ok bool
	var sec *rc.Section
	if section == "" {
		sec = f.Anonymous
		if sec == nil {
			return "", errors.Newf("No anonymous section in file %s", section, f.Name)
		}
	} else {
		sec, ok = f.Sections[section]
		if !ok {
			return "", errors.Newf("Unknown section [%s] in file %s", section, f.Name)
		}
	}
	result, ok = sec.Resources[key]
	if !ok {
		return "", errors.Newf("Unknown key %s in section [%s] of file %s", key, section, f.Name)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:25,代码来源:config.go

示例4: parse_ingredient

func (self *parse_generator_context) parse_ingredient() (err error) {
	self.last_ingredient = ""
	for self.index < len(self.source) {
		switch b := self.source[self.index]; b {
		case 'a':
			self.last_ingredient = self.last_ingredient + letters
			self.index++
		case 'n':
			self.last_ingredient = self.last_ingredient + figures
			self.index++
		case 's':
			self.last_ingredient = self.last_ingredient + symbols
			self.index++
		case '+':
			self.index++
			break
		default:
			err = errors.Newf("expected one of 'a', 'n', 's', '+'; not '%v'", rune(b))
			break
		}
	}
	if err == nil && self.last_ingredient == "" {
		if self.last_quantity == 0 {
			err = errors.Newf("expected ingredient or quantity at %d", self.index)
		} else {
			err = errors.Newf("expected ingredient at %d", self.index)
		}
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:30,代码来源:pass_generator.go

示例5: setProperty

func (self *properties) setProperty(key, value string) (err error) {
	for k, mandatory := range self.allowed {
		if k == key {
			if value == "" && mandatory {
				err = errors.Newf("cannot reset '%s': mandatory property", key)
			} else {
				self.properties[key] = value
			}
			return
		}
	}
	return errors.Newf("key not allowed: %s", key)
}
开发者ID:cadrian,项目名称:gate,代码行数:13,代码来源:properties.go

示例6: Get

func (self *serverImpl) Get(name string, reply *string) (err error) {
	log.Printf("Get(name='%s')", name)
	if !self.vault.IsOpen() {
		return errors.Newf("Vault is not open: cannot get %s", name)
	}
	key, err := self.vault.Item(name)
	if err != nil {
		return
	}
	if key == nil || key.IsDeleted() {
		return errors.Newf("Unknown key %s", name)
	}
	*reply = key.Password()
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:15,代码来源:server.go

示例7: readRemote

func (self *remoter) readRemote(name string) (result Remote, err error) {
	method, err := self.config.Eval(name+".rc", "remote", "method", nil)
	if err != nil {
		return
	}
	switch method {
	case "curl":
		result, err = newCurl(name, self.server, self.config, self)
	case "":
		err = errors.Newf("Unknown remote: %s", name)
	default:
		err = errors.Newf("Unknown remote method: %s", method)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:15,代码来源:remote.go

示例8: Next

// Go to the next character, if possible.
func (self *FileContent) Next() error {
	if self.index > len(self.data) {
		return errors.Newf("cannot go next, index out of range: %d > %d", self.index, len(self.data))
	}
	self.index++
	return nil
}
开发者ID:cadrian,项目名称:gate,代码行数:8,代码来源:lexer.go

示例9: arguments

func (self *curl) arguments(option, file, request string) (result []string, err error) {
	url := self.getProperty("url")
	if url == "" {
		err = errors.Newf("missing remote vault url")
		return
	}
	result = []string{"-#", option, file, url}
	user := self.getProperty("user")
	passkey := self.getProperty("passkey")
	if user != "" {
		if passkey == "" {
			result = append(result, "-u", user)
		} else {
			var pass string
			err = self.server.Get(passkey, &pass)
			if err != nil {
				return
			}
			result = append(result, "-u", fmt.Sprintf("%s:%s", user, escape_pass_url(pass)))
		}
	}
	if request != "" {
		result = append(result, "--request", request)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:26,代码来源:curl.go

示例10: Item

func (self *vault) Item(name string) (result Key, err error) {
	result, ok := self.data[name]
	if !ok {
		err = errors.Newf("Unknown key: %s", name)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:7,代码来源:vault.go

示例11: Back

// Go to the previous character, if possible.
func (self *FileContent) Back() error {
	if self.index < 0 {
		return errors.Newf("cannot go back, index out of range: %d < 0", self.index)
	}
	self.index--
	return nil
}
开发者ID:cadrian,项目名称:gate,代码行数:8,代码来源:lexer.go

示例12: Run

func (self *cmd_save) Run(line []string) (err error) {
	var remoteName string
	if len(line) > 1 {
		remoteName = line[1]
	} else {
		remoteName = ""
	}

	remote, err := self.remoter.Remote(remoteName)
	if err != nil {
		return
	}

	vault_path, err := self.config.VaultPath()
	if err != nil {
		return
	}

	var saved bool
	err = self.server.Save(true, &saved)
	if err != nil {
		return
	}
	if !saved {
		err = errors.Newf("Could not save vault")
		return
	}

	err = remote.SaveVault(vault_path)

	return
}
开发者ID:cadrian,项目名称:gate,代码行数:32,代码来源:cmd_save.go

示例13: Current

// The current character.
func (self *FileContent) Current() (result rune, err error) {
	if !self.IsValid() {
		return 0, errors.Newf("invalid current character at index %d", self.index)
	}
	result = self.data[self.index]
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:8,代码来源:lexer.go

示例14: resetProperty

func (self *properties) resetProperty(key string) (err error) {
	if self.allowed[key] {
		err = errors.Newf("cannot reset '%s': mandatory property", key)
	} else {
		delete(self.properties, key)
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:8,代码来源:properties.go

示例15: List

func (self *serverImpl) List(filter string, reply *[]string) (err error) {
	log.Printf("List(filter='%s')", filter)
	if !self.vault.IsOpen() {
		return errors.Newf("Vault is not open: cannot list")
	}
	*reply, err = self.vault.List(filter)
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:8,代码来源:server.go


注:本文中的gate/core/errors.Newf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。