• Complain

it-ebooks - Go Mega 教程

Here you can read online it-ebooks - Go Mega 教程 full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2019, publisher: iBooker it-ebooks, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

it-ebooks Go Mega 教程
  • Book:
    Go Mega 教程
  • Author:
  • Publisher:
    iBooker it-ebooks
  • Genre:
  • Year:
    2019
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Go Mega 教程: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Go Mega 教程" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

it-ebooks: author's other books


Who wrote Go Mega 教程? Find out the surname, the name of the author of the book and a list of all author's works by series.

Go Mega 教程 — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Go Mega 教程" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Go-Mega
cover Go-Mega BONFY Web Python Web Miguel Grinberg Flask Web Go Web - photo 1
cover
Go-Mega

Picture 2

BONFY Web Python Web Miguel Grinberg Flask Web

Go Web The Flask Mega-Tutorial Go Web

The Flask Mega

Title

Source Code

Zip

00-Prepare

01-Hello-World

View

Download

02-Template-Basic

View

Download

03-Template-Advance

View

Download

04-Web-Form

View

Download

05-Database

View

Download

06-User-Login

View

Download

07-Profile-Page-And-Avatar

View

Download

08-Follower

View

Download

09-Pagination

View

Download

10-Email-Support

View

Download

11-Facelift

View

Download

12-Dates-And-Times

View

Download

13-Javascript-Magic

View

Download

14-Deployment-On-Heroku

View

Download

15-Deployment-On-Linux

View

Download

16-Summary

08-Follower Twitter GitHub Source DiffZip - Follow - UnFollow - - photo 3
08-Follower

Twitter

GitHub Source, Diff,Zip

:

  • - Follow
  • - UnFollow
  • - FollowSelf
  • follower - FollowersCount
  • following - FollowingCount
  • Posts - FollowingPosts IndexView
  • - IsFollowedByUser
  • (*)Post - CreatePost

Tip: Followers Gorm Association("Followers") Following ()

model/user.go

... // Follow func // follow someone usr_id other.id follow_id u.id func ( u * User ) Follow ( username string ) error { other , err := GetUserByUsername (username) if err != nil { return err} return db. Model (other). Association ( " Followers " ). Append (u). Error } // Unfollow func func ( u * User ) Unfollow ( username string ) error { other , err := GetUserByUsername (username) if err != nil { return err} return db. Model (other). Association ( " Followers " ). Delete (u). Error } // FollowSelf func func ( u * User ) FollowSelf () error { return db. Model (u). Association ( " Followers " ). Append (u). Error } // FollowersCount func func ( u * User ) FollowersCount () int { return db. Model (u). Association ( " Followers " ). Count ()} // FollowingIDs func func ( u * User ) FollowingIDs () [] int { var ids [] int rows , err := db. Table ( " follower " ). Where ( " follower_id = ? " , u. ID ). Select ( " user_id, follower_id " ). Rows () if err != nil {log. Println ( " Counting Following error: " , err) return ids} defer rows. Close () for rows. Next () { var id , followerID int rows. Scan (&id, &followerID)ids = append (ids, id)} return ids} // FollowingCount func func ( u * User ) FollowingCount () int { ids := u. FollowingIDs () return len (ids)} // FollowingPosts func func ( u * User ) FollowingPosts () (*[] Post , error ) { var posts []Post ids := u. FollowingIDs () if err := db. Preload ( " User " ). Order ( " timestamp desc " ). Where ( " user_id in (?) " , ids). Find (&posts). Error ; err != nil { return nil , err} return &posts, nil } // IsFollowedByUser func func ( u * User ) IsFollowedByUser ( username string ) bool { user , _ := GetUserByUsername (username) ids := user. FollowingIDs () for _ , id := range ids { if u. ID == id { return true }} return false } // CreatePost func func ( u * User ) CreatePost ( body string ) error { post := Post{Body: body, UserID: u. ID } return db. Create (&post). Error }...

AddUser FollowSelf, Profile FollowingPosts Post

model/user.go

// AddUser func func AddUser ( username , password , email string ) error { user := User{Username: username, Email: email}user. SetPassword (password)user. SetAvatar (email) if err := db. Create (&user). Error ; err != nil { return err} return user. FollowSelf ()}

Follower

cmd/init_db\main.go

