• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang errors.Newf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: SetMaster

func (self *vault) SetMaster(master string) (err error) {
	if master == "" {
		err = errors.Newf("empty master not allowed")
	} else {
		self.master = master
		self.dirty = true
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:9,代码来源:vault.go


示例17: Open

func (self *serverImpl) Open(master string, reply *bool) (err error) {
	log.Printf("Open(master='***')")
	if self.vault.IsOpen() {
		return errors.Newf("Vault is already open: cannot open")
	}
	err = self.vault.Open(master, self.config)
	*reply = err == nil
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:9,代码来源:server.go


示例18: Unset

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


示例19: SetMaster

func (self *serverImpl) SetMaster(master string, reply *bool) (err error) {
	log.Printf("SetMaster(master='***')")
	if !self.vault.IsOpen() {
		return errors.Newf("Vault is not open: cannot set master")
	}
	err = self.vault.SetMaster(master)
	if err == nil {
		*reply = true
	}
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:11,代码来源:server.go


示例20: Save

func (self *serverImpl) Save(force bool, reply *bool) (err error) {
	log.Printf("Save(force=%t)", force)
	if !self.vault.IsOpen() {
		return errors.Newf("Vault is not open: cannot save")
	}
	err = self.vault.Save(force, self.config)
	if err != nil {
		return
	}
	*reply = true
	return
}
开发者ID:cadrian,项目名称:gate,代码行数:12,代码来源:server.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang common.LogString类代码示例发布时间:2022-05-24
下一篇:
Golang errors.Decorated函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap