Skip to content

Commit

Permalink
Make method* variables public
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Aug 27, 2019
1 parent 89fa55d commit 6e176a9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions app/proxy/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func processQuery(query *jsonrpc.RPCRequest) (processedQuery *jsonrpc.RPCRequest, err error) {
processedQuery = query
switch query.Method {
case methodGet:
case MethodGet:
processedQuery, err = queryProcessorGet(query)
}
return processedQuery, err
Expand All @@ -25,11 +25,11 @@ func processQuery(query *jsonrpc.RPCRequest) (processedQuery *jsonrpc.RPCRequest
func processResponse(query *jsonrpc.RPCRequest, response *jsonrpc.RPCResponse) (processedResponse *jsonrpc.RPCResponse, err error) {
processedResponse = response
switch query.Method {
case methodGet:
case MethodGet:
processedResponse, err = responseProcessorGet(query, response)
case methodFileList:
case MethodFileList:
processedResponse, err = responseProcessorFileList(query, response)
case methodAccountList:
case MethodAccountList:
processedResponse, err = responseProcessorAccountList(query, response)
}
return processedResponse, err
Expand Down
22 changes: 11 additions & 11 deletions app/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ var accountSpecificMethods = []string{
"utxo_release",
}

const methodGet = "get"
const methodFileList = "file_list"
const methodAccountList = "account_list"
const methodAccountBalance = "account_balance"
const methodStatus = "status"
const methodResolve = "resolve"
const methodClaimSearch = "claim_search"
const methodCommentList = "comment_list"
const MethodGet = "get"
const MethodFileList = "file_list"
const MethodAccountList = "account_list"
const MethodAccountBalance = "account_balance"
const MethodStatus = "status"
const MethodResolve = "resolve"
const MethodClaimSearch = "claim_search"
const MethodCommentList = "comment_list"

const paramAccountID = "account_id"
const paramUrls = "urls"

var ignoreLog = []string{
methodAccountBalance,
methodStatus,
MethodAccountBalance,
MethodStatus,
}

var ResolveTime float64
Expand Down Expand Up @@ -211,7 +211,7 @@ func ForwardCall(request jsonrpc.RPCRequest) ([]byte, error) {

// shouldCache returns true if we got a resolve query with more than `cacheResolveLongerThan` urls in it.
func shouldCache(method string, params interface{}) bool {
if method == methodResolve && params != nil {
if method == MethodResolve && params != nil {
paramsMap := params.(map[string]interface{})
if urls, ok := paramsMap[paramUrls].([]interface{}); ok {
if len(urls) > cacheResolveLongerThan {
Expand Down
18 changes: 9 additions & 9 deletions app/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestForwardCall_HTTPError(t *testing.T) {
config.Override("Lbrynet", "http://127.0.0.1:49999")
defer config.RestoreOverridden()

query := jsonrpc.NewRequest(methodAccountBalance)
query := jsonrpc.NewRequest(MethodAccountBalance)
response, err := ForwardCall(*query)
assert.NotNil(t, err)
assert.Nil(t, response)
Expand Down Expand Up @@ -209,18 +209,18 @@ func TestForwardCall_ClientError(t *testing.T) {
}

func TestForwardCall_InvalidResolveParams(t *testing.T) {
r := call(t, methodResolve)
r := call(t, MethodResolve)
assert.NotNil(t, r.Error)
assert.Equal(t, "jsonrpc_resolve() missing 1 required positional argument: 'urls'", r.Error.Message)
}

func TestForwardCall_shouldLog(t *testing.T) {
hook := test.NewLocal(monitor.Logger)

call(t, methodResolve, map[string]interface{}{"urls": "what"})
assert.Equal(t, methodResolve, hook.LastEntry().Data["method"])
call(t, methodAccountBalance)
assert.Equal(t, methodResolve, hook.LastEntry().Data["method"])
call(t, MethodResolve, map[string]interface{}{"urls": "what"})
assert.Equal(t, MethodResolve, hook.LastEntry().Data["method"])
call(t, MethodAccountBalance)
assert.Equal(t, MethodResolve, hook.LastEntry().Data["method"])
}

func TestUnmarshalRequest(t *testing.T) {
Expand All @@ -241,7 +241,7 @@ func TesProxyWithCache(t *testing.T) {

resolveArgs := map[string][110]string{paramUrls: homePageUrls}

query = jsonrpc.NewRequest(methodResolve, resolveArgs)
query = jsonrpc.NewRequest(MethodResolve, resolveArgs)
queryBody, _ := json.Marshal(query)
query, err = UnmarshalRequest(queryBody)
rawResponse, err = ForwardCall(*query)
Expand Down Expand Up @@ -274,7 +274,7 @@ func TesProxyWithCache(t *testing.T) {
}

func BenchmarkResolve(b *testing.B) {
query := jsonrpc.NewRequest(methodResolve, map[string][110]string{paramUrls: homePageUrls})
query := jsonrpc.NewRequest(MethodResolve, map[string][110]string{paramUrls: homePageUrls})

wg := sync.WaitGroup{}

Expand All @@ -299,7 +299,7 @@ func BenchmarkResolve(b *testing.B) {

func BenchmarkDirectResolve(b *testing.B) {
rpcClient := jsonrpc.NewClient(config.GetLbrynet())
query := jsonrpc.NewRequest(methodResolve, map[string][110]string{paramUrls: homePageUrls})
query := jsonrpc.NewRequest(MethodResolve, map[string][110]string{paramUrls: homePageUrls})

wg := sync.WaitGroup{}

Expand Down
2 changes: 1 addition & 1 deletion app/proxy/query_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func getPreconditionedQueryResponse(method string, params interface{}) *jsonrpc.
}
}

if method == methodStatus {
if method == MethodStatus {
var r jsonrpc.RPCResponse
r.Result = getStatusResponse()
return &r
Expand Down
4 changes: 2 additions & 2 deletions app/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (q *Query) paramsForLog() map[string]interface{} {

// cacheHit returns true if we got a resolve query with more than `cacheResolveLongerThan` urls in it.
func (q *Query) isCacheable() bool {
if q.Method() == methodResolve && q.Params() != nil {
if q.Method() == MethodResolve && q.Params() != nil {
paramsMap := q.Params().(map[string]interface{})
if urls, ok := paramsMap[paramUrls].([]interface{}); ok {
if len(urls) > cacheResolveLongerThan {
Expand Down Expand Up @@ -163,7 +163,7 @@ func (q *Query) cacheHit() *jsonrpc.RPCResponse {
}

func (q *Query) predefinedResponse() *jsonrpc.RPCResponse {
if q.Method() == methodStatus {
if q.Method() == MethodStatus {
response := q.newResponse()
response.Result = getStatusResponse()
return response
Expand Down

0 comments on commit 6e176a9

Please sign in to comment.