Is Go suitable for writing Web applications?

    2 answers 2

    Full The site http://golang.org has an example wiki application.

    Below is an example of a simple notebook like guestbook on Go.

    File guest.go.

    package main import ( "http" "template" ) const всего = 16 var последняя = 0 type записи struct { сообщение [всего]string } var гостевая записи var шаблон *template.Template = template.MustParseFile("шаблон.html", nil) func увидеть(w http.ResponseWriter, r *http.Request) { ошибка := шаблон.Execute(&гостевая, w) if ошибка != nil { http.Error(w, ошибка.String(), http.StatusInternalServerError) } } func добавить(w http.ResponseWriter, r *http.Request) { if последняя < всего { гостевая.сообщение[последняя] = r.FormValue("body") последняя++ } http.Redirect(w, r, "/увидеть/", http.StatusFound) } func main() { http.HandleFunc("/увидеть/", увидеть) http.HandleFunc("/добавить/", добавить) http.ListenAndServe(":8080", nil) } 

    Template.html file.

     {.repeated section сообщение} <p>{@}</p> {.end} <form action="/добавить/" method="POST"> <div> <textarea name="body" rows="1" cols="40"></textarea> </div> <div> <input type="submit" value="Сохранить"> </div> </form> 

    Run as

     8g гостевая.go && 8l гостевая.8 && ./8.out 

    and look at

     localhost:8080/увидеть/ 

      Only for server-side

      ps hashcode is written in go. Some google stuff too