Go language implementation Simple message book

Source: Internet
Author: User

Made a simple message to practice HTTP and template.


Main Go code:

Package Main//golang version of the message//author:xiong Chuan liang//date:2015-3-2import ("FMT" "Html/template" "Io/ioutil" "net/ HTTP "" OS ") Func Main () {http. Handle ("/images/", http. Fileserver (http. Dir ("asset"))) HTTP. Handlefunc ("/", Listhandler) http. Handlefunc ("/add", AddHandler) http. Listenandserve (": 8055", nil)}func AddHandler (w http. Responsewriter, R *http. Request) {h, _: = template. Parsefiles ("Template/addinfo.tpl", "Template/header.tpl", "Template/footer.tpl") h.executetemplate (W, "Addinfo", Nil)}func Listhandler (w http. Responsewriter, R *http.  Request) {if R.method = = "POST" {r.parseform () If Len (r.form["note"][0]) = = 0 {infohandler (W, R, ' <b> commit failed!</b> <br/> message can not be empty! <br/> <a href= "Http://127.0.0.1:8055/add" > Return </a> ') Return}info: = Fmt. Sprintf ("Message person: <a href= ' mailto:%s ' >%s</a><br/> message:%s

Its GUESTBOOK.TPL:

{{define "Guestbook"}}

The effect of the implementation is as follows:





The whole source package is here: Click to download


MAIL: [Email protected]

blog:http://blog.csdn.net/xcl168




Go language implementation Simple message book

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.