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


Golang log.Stderrf函数代码示例

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


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

示例1: ParseGameState

func ParseGameState(lines []string) *PlanetWars {
	pw := &PlanetWars{make([]*Planet, len(lines)), make([]*Fleet, len(lines))}
	pNum, fNum := 0, 0

	for _, ln := range lines {

		switch ln[0] {
		case 'P':
			p := &Planet{ID: pNum}
			read, e := fmt.Sscanf(ln[2:], "%f %f %d %d %d", &p.X, &p.Y, &p.Owner, &p.NumShips, &p.GrowthRate)

			if read < 5 || e != nil {
				log.Stderrf("Bad line in input: %s\n", ln)
			}
			pw.Planets[pNum] = p
			pNum++
		case 'F':
			f := &Fleet{ID: fNum}
			read, e := fmt.Sscanf(ln[2:], "%d %d %d %d %d", &f.Owner, &f.NumShips, &f.Source, &f.Dest, &f.TripLength, &f.TurnsRemaining)

			if read < 5 || e != nil {
				log.Stderrf("Bad line in input: %s\n", ln)
			}
			pw.Fleets[fNum] = f
			fNum++
		default:
			log.Stderr("Error parsing gamestate: First char of line not 'P' or 'F'\n")
			return nil
		}
	}

	pw.Fleets = pw.Fleets[0:fNum]
	pw.Planets = pw.Planets[0:pNum]
	return pw
}
开发者ID:vil1,项目名称:ai-contest,代码行数:35,代码来源:PlanetWars.go

示例2: main

func main() {
	flag.Parse()
	if len(*deliciousUser) == 0 || len(*deliciousPassword) == 0 {
		log.Stderrf("Missing user or password.\n\n")
		flag.Usage()
		os.Exit(2)
	}
	if strings.HasPrefix(*deliciousUrl, "http://") != true {
		log.Stderrf("URL missing 'http://' prefix. HTTPS is currently NOT supported.\n\n")
		flag.Usage()
		os.Exit(2)
	}
	userInfo := strings.Split(*deliciousUrl, "http://", 2)[1]
	url := fmt.Sprintf("http://%s:%[email protected]%s", *deliciousUser, *deliciousPassword, userInfo)

	b, err := readData(url)
	if err != nil {
		log.Stderrf("Error downloading %s: %s", url, err)
		os.Exit(1)
	}
	err = saveBackup(b)
	if err != nil {
		log.Stderrf("Error saving file to disk %s", err)
		os.Exit(1)
	}
}
开发者ID:nictuku,项目名称:Cloud-Backups,代码行数:26,代码来源:delicious.go

示例3: getPageInfo

// getPageInfo returns the PageInfo for a package directory path. If the
// parameter try is true, no errors are logged if getPageInfo fails.
// If there is no corresponding package in the directory,
// PageInfo.PDoc is nil. If there are no subdirectories,
// PageInfo.Dirs is nil.
//
func (h *httpHandler) getPageInfo(path string, try bool) PageInfo {
	// the path is relative to h.fsroot
	dirname := pathutil.Join(h.fsRoot, path)

	// the package name is the directory name within its parent
	// (use dirname instead of path because dirname is clean; i.e. has no trailing '/')
	_, pkgname := pathutil.Split(dirname)

	// filter function to select the desired .go files
	filter := func(d *os.Dir) bool {
		if isPkgFile(d) {
			// Some directories contain main packages: Only accept
			// files that belong to the expected package so that
			// parser.ParsePackage doesn't return "multiple packages
			// found" errors.
			// Additionally, accept the special package name
			// fakePkgName if we are looking at cmd documentation.
			name := pkgName(dirname + "/" + d.Name)
			return name == pkgname || h.fsRoot == *cmdroot && name == fakePkgName
		}
		return false
	}

	// get package AST
	pkgs, err := parser.ParseDir(dirname, filter, parser.ParseComments)
	if err != nil && !try {
		// TODO: errors should be shown instead of an empty directory
		log.Stderrf("parser.parseDir: %s", err)
	}
	if len(pkgs) != 1 && !try {
		// TODO: should handle multiple packages
		log.Stderrf("parser.parseDir: found %d packages", len(pkgs))
	}
	var pkg *ast.Package
	for _, pkg = range pkgs {
		break // take the first package found
	}

	// compute package documentation
	var pdoc *doc.PackageDoc
	if pkg != nil {
		ast.PackageExports(pkg)
		pdoc = doc.NewPackageDoc(pkg, pathutil.Clean(path)) // no trailing '/' in importpath
	}

	// get directory information
	var dir *Directory
	if tree, _ := fsTree.get(); tree != nil {
		// directory tree is present; lookup respective directory
		// (may still fail if the file system was updated and the
		// new directory tree has not yet beet computed)
		dir = tree.(*Directory).lookup(dirname)
	} else {
		// no directory tree present (either early after startup
		// or command-line mode); compute one level for this page
		dir = newDirectory(dirname, 1)
	}

	return PageInfo{pdoc, dir.listing(true), h.isPkg}
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:66,代码来源:godoc.go

示例4: DEFAULT

// TODO: need uuid for session
// TODO: cookie domain site param?
// TODO: cookie exparation
func DEFAULT(c *http.Conn, req *http.Request) {
	s := session_service.GetSession(c,req);
	log.Stderrf("session data id:%s", s.Id);
	for k,v := range s.Data {
		log.Stderrf("session kv:%s:%s", k, v);
	}
	var defaultTemplate = get_template("default.html");
	defaultTemplate.Execute(s.Id, c);
}
开发者ID:montsamu,项目名称:go-twitter-oauth,代码行数:12,代码来源:example.go

示例5: Create

func (this *Model) Create(param string) *Instance {
	p := Parameterize(param)
	id, err := this.NextId()
	if err != nil {
		log.Stderrf("Impossible to create an instance of %s", this.name, err)
		return nil
	}
	err = this.Set(p, string(id))
	if err != nil {
		log.Stderrf("Impossible to create an instance of %s", this.name, err)
		return nil
	}
	return &Instance{this, id, p}
}
开发者ID:nono,项目名称:Goldorak.Go,代码行数:14,代码来源:model.go

示例6: Get

// TODO: malicious ids
func (ps *PersistService) Get(id string) (*Model, bool) {
	log.Stderrf("PS:GET:%s", id);
	mpath := path.Join(ps.Path, id);
	log.Stderrf("PS:GET:path:%s", mpath);
	bs, e := io.ReadFile(mpath);
	// TODO: check error more specifically (not found, etc.)
	if e != nil {
		log.Stderrf("PS:GET:e:%s", e);
		return nil, false;
	}
	else {
		return parse_model(id, bs), true;
	}
	panic("unreachable");
}
开发者ID:montsamu,项目名称:go-twitter-oauth,代码行数:16,代码来源:persist.go

示例7: Del

func (ps *PersistService) Del(id string) os.Error {
	// TODO: malicious id path
	log.Stderrf(":DEL:id:%s", id);
	mpath := path.Join(ps.Path, id);
	e := os.Remove(mpath);
	return e;
}
开发者ID:montsamu,项目名称:go-twitter-oauth,代码行数:7,代码来源:persist.go

示例8: run

func (l *listenConn) run() {
	log.Stderrf("listening on %s\n", l.listen.Addr())
	// TODO a way to shut this down
	for {
		conn, err := l.listen.Accept()
		if err != nil {
			log.Stderrf("accept failed: %s\n", err)
			l.listen.Close()
			if l.error != nil {
				l.error(err)
			}
			return
		}
		l.accept(conn)
	}
}
开发者ID:stefanha,项目名称:bouncin,代码行数:16,代码来源:listenconn.go

示例9: applyTemplate

func applyTemplate(t *template.Template, name string, data interface{}) []byte {
	var buf bytes.Buffer
	if err := t.Execute(data, &buf); err != nil {
		log.Stderrf("%s.Execute: %s", name, err)
	}
	return buf.Bytes()
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:7,代码来源:godoc.go

示例10: Save

// Saves the database to the friend db file that was used to read it
// TODO: This should be checkpointed to prevent data loss
func (db *buttress) Save() os.Error {
	// Convert to json
	me := db.me
	jm := jsonMe{
		Id:      me.Id.String(),
		SigKey:  me.SignatureKey.String(),
		Name:    me.Name,
		Email:   me.Email,
		Addr:    me.Addr,
		ExtAddr: me.ExtAddr,
	}
	book := &jsonDb{jm, make([]jsonFriend, len(db.recs))}
	k := 0
	for _, v := range db.recs {
		jf := jsonFriend{
			Slot:  strconv.Itoa(v.Slot),
			Name:  v.Name,
			Email: v.Email,
			Addr:  v.Addr,
			Rest:  v.Rest,
		}
		if v.Id != nil {
			jf.Id = v.Id.String()
		}
		if v.SignatureKey != nil {
			jf.SigKey = v.SignatureKey.String()
		}
		if v.HelloKey != nil {
			jf.HelloKey = v.HelloKey.String()
		}
		if v.DialKey != nil {
			jf.DialKey = v.DialKey.String()
		}
		if v.AcceptKey != nil {
			jf.AcceptKey = v.AcceptKey.String()
		}
		book.Friends[k] = jf
		k++
	}
	// Open file
	file, err := os.Open(db.path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		log.Stderrf("Cannot open friends file \"%s\"\n", db.path)
		return &Error{ErrSave, err}
	}
	// Marshal to json string
	data, err := json.Marshal(&book)
	if err != nil {
		return &Error{ErrEncode, err}
	}
	bf := bytes.NewBuffer(data)
	n, err := io.Copy(file, bf)
	if err != nil || n != int64(len(data)) {
		return &Error{ErrEncode, err}
	}
	if err := file.Close(); err != nil {
		return &Error{ErrSave, err}
	}
	return nil
}
开发者ID:fedgrant,项目名称:tonika,代码行数:62,代码来源:db.go

示例11: readOb

func readOb(s net.Conn, buf []byte) {
	x, err := io.ReadFull(s, buf)
	if err != nil || x != len(buf) {
		log.Stderrf("Error reading part: %s", err)
		runtime.Goexit()
	}
}
开发者ID:andradeandrey,项目名称:gomemcached,代码行数:7,代码来源:mc_conn_handler.go

示例12: handleScgiRequest

func handleScgiRequest(fd io.ReadWriteCloser) {
	var buf bytes.Buffer
	var tmp [1024]byte
	n, err := fd.Read(&tmp)
	if err != nil || n == 0 {
		return
	}

	colonPos := bytes.IndexByte(tmp[0:], ':')

	read := n
	length, _ := strconv.Atoi(string(tmp[0:colonPos]))
	buf.Write(tmp[0:n])

	for read < length {
		n, err := fd.Read(&tmp)
		if err != nil || n == 0 {
			break
		}

		buf.Write(tmp[0:n])
		read += n
	}

	req, err := readScgiRequest(&buf)

	if err != nil {
		log.Stderrf("SCGI read error", err.String())
		return
	}

	sc := scgiConn{fd, make(map[string][]string), false}
	routeHandler(req, &sc)
	fd.Close()
}
开发者ID:sschober,项目名称:web.go,代码行数:35,代码来源:scgi.go

示例13: TestServerClient

func TestServerClient(t *testing.T) {
	port := empty_port()
	ok(t, port != 0, "empty_port")
	log.Stderrf("got empty port: %d", port)

	addr := fmt.Sprintf("localhost:%d", port)
	go RunServer(addr)

	time.Sleep(int64(1) * 1e8) // wait for Server started

	client, err := NewClient(addr)
	ok(t, err == nil, "NewClient()")

	var value string
	value, err = client.Get("xxx")
	ok(t, err == nil, "")
	ok(t, value == "", "client.Get(xxx) == \"\"")

	for i := 0; i < 10; i++ {
		key := fmt.Sprintf("key_%d", i)
		val := fmt.Sprintf("val_%d", i)

		_, err = client.Set(key, val)
		ok(t, err == nil, fmt.Sprintf("client.Set(%s,%s)", key, val))

		value, err = client.Get(key)
		ok(t, err == nil, "")
		ok(t, value == val, fmt.Sprintf("client.Get(%s)", key))
	}
}
开发者ID:ike-dai,项目名称:go-simple-kvs,代码行数:30,代码来源:kvs_test.go

示例14: Find

func (this *Model) Find(param string) *Instance {
	value, err := this.Get(param)
	if err != nil {
		log.Stderrf("Impossible to find %s (%s)", param, this.name, err)
		return nil
	}
	if value == "" {
		return nil
	}
	id, err := strconv.Atoi64(value)
	if err != nil {
		log.Stderrf("Impossible to convert %s to int", value, err)
		return nil
	}
	return &Instance{this, id, param}
}
开发者ID:nono,项目名称:Goldorak.Go,代码行数:16,代码来源:model.go

示例15: search

func search(c *http.Conn, r *http.Request) {
	query := strings.TrimSpace(r.FormValue("q"))
	var result SearchResult

	if index, timestamp := searchIndex.get(); index != nil {
		result.Query = query
		result.Hit, result.Alt, result.Illegal = index.(*Index).Lookup(query)
		_, ts := fsTree.get()
		result.Accurate = timestamp >= ts
	}

	var buf bytes.Buffer
	if err := searchHTML.Execute(result, &buf); err != nil {
		log.Stderrf("searchHTML.Execute: %s", err)
	}

	var title string
	if result.Hit != nil {
		title = fmt.Sprintf(`Results for query %q`, query)
	} else {
		title = fmt.Sprintf(`No results found for query %q`, query)
	}

	servePage(c, title, query, buf.Bytes())
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:25,代码来源:godoc.go


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