\u6a21\u677f\u662f\u5c06\u4e00\u4e2a\u4e8b\u7269\u7684\u7ed3\u6784\u89c4\u5f8b\u4e88\u4ee5\u56fa\u5b9a\u5316\u3001\u6807\u51c6\u5316\u7684\u6210\u679c\uff0c\u5b83\u4f53\u73b0\u7684\u662f\u7ed3\u6784\u5f62\u5f0f\u7684\u6807\u51c6\u5316\u3002\u5bf9\u4e8e\u6211\u4eec\u7a0b\u5e8f\u5458\u6765\u8bf4\uff0c\u66f4\u76f4\u767d\u7684\u7406\u89e3\u662f\uff1b\u5bf9\u4e8e\u8981\u8f93\u51fa\u7684\u5185\u5bb9\uff0c\u4e2a\u4eba\u4f4d\u7f6e\u9700\u8981\u53c2\u6570\u5316\u586b\u5145\uff0c\u9700\u8981\u586b\u5145\u7684\u53c2\u6570\u4f4d\u7f6e\u662f\u56fa\u5b9a\u7684\uff0c\u8f93\u51fa\u7684\u5185\u5bb9\u662f\u6709\u7edf\u4e00\u6807\u51c6\u7684\u3002\u5c31\u50cf\u662f\u6211\u4eec\u5c0f\u65f6\u5019\u505a\u7684\u586b\u7a7a\u9898\uff0c\u9898\u76ee\u56fa\u5b9a\uff0c\u6709\u56fa\u5b9a\u7684\u4f4d\u7f6e\u9700\u8981\u586b\u5145\uff0c\u6a21\u7248\u5c31\u662f\u539f\u7406\u3002<\/p> \n go\u8bed\u8a00\u5f00\u53d1\u4e86\u4e13\u95e8\u7684packge\u7528\u4e8e\u652f\u6301\u6a21\u7248\u7f16\u7a0b\uff0c\u6211\u4eec\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6709\u65f6\u5019\u4f1a\u78b0\u5230\u6a21\u7248\u7f16\u7a0b\u5f97\u5230\u60c5\u51b5\uff0c\u6bd4\u5982\u60f3\u8981\u5b9e\u73b0\u81ea\u52a8\u5316\u7684\u8f93\u51fa\u4e00\u4e9b\u7528\u4e8e\u5176\u4ed6\u5de5\u7a0b\u6267\u884c\u7684\u6709\u6548\u4ee3\u7801\uff0c\u6216\u8005\u5f62\u6210\u4e00\u4e9b\u524d\u7aef\u9875\u9762\uff0c\u90fd\u4f1a\u7528\u5230\u6a21\u7248\u7f16\u7a0b\u3002<\/p> \n go\u8bed\u8a00\u4e2d\u6a21\u7248\u7f16\u7a0b\u5206\u4e3a\u4e24\u4e2a\u5927\u65b9\u5411\uff0c\u4e00\u79cd\u662f\u771f\u7684\u524d\u7aef\u7684\uff0c\u662f\u5728html\/template\u4e0b\uff0c\u8fd8\u6709\u4e00\u4e2a\u662f\u9488\u5bf9\u6587\u672c\u7684\uff0c\u5728text\/template\u4e0b\uff0c\u4e24\u8005\u5957\u8def\u7c7b\u4f3c\uff0c\u6211\u4eec\u6765\u8bf4\u4e00\u4e0b\u5bf9\u4e8e\u6587\u672c\u7684\u5904\u7406\u3002<\/p> \n \u6a21\u7248\u7f16\u7a0b\u53ef\u5206\u4e3a4\u6b65\uff1a<\/p> \n \u6211\u4eec\u53ef\u4ee5\u5148\u770b\u5b98\u65b9\u793a\u4f8b\u7ed9\u7684\u4ee3\u7801\uff0c\u628a\u6b65\u9aa4\u91cd\u65b0\u8ba4\u8bc6\u4e00\u904d\u3002<\/p> \n \u6240\u8c13\u7684\u5b9a\u4e49\u6a21\u7248\u5c31\u662fParse\u4e2d\u7684\u5185\u5bb9\uff1a<\/p> \n template\u8c03\u7528New\u4ee5\u53ca\u540e\u9762\u7684Parse\u5c31\u662f\u521b\u5efa\u6a21\u7248\uff1a<\/p> \n \u6a21\u7248\u6570\u636e\u7684\u51c6\u5907\u662f\u6307\u7ed3\u6784\u5b9a\u4e49\u548c\u6570\u636e\u51c6\u5907\uff1a<\/p> \n \u6a21\u7248\u6267\u884c\u662fExecute\uff0c\u6ce8\u610f\u6a21\u7248\u6267\u884c\u65f6\u9700\u8981\u6307\u5b9a\u8f93\u51fa\u63cf\u8ff0\u7b26\uff08\u53ef\u4ee5\u662f\u67d0\u4e2a\u6587\u4ef6\u6216\u8005\u6807\u51c6\u8f93\u51fa\uff0c\u5bf9\u5e94\u7684go\u8bed\u8a00\u4e2d\u7684io.writer\uff09<\/p> \n \u4e0a\u8ff0\u4f8b\u5b50\u5c31\u662f\u4e00\u4e2a\u6700\u4e3a\u7b80\u5355\u7684\u6a21\u7248\u7f16\u7a0b\uff0c\u66f4\u8be6\u5c3d\u7684\u53ef\u4ee5\u770b\u8fd9\u91cc\uff1a\u5b98\u65b9\u8be6\u7ec6\u8d44\u6599<\/a><\/p> \n \u4e0a\u8ff0\u4f8b\u5b50\u9664\u4e86\u9610\u8ff0\u6a21\u7248\u7f16\u7a0b\u7684\u56db\u6b65\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u91cd\u8981\u4fe1\u606f<\/strong>\uff0c\u6a21\u7248\u7f16\u7a0b\u5728\u6267\u884c\u7684\u65f6\u5019\uff0c\u5bf9\u6570\u636e\u7ed3\u6784\u4f53\u6709\u8981\u6c42\uff0c\u6a21\u7248\u4f7f\u7528{{}}\u5305\u542b\u7684\u53d8\u91cf\u540d\u5b57\u5fc5\u987b\u5728\u7ed3\u6784\u4f53\u6709\u5176\u5bf9\u5e94\uff0c\u5426\u5219\u6267\u884c\u7684\u65f6\u5019\u5c06\u4e0d\u80fd\u6210\u529f\u3002<\/p> \n \u4e0b\u9762\u662f\u6a21\u7248\u7f16\u7a0b\u91cc\u7684\u4e00\u4e9bactions\u4ecb\u7ecd\u3002<\/p> \n \u6211\u4eec\u6765\u770b\u4e00\u4e9b\u590d\u6742\u70b9\u7684\u4f8b\u5b50\uff1a<\/p> \n \u4e0a\u8ff0\u4ee3\u7801\u662f\u4e00\u4e2a\u5199\u4fe1\u7684\u6a21\u7248\uff0c\u6536\u4fe1\u65b9\u662f\u4e00\u4e2a\u56fa\u5b9a\u586b\u5145\u4f4d\u7f6e\uff0cAttended\u662f\u4e00\u4e2a\u9644\u52a0\u4fe1\u606f\uff0c\u5982\u679c\u4e3a\u771f\uff0c\u5219\u4e3a\u53d7\u9080\u53c2\u52a0\u5a5a\u793c\uff0c\u4e3a\u5047\u5219\u4e0d\u88ab\u9080\u8bf7\u3002Gift\u5219\u662f\u5bf9\u793c\u7269\u7684\u63cf\u8ff0\uff0c\u5982\u679c\u793c\u7269\u4e0d\u4e3a\u7a7a\uff0c\u5219\u8be5\u6536\u4fe1\u4eba\u4f1a\u6709\u793c\u7269\uff0c\u5426\u5219\u6ca1\u6709\u3002<\/p> \n \u6839\u636e\u6570\u636e\u60c5\u51b5recipients\u6765\u770b\uff0c\u53ea\u6709\u7b2c\u4e00\u4e2a\u4eba\u53d7\u9080\u53c2\u52a0\u5a5a\u793c\uff0c\u524d\u4e24\u4e2a\u4eba\u4f1a\u6709\u793c\u7269\uff0c\u6240\u4ee5\u6700\u7ec8\u7684\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p> \n
\u4f20\u9001\u95e8: \u67cf\u94fe\u9879\u76ee\u5b66\u9662<\/a><\/p> \n
\n
<\/p> \n go\u8bed\u8a00\u4e0e\u6a21\u7248\u7f16\u7a0b<\/h2> \n
\u4ec0\u4e48\u662f\u6a21\u7248\u7f16\u7a0b<\/h3> \n
go\u8bed\u8a00\u6a21\u7248\u7f16\u7a0b\u6b65\u9aa4<\/h2> \n
\n
type Inventory struct {\n Material string\n Count uint\n}\nsweaters := Inventory{"wool", 17}\ntmpl, err := template.New("test").Parse("{{.Count}} items are made of {{.Material}}")\nif err != nil { panic(err) }\nerr = tmpl.Execute(os.Stdout, sweaters)\nif err != nil { panic(err) }<\/code><\/pre> \n
{{.Count}} items are made of {{.Material}}<\/code><\/pre> \n
tmpl, err := template.New("test").Parse("{{.Count}} items are made of {{.Material}}")\nif err != nil { panic(err) }<\/code><\/pre> \n
type Inventory struct {\n Material string\n Count uint\n}\nsweaters := Inventory{"wool", 17}<\/code><\/pre> \n
err = tmpl.Execute(os.Stdout, sweaters)<\/code><\/pre> \n
{{\/* a comment *\/}} \u6ce8\u91ca\n{{pipeline}} \u6a21\u7248\u7684\u53d8\u91cf\n{{if pipeline}} T1 {{end}} \u5982\u679cpipeline\u4e3a\u7a7a\uff0c\u5219T1\u4e0d\u4f1a\u6267\u884c\uff0c\n{{if pipeline}} T1 {{else}} T0 {{end}} \u8fd9\u662f\u5728\u4e0a\u9762\u7684\u57fa\u7840\u4e0a\u589e\u52a0\u4e86else\u5206\u652f\n{{if pipeline}} T1 {{else if pipeline}} T0 {{end}} \u5f53\u7136\u8fd8\u53ef\u4ee5else if\uff0c\u8fd9\u4e9b\u5bf9\u719f\u6089\u7f16\u7a0b\u7684\u4eba\u6765\u8bf4\u4e0d\u7b97\u4ec0\u4e48\n{{range pipeline}} T1 {{end}} \u8fd9\u4e2a\u8981\u6c42pipeline\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u53ef\u4ee5\u5faa\u73af\u8f93\u51faT1\n{{range pipeline}} T1 {{else}} T0 {{end}} \u8fd9\u4e2a\u5c31\u662fpipeline\u4e3a\u7a7a\u5219\u6267\u884cT0\n{{with pipeline}} T1 {{end}} with\u548cif\u7c7b\u4f3c\uff0c\u5982\u679cpipeline\u5b58\u5728\uff0c\u5219\u6267\u884cT1\n{{with pipeline}} T1 {{else}} T0 {{end}} \u540c\u6837\u7684else\u5206\u652f\u5904\u7406\n<\/code><\/pre> \n
package main\n\nimport (\n "fmt"\n "os"\n "text\/template"\n)\n\n\/\/ Define a template.\nconst letter = `\nDear {{.Name}},\n{{if .Attended}}\nIt was a pleasure to see you at the wedding.{{else}}\nIt is a shame you couldn't make it to the wedding.{{end}}\n{{with .Gift}}Thank you for the lovely {{.}}.\n{{end}}\nBest wishes,\nJosie\n`\n\nfunc main() {\n\n \/\/ Prepare some data to insert into the template.\n type Recipient struct {\n Name, Gift string\n Attended bool\n }\n var recipients = []Recipient{\n {"Aunt Mildred", "bone china tea set", true},\n {"Uncle John", "moleskin pants", false},\n {"Cousin Rodney", "", false},\n }\n\n \/\/ Create a new template and parse the letter into it.\n t := template.Must(template.New("letter").Parse(letter))\n\n \/\/ Execute the template for each recipient.\n for _, r := range recipients {\n err := t.Execute(os.Stdout, r)\n if err != nil {\n fmt.Println("executing template:", err)\n }\n }\n}<\/code><\/pre> \n
Dear Aunt Mildred,\n\nIt was a pleasure to see you at the wedding.\nThank you for the lovely bone china tea set.\n\nBest wishes,\nJosie\n\nDear Uncle John,\n\nIt is a shame you couldn't make it to the wedding.\nThank you for the lovely moleskin pants.\n\nBest wishes,\nJosie\n\nDear Cousin Rodney,\n\nIt is a shame you couldn't make i","orderid":"0","title":"go\u8bed\u8a00\u6a21\u7248\u7f16\u7a0b(\u4e00)","smalltitle":"","mid":"0","fname":"GO","special_id":"0","bak_id":"0","info":"0","hits":"262","pages":"2","comments":"0","posttime":"2019-04-02 18:08:01","list":"1554199681","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"http:\/\/pdjedu.com\/uploadarticle\/images\/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20190103092604.jpg","ispic":"1","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u8bed\u8a00<\/A> \u6a21\u7248<\/A> \u7f16\u7a0b<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"47.106.78.186","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"go\u8bed\u8a00\u6a21\u7248\u7f16\u7a0b","lastview":"1709246894","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}