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


Golang errgo.Notef函数代码示例

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


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

示例1: pageShow

func pageShow(w http.ResponseWriter, r *http.Request, p httprouter.Params) *httphelper.HandlerError {
	l := httphelper.NewHandlerLogEntry(r)

	etype := p.ByName("type")
	project := p.ByName("project")

	l.Debug("Type: ", etype)
	l.Debug("Project: ", project)

	projects, err := helper.ProjectNamesFromArgs(dataStore, []string{project}, false)
	if err != nil {
		return httphelper.NewHandlerErrorDef(errgo.Notef(err, "can not get list of projects"))
	}

	err = dataStore.PopulateProjects(&projects)
	if err != nil {
		return httphelper.NewHandlerErrorDef(errgo.Notef(err, "can not populate projects with entries"))
	}

	buffer := new(bytes.Buffer)
	formatting.Projects(buffer, "Entries", 0, &projects)

	err = asciiDoctor(buffer, w)
	if err != nil {
		return httphelper.NewHandlerErrorDef(errgo.Notef(err, "can not format entries with asciidoctor"))
	}

	return nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:29,代码来源:pages.go

示例2: ParseTodo

func ParseTodo(values []string) (Todo, error) {
	if len(values) != 4 {
		return Todo{}, errgo.New("entry with the type todo needs exactly four fields")
	}

	etype, err := ParseEntryType(values[0])
	if err != nil {
		return Todo{}, errgo.Notef(err, "can not parse entry type")
	}
	if etype != EntryTypeTodo {
		return Todo{}, errgo.New("tried to parse a todo but got the entry type " + etype.String())
	}

	timestamp, err := time.Parse(TimeStampFormat, values[1])
	if err != nil {
		return Todo{}, errgo.Notef(err, "can not parse timestamp")
	}

	active, err := strconv.ParseBool(values[2])
	if err != nil {
		return Todo{}, errgo.Notef(err, "can not parse active state")
	}

	return Todo{Active: active, TimeStamp: timestamp, Value: values[3]}, nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:25,代码来源:todo.go

示例3: runCmdAddNote

func runCmdAddNote(cmd *cobra.Command, args []string) error {
	project, timestamp, value, err := helper.ArgsToEntryValues(args, flagAddTimeStamp, flagAddTimeStampRaw)
	if err != nil {
		return errgo.Notef(err, "can not convert args to entry usable values")
	}

	buffer := new(bytes.Buffer)

	if value != "-" {
		buffer.WriteString(value)
	}

	// If there is something piped in over stdin append it to the already set
	// value

	stat, _ := os.Stdin.Stat()
	if (stat.Mode() & os.ModeCharDevice) == 0 {
		io.Copy(buffer, os.Stdin)
	}

	note := data.Note{
		Value:     buffer.String(),
		TimeStamp: timestamp,
	}

	err = helper.RecordEntry(flagDataDir, project, note, flagAddAutoCommit)
	if err != nil {
		errgo.Notef(err, "can not record note to store")
	}

	return nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:32,代码来源:add.go

示例4: Put

func (db *DBFiles) Put(values []string, key ...string) error {
	record := record{
		values:  values,
		key:     key,
		basedir: db.BaseDir,
	}

	_, err := os.Stat(record.basedir)
	if os.IsNotExist(err) {
		err := db.Structure.Create(record.basedir)
		if err != nil {
			return errgo.Notef(err, "can not create structure")

		}
	}

	file, err := db.Structure.File(record.basedir, db.Driver, record.key)
	if err != nil {
		return errgo.Notef(err, "can not open file")
	}
	defer file.Close()

	err = db.Driver.Write(file, record.values)
	if err != nil {
		return errgo.Notef(err, "can not write values")
	}

	var data []byte
	io.ReadFull(file, data)
	log.Debug("Data: ", string(data))

	log.Debug("finished writing record: ", record)

	return err
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:35,代码来源:main.go

示例5: Listen

func Listen(datadir, binding string, loglevel log.Level) error {
	var err error
	dataStore, err = helper.DefaultStore(datadir)
	if err != nil {
		return errgo.Notef(err, "can not get data store")
	}

	router := httprouter.New()

	// Router handler
	router.MethodNotAllowed = httphelper.HandlerLoggerHTTP(httphelper.PageRouterMethodNotAllowed)
	router.NotFound = httphelper.HandlerLoggerHTTP(httphelper.PageRouterNotFound)

	// Root and Favicon
	router.GET("/", httphelper.HandlerLoggerRouter(pageRoot))
	router.GET("/favicon.ico", httphelper.HandlerLoggerRouter(pageFavicon))

	// Show
	router.GET("/show/:type/", httphelper.HandlerLoggerRouter(pageShow))
	router.GET("/show/:type/:project", httphelper.HandlerLoggerRouter(pageShow))

	log.Info("Listening on ", binding)
	err = http.ListenAndServe(binding, router)
	if err != nil {
		return errgo.Notef(err, "can not listen to binding")
	}

	return nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:29,代码来源:main.go

示例6: ProjectNamesFromArgs

// ProjectNamesFromArgs will return all projects or all projects with
// subprojects if the length of the args is not 0.
func ProjectNamesFromArgs(store store.Store, args []string, showarchive bool) (data.Projects, error) {
	projects, err := store.ListProjects(showarchive)
	if err != nil {
		return data.Projects{}, errgo.Notef(err, "can not get list of projects")
	}

	log.Debug("Args: ", args)

	out := data.NewProjects()
	if len(args) == 0 {
		out = projects
	} else {
		for _, arg := range args {
			name, err := data.ParseProjectName(arg)
			if err != nil {
				return data.Projects{}, errgo.Notef(err, "can not parse project name")
			}

			items := projects.List(data.Project{Name: name})
			for _, item := range items {
				out.Add(item)
			}
		}
	}

	return out, nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:29,代码来源:main.go

示例7: parseDockerPort

func parseDockerPort(input string, dp *Port) error {
	s := strings.Split(input, "/")

	switch len(s) {
	case 1:
		dp.Port = s[0]
		dp.Protocol = protocolTCP
	case 2:
		dp.Port = s[0]
		dp.Protocol = s[1]
	default:
		return errgo.Newf("Invalid format, must be either <port> or <port>/<prot>, got '%s'", input)
	}

	if parsedPort, err := strconv.Atoi(dp.Port); err != nil {
		return errgo.Notef(err, "Port must be a number, got '%s'", dp.Port)
	} else if parsedPort < 1 || parsedPort > 65535 {
		return errgo.Notef(err, "Port must be a number between 1 and 65535, got '%s'", dp.Port)
	}

	switch dp.Protocol {
	case "":
		return errgo.Newf("Protocol must not be empty.")
	case protocolUDP, protocolTCP:
		return nil
	default:
		return errgo.Newf("Unknown protocol: '%s' in '%s'", dp.Protocol, input)
	}
}
开发者ID:pulcy,项目名称:j2,代码行数:29,代码来源:port.go

示例8: TestNotef

func TestNotef(t *testing.T) {
	err0 := errgo.WithCausef(nil, someErr, "foo") //err TestNotef#0
	err := errgo.Notef(err0, "bar")               //err TestNotef#1
	checkErr(t, err, err0, "bar: foo", "[{$TestNotef#1$: bar} {$TestNotef#0$: foo}]", err)

	err = errgo.Notef(nil, "bar") //err TestNotef#2
	checkErr(t, err, nil, "bar", "[{$TestNotef#2$: bar}]", err)
}
开发者ID:howbazaar,项目名称:errgo,代码行数:8,代码来源:errors_test.go

示例9: TestNotef

func (*errorsSuite) TestNotef(c *gc.C) {
	err0 := errgo.WithCausef(nil, someErr, "foo") //err TestNotef#0
	err := errgo.Notef(err0, "bar")               //err TestNotef#1
	checkErr(c, err, err0, "bar: foo", "[{$TestNotef#1$: bar} {$TestNotef#0$: foo}]", err)

	err = errgo.Notef(nil, "bar") //err TestNotef#2
	checkErr(c, err, nil, "bar", "[{$TestNotef#2$: bar}]", err)
}
开发者ID:vnadgir-ef,项目名称:fleet-ui,代码行数:8,代码来源:errors_test.go

示例10: main

func main() {
	if FlagLogFile != "" {
		logfile, err := os.OpenFile(FlagLogFile, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0644)
		if err != nil {
			log.Fatal(errgo.Notef(err, "can not open logfile for writing"))
		}
		defer logfile.Close()

		log.SetOutput(logfile)
	}

	log.Info("Starting buchführung api v", BuildVersion, " +", BuildTime)

	err := initDatabase()
	if err != nil {
		log.Fatal(errgo.Notef(err, "can not initialize database"))
	}

	go func() {
		router := httprouter.New()

		// Router handler
		router.MethodNotAllowed = httphelper.HandlerLoggerHTTP(httphelper.PageRouterMethodNotAllowed)
		router.NotFound = httphelper.HandlerLoggerHTTP(httphelper.PageRouterNotFound)

		// Root and Favicon
		router.GET("/", httphelper.HandlerLoggerRouter(pageRoot))
		router.GET("/favicon.ico", httphelper.HandlerLoggerRouter(httphelper.PageMinimalFavicon))

		// API v0
		// Accounts
		router.POST("/api/v0/account/add", httphelper.HandlerLoggerRouter(pageAPIV0AccountAdd))
		router.GET("/api/v0/account/get/byid/:id", httphelper.HandlerLoggerRouter(pageAPIV0AccountGetByID))
		router.GET("/api/v0/account/get/byname/:name", httphelper.HandlerLoggerRouter(pageAPIV0AccountGetByName))
		router.GET("/api/v0/account/list", httphelper.HandlerLoggerRouter(pageAPIV0AccountList))

		// Transactions
		router.POST("/api/v0/transaction/add", httphelper.HandlerLoggerRouter(pageAPIV0TransactionAdd))
		router.GET("/api/v0/transaction/get/byid/:id", httphelper.HandlerLoggerRouter(pageAPIV0TransactionGetByID))
		router.GET("/api/v0/transaction/list", httphelper.HandlerLoggerRouter(pageAPIV0TransactionList))

		log.Info("Start serving api on ", FlagBindingAPI)
		log.Fatal(http.ListenAndServe(FlagBindingAPI, router))
	}()

	go func() {
		if FlagBindingMetrics != "" {
			log.Info("Starting Metrics", FlagBindingMetrics)
			http.Handle("/metrics", prometheus.Handler())
			http.ListenAndServe(FlagBindingMetrics, nil)
		}
	}()

	log.Debug("Waiting for interrupt signal")
	httphelper.WaitForStopSignal()
	log.Info("Stopping")
}
开发者ID:AlexanderThaller,项目名称:buchfuehrung,代码行数:57,代码来源:main.go

示例11: PageMinimalFavicon

func PageMinimalFavicon(w http.ResponseWriter, r *http.Request, p httprouter.Params) *HandlerError {
	raw, err := Asset("data/favicon.ico")
	if err != nil {
		return NewHandlerErrorDef(errgo.Notef(err, "can not read raw page"))
	}

	_, err = w.Write(raw)
	if err != nil {
		return NewHandlerErrorDef(errgo.Notef(err, "can not write raw data to responsewriter"))
	}

	return nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:13,代码来源:page.go

示例12: getAssetTemplate

func getAssetTemplate(asset string) (*template.Template, error) {
	rawtmpl, err := Asset(asset)
	if err != nil {
		return nil, errgo.Notef(err, "can not get asset: "+asset)
	}

	tmpl, err := template.New(asset).Parse(string(rawtmpl))
	if err != nil {
		return nil, errgo.Notef(err, "can not parse template for asset: "+asset)
	}

	return tmpl, nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:13,代码来源:main.go

示例13: pageFavicon

func pageFavicon(w http.ResponseWriter, r *http.Request, p httprouter.Params) *httphelper.HandlerError {
	raw, err := Asset("templates/trivago-folder.ico")
	if err != nil {
		return httphelper.NewHandlerErrorDef(errgo.Notef(err, "can not read raw page"))
	}

	_, err = w.Write(raw)
	if err != nil {
		return httphelper.NewHandlerErrorDef(errgo.Notef(err, "can not write raw data to responsewriter"))
	}

	return nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:13,代码来源:pages.go

示例14: runWeb

func runWeb(cmd *cobra.Command, args []string) error {
	level, err := log.ParseLevel(flagLogLevel)
	if err != nil {
		return errgo.Notef(err, "can not parse loglevel from flag")
	}

	err = web.Listen(flagDataDir, flagWebBinding, level)
	if err != nil {
		return errgo.Notef(err, "can not start web listener")
	}

	return nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:13,代码来源:web.go

示例15: Get

func (db DBFiles) Get(key ...string) ([][]string, error) {
	file, err := db.Structure.File(db.BaseDir, db.Driver, key)
	if err != nil {
		return nil, errgo.Notef(err, "can not open file")
	}

	values, err := db.Driver.Read(file)
	if err != nil {
		return nil, errgo.Notef(err, "can not read values")
	}

	return values, nil
}
开发者ID:AlexanderThaller,项目名称:lablog,代码行数:13,代码来源:main.go


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