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


Golang os.ErrorString函数代码示例

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


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

示例1: serveLocal

func (v *Vault0) serveLocal(fpath, query string) (*http.Response, os.Error) {
	fpath = path.Clean(fpath)
	if len(fpath) > 0 && fpath[0] == '/' {
		fpath = fpath[1:]
	}
	if fpath == "" {
		fpath = "index.html"
	}
	full := path.Join(v.hdir, fpath)
	if !isFile(full) {
		if fpath == "index.html" {
			return newRespNoIndexHTML(), nil
		} else {
			return newRespNotFound(), os.ErrorString("not found")
		}
	}

	// Serve file if we can allocate a file descriptor in time
	if v.fdlim.LockOrTimeout(10e9) == nil {
		body, bodylen, err := http.FileToBody(full)
		if err != nil {
			if body != nil {
				body.Close()
			}
			v.fdlim.Unlock()
			return newRespServiceUnavailable(), os.ErrorString("service unavailable")
		}
		body = http.NewRunOnClose(body, func() { v.fdlim.Unlock() })
		return buildRespFromBody(body, bodylen), nil
	} else {
		return newRespServiceUnavailable(), os.ErrorString("service unavailable")
	}
	panic("unreach")
}
开发者ID:fedgrant,项目名称:tonika,代码行数:34,代码来源:vault.go

示例2: ParseURL

// ParseURL parses rawurl into a URL structure.
// The string rawurl is assumed not to have a #fragment suffix.
// (Web browsers strip #fragment before sending the URL to a web server.)
func ParseURL(rawurl string) (url *URL, err os.Error) {
	if rawurl == "" {
		err = os.ErrorString("empty url")
		goto Error
	}
	url = new(URL)
	url.Raw = rawurl

	// split off possible leading "http:", "mailto:", etc.
	var path string
	if url.Scheme, path, err = getscheme(rawurl); err != nil {
		goto Error
	}
	url.RawPath = path

	// RFC 2396: a relative URI (no scheme) has a ?query,
	// but absolute URIs only have query if path begins with /
	if url.Scheme == "" || len(path) > 0 && path[0] == '/' {
		path, url.RawQuery = split(path, '?', true)
	}

	// Maybe path is //authority/path
	if len(path) > 2 && path[0:2] == "//" {
		url.Authority, path = split(path[2:], '/', false)
	}

	// If there's no @, split's default is wrong.  Check explicitly.
	if strings.Index(url.Authority, "@") < 0 {
		url.Host = url.Authority
	} else {
		url.Userinfo, url.Host = split(url.Authority, '@', true)
	}

	if url.Path, err = urlUnescape(path, false); err != nil {
		goto Error
	}

	// Remove escapes from the Authority and Userinfo fields, and verify
	// that Scheme and Host contain no escapes (that would be illegal).
	if url.Authority, err = urlUnescape(url.Authority, false); err != nil {
		goto Error
	}
	if url.Userinfo, err = urlUnescape(url.Userinfo, false); err != nil {
		goto Error
	}
	if strings.Index(url.Scheme, "%") >= 0 {
		err = os.ErrorString("hexadecimal escape in scheme")
		goto Error
	}
	if strings.Index(url.Host, "%") >= 0 {
		err = os.ErrorString("hexadecimal escape in host")
		goto Error
	}

	return url, nil

Error:
	return nil, &URLError{"parse", rawurl, err}

}
开发者ID:quantumelixir,项目名称:Taipei-Torrent,代码行数:63,代码来源:url.go

示例3: Get

// Much like http.Get. If s is nil, uses DefaultSender.
func Get(s Sender, url string) (rs []*http.Response, err os.Error) {
	for redirect := 0; ; redirect++ {
		if redirect >= 10 {
			err = os.ErrorString("stopped after 10 redirects")
			break
		}

		var req http.Request
		req.RawURL = url
		req.Header = map[string]string{}
		r, err := Send(s, &req)
		if err != nil {
			break
		}
		rs = prepend(r, rs)
		if shouldRedirect(r.StatusCode) {
			r.Body.Close()
			if url = r.GetHeader("Location"); url == "" {
				err = os.ErrorString(fmt.Sprintf("%d response missing Location header", r.StatusCode))
				break
			}
			continue
		}

		return
	}

	err = &http.URLError{"Get", url, err}
	return
}
开发者ID:kr,项目名称:httpc.go,代码行数:31,代码来源:httpc.go

