github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume3/section5/gopherface/endpoints/getuserprofile.go (about) 1 package endpoints 2 3 import ( 4 "encoding/json" 5 "log" 6 "net/http" 7 8 "github.com/EngineerKamesh/gofullstack/volume3/section5/gopherface/common/authenticate" 9 10 "github.com/EngineerKamesh/gofullstack/volume3/section5/gopherface/common" 11 ) 12 13 func GetUserProfileEndpoint(env *common.Env) http.HandlerFunc { 14 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 15 16 gfSession, err := authenticate.SessionStore.Get(r, "gopherface-session") 17 if err != nil { 18 log.Print(err) 19 return 20 } 21 uuid := gfSession.Values["uuid"] 22 u, err := env.DB.GetUserProfile(uuid.(string)) 23 24 if err != nil { 25 log.Print(err) 26 } 27 28 u.Username = gfSession.Values["username"].(string) 29 30 w.Header().Set("Content-Type", "application/json") 31 json.NewEncoder(w).Encode(u) 32 33 }) 34 }