github.com/zhiqiangxu/go-ethereum@v1.9.16-0.20210824055606-be91cfdebc48/rpc/endpoints.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package rpc 18 19 import ( 20 "net" 21 22 "github.com/zhiqiangxu/go-ethereum/log" 23 ) 24 25 // StartIPCEndpoint starts an IPC endpoint. 26 func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, error) { 27 // Register all the APIs exposed by the services. 28 handler := NewServer() 29 for _, api := range apis { 30 if err := handler.RegisterName(api.Namespace, api.Service); err != nil { 31 return nil, nil, err 32 } 33 log.Debug("IPC registered", "namespace", api.Namespace) 34 } 35 // All APIs registered, start the IPC listener. 36 listener, err := ipcListen(ipcEndpoint) 37 if err != nil { 38 return nil, nil, err 39 } 40 go handler.ServeListener(listener) 41 return listener, handler, nil 42 }