示例4: processClientKeyExchange

func (ka rsaKeyAgreement) processClientKeyExchange(config *Config, ckx *clientKeyExchangeMsg) ([]byte, os.Error) {
	preMasterSecret := make([]byte, 48)
	_, err := io.ReadFull(config.rand(), preMasterSecret[2:])
	if err != nil {
		return nil, err
	}

	if len(ckx.ciphertext) < 2 {
		return nil, os.ErrorString("bad ClientKeyExchange")
	}
	ciphertextLen := int(ckx.ciphertext[0])<<8 | int(ckx.ciphertext[1])
	if ciphertextLen != len(ckx.ciphertext)-2 {
		return nil, os.ErrorString("bad ClientKeyExchange")
	}
	ciphertext := ckx.ciphertext[2:]

	err = rsa.DecryptPKCS1v15SessionKey(config.rand(), config.Certificates[0].PrivateKey, ciphertext, preMasterSecret)
	if err != nil {
		return nil, err
	}
	// We don't check the version number in the premaster secret.  For one,
	// by checking it, we would leak information about the validity of the
	// encrypted pre-master secret. Secondly, it provides only a small
	// benefit against a downgrade attack and some implementations send the
	// wrong version anyway. See the discussion at the end of section
	// 7.4.7.1 of RFC 4346.
	return preMasterSecret, nil
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:28,代码来源:key_agreement.go

示例5: readRequest

func (server *Server) readRequest(codec ServerCodec) (req *Request, service *service, mtype *methodType, err os.Error) {
	// Grab the request header.
	req = server.getRequest()
	err = codec.ReadRequestHeader(req)
	if err != nil {
		req = nil
		if err == os.EOF || err == io.ErrUnexpectedEOF {
			return
		}
		err = os.ErrorString("rpc: server cannot decode request: " + err.String())
		return
	}

	serviceMethod := strings.Split(req.ServiceMethod, ".", -1)
	if len(serviceMethod) != 2 {
		err = os.ErrorString("rpc: service/method request ill-formed: " + req.ServiceMethod)
		return
	}
	// Look up the request.
	server.Lock()
	service = server.serviceMap[serviceMethod[0]]
	server.Unlock()
	if service == nil {
		err = os.ErrorString("rpc: can't find service " + req.ServiceMethod)
		return
	}
	mtype = service.method[serviceMethod[1]]
	if mtype == nil {
		err = os.ErrorString("rpc: can't find method " + req.ServiceMethod)
	}
	return
}
开发者ID:go-nosql,项目名称:golang,代码行数:32,代码来源:server.go

示例6: ImportNValues

// ImportNValues imports a channel of the given type and specified direction
// and then receives or transmits up to n values on that channel.  A value of
// n==0 implies an unbounded number of values.  The channel to be bound to
// the remote site's channel is provided in the call and may be of arbitrary
// channel type.
// Despite the literal signature, the effective signature is
//	ImportNValues(name string, chT chan T, dir Dir, pT T)
// where T must be a struct, pointer to struct, etc.  pT may be more indirect
// than the value type of the channel (e.g.  chan T, pT *T) but it must be a
// pointer.
// Example usage:
//	imp, err := NewImporter("tcp", "netchanserver.mydomain.com:1234")
//	if err != nil { log.Exit(err) }
//	ch := make(chan myType)
//	err := imp.ImportNValues("name", ch, Recv, new(myType), 1)
//	if err != nil { log.Exit(err) }
//	fmt.Printf("%+v\n", <-ch)
// (TODO: Can we eliminate the need for pT?)
func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, pT interface{}, n int) os.Error {
	ch, err := checkChan(chT, dir)
	if err != nil {
		return err
	}
	// Make sure pT is a pointer (to a pointer...) to a struct.
	rt := reflect.Typeof(pT)
	if _, ok := rt.(*reflect.PtrType); !ok {
		return os.ErrorString("not a pointer:" + rt.String())
	}
	if _, ok := reflect.Indirect(reflect.NewValue(pT)).(*reflect.StructValue); !ok {
		return os.ErrorString("not a pointer to a struct:" + rt.String())
	}
	imp.chanLock.Lock()
	defer imp.chanLock.Unlock()
	_, present := imp.chans[name]
	if present {
		return os.ErrorString("channel name already being imported:" + name)
	}
	ptr := reflect.MakeZero(reflect.Typeof(pT)).(*reflect.PtrValue)
	imp.chans[name] = &importChan{ch, dir, ptr, n}
	// Tell the other side about this channel.
	req := new(request)
	req.name = name
	req.dir = dir
	req.count = n
	if err := imp.encode(req, nil); err != nil {
		log.Stderr("importer request encode:", err)
		return err
	}
	return nil
}
开发者ID:lougxing,项目名称:golang-china,代码行数:50,代码来源:import.go