package main import ( " log " " github.com/bonfy/go-mega-code/model " _ " github.com/jinzhu/gorm/dialects/mysql " ) func main () {log. Println ( " DB Init ... " ) db := model. ConnectToDB () defer db. Close ()model. SetDB (db)db. DropTableIfExists (model. User {}, model. Post {}, " follower " )db. CreateTable (model. User {}, model. Post {})model. AddUser ( " bonfy " , " abc123 " , " i@bonfy.im " )model. AddUser ( " rene " , " abc123 " , " rene@test.com " ) u1 , _ := model. GetUserByUsername ( " bonfy " )u1. CreatePost ( " Beautiful day in Portland! " )model. UpdateAboutMe (u1. Username , ` I'm the author of Go-Mega Tutorial you are reading now! ` ) u2 , _ := model. GetUserByUsername ( " rene " )u2. CreatePost ( " The Avengers movie was so cool! " )u2. CreatePost ( " Sun shine is beautiful " )u1. Follow (u2. Username )}
$ go run cmd/db_init/main.go

follower

userid followerid bonfyid1 reneid2 u1Followu2Username Diff - photo 4

: user_id follower_id bonfyid:1) , rene(id:2) , u1.Follow(u2.Username)

Diff

Follow and Unfollow

controller/home.go

... func ( h home ) registerRoutes () { r := mux. NewRouter ()r. HandleFunc ( " /logout " , middleAuth (logoutHandler))r. HandleFunc ( " /login " , loginHandler)r. HandleFunc ( " /register " , registerHandler)r. HandleFunc ( " /user/{username} " , middleAuth (profileHandler))r. HandleFunc ( " /follow/{username} " , middleAuth (followHandler))r. HandleFunc ( " /unfollow/{username} " , middleAuth (unFollowHandler))r. HandleFunc ( " /profile_edit " , middleAuth (profileEditHandler))r. HandleFunc ( " / " , middleAuth (indexHandler))http. Handle ( " / " , r)}... func followHandler ( w http . ResponseWriter , r * http . Request ) { vars := mux. Vars (r) pUser := vars[ " username " ] sUser , _ := getSessionUser (r) err := vm. Follow (sUser, pUser) if err != nil {log. Println ( " Follow error: " , err)w. Write ([] byte ( " Error in Follow " )) return }http. Redirect (w, r, fmt. Sprintf ( " /user/ %s " , pUser), http. StatusSeeOther )} func unFollowHandler ( w http . ResponseWriter , r * http . Request ) { vars := mux. Vars (r) pUser := vars[ " username " ] sUser , _ := getSessionUser (r) err := vm. UnFollow (sUser, pUser) if err != nil {log. Println ( " UnFollow error: " , err)w. Write ([] byte ( " Error in UnFollow " )) return }http. Redirect (w, r, fmt. Sprintf ( " /user/ %s " , pUser), http. StatusSeeOther )}

FollowUnfollow Redirect

Profile

vm/profile.go

package vm import " github.com/bonfy/go-mega-code/model " // ProfileViewModel struct type ProfileViewModel struct { BaseViewModel Posts []model. Post Editable bool IsFollow bool FollowersCount int FollowingCount int ProfileUser model. User } // ProfileViewModelOp struct type ProfileViewModelOp struct {} // GetVM func func ( ProfileViewModelOp ) GetVM ( sUser , pUser string ) ( ProfileViewModel , error ) { v := ProfileViewModel{}v. SetTitle ( " Profile " ) u , err := model. GetUserByUsername (pUser) if err != nil { return v, err} posts , _ := model. GetPostsByUserID (u. ID )v. ProfileUser = *uv. Editable = (sUser == pUser) if !v. Editable {v. IsFollow = u. IsFollowedByUser (sUser)}v. FollowersCount = u. FollowersCount ()v. FollowingCount = u. FollowingCount ()v. Posts = *postsv. SetCurrentUser (sUser) return v, nil } // Follow func : A follow B func Follow ( a , b string ) error { u , err := model. GetUserByUsername (a) if err != nil { return err} return u. Follow (b)} // UnFollow func : A unfollow B func UnFollow ( a , b string ) error { u , err := model. GetUserByUsername (a) if err != nil { return err} return u. Unfollow (b)}
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Go Mega 教程»

Look at similar books to Go Mega 教程. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Go Mega 教程»

Discussion, reviews of the book Go Mega 教程 and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.