本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.IState.GetPort方法的典型用法代碼示例。如果您正苦於以下問題:Golang IState.GetPort方法的具體用法?Golang IState.GetPort怎麽用?Golang IState.GetPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/FactomProject/factomd/common/interfaces.IState
的用法示例。
在下文中一共展示了IState.GetPort方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetState
func SetState(state interfaces.IState) {
wait := func() {
ServersMutex.Lock()
defer ServersMutex.Unlock()
for Servers == nil && Servers[state.GetPort()] != nil {
time.Sleep(10 * time.Millisecond)
}
Servers[state.GetPort()].Env["state"] = state
}
go wait()
}
示例2: Start
func Start(state interfaces.IState) {
var server *web.Server
if Servers == nil {
Servers = make(map[int]*web.Server)
}
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/directory-block-by-keymr/([^/]+)", HandleDirectoryBlock)
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)
log.Print("Starting server")
go server.Run(fmt.Sprintf("localhost:%d", state.GetPort()))
}
}
示例3: 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()))
}
}
}
示例4: Stop
func Stop(state interfaces.IState) {
ServersMutex.Lock()
defer ServersMutex.Unlock()
Servers[state.GetPort()].Close()
}
示例5: Stop
func Stop(state interfaces.IState) {
Servers[state.GetPort()].Close()
}