示例7: Auth

func (y *Conn) Auth(af connAuthFunc) (remote sys.Id, err os.Error) {
	y.lk.Lock()
	if y.err != nil {
		y.lk.Unlock()
		return 0, os.ErrorString("d,conn: closed meantime")
	}
	if y.regime != regimeUnAuth || y.tube == nil {
		panic("d,conn: regime logic")
	}
	y.regime = regimeAuth
	tube := y.tube
	y.lk.Unlock()

	remote, tubex, err := af(tube)

	y.lk.Lock()
	if y.err != nil {
		y.lk.Unlock()
		return 0, os.ErrorString("d,conn: closed meantime")
	}
	if err != nil {
		y.lk.Unlock()
		return 0, y.kill(os.ErrorString("d,conn: auth failed"))
	}
	y.id = &remote
	y.tube = tubex
	y.regime = regimeReady
	y.lk.Unlock()
	return remote, nil
}
开发者ID:fedgrant,项目名称:tonika,代码行数:30,代码来源:conn.go

示例8: Greet

func (y *Conn) Greet() (string, string, os.Error) {
	y.lk.Lock()
	if y.err != nil {
		y.lk.Unlock()
		return "", "", os.ErrorString("d,conn: closed meantime")
	}
	if y.regime != regimeUnAuth || y.tube == nil {
		panic("d,conn: regime logic")
	}
	y.regime = regimeAuth
	tube := y.tube
	y.lk.Unlock()

	g := &U_Greet{sys.Build, Version}
	err := tube.Encode(g)
	if err == nil {
		err = tube.Decode(g)
	}

	y.lk.Lock()
	if y.err != nil {
		y.lk.Unlock()
		return "", "", os.ErrorString("d,conn: closed meantime")
	}
	if err != nil {
		y.lk.Unlock()
		return "", "", y.kill(os.ErrorString("d,conn: greet failed"))
	}
	y.regime = regimeUnAuth
	y.lk.Unlock()
	return g.Build, g.Version, nil
}
开发者ID:fedgrant,项目名称:tonika,代码行数:32,代码来源:conn.go

示例9: consumeQuotedString

// consumeQuotedString parses the quoted string at the start of p.
func (p *addrParser) consumeQuotedString() (qs string, err os.Error) {
	// Assume first byte is '"'.
	i := 1
	qsb := make([]byte, 0, 10)
Loop:
	for {
		if i >= p.len() {
			return "", os.ErrorString("mail: unclosed quoted-string")
		}
		switch c := (*p)[i]; {
		case c == '"':
			break Loop
		case c == '\\':
			if i+1 == p.len() {
				return "", os.ErrorString("mail: unclosed quoted-string")
			}
			qsb = append(qsb, (*p)[i+1])
			i += 2
		case isQtext(c), c == ' ' || c == '\t':
			// qtext (printable US-ASCII excluding " and \), or
			// FWS (almost; we're ignoring CRLF)
			qsb = append(qsb, c)
			i++
		default:
			return "", fmt.Errorf("mail: bad character in quoted-string: %q", c)
		}
	}
	*p = (*p)[i+1:]
	return string(qsb), nil
}
开发者ID:jnwhiteh,项目名称:go,代码行数:31,代码来源:message.go

