erigon-pulse/cmd/restapi/apis/remote_db_api.go
Alex Sharov 9324d83cb2
ethdb.KV interface - pase 2 (#420)
* - handle cursor.Prefix on server
- move state reports to KV interface

* add CmdCursorSeekKey

* tests for abstract_kv

* avoid reading configs of databases

* avoid reading configs of databases

* make linter happy

* make linter happy

* cleanup

* port badger features from original implementation

* try to fix test

* try to fix test

* .Close() don't return error anymore - defer friendly

* try to enable badger now

* try to enable badger now

* badger can't run on CI yet

* badger can't run on CI yet

* re-run ci

* skip ctx cancelation for badger
2020-04-04 08:18:10 +01:00

41 lines
821 B
Go

package apis
import (
"context"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/ledgerwatch/turbo-geth/ethdb"
)
func RegisterRemoteDBAPI(router *gin.RouterGroup, e *Env) error {
router.GET("/", e.GetDB)
router.POST("/", e.PostDB)
return nil
}
func (e *Env) GetDB(c *gin.Context) {
var host, port string
split := strings.Split(e.RemoteDBAddress, ":")
if len(split) == 2 {
host, port = split[0], split[1]
}
c.JSON(http.StatusOK, map[string]string{"host": host, "port": port})
}
func (e *Env) PostDB(c *gin.Context) {
newAddr := c.Query("host") + ":" + c.Query("port")
remoteDB, err := ethdb.NewRemote().Path(newAddr).Open(context.TODO())
if err != nil {
c.Error(err) //nolint:errcheck
return
}
e.RemoteDBAddress = newAddr
e.DB.Close()
e.DB = remoteDB
c.Status(http.StatusOK)
}