This is a creation in Article, where the information may have evolved or changed.
Package Main
Import (
"Database/sql"
_ "Github.com/mattn/go-sqlite3"
"FMT"
"Log"
"Net/http"
"StrConv"
)
Type User struct {
ID int
Name string
}
Func (user User) string () string {
Format: = ' ID:%d Name:%s '
Return to FMT. Sprintf (format, user.id, user. Name)
}
Func AddUser (w http. Responsewriter, req *http. Request) {
UserId, _: = StrConv. Atoi (req. Formvalue ("Id"))
Name: = Req. Formvalue ("name")
Out: = StrConv. Itoa (userId) + "-" + Name
U: = &user{id:userid, Name:name}
Log. Println (out)
Fmt. fprintf (W, u.string ())
}
Func SayHello (w http. Responsewriter, R *http. Request) {
Fmt. fprintf (w, "Hello world!")
}
Func Main () {
http. Handlefunc ("/", SayHello)
http. Handlefunc ("/user", AddUser)
ERR: = http. Listenandserve (": 8880", nil)
If err! = Nil {
Log. Fatal ("Listenandserve:", err.) Error ())
}
}