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


Golang IState.SetRpcAuthHash方法代碼示例

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


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

示例1: Start

func Start(state interfaces.IState) {
	var server *web.Server

	ServersMutex.Lock()
	defer ServersMutex.Unlock()

	if Servers == nil {
		Servers = make(map[int]*web.Server)
	}

	rpcUser := state.GetRpcUser()
	rpcPass := state.GetRpcPass()
	h := sha256.New()
	h.Write(httpBasicAuth(rpcUser, rpcPass))
	state.SetRpcAuthHash(h.Sum(nil)) //set this in the beginning to prevent timing attacks

	if Servers[state.GetPort()] == nil {
		server = web.NewServer()

		Servers[state.GetPort()] = server
		server.Env["state"] = state

		server.Post("/v1/factoid-submit/?", HandleFactoidSubmit)
		server.Post("/v1/commit-chain/?", HandleCommitChain)
		server.Post("/v1/reveal-chain/?", HandleRevealChain)
		server.Post("/v1/commit-entry/?", HandleCommitEntry)
		server.Post("/v1/reveal-entry/?", HandleRevealEntry)
		server.Get("/v1/directory-block-head/?", HandleDirectoryBlockHead)
		server.Get("/v1/get-raw-data/([^/]+)", HandleGetRaw)
		server.Get("/v1/get-receipt/([^/]+)", HandleGetReceipt)
		server.Get("/v1/directory-block-by-keymr/([^/]+)", HandleDirectoryBlock)
		server.Get("/v1/directory-block-height/?", HandleDirectoryBlockHeight)
		server.Get("/v1/entry-block-by-keymr/([^/]+)", HandleEntryBlock)
		server.Get("/v1/entry-by-hash/([^/]+)", HandleEntry)
		server.Get("/v1/chain-head/([^/]+)", HandleChainHead)
		server.Get("/v1/entry-credit-balance/([^/]+)", HandleEntryCreditBalance)
		server.Get("/v1/factoid-balance/([^/]+)", HandleFactoidBalance)
		server.Get("/v1/factoid-get-fee/", HandleGetFee)
		server.Get("/v1/properties/", HandleProperties)
		server.Get("/v1/heights/", HandleHeights)

		server.Post("/v2", HandleV2)
		server.Get("/v2", HandleV2)

		tlsIsEnabled, tlsPrivate, tlsPublic := state.GetTlsInfo()
		if tlsIsEnabled {
			log.Print("Starting encrypted API server")
			if !fileExists(tlsPrivate) && !fileExists(tlsPublic) {
				err := genCertPair(tlsPublic, tlsPrivate, state.GetFactomdLocations())
				if err != nil {
					panic(fmt.Sprintf("could not start encrypted API server with error: %v", err))
				}
			}
			keypair, err := tls.LoadX509KeyPair(tlsPublic, tlsPrivate)
			if err != nil {
				panic(fmt.Sprintf("could not create TLS keypair with error: %v", err))
			}
			tlsConfig := &tls.Config{
				Certificates: []tls.Certificate{keypair},
				MinVersion:   tls.VersionTLS12,
			}
			go server.RunTLS(fmt.Sprintf(":%d", state.GetPort()), tlsConfig)

		} else {
			log.Print("Starting API server")
			go server.Run(fmt.Sprintf(":%d", state.GetPort()))
		}
	}
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:69,代碼來源:wsapi.go


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