{"id":41812,"date":"2024-12-01T11:01:16","date_gmt":"2024-12-01T03:01:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/41812\/"},"modified":"2024-12-01T11:01:16","modified_gmt":"2024-12-01T03:01:16","slug":"%e4%bd%bf%e7%94%a8-go-html-%e6%a8%a1%e6%9d%bf%e7%9a%84%e5%8a%a8%e6%80%81%e5%ad%97%e6%ae%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/41812\/","title":{"rendered":"\u4f7f\u7528 Go html \u6a21\u677f\u7684\u52a8\u6001\u5b57\u6bb5"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u4f7f\u7528 Go html \u6a21\u677f\u7684\u52a8\u6001\u5b57\u6bb5<\/span><\/p>\n<h1>\u4f7f\u7528 Go html \u6a21\u677f\u7684\u52a8\u6001\u5b57\u6bb5<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-21 16:30:36<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4f7f\u7528 Go html \u6a21\u677f\u7684\u52a8\u6001\u5b57\u6bb5\u300b<\/span>\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u65e0\u8bba\u4f60\u662f\u5c0f\u767d\u8fd8\u662f\u8001\u624b\uff0c\u90fd\u9002\u5408\u770b\u4e00\u770b\u54e6~\u6709\u597d\u7684\u5efa\u8bae\u4e5f\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u82e5\u662f\u770b\u5b8c\u6709\u6240\u6536\u83b7\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u70b9\u8d5e\u652f\u6301\u5440\uff01\u4e00\u8d77\u52a0\u6cb9\u5b66\u4e60~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u53ef\u4ee5\u5728 go \u4e2d\u5236\u4f5c\u4e00\u4e2a\u5e26\u6709\u52a8\u6001\u5c5e\u6027\u7684 html \u6a21\u677f\u5417\uff1f<\/p>\n<p>\u50cf\u8fd9\u6837\u5f53\u524d\u4f1a\u5bfc\u81f4\u9519\u8bef<\/p>\n<p> \u6a21\u677f\u65e0\u6548\uff1a\u6a21\u677f\uff1asticker.cellrepresentation\uff1a1:23\uff1a\u5728 &lt;.sticker_set.url&gt; \u5904\u6267\u884c\u201csticker.cellrepresentation\u201d\uff1a\u65e0\u6cd5\u8bc4\u4f30\u7c7b\u578b\u63a5\u53e3 {} \u4e2d\u7684\u5b57\u6bb5 url <\/p>\n<pre>func sample() error {\n    tpl, err := template.New(\"sample\").Parse(`&lt;a href=\"${sticker_set.url}\"&gt;{{.sticker_set.url}}&lt;\/a&gt;`)\n    if err != nil {\n        return err\n    }\n\n    data := map[string]interface{}{\n        \"sticker_set\": map[string]interface{}{\n            \"url\": \"x\",\n        },\n    }\n\n    if err := tpl.Execute(NoopWriter{}, data); err != nil {\n        return fmt.Errorf(\"Invalid template: %w\", err)\n    }\n\n    return nil\n}\n\nfunc main() {\n    err := sample()\n    if err != nil {\n        panic(err)\n    }\n}\n<\/pre>\n<p>\u6211\u6ca1\u6709\u4f7f\u7528\u7ed3\u6784\uff0c\u56e0\u4e3a\u6211\u5c1d\u8bd5\u6267\u884c\u7684\u6a21\u677f\u9002\u7528\u4e8e\u7f16\u8bd1\u65f6\u672a\u5b9a\u4e49\u7684\u7ed3\u6784\u7684 json<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u4f60\u7684\u4f8b\u5b50\u5bf9\u6211\u548c\u6f14\u793a\u90fd\u5f88\u6709\u6548\u3002\u6211\u7a0d\u5fae\u8c03\u6574\u4e86\u6a21\u677f\u5e76\u4f7f\u7528 <code>os.stdout<\/code> \u4f5c\u4e3a\u7f16\u5199\u5668\u3002<\/p>\n<pre>func sample() error {\n    tpl, err := template.New(\"sample\").Parse(`&lt;a href=\"{{.sticker_set.url}}\"&gt;{{.sticker_set.url}}&lt;\/a&gt;`)\n    if err != nil {\n        return err\n    }\n\n    data := map[string]interface{}{\n        \"sticker_set\": map[string]interface{}{\n            \"url\": \"xyz\",\n        },\n    }\n\n    if err := tpl.Execute(os.Stdout, data); err != nil {\n        return fmt.Errorf(\"Invalid template: %w\", err)\n    }\n\n    return nil\n}\n<\/pre>\n<p>\u751a\u81f3\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u7684\u503c\u7c7b\u578b\uff1a<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGolang\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u4f7f\u7528 Go html \u6a21\u677f\u7684\u52a8\u6001\u5b57\u6bb5 \u4f7f\u7528 Go html \u6a21\u677f\u7684\u52a8\u6001\u5b57\u6bb5 \u6765\u6e90\uff1astackoverflow 2024-04-21 16:30:36 0\u6d4f\u89c8 \u6536\u85cf \u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u300a\u4f7f\u7528 Go html \u6a21\u677f\u7684\u52a8\u6001\u5b57\u6bb5\u300b\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9\u5305\u62ec\u7b49\u7b49\uff0c\u65e0\u8bba\u4f60\u662f\u5c0f\u767d\u8fd8\u662f\u8001\u624b\uff0c\u90fd\u9002\u5408\u770b\u4e00\u770b\u54e6~\u6709\u597d\u7684\u5efa\u8bae\u4e5f\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u82e5\u662f\u770b\u5b8c\u6709\u6240\u6536\u83b7\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u70b9\u8d5e\u652f\u6301\u5440\uff01\u4e00\u8d77\u52a0\u6cb9\u5b66\u4e60~ \u95ee\u9898\u5185\u5bb9 \u6211\u53ef\u4ee5\u5728 go \u4e2d\u5236\u4f5c\u4e00\u4e2a\u5e26\u6709\u52a8\u6001\u5c5e\u6027\u7684 html \u6a21\u677f\u5417\uff1f \u50cf\u8fd9\u6837\u5f53\u524d\u4f1a\u5bfc\u81f4\u9519\u8bef \u6a21\u677f\u65e0\u6548\uff1a\u6a21\u677f\uff1asticker.cellrepresentation\uff1a1:23\uff1a\u5728 &lt;.sticker_set.url&gt; \u5904\u6267\u884c\u201csticker.cellrepresentation\u201d\uff1a\u65e0\u6cd5\u8bc4\u4f30\u7c7b\u578b\u63a5\u53e3 {} \u4e2d\u7684\u5b57\u6bb5 url func sample() error { tpl, err := template.New(&#8220;sample&#8221;).Parse(`&lt;a href=&#8221;${sticker_set.url}&#8221;&gt;{{.sticker_set.url}}&lt;\/a&gt;`) if err != nil { return err } data := map[string]interface{}{ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-41812","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=41812"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41812\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=41812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=41812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=41812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}