Description
I am very new to Nakama , I started playing around Nakama and tried to access Nakama by rpc.
we are started using Nakama for our game dev purposes
When trying to call custom RPC registered using sling client in go its failing and returning "400 with bad request " error in the response from nakama
i am trying to access the rpc function i registered in nakama as “create_match_table”
the code is given below. i was trying with sling http requests
even I tried with simple http request , but no luck, the code is given for the http post request
func main() {
url := "http://127.0.0.1:7350/v2/rpc/create_match_table?http_key=defalutkey"
fmt.Println("URL:>", url)
payloadbuff := []byte(`{\"house_id\":\"mega\",\"tour_id\":\"devtourId\",\"table_config\":{\"nakama_table_label\":\"pokertable\",\"small_blind\":25,\"min_buy_in\":20,\"max_buy_in\":40,\"table_start_min_player_count\":2,\"table_start_max_player_count\":6,\"inr_conv_rate\":0.2}}`)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payloadbuff))
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}`
output :
response Status: 400 Bad Request
response Headers: map[Cache-Control:[no-store, no-cache, must-revalidate] Content-Type:[application/x-gzip] Date:[Sat, 07 Mar 2020 14:04:24 GMT] Vary:[Accept-Encoding]]
response Body: {“error”:“json: cannot unmarshal object into Go value of type string”,“message”:“json: cannot unmarshal object into Go value of type string”,“code”:3}
i don’t really understand why this error is coming ,is it because of payload is in string format in nakama function signature?, the code that i wrote in nakama under this rpc function call back also not hitting?
but when i am trying with simple curl request it is working fine
curl "http://127.0.0.1:7350/v2/rpc/create_match_table?http_key=defalutkey" -d '"{\"house_id\":\"mega\",\"tour_id\":\"devtbel\":\"pokertable\",\"small_blind\":25,\"min_buy_in\":20,\"max_buy_in\":40,\"table_start_min_player_count\":2,\"table_start_max_player_count\":6,\"inr_conv_rate\":0.2}}"' -H 'Content-Type: application/json' -H 'Accept: application/json'
any help would be really appreciated
part from that I am trying to use
// Execute a Lua function on the server.
RpcFunc(ctx context.Context, in *api.Rpc, opts ...grpc.CallOption) (*api.Rpc, error)
function to call my custom rpc , why there is a httpkey in response as well
I am new to this as well , if there any link to custom code , like how to dial securely
Details
*Nakama:“Node”,“name”:“nakama1”,“version”:“2.7.0+d5e0b5bb”,“runtime”:“go1.13”,“cpu”:4,“proc”:4}
- Database: "CockroachDB CCL v19.1.2 (x86_64-unknown-linux-gnu, built 2019/06/07 17:32:15, go1.11.6)
- Environment name and version: docker
- Operating System and version: Mac osx