Is Go suitable for writing Web applications?

Is Go suitable for writing Web applications?

Author: Nicolas Chabanovsky, 2010-10-14

2 answers

Quite. On the site http://golang.org there is an example of a wiki application.

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

Guest file.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)
}

File шаблон.html.

{.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/увидеть/
 5
Author: stanislav, 2010-10-14 18:14:20

Only for server-side

P. s. the hashcode is written in go. Some stuff on google too

 2
Author: kandi, 2012-10-25 14:31:36