kopia lustrzana https://github.com/bugout-dev/moonstream
pagination for cli resources
rodzic
34ec0f3b93
commit
6dcb63b5df
|
@ -6,7 +6,7 @@
|
|||
- Build application
|
||||
|
||||
```bash
|
||||
go build -o nodebalancer
|
||||
go build -o nodebalancer .
|
||||
```
|
||||
|
||||
# Work with nodebalancer
|
||||
|
@ -90,3 +90,10 @@ curl --request GET 'http://127.0.0.1:8544/nb/ethereum/jsonrpc?access_id=<access_
|
|||
"id":1
|
||||
}'
|
||||
```
|
||||
|
||||
For Web3 providers `access_id` and `data_source` could be specified in headers
|
||||
|
||||
```bash
|
||||
--header 'x-node-balancer-data-source: <blockchain/database>'
|
||||
--header 'x-node-balancer-access-id: <access_id>'
|
||||
```
|
||||
|
|
|
@ -39,6 +39,10 @@ type StateCLI struct {
|
|||
listeningPortFlag string
|
||||
enableHealthCheckFlag bool
|
||||
enableDebugFlag bool
|
||||
|
||||
// Users list flags
|
||||
limitFlag int
|
||||
offsetFlag int
|
||||
}
|
||||
|
||||
func (s *StateCLI) usage() {
|
||||
|
@ -58,23 +62,23 @@ func (s *StateCLI) checkRequirements() {
|
|||
if s.helpFlag {
|
||||
switch {
|
||||
case s.addAccessCmd.Parsed():
|
||||
fmt.Println("add new user access token")
|
||||
fmt.Printf("Add new user access token\n\n")
|
||||
s.addAccessCmd.PrintDefaults()
|
||||
os.Exit(0)
|
||||
case s.deleteAccessCmd.Parsed():
|
||||
fmt.Println("delete user access token")
|
||||
fmt.Printf("Delete user access token\n\n")
|
||||
s.deleteAccessCmd.PrintDefaults()
|
||||
os.Exit(0)
|
||||
case s.serverCmd.Parsed():
|
||||
fmt.Println("start nodebalancer server")
|
||||
fmt.Printf("Start nodebalancer server\n\n")
|
||||
s.serverCmd.PrintDefaults()
|
||||
os.Exit(0)
|
||||
case s.usersCmd.Parsed():
|
||||
fmt.Println("list user access tokens")
|
||||
fmt.Printf("List user access tokens\n\n")
|
||||
s.usersCmd.PrintDefaults()
|
||||
os.Exit(0)
|
||||
case s.versionCmd.Parsed():
|
||||
fmt.Println("show version")
|
||||
fmt.Printf("Show version\n\n")
|
||||
s.versionCmd.PrintDefaults()
|
||||
os.Exit(0)
|
||||
default:
|
||||
|
@ -86,7 +90,7 @@ func (s *StateCLI) checkRequirements() {
|
|||
switch {
|
||||
case s.addAccessCmd.Parsed():
|
||||
if s.userIDFlag == "" {
|
||||
fmt.Println("User ID should be specified")
|
||||
fmt.Printf("User ID should be specified\n\n")
|
||||
s.addAccessCmd.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -94,16 +98,22 @@ func (s *StateCLI) checkRequirements() {
|
|||
s.accessIDFlag = uuid.New().String()
|
||||
}
|
||||
if s.accessNameFlag == "" {
|
||||
fmt.Println("Access name should be specified")
|
||||
fmt.Printf("Access name should be specified\n\n")
|
||||
s.addAccessCmd.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
case s.deleteAccessCmd.Parsed():
|
||||
if s.userIDFlag == "" && s.accessIDFlag == "" {
|
||||
fmt.Println("User or access ID flag should be specified")
|
||||
fmt.Printf("User or access ID flag should be specified\n\n")
|
||||
s.deleteAccessCmd.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
case s.usersCmd.Parsed():
|
||||
if s.offsetFlag < 0 || s.limitFlag < 0 {
|
||||
fmt.Printf("Offset and limit flags should be greater then zero\n\n")
|
||||
s.usersCmd.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,6 +147,10 @@ func (s *StateCLI) populateCLI() {
|
|||
s.serverCmd.StringVar(&s.listeningPortFlag, "port", "8544", "Server listening port")
|
||||
s.serverCmd.BoolVar(&s.enableHealthCheckFlag, "healthcheck", false, "To enable healthcheck ser healthcheck flag")
|
||||
s.serverCmd.BoolVar(&s.enableDebugFlag, "debug", false, "To enable debug mode with extended log set debug flag")
|
||||
|
||||
// Users list subcommand flag pointers
|
||||
s.usersCmd.IntVar(&s.limitFlag, "limit", 10, "Output result limit")
|
||||
s.usersCmd.IntVar(&s.offsetFlag, "offset", 0, "Result output offset")
|
||||
}
|
||||
|
||||
func CLI() {
|
||||
|
@ -216,7 +230,17 @@ func CLI() {
|
|||
}
|
||||
|
||||
var userAccesses []UserAccess
|
||||
for _, resourceData := range resources.Resources {
|
||||
|
||||
offset := stateCLI.offsetFlag
|
||||
if stateCLI.offsetFlag > len(resources.Resources) {
|
||||
offset = len(resources.Resources)
|
||||
}
|
||||
limit := stateCLI.offsetFlag + stateCLI.limitFlag
|
||||
if limit > len(resources.Resources) {
|
||||
limit = len(resources.Resources[offset:]) + offset
|
||||
}
|
||||
|
||||
for _, resourceData := range resources.Resources[offset:limit] {
|
||||
userAccesses = append(userAccesses, resourceData.ResourceData)
|
||||
}
|
||||
userAccessesJson, err := json.Marshal(userAccesses)
|
||||
|
|
|
@ -17,7 +17,10 @@ import (
|
|||
|
||||
var ALLOWED_METHODS = []string{
|
||||
"eth_blockNumber",
|
||||
"eth_call",
|
||||
"eth_chainId",
|
||||
"eth_estimateGas",
|
||||
"eth_feeHistory",
|
||||
"eth_gasPrice",
|
||||
"eth_getBalance",
|
||||
"eth_getBlockByHash",
|
||||
|
@ -25,6 +28,7 @@ var ALLOWED_METHODS = []string{
|
|||
"eth_getBlockTransactionCountByHash",
|
||||
"eth_getBlockTransactionCountByNumber",
|
||||
"eth_getCode",
|
||||
"eth_getLogs",
|
||||
"eth_getStorageAt",
|
||||
"eth_getTransactionByHash",
|
||||
"eth_getTransactionByBlockHashAndIndex",
|
||||
|
@ -36,8 +40,16 @@ var ALLOWED_METHODS = []string{
|
|||
"eth_getUncleCountByBlockHash",
|
||||
"eth_getUncleCountByBlockNumber",
|
||||
"eth_getWork",
|
||||
"eth_mining",
|
||||
// "eth_sendRawTransaction",
|
||||
"eth_protocolVersion",
|
||||
"eth_syncing",
|
||||
|
||||
"net_listening",
|
||||
"net_peerCount",
|
||||
"net_version",
|
||||
|
||||
"web3_clientVersion",
|
||||
}
|
||||
|
||||
type JSONRPCRequest struct {
|
||||
|
|
Ładowanie…
Reference in New Issue