本文整理汇总了Golang中os.Error.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Error.String方法的具体用法?Golang Error.String怎么用?Golang Error.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.Error
的用法示例。
在下文中一共展示了Error.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: myWidgets
func myWidgets(w http.ResponseWriter, r *http.Request) {
var err os.Error
ctx := appengine.NewContext(r)
page, err := template.Parse(myWidgetTemplate, nil)
if err != nil {
http.Error(w, err.String(), http.StatusInternalServerError)
return
}
data := myWidgetData{
CSS: commonCSS(),
Header: header(ctx),
}
data.Widget, err = LoadWidgets(ctx)
if err != nil {
http.Error(w, err.String(), http.StatusInternalServerError)
return
}
if len(r.FormValue("ids_only")) > 0 {
w.Header().Set("Content-Type", "text/plain")
for _, widget := range data.Widget {
fmt.Fprintln(w, widget.ID)
}
return
}
page.Execute(w, data)
}
示例2: 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
}
示例3: 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
}
示例4: 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)
}
示例5: TestBasic
func TestBasic(t *testing.T) {
var val []byte
var err os.Error
err = client.Set("a", []byte("hello"))
if err != nil {
t.Fatal("set failed", err.String())
}
if val, err = client.Get("a"); err != nil || string(val) != "hello" {
t.Fatal("get failed")
}
if typ, err := client.Type("a"); err != nil || typ != "string" {
t.Fatal("type failed", typ)
}
//if keys, err := client.Keys("*"); err != nil || len(keys) != 1 {
// t.Fatal("keys failed", keys)
//}
client.Del("a")
if ok, _ := client.Exists("a"); ok {
t.Fatal("Should be deleted")
}
}
示例6: match
func match(t *testing.T, err os.Error, pat string) bool {
ok, errstr := testing.MatchString(pat, err.String())
if errstr != "" {
t.Fatalf("compile regexp %s: %v", pat, errstr)
}
return ok
}
示例7: 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())
}
}
示例8: sending
// Keep on writing outgoing messages to the socket
func (conn *Conn) sending() {
for p := range conn.out {
if p == nil {
conn.Err <- ErrNilPacket
continue
}
var err os.Error
if p.Addr == nil {
if !conn.IsConnected() {
conn.error("conn.sending(): [%s] %s", p.Addr.String(), ErrClosedConn.String())
continue
}
if _, err = conn.sock.Write(p.Msg); err != nil {
conn.error("conn.sending(): %s", err.String())
}
} else {
if !conn.IsConnected() {
conn.error("conn.sending(): %s", ErrClosedConn.String())
continue
}
if _, err = conn.sock.WriteTo(p.Msg, p.Addr); err != nil {
conn.error("conn.sending() [%s]: %s", p.Addr.String(), err.String())
}
}
if err != nil {
conn.Disconnect()
break
}
}
}
示例9: 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
}
示例10: main
func main() {
hdr := map[string]string{}
e, _ := armor.Encode(os.Stdout, "RADIX-64", hdr)
const NBUF = 512
var buf [NBUF]byte
var err, erw os.Error
var nr, nw int
for {
switch nr, err = os.Stdin.Read(buf[:]); true {
case nr < 0:
fmt.Fprintf(os.Stderr, "error reading from Stdin: %s\n", err.String())
os.Exit(1)
case nr == 0:
break
case nr > 0:
if nw, erw = e.Write(buf[0:nr]); nw != nr {
fmt.Fprintf(os.Stderr, "error writing encoded bytes to Stdout: %s\n", erw.String())
os.Exit(1)
}
}
if err == os.EOF {
break
}
}
e.Close()
}
示例11: 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
}
示例12: handle
func (l *pktHandler) handle() {
var err, clientErr os.Error
defer func() {
if err != nil {
log.Print("Connection closed ", err.String())
if clientErr == nil {
clientErr = clientErrGeneral
}
proto.WriteDisconnect(l.conn, clientErr.String())
l.conn.Close()
}
}()
err = proto.ServerReadPacketExpect(l.conn, l, []byte{
proto.PacketIdHandshake,
proto.PacketIdServerListPing,
})
if err != nil {
clientErr = clientErrLoginGeneral
return
}
switch l.connType {
case connTypeLogin:
err, clientErr = l.handleLogin(l.conn)
case connTypeServerQuery:
err, clientErr = l.handleServerQuery(l.conn)
default:
err = loginErrorConnType
}
}
示例13: 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
}
}
}
示例14: failnoting
func failnoting(s string, e os.Error) {
if e != nil {
fmt.Println(Usage())
fmt.Println("\n"+s, e.String())
os.Exit(1)
}
}
示例15: 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)
}
}