quran-go

Read Qur'an right in the terminal.
git clone http://git.hanabi.in/repos/quran-go.git
Log | Files | Refs | README | LICENSE

http-get.go (567B)


      1 package qurancom
      2 
      3 import (
      4 	"encoding/json"
      5 	"io/ioutil"
      6 	"net/http"
      7 )
      8 
      9 // Custom HTTP client for GET method.
     10 func HttpGet(endpoint string, st interface{}) (err error) {
     11 
     12 	client := &http.Client{}
     13 
     14 	req, err := http.NewRequest(http.MethodGet, endpoint, nil)
     15 	if err != nil {
     16 		return err
     17 	}
     18 
     19 	req.Header.Set("User-Agent", "git.hanabi.in/quran-go v1.0.1")
     20 	resp, err := client.Do(req)
     21 
     22 	if err != nil {
     23 		return err
     24 	}
     25 	defer resp.Body.Close()
     26 
     27 	body, err := ioutil.ReadAll(resp.Body)
     28 	if err != nil {
     29 		return err
     30 	}
     31 
     32 	err = json.Unmarshal(body, &st)
     33 
     34 	return err
     35 
     36 }