extract startServer

This commit is contained in:
Anton Evangelatov 2020-06-30 17:53:27 +02:00
parent e3d2d2e7c1
commit 0a9af6ad5c
2 changed files with 20 additions and 32 deletions

View File

@ -1341,8 +1341,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/testground/sdk-go v0.2.3-0.20200626214218-7a87893cf56c h1:fZXuBXPwBL2Z4UdH1YVkWs7rqNCaVwSmpu3SmVeayZ0=
github.com/testground/sdk-go v0.2.3-0.20200626214218-7a87893cf56c/go.mod h1:3auzMDXaoK7NQ+CLQS3pqp4hmREECWO9V+TJi/IWmms=
github.com/testground/sdk-go v0.2.3-0.20200630123819-17fe227923bd h1:e4QpR+UgiQUfFMz3LjMT2ey1VO5+Wa6R0MJBu3BpwIk=
github.com/testground/sdk-go v0.2.3-0.20200630123819-17fe227923bd/go.mod h1:3auzMDXaoK7NQ+CLQS3pqp4hmREECWO9V+TJi/IWmms=
github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e/go.mod h1:XDKHRm5ThF8YJjx001LtgelzsoaEcvnA7lVWz9EeX3g=

View File

@ -782,16 +782,6 @@ func getDrandConfig(ctx context.Context, t *TestEnvironment) (node.Option, error
}
func startStorMinerAPIServer(repo *repo.MemRepo, minerApi api.StorageMiner) error {
endpoint, err := repo.APIEndpoint()
if err != nil {
return err
}
lst, err := manet.Listen(endpoint)
if err != nil {
return fmt.Errorf("could not listen: %w", err)
}
mux := mux.NewRouter()
rpcServer := jsonrpc.NewServer()
@ -808,24 +798,10 @@ func startStorMinerAPIServer(repo *repo.MemRepo, minerApi api.StorageMiner) erro
srv := &http.Server{Handler: ah}
go func() {
_ = srv.Serve(manet.NetListener(lst))
}()
return nil
return startServer(repo, srv)
}
func startClientAPIServer(repo *repo.MemRepo, api api.FullNode) error {
endpoint, err := repo.APIEndpoint()
if err != nil {
return err
}
lst, err := manet.Listen(endpoint)
if err != nil {
return fmt.Errorf("could not listen: %w", err)
}
rpcServer := jsonrpc.NewServer()
rpcServer.Register("Filecoin", apistruct.PermissionedFullAPI(api))
@ -838,11 +814,7 @@ func startClientAPIServer(repo *repo.MemRepo, api api.FullNode) error {
srv := &http.Server{Handler: http.DefaultServeMux}
go func() {
_ = srv.Serve(manet.NetListener(lst))
}()
return nil
return startServer(repo, srv)
}
func withApiEndpoint(lr repo.LockedRepo) error {
@ -852,3 +824,21 @@ func withApiEndpoint(lr repo.LockedRepo) error {
}
return lr.SetAPIEndpoint(apima)
}
func startServer(repo *repo.MemRepo, srv *http.Server) error {
endpoint, err := repo.APIEndpoint()
if err != nil {
return err
}
lst, err := manet.Listen(endpoint)
if err != nil {
return fmt.Errorf("could not listen: %w", err)
}
go func() {
_ = srv.Serve(manet.NetListener(lst))
}()
return nil
}