示例10: Get

// Get issues a GET to the specified URL.  If the response is one of the following
// redirect codes, it follows the redirect, up to a maximum of 10 redirects:
//
//    301 (Moved Permanently)
//    302 (Found)
//    303 (See Other)
//    307 (Temporary Redirect)
//
// finalUrl is the URL from which the response was fetched -- identical to the input
// URL unless redirects were followed.
//
// Caller should close r.Body when done reading it.
func Get(url string) (r *Response, finalURL string, err os.Error) {
	// TODO: if/when we add cookie support, the redirected request shouldn't
	// necessarily supply the same cookies as the original.
	// TODO: set referrer header on redirects.
	for redirect := 0; ; redirect++ {
		if redirect >= 10 {
			err = os.ErrorString("stopped after 10 redirects")
			break
		}

		var req Request
		if req.Url, err = ParseURL(url); err != nil {
			break
		}
		if r, err = send(&req); err != nil {
			break
		}
		if shouldRedirect(r.StatusCode) {
			r.Body.Close()
			if url = r.GetHeader("Location"); url == "" {
				err = os.ErrorString(fmt.Sprintf("%d response missing Location header", r.StatusCode))
				break
			}
			continue
		}
		finalURL = url
		return
	}

	err = &URLError{"Get", url, err}
	return
}
开发者ID:8l,项目名称:go-learn,代码行数:44,代码来源:client.go

示例11: pkcs1v15HashInfo

