Golang template uses map [String] interface {}

Source: Internet
Author: User

About how golang tmplate transmits values, the previous survey results showed that only struct can be used, but recently an open source was opened, and it was found that map [String] interface {} was used {}, think twice, so use the code for verification.

PS, ah, golang's documents are still too weak.

Package mainimport ("FMT" "html/template" "net/HTTP" "OS ") type person struct {name stringage intemails [] stringcompany stringrole string} const Templ = 'name is {{. name} company is {{. resources. company} 'func handler (w http. responsewriter, R * HTTP. request) {chxd: = person {company: "Intel", name: "chxd"} t: = template. new ("person template") T, err: = T. parse (Templ) checkerror (ERR) var TMP map [String] interf Ace {}= map [String] interface {}{ "name": "macs", "Resources": chxd} err = T. execute (W, TMP) checkerror (ERR)} func main () {HTTP. handlefunc ("/", Handler) HTTP. listenandserve (": 8888", nil)} func checkerror (ERR error) {If Err! = Nil {FMT. println ("Fatal error", Err. Error () OS. Exit (1 )}}

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.