github.com/gramework/gramework@v1.8.1-0.20231027140105-82555c9057f5/x/client/get.go (about)

     1  // Copyright 2017-present Kirill Danshin and Gramework contributors
     2  // Copyright 2019-present Highload LTD (UK CN: 11893420)
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  
    11  package client
    12  
    13  import (
    14  	"bytes"
    15  	"encoding/json"
    16  )
    17  
    18  // GET sends a request with GET method
    19  func (client *Instance) GET() (statusCode int, body []byte, err error) {
    20  	api, err := client.nextServer()
    21  	if err != nil {
    22  		return 0, nil, err
    23  	}
    24  
    25  	return api.HostClient.Get(nil, api.Addr)
    26  }
    27  
    28  // GetJSON sends a GET request and deserializes response in a provided variable
    29  func (client *Instance) GetJSON(v interface{}) (statusCode int, err error) {
    30  	statusCode, body, err := client.GET()
    31  	if err != nil {
    32  		return 0, err
    33  	}
    34  
    35  	return statusCode, json.NewDecoder(bytes.NewReader(body)).Decode(&v)
    36  }