Google App Engine users
Another service we are going to make use of is the Google App Engine Users API, which provides the authentication of Google accounts (and Google Apps accounts).
Create a new file called users.go
and add the following code:
type User struct { Key *datastore.Key `json:"id" datastore:"-"` UserID string `json:"-"` DisplayName string `json:"display_name"` AvatarURL string `json:"avatar_url"` Score int `json:"score"` }
Similar to the Question
struct, we have Key
and a few fields that make up the User
entity. This struct represents an object that belongs to our application that describes a user; we will have one for every authenticated user in our system, but this isn't the same user object that we'll get from the Users API.
Importing the https://godoc.org/google.golang.org/appengine/user package and calling the user.Current(context.Context)
function will return either nil (if no user is authenticated) or a user.User
object. This object belongs to the Users...