package users import ( "git.aiterp.net/rpdata/api/models" "github.com/globalsign/mgo" ) // Ensure finds a user by id, or makes a new one. func Ensure(id string) (models.User, error) { user := models.User{} err := collection.FindId(id).One(&user) if err == mgo.ErrNotFound { user = models.User{ ID: id, Nick: "", Permissions: []string{ "member", "log.edit", "post.edit", "post.move", "file.upload", }, } err := collection.Insert(user) if err != nil { return models.User{}, err } } return user, err }