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


Golang Reply.Id方法代碼示例

本文整理匯總了Golang中github.com/conformal/btcjson.Reply.Id方法的典型用法代碼示例。如果您正苦於以下問題:Golang Reply.Id方法的具體用法?Golang Reply.Id怎麽用?Golang Reply.Id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/conformal/btcjson.Reply的用法示例。


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

示例1: jsonRPCRead

// jsonRPCRead is the RPC wrapper around the jsonRead function to handle reading
// and responding to RPC messages.
func jsonRPCRead(w http.ResponseWriter, r *http.Request, s *rpcServer) {
	if atomic.LoadInt32(&s.shutdown) != 0 {
		return
	}
	body, err := btcjson.GetRaw(r.Body)
	if err != nil {
		rpcsLog.Errorf("Error getting json message: %v", err)
		return
	}

	var reply btcjson.Reply
	cmd, jsonErr := parseCmd(body)
	if cmd != nil {
		// Unmarshaling at least a valid JSON-RPC message succeeded.
		// Use the provided id for errors.
		id := cmd.Id()
		reply.Id = &id
	}
	if jsonErr != nil {
		reply.Error = jsonErr
	} else {
		reply = standardCmdReply(cmd, s)
	}

	rpcsLog.Tracef("reply: %v", reply)

	msg, err := btcjson.MarshallAndSend(reply, w)
	if err != nil {
		rpcsLog.Errorf(msg)
		return
	}
	rpcsLog.Debugf(msg)
}
開發者ID:Cryptoper,項目名稱:btcd,代碼行數:35,代碼來源:rpcserver.go

示例2: websocketJSONHandler

// websocketJSONHandler parses and handles a marshalled json message,
// sending the marshalled reply to a wallet notification channel.
func (s *rpcServer) websocketJSONHandler(wallet walletChan, msg []byte) {
	s.wg.Add(1)
	defer s.wg.Done()

	cmd, jsonErr := parseCmd(msg)
	if jsonErr != nil {
		var reply btcjson.Reply
		if cmd != nil {
			// Unmarshaling at least a valid JSON-RPC message succeeded.
			// Use the provided id for errors.
			id := cmd.Id()
			reply.Id = &id
		}
		reply.Error = jsonErr
		mreply, _ := json.Marshal(reply)
		wallet <- mreply
		return
	}

	respondToAnyCmd(cmd, s, wallet)
}
開發者ID:Nevtep,項目名稱:mastercoind,代碼行數:23,代碼來源:rpcwebsocket.go

示例3: websocketJSONHandler

// websocketJSONHandler parses and handles a marshalled json message,
// sending the marshalled reply to a wallet notification channel.
func (s *rpcServer) websocketJSONHandler(r chan *btcjson.Reply, c handlerChans, msg string) error {
	var resp *btcjson.Reply

	cmd, jsonErr := parseCmd([]byte(msg))
	if jsonErr != nil {
		resp = &btcjson.Reply{}
		if cmd != nil {
			// Unmarshaling at least a valid JSON-RPC message succeeded.
			// Use the provided id for errors.  Requests with no IDs
			// should be ignored.
			id := cmd.Id()
			if id == nil {
				return nil
			}
			resp.Id = &id
		}
		resp.Error = jsonErr
	} else {
		// The first command must be the "authenticate" command if the
		// connection is not already authenticated.
		s.ws.Lock()
		rc := s.ws.connections[c.n]
		if _, ok := cmd.(*btcws.AuthenticateCmd); ok {
			// Validate the provided credentials.
			err := websocketAuthenticate(cmd, rc, s.authsha[:])
			if err != nil {
				s.ws.Unlock()
				return err
			}

			// Generate an empty response to send for the successful
			// authentication.
			id := cmd.Id()
			resp = &btcjson.Reply{
				Id:     &id,
				Result: nil,
				Error:  nil,
			}
		} else if !rc.authenticated {
			rpcsLog.Warnf("Unauthenticated websocket message " +
				"received")
			s.ws.Unlock()
			return ErrBadAuth
		}

		s.ws.Unlock()
	}

	// Find and run handler in new goroutine.
	go func() {
		if resp == nil {
			resp = respondToAnyCmd(cmd, s, c)
		}
		select {
		case <-c.disconnected:
			return

		default:
			r <- resp
		}
	}()

	return nil
}
開發者ID:kawalgrover,項目名稱:btcd,代碼行數:66,代碼來源:rpcwebsocket.go


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