func pkcs1v15HashInfo(hash PKCS1v15Hash, inLen int) (hashLen int, prefix []byte, err os.Error) {
	switch hash {
	case HashMD5:
		hashLen = 16
	case HashSHA1:
		hashLen = 20
	case HashSHA256:
		hashLen = 32
	case HashSHA384:
		hashLen = 48
	case HashSHA512:
		hashLen = 64
	case HashMD5SHA1:
		hashLen = 36
	default:
		return 0, nil, os.ErrorString("unknown hash function")
	}

	if inLen != hashLen {
		return 0, nil, os.ErrorString("input must be hashed message")
	}

	prefix = hashPrefixes[int(hash)]
	return
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:25,代码来源:pkcs1v15.go

示例12: ignoreMap

func (dec *Decoder) ignoreMap(state *decodeState, keyOp, elemOp decOp) {
	n := int(state.decodeUint())
	keyInstr := &decInstr{keyOp, 0, 0, 0, os.ErrorString("no error")}
	elemInstr := &decInstr{elemOp, 0, 0, 0, os.ErrorString("no error")}
	for i := 0; i < n; i++ {
		keyOp(keyInstr, state, nil)
		elemOp(elemInstr, state, nil)
	}
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:9,代码来源:decode.go

示例13: AttachRecvChan

func (s *routerImpl) AttachRecvChan(id Id, v interface{}, args ...interface{}) (routCh *RoutedChan, err os.Error) {
	if err = s.validateId(id); err != nil {
		s.LogError(err)
		s.Raise(err)
		return
	}
	var ok bool
	ch, internalChan := v.(Channel)
	if !internalChan {
		ch, ok = reflect.NewValue(v).(*reflect.ChanValue)
		if !ok {
			err = os.ErrorString(errInvalidChan)
			s.LogError(err)
			s.Raise(err)
			return
		}
	}
	var bindChan chan *BindEvent
	for i := 0; i < len(args); i++ {
		switch cv := args[0].(type) {
		case chan *BindEvent:
			bindChan = cv
			if cap(bindChan) == 0 {
				err = os.ErrorString(errInvalidBindChan + ": binding bindChan is not buffered")
				s.LogError(err)
				s.Raise(err)
				return
			}
		case int:
			//set recv chan buffer size
			s.bufSizeLock.Lock()
			old, ok := s.recvBufSizes[id.Key()]
			if !ok || old < cv {
				s.recvBufSizes[id.Key()] = cv
			}
			s.bufSizeLock.Unlock()
		default:
			err = os.ErrorString("invalid arguments to attach recv chan")
			s.LogError(err)
			s.Raise(err)
			return
		}
	}
	if s.async && ch.Cap() != UnlimitedBuffer && !internalChan {
		//for async router, external recv chans must have unlimited buffering,
		//ie. Cap()==-1, all undelivered msgs will be buffered right before ext recv chans
		ch = &asyncChan{Channel: ch}
	}
	routCh = newRoutedChan(id, recverType, ch, s, bindChan)
	routCh.internalChan = internalChan
	err = s.attach(routCh)
	if err != nil {
		s.LogError(err)
		s.Raise(err)
	}
	return
}
开发者ID:niltonkummer,项目名称:go-router,代码行数:57,代码来源:router.go

示例14: Demarshal

func (jm *jsonDemarshaler) Demarshal() (id Id, ctrlMsg interface{}, appMsg reflect.Value, err os.Error) {
	seedId := jm.proxy.router.seedId
	id, _ = seedId.Clone()
	if err = jm.Decode(id); err != nil {
		return
	}
	if id.Scope() == NumScope && id.Member() == NumMembership {
		return
	}
	switch id.SysIdIndex() {
	case ConnId, DisconnId, ErrorId:
		idc, _ := seedId.Clone()
		ctrlMsg = &ConnInfoMsg{Id: idc}
		err = jm.demarshalCtrlMsg(ctrlMsg)
	case ReadyId:
		idc, _ := seedId.Clone()
		ctrlMsg = &ConnReadyMsg{[]*ChanReadyInfo{&ChanReadyInfo{Id: idc}}}
		err = jm.demarshalCtrlMsg(ctrlMsg)
	case PubId, UnPubId, SubId, UnSubId:
		idc, _ := seedId.Clone()
		ctrlMsg = &IdChanInfoMsg{[]*IdChanInfo{&IdChanInfo{idc, nil, nil}}}
		err = jm.demarshalCtrlMsg(ctrlMsg)
	default: //appMsg
		chanType := jm.proxy.getExportRecvChanType(id)
		if chanType == nil {
			err = os.ErrorString(fmt.Sprintf("failed to find chanType for id %v", id))
			return
		}
		et := chanType.Elem()
		appMsg = reflect.MakeZero(et)
		var ptrT *reflect.PtrValue
		switch et := et.(type) {
		case *reflect.BoolType:
			ptrT = jm.ptrBool
			ptrT.PointTo(appMsg)
		case *reflect.IntType:
			ptrT = jm.ptrInt
			ptrT.PointTo(appMsg)
		case *reflect.FloatType:
			ptrT = jm.ptrFloat
			ptrT.PointTo(appMsg)
		case *reflect.StringType:
			ptrT = jm.ptrString
			ptrT.PointTo(appMsg)
		case *reflect.PtrType:
			sto := reflect.MakeZero(et.Elem())
			ptrT = appMsg.(*reflect.PtrValue)
			ptrT.PointTo(sto)
		default:
			err = os.ErrorString(fmt.Sprintf("invalid chanType for id %v", id))
			return
		}
		err = jm.Decode(ptrT.Interface())
	}
	return
}
开发者ID:niltonkummer,项目名称:go-router,代码行数:56,代码来源:marshaler.go

示例15: VerifyHostname

// VerifyHostname checks that the peer certificate chain is valid for
// connecting to host.  If so, it returns nil; if not, it returns an os.Error
// describing the problem.
func (c *Conn) VerifyHostname(host string) os.Error {
	c.handshakeMutex.Lock()
	defer c.handshakeMutex.Unlock()
	if !c.isClient {
		return os.ErrorString("VerifyHostname called on TLS server connection")
	}
	if !c.handshakeComplete {
		return os.ErrorString("TLS handshake has not yet been performed")
	}
	return c.peerCertificates[0].VerifyHostname(host)
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:14,代码来源:conn.go


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