0

I'm trying to make a RESTful API on Go Lang returning JSON value. I am not getting any value on the page when I load it. Could anyone help me out here.. ?

type sessiond struct{
   apiKey string `json:"apiKey"`
   token string `json:"token"`
}

func dummy(w http.ResponseWriter, r *http.Request) {
   se:=sessiond{apiKey:key,token:"erer"}
   log.Println(se);    // Iam getting the value here ! but nothing on the page.
   w.Header().Set("Content-Type", "application/json; charset=UTF-8")
   w.WriteHeader(http.StatusOK)
      if err := json.NewEncoder(w).Encode(se); err != nil {
      panic(err)
   }
   //res.R200(w, se)
}
Tjs
  • 773
  • 8
  • 15

1 Answers1

2

Export the fields in type sessiond by starting the field name with an uppercase letter.

type sessiond struct{
   ApiKey string `json:"apiKey"`
   Token string `json:"token"`
}

The JSON encoder and decoder ignore unexported fields.

Bayta Darell
  • 101,448
  • 10
  • 207
  • 215