{"id":484,"date":"2018-12-22T15:00:16","date_gmt":"2018-12-22T06:00:16","guid":{"rendered":"https:\/\/weseek.co.jp\/tech\/?p=484"},"modified":"2018-12-22T15:00:16","modified_gmt":"2018-12-22T06:00:16","slug":"go%e8%a8%80%e8%aa%9e%e3%81%a7%e3%81%ae%e9%96%8b%e7%99%ba%e5%a7%8b%e3%82%81%e3%81%a6%e3%81%bf%e3%82%8b%e3%80%9cbeego-%e3%81%a7%e6%8e%b2%e7%a4%ba%e6%9d%bf%e3%81%a3%e3%81%bd%e3%81%84%e3%82%82%e3%81%ae","status":"publish","type":"post","link":"https:\/\/growi.co.jp\/blog\/growi\/go%e8%a8%80%e8%aa%9e%e3%81%a7%e3%81%ae%e9%96%8b%e7%99%ba%e5%a7%8b%e3%82%81%e3%81%a6%e3%81%bf%e3%82%8b%e3%80%9cbeego-%e3%81%a7%e6%8e%b2%e7%a4%ba%e6%9d%bf%e3%81%a3%e3%81%bd%e3%81%84%e3%82%82%e3%81%ae\/","title":{"rendered":"go\u8a00\u8a9e+beego\u3067\u63b2\u793a\u677f\u3092\u4f5c\u308b"},"content":{"rendered":"<p>\u524d\u56de\u306e\u7d9a\u304d\u3067go\u8a00\u8a9e\u7528\u306eweb\u30d5\u30eb\u30b9\u30bf\u30c3\u30af\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3042\u308b beego \u3067\u5b9f\u969b\u306b\u30b5\u30fc\u30d3\u30b9\u3092\u4f5c\u3063\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u524d\u56de\u306f\u30b3\u30fc\u30c9\u81ea\u52d5\u751f\u6210\u6a5f\u80fd\u3092\u8a66\u3057\u3066\u307f\u3066 CURD \u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002\u4f55\u3092\u4f5c\u308b\u304b\u3067\u3059\u304c\u3068\u308a\u3042\u3048\u305a\u63b2\u793a\u677f\u307f\u305f\u3044\u306a\u3082\u306e\u3092\u4f5c\u308d\u3046\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3068\u3057\u3066\u306f\u30e6\u30fc\u30b6\u304c\u30d5\u30a9\u30fc\u30e0\u304b\u3089\u6587\u5b57\u5217\u3092\u9001\u4fe1\u3059\u308b\u3068DB\u306b\u6587\u5b57\u5217\u304c\u4fdd\u5b58\u3055\u308c\u3001\u305d\u306e\u6587\u5b57\u5217\u3092\u8868\u793a\u304c\u3067\u304d\u308b\u3002\u3068\u3044\u3046\u5177\u5408\u3067\u9032\u3081\u3088\u3046\u3068\u601d\u3044\u3064\u3064\u3001beego \u306e\u6a5f\u80fd\u3092\u89e6\u3063\u3066\u898b\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n\n<h2>\u66f8\u304d\u8fbc\u307f\u30da\u30fc\u30b8\u306e\u4f5c\u6210<\/h2>\n<p>scaffold \u3092\u4f7f\u3063\u3066\u306e view \u306f\u81ea\u52d5\u4f5c\u6210\u3057\u3066\u304f\u308c\u306a\u304b\u3063\u305f\u306e\u3067\u81ea\u524d\u3067 HTML \u3092\u66f8\u3044\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u63b2\u793a\u677f\u3068\u3044\u3046\u3053\u3068\u306a\u306e\u3067\u307e\u305a\u306f\u66f8\u304d\u8fbc\u307f\u306e\u30da\u30fc\u30b8\u3092\u4f5c\u3063\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u304b\u3089\u63b2\u793a\u677f\u3078\u9077\u79fb\u3057\u3066\u3001\u30d5\u30a9\u30fc\u30e0\u304c\u898b\u3048\u308b\u3068\u3044\u3046\u3053\u308d\u307e\u3067\u3092\u884c\u304a\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h3>bootstrap \u5c0e\u5165<\/h3>\n<p>web\u30b5\u30a4\u30c8\u4f5c\u308a\u306b\u500b\u4eba\u7684\u306b\u6b20\u304b\u305b\u306a\u3044\u306e\u306f CSS\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3042\u308b <a href=\"https:\/\/getbootstrap.com\/\">bootstrap<\/a><br \/>\n\u3053\u3044\u3064\u3092\u5c0e\u5165\u3057\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305a\u306f\u5171\u901a\u3067\u8aad\u307f\u8fbc\u307f\u306e\u3067\u304d\u308b <code>layout.html<\/code> \u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/beego.me\/docs\/mvc\/view\/view.md#layout-design\">\u516c\u5f0f\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u306f\u3053\u306e\u3078\u3093<br \/>\n\u30b5\u30f3\u30d7\u30eb\u306b\u306f\u3059\u3067\u306b bootstrap3 \u304c\u5165\u3063\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u305b\u3063\u304b\u304f\u306a\u306e\u3067 bootstrap4 \u3092\u5165\u308c\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n<code>views\/layout\/layout.html<\/code> \u4f5c\u6210<\/p>\n<pre><code>&lt;span class=&quot;hljs-meta&quot;&gt;&lt;!DOCTYPE html&gt;&lt;\/span&gt;\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;html&lt;\/span&gt;&gt;&lt;\/span&gt;\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;head&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;title&lt;\/span&gt;&gt;&lt;\/span&gt;haruch&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;title&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;meta&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;viewport&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;content&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;width=device-width, initial-scale=1.0&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;meta&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;http-equiv&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;Content-Type&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;content&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;text\/html; charset=utf-8&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;link&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;rel&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;stylesheet&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;href&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.1.3\/css\/bootstrap.min.css&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;integrity&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;sha384-MCw98\/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;crossorigin&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;anonymous&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n    {{.HtmlHead}}\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;head&lt;\/span&gt;&gt;&lt;\/span&gt;\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;body&lt;\/span&gt;&gt;&lt;\/span&gt;\n\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;container&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n        {{.LayoutContent}}\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n        {{.SideBar}}\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;script&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;src&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;https:\/\/code.jquery.com\/jquery-3.3.1.slim.min.js&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;integrity&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;sha384-q8i\/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;crossorigin&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;anonymous&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;script&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;script&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;src&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/popper.js\/1.14.3\/umd\/popper.min.js&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;integrity&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK\/l8WvCWPIPm49&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;crossorigin&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;anonymous&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;script&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;script&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;src&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.1.3\/js\/bootstrap.min.js&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;integrity&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW\/JmZQ5stwEULTy&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;crossorigin&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;anonymous&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;script&lt;\/span&gt;&gt;&lt;\/span&gt;\n    {{.Scripts}}\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;body&lt;\/span&gt;&gt;&lt;\/span&gt;\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;html&lt;\/span&gt;&gt;&lt;\/span&gt;<\/code><\/pre>\n<p>\u305d\u3057\u3066 <code>views\/index.tpl<\/code> \u306b\u9069\u5f53\u306b bootstrap \u306e\u30af\u30e9\u30b9\u3092\u66f8\u304d\u8fbc\u307f\u52d5\u4f5c\u30c6\u30b9\u30c8\u3067\u3059\u3002<\/p>\n<pre><code>&lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;alert alert-primary&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;role&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;alert&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n  bootstrap \u5165\u3063\u305f\u3088\uff01\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;<\/code><\/pre>\n<p>\u7279\u306b\u610f\u5473\u306a\u304f\u30a2\u30e9\u30fc\u30c8\u3067\u3059\u304c\u3061\u3083\u3093\u3068\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/blog.st.growi.co.jp\/blog\/wp-content\/uploads\/2021\/06\/f7b12f3aaa47523c9500c0a1d9a95937.png\" alt=\"\" \/><\/p>\n<h3>\u66f8\u304d\u8fbc\u307f\u30da\u30fc\u30b8\u3078\u306e\u9077\u79fb<\/h3>\n<p>\u9077\u79fb\u3055\u305b\u308b\u306b\u306f <a href=\"https:\/\/beego.me\/docs\/quickstart\/router.md\">router<\/a> \u306e\u6a5f\u80fd\u3092\u4f7f\u3044 URL \u3068 controller \u3068 view \u3092\u30de\u30c3\u30d4\u30f3\u30b0\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u4e00\u65e6HTML \u3092\u8868\u793a\u3055\u305b\u308b\u3060\u3051\u306b\u3057\u3088\u3046\u3068\u601d\u3046\u306e\u3067 controller \u306e scaffold \u3067\u81ea\u52d5\u751f\u6210\u3055\u308c\u305f\u30b3\u30fc\u30c9\u306f\u7121\u8996\u3057\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>\n<p>router.go \u306e\u7de8\u96c6<br \/>\n\u65b0\u3057\u304f<\/p>\n<p>beego.Include(&amp;controllers.PostController{})<\/p>\n<\/li>\n<\/ul>\n<p>\u3053\u3061\u3089\u3092 <code>init()<\/code> \u30e1\u30bd\u30c3\u30c9\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n\u3053\u308c\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067 scaffold \u3067\u4f5c\u6210\u3055\u308c\u305f controller \u306b\u6307\u5b9a\u3057\u305f URL \u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>controller\/post.go \u306e\u7de8\u96c6<br \/>\nindex \u30e1\u30bd\u30c3\u30c9\u3092\u751f\u3084\u3057\u3001 scaffold \u3067\u4f5c\u6210\u3055\u308c\u305f\u7a7a\u306e post\/index.tpl \u3092\u7d10\u4ed8\u3051\u307e\u3059\u3002<\/li>\n<\/ul>\n<pre><code>&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ Index ...&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Title Index&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Description show BBS&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Success 200&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Failure 403 body is empty&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @router \/post\/index [get]&lt;\/span&gt;\n&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;func&lt;\/span&gt; &lt;span class=&quot;hljs-params&quot;&gt;(c *PostController)&lt;\/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;Index&lt;\/span&gt;&lt;span class=&quot;hljs-params&quot;&gt;()&lt;\/span&gt;&lt;\/span&gt; {\n    c.TplName = &lt;span class=&quot;hljs-string&quot;&gt;&quot;post\/index.tpl&quot;&lt;\/span&gt;\n}<\/code><\/pre>\n<p>\u305d\u3057\u3066\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306b\u66f8\u304b\u308c\u3066\u3044\u308b <code>\/post\/index<\/code> \u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u4f55\u3082\u306a\u3044\u30da\u30fc\u30b8\u3078\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<h3>\u30d5\u30a9\u30fc\u30e0\u306e\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0<\/h3>\n<p>bootstrap \u3092\u5c0e\u5165\u3057\u305f\u306e\u3067\u30b5\u30af\u30c3\u3068\u30d5\u30a9\u30fc\u30e0\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u3053\u3053\u306f\u3082\u3046\u9069\u5f53\u306b bootstrap \u306e\u516c\u5f0f\u304b\u3089 example \u3092\u6301\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<pre><code>&lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;form&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;form-group&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;label&lt;\/span&gt;&gt;&lt;\/span&gt;\u30bf\u30a4\u30c8\u30eb&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;label&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;input&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;form-control&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;placeholder&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;\u30bf\u30a4\u30c8\u30eb&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;form-group&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;label&lt;\/span&gt;&gt;&lt;\/span&gt;\u5185\u5bb9&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;label&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;textarea&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;form-control&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;rows&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;3&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;placeholder&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;\u66f8\u304d\u8fbc\u3080\u5185\u5bb9&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;textarea&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;button&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;type&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;submit&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;btn btn-primary&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\u9001\u4fe1&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;button&lt;\/span&gt;&gt;&lt;\/span&gt;\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;form&lt;\/span&gt;&gt;&lt;\/span&gt;<\/code><\/pre>\n<p>bootstrap\u3092\u9069\u7528\u3059\u308b\u305f\u3081\u306b <code>post.go<\/code> \u306e <code>index()<\/code> \u30e1\u30bd\u30c3\u30c9\u306b <code>c.Layout<\/code> \u3082\u5fd8\u308c\u305a\u306b\u8ffd\u52a0\u3057\u3066\u3042\u3052\u307e\u3059\u3002<\/p>\n<pre><code>&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ Index ...&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Title Index&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Description show BBS&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Success 200&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Failure 403 body is empty&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @router \/post\/index [get]&lt;\/span&gt;\n&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;func&lt;\/span&gt; &lt;span class=&quot;hljs-params&quot;&gt;(c *PostController)&lt;\/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;Index&lt;\/span&gt;&lt;span class=&quot;hljs-params&quot;&gt;()&lt;\/span&gt;&lt;\/span&gt; {\n    c.Layout = &lt;span class=&quot;hljs-string&quot;&gt;&quot;layout\/layout.html&quot;&lt;\/span&gt;\n    c.TplName = &lt;span class=&quot;hljs-string&quot;&gt;&quot;post\/index.tpl&quot;&lt;\/span&gt;\n}<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blog.st.growi.co.jp\/blog\/wp-content\/uploads\/2021\/06\/20201104181530.png\" alt=\"\" \/><\/p>\n<p>\u30b5\u30af\u30c3\u3068\u4f5c\u308c\u307e\u3059\u3002<\/p>\n<h2>DB\u3078\u306e\u63a5\u7d9a\u8a2d\u5b9a\u8ffd\u52a0<\/h2>\n<p>\u6b63\u76f4\u306a\u3093\u3067\u3053\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u3063\u3066\u3084\u3063\u3066\u3066\u601d\u3046\u3093\u3067\u3059\u304c\u3001 scaffold \u3067\u30b3\u30fc\u30c9\u306e\u81ea\u52d5\u751f\u6210\u3057\u305f\u3060\u3051\u3067\u3070 DB \u306e\u63a5\u7d9a\u8a2d\u5b9a\u306a\u3069\u306f\u4e00\u5207\u3084\u3063\u3066\u304f\u308c\u306a\u3044\u306e\u3067 DB \u306b\u5bfe\u3057\u3066\u306e\u64cd\u4f5c\u3092\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u3001\u30a2\u30d7\u30ea\u304c\u843d\u3061\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre><code>must have one register DataBase alias named `default`<\/code><\/pre>\n<p>\u3063\u3066\u3053\u3068\u306a\u306e\u3067<a href=\"https:\/\/beego.me\/docs\/mvc\/model\/orm.md#set-up-database\">\u30de\u30cb\u30e5\u30a2\u30eb<\/a>\u306b\u5f93\u3063\u3066\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n<code>main.go<\/code> \u306b\u4e0b\u8a18\u8ffd\u52a0\u3067\u3059\u3002<\/p>\n<pre><code>&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;func&lt;\/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;init&lt;\/span&gt;&lt;span class=&quot;hljs-params&quot;&gt;()&lt;\/span&gt;&lt;\/span&gt; {\n    orm.RegisterDriver(&lt;span class=&quot;hljs-string&quot;&gt;&quot;postgres&quot;&lt;\/span&gt;, orm.DRPostgres)\n    orm.RegisterDataBase(\n        &lt;span class=&quot;hljs-string&quot;&gt;&quot;default&quot;&lt;\/span&gt;,\n        &lt;span class=&quot;hljs-string&quot;&gt;&quot;postgres&quot;&lt;\/span&gt;,\n        &lt;span class=&quot;hljs-string&quot;&gt;&quot;user=user password=pass host=127.0.0.1 port=5432 dbname=postgres sslmode=disable&quot;&lt;\/span&gt;)\n\n    orm.RunSyncdb(&lt;span class=&quot;hljs-string&quot;&gt;&quot;default&quot;&lt;\/span&gt;, &lt;span class=&quot;hljs-literal&quot;&gt;false&lt;\/span&gt;, &lt;span class=&quot;hljs-literal&quot;&gt;true&lt;\/span&gt;)\n}<\/code><\/pre>\n<h2>\u30d5\u30a9\u30fc\u30e0\u5165\u529b\u5024\u3092\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3078\u306e\u9001\u4fe1<\/h2>\n<p>DB \u3078\u306e\u8a2d\u5b9a\u3092\u66f8\u3044\u305f\u3068\u3053\u308d\u3067\u5b9f\u969b\u306b\u4f5c\u3063\u305f\u30d5\u30a9\u30fc\u30e0\u304b\u3089 ORM \u3092\u5229\u7528\u3057\u3066 DB \u306b\u5024\u3092\u4fdd\u5b58\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305a View \u306e\u307b\u3046\u306e\u7de8\u96c6\u3092\u3057\u307e\u3059\u3002<br \/>\nform \u30bf\u30b0\u306b actuon \u3068 method \u306e\u8ffd\u52a0\u3068\u3001inpot \u3068 textarea \u306b name \u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre><code>&lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;form&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;action&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;\/post&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;method&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;post&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;form-group&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;label&lt;\/span&gt;&gt;&lt;\/span&gt;\u30bf\u30a4\u30c8\u30eb&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;label&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;input&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;title&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;form-control&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;placeholder&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;\u30bf\u30a4\u30c8\u30eb&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;form-group&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;label&lt;\/span&gt;&gt;&lt;\/span&gt;\u5185\u5bb9&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;label&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;textarea&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;body&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;form-control&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;rows&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;3&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;placeholder&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;\u66f8\u304d\u8fbc\u3080\u5185\u5bb9&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;textarea&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;button&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;type&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;submit&quot;&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;btn btn-primary&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\u9001\u4fe1&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;button&lt;\/span&gt;&gt;&lt;\/span&gt;\n&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;form&lt;\/span&gt;&gt;&lt;\/span&gt;<\/code><\/pre>\n<p>Controller\u306e\u307b\u3046\u306f <code>Post()<\/code> \u30e1\u30bd\u30c3\u30c9\u306e @router \u304c \u305f\u3060\u306e <code>\/<\/code> \u306b\u306a\u3063\u3066\u3044\u305f\u306e\u3067\u4e0b\u8a18\u306e\u3088\u3046\u306b\u76f4\u3059\u306e\u3068\u3001\u305d\u3082\u305d\u3082 scaffold \u3067\u751f\u6210\u3055\u308c\u305f\u30b3\u30fc\u30c9\u306f JSON \u3067\u30c7\u30fc\u30bf\u304c\u9001\u3089\u308c\u3066\u304f\u308b\u3053\u3068\u304c\u524d\u63d0\u3060\u3063\u305f\u307f\u305f\u3044\u306a\u306e\u3067\u3001POST \u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u305d\u306e\u307e\u307e\u9001\u3089\u308c\u3066\u304d\u305f\u306e\u3092\u53d7\u3051\u53d6\u308b\u3088\u3046\u306b\u4fee\u6b63\u3057\u307e\u3059\u3002\u3055\u3089\u306b\u3001JSON\u3092\u8fd4\u3055\u308c\u3066\u3082\u56f0\u308b\u306e\u3067\u3001\u305d\u306e\u307e\u307e\u63b2\u793a\u677f\u3078\u3068\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u3088\u3046\u306b\u4e00\u65e6\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre><code>&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ Post ...&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Title Post&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Description create Post&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Param    body        body    models.Post true        &quot;body for Post content&quot;&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Success 201 {int} models.Post&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Failure 403 body is empty&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @router \/post [post]&lt;\/span&gt;\n&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;func&lt;\/span&gt; &lt;span class=&quot;hljs-params&quot;&gt;(c *PostController)&lt;\/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;Post&lt;\/span&gt;&lt;span class=&quot;hljs-params&quot;&gt;()&lt;\/span&gt;&lt;\/span&gt; {\n    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;\/span&gt; post models.Post\n    &lt;span class=&quot;hljs-comment&quot;&gt;\/\/ \u30c7\u30fc\u30bf\u53d6\u5f97\u3057\u3066 post \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u4f5c\u6210&lt;\/span&gt;\n    post = models.Post{\n        Title: c.GetString(&lt;span class=&quot;hljs-string&quot;&gt;&quot;title&quot;&lt;\/span&gt;),\n        Body:  c.GetString(&lt;span class=&quot;hljs-string&quot;&gt;&quot;body&quot;&lt;\/span&gt;),\n    }\n    &lt;span class=&quot;hljs-comment&quot;&gt;\/\/ \u30c7\u30fc\u30bf\u4fdd\u5b58&lt;\/span&gt;\n    &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;\/span&gt; _, err := models.AddPost(&amp;post); err == &lt;span class=&quot;hljs-literal&quot;&gt;nil&lt;\/span&gt; {\n        c.Ctx.Output.SetStatus(&lt;span class=&quot;hljs-number&quot;&gt;201&lt;\/span&gt;)\n        &lt;span class=&quot;hljs-comment&quot;&gt;\/\/ \u4e00\u5fdc json \u683c\u7d0d\u3057\u3066\u304a\u304f&lt;\/span&gt;\n        c.Data[&lt;span class=&quot;hljs-string&quot;&gt;&quot;json&quot;&lt;\/span&gt;] = post\n        &lt;span class=&quot;hljs-comment&quot;&gt;\/\/ \u6210\u529f\u3057\u305f\u3089\u63b2\u793a\u677f\u30c8\u30c3\u30d7\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8&lt;\/span&gt;\n        c.Redirect(&lt;span class=&quot;hljs-string&quot;&gt;&quot;\/post\/index&quot;&lt;\/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;302&lt;\/span&gt;)\n    } &lt;span class=&quot;hljs-keyword&quot;&gt;else&lt;\/span&gt; {\n        c.Data[&lt;span class=&quot;hljs-string&quot;&gt;&quot;json&quot;&lt;\/span&gt;] = err.Error()\n        &lt;span class=&quot;hljs-comment&quot;&gt;\/\/ \u5931\u6557\u6642\u306f\u4e00\u65e6\u30a8\u30e9\u30fc\u3092\u305d\u306e\u307e\u307e\u63cf\u753b\u3059\u308b\u3053\u3068\u306b\u3059\u308b&lt;\/span&gt;\n        c.ServeJSON()\n    }\n}<\/code><\/pre>\n<p>\u3053\u308c\u3067\u66f8\u304d\u8fbc\u307f\u753b\u9762\u304b\u3089\u30bf\u30a4\u30c8\u30eb\u3068\u5185\u5bb9\u3092\u5165\u529b\u3057\u3066\u9001\u4fe1\u3059\u308b\u3068 DB \u306b\u5024\u304c\u4fdd\u5b58\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>DB\u304b\u3089\u66f8\u304d\u8fbc\u307f\u30c7\u30fc\u30bf\u3092View\u306b\u8868\u793a<\/h2>\n<p>\u4eca\u306e\u307e\u307e\u3067\u306f\u4e00\u65b9\u7684\u306bDB\u306b\u66f8\u304d\u8fbc\u3080\u3060\u3051\u3067\u66f8\u304d\u8fbc\u307f\u304c\u95b2\u89a7\u304c\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\n\u5f53\u7136\u3067\u3059\u304c\u63b2\u793a\u677f\u30b5\u30fc\u30d3\u30b9\u306a\u306e\u3067\u66f8\u304d\u8fbc\u307f\u304c web \u4e0a\u3067\u95b2\u89a7\u3067\u304d\u306a\u304f\u3066\u306f\u610f\u5473\u304c\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u81ea\u52d5\u751f\u6210\u3055\u308c\u305f <code>GetAll()<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u53c2\u8003\u306b\u66f8\u304b\u308c\u305f\u5185\u5bb9\u306e\u53d6\u5f97\u3068 view \u3078\u306e\u8868\u793a\u3092\u5b9f\u88c5\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u4e00\u65e6\u53d6\u5f97\u6642\u306e\u691c\u7d22\u30d1\u30e9\u30e1\u30fc\u30bf\u306a\u3069\u306f\u7121\u8996\u3057\u3066 <code>GetAll()<\/code> \u304b\u3089\u306e\u5185\u5bb9\u3092\u307b\u307c\u30b3\u30d4\u30da\u3057\u3001\u6700\u65b010\u4ef6\u3092\u53d6\u5f97\u3057\u3066 View\u306b\u6e21\u305d\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre><code>&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ Index ...&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Title Index&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Description show BBS&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Success 200&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @Failure 403 body is empty&lt;\/span&gt;\n&lt;span class=&quot;hljs-comment&quot;&gt;\/\/ @router \/post\/index [get]&lt;\/span&gt;\n&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;func&lt;\/span&gt; &lt;span class=&quot;hljs-params&quot;&gt;(c *PostController)&lt;\/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;Index&lt;\/span&gt;&lt;span class=&quot;hljs-params&quot;&gt;()&lt;\/span&gt;&lt;\/span&gt; {\n    c.Layout = &lt;span class=&quot;hljs-string&quot;&gt;&quot;layout\/layout.html&quot;&lt;\/span&gt;\n    c.TplName = &lt;span class=&quot;hljs-string&quot;&gt;&quot;post\/index.tpl&quot;&lt;\/span&gt;\n\n    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;\/span&gt; fields []&lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;\/span&gt;\n    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;\/span&gt; sortby []&lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;\/span&gt;\n    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;\/span&gt; order []&lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;\/span&gt;\n    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;\/span&gt; query = &lt;span class=&quot;hljs-built_in&quot;&gt;make&lt;\/span&gt;(&lt;span class=&quot;hljs-keyword&quot;&gt;map&lt;\/span&gt;[&lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;\/span&gt;]&lt;span class=&quot;hljs-keyword&quot;&gt;string&lt;\/span&gt;)\n    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;\/span&gt; limit &lt;span class=&quot;hljs-keyword&quot;&gt;int64&lt;\/span&gt; = &lt;span class=&quot;hljs-number&quot;&gt;10&lt;\/span&gt;\n    &lt;span class=&quot;hljs-keyword&quot;&gt;var&lt;\/span&gt; offset &lt;span class=&quot;hljs-keyword&quot;&gt;int64&lt;\/span&gt;\n\n    l, err := models.GetAllPost(query, fields, sortby, order, offset, limit)\n\n    &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;\/span&gt; err != &lt;span class=&quot;hljs-literal&quot;&gt;nil&lt;\/span&gt; {\n        c.Data[&lt;span class=&quot;hljs-string&quot;&gt;&quot;json&quot;&lt;\/span&gt;] = err.Error()\n        c.ServeJSON()\n    } &lt;span class=&quot;hljs-keyword&quot;&gt;else&lt;\/span&gt; {\n        c.Data[&lt;span class=&quot;hljs-string&quot;&gt;&quot;posts&quot;&lt;\/span&gt;] = l\n    }\n}<\/code><\/pre>\n<p>\u3053\u308c\u3067 View \u306b\u306f <code>posts<\/code> \u3068\u3044\u3046\u540d\u524d\u3067 DB \u304b\u3089\u53d6\u5f97\u3057\u305f\u5024\u304c\u6e21\u3063\u305f\u306e\u3067\u306f\u3068\u306f HTML \u3092\u7de8\u96c6\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<pre><code>&lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;hr&lt;\/span&gt;&gt;&lt;\/span&gt;\n\n{{range $val := .posts}}\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;card bg-light mb-3&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;card-header&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;{{$val.Id}}. \u306a\u306a\u3057\u3055\u3093&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;card-body&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;\n      &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;h5&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;card-title&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;{{$val.Title}} &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;h5&lt;\/span&gt;&gt;&lt;\/span&gt;\n      &lt;span class=&quot;hljs-tag&quot;&gt;&lt;&lt;span class=&quot;hljs-name&quot;&gt;p&lt;\/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;class&lt;\/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&quot;card-text&quot;&lt;\/span&gt;&gt;&lt;\/span&gt;{{$val.Body}}&lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;p&lt;\/span&gt;&gt;&lt;\/span&gt;\n    &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n  &lt;span class=&quot;hljs-tag&quot;&gt;&lt;\/&lt;span class=&quot;hljs-name&quot;&gt;div&lt;\/span&gt;&gt;&lt;\/span&gt;\n{{end}}<\/code><\/pre>\n<p>\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f <code>form<\/code> \u30bf\u30b0\u306e\u4e0b\u306b Controller \u304b\u3089\u9001\u3089\u308c\u3066\u304f\u308b <code>posts<\/code> \u3092 <code>range<\/code> \u3092\u4f7f\u3063\u3066\u8868\u793a\u3055\u305b\u3066\u304d\u307e\u3059\u3002<br \/>\n\u540d\u524d\u30d5\u30a3\u30fc\u30eb\u30c9\u306f DB \u306b\u5b9a\u7fa9\u3057\u3066\u3044\u306a\u304b\u3063\u305f\u306e\u3067\u5f37\u5236\u7684\u306b\u540d\u7121\u3057\u3055\u3093\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.st.growi.co.jp\/blog\/wp-content\/uploads\/2021\/06\/20201104181537.gif\" alt=\"\" \/><\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u66f8\u3044\u305f\u5185\u5bb9\u304c\u53cd\u6620\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\uff01<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u4f55\u5ea6\u3082\u8a00\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u307e\u3059\u304cDB\u63a5\u7d9a\u8a2d\u5b9a\u306a\u3069\u3042\u308c\u3053\u308c\u81ea\u52d5\u3067\u3084\u3063\u3066\u304f\u308c\u308b\u3068\u601d\u3044\u304d\u3084\u3001\u3084\u3063\u3066\u304f\u308c\u306a\u304b\u3063\u305f\u308a\u3059\u308b\u3068\u3053\u308d\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u516c\u5f0f\u306b\u8a2d\u5b9a\u65b9\u6cd5\u306f\u3042\u305f\u308a\u307e\u3048\u3067\u3059\u304c\u66f8\u3044\u3066\u3042\u308b\u306e\u3067\u51b7\u9759\u306b\u5bfe\u51e6\u3059\u308c\u3070\u826f\u3044\u3068\u3044\u3046\u5370\u8c61\u3067\u3057\u305f\u3002<\/p>\n<p>\u3068\u306f\u3044\u3048\u81ea\u5206\u304c go \u306b\u306a\u308c\u3066\u306a\u3044\u305b\u3044\u304c\u307b\u3068\u3093\u3069\u3060\u3068\u306f\u601d\u3044\u3064\u3064\u3082 scaffold \u3067\u751f\u6210\u3055\u308c\u305f\u30b3\u30fc\u30c9\u304c\u8aad\u307f\u306b\u304f\u304f\u3001go \u3063\u3066\u96f0\u56f2\u6c17\u3058\u3083\u66f8\u3051\u306a\u3044\u8a00\u8a9e\u306a\u3093\u3060\u306a\u3068\u601d\u3044\u77e5\u3089\u3055\u308c\u3066\u3044\u307e\u3059\u3002C\u8a00\u8a9e\u3092\u3061\u3083\u3093\u3068\u5b66\u3093\u3060\u3053\u3068\u306e\u3042\u308b\u4eba\u306f\u307e\u305f\u9055\u3046\u3068\u306f\u601d\u3046\u306e\u3067\u3059\u304c\u3002<\/p>\n<p>\u5b8c\u5168\u306a\u500b\u4eba\u7684\u306a\u6bd4\u8f03\u306b\u306f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u304c Ruby on Rails \u3092\u4f55\u3082\u77e5\u3089\u305a\u306b\u521d\u3081\u3066\u89e6\u3063\u305f\u3068\u304d\u306f\u3053\u3053\u307e\u3067\u82e6\u52b4\u3057\u306a\u304b\u3063\u305f\u3063\u3066\u5370\u8c61\u3067\u3044\u3063\u3071\u3044\u3067\u3059\uff57<\/p>\n<p>\u3068\u3063\u3064\u304d\u3068\u3057\u3066\u306f\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u4f7f\u3063\u3066\u6210\u679c\u7269\u3092\u4f5c\u308b\u306e\u306f\u3059\u3054\u3044\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3053\u3053\u307e\u3067\u304f\u308b\u3068\u8a00\u8a9e\u81ea\u4f53\u3082\u3061\u3083\u3093\u3068\u52c9\u5f37\u3057\u305f\u3044\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u6b21\u56de\u306f\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b\u304b\u3001\u3082\u3057\u304f\u306f\u96f0\u56f2\u6c17\u3067\u66f8\u3044\u3066\u3044\u305fGo\u8a00\u8a9e\u81ea\u4f53\u3092\u8aad\u307f\u89e3\u3044\u3066\u3044\u304f\u304b\u306e\u3069\u3061\u3089\u304b\u3092\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306e\u7d9a\u304d\u3067go\u8a00\u8a9e\u7528\u306eweb\u30d5\u30eb\u30b9\u30bf\u30c3\u30af\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3042\u308b beego \u3067\u5b9f\u969b\u306b\u30b5\u30fc\u30d3\u30b9\u3092\u4f5c\u3063\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u524d\u56de\u306f\u30b3\u30fc\u30c9\u81ea\u52d5\u751f\u6210\u6a5f\u80fd\u3092\u8a66\u3057\u3066\u307f\u3066 CURD \u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002\u4f55\u3092\u4f5c\u308b\u304b\u3067\u3059\u304c\u3068\u308a\u3042 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":485,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-484","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-growi"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/posts\/484"}],"collection":[{"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=484"}],"version-history":[{"count":0,"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/media\/485"}],"wp:attachment":[{"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/growi.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}