i'm new to golang and it may be a very basic thing but i can't seems to find the solution.
the request return json which is like this.
{"uuid":"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a22","name":"core1","owner":"systems","description":"new","creation_date":"2017-06-10T14:20:00Z"}
This is the gocode.
package main
import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Project struct {
Uuid string `json:"uuid"`
Name string `json:"name"`
Owner string `json:"owner"`
Description string `json:"description"`
Creation_date string `json:"creation_date"`
}
func main() {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
req, err := http.NewRequest("GET", "https://localhost:4443/project/core1", nil)
req.SetBasicAuth("rohit", "rohit")
resp, err := client.Do(req)
if err != nil {
fmt.Printf("server not responding %s", err.Error())
}
var p Project
b, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
err = json.Unmarshal(b, &p)
if err != nil {
fmt.Printf("Test case failed with error %s", err.Error())
}
if resp.StatusCode != 403 {
fmt.Printf("failed %s", err.Error())
}
}
after running i'm getting this error
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x40142f]
goroutine 1 [running]:
panic(0x60c860, 0xc42000c130)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
main.main()
/home/rohitk/Go_projects/src/first_program/test/main.go:41 +0x42f
exit status 2
i checked and response body has right data. can someone please suggest what's happening here.Thanks!