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


Golang os.Error類代碼示例

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


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

示例1: failnoting

func failnoting(s string, e os.Error) {
	if e != nil {
		fmt.Println(Usage())
		fmt.Println("\n"+s, e.String())
		os.Exit(1)
	}
}
開發者ID:saschpe,項目名稱:goopt,代碼行數:7,代碼來源:goopt.go

示例2: main

func main() {

	var err os.Error

	db := 0
	port := 6379

	args := os.Args[1:]

	for i := 0; i < len(args); i++ {
		arg := args[i]
		if arg == "-p" && i < len(args)-1 {
			if port, err = strconv.Atoi(args[i+1]); err != nil {
				println(err.String())
				return
			}
			i += 1
			continue
		} else if arg == "-db" && i < len(args)-1 {
			if db, err = strconv.Atoi(args[i+1]); err != nil {
				println(err.String())
				return
			}
			i += 1
			continue
		} else {
			println("Invalid argument: ", arg)
			usage()
			return
		}
	}
	println("port", port, db)
	load_db(port, db, bufio.NewReader(os.Stdin))

}
開發者ID:saschpe,項目名稱:redis.go,代碼行數:35,代碼來源:redis-load.go

示例3: Pass

func (n *Network) Pass() os.Error {
	t := strconv.Itoa64(time.Nanoseconds())
	myreplies := []string{"ERR_NEEDMOREPARAMS", "ERR_ALREADYREGISTRED"}
	var err os.Error
	repch := make(chan *IrcMessage)
	for _, rep := range myreplies {
		if err := n.Listen.RegListener(replies[rep], t, repch); err != nil {
			err = os.NewError(fmt.Sprintf("Couldn't authenticate with password, exiting: %s", err.String()))
		}
	}
	ticker := time.NewTicker(timeout(n.lag))
	defer func(myreplies []string, t string, tick *time.Ticker) {
		for _, rep := range myreplies {
			n.Listen.DelListener(replies[rep], t)
		}
		tick.Stop()
		return
	}(myreplies, t, ticker)
	n.queueOut <- &IrcMessage{"", "PASS", []string{n.password}}
	select {
	case msg := <-repch:
		if msg.Cmd == replies["ERR_NEEDMOREPARAMS"] {
			err = os.NewError(fmt.Sprintf("Need more parameters for password: %s", msg.String()))
		}
		break
	case <-ticker.C:
		break
	}
	return err
}
開發者ID:soul9,項目名稱:go-irc-chans,代碼行數:30,代碼來源:ircextras.go

示例4: NewStore

func NewStore(dir string, depth int, before int64) *BitcaskStore {
	p := new(BitcaskStore)
	p.depth = depth
	p.before = before
	p.locks = make([]sync.Mutex, 97)

	count := 1 << uint32(depth*4)
	p.bc = make([]*htree.Bitcask, count)
	for i := 0; i < count; i++ {
		subdir := ""
		if depth > 0 {
			sf := fmt.Sprintf("%%0%dx", depth)
			subdir = fmt.Sprintf(sf, i)
			subdir = strings.Join(strings.Split(subdir, ""), "/")
		}
		dbpath := path.Join(dir, subdir)
		os.MkdirAll(dbpath, 0755)
		var err os.Error
		p.bc[i], err = htree.NewBitcask(dbpath, depth, before)
		if err != nil {
			panic(os.NewError("Can not open db:" + dbpath + err.String()))
		}
	}

	return p
}
開發者ID:haiger,項目名稱:beansdb,代碼行數:26,代碼來源:beansdb.go

示例5: addWidget

func addWidget(w http.ResponseWriter, r *http.Request) {
	var err os.Error
	if fixup == nil {
		fixup, err = regexp.Compile(`[^A-Za-z0-9\-_. ]`)
		if err != nil {
			http.Error(w, err.String(), http.StatusInternalServerError)
			return
		}
	}

	ctx := appengine.NewContext(r)
	name := fixup.ReplaceAllString(r.FormValue("name"), "")

	if len(name) == 0 {
		http.Error(w, "Invalid/no name provided", http.StatusInternalServerError)
		return
	}

	widget := NewWidget(ctx, name)

	err = widget.Commit()
	if err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}

	http.Redirect(w, r, "/widget/list", http.StatusFound)
}
開發者ID:kylelemons,項目名稱:go-widget,代碼行數:28,代碼來源:my_widgets.go

示例6: match

func match(t *testing.T, err os.Error, pat string) bool {
	ok, err1 := regexp.MatchString(pat, err.String())
	if err1 != nil {
		t.Fatalf("compile regexp %s: %v", pat, err1)
	}
	return ok
}
開發者ID:IntegerCompany,項目名稱:linaro-android-gcc,代碼行數:7,代碼來源:eval_test.go

示例7: Abort

// Abort aborts the thread's current computation,
// causing the innermost Try to return err.
func (t *Thread) Abort(err os.Error) {
	if t.abort == nil {
		panicln("abort:", err.String())
	}
	t.abort <- err
	runtime.Goexit()
}
開發者ID:8l,項目名稱:go-learn,代碼行數:9,代碼來源:abort.go

示例8: print

func print(a interface{}, err os.Error) {
	if err == nil {
		fmt.Printf("  answer: %v\r\n", a)
	} else if err != ErrCtrlD {
		fmt.Printf(err.String() + "\r\n")
	}
}
開發者ID:postfix,項目名稱:go-linoise,代碼行數:7,代碼來源:question_test.go

示例9: TestSet

func TestSet(t *testing.T) {
	var err os.Error

	vals := []string{"a", "b", "c", "d", "e"}

	for _, v := range vals {
		client.Sadd("s", strings.Bytes(v))
	}

	var members [][]byte

	if members, err = client.Smembers("s"); err != nil || len(members) != 5 {
		t.Fatal("Set setup failed", err.String())
	}

	for _, v := range vals {
		if ok, err := client.Sismember("s", strings.Bytes(v)); err != nil || !ok {
			t.Fatal("Sismember test failed")
		}
	}

	for _, v := range vals {
		if ok, err := client.Srem("s", strings.Bytes(v)); err != nil || !ok {
			t.Fatal("Sismember test failed")
		}
	}

	if members, err = client.Smembers("s"); err != nil || len(members) != 0 {
		t.Fatal("Set setup failed", err.String())
	}

	client.Del("s")

}
開發者ID:Goemon,項目名稱:redis.go,代碼行數:34,代碼來源:redis_test.go

示例10: error

func error(t *testing.T, err os.Error, msg string) {
	if err == nil {
		t.Error(msg)
	} else {
		t.Errorf("%s: %s\n", msg, err.String())
	}
}
開發者ID:eden,項目名稱:mysqlgo,代碼行數:7,代碼來源:mysql_test.go

示例11: checkErr

func checkErr(message string, err os.Error) {
	// ignore os.EOF since it's not really an error...
	if err != nil && err != os.EOF {
		os.Stderr.WriteString(message + "\n" + err.String() + "\n")
		os.Exit(1)
	}
}
開發者ID:retro486,項目名稱:go-dungeon,代碼行數:7,代碼來源:helpfuls.go

示例12: listenAndServeFcgi

func (s *Server) listenAndServeFcgi(addr string) os.Error {
	var l net.Listener
	var err os.Error

	//if the path begins with a "/", assume it's a unix address
	if strings.HasPrefix(addr, "/") {
		l, err = net.Listen("unix", addr)
	} else {
		l, err = net.Listen("tcp", addr)
	}

	if err != nil {
		s.Logger.Println("FCGI listen error", err.String())
		return err
	}
	for {
		fd, err := l.Accept()
		if err != nil {
			s.Logger.Println("FCGI accept error", err.String())
			break
		}
		go s.handleFcgiConnection(fd)
	}
	return nil
}
開發者ID:ality,項目名稱:web.go,代碼行數:25,代碼來源:fcgi.go

示例13: VerifySignature

func (vr *VerifyRequest) VerifySignature() bool {
	armorData := reArmor(vr.CamliSig)
	block, _ := armor.Decode(bytes.NewBufferString(armorData))
	if block == nil {
		return vr.fail("can't parse camliSig armor")
	}
	var p packet.Packet
	var err os.Error
	p, err = packet.Read(block.Body)
	if err != nil {
		return vr.fail("error reading PGP packet from camliSig: " + err.String())
	}
	sig, ok := p.(*packet.Signature)
	if !ok {
		return vr.fail("PGP packet isn't a signature packet")
	}
	if sig.Hash != crypto.SHA1 && sig.Hash != crypto.SHA256 {
		return vr.fail("I can only verify SHA1 or SHA256 signatures")
	}
	if sig.SigType != packet.SigTypeBinary {
		return vr.fail("I can only verify binary signatures")
	}
	hash := sig.Hash.New()
	hash.Write(vr.bp) // payload bytes
	err = vr.PublicKeyPacket.VerifySignature(hash, sig)
	if err != nil {
		return vr.fail(fmt.Sprintf("bad signature: %s", err))
	}
	vr.SignerKeyId = vr.PublicKeyPacket.KeyIdString()
	return true
}
開發者ID:ipeet,項目名稱:camlistore,代碼行數:31,代碼來源:verify.go

示例14: SendLoop

// Sends messages over the remote conn that come through the queue.
func (cl *client) SendLoop(cs chan<- Msg) {
	defer logAndClose(cl.conn)
	for {
		msg := <-cl.SendQueue
		var err os.Error
		switch m := msg.(type) {
		case MsgAddEntity:
			err = sendMessage(cl.conn, makeAddEntity(int32(m.Uid), m.Name))
		case MsgRemoveEntity:
			err = sendMessage(cl.conn, makeRemoveEntity(int32(m.Uid), m.Name))
		case MsgUpdateState:
			value := packState(m.State)
			err = sendMessage(cl.conn, makeUpdateState(int32(m.Uid), m.State.Name(), value))
		case MsgAssignControl:
			err = sendMessage(cl.conn, makeAssignControl(int32(m.Uid), m.Revoked))
		case MsgEntityDeath:
			uid, name := m.Entity.Uid, m.Entity.Name
			kuid, kname := m.Killer.Uid, m.Killer.Name
			err = sendMessage(cl.conn, makeEntityDeath(int32(uid), name, int32(kuid), kname))
		case MsgCombatHit:
			auid, aname := m.Attacker.Uid, m.Attacker.Name
			vuid, vname := m.Victim.Uid, m.Victim.Name
			err = sendMessage(cl.conn, makeCombatHit(int32(auid), aname, int32(vuid), vname, m.Damage))
		}
		// Remove client if something went wrong
		if err != nil {
			cs <- removeClientMsg{cl, "Sending message to client failed: " + err.String()}
			return
		}
	}
}
開發者ID:archwyrm,項目名稱:ghack,代碼行數:32,代碼來源:comm.go

示例15: ParseFile

// parse a file, and store the templates in Page.Template
func (t *Page) ParseFile(formatterMap map[string]func(io.Writer, string, ...interface{})) {
	var err os.Error
	t.Template, err = template.ParseFile(t.Filename, formatterMap)
	if err != nil {
		log.Fatal("Cannot Parse " + t.Filename + "; got " + err.String())
	}
}
開發者ID:nstott,項目名稱:gopages,代碼行數:8,代碼來源:pages.go


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