fix_: moved server package, fix flag parsing, response jsone

This commit is contained in:
Igor Sirotin 2024-09-19 23:52:18 +01:00
parent 9f6bfa6a36
commit 1618aab830
No known key found for this signature in database
GPG Key ID: 425E227CAAB81F95
7 changed files with 20 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/cmd/statusd/server"
"github.com/status-im/status-go/cmd/status-backend/server"
)
var (
@ -14,6 +14,8 @@ var (
)
func main() {
flag.Parse()
srv := server.NewServer()
srv.Setup()

View File

@ -1,5 +1,14 @@
//go:generate go run main.go
/*
This script generates a Go file with a list of supported endpoints based on the public functions in `mobile/status.go`.
The output has 3 sections:
- Endpoints with a response of type `string`
- Endpoints with no arguments and a response of type `string`
- Unsupported endpoints: those have non-standard signatures
Deprecated functions are ignored.
*/
package main
import (

View File

@ -2,7 +2,6 @@ package server
import (
"context"
"errors"
"io"
"net"
"net/http"
@ -14,6 +13,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/pkg/errors"
"github.com/status-im/status-go/signal"
)
@ -65,6 +65,11 @@ func (s *Server) Listen(address string) error {
return errors.New("server already started")
}
_, _, err := net.SplitHostPort(address)
if err != nil {
return errors.Wrap(err, "invalid address")
}
s.server = &http.Server{
Addr: address,
ReadHeaderTimeout: 5 * time.Second,
@ -74,7 +79,6 @@ func (s *Server) Listen(address string) error {
s.mux.HandleFunc("/signals", s.signals)
s.server.Handler = s.mux
var err error
s.listener, err = net.Listen("tcp", address)
if err != nil {
return err
@ -140,6 +144,7 @@ func (s *Server) addEndpointWithResponse(name string, handler func(string) strin
response := handler(string(request))
w.Header().Set("Content-Type", "application/json")
_, err = w.Write([]byte(response))
if err != nil {
log.Error("failed to write response: %w", err)

View File

@ -23,7 +23,7 @@ import (
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/cmd/statusd/server"
"github.com/status-im/status-go/cmd/status-backend/server"
"github.com/status-im/status-go/common/dbsetup"
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
"github.com/status-im/status-go/eth-node/crypto"