rpc: move server-related code to a separate package
This commit is contained in:
parent
d24c6d1d9e
commit
b50704fd3b
8 changed files with 16 additions and 16 deletions
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/CityOfZion/neo-go/pkg/io"
|
||||
"github.com/CityOfZion/neo-go/pkg/network"
|
||||
"github.com/CityOfZion/neo-go/pkg/network/metrics"
|
||||
"github.com/CityOfZion/neo-go/pkg/rpc"
|
||||
"github.com/CityOfZion/neo-go/pkg/rpc/server"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
"go.uber.org/zap"
|
||||
|
@ -341,18 +341,18 @@ func startServer(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
server, err := network.NewServer(serverConfig, chain, log)
|
||||
serv, err := network.NewServer(serverConfig, chain, log)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to create network server: %v", err), 1)
|
||||
}
|
||||
rpcServer := rpc.NewServer(chain, cfg.ApplicationConfiguration.RPC, server, log)
|
||||
rpcServer := server.New(chain, cfg.ApplicationConfiguration.RPC, serv, log)
|
||||
errChan := make(chan error)
|
||||
|
||||
go server.Start(errChan)
|
||||
go serv.Start(errChan)
|
||||
go rpcServer.Start(errChan)
|
||||
|
||||
fmt.Println(logo())
|
||||
fmt.Println(server.UserAgent)
|
||||
fmt.Println(serv.UserAgent)
|
||||
fmt.Println()
|
||||
|
||||
var shutdownErr error
|
||||
|
@ -364,7 +364,7 @@ Main:
|
|||
cancel()
|
||||
|
||||
case <-grace.Done():
|
||||
server.Shutdown()
|
||||
serv.Shutdown()
|
||||
if serverErr := rpcServer.Shutdown(); serverErr != nil {
|
||||
shutdownErr = errors.Wrap(serverErr, "Error encountered whilst shutting down server")
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Package rpc implements NEO-specific JSON-RPC 2.0 server.
|
||||
Package server implements NEO-specific JSON-RPC 2.0 server.
|
||||
This package is currently in alpha and is subject to change.
|
||||
|
||||
Server
|
||||
|
@ -45,4 +45,4 @@ Unsupported methods
|
|||
submitblock (needs to be implemented in pkg/core/blockchain.go)
|
||||
|
||||
*/
|
||||
package rpc
|
||||
package server
|
|
@ -1,4 +1,4 @@
|
|||
package rpc
|
||||
package server
|
||||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package rpc
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -38,8 +38,8 @@ var invalidBlockHeightError = func(index int, height int) error {
|
|||
return errors.Errorf("Param at index %d should be greater than or equal to 0 and less then or equal to current block height, got: %d", index, height)
|
||||
}
|
||||
|
||||
// NewServer creates a new Server struct.
|
||||
func NewServer(chain core.Blockchainer, conf config.RPCConfig, coreServer *network.Server, log *zap.Logger) Server {
|
||||
// New creates a new Server struct.
|
||||
func New(chain core.Blockchainer, conf config.RPCConfig, coreServer *network.Server, log *zap.Logger) Server {
|
||||
httpServer := &http.Server{
|
||||
Addr: conf.Address + ":" + strconv.FormatUint(uint64(conf.Port), 10),
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package rpc
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -178,7 +178,7 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, http.HandlerFu
|
|||
var nBlocks uint32
|
||||
|
||||
net := config.ModeUnitTestNet
|
||||
configPath := "../../config"
|
||||
configPath := "../../../config"
|
||||
cfg, err := config.Load(configPath, net)
|
||||
require.NoError(t, err, "could not load config")
|
||||
|
||||
|
@ -210,7 +210,7 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, http.HandlerFu
|
|||
serverConfig := network.NewServerConfig(cfg)
|
||||
server, err := network.NewServer(serverConfig, chain, logger)
|
||||
require.NoError(t, err)
|
||||
rpcServer := NewServer(chain, cfg.ApplicationConfiguration.RPC, server, logger)
|
||||
rpcServer := New(chain, cfg.ApplicationConfiguration.RPC, server, logger)
|
||||
handler := http.HandlerFunc(rpcServer.requestHandler)
|
||||
|
||||
return chain, handler
|
|
@ -1,4 +1,4 @@
|
|||
package rpc
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
Loading…
Reference in a new issue