go-eth-proxy

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs

commit 0deb189254141dbca5530a205b6b0f4774c0dae3
parent 40ed55ca259722161105654fef1f1680e7c0ca1e
Author: lash <dev@holbrook.no>
Date:   Fri, 28 Jun 2024 21:35:17 +0100

Enable invoke without remote

Diffstat:
Mcmd/main.go | 2+-
Mproxy/rpc.go | 17++++++++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go @@ -23,7 +23,7 @@ func main() { defer db.Close() svc := proxy.NewProxyService(db) - h, err := proxy.NewProxyServer(svc, flag.Args()[0]) + h, err := proxy.NewProxyServer(svc, flag.Arg(0)) if err != nil { log.Printf("%s", err) os.Exit(1) diff --git a/proxy/rpc.go b/proxy/rpc.go @@ -24,9 +24,14 @@ type ProxyServer struct { } func NewProxyServer(svc *ProxyService, remoteURI string) (*ProxyServer, error) { - uri, err := url.Parse(remoteURI) - if err != nil { - return nil, err + var uri *url.URL + var err error + + if remoteURI != "" { + uri, err = url.Parse(remoteURI) + if err != nil { + return nil, err + } } srv := &ProxyServer{ Server: rpc.NewServer(), @@ -72,6 +77,12 @@ func (s *ProxyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } + if s.uri == nil { + log.Printf("missing remote side for unproxied method: %s", msg.Method) + w.WriteHeader(http.StatusBadGateway) + return + } + client_req := &http.Request{} client_req.Method = "POST" client_req.URL = s.uri