diff --git a/404.html b/404.html index 3aed7fa..cef2001 100644 --- a/404.html +++ b/404.html @@ -21,11 +21,11 @@ } - +
- + diff --git a/assets/js/19.70a7fcd1.js b/assets/js/19.06ac8f8c.js similarity index 99% rename from assets/js/19.70a7fcd1.js rename to assets/js/19.06ac8f8c.js index da40749..18deb4c 100644 --- a/assets/js/19.70a7fcd1.js +++ b/assets/js/19.06ac8f8c.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{256:function(t,n){t.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjQAAAEECAYAAAA/Ga4zAAAACXBIWXMAAAsTAAALEwEAmpwYAAATvElEQVR4nO3df2xV9f3H8dfBhrnGGoxyGzI7wWsaQEGjoriB3NsoIERBScC4gEaUZR31By5kEKX3opFA5owTpoKIWAUEf26ZEwRaNgzLUJdmVsFCW7ZC2sqAjXUtUPh8/yD3fCk/SpH2nvs+9/lIbtJy7z3n3Hs/HJ587qe3nnPOCQAAwLAeQR8AAADA+SJoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeYEFTTwel+d5GXuJx+NBPTUAQohzHtC9POecC2THnqeAdt0pmX58AGzJ9HNKph8fcDa85QQAAMwjaAAAgHkEDQAAMI+gAQAA5hE0AADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMwjaAAAgHkEDQAAMI+gAQAA5uUEteO+ffvK87ygdt8pmX58OD+xWEzl5eVBHwayBOc8BC3s5zx+2zayFmMQ6cR4Q9DCPgZ5ywkAAJhH0AAAAPMIGgAAYF4ogyaZTMrzPP3tb38L+lAAoNsFdc779ttv5XmeJk2alNb9AqcTyqA5fPiwJIV68RMApAR1zkvt7+jRo2ndL3A6gQfN5s2bNWzYMC1YsED33HOPotGoZs2a5f8F3bhxo4YNG6b8/HyNGTNGZWVl7e576623Kj8/Xw888ID+9Kc/nbL9f/7znxozZozGjBmj+vr6Drf33nvv6dprr1VBQYFeeeUVDRs2TM8995wkqbKyUiNHjtTFF1+seDyuzZs3n/bxdLR9AAjbOU+S9u/frylTpqigoEATJ05UQ0NDVz1dQOe5gKR2/eGHHzpJTpIrLCz0v3722Wdda2ury8vLc5LcxIkT/a+rq6vdP/7xD/+2Q4cO9b9uampys2fPdpJcRUWFu/76650k98Ybb3S4vcbGRn8bAwcO9L8uLi52+/fv9297++23+9dVV1e3e0wdbR+ZJ8DhjywUxnPeiduIRCIuEok4Se7+++8P4BnG2YT9nBf4DE3KhAkTtH37dm3atEmS9Oabb2rfvn2aOXOmPvjgA82ZM0fXXXedJGnXrl1atWqVJOlXv/qVtmzZot/85jcaNWqUdu3a5W/zwQcf1BdffKFEIqHJkyd3uL2NGzdKkp5//nlVVVVp3rx5/nb+8Ic/6ODBgyopKdHrr7+up59+WpL0zjvvtHsMHW0fAE4UhnNeSiQSUW1trWpqahSJRPTee++pra2ti58xoGOBfVLwyWKxmCRp+PDhko5Pm0YiETU2Nuqpp5465fZ1dXWSpOuvv16SVFJSopKSEknS+++/L0mqqalpd5+Otpeaur3lllvaHY/0/0Hy4osv6sUXXzzlzzuzfQA4URjOeSk//vGPlZubK0m6+eab9fvf/17V1dUaMGDAGR490PUyZoZmy5YtkqQ9e/ZIkvr06aMPP/xQCxcu1J133qnq6moVFxf7tx84cKCk47MikrRu3TrNnTtXO3bs8G8zefJkSVIikdCuXbs63N6gQYMkSdXV1ZKkqqoq/7rLLrtMkjR9+nR99dVXqqys1KeffqqZM2e2ewwdbR8AThSGc15KZWWl/3VqO9Fo9JyfE+B8ZMwMzYoVKzRgwAD97ne/kySNGjXKXznfp08fff311/5iNuecRo4cKUmaM2eOGhoaNHfuXDU1Nemxxx7zt/nYY49pwIABmj17tmbPnq3x48efcXujR4+WJBUXF2v9+vVavny5v50f/ehHkqTVq1frhhtu0IoVK/TJJ5/o3XffVb9+/fzbdXS8AHCiMJzzUmpqajRp0iTl5uaqpqZG48aNU8+ePbv0+QLOKqjFOzppgVxqIZskN2TIENfQ0OCam5vd4MGD/T8fO3ask+Tmz5/vnHNu+vTp/nWS3MqVK51zzl8g9/nnn7v//ve//kK18vLyDrc3f/58l5eX5yKRiJswYYKT5EpKSpxzzr355pvt7jt9+nTX1tbW7jGd7XiRWQIc/shCYTznNTU1+YubU/uMRCJu69at6XpacQ7Cfs7LmKBZuHCha2lpcfX19afctq6uzh0+fPi029m3b5+rqqpyra2tnd736bZXWVnpXnrpJbdlyxbX1tbmFixY4CS5V155pd3tdu7c6Q4cOHDO20fmCftfbmSWMJ/znHPu6NGjrr6+/pToQeYI+zkvY95ykqQLL7xQP/jBD0758yuuuOKM97nkkkt0ySWXnNN+Tre9/Px8zZw5UwcPHlQkElFTU5Py8vJUVFTU7nZXXnnld9o+AJwsLOc8SerRo8dpHwuQLp5zwSzwSP0a8+3bt+vdd9/V7bffriFDhgRxKL6amhpt2rRJ27ZtU9++fTV27Fj98Ic/DPSY0H1SYxBIB855CFrYz3mBBw0QFMYg0onxhqCFfQxmzI9tAwAAfFcEDQAAMI+gAQAA5hE0AADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMzLqF99gM5JJBJKJpNBH0YoeJ4X9CEgizDeulaYPyQO544ZGgAAYB4zNIaVlpYqkUgEfRhmhf1jwJFZGG9dh5kunA4zNAAAwDyCBgAAmEfQAAAA8wgaAABgHkEDAADMI2gyXEVFRdCHAABAxiNoDPA876w/nl1RUaF4PM6PcQMAshJBk+FisZhisZiSyeRpwyYVMvF4XCNGjCBoAABZyXMBfdITHzLVealoOVnfvn1VV1fnf88H7Z0bxiDSifHWdVIfrMfzeW7CPgYJGiPi8XiH62mImXPHGEQ6Md66DkHz3YR9DPKWkxGlpaVBHwIAABmLoDEitZbmdJidAQBkO345pSGlpaX8GDeA08rGX9iYbY85zG8XdQXW0Bhz8loaZme+O8Yg0qm7xxvjOdy64vUN+xjhLSdjWEsDAMCpCBpjTlxLw+wMAADHETQGMUsDAEB7rKExqqKi4ow/9YTOYQwinVhDg/PBGpqzC80MTepXA2TLJR6PB34M6b4kk8mghxkAIEOFJmgkKZFIyDnHJYQX1goBADoSqqABAADZiaABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNACBjHDt2THV1ddq7d2/QhwJjCBoAQLe7+OKL5XmefykoKNDcuXN17NgxSZJzTkuXLlWvXr3Ur18/9e7dW9FoVG+//XbARw4rCBoAQFqUlZVp//79amho0OzZs1VaWqotW7ZIkt566y099NBDKisr05EjR7R3715NmzZN9957rz777LOAjxwWEDQAgLS46KKL1KtXL+Xn5+vuu++WJDU3N0uSnnjiCc2fP1/jxo1TTk6OLr30Us2cOVNPPfWUdu/eLUk6evSonnnmGRUUFCg/P18zZsxQS0uLWltbddNNN2np0qW6+uqrFY1G9eqrr/r7/etf/6pbb71V+fn5mjJliv71r39JkpYtW6Y5c+Zo6tSp+ulPf5rmZwNdjaABAKTFunXrtGzZMi1atEg/+clPVFhYqBEjRqixsVFNTU267bbb/NsePnxYR44c0ZNPPqmxY8dKkl577TUtWLBAv/zlL7VmzRqtWbNGzz77rI4dO6atW7dqwYIFev755xWPx/Xwww+rtbVVjY2Nuvnmm3XddddpzZo12rdvnx9Te/bs0dNPP63du3fr3nvvDeQ5QdfJCfoAAADZ4dNPP1VdXZ3a2tr05ZdfqmfPnqqtrVVLS4uk4+tsJGnnzp266qqr/PsVFRVpw4YNWrJkiR599FH9/Oc/lySVlpYqmUxq1qxZkqSXX35Z8Xhct9xyi5YuXaq6ujp9/PHHuvzyy/XCCy/I8zzl5+erf//+amhokCRFIhF99NFH6tGD/99bxyuYgVjlDyCMksmkPvroI61bt067d+/WoEGDtHjxYvXp00eS/LUyV1xxhXbs2KEdO3aouLjYv/+2bdt04403+t/369dP9fX1/vcFBQWSpLy8PEnSoUOHtHPnTtXX16tHjx7yPE/9+/eXJP/8ettttxEzIcGrGIBf/OIX8jzvlIVurPIHkC1ycnI0aNAgVVZWKj8/X3l5eSovL/evi0ajikaj2rZtm3+fG264oV3AfPPNNxo1apT//QUXXHDKfnr16qUhQ4aoublZzc3NOnDggDZv3qzCwsJufHQIAkGTZkeOHNHixYuVl5en1atXt7uOVf4Awqy+vl7bt29XVVWV5s2bp5deekl33XWXPM/TvHnztHjxYq1Zs0YtLS2qqqrS448/ro0bN/r3Hz9+vJYvX66amhodPnxYK1eu1OjRozvc5/Dhw7V161Z99tln8jxPL7zwgu655x5mZUKIVzTN1q9fr+9///v69a9/reXLl6utrc2/jlX+AMKspKRE/fv31zXXXKPf/va3Ki4u1s9+9jNJ0rRp0zRr1ixNnDhRubm5uuaaa/SXv/xFZWVl/szLpEmTdOjQIUWjUX3ve99Ta2ur7rvvvjPuz/M8jRw5UjNmzNCIESOUm5urRYsWaeXKlcrJyZHneYRNmLiAdPWuE4mESyQSXbrN7nDfffe5J554wu3du9dJchs2bHDOOdfQ0OAkuc8//9y/7aFDh/zLkSNHnHPOLV682OXl5bmFCxe6TZs2ucsvv9w9+eSTrrm52UlyhYWFbu3atW7q1KlOkmtpafG3XVJS4jZt2uTGjh3rhg8f7pxz7plnnnGS3KhRo9zGjRvT/4R0Une8vgEOf2Sh7h5vYRnPzc3N7ssvv3T//ve/T3t9W1ubq66udrt27XLHjh3r9Habmprc3//+d9fS0tJVh5pWXfH6hmWMnAk/5ZRGBw4c0IoVK7R161ZdeumluuOOO7Rq1SoVFRVpz549kljlDyC75ebm6uqrrz7j9RdccEG7c2Nn9e7dW7179z6fQ0OG41+wNHr//fclHZ82jUaj+uMf/6hVq1appaWFVf4AAJwH/hVLo2XLlmnq1KlasmSJlixZorVr1+rgwYNau3Ytq/wBADgPBE2a1NbW6s9//rMeeeQRFRUVqaioSCNHjtS4ceO0YsUKVvkDAHAeWEOTJqtXr1ZhYaEGDx7c7s8nTJigKVOm6D//+Y+mTZum3bt3a+LEif71Q4cOVVlZmd544w1Jx9+ueu211xSNRiVJQ4YMOadV/tLxNTOs8gcAhInnnHOB7Njz1JW7TiaTko4vkrXuf//7n2pra1VQUOAvEj7R0aNHVVtbq549e6qgoECe53Vqu99++60aGxt11VVX6cILL+zqw+5W3fH6dvUYBDrS3eON8RxuXfH6hn2MMEOTgVjlDwDAueG9BgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzMsJ+gAAAF3D87ygDwEIDEEDACHgnAv6ENImHo9rxIgRSiQSQR8KMghBAwAwo6Kiwr9IImrgYw0NAMCMZDIZ9CEgQxE0AAATTpyZkY7HDTM0SCFoAAAmMDuDjoQqaBKJhDzP4xLCC/8LA7LbybMzKczSICU0QVNaWirnXFZcSktLs+4xn/i4AWQfZmdwNqEJGgBAOJ1pdiaFWRpIBA0AIMMxO4POIGgAABnrxNmZ1NvsKeXl5YrFYpKYpQFBAwDIYMlk0g+Zk4MlFoupvLy8Xdgge/FJwQCAjFVeXn7W28RiMcViMX82h7jJTgQNACAUCJnsxltOAADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMzjp5wMSyaTfILmefI8L+hDQBZhvAHdhxkaAABgnudO/BzpdO7Y8xTQrgFJjEGkF+MNQQv7GGSGBgAAmEfQAAAA8wgaAABgHkEDAADMI2gAAIB5BA0AADCPoAEAAOYRNAAAwDyCBgAAmEfQAAAA8wgaAABgHkEDAADMI2gAAIB5BA0AADCPoAEAAOblBLXjWCwmz/OC2j2gWCwW9CEgi3DOQ9DCfs7znHMu6IMAAAA4H7zlBAAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPP+D7qGTX8Q8og4AAAAAElFTkSuQmCC"},257:function(t,n,s){t.exports=s.p+"assets/img/image7.ca08b1e7.png"},278:function(t,n,s){t.exports=s.p+"assets/img/image8.5d2d558a.png"},320:function(t,n,s){"use strict";s.r(n);var a=s(10),e=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"injection-methods-supported-by-gone"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#injection-methods-supported-by-gone"}},[t._v("#")]),t._v(" Injection Methods Supported by Gone")]),t._v(" "),n("p"),n("div",{staticClass:"table-of-contents"},[n("ul",[n("li",[n("a",{attrs:{href:"#public-property-injection-vs-private-property-injection"}},[t._v("Public Property Injection vs Private Property Injection")])]),n("li",[n("a",{attrs:{href:"#anonymous-injection-vs-named-injection"}},[t._v("Anonymous Injection vs Named Injection")]),n("ul",[n("li",[n("a",{attrs:{href:"#anonymous-burial-and-named-burial"}},[t._v("Anonymous Burial and Named Burial")])]),n("li",[n("a",{attrs:{href:"#anonymous-injection"}},[t._v("Anonymous Injection")])]),n("li",[n("a",{attrs:{href:"#named-injection"}},[t._v("Named Injection")])])])]),n("li",[n("a",{attrs:{href:"#supported-injection-property-types"}},[t._v("Supported Injection Property Types")]),n("ul",[n("li",[n("a",{attrs:{href:"#_1-pointer-types"}},[t._v("1. Pointer Types")])]),n("li",[n("a",{attrs:{href:"#_2-value-types"}},[t._v("2. Value Types")])]),n("li",[n("a",{attrs:{href:"#_3-interface-types"}},[t._v("3. Interface Types")])]),n("li",[n("a",{attrs:{href:"#_4-slice-types"}},[t._v("4. Slice Types")])]),n("li",[n("a",{attrs:{href:"#_5-map-types"}},[t._v("5. Map Types")])])])]),n("li",[n("a",{attrs:{href:"#pointer-injection-vs-interface-injection"}},[t._v("Pointer Injection vs Interface Injection")])]),n("li",[n("a",{attrs:{href:"#slice-injection-vs-map-injection"}},[t._v("Slice Injection vs Map Injection")])])])]),n("p"),t._v(" "),n("h2",{attrs:{id:"public-property-injection-vs-private-property-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#public-property-injection-vs-private-property-injection"}},[t._v("#")]),t._v(" Public Property Injection vs Private Property Injection")]),t._v(" "),n("p",[t._v('In Gone, both public property injection and private property injection are supported. Dependency injection typically restricts the "objects" to be injected to be used only within the module. Following the "open-closed" principle, I recommend using private property injection.')]),t._v(" "),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("Recommendation: Private Property Injection")])]),t._v(" "),n("p",[t._v("For example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\n seller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"seller"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// lowercase first letter indicates private property injection, accessible only within the package")]),t._v("\n Manager "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"manager"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// uppercase first letter indicates public property injection, accessible without restrictions")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"anonymous-injection-vs-named-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#anonymous-injection-vs-named-injection"}},[t._v("#")]),t._v(" Anonymous Injection vs Named Injection")]),t._v(" "),n("h3",{attrs:{id:"anonymous-burial-and-named-burial"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#anonymous-burial-and-named-burial"}},[t._v("#")]),t._v(" Anonymous Burial and Named Burial")]),t._v(" "),n("p",[t._v("To inject a Goner, it must first be loaded into the system. In Gone, this process is termed as "),n("strong",[t._v("burial")]),t._v(", done in the "),n("strong",[t._v("Priest")]),t._v(" function by invoking the "),n("code",[t._v("cemetery.Bury")]),t._v(' function to "bury" the reference of the Goner into the '),n("strong",[t._v("cemetery")]),t._v(". When burying, if no GonerId is specified, it's an "),n("strong",[t._v("anonymous burial")]),t._v("; if specified, it's a "),n("strong",[t._v("named burial")]),t._v(".")]),t._v(" "),n("p",[t._v("The complete definition of the "),n("strong",[n("code",[t._v("Cemetery.Bury")])]),t._v(" function is as follows: "),n("strong",[n("code",[t._v("Bury(Goner, ...GonerId) Cemetery")])]),t._v(". This definition is designed with two considerations:")]),t._v(" "),n("ol",[n("li",[t._v("It supports "),n("strong",[t._v("named burials")]),t._v(", where the second parameter is optional, allowing passing a string as the "),n("strong",[t._v("Goner")]),t._v("'s "),n("strong",[t._v("ID")]),t._v(" ("),n("strong",[t._v("GonerId")]),t._v(").")]),t._v(" "),n("li",[t._v("It enables method chaining for the Bury function.")])]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// named burial for the first AGoner, ID=A1")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// named burial for the second AGoner, ID=A2")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// anonymous burial")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("In anonymous burial, if there exist multiple compatible types of "),n("strong",[t._v("Goner")]),t._v(", only one of them will be injected, typically the first one revived. This may lead to undefined behavior. For example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\n\tseller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// anonymous injection, if multiple Workers exist, only one will be injected, typically the first one")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"John"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Alice"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),t._v(" "),n("h3",{attrs:{id:"anonymous-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#anonymous-injection"}},[t._v("#")]),t._v(" Anonymous Injection")]),t._v(" "),n("p",[t._v("When injecting without specifying the Goner's GonerId, it's termed as anonymous injection, indicated by the injection tag "),n("code",[t._v('gone:"*"')]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\n seller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// anonymous injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("div",{staticClass:"custom-block warning"},[n("p",{staticClass:"custom-block-title"},[t._v("WARNING")]),t._v(" "),n("p",[t._v("In anonymous injection, if there are multiple compatible types of "),n("strong",[t._v("Goner")]),t._v(", only one will be injected, typically the first one revived. This may lead to undefined behavior. For example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\n\tseller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// anonymous injection, if multiple Workers exist, only one will be injected, typically the first one")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"John"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Alice"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),t._v(" "),n("h3",{attrs:{id:"named-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#named-injection"}},[t._v("#")]),t._v(" Named Injection")]),t._v(" "),n("p",[t._v("When injecting with a specified GonerId, it's termed as named injection. Named injection accurately injects a Goner based on its name, which is useful in practical development. It's essential to ensure that a Goner with the corresponding GonerId is buried in the cemetery.")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n Manager "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"manager"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// named injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"supported-injection-property-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#supported-injection-property-types"}},[t._v("#")]),t._v(" Supported Injection Property Types")]),t._v(" "),n("h3",{attrs:{id:"_1-pointer-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_1-pointer-types"}},[t._v("#")]),t._v(" 1. Pointer Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is a pointer, it's termed as "),n("strong",[t._v("pointer injection")]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n seller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"seller"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// pointer type")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h3",{attrs:{id:"_2-value-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_2-value-types"}},[t._v("#")]),t._v(" 2. Value Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is a value type, it's termed as "),n("strong",[t._v("value injection")]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n seller Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"seller"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// value type")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("div",{staticClass:"custom-block warning"},[n("p",{staticClass:"custom-block-title"},[t._v("WARNING")]),t._v(" "),n("p",[t._v('In Go, value types are passed by copy, meaning that when using value injection, a new "object" is created, and the old and new objects are independent in memory. This may lead to unexpected results. For example:')]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\ta1 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// value injection")]),t._v("\n\ta2 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// value injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dapeng"')]),t._v("\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"wang"')]),t._v("\n\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a1 is eq a2: %v"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the above code, the printed result will be "),n("code",[t._v("false")]),t._v(".")])]),t._v(" "),n("h3",{attrs:{id:"_3-interface-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_3-interface-types"}},[t._v("#")]),t._v(" 3. Interface Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is an interface type, it's termed as "),n("strong",[t._v("interface injection")]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Seller "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sell")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n seller Seller "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"seller"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// interface type")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h3",{attrs:{id:"_4-slice-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_4-slice-types"}},[t._v("#")]),t._v(" 4. Slice Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is a slice type, it's termed as "),n("strong",[t._v("slice injection")]),t._v('. In slice injection, the element types of the slice can be value types, pointer types, or interface types. Due to the "copy by pass" nature of value types, it\'s not recommended to use them.')]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Seller "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sell")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n sellers "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Seller "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as interface types")]),t._v("\n workers "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as pointer types")]),t._v("\n persons "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as value types (not recommended)")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h3",{attrs:{id:"_5-map-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_5-map-types"}},[t._v("#")]),t._v(" 5. Map Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is a map type, it's termed as "),n("strong",[t._v("map injection")]),t._v('. In map injection, the element types of the map can be value types, pointer types, or interface types. Due to the "copy by pass" nature of value types, it\'s not recommended to use them. The keys of the map are always of type '),n("code",[t._v("string")]),t._v(", and the value of each key is the GonerId of the injected Goner.")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Seller "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sell")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n sellers "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Seller "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as interface types")]),t._v("\n workers "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as pointer types")]),t._v("\n persons "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as value types (not recommended)")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"pointer-injection-vs-interface-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#pointer-injection-vs-interface-injection"}},[t._v("#")]),t._v(" Pointer Injection vs Interface Injection")]),t._v(" "),n("p",[t._v("During the Bury process of a Goner in Gone, it's required to pass a reference. Both pointer injection and interface injection can pass the reference obtained from the "),n("code",[t._v("Cemetery.Bury")]),t._v(" method to the properties of a structure. "),n("strong",[t._v("Pointer injection")]),t._v(" is simple and straightforward, with a one-to-one correspondence between types, requiring no further explanation. "),n("strong",[t._v("Interfaces")]),t._v(" in Go are designed to decouple business usage from business logic implementation, allowing the usage side to be unaware of the implementation details. Interfaces also help break circular dependencies, which are not allowed in Go due to its strong typing and compile-time checks. Here's how interfaces can be used to break circular dependencies between packages:")]),t._v(" "),n("p",[t._v("Circular dependency:\n"),n("img",{attrs:{src:s(256),alt:"Circular Dependency"}})]),t._v(" "),n("p",[t._v("Using interfaces to break the circular dependency:\n"),n("img",{attrs:{src:s(257),alt:"Using Interfaces to Break Circular Dependency"}})]),t._v(" "),n("p",[t._v('Using interfaces helps hide implementation details, reduces coupling between modules, and adheres better to the "open-closed" principle. Therefore, '),n("strong",[t._v("interface injection")]),t._v(" is recommended. However, there are no absolute rules, and introducing interfaces will increase additional costs. Hence, we still support "),n("strong",[t._v("pointer injection")]),t._v(".")]),t._v(" "),n("h2",{attrs:{id:"slice-injection-vs-map-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#slice-injection-vs-map-injection"}},[t._v("#")]),t._v(" Slice Injection vs Map Injection")]),t._v(" "),n("p",[t._v("Gone supports injecting into "),n("code",[t._v("Slice")]),t._v(" and "),n("code",[t._v("Map")]),t._v(", termed as "),n("strong",[t._v("slice injection")]),t._v(" and "),n("strong",[t._v("map injection")]),t._v(" respectively. In both cases, the elements of the Slice and Map can be value types, pointer types, or interface types. However, due to the \"copy by pass\" nature of value types, it's not recommended to use them. Here's how you can inject into Slice and Map properties:")]),t._v(" "),n("p",[n("strong",[t._v("Injection rules are as follows:")])]),t._v(" "),n("ul",[n("li",[t._v("Slice and Map can contain elements of Goner pointer types, Goner value types, or interfaces.")]),t._v(" "),n("li",[t._v("Gone injects all compatible types of Goners into Slice and Map.")]),t._v(" "),n("li",[t._v("Map keys are of type "),n("code",[t._v("string")]),t._v(", and the value of each key is the GonerId of the injected Goner. If no GonerId is specified during burial, Gone generates one.")])]),t._v(" "),n("div",{staticClass:"custom-block warning"},[n("p",{staticClass:"custom-block-title"},[t._v("WARNING")]),t._v(" "),n("p",[t._v("Using value types as Slice and Map types is not recommended.")])]),t._v(" "),n("p",[t._v("Here's a complete example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" AGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sprintf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I am the AGoner, My name is: %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\taSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as Goner pointer types")]),t._v("\n\taSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as Goner value types")]),t._v("\n\n\taMap1 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as Goner pointer types")]),t._v("\n\taMap2 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as Goner value types")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive executed After the Goner is revived; After `gone.Run`, gone framework detects the AfterRevive function on goners and runs it.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aSlice1:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aSlice2:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aMap1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aMap1[%s]:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aMap2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aMap2[%s]:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA1 constructs A1 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA2 constructs A2 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Anonymous"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The example produces the following output:\n"),n("img",{attrs:{src:s(278),alt:"slice map injected example result"}})])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{256:function(t,n){t.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjQAAAEECAYAAAA/Ga4zAAAACXBIWXMAAAsTAAALEwEAmpwYAAATvElEQVR4nO3df2xV9f3H8dfBhrnGGoxyGzI7wWsaQEGjoriB3NsoIERBScC4gEaUZR31By5kEKX3opFA5owTpoKIWAUEf26ZEwRaNgzLUJdmVsFCW7ZC2sqAjXUtUPh8/yD3fCk/SpH2nvs+9/lIbtJy7z3n3Hs/HJ587qe3nnPOCQAAwLAeQR8AAADA+SJoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeYEFTTwel+d5GXuJx+NBPTUAQohzHtC9POecC2THnqeAdt0pmX58AGzJ9HNKph8fcDa85QQAAMwjaAAAgHkEDQAAMI+gAQAA5hE0AADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMwjaAAAgHkEDQAAMI+gAQAA5uUEteO+ffvK87ygdt8pmX58OD+xWEzl5eVBHwayBOc8BC3s5zx+2zayFmMQ6cR4Q9DCPgZ5ywkAAJhH0AAAAPMIGgAAYF4ogyaZTMrzPP3tb38L+lAAoNsFdc779ttv5XmeJk2alNb9AqcTyqA5fPiwJIV68RMApAR1zkvt7+jRo2ndL3A6gQfN5s2bNWzYMC1YsED33HOPotGoZs2a5f8F3bhxo4YNG6b8/HyNGTNGZWVl7e576623Kj8/Xw888ID+9Kc/nbL9f/7znxozZozGjBmj+vr6Drf33nvv6dprr1VBQYFeeeUVDRs2TM8995wkqbKyUiNHjtTFF1+seDyuzZs3n/bxdLR9AAjbOU+S9u/frylTpqigoEATJ05UQ0NDVz1dQOe5gKR2/eGHHzpJTpIrLCz0v3722Wdda2ury8vLc5LcxIkT/a+rq6vdP/7xD/+2Q4cO9b9uampys2fPdpJcRUWFu/76650k98Ybb3S4vcbGRn8bAwcO9L8uLi52+/fv9297++23+9dVV1e3e0wdbR+ZJ8DhjywUxnPeiduIRCIuEok4Se7+++8P4BnG2YT9nBf4DE3KhAkTtH37dm3atEmS9Oabb2rfvn2aOXOmPvjgA82ZM0fXXXedJGnXrl1atWqVJOlXv/qVtmzZot/85jcaNWqUdu3a5W/zwQcf1BdffKFEIqHJkyd3uL2NGzdKkp5//nlVVVVp3rx5/nb+8Ic/6ODBgyopKdHrr7+up59+WpL0zjvvtHsMHW0fAE4UhnNeSiQSUW1trWpqahSJRPTee++pra2ti58xoGOBfVLwyWKxmCRp+PDhko5Pm0YiETU2Nuqpp5465fZ1dXWSpOuvv16SVFJSopKSEknS+++/L0mqqalpd5+Otpeaur3lllvaHY/0/0Hy4osv6sUXXzzlzzuzfQA4URjOeSk//vGPlZubK0m6+eab9fvf/17V1dUaMGDAGR490PUyZoZmy5YtkqQ9e/ZIkvr06aMPP/xQCxcu1J133qnq6moVFxf7tx84cKCk47MikrRu3TrNnTtXO3bs8G8zefJkSVIikdCuXbs63N6gQYMkSdXV1ZKkqqoq/7rLLrtMkjR9+nR99dVXqqys1KeffqqZM2e2ewwdbR8AThSGc15KZWWl/3VqO9Fo9JyfE+B8ZMwMzYoVKzRgwAD97ne/kySNGjXKXznfp08fff311/5iNuecRo4cKUmaM2eOGhoaNHfuXDU1Nemxxx7zt/nYY49pwIABmj17tmbPnq3x48efcXujR4+WJBUXF2v9+vVavny5v50f/ehHkqTVq1frhhtu0IoVK/TJJ5/o3XffVb9+/fzbdXS8AHCiMJzzUmpqajRp0iTl5uaqpqZG48aNU8+ePbv0+QLOKqjFOzppgVxqIZskN2TIENfQ0OCam5vd4MGD/T8fO3ask+Tmz5/vnHNu+vTp/nWS3MqVK51zzl8g9/nnn7v//ve//kK18vLyDrc3f/58l5eX5yKRiJswYYKT5EpKSpxzzr355pvt7jt9+nTX1tbW7jGd7XiRWQIc/shCYTznNTU1+YubU/uMRCJu69at6XpacQ7Cfs7LmKBZuHCha2lpcfX19afctq6uzh0+fPi029m3b5+rqqpyra2tnd736bZXWVnpXnrpJbdlyxbX1tbmFixY4CS5V155pd3tdu7c6Q4cOHDO20fmCftfbmSWMJ/znHPu6NGjrr6+/pToQeYI+zkvY95ykqQLL7xQP/jBD0758yuuuOKM97nkkkt0ySWXnNN+Tre9/Px8zZw5UwcPHlQkElFTU5Py8vJUVFTU7nZXXnnld9o+AJwsLOc8SerRo8dpHwuQLp5zwSzwSP0a8+3bt+vdd9/V7bffriFDhgRxKL6amhpt2rRJ27ZtU9++fTV27Fj98Ic/DPSY0H1SYxBIB855CFrYz3mBBw0QFMYg0onxhqCFfQxmzI9tAwAAfFcEDQAAMI+gAQAA5hE0AADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMzLqF99gM5JJBJKJpNBH0YoeJ4X9CEgizDeulaYPyQO544ZGgAAYB4zNIaVlpYqkUgEfRhmhf1jwJFZGG9dh5kunA4zNAAAwDyCBgAAmEfQAAAA8wgaAABgHkEDAADMI2gyXEVFRdCHAABAxiNoDPA876w/nl1RUaF4PM6PcQMAshJBk+FisZhisZiSyeRpwyYVMvF4XCNGjCBoAABZyXMBfdITHzLVealoOVnfvn1VV1fnf88H7Z0bxiDSifHWdVIfrMfzeW7CPgYJGiPi8XiH62mImXPHGEQ6Md66DkHz3YR9DPKWkxGlpaVBHwIAABmLoDEitZbmdJidAQBkO345pSGlpaX8GDeA08rGX9iYbY85zG8XdQXW0Bhz8loaZme+O8Yg0qm7xxvjOdy64vUN+xjhLSdjWEsDAMCpCBpjTlxLw+wMAADHETQGMUsDAEB7rKExqqKi4ow/9YTOYQwinVhDg/PBGpqzC80MTepXA2TLJR6PB34M6b4kk8mghxkAIEOFJmgkKZFIyDnHJYQX1goBADoSqqABAADZiaABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNACBjHDt2THV1ddq7d2/QhwJjCBoAQLe7+OKL5XmefykoKNDcuXN17NgxSZJzTkuXLlWvXr3Ur18/9e7dW9FoVG+//XbARw4rCBoAQFqUlZVp//79amho0OzZs1VaWqotW7ZIkt566y099NBDKisr05EjR7R3715NmzZN9957rz777LOAjxwWEDQAgLS46KKL1KtXL+Xn5+vuu++WJDU3N0uSnnjiCc2fP1/jxo1TTk6OLr30Us2cOVNPPfWUdu/eLUk6evSonnnmGRUUFCg/P18zZsxQS0uLWltbddNNN2np0qW6+uqrFY1G9eqrr/r7/etf/6pbb71V+fn5mjJliv71r39JkpYtW6Y5c+Zo6tSp+ulPf5rmZwNdjaABAKTFunXrtGzZMi1atEg/+clPVFhYqBEjRqixsVFNTU267bbb/NsePnxYR44c0ZNPPqmxY8dKkl577TUtWLBAv/zlL7VmzRqtWbNGzz77rI4dO6atW7dqwYIFev755xWPx/Xwww+rtbVVjY2Nuvnmm3XddddpzZo12rdvnx9Te/bs0dNPP63du3fr3nvvDeQ5QdfJCfoAAADZ4dNPP1VdXZ3a2tr05ZdfqmfPnqqtrVVLS4uk4+tsJGnnzp266qqr/PsVFRVpw4YNWrJkiR599FH9/Oc/lySVlpYqmUxq1qxZkqSXX35Z8Xhct9xyi5YuXaq6ujp9/PHHuvzyy/XCCy/I8zzl5+erf//+amhokCRFIhF99NFH6tGD/99bxyuYgVjlDyCMksmkPvroI61bt067d+/WoEGDtHjxYvXp00eS/LUyV1xxhXbs2KEdO3aouLjYv/+2bdt04403+t/369dP9fX1/vcFBQWSpLy8PEnSoUOHtHPnTtXX16tHjx7yPE/9+/eXJP/8ettttxEzIcGrGIBf/OIX8jzvlIVurPIHkC1ycnI0aNAgVVZWKj8/X3l5eSovL/evi0ajikaj2rZtm3+fG264oV3AfPPNNxo1apT//QUXXHDKfnr16qUhQ4aoublZzc3NOnDggDZv3qzCwsJufHQIAkGTZkeOHNHixYuVl5en1atXt7uOVf4Awqy+vl7bt29XVVWV5s2bp5deekl33XWXPM/TvHnztHjxYq1Zs0YtLS2qqqrS448/ro0bN/r3Hz9+vJYvX66amhodPnxYK1eu1OjRozvc5/Dhw7V161Z99tln8jxPL7zwgu655x5mZUKIVzTN1q9fr+9///v69a9/reXLl6utrc2/jlX+AMKspKRE/fv31zXXXKPf/va3Ki4u1s9+9jNJ0rRp0zRr1ixNnDhRubm5uuaaa/SXv/xFZWVl/szLpEmTdOjQIUWjUX3ve99Ta2ur7rvvvjPuz/M8jRw5UjNmzNCIESOUm5urRYsWaeXKlcrJyZHneYRNmLiAdPWuE4mESyQSXbrN7nDfffe5J554wu3du9dJchs2bHDOOdfQ0OAkuc8//9y/7aFDh/zLkSNHnHPOLV682OXl5bmFCxe6TZs2ucsvv9w9+eSTrrm52UlyhYWFbu3atW7q1KlOkmtpafG3XVJS4jZt2uTGjh3rhg8f7pxz7plnnnGS3KhRo9zGjRvT/4R0Une8vgEOf2Sh7h5vYRnPzc3N7ssvv3T//ve/T3t9W1ubq66udrt27XLHjh3r9Habmprc3//+d9fS0tJVh5pWXfH6hmWMnAk/5ZRGBw4c0IoVK7R161ZdeumluuOOO7Rq1SoVFRVpz549kljlDyC75ebm6uqrrz7j9RdccEG7c2Nn9e7dW7179z6fQ0OG41+wNHr//fclHZ82jUaj+uMf/6hVq1appaWFVf4AAJwH/hVLo2XLlmnq1KlasmSJlixZorVr1+rgwYNau3Ytq/wBADgPBE2a1NbW6s9//rMeeeQRFRUVqaioSCNHjtS4ceO0YsUKVvkDAHAeWEOTJqtXr1ZhYaEGDx7c7s8nTJigKVOm6D//+Y+mTZum3bt3a+LEif71Q4cOVVlZmd544w1Jx9+ueu211xSNRiVJQ4YMOadV/tLxNTOs8gcAhInnnHOB7Njz1JW7TiaTko4vkrXuf//7n2pra1VQUOAvEj7R0aNHVVtbq549e6qgoECe53Vqu99++60aGxt11VVX6cILL+zqw+5W3fH6dvUYBDrS3eON8RxuXfH6hn2MMEOTgVjlDwDAueG9BgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzMsJ+gAAAF3D87ygDwEIDEEDACHgnAv6ENImHo9rxIgRSiQSQR8KMghBAwAwo6Kiwr9IImrgYw0NAMCMZDIZ9CEgQxE0AAATTpyZkY7HDTM0SCFoAAAmMDuDjoQqaBKJhDzP4xLCC/8LA7LbybMzKczSICU0QVNaWirnXFZcSktLs+4xn/i4AWQfZmdwNqEJGgBAOJ1pdiaFWRpIBA0AIMMxO4POIGgAABnrxNmZ1NvsKeXl5YrFYpKYpQFBAwDIYMlk0g+Zk4MlFoupvLy8Xdgge/FJwQCAjFVeXn7W28RiMcViMX82h7jJTgQNACAUCJnsxltOAADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMzjp5wMSyaTfILmefI8L+hDQBZhvAHdhxkaAABgnudO/BzpdO7Y8xTQrgFJjEGkF+MNQQv7GGSGBgAAmEfQAAAA8wgaAABgHkEDAADMI2gAAIB5BA0AADCPoAEAAOYRNAAAwDyCBgAAmEfQAAAA8wgaAABgHkEDAADMI2gAAIB5BA0AADCPoAEAAOblBLXjWCwmz/OC2j2gWCwW9CEgi3DOQ9DCfs7znHMu6IMAAAA4H7zlBAAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPP+D7qGTX8Q8og4AAAAAElFTkSuQmCC"},257:function(t,n,s){t.exports=s.p+"assets/img/image7.ca08b1e7.png"},278:function(t,n,s){t.exports=s.p+"assets/img/image8.5d2d558a.png"},319:function(t,n,s){"use strict";s.r(n);var a=s(10),e=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"injection-methods-supported-by-gone"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#injection-methods-supported-by-gone"}},[t._v("#")]),t._v(" Injection Methods Supported by Gone")]),t._v(" "),n("p"),n("div",{staticClass:"table-of-contents"},[n("ul",[n("li",[n("a",{attrs:{href:"#public-property-injection-vs-private-property-injection"}},[t._v("Public Property Injection vs Private Property Injection")])]),n("li",[n("a",{attrs:{href:"#anonymous-injection-vs-named-injection"}},[t._v("Anonymous Injection vs Named Injection")]),n("ul",[n("li",[n("a",{attrs:{href:"#anonymous-burial-and-named-burial"}},[t._v("Anonymous Burial and Named Burial")])]),n("li",[n("a",{attrs:{href:"#anonymous-injection"}},[t._v("Anonymous Injection")])]),n("li",[n("a",{attrs:{href:"#named-injection"}},[t._v("Named Injection")])])])]),n("li",[n("a",{attrs:{href:"#supported-injection-property-types"}},[t._v("Supported Injection Property Types")]),n("ul",[n("li",[n("a",{attrs:{href:"#_1-pointer-types"}},[t._v("1. Pointer Types")])]),n("li",[n("a",{attrs:{href:"#_2-value-types"}},[t._v("2. Value Types")])]),n("li",[n("a",{attrs:{href:"#_3-interface-types"}},[t._v("3. Interface Types")])]),n("li",[n("a",{attrs:{href:"#_4-slice-types"}},[t._v("4. Slice Types")])]),n("li",[n("a",{attrs:{href:"#_5-map-types"}},[t._v("5. Map Types")])])])]),n("li",[n("a",{attrs:{href:"#pointer-injection-vs-interface-injection"}},[t._v("Pointer Injection vs Interface Injection")])]),n("li",[n("a",{attrs:{href:"#slice-injection-vs-map-injection"}},[t._v("Slice Injection vs Map Injection")])])])]),n("p"),t._v(" "),n("h2",{attrs:{id:"public-property-injection-vs-private-property-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#public-property-injection-vs-private-property-injection"}},[t._v("#")]),t._v(" Public Property Injection vs Private Property Injection")]),t._v(" "),n("p",[t._v('In Gone, both public property injection and private property injection are supported. Dependency injection typically restricts the "objects" to be injected to be used only within the module. Following the "open-closed" principle, I recommend using private property injection.')]),t._v(" "),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("Recommendation: Private Property Injection")])]),t._v(" "),n("p",[t._v("For example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\n seller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"seller"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// lowercase first letter indicates private property injection, accessible only within the package")]),t._v("\n Manager "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"manager"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// uppercase first letter indicates public property injection, accessible without restrictions")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"anonymous-injection-vs-named-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#anonymous-injection-vs-named-injection"}},[t._v("#")]),t._v(" Anonymous Injection vs Named Injection")]),t._v(" "),n("h3",{attrs:{id:"anonymous-burial-and-named-burial"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#anonymous-burial-and-named-burial"}},[t._v("#")]),t._v(" Anonymous Burial and Named Burial")]),t._v(" "),n("p",[t._v("To inject a Goner, it must first be loaded into the system. In Gone, this process is termed as "),n("strong",[t._v("burial")]),t._v(", done in the "),n("strong",[t._v("Priest")]),t._v(" function by invoking the "),n("code",[t._v("cemetery.Bury")]),t._v(' function to "bury" the reference of the Goner into the '),n("strong",[t._v("cemetery")]),t._v(". When burying, if no GonerId is specified, it's an "),n("strong",[t._v("anonymous burial")]),t._v("; if specified, it's a "),n("strong",[t._v("named burial")]),t._v(".")]),t._v(" "),n("p",[t._v("The complete definition of the "),n("strong",[n("code",[t._v("Cemetery.Bury")])]),t._v(" function is as follows: "),n("strong",[n("code",[t._v("Bury(Goner, ...GonerId) Cemetery")])]),t._v(". This definition is designed with two considerations:")]),t._v(" "),n("ol",[n("li",[t._v("It supports "),n("strong",[t._v("named burials")]),t._v(", where the second parameter is optional, allowing passing a string as the "),n("strong",[t._v("Goner")]),t._v("'s "),n("strong",[t._v("ID")]),t._v(" ("),n("strong",[t._v("GonerId")]),t._v(").")]),t._v(" "),n("li",[t._v("It enables method chaining for the Bury function.")])]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// named burial for the first AGoner, ID=A1")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// named burial for the second AGoner, ID=A2")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// anonymous burial")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("In anonymous burial, if there exist multiple compatible types of "),n("strong",[t._v("Goner")]),t._v(", only one of them will be injected, typically the first one revived. This may lead to undefined behavior. For example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\n\tseller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// anonymous injection, if multiple Workers exist, only one will be injected, typically the first one")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"John"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Alice"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),t._v(" "),n("h3",{attrs:{id:"anonymous-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#anonymous-injection"}},[t._v("#")]),t._v(" Anonymous Injection")]),t._v(" "),n("p",[t._v("When injecting without specifying the Goner's GonerId, it's termed as anonymous injection, indicated by the injection tag "),n("code",[t._v('gone:"*"')]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\n seller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// anonymous injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("div",{staticClass:"custom-block warning"},[n("p",{staticClass:"custom-block-title"},[t._v("WARNING")]),t._v(" "),n("p",[t._v("In anonymous injection, if there are multiple compatible types of "),n("strong",[t._v("Goner")]),t._v(", only one will be injected, typically the first one revived. This may lead to undefined behavior. For example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n\n\tseller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// anonymous injection, if multiple Workers exist, only one will be injected, typically the first one")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"John"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Alice"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),t._v(" "),n("h3",{attrs:{id:"named-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#named-injection"}},[t._v("#")]),t._v(" Named Injection")]),t._v(" "),n("p",[t._v("When injecting with a specified GonerId, it's termed as named injection. Named injection accurately injects a Goner based on its name, which is useful in practical development. It's essential to ensure that a Goner with the corresponding GonerId is buried in the cemetery.")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner flag, embedding `gone.Flag` anonymously indicates that this structure is a Goner")]),t._v("\n Manager "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"manager"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// named injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"supported-injection-property-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#supported-injection-property-types"}},[t._v("#")]),t._v(" Supported Injection Property Types")]),t._v(" "),n("h3",{attrs:{id:"_1-pointer-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_1-pointer-types"}},[t._v("#")]),t._v(" 1. Pointer Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is a pointer, it's termed as "),n("strong",[t._v("pointer injection")]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n seller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"seller"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// pointer type")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h3",{attrs:{id:"_2-value-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_2-value-types"}},[t._v("#")]),t._v(" 2. Value Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is a value type, it's termed as "),n("strong",[t._v("value injection")]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n seller Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"seller"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// value type")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("div",{staticClass:"custom-block warning"},[n("p",{staticClass:"custom-block-title"},[t._v("WARNING")]),t._v(" "),n("p",[t._v('In Go, value types are passed by copy, meaning that when using value injection, a new "object" is created, and the old and new objects are independent in memory. This may lead to unexpected results. For example:')]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\ta1 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// value injection")]),t._v("\n\ta2 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// value injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dapeng"')]),t._v("\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"wang"')]),t._v("\n\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a1 is eq a2: %v"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the above code, the printed result will be "),n("code",[t._v("false")]),t._v(".")])]),t._v(" "),n("h3",{attrs:{id:"_3-interface-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_3-interface-types"}},[t._v("#")]),t._v(" 3. Interface Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is an interface type, it's termed as "),n("strong",[t._v("interface injection")]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Seller "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sell")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n seller Seller "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"seller"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// interface type")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h3",{attrs:{id:"_4-slice-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_4-slice-types"}},[t._v("#")]),t._v(" 4. Slice Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is a slice type, it's termed as "),n("strong",[t._v("slice injection")]),t._v('. In slice injection, the element types of the slice can be value types, pointer types, or interface types. Due to the "copy by pass" nature of value types, it\'s not recommended to use them.')]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Seller "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sell")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n sellers "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Seller "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as interface types")]),t._v("\n workers "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as pointer types")]),t._v("\n persons "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as value types (not recommended)")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h3",{attrs:{id:"_5-map-types"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_5-map-types"}},[t._v("#")]),t._v(" 5. Map Types")]),t._v(" "),n("p",[t._v("When the injected Goner property is a map type, it's termed as "),n("strong",[t._v("map injection")]),t._v('. In map injection, the element types of the map can be value types, pointer types, or interface types. Due to the "copy by pass" nature of value types, it\'s not recommended to use them. The keys of the map are always of type '),n("code",[t._v("string")]),t._v(", and the value of each key is the GonerId of the injected Goner.")]),t._v(" "),n("p",[n("strong",[t._v("Example:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Seller "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sell")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n sellers "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Seller "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as interface types")]),t._v("\n workers "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as pointer types")]),t._v("\n persons "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Worker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as value types (not recommended)")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"pointer-injection-vs-interface-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#pointer-injection-vs-interface-injection"}},[t._v("#")]),t._v(" Pointer Injection vs Interface Injection")]),t._v(" "),n("p",[t._v("During the Bury process of a Goner in Gone, it's required to pass a reference. Both pointer injection and interface injection can pass the reference obtained from the "),n("code",[t._v("Cemetery.Bury")]),t._v(" method to the properties of a structure. "),n("strong",[t._v("Pointer injection")]),t._v(" is simple and straightforward, with a one-to-one correspondence between types, requiring no further explanation. "),n("strong",[t._v("Interfaces")]),t._v(" in Go are designed to decouple business usage from business logic implementation, allowing the usage side to be unaware of the implementation details. Interfaces also help break circular dependencies, which are not allowed in Go due to its strong typing and compile-time checks. Here's how interfaces can be used to break circular dependencies between packages:")]),t._v(" "),n("p",[t._v("Circular dependency:\n"),n("img",{attrs:{src:s(256),alt:"Circular Dependency"}})]),t._v(" "),n("p",[t._v("Using interfaces to break the circular dependency:\n"),n("img",{attrs:{src:s(257),alt:"Using Interfaces to Break Circular Dependency"}})]),t._v(" "),n("p",[t._v('Using interfaces helps hide implementation details, reduces coupling between modules, and adheres better to the "open-closed" principle. Therefore, '),n("strong",[t._v("interface injection")]),t._v(" is recommended. However, there are no absolute rules, and introducing interfaces will increase additional costs. Hence, we still support "),n("strong",[t._v("pointer injection")]),t._v(".")]),t._v(" "),n("h2",{attrs:{id:"slice-injection-vs-map-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#slice-injection-vs-map-injection"}},[t._v("#")]),t._v(" Slice Injection vs Map Injection")]),t._v(" "),n("p",[t._v("Gone supports injecting into "),n("code",[t._v("Slice")]),t._v(" and "),n("code",[t._v("Map")]),t._v(", termed as "),n("strong",[t._v("slice injection")]),t._v(" and "),n("strong",[t._v("map injection")]),t._v(" respectively. In both cases, the elements of the Slice and Map can be value types, pointer types, or interface types. However, due to the \"copy by pass\" nature of value types, it's not recommended to use them. Here's how you can inject into Slice and Map properties:")]),t._v(" "),n("p",[n("strong",[t._v("Injection rules are as follows:")])]),t._v(" "),n("ul",[n("li",[t._v("Slice and Map can contain elements of Goner pointer types, Goner value types, or interfaces.")]),t._v(" "),n("li",[t._v("Gone injects all compatible types of Goners into Slice and Map.")]),t._v(" "),n("li",[t._v("Map keys are of type "),n("code",[t._v("string")]),t._v(", and the value of each key is the GonerId of the injected Goner. If no GonerId is specified during burial, Gone generates one.")])]),t._v(" "),n("div",{staticClass:"custom-block warning"},[n("p",{staticClass:"custom-block-title"},[t._v("WARNING")]),t._v(" "),n("p",[t._v("Using value types as Slice and Map types is not recommended.")])]),t._v(" "),n("p",[t._v("Here's a complete example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" AGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sprintf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I am the AGoner, My name is: %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\taSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as Goner pointer types")]),t._v("\n\taSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Slice type with elements as Goner value types")]),t._v("\n\n\taMap1 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as Goner pointer types")]),t._v("\n\taMap2 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Map type with values as Goner value types")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive executed After the Goner is revived; After `gone.Run`, gone framework detects the AfterRevive function on goners and runs it.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aSlice1:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aSlice2:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aMap1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aMap1[%s]:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aMap2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aMap2[%s]:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA1 constructs A1 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA2 constructs A2 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Anonymous"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The example produces the following output:\n"),n("img",{attrs:{src:s(278),alt:"slice map injected example result"}})])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/23.f7691d82.js b/assets/js/23.06f1e408.js similarity index 99% rename from assets/js/23.f7691d82.js rename to assets/js/23.06f1e408.js index 427eb49..c6f96d0 100644 --- a/assets/js/23.f7691d82.js +++ b/assets/js/23.06f1e408.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[23],{256:function(t,n){t.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjQAAAEECAYAAAA/Ga4zAAAACXBIWXMAAAsTAAALEwEAmpwYAAATvElEQVR4nO3df2xV9f3H8dfBhrnGGoxyGzI7wWsaQEGjoriB3NsoIERBScC4gEaUZR31By5kEKX3opFA5owTpoKIWAUEf26ZEwRaNgzLUJdmVsFCW7ZC2sqAjXUtUPh8/yD3fCk/SpH2nvs+9/lIbtJy7z3n3Hs/HJ587qe3nnPOCQAAwLAeQR8AAADA+SJoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeYEFTTwel+d5GXuJx+NBPTUAQohzHtC9POecC2THnqeAdt0pmX58AGzJ9HNKph8fcDa85QQAAMwjaAAAgHkEDQAAMI+gAQAA5hE0AADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMwjaAAAgHkEDQAAMI+gAQAA5uUEteO+ffvK87ygdt8pmX58OD+xWEzl5eVBHwayBOc8BC3s5zx+2zayFmMQ6cR4Q9DCPgZ5ywkAAJhH0AAAAPMIGgAAYF4ogyaZTMrzPP3tb38L+lAAoNsFdc779ttv5XmeJk2alNb9AqcTyqA5fPiwJIV68RMApAR1zkvt7+jRo2ndL3A6gQfN5s2bNWzYMC1YsED33HOPotGoZs2a5f8F3bhxo4YNG6b8/HyNGTNGZWVl7e576623Kj8/Xw888ID+9Kc/nbL9f/7znxozZozGjBmj+vr6Drf33nvv6dprr1VBQYFeeeUVDRs2TM8995wkqbKyUiNHjtTFF1+seDyuzZs3n/bxdLR9AAjbOU+S9u/frylTpqigoEATJ05UQ0NDVz1dQOe5gKR2/eGHHzpJTpIrLCz0v3722Wdda2ury8vLc5LcxIkT/a+rq6vdP/7xD/+2Q4cO9b9uampys2fPdpJcRUWFu/76650k98Ybb3S4vcbGRn8bAwcO9L8uLi52+/fv9297++23+9dVV1e3e0wdbR+ZJ8DhjywUxnPeiduIRCIuEok4Se7+++8P4BnG2YT9nBf4DE3KhAkTtH37dm3atEmS9Oabb2rfvn2aOXOmPvjgA82ZM0fXXXedJGnXrl1atWqVJOlXv/qVtmzZot/85jcaNWqUdu3a5W/zwQcf1BdffKFEIqHJkyd3uL2NGzdKkp5//nlVVVVp3rx5/nb+8Ic/6ODBgyopKdHrr7+up59+WpL0zjvvtHsMHW0fAE4UhnNeSiQSUW1trWpqahSJRPTee++pra2ti58xoGOBfVLwyWKxmCRp+PDhko5Pm0YiETU2Nuqpp5465fZ1dXWSpOuvv16SVFJSopKSEknS+++/L0mqqalpd5+Otpeaur3lllvaHY/0/0Hy4osv6sUXXzzlzzuzfQA4URjOeSk//vGPlZubK0m6+eab9fvf/17V1dUaMGDAGR490PUyZoZmy5YtkqQ9e/ZIkvr06aMPP/xQCxcu1J133qnq6moVFxf7tx84cKCk47MikrRu3TrNnTtXO3bs8G8zefJkSVIikdCuXbs63N6gQYMkSdXV1ZKkqqoq/7rLLrtMkjR9+nR99dVXqqys1KeffqqZM2e2ewwdbR8AThSGc15KZWWl/3VqO9Fo9JyfE+B8ZMwMzYoVKzRgwAD97ne/kySNGjXKXznfp08fff311/5iNuecRo4cKUmaM2eOGhoaNHfuXDU1Nemxxx7zt/nYY49pwIABmj17tmbPnq3x48efcXujR4+WJBUXF2v9+vVavny5v50f/ehHkqTVq1frhhtu0IoVK/TJJ5/o3XffVb9+/fzbdXS8AHCiMJzzUmpqajRp0iTl5uaqpqZG48aNU8+ePbv0+QLOKqjFOzppgVxqIZskN2TIENfQ0OCam5vd4MGD/T8fO3ask+Tmz5/vnHNu+vTp/nWS3MqVK51zzl8g9/nnn7v//ve//kK18vLyDrc3f/58l5eX5yKRiJswYYKT5EpKSpxzzr355pvt7jt9+nTX1tbW7jGd7XiRWQIc/shCYTznNTU1+YubU/uMRCJu69at6XpacQ7Cfs7LmKBZuHCha2lpcfX19afctq6uzh0+fPi029m3b5+rqqpyra2tnd736bZXWVnpXnrpJbdlyxbX1tbmFixY4CS5V155pd3tdu7c6Q4cOHDO20fmCftfbmSWMJ/znHPu6NGjrr6+/pToQeYI+zkvY95ykqQLL7xQP/jBD0758yuuuOKM97nkkkt0ySWXnNN+Tre9/Px8zZw5UwcPHlQkElFTU5Py8vJUVFTU7nZXXnnld9o+AJwsLOc8SerRo8dpHwuQLp5zwSzwSP0a8+3bt+vdd9/V7bffriFDhgRxKL6amhpt2rRJ27ZtU9++fTV27Fj98Ic/DPSY0H1SYxBIB855CFrYz3mBBw0QFMYg0onxhqCFfQxmzI9tAwAAfFcEDQAAMI+gAQAA5hE0AADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMzLqF99gM5JJBJKJpNBH0YoeJ4X9CEgizDeulaYPyQO544ZGgAAYB4zNIaVlpYqkUgEfRhmhf1jwJFZGG9dh5kunA4zNAAAwDyCBgAAmEfQAAAA8wgaAABgHkEDAADMI2gyXEVFRdCHAABAxiNoDPA876w/nl1RUaF4PM6PcQMAshJBk+FisZhisZiSyeRpwyYVMvF4XCNGjCBoAABZyXMBfdITHzLVealoOVnfvn1VV1fnf88H7Z0bxiDSifHWdVIfrMfzeW7CPgYJGiPi8XiH62mImXPHGEQ6Md66DkHz3YR9DPKWkxGlpaVBHwIAABmLoDEitZbmdJidAQBkO345pSGlpaX8GDeA08rGX9iYbY85zG8XdQXW0Bhz8loaZme+O8Yg0qm7xxvjOdy64vUN+xjhLSdjWEsDAMCpCBpjTlxLw+wMAADHETQGMUsDAEB7rKExqqKi4ow/9YTOYQwinVhDg/PBGpqzC80MTepXA2TLJR6PB34M6b4kk8mghxkAIEOFJmgkKZFIyDnHJYQX1goBADoSqqABAADZiaABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNACBjHDt2THV1ddq7d2/QhwJjCBoAQLe7+OKL5XmefykoKNDcuXN17NgxSZJzTkuXLlWvXr3Ur18/9e7dW9FoVG+//XbARw4rCBoAQFqUlZVp//79amho0OzZs1VaWqotW7ZIkt566y099NBDKisr05EjR7R3715NmzZN9957rz777LOAjxwWEDQAgLS46KKL1KtXL+Xn5+vuu++WJDU3N0uSnnjiCc2fP1/jxo1TTk6OLr30Us2cOVNPPfWUdu/eLUk6evSonnnmGRUUFCg/P18zZsxQS0uLWltbddNNN2np0qW6+uqrFY1G9eqrr/r7/etf/6pbb71V+fn5mjJliv71r39JkpYtW6Y5c+Zo6tSp+ulPf5rmZwNdjaABAKTFunXrtGzZMi1atEg/+clPVFhYqBEjRqixsVFNTU267bbb/NsePnxYR44c0ZNPPqmxY8dKkl577TUtWLBAv/zlL7VmzRqtWbNGzz77rI4dO6atW7dqwYIFev755xWPx/Xwww+rtbVVjY2Nuvnmm3XddddpzZo12rdvnx9Te/bs0dNPP63du3fr3nvvDeQ5QdfJCfoAAADZ4dNPP1VdXZ3a2tr05ZdfqmfPnqqtrVVLS4uk4+tsJGnnzp266qqr/PsVFRVpw4YNWrJkiR599FH9/Oc/lySVlpYqmUxq1qxZkqSXX35Z8Xhct9xyi5YuXaq6ujp9/PHHuvzyy/XCCy/I8zzl5+erf//+amhokCRFIhF99NFH6tGD/99bxyuYgVjlDyCMksmkPvroI61bt067d+/WoEGDtHjxYvXp00eS/LUyV1xxhXbs2KEdO3aouLjYv/+2bdt04403+t/369dP9fX1/vcFBQWSpLy8PEnSoUOHtHPnTtXX16tHjx7yPE/9+/eXJP/8ettttxEzIcGrGIBf/OIX8jzvlIVurPIHkC1ycnI0aNAgVVZWKj8/X3l5eSovL/evi0ajikaj2rZtm3+fG264oV3AfPPNNxo1apT//QUXXHDKfnr16qUhQ4aoublZzc3NOnDggDZv3qzCwsJufHQIAkGTZkeOHNHixYuVl5en1atXt7uOVf4Awqy+vl7bt29XVVWV5s2bp5deekl33XWXPM/TvHnztHjxYq1Zs0YtLS2qqqrS448/ro0bN/r3Hz9+vJYvX66amhodPnxYK1eu1OjRozvc5/Dhw7V161Z99tln8jxPL7zwgu655x5mZUKIVzTN1q9fr+9///v69a9/reXLl6utrc2/jlX+AMKspKRE/fv31zXXXKPf/va3Ki4u1s9+9jNJ0rRp0zRr1ixNnDhRubm5uuaaa/SXv/xFZWVl/szLpEmTdOjQIUWjUX3ve99Ta2ur7rvvvjPuz/M8jRw5UjNmzNCIESOUm5urRYsWaeXKlcrJyZHneYRNmLiAdPWuE4mESyQSXbrN7nDfffe5J554wu3du9dJchs2bHDOOdfQ0OAkuc8//9y/7aFDh/zLkSNHnHPOLV682OXl5bmFCxe6TZs2ucsvv9w9+eSTrrm52UlyhYWFbu3atW7q1KlOkmtpafG3XVJS4jZt2uTGjh3rhg8f7pxz7plnnnGS3KhRo9zGjRvT/4R0Une8vgEOf2Sh7h5vYRnPzc3N7ssvv3T//ve/T3t9W1ubq66udrt27XLHjh3r9Habmprc3//+d9fS0tJVh5pWXfH6hmWMnAk/5ZRGBw4c0IoVK7R161ZdeumluuOOO7Rq1SoVFRVpz549kljlDyC75ebm6uqrrz7j9RdccEG7c2Nn9e7dW7179z6fQ0OG41+wNHr//fclHZ82jUaj+uMf/6hVq1appaWFVf4AAJwH/hVLo2XLlmnq1KlasmSJlixZorVr1+rgwYNau3Ytq/wBADgPBE2a1NbW6s9//rMeeeQRFRUVqaioSCNHjtS4ceO0YsUKVvkDAHAeWEOTJqtXr1ZhYaEGDx7c7s8nTJigKVOm6D//+Y+mTZum3bt3a+LEif71Q4cOVVlZmd544w1Jx9+ueu211xSNRiVJQ4YMOadV/tLxNTOs8gcAhInnnHOB7Njz1JW7TiaTko4vkrXuf//7n2pra1VQUOAvEj7R0aNHVVtbq549e6qgoECe53Vqu99++60aGxt11VVX6cILL+zqw+5W3fH6dvUYBDrS3eON8RxuXfH6hn2MMEOTgVjlDwDAueG9BgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzMsJ+gAAAF3D87ygDwEIDEEDACHgnAv6ENImHo9rxIgRSiQSQR8KMghBAwAwo6Kiwr9IImrgYw0NAMCMZDIZ9CEgQxE0AAATTpyZkY7HDTM0SCFoAAAmMDuDjoQqaBKJhDzP4xLCC/8LA7LbybMzKczSICU0QVNaWirnXFZcSktLs+4xn/i4AWQfZmdwNqEJGgBAOJ1pdiaFWRpIBA0AIMMxO4POIGgAABnrxNmZ1NvsKeXl5YrFYpKYpQFBAwDIYMlk0g+Zk4MlFoupvLy8Xdgge/FJwQCAjFVeXn7W28RiMcViMX82h7jJTgQNACAUCJnsxltOAADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMzjp5wMSyaTfILmefI8L+hDQBZhvAHdhxkaAABgnudO/BzpdO7Y8xTQrgFJjEGkF+MNQQv7GGSGBgAAmEfQAAAA8wgaAABgHkEDAADMI2gAAIB5BA0AADCPoAEAAOYRNAAAwDyCBgAAmEfQAAAA8wgaAABgHkEDAADMI2gAAIB5BA0AADCPoAEAAOblBLXjWCwmz/OC2j2gWCwW9CEgi3DOQ9DCfs7znHMu6IMAAAA4H7zlBAAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPP+D7qGTX8Q8og4AAAAAElFTkSuQmCC"},257:function(t,n,a){t.exports=a.p+"assets/img/image7.ca08b1e7.png"},321:function(t,n,a){"use strict";a.r(n);var s=a(10),e=Object(s.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h2",{attrs:{id:"goner-and-dependency-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#goner-and-dependency-injection"}},[t._v("#")]),t._v(" Goner and Dependency Injection")]),t._v(" "),n("h3",{attrs:{id:"definition-of-goner"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#definition-of-goner"}},[t._v("#")]),t._v(" Definition of Goner")]),t._v(" "),n("p",[t._v('In the Gone application, all components are required to be defined as Goners (i.e., structures that "inherit" '),n("code",[t._v("gone.Flag")]),t._v(', although Go does not have the concept of "inheritance" as seen in other languages; instead, it uses anonymous embedding). If a property of a Goner is tagged with the '),n("code",[t._v('gone:""')]),t._v(" tag, the Gone framework will attempt to automatically wire this property. Here's an example of defining a Goner:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" example\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" AGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Injecting the above-defined AGoner into another Goner:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" example\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n A "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The purpose of the gone tag is to inform Gone that this property needs to be automatically injected with a value")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In this example, both the injected and the injecting structures must be "),n("code",[t._v("Goner")]),t._v(" (i.e., structures embedded with "),n("code",[t._v("gone.Flag")]),t._v("). The "),n("code",[t._v('gone:"*"')]),t._v(" tag on the "),n("code",[t._v("A")]),t._v(" property of the "),n("code",[t._v("BGoner")]),t._v(" tells the framework that this property needs to be injected with a value.")]),t._v(" "),n("h3",{attrs:{id:"how-dependency-injection-is-achieved-in-gone"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#how-dependency-injection-is-achieved-in-gone"}},[t._v("#")]),t._v(" How Dependency Injection is Achieved in Gone")]),t._v(" "),n("p",[t._v("In Java Spring, classes are annotated with "),n("code",[t._v("@Component")]),t._v(", "),n("code",[t._v("@Service")]),t._v(", etc., and during Spring startup, these specially annotated classes are automatically scanned, instantiated, and their annotated properties injected with corresponding values.")]),t._v(" "),n("p",[t._v("The reason Spring can achieve this functionality lies in a critical feature of Java: after Java code is compiled into a JAR file, all class bytecode is preserved, even for classes not directly dependent on the "),n("code",[t._v("main")]),t._v(" function. However, in Go, the compiled code is pruned, and only the code relevant to the "),n("code",[t._v("main")]),t._v(" function is retained in the binary. Therefore, if we merely define Goners, we'll find that our Goner code has been pruned.")]),t._v(" "),n("p",[t._v('How do we prevent our Goners from being pruned? The answer is simple: explicitly add all Goners to a "repository". In Gone, this repository is called the '),n("code",[t._v("Cemetery")]),t._v(". "),n("code",[t._v("Goner")]),t._v(' means "deceased", and '),n("code",[t._v("Cemetery")]),t._v(" is the graveyard used to bury (Bury) Goners. We can instantiate all Goners and add them to the Cemetery at program startup:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("example"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("example"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the above code, we see that "),n("code",[t._v("gone.Run")]),t._v(" can accept a function in the form of "),n("strong",[n("code",[t._v("func (cemetery gone.Cemetery) error")])]),t._v(". In practice, this function, which we call "),n("strong",[t._v("Priest")]),t._v(", is responsible for burying Goners in the cemetery.")]),t._v(" "),n("h3",{attrs:{id:"how-to-execute-business-code-in-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#how-to-execute-business-code-in-goners"}},[t._v("#")]),t._v(" How to Execute Business Code in Goners?")]),t._v(" "),n("p",[t._v("In Gone, we've made an interesting definition: when all properties of a Goner are injected, we say that this Goner has been resurrected (Revive). If you look at the source code of Gone, you'll find that the component responsible for managing the revived Goner status is called "),n("strong",[t._v("Heaven")]),t._v(", inspired by the mythical belief across religions that people ascend to heaven after death.")]),t._v(" "),n("p",[t._v("To execute business code in Goners, we can define a method on Goners called "),n("strong",[n("code",[t._v("AfterRevive() gone.AfterReviveError")])]),t._v(". This method is executed after a Goner is "),n("strong",[t._v("Revived")]),t._v(", and Goners possessing this method are called "),n("strong",[t._v("Prophets")]),t._v(". In practice, we typically only need to define a small number of prophets to guide code execution.")]),t._v(" "),n("p",[t._v("Here's an example; you can find the code "),n("a",{attrs:{href:"https://github.com/gone-io/gone/blob/main/example/after-revive/main.go",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),n("OutboundLink")],1),t._v(":")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Adder "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Add")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a2 "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" a1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" a2\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Computer "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tadder Adder "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Compute")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I want to compute!"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1000 add 2000 is"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" c"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Add")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive is a function executed after revival.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// boot")]),t._v("\n\tc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Compute")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Executing the above code will yield the following result:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("Revive github.com/gone-io/gone/heaven\nRevive github.com/gone-io/gone/cemetery\nRevive main/Computer\nRevive main/Adder\nI want to compute"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2000")]),t._v(" is "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3000")]),t._v("\n")])])]),n("h3",{attrs:{id:"the-gone-command-automatically-generating-priest-functions"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#the-gone-command-automatically-generating-priest-functions"}},[t._v("#")]),t._v(" The gone Command: Automatically Generating "),n("code",[t._v("Priest")]),t._v(" Functions")]),t._v(" "),n("p",[t._v("In fact, we've already covered the core functionality of the Gone framework. However, due to limitations in Golang itself, we can't achieve the same level of convenience as Spring, where all "),n("strong",[n("code",[t._v("Goners")])]),t._v(" need to be manually "),n("strong",[t._v("buried")]),t._v(" (**"),n("code",[t._v("Bury")]),t._v("**ed) into the "),n("strong",[n("code",[t._v("Cemetery")])]),t._v(". To make Gone easier to use, we've developed a utility tool to automatically generate "),n("strong",[n("code",[t._v("Priest")])]),t._v(" functions. Below, we'll explain how to use this utility tool in a project.")]),t._v(" "),n("blockquote",[n("p",[t._v("You can find the complete code "),n("a",{attrs:{href:"https://github.com/gone-io/gone/blob/main/example/gen-code",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),n("OutboundLink")],1)])]),t._v(" "),n("h4",{attrs:{id:"_1-install-the-utility-tool-gone"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_1-install-the-utility-tool-gone"}},[t._v("#")]),t._v(" 1. Install the Utility Tool: gone")]),t._v(" "),n("p",[t._v("The utility tool, also named gone, can be installed using "),n("code",[t._v("go install")]),t._v(" as follows:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),n("p",[t._v("For more information on using the gone command, please refer to the "),n("a",{attrs:{href:"https://goner.fun/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gone utility tool documentation"),n("OutboundLink")],1),t._v(".")]),t._v(" "),n("h4",{attrs:{id:"_2-create-a-new-project-named-gen-code"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_2-create-a-new-project-named-gen-code"}},[t._v("#")]),t._v(" 2. Create a New Project Named "),n("code",[t._v("gen-code")])]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" gen-code\n"),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" gen-code\ngo mod init gen-code\n")])])]),n("h4",{attrs:{id:"_3-create-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_3-create-goners"}},[t._v("#")]),t._v(" 3. Create Goners")]),t._v(" "),n("p",[t._v("File: goner.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewAdder")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewComputer")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Adder "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Add")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a2 "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" a1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" a2\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Computer "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tadder Adder "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Compute")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I want to compute!"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1000 add 2000 is"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" c"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Add")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive is a function executed after revival.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// boot")]),t._v("\n\tc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Compute")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the code above, please note that we've added two factory functions "),n("code",[t._v("NewAdder() gone.Goner")]),t._v(" and "),n("code",[t._v("func NewComputer() gone.Goner")]),t._v(", and we've put a special comment before the functions:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n")])])]),n("p",[t._v("Please do not remove this comment, as it tells the utility tool how to generate the code.")]),t._v(" "),n("h4",{attrs:{id:"_4-use-the-utility-tool"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_4-use-the-utility-tool"}},[t._v("#")]),t._v(" 4. Use the Utility Tool")]),t._v(" "),n("p",[t._v("Please execute the following command in the "),n("code",[t._v("gen-code")]),t._v(" directory:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("gone priest "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-s")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-p")]),t._v(" main "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" Priest "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" priest.go\n")])])]),n("p",[t._v("This command scans the current directory and generates a "),n("strong",[t._v("priest")]),t._v(" function with the function name "),n("code",[t._v("Priest")]),t._v(", in the package named "),n("code",[t._v("main")]),t._v(", and puts the code in a file named "),n("code",[t._v("priest.go")]),t._v(".\nAfter executing the command, a file named "),n("code",[t._v("priest.go")]),t._v(" will be generated in the current directory with the following content:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Code generated by gone; DO NOT EDIT.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewAdder")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewComputer")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h4",{attrs:{id:"_5-add-a-main-function"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_5-add-a-main-function"}},[t._v("#")]),t._v(" 5. Add a "),n("code",[t._v("main")]),t._v(" Function")]),t._v(" "),n("p",[t._v("File: main.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Now, we've completed the entire small Gone program. Its file structure is as follows:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(".")]),t._v("\n├── go.mod\n├── go.sum\n├── goner.go "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Definition of goners")]),t._v("\n├── main.go\n└── priest.go "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Generated code")]),t._v("\n")])])]),n("p",[t._v("You can run the program using the command "),n("code",[t._v("go run .")]),t._v(", and the program will output the following:")]),t._v(" "),n("div",{staticClass:"language-code extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("Revive github.com/gone-io/gone/heaven\nRevive github.com/gone-io/gone/cemetery\nRevive main/Adder\nRevive main/Computer\nI want to compute!\n1000 add 2000 is 3000\n")])])]),n("h2",{attrs:{id:"anonymous-injection-vs-named-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#anonymous-injection-vs-named-injection"}},[t._v("#")]),t._v(" Anonymous Injection vs Named Injection")]),t._v(" "),n("p",[t._v("In the preceding sections, all of our examples have demonstrated anonymous injection by type. When injecting anonymously, if there are multiple "),n("strong",[n("code",[t._v("Goners")])]),t._v(" of the same type, only one will be injected, typically the first one that was revived. Gone also supports named injection, or "),n("strong",[t._v("named burial")]),t._v(".")]),t._v(" "),n("p",[t._v("Firstly, let's take a look at the complete definition of the "),n("strong",[n("code",[t._v("Cemetery.Bury")])]),t._v(" function: "),n("strong",[n("code",[t._v("Bury(Goner, ...GonerId) Cemetery")])]),t._v(". This definition serves two purposes:")]),t._v(" "),n("ol",[n("li",[t._v("It supports named burial, where the second parameter is optional, allowing you to pass a string as the "),n("strong",[t._v("ID")]),t._v(" ("),n("strong",[t._v("GonerId")]),t._v(") of the "),n("strong",[t._v("Goner")]),t._v(".")]),t._v(" "),n("li",[t._v("It supports chaining of the Bury function.")])]),t._v(" "),n("h3",{attrs:{id:"named-burial"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#named-burial"}},[t._v("#")]),t._v(" Named Burial")]),t._v(" "),n("p",[t._v("To achieve named burial, our code can be written like this:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Priest Responsible for putting Goners that need to be used into the framework")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Burial of the first AGoner, ID=A1")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Burial of the second AGoner, ID=A2")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Alternatively, you can decouple the construction of Goners from their burial like this:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA1 constructs A1 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA2 constructs A2 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Priest Responsible for putting Goners that need to be used into the framework")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Next is the named injection within structs, which can be better understood with an example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Tell the framework that this struct is a Goner")]),t._v("\n\ta "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Anonymous injection of an AGoner")]),t._v("\n\ta1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection of A1")]),t._v("\n\ta2 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A2"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection of A2")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Note: In the code above, the tag after the struct field:")]),t._v(" "),n("ul",[n("li",[n("code",[t._v('gone:"*"')]),t._v(" denotes anonymous injection.")]),t._v(" "),n("li",[n("code",[t._v('gone:"A1"')]),t._v(" denotes injection with the ID "),n("code",[t._v("A1")]),t._v(".")])]),t._v(" "),n("p",[t._v("In Go, whether anonymous or named, the "),n("strong",[t._v("Goner")]),t._v(" to be injected must be type-compatible; otherwise, the injection will fail.")]),t._v(" "),n("h2",{attrs:{id:"pointer-injection-value-injection-and-interface-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#pointer-injection-value-injection-and-interface-injection"}},[t._v("#")]),t._v(" Pointer Injection, Value Injection, and Interface Injection")]),t._v(" "),n("p",[t._v("If the property of the injected struct is a pointer, then the injection is called "),n("strong",[t._v("pointer injection")]),t._v(". The definitions for "),n("strong",[t._v("value injection")]),t._v(" and "),n("strong",[t._v("interface injection")]),t._v(" are similar. Let's take an example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" AGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Tell the framework that this struct is a Goner")]),t._v("\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I am the AGoner, My name is"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Speaker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Tell the framework that this struct is a Goner")]),t._v("\n\ta0 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Anonymous injection of an AGoner; pointer injection")]),t._v("\n\ta1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection of A1; pointer injection")]),t._v("\n\n\ta2 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Value injection")]),t._v("\n\ta3 Speaker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A2"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Interface injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the code above, "),n("code",[t._v("BGoner.a0")]),t._v(" and "),n("code",[t._v("BGoner.a1")]),t._v(" are subjected to "),n("strong",[t._v("pointer injection")]),t._v(". "),n("code",[t._v("BGoner.a2")]),t._v(" is subjected to "),n("strong",[t._v("value injection")]),t._v(", while "),n("code",[t._v("BGoner.a3")]),t._v(" is subjected to "),n("strong",[t._v("interface injection")]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("A special note:")]),t._v(' In Go, "assigning or passing a value type involves making a copy." This means that when using '),n("strong",[t._v("value injection")]),t._v(', a new "object" is actually created, and the new and old objects are only equal at the moment of transfer. They are independent in memory. This can lead to some unexpected results. For example:')]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\ta1 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Value injection")]),t._v("\n\ta2 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Value injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dapeng"')]),t._v("\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"wang"')]),t._v("\n\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a1 is eq a2: %v"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the code above, "),n("code",[t._v("BGoner.a1")]),t._v(" and "),n("code",[t._v("BGoner.a2")]),t._v(" are both injected with the same Goner ("),n("code",[t._v("A1")]),t._v("). However, since it's "),n("strong",[t._v("value injection")]),t._v(", during the injection process, the framework can only copy the value of "),n("code",[t._v("A1")]),t._v(" Goner to "),n("code",[t._v("BGoner.a1")]),t._v(" and "),n("code",[t._v("BGoner.a2")]),t._v(". After injection, "),n("code",[t._v("BGoner.a1")]),t._v(" and "),n("code",[t._v("BGoner.a2")]),t._v(" have no connection with "),n("code",[t._v("A1")]),t._v(", and there's no connection between "),n("code",[t._v("BGoner.a1")]),t._v(" and "),n("code",[t._v("BGoner.a2")]),t._v(". There will also be three separate spaces in memory occupied by "),n("code",[t._v("AGoner")]),t._v(" type. The result of "),n("code",[t._v('fmt.Printf("a1 is eq a2: %v", g.a1 == g.a2)')]),t._v(" will be "),n("code",[t._v("false")]),t._v(".")]),t._v(" "),n("blockquote",[n("p",[t._v("Considering that "),n("strong",[t._v("Gone")]),t._v(" is primarily intended as a foundational framework, we have retained the "),n("strong",[t._v("value injection")]),t._v(" feature. However, in most cases, we recommend using "),n("strong",[t._v("pointer injection")]),t._v(" and "),n("strong",[t._v("interface injection")]),t._v(".")])]),t._v(" "),n("h3",{attrs:{id:"pointer-injection-vs-interface-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#pointer-injection-vs-interface-injection"}},[t._v("#")]),t._v(" Pointer Injection vs Interface Injection")]),t._v(" "),n("p",[t._v("During the Bury process of "),n("strong",[t._v("Goner")]),t._v(", it's required to pass a reference. This means that the first parameter of the "),n("code",[t._v("Cemetery.Bury")]),t._v(" method must be of a reference type. Both pointer injection and interface injection can pass the reference of "),n("strong",[t._v("Bury")]),t._v(" to the properties of a struct. "),n("strong",[t._v("Pointer injection")]),t._v(" is straightforward and intuitive, with a one-to-one correspondence between types, requiring little explanation.")]),t._v(" "),n("p",[t._v("Interfaces are one of the most essential designs in Go. Their purpose is to decouple the business usage from the implementation logic, allowing users of the interface to not be concerned with the implementation details. Another purpose of interfaces is to break circular dependencies. If two modules have a circular reference and they are in different packages, it violates the rule of no circular dependencies in Go, leading to compilation failure. We can use interfaces to break this circular dependency.")]),t._v(" "),n("p",[t._v("Circular dependency:\n"),n("img",{attrs:{src:a(256),alt:"Circular dependency"}})]),t._v(" "),n("p",[t._v("Using interfaces to break circular dependency:\n"),n("img",{attrs:{src:a(257),alt:"Using interfaces to break circular dependency"}})]),t._v(" "),n("p",[t._v('Using interfaces can hide the implementation details of business logic, effectively reducing the coupling between modules and better adhering to the "open-closed" principle. Therefore, we recommend using '),n("strong",[t._v("interface injection")]),t._v(". However, there are no absolutes in everything, introducing interfaces will certainly increase additional costs, so we still support "),n("strong",[t._v("pointer injection")]),t._v(".")]),t._v(" "),n("h2",{attrs:{id:"slice-injection-and-map-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#slice-injection-and-map-injection"}},[t._v("#")]),t._v(" Slice Injection and Map Injection")]),t._v(" "),n("p",[t._v("Gone supports injection into "),n("code",[t._v("Slice")]),t._v(" and "),n("code",[t._v("Map")]),t._v(", meaning it supports the following syntax:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n aSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a slice of Goner pointers")]),t._v("\n aSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a slice of Goner values")]),t._v("\n\n aMap1 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a map of Goner pointers")]),t._v("\n aMap2 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a map of Goner values")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[n("strong",[t._v("The rules for injection are as follows:")])]),t._v(" "),n("ul",[n("li",[n("ol",[n("li",[t._v("The element type of Slice and Map can be Goner pointer type or Goner value type, or an interface.")])])]),t._v(" "),n("li",[n("ol",{attrs:{start:"2"}},[n("li",[t._v("Gone will inject all types compatible with Goner into Slice and Map.")])])]),t._v(" "),n("li",[n("ol",{attrs:{start:"3"}},[n("li",[t._v("The type of Map key can only be string.")])])]),t._v(" "),n("li",[n("ol",{attrs:{start:"4"}},[n("li",[t._v("The value of Map key is the GonerId of the injected Goner. If no GonerId is specified when burying an anonymous Goner, Gone will generate one automatically.")])])])]),t._v(" "),n("div",{staticClass:"custom-block warning"},[n("p",{staticClass:"custom-block-title"},[t._v("WARNING")]),t._v(" "),n("p",[t._v("Using values as the element types for Slice and Map is not recommended.")])]),t._v(" "),n("p",[t._v("Here's a complete example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" AGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Tell the framework that this struct is a Goner")]),t._v("\n Name "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sprintf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I am the AGoner, My name is: %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n aSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a slice of Goner pointers")]),t._v("\n aSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a slice of Goner values")]),t._v("\n\n aMap1 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a map of Goner pointers")]),t._v("\n aMap2 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a map of Goner values")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive executed After the Goner is revived; After `gone.Run`, gone framework detects the AfterRevive function on goners and runs it.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aSlice1:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aSlice2:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aMap1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aMap1[%s]:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aMap2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aMap2[%s]:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA1 creates A1 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA2 creates A2 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Anonymous"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The example yields the following result upon execution:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("Revive github.com/gone-io/gone/heaven\nRevive github.com/gone-io/gone/cemetery\nRevive main/AGoner\nRevive main/AGoner\nRevive main/AGoner\nRevive main/BGoner\naSlice1:I am the AGoner, My name is: Injected Goner1\naSlice1:I am the AGoner, My name is: Anonymous\naSlice1:I am the AGoner, My name is: Injected Goner2\n\naSlice2:I am the AGoner, My name is: Injected Goner1\naSlice2:I am the AGoner, My name is: Anonymous\naSlice2:I am the AGoner, My name is: Injected Goner2\n\naMap1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("A1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":I am the AGoner, My name is: Injected Goner1\naMap1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("main/AGoner"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#1374393662624]:I am the AGoner, My name is: Anonymous")]),t._v("\naMap1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("A2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":I am the AGoner, My name is: Injected Goner2\n\naMap2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("A2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":I am the AGoner, My name is: Injected Goner2\naMap2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("A1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":I am the AGoner, My name is: Injected Goner1\naMap2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("main/AGoner"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#1374393662624]:I am the AGoner, My name is: Anonymous")]),t._v("\n")])])]),n("h3",{attrs:{id:"private-property-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#private-property-injection"}},[t._v("#")]),t._v(" Private Property Injection")]),t._v(" "),n("p",[t._v('Following the "Open-Closed Principle," attributes that modules depend on should ideally be private. Gone supports injecting into private variables of a struct.')]),t._v(" "),n("h2",{attrs:{id:"configuration-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-injection"}},[t._v("#")]),t._v(" "),n("RouterLink",{attrs:{to:"/guide/guide/config.html"}},[t._v("Configuration Injection")])],1)])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[23],{256:function(t,n){t.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjQAAAEECAYAAAA/Ga4zAAAACXBIWXMAAAsTAAALEwEAmpwYAAATvElEQVR4nO3df2xV9f3H8dfBhrnGGoxyGzI7wWsaQEGjoriB3NsoIERBScC4gEaUZR31By5kEKX3opFA5owTpoKIWAUEf26ZEwRaNgzLUJdmVsFCW7ZC2sqAjXUtUPh8/yD3fCk/SpH2nvs+9/lIbtJy7z3n3Hs/HJ587qe3nnPOCQAAwLAeQR8AAADA+SJoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeYEFTTwel+d5GXuJx+NBPTUAQohzHtC9POecC2THnqeAdt0pmX58AGzJ9HNKph8fcDa85QQAAMwjaAAAgHkEDQAAMI+gAQAA5hE0AADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMwjaAAAgHkEDQAAMI+gAQAA5uUEteO+ffvK87ygdt8pmX58OD+xWEzl5eVBHwayBOc8BC3s5zx+2zayFmMQ6cR4Q9DCPgZ5ywkAAJhH0AAAAPMIGgAAYF4ogyaZTMrzPP3tb38L+lAAoNsFdc779ttv5XmeJk2alNb9AqcTyqA5fPiwJIV68RMApAR1zkvt7+jRo2ndL3A6gQfN5s2bNWzYMC1YsED33HOPotGoZs2a5f8F3bhxo4YNG6b8/HyNGTNGZWVl7e576623Kj8/Xw888ID+9Kc/nbL9f/7znxozZozGjBmj+vr6Drf33nvv6dprr1VBQYFeeeUVDRs2TM8995wkqbKyUiNHjtTFF1+seDyuzZs3n/bxdLR9AAjbOU+S9u/frylTpqigoEATJ05UQ0NDVz1dQOe5gKR2/eGHHzpJTpIrLCz0v3722Wdda2ury8vLc5LcxIkT/a+rq6vdP/7xD/+2Q4cO9b9uampys2fPdpJcRUWFu/76650k98Ybb3S4vcbGRn8bAwcO9L8uLi52+/fv9297++23+9dVV1e3e0wdbR+ZJ8DhjywUxnPeiduIRCIuEok4Se7+++8P4BnG2YT9nBf4DE3KhAkTtH37dm3atEmS9Oabb2rfvn2aOXOmPvjgA82ZM0fXXXedJGnXrl1atWqVJOlXv/qVtmzZot/85jcaNWqUdu3a5W/zwQcf1BdffKFEIqHJkyd3uL2NGzdKkp5//nlVVVVp3rx5/nb+8Ic/6ODBgyopKdHrr7+up59+WpL0zjvvtHsMHW0fAE4UhnNeSiQSUW1trWpqahSJRPTee++pra2ti58xoGOBfVLwyWKxmCRp+PDhko5Pm0YiETU2Nuqpp5465fZ1dXWSpOuvv16SVFJSopKSEknS+++/L0mqqalpd5+Otpeaur3lllvaHY/0/0Hy4osv6sUXXzzlzzuzfQA4URjOeSk//vGPlZubK0m6+eab9fvf/17V1dUaMGDAGR490PUyZoZmy5YtkqQ9e/ZIkvr06aMPP/xQCxcu1J133qnq6moVFxf7tx84cKCk47MikrRu3TrNnTtXO3bs8G8zefJkSVIikdCuXbs63N6gQYMkSdXV1ZKkqqoq/7rLLrtMkjR9+nR99dVXqqys1KeffqqZM2e2ewwdbR8AThSGc15KZWWl/3VqO9Fo9JyfE+B8ZMwMzYoVKzRgwAD97ne/kySNGjXKXznfp08fff311/5iNuecRo4cKUmaM2eOGhoaNHfuXDU1Nemxxx7zt/nYY49pwIABmj17tmbPnq3x48efcXujR4+WJBUXF2v9+vVavny5v50f/ehHkqTVq1frhhtu0IoVK/TJJ5/o3XffVb9+/fzbdXS8AHCiMJzzUmpqajRp0iTl5uaqpqZG48aNU8+ePbv0+QLOKqjFOzppgVxqIZskN2TIENfQ0OCam5vd4MGD/T8fO3ask+Tmz5/vnHNu+vTp/nWS3MqVK51zzl8g9/nnn7v//ve//kK18vLyDrc3f/58l5eX5yKRiJswYYKT5EpKSpxzzr355pvt7jt9+nTX1tbW7jGd7XiRWQIc/shCYTznNTU1+YubU/uMRCJu69at6XpacQ7Cfs7LmKBZuHCha2lpcfX19afctq6uzh0+fPi029m3b5+rqqpyra2tnd736bZXWVnpXnrpJbdlyxbX1tbmFixY4CS5V155pd3tdu7c6Q4cOHDO20fmCftfbmSWMJ/znHPu6NGjrr6+/pToQeYI+zkvY95ykqQLL7xQP/jBD0758yuuuOKM97nkkkt0ySWXnNN+Tre9/Px8zZw5UwcPHlQkElFTU5Py8vJUVFTU7nZXXnnld9o+AJwsLOc8SerRo8dpHwuQLp5zwSzwSP0a8+3bt+vdd9/V7bffriFDhgRxKL6amhpt2rRJ27ZtU9++fTV27Fj98Ic/DPSY0H1SYxBIB855CFrYz3mBBw0QFMYg0onxhqCFfQxmzI9tAwAAfFcEDQAAMI+gAQAA5hE0AADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMzLqF99gM5JJBJKJpNBH0YoeJ4X9CEgizDeulaYPyQO544ZGgAAYB4zNIaVlpYqkUgEfRhmhf1jwJFZGG9dh5kunA4zNAAAwDyCBgAAmEfQAAAA8wgaAABgHkEDAADMI2gyXEVFRdCHAABAxiNoDPA876w/nl1RUaF4PM6PcQMAshJBk+FisZhisZiSyeRpwyYVMvF4XCNGjCBoAABZyXMBfdITHzLVealoOVnfvn1VV1fnf88H7Z0bxiDSifHWdVIfrMfzeW7CPgYJGiPi8XiH62mImXPHGEQ6Md66DkHz3YR9DPKWkxGlpaVBHwIAABmLoDEitZbmdJidAQBkO345pSGlpaX8GDeA08rGX9iYbY85zG8XdQXW0Bhz8loaZme+O8Yg0qm7xxvjOdy64vUN+xjhLSdjWEsDAMCpCBpjTlxLw+wMAADHETQGMUsDAEB7rKExqqKi4ow/9YTOYQwinVhDg/PBGpqzC80MTepXA2TLJR6PB34M6b4kk8mghxkAIEOFJmgkKZFIyDnHJYQX1goBADoSqqABAADZiaABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNACBjHDt2THV1ddq7d2/QhwJjCBoAQLe7+OKL5XmefykoKNDcuXN17NgxSZJzTkuXLlWvXr3Ur18/9e7dW9FoVG+//XbARw4rCBoAQFqUlZVp//79amho0OzZs1VaWqotW7ZIkt566y099NBDKisr05EjR7R3715NmzZN9957rz777LOAjxwWEDQAgLS46KKL1KtXL+Xn5+vuu++WJDU3N0uSnnjiCc2fP1/jxo1TTk6OLr30Us2cOVNPPfWUdu/eLUk6evSonnnmGRUUFCg/P18zZsxQS0uLWltbddNNN2np0qW6+uqrFY1G9eqrr/r7/etf/6pbb71V+fn5mjJliv71r39JkpYtW6Y5c+Zo6tSp+ulPf5rmZwNdjaABAKTFunXrtGzZMi1atEg/+clPVFhYqBEjRqixsVFNTU267bbb/NsePnxYR44c0ZNPPqmxY8dKkl577TUtWLBAv/zlL7VmzRqtWbNGzz77rI4dO6atW7dqwYIFev755xWPx/Xwww+rtbVVjY2Nuvnmm3XddddpzZo12rdvnx9Te/bs0dNPP63du3fr3nvvDeQ5QdfJCfoAAADZ4dNPP1VdXZ3a2tr05ZdfqmfPnqqtrVVLS4uk4+tsJGnnzp266qqr/PsVFRVpw4YNWrJkiR599FH9/Oc/lySVlpYqmUxq1qxZkqSXX35Z8Xhct9xyi5YuXaq6ujp9/PHHuvzyy/XCCy/I8zzl5+erf//+amhokCRFIhF99NFH6tGD/99bxyuYgVjlDyCMksmkPvroI61bt067d+/WoEGDtHjxYvXp00eS/LUyV1xxhXbs2KEdO3aouLjYv/+2bdt04403+t/369dP9fX1/vcFBQWSpLy8PEnSoUOHtHPnTtXX16tHjx7yPE/9+/eXJP/8ettttxEzIcGrGIBf/OIX8jzvlIVurPIHkC1ycnI0aNAgVVZWKj8/X3l5eSovL/evi0ajikaj2rZtm3+fG264oV3AfPPNNxo1apT//QUXXHDKfnr16qUhQ4aoublZzc3NOnDggDZv3qzCwsJufHQIAkGTZkeOHNHixYuVl5en1atXt7uOVf4Awqy+vl7bt29XVVWV5s2bp5deekl33XWXPM/TvHnztHjxYq1Zs0YtLS2qqqrS448/ro0bN/r3Hz9+vJYvX66amhodPnxYK1eu1OjRozvc5/Dhw7V161Z99tln8jxPL7zwgu655x5mZUKIVzTN1q9fr+9///v69a9/reXLl6utrc2/jlX+AMKspKRE/fv31zXXXKPf/va3Ki4u1s9+9jNJ0rRp0zRr1ixNnDhRubm5uuaaa/SXv/xFZWVl/szLpEmTdOjQIUWjUX3ve99Ta2ur7rvvvjPuz/M8jRw5UjNmzNCIESOUm5urRYsWaeXKlcrJyZHneYRNmLiAdPWuE4mESyQSXbrN7nDfffe5J554wu3du9dJchs2bHDOOdfQ0OAkuc8//9y/7aFDh/zLkSNHnHPOLV682OXl5bmFCxe6TZs2ucsvv9w9+eSTrrm52UlyhYWFbu3atW7q1KlOkmtpafG3XVJS4jZt2uTGjh3rhg8f7pxz7plnnnGS3KhRo9zGjRvT/4R0Une8vgEOf2Sh7h5vYRnPzc3N7ssvv3T//ve/T3t9W1ubq66udrt27XLHjh3r9Habmprc3//+d9fS0tJVh5pWXfH6hmWMnAk/5ZRGBw4c0IoVK7R161ZdeumluuOOO7Rq1SoVFRVpz549kljlDyC75ebm6uqrrz7j9RdccEG7c2Nn9e7dW7179z6fQ0OG41+wNHr//fclHZ82jUaj+uMf/6hVq1appaWFVf4AAJwH/hVLo2XLlmnq1KlasmSJlixZorVr1+rgwYNau3Ytq/wBADgPBE2a1NbW6s9//rMeeeQRFRUVqaioSCNHjtS4ceO0YsUKVvkDAHAeWEOTJqtXr1ZhYaEGDx7c7s8nTJigKVOm6D//+Y+mTZum3bt3a+LEif71Q4cOVVlZmd544w1Jx9+ueu211xSNRiVJQ4YMOadV/tLxNTOs8gcAhInnnHOB7Njz1JW7TiaTko4vkrXuf//7n2pra1VQUOAvEj7R0aNHVVtbq549e6qgoECe53Vqu99++60aGxt11VVX6cILL+zqw+5W3fH6dvUYBDrS3eON8RxuXfH6hn2MMEOTgVjlDwDAueG9BgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzMsJ+gAAAF3D87ygDwEIDEEDACHgnAv6ENImHo9rxIgRSiQSQR8KMghBAwAwo6Kiwr9IImrgYw0NAMCMZDIZ9CEgQxE0AAATTpyZkY7HDTM0SCFoAAAmMDuDjoQqaBKJhDzP4xLCC/8LA7LbybMzKczSICU0QVNaWirnXFZcSktLs+4xn/i4AWQfZmdwNqEJGgBAOJ1pdiaFWRpIBA0AIMMxO4POIGgAABnrxNmZ1NvsKeXl5YrFYpKYpQFBAwDIYMlk0g+Zk4MlFoupvLy8Xdgge/FJwQCAjFVeXn7W28RiMcViMX82h7jJTgQNACAUCJnsxltOAADAPIIGAACYR9AAAADzCBoAAGAeQQMAAMzjp5wMSyaTfILmefI8L+hDQBZhvAHdhxkaAABgnudO/BzpdO7Y8xTQrgFJjEGkF+MNQQv7GGSGBgAAmEfQAAAA8wgaAABgHkEDAADMI2gAAIB5BA0AADCPoAEAAOYRNAAAwDyCBgAAmEfQAAAA8wgaAABgHkEDAADMI2gAAIB5BA0AADCPoAEAAOblBLXjWCwmz/OC2j2gWCwW9CEgi3DOQ9DCfs7znHMu6IMAAAA4H7zlBAAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPMIGgAAYB5BAwAAzCNoAACAeQQNAAAwj6ABAADmETQAAMA8ggYAAJhH0AAAAPP+D7qGTX8Q8og4AAAAAElFTkSuQmCC"},257:function(t,n,a){t.exports=a.p+"assets/img/image7.ca08b1e7.png"},318:function(t,n,a){"use strict";a.r(n);var s=a(10),e=Object(s.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h2",{attrs:{id:"goner-and-dependency-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#goner-and-dependency-injection"}},[t._v("#")]),t._v(" Goner and Dependency Injection")]),t._v(" "),n("h3",{attrs:{id:"definition-of-goner"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#definition-of-goner"}},[t._v("#")]),t._v(" Definition of Goner")]),t._v(" "),n("p",[t._v('In the Gone application, all components are required to be defined as Goners (i.e., structures that "inherit" '),n("code",[t._v("gone.Flag")]),t._v(', although Go does not have the concept of "inheritance" as seen in other languages; instead, it uses anonymous embedding). If a property of a Goner is tagged with the '),n("code",[t._v('gone:""')]),t._v(" tag, the Gone framework will attempt to automatically wire this property. Here's an example of defining a Goner:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" example\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" AGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Injecting the above-defined AGoner into another Goner:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" example\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n A "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The purpose of the gone tag is to inform Gone that this property needs to be automatically injected with a value")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In this example, both the injected and the injecting structures must be "),n("code",[t._v("Goner")]),t._v(" (i.e., structures embedded with "),n("code",[t._v("gone.Flag")]),t._v("). The "),n("code",[t._v('gone:"*"')]),t._v(" tag on the "),n("code",[t._v("A")]),t._v(" property of the "),n("code",[t._v("BGoner")]),t._v(" tells the framework that this property needs to be injected with a value.")]),t._v(" "),n("h3",{attrs:{id:"how-dependency-injection-is-achieved-in-gone"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#how-dependency-injection-is-achieved-in-gone"}},[t._v("#")]),t._v(" How Dependency Injection is Achieved in Gone")]),t._v(" "),n("p",[t._v("In Java Spring, classes are annotated with "),n("code",[t._v("@Component")]),t._v(", "),n("code",[t._v("@Service")]),t._v(", etc., and during Spring startup, these specially annotated classes are automatically scanned, instantiated, and their annotated properties injected with corresponding values.")]),t._v(" "),n("p",[t._v("The reason Spring can achieve this functionality lies in a critical feature of Java: after Java code is compiled into a JAR file, all class bytecode is preserved, even for classes not directly dependent on the "),n("code",[t._v("main")]),t._v(" function. However, in Go, the compiled code is pruned, and only the code relevant to the "),n("code",[t._v("main")]),t._v(" function is retained in the binary. Therefore, if we merely define Goners, we'll find that our Goner code has been pruned.")]),t._v(" "),n("p",[t._v('How do we prevent our Goners from being pruned? The answer is simple: explicitly add all Goners to a "repository". In Gone, this repository is called the '),n("code",[t._v("Cemetery")]),t._v(". "),n("code",[t._v("Goner")]),t._v(' means "deceased", and '),n("code",[t._v("Cemetery")]),t._v(" is the graveyard used to bury (Bury) Goners. We can instantiate all Goners and add them to the Cemetery at program startup:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("example"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("example"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the above code, we see that "),n("code",[t._v("gone.Run")]),t._v(" can accept a function in the form of "),n("strong",[n("code",[t._v("func (cemetery gone.Cemetery) error")])]),t._v(". In practice, this function, which we call "),n("strong",[t._v("Priest")]),t._v(", is responsible for burying Goners in the cemetery.")]),t._v(" "),n("h3",{attrs:{id:"how-to-execute-business-code-in-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#how-to-execute-business-code-in-goners"}},[t._v("#")]),t._v(" How to Execute Business Code in Goners?")]),t._v(" "),n("p",[t._v("In Gone, we've made an interesting definition: when all properties of a Goner are injected, we say that this Goner has been resurrected (Revive). If you look at the source code of Gone, you'll find that the component responsible for managing the revived Goner status is called "),n("strong",[t._v("Heaven")]),t._v(", inspired by the mythical belief across religions that people ascend to heaven after death.")]),t._v(" "),n("p",[t._v("To execute business code in Goners, we can define a method on Goners called "),n("strong",[n("code",[t._v("AfterRevive() gone.AfterReviveError")])]),t._v(". This method is executed after a Goner is "),n("strong",[t._v("Revived")]),t._v(", and Goners possessing this method are called "),n("strong",[t._v("Prophets")]),t._v(". In practice, we typically only need to define a small number of prophets to guide code execution.")]),t._v(" "),n("p",[t._v("Here's an example; you can find the code "),n("a",{attrs:{href:"https://github.com/gone-io/gone/blob/main/example/after-revive/main.go",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),n("OutboundLink")],1),t._v(":")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Adder "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Add")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a2 "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" a1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" a2\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Computer "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tadder Adder "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Compute")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I want to compute!"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1000 add 2000 is"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" c"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Add")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive is a function executed after revival.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// boot")]),t._v("\n\tc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Compute")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Executing the above code will yield the following result:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("Revive github.com/gone-io/gone/heaven\nRevive github.com/gone-io/gone/cemetery\nRevive main/Computer\nRevive main/Adder\nI want to compute"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2000")]),t._v(" is "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3000")]),t._v("\n")])])]),n("h3",{attrs:{id:"the-gone-command-automatically-generating-priest-functions"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#the-gone-command-automatically-generating-priest-functions"}},[t._v("#")]),t._v(" The gone Command: Automatically Generating "),n("code",[t._v("Priest")]),t._v(" Functions")]),t._v(" "),n("p",[t._v("In fact, we've already covered the core functionality of the Gone framework. However, due to limitations in Golang itself, we can't achieve the same level of convenience as Spring, where all "),n("strong",[n("code",[t._v("Goners")])]),t._v(" need to be manually "),n("strong",[t._v("buried")]),t._v(" (**"),n("code",[t._v("Bury")]),t._v("**ed) into the "),n("strong",[n("code",[t._v("Cemetery")])]),t._v(". To make Gone easier to use, we've developed a utility tool to automatically generate "),n("strong",[n("code",[t._v("Priest")])]),t._v(" functions. Below, we'll explain how to use this utility tool in a project.")]),t._v(" "),n("blockquote",[n("p",[t._v("You can find the complete code "),n("a",{attrs:{href:"https://github.com/gone-io/gone/blob/main/example/gen-code",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),n("OutboundLink")],1)])]),t._v(" "),n("h4",{attrs:{id:"_1-install-the-utility-tool-gone"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_1-install-the-utility-tool-gone"}},[t._v("#")]),t._v(" 1. Install the Utility Tool: gone")]),t._v(" "),n("p",[t._v("The utility tool, also named gone, can be installed using "),n("code",[t._v("go install")]),t._v(" as follows:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),n("p",[t._v("For more information on using the gone command, please refer to the "),n("a",{attrs:{href:"https://goner.fun/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gone utility tool documentation"),n("OutboundLink")],1),t._v(".")]),t._v(" "),n("h4",{attrs:{id:"_2-create-a-new-project-named-gen-code"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_2-create-a-new-project-named-gen-code"}},[t._v("#")]),t._v(" 2. Create a New Project Named "),n("code",[t._v("gen-code")])]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" gen-code\n"),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" gen-code\ngo mod init gen-code\n")])])]),n("h4",{attrs:{id:"_3-create-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_3-create-goners"}},[t._v("#")]),t._v(" 3. Create Goners")]),t._v(" "),n("p",[t._v("File: goner.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewAdder")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewComputer")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Adder "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Add")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a2 "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" a1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" a2\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Computer "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tadder Adder "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Compute")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I want to compute!"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1000 add 2000 is"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" c"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("adder"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Add")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive is a function executed after revival.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Computer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// boot")]),t._v("\n\tc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Compute")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the code above, please note that we've added two factory functions "),n("code",[t._v("NewAdder() gone.Goner")]),t._v(" and "),n("code",[t._v("func NewComputer() gone.Goner")]),t._v(", and we've put a special comment before the functions:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n")])])]),n("p",[t._v("Please do not remove this comment, as it tells the utility tool how to generate the code.")]),t._v(" "),n("h4",{attrs:{id:"_4-use-the-utility-tool"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_4-use-the-utility-tool"}},[t._v("#")]),t._v(" 4. Use the Utility Tool")]),t._v(" "),n("p",[t._v("Please execute the following command in the "),n("code",[t._v("gen-code")]),t._v(" directory:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("gone priest "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-s")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-p")]),t._v(" main "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" Priest "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" priest.go\n")])])]),n("p",[t._v("This command scans the current directory and generates a "),n("strong",[t._v("priest")]),t._v(" function with the function name "),n("code",[t._v("Priest")]),t._v(", in the package named "),n("code",[t._v("main")]),t._v(", and puts the code in a file named "),n("code",[t._v("priest.go")]),t._v(".\nAfter executing the command, a file named "),n("code",[t._v("priest.go")]),t._v(" will be generated in the current directory with the following content:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Code generated by gone; DO NOT EDIT.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewAdder")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewComputer")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h4",{attrs:{id:"_5-add-a-main-function"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_5-add-a-main-function"}},[t._v("#")]),t._v(" 5. Add a "),n("code",[t._v("main")]),t._v(" Function")]),t._v(" "),n("p",[t._v("File: main.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Now, we've completed the entire small Gone program. Its file structure is as follows:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(".")]),t._v("\n├── go.mod\n├── go.sum\n├── goner.go "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Definition of goners")]),t._v("\n├── main.go\n└── priest.go "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Generated code")]),t._v("\n")])])]),n("p",[t._v("You can run the program using the command "),n("code",[t._v("go run .")]),t._v(", and the program will output the following:")]),t._v(" "),n("div",{staticClass:"language-code extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("Revive github.com/gone-io/gone/heaven\nRevive github.com/gone-io/gone/cemetery\nRevive main/Adder\nRevive main/Computer\nI want to compute!\n1000 add 2000 is 3000\n")])])]),n("h2",{attrs:{id:"anonymous-injection-vs-named-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#anonymous-injection-vs-named-injection"}},[t._v("#")]),t._v(" Anonymous Injection vs Named Injection")]),t._v(" "),n("p",[t._v("In the preceding sections, all of our examples have demonstrated anonymous injection by type. When injecting anonymously, if there are multiple "),n("strong",[n("code",[t._v("Goners")])]),t._v(" of the same type, only one will be injected, typically the first one that was revived. Gone also supports named injection, or "),n("strong",[t._v("named burial")]),t._v(".")]),t._v(" "),n("p",[t._v("Firstly, let's take a look at the complete definition of the "),n("strong",[n("code",[t._v("Cemetery.Bury")])]),t._v(" function: "),n("strong",[n("code",[t._v("Bury(Goner, ...GonerId) Cemetery")])]),t._v(". This definition serves two purposes:")]),t._v(" "),n("ol",[n("li",[t._v("It supports named burial, where the second parameter is optional, allowing you to pass a string as the "),n("strong",[t._v("ID")]),t._v(" ("),n("strong",[t._v("GonerId")]),t._v(") of the "),n("strong",[t._v("Goner")]),t._v(".")]),t._v(" "),n("li",[t._v("It supports chaining of the Bury function.")])]),t._v(" "),n("h3",{attrs:{id:"named-burial"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#named-burial"}},[t._v("#")]),t._v(" Named Burial")]),t._v(" "),n("p",[t._v("To achieve named burial, our code can be written like this:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Priest Responsible for putting Goners that need to be used into the framework")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Burial of the first AGoner, ID=A1")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Burial of the second AGoner, ID=A2")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Alternatively, you can decouple the construction of Goners from their burial like this:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA1 constructs A1 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA2 constructs A2 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Priest Responsible for putting Goners that need to be used into the framework")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Next is the named injection within structs, which can be better understood with an example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Tell the framework that this struct is a Goner")]),t._v("\n\ta "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Anonymous injection of an AGoner")]),t._v("\n\ta1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection of A1")]),t._v("\n\ta2 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A2"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection of A2")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Note: In the code above, the tag after the struct field:")]),t._v(" "),n("ul",[n("li",[n("code",[t._v('gone:"*"')]),t._v(" denotes anonymous injection.")]),t._v(" "),n("li",[n("code",[t._v('gone:"A1"')]),t._v(" denotes injection with the ID "),n("code",[t._v("A1")]),t._v(".")])]),t._v(" "),n("p",[t._v("In Go, whether anonymous or named, the "),n("strong",[t._v("Goner")]),t._v(" to be injected must be type-compatible; otherwise, the injection will fail.")]),t._v(" "),n("h2",{attrs:{id:"pointer-injection-value-injection-and-interface-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#pointer-injection-value-injection-and-interface-injection"}},[t._v("#")]),t._v(" Pointer Injection, Value Injection, and Interface Injection")]),t._v(" "),n("p",[t._v("If the property of the injected struct is a pointer, then the injection is called "),n("strong",[t._v("pointer injection")]),t._v(". The definitions for "),n("strong",[t._v("value injection")]),t._v(" and "),n("strong",[t._v("interface injection")]),t._v(" are similar. Let's take an example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" AGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Tell the framework that this struct is a Goner")]),t._v("\n\tName "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I am the AGoner, My name is"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Speaker "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Tell the framework that this struct is a Goner")]),t._v("\n\ta0 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Anonymous injection of an AGoner; pointer injection")]),t._v("\n\ta1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection of A1; pointer injection")]),t._v("\n\n\ta2 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Value injection")]),t._v("\n\ta3 Speaker "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A2"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Interface injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the code above, "),n("code",[t._v("BGoner.a0")]),t._v(" and "),n("code",[t._v("BGoner.a1")]),t._v(" are subjected to "),n("strong",[t._v("pointer injection")]),t._v(". "),n("code",[t._v("BGoner.a2")]),t._v(" is subjected to "),n("strong",[t._v("value injection")]),t._v(", while "),n("code",[t._v("BGoner.a3")]),t._v(" is subjected to "),n("strong",[t._v("interface injection")]),t._v(".")]),t._v(" "),n("p",[n("strong",[t._v("A special note:")]),t._v(' In Go, "assigning or passing a value type involves making a copy." This means that when using '),n("strong",[t._v("value injection")]),t._v(', a new "object" is actually created, and the new and old objects are only equal at the moment of transfer. They are independent in memory. This can lead to some unexpected results. For example:')]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\ta1 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Value injection")]),t._v("\n\ta2 AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"A1"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Value injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dapeng"')]),t._v("\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"wang"')]),t._v("\n\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a1 is eq a2: %v"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a1 "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("a2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("In the code above, "),n("code",[t._v("BGoner.a1")]),t._v(" and "),n("code",[t._v("BGoner.a2")]),t._v(" are both injected with the same Goner ("),n("code",[t._v("A1")]),t._v("). However, since it's "),n("strong",[t._v("value injection")]),t._v(", during the injection process, the framework can only copy the value of "),n("code",[t._v("A1")]),t._v(" Goner to "),n("code",[t._v("BGoner.a1")]),t._v(" and "),n("code",[t._v("BGoner.a2")]),t._v(". After injection, "),n("code",[t._v("BGoner.a1")]),t._v(" and "),n("code",[t._v("BGoner.a2")]),t._v(" have no connection with "),n("code",[t._v("A1")]),t._v(", and there's no connection between "),n("code",[t._v("BGoner.a1")]),t._v(" and "),n("code",[t._v("BGoner.a2")]),t._v(". There will also be three separate spaces in memory occupied by "),n("code",[t._v("AGoner")]),t._v(" type. The result of "),n("code",[t._v('fmt.Printf("a1 is eq a2: %v", g.a1 == g.a2)')]),t._v(" will be "),n("code",[t._v("false")]),t._v(".")]),t._v(" "),n("blockquote",[n("p",[t._v("Considering that "),n("strong",[t._v("Gone")]),t._v(" is primarily intended as a foundational framework, we have retained the "),n("strong",[t._v("value injection")]),t._v(" feature. However, in most cases, we recommend using "),n("strong",[t._v("pointer injection")]),t._v(" and "),n("strong",[t._v("interface injection")]),t._v(".")])]),t._v(" "),n("h3",{attrs:{id:"pointer-injection-vs-interface-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#pointer-injection-vs-interface-injection"}},[t._v("#")]),t._v(" Pointer Injection vs Interface Injection")]),t._v(" "),n("p",[t._v("During the Bury process of "),n("strong",[t._v("Goner")]),t._v(", it's required to pass a reference. This means that the first parameter of the "),n("code",[t._v("Cemetery.Bury")]),t._v(" method must be of a reference type. Both pointer injection and interface injection can pass the reference of "),n("strong",[t._v("Bury")]),t._v(" to the properties of a struct. "),n("strong",[t._v("Pointer injection")]),t._v(" is straightforward and intuitive, with a one-to-one correspondence between types, requiring little explanation.")]),t._v(" "),n("p",[t._v("Interfaces are one of the most essential designs in Go. Their purpose is to decouple the business usage from the implementation logic, allowing users of the interface to not be concerned with the implementation details. Another purpose of interfaces is to break circular dependencies. If two modules have a circular reference and they are in different packages, it violates the rule of no circular dependencies in Go, leading to compilation failure. We can use interfaces to break this circular dependency.")]),t._v(" "),n("p",[t._v("Circular dependency:\n"),n("img",{attrs:{src:a(256),alt:"Circular dependency"}})]),t._v(" "),n("p",[t._v("Using interfaces to break circular dependency:\n"),n("img",{attrs:{src:a(257),alt:"Using interfaces to break circular dependency"}})]),t._v(" "),n("p",[t._v('Using interfaces can hide the implementation details of business logic, effectively reducing the coupling between modules and better adhering to the "open-closed" principle. Therefore, we recommend using '),n("strong",[t._v("interface injection")]),t._v(". However, there are no absolutes in everything, introducing interfaces will certainly increase additional costs, so we still support "),n("strong",[t._v("pointer injection")]),t._v(".")]),t._v(" "),n("h2",{attrs:{id:"slice-injection-and-map-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#slice-injection-and-map-injection"}},[t._v("#")]),t._v(" Slice Injection and Map Injection")]),t._v(" "),n("p",[t._v("Gone supports injection into "),n("code",[t._v("Slice")]),t._v(" and "),n("code",[t._v("Map")]),t._v(", meaning it supports the following syntax:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n aSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a slice of Goner pointers")]),t._v("\n aSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a slice of Goner values")]),t._v("\n\n aMap1 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a map of Goner pointers")]),t._v("\n aMap2 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a map of Goner values")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[n("strong",[t._v("The rules for injection are as follows:")])]),t._v(" "),n("ul",[n("li",[n("ol",[n("li",[t._v("The element type of Slice and Map can be Goner pointer type or Goner value type, or an interface.")])])]),t._v(" "),n("li",[n("ol",{attrs:{start:"2"}},[n("li",[t._v("Gone will inject all types compatible with Goner into Slice and Map.")])])]),t._v(" "),n("li",[n("ol",{attrs:{start:"3"}},[n("li",[t._v("The type of Map key can only be string.")])])]),t._v(" "),n("li",[n("ol",{attrs:{start:"4"}},[n("li",[t._v("The value of Map key is the GonerId of the injected Goner. If no GonerId is specified when burying an anonymous Goner, Gone will generate one automatically.")])])])]),t._v(" "),n("div",{staticClass:"custom-block warning"},[n("p",{staticClass:"custom-block-title"},[t._v("WARNING")]),t._v(" "),n("p",[t._v("Using values as the element types for Slice and Map is not recommended.")])]),t._v(" "),n("p",[t._v("Here's a complete example:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" AGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Tell the framework that this struct is a Goner")]),t._v("\n Name "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sprintf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I am the AGoner, My name is: %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" BGoner "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n aSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a slice of Goner pointers")]),t._v("\n aSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a slice of Goner values")]),t._v("\n\n aMap1 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a map of Goner pointers")]),t._v("\n aMap2 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("map")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("AGoner "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Injected property is a map of Goner values")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive executed After the Goner is revived; After `gone.Run`, gone framework detects the AfterRevive function on goners and runs it.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aSlice1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aSlice1:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aSlice2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aSlice2:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aMap1 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aMap1[%s]:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("range")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("aMap2 "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n fmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"aMap2[%s]:%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" k"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA1 creates A1 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A1"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewA2 creates A2 AGoner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Injected Goner2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A2"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("AGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Anonymous"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewA2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("BGoner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The example yields the following result upon execution:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("Revive github.com/gone-io/gone/heaven\nRevive github.com/gone-io/gone/cemetery\nRevive main/AGoner\nRevive main/AGoner\nRevive main/AGoner\nRevive main/BGoner\naSlice1:I am the AGoner, My name is: Injected Goner1\naSlice1:I am the AGoner, My name is: Anonymous\naSlice1:I am the AGoner, My name is: Injected Goner2\n\naSlice2:I am the AGoner, My name is: Injected Goner1\naSlice2:I am the AGoner, My name is: Anonymous\naSlice2:I am the AGoner, My name is: Injected Goner2\n\naMap1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("A1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":I am the AGoner, My name is: Injected Goner1\naMap1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("main/AGoner"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#1374393662624]:I am the AGoner, My name is: Anonymous")]),t._v("\naMap1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("A2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":I am the AGoner, My name is: Injected Goner2\n\naMap2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("A2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":I am the AGoner, My name is: Injected Goner2\naMap2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("A1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":I am the AGoner, My name is: Injected Goner1\naMap2"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("main/AGoner"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#1374393662624]:I am the AGoner, My name is: Anonymous")]),t._v("\n")])])]),n("h3",{attrs:{id:"private-property-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#private-property-injection"}},[t._v("#")]),t._v(" Private Property Injection")]),t._v(" "),n("p",[t._v('Following the "Open-Closed Principle," attributes that modules depend on should ideally be private. Gone supports injecting into private variables of a struct.')]),t._v(" "),n("h2",{attrs:{id:"configuration-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-injection"}},[t._v("#")]),t._v(" "),n("RouterLink",{attrs:{to:"/guide/guide/config.html"}},[t._v("Configuration Injection")])],1)])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/24.41c07631.js b/assets/js/24.86b21c76.js similarity index 99% rename from assets/js/24.41c07631.js rename to assets/js/24.86b21c76.js index 6a4e086..fa1c151 100644 --- a/assets/js/24.41c07631.js +++ b/assets/js/24.86b21c76.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[24],{279:function(t,s,n){t.exports=n.p+"assets/img/image9.48d32078.png"},280:function(t,s,n){t.exports=n.p+"assets/img/image10.91a30027.png"},329:function(t,s,n){"use strict";n.r(s);var e=n(10),a=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"web-mysql"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#web-mysql"}},[t._v("#")]),t._v(" Web + MySQL")]),t._v(" "),s("p",[t._v("In this document, I will demonstrate how to create a production-ready web project and provide a brief introduction to the project. The project uses MySQL as the database and Docker Compose to manage containers.")]),t._v(" "),s("h2",{attrs:{id:"install-the-gone-tool"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-the-gone-tool"}},[t._v("#")]),t._v(" Install the gone Tool")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),s("p",[t._v("For more information about the gone command, refer to: "),s("a",{attrs:{href:"https://goner.fun/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Gone Tool"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"create-a-project-using-the-gone-command"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#create-a-project-using-the-gone-command"}},[t._v("#")]),t._v(" Create a Project Using the gone Command")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone create "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-t")]),t._v(" web+mysql web-mysql-docker\n")])])]),s("p",[t._v("The above command will create a directory named web-mysql-docker in the current directory.")]),t._v(" "),s("h2",{attrs:{id:"compile-and-run"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#compile-and-run"}},[t._v("#")]),t._v(" Compile And Run")]),t._v(" "),s("blockquote",[s("p",[t._v("Ensure you have make installed; if not, please install it first.\nEnsure you have docker and docker compose installed; if not, refer to: https://docs.docker.com/engine/install/.")])]),t._v(" "),s("p",[t._v("Execute the following commands:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Enter the project directory")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" web-mysql-docker\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Generate the Priest functions: https://goner.fun/guide/auto-gen-priest.html")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" gone\n\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Start the MySQL service")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("docker")]),t._v(" compose up "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" mysql\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Compile and run")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n")])])]),s("p",[t._v("The logs should display as follows:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("➜ web-mysql-docker "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" gone\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" install-gone\ngo "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\ngo mod tidy\ngo generate ./"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\ngo run cmd/server/main.go\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/heaven\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/cemetery\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/tracer/tracer\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/logrus/logger\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/config\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/logrus/logger\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("Use Env: "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("local")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("properties: /var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build521033176/b001/exe/config/default.properties not found. skipping\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("properties: /var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build521033176/b001/exe/config/local.properties not found. skipping\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/config\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/xorm/engine\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/cmux/server\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/proxy\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/router\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/sysProcessor\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/responser\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/server\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/httpInjector\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/controller/demoController\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/middleware/AuthorizeMiddleware\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/middleware/PubMiddleware\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/module/demo/db\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/module/demo/demoService\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/router/authRouter\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/router/pubRouter\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" Running "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"debug"')]),t._v(" mode. Switch to "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"release"')]),t._v(" mode "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" production.\n - using env: "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("GIN_MODE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("release\n - using code: gin.SetMode"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gin.ReleaseMode"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo/show --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/show --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/error --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/echo --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject-query --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject/:key --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" POST /api/inject-http-body --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject-http-struct --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" POST /api/users --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users/page --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" PUT /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" DELETE /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.576"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.3.1/goner/gin/server.go:46"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("Server Listen At :8080\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.576"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/xorm.io/xorm@v1.3.2/log/logger_context.go:90"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("PING DATABASE mysql\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.585"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.3.1/cemetery.go:329"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("Revive "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("Anonymous Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.585"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/works/gone-io/web-app/demo/web-mysql-docker/cmd/server/main.go:28"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("before start\n")])])]),s("h2",{attrs:{id:"api-testing"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#api-testing"}},[t._v("#")]),t._v(" API Testing")]),t._v(" "),s("p",[t._v("I'm going to test using the built-in HTTP Request plugin in Goland. Open the project in Goland, navigate to the file "),s("code",[t._v("tests/api/user.http")]),t._v(", and select the "),s("code",[t._v("dev")]),t._v(" environment to run, as shown below:")]),t._v(" "),s("p",[s("img",{attrs:{src:n(279),alt:"Run"}})]),t._v(" "),s("p",[t._v("Execution Result:\n"),s("img",{attrs:{src:n(280),alt:"Result"}})]),t._v(" "),s("h2",{attrs:{id:"project-brief-introduction"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#project-brief-introduction"}},[t._v("#")]),t._v(" Project Brief Introduction")]),t._v(" "),s("h3",{attrs:{id:"directory-structure"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#directory-structure"}},[t._v("#")]),t._v(" Directory Structure")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("├── Dockerfile\n├── Makefile\n├── README.md\n├── cmd\n│ └── server\n│ └── main.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# File containing the main method of the project")]),t._v("\n├── config "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Project configuration directory")]),t._v("\n│ ├── default.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Default configuration")]),t._v("\n│ ├── dev.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Development environment configuration")]),t._v("\n│ ├── local.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Local environment configuration")]),t._v("\n│ └── prod.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Production environment configuration")]),t._v("\n├── docker-compose.yaml "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# docker-compose, defines mysql and web containers")]),t._v("\n├── go.mod\n├── internal\n│ ├── controller "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Controller")]),t._v("\n│ │ └── demo_ctr.go\n│ ├── interface "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Interface directory")]),t._v("\n│ │ ├── domain "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Domain models")]),t._v("\n│ │ │ ├── demo.go\n│ │ │ ├── page.go\n│ │ │ └── user.go\n│ │ ├── entity "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Entity models")]),t._v("\n│ │ │ └── User.go\n│ │ └── "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Service interfaces")]),t._v("\n│ │ └── i_demo.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Typically one interface per file, file name starts with `i_`, interface name starts with `I`, e.g., `IDemo`")]),t._v("\n│ ├── master.go\n│ ├── middleware "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Middleware directory, can define unified processing logic such as authentication")]),t._v("\n│ │ ├── authorize.go\n│ │ └── pub.go\n│ ├── module "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Module directory")]),t._v("\n│ │ └── demo "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Demo module")]),t._v("\n│ │ ├── db.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Implementation of demo module's database interface")]),t._v("\n│ │ ├── demo_svc.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Demo Service, implementing `service.IDemo` interface")]),t._v("\n│ │ ├── error.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Error code definition for the current directory")]),t._v("\n│ │ └── i_db.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Database interface of the demo module")]),t._v("\n│ ├── pkg "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Public utilities directory")]),t._v("\n│ │ └── utils\n│ │ └── error.go\n│ ├── priest.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Not present when created by gone create, generated by running `make gone`")]),t._v("\n│ └── router "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Router directory")]),t._v("\n│ ├── auth_router.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Defines authenticated router groups")]),t._v("\n│ └── pub_router.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Defines unauthenticated router groups")]),t._v("\n├── scripts "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Script directory, used to store some scripts")]),t._v("\n│ └── mysql\n│ └── initdb.d "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# mysql initdb.d directory, all sql files under this directory will be executed when mysql defined in docker-compose starts for the first time")]),t._v("\n│ └── user.sql\n└── tests "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Integration test directory")]),t._v("\n └── api "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# API test directory")]),t._v("\n ├── demo.http\n ├── http-client.env.json\n └── user.http\n")])])]),s("h3",{attrs:{id:"project-features"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#project-features"}},[t._v("#")]),t._v(" Project Features")]),t._v(" "),s("ul",[s("li",[t._v("Ready to use, no additional configuration needed to run")]),t._v(" "),s("li",[t._v("Provides a "),s("code",[t._v("Dockerfile")]),t._v(" for easy deployment to various container environments")]),t._v(" "),s("li",[t._v("Integrated commands like gone, go, docker, and docker compose using Makefile")]),t._v(" "),s("li",[t._v("Automatically generates Priest functions for smoother development")]),t._v(" "),s("li",[t._v("Utilizes the gone framework, incorporating dependency injection")]),t._v(" "),s("li",[t._v("Decoupling through interface usage")]),t._v(" "),s("li",[t._v("Supports configuration writing for different environments")]),t._v(" "),s("li",[t._v("Integrated MySQL database")])]),t._v(" "),s("h3",{attrs:{id:"partial-code-explanation"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#partial-code-explanation"}},[t._v("#")]),t._v(" Partial Code Explanation")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// CRUD operations for user data under the demo module, mounted on authRouter for demonstration purposes")]),t._v("\n ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n pubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/users"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("POST")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Body injection, parses HTTP body into a struct based on contentType, supports json, xml, form-data, x-www-form-urlencoded, etc.")]),t._v("\n req "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("User "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ListUsers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/page"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n query domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("PageQuery "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Query injection")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("PageUsers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("query"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n id "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Url parameter injection, injected from the route defined as `:id`")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetUserById")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("PUT")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n id "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Url parameter injection, injected from the route defined as `:id`")]),t._v("\n req "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("User "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Body injection")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UpdateUserById")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("DELETE")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n id "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Url parameter injection, injected from the route defined as `:id`")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("DeleteUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),s("p",[t._v("The above code snippet is taken from the "),s("code",[t._v("internal/controller/demo_ctr.go")]),t._v(" file.")]),t._v(" "),s("h3",{attrs:{id:"http-injection"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#http-injection"}},[t._v("#")]),t._v(" HTTP Injection")]),t._v(" "),s("p",[t._v("As observed, "),s("strong",[t._v("Gone")]),t._v(" supports dependency injection on route handling functions. This is achieved by using an anonymous struct as the input parameter of the handling function and marking the struct attributes with special tags.\nThe injection tags used in the above code are:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v('gone:"http,body"')]),t._v(": Body injection, parses HTTP body into a struct based on contentType, supports json, xml, form-data, x-www-form-urlencoded, etc. The injected struct attribute should be of type "),s("strong",[t._v("struct")]),t._v(" or "),s("strong",[t._v("struct pointer")]),t._v(".")]),t._v(" "),s("li",[s("code",[t._v('gone:"http,query"')]),t._v(": Query injection, the injected struct attribute can be of type "),s("strong",[t._v("struct")]),t._v(", "),s("strong",[t._v("struct pointer")]),t._v(", "),s("strong",[t._v("string")]),t._v(", "),s("strong",[t._v("Number (int, uint, float64, etc.)")]),t._v(", or "),s("strong",[t._v("Slice of string or Number")]),t._v(".")]),t._v(" "),s("li",[s("code",[t._v('gone:"http,param"')]),t._v(": URL parameter injection, injected from the route defined as "),s("code",[t._v(":id")]),t._v(". The injected struct attribute should be of type "),s("strong",[t._v("string")]),t._v(" or "),s("strong",[t._v("Number")]),t._v(".")])]),t._v(" "),s("p",[t._v("Additionally, handling functions also support injection of some special structs or pointers (pointers are recommended):")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("gone.Content")]),t._v(": Request context")]),t._v(" "),s("li",[s("code",[t._v("http.Request")]),t._v(": HTTP request")]),t._v(" "),s("li",[s("code",[t._v("http.Header")]),t._v(": Request header")]),t._v(" "),s("li",[s("code",[t._v("url.Url")]),t._v(": URL")])]),t._v(" "),s("p",[t._v("The framework supports more injection tags and types, please refer to the documentation "),s("a",{attrs:{href:"https://goner.fun/en/references/http-inject.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("HTTP Injection"),s("OutboundLink")],1),t._v(".")]),t._v(" "),s("h3",{attrs:{id:"request-handling-function-parameters"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#request-handling-function-parameters"}},[t._v("#")]),t._v(" Request Handling Function Parameters")]),t._v(" "),s("p",[t._v("Request handling functions can have the following return formats:")]),t._v(" "),s("ol",[s("li",[t._v("No return parameters")]),t._v(" "),s("li",[t._v("Return a non-"),s("code",[t._v("error")]),t._v(" parameter")]),t._v(" "),s("li",[t._v("Return data and "),s("code",[t._v("error")])])])])}),[],!1,null,null,null);s.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[24],{279:function(t,s,n){t.exports=n.p+"assets/img/image9.48d32078.png"},280:function(t,s,n){t.exports=n.p+"assets/img/image10.91a30027.png"},328:function(t,s,n){"use strict";n.r(s);var e=n(10),a=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"web-mysql"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#web-mysql"}},[t._v("#")]),t._v(" Web + MySQL")]),t._v(" "),s("p",[t._v("In this document, I will demonstrate how to create a production-ready web project and provide a brief introduction to the project. The project uses MySQL as the database and Docker Compose to manage containers.")]),t._v(" "),s("h2",{attrs:{id:"install-the-gone-tool"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-the-gone-tool"}},[t._v("#")]),t._v(" Install the gone Tool")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),s("p",[t._v("For more information about the gone command, refer to: "),s("a",{attrs:{href:"https://goner.fun/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Gone Tool"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"create-a-project-using-the-gone-command"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#create-a-project-using-the-gone-command"}},[t._v("#")]),t._v(" Create a Project Using the gone Command")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone create "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-t")]),t._v(" web+mysql web-mysql-docker\n")])])]),s("p",[t._v("The above command will create a directory named web-mysql-docker in the current directory.")]),t._v(" "),s("h2",{attrs:{id:"compile-and-run"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#compile-and-run"}},[t._v("#")]),t._v(" Compile And Run")]),t._v(" "),s("blockquote",[s("p",[t._v("Ensure you have make installed; if not, please install it first.\nEnsure you have docker and docker compose installed; if not, refer to: https://docs.docker.com/engine/install/.")])]),t._v(" "),s("p",[t._v("Execute the following commands:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Enter the project directory")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" web-mysql-docker\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Generate the Priest functions: https://goner.fun/guide/auto-gen-priest.html")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" gone\n\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Start the MySQL service")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("docker")]),t._v(" compose up "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" mysql\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Compile and run")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n")])])]),s("p",[t._v("The logs should display as follows:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("➜ web-mysql-docker "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" gone\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" install-gone\ngo "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\ngo mod tidy\ngo generate ./"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\ngo run cmd/server/main.go\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/heaven\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/cemetery\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/tracer/tracer\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/logrus/logger\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/config\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/logrus/logger\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("Use Env: "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("local")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("properties: /var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build521033176/b001/exe/config/default.properties not found. skipping\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("properties: /var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build521033176/b001/exe/config/local.properties not found. skipping\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/config\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/xorm/engine\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/cmux/server\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/proxy\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/router\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/sysProcessor\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/responser\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/server\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/httpInjector\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/controller/demoController\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/middleware/AuthorizeMiddleware\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/middleware/PubMiddleware\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/module/demo/db\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/module/demo/demoService\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/router/authRouter\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/router/pubRouter\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" Running "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"debug"')]),t._v(" mode. Switch to "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"release"')]),t._v(" mode "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" production.\n - using env: "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("GIN_MODE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("release\n - using code: gin.SetMode"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gin.ReleaseMode"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo/show --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/show --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/error --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/echo --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject-query --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject/:key --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" POST /api/inject-http-body --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject-http-struct --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" POST /api/users --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users/page --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" PUT /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" DELETE /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.576"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.3.1/goner/gin/server.go:46"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("Server Listen At :8080\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.576"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/xorm.io/xorm@v1.3.2/log/logger_context.go:90"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("PING DATABASE mysql\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.585"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.3.1/cemetery.go:329"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("Revive "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("Anonymous Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.585"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/works/gone-io/web-app/demo/web-mysql-docker/cmd/server/main.go:28"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("before start\n")])])]),s("h2",{attrs:{id:"api-testing"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#api-testing"}},[t._v("#")]),t._v(" API Testing")]),t._v(" "),s("p",[t._v("I'm going to test using the built-in HTTP Request plugin in Goland. Open the project in Goland, navigate to the file "),s("code",[t._v("tests/api/user.http")]),t._v(", and select the "),s("code",[t._v("dev")]),t._v(" environment to run, as shown below:")]),t._v(" "),s("p",[s("img",{attrs:{src:n(279),alt:"Run"}})]),t._v(" "),s("p",[t._v("Execution Result:\n"),s("img",{attrs:{src:n(280),alt:"Result"}})]),t._v(" "),s("h2",{attrs:{id:"project-brief-introduction"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#project-brief-introduction"}},[t._v("#")]),t._v(" Project Brief Introduction")]),t._v(" "),s("h3",{attrs:{id:"directory-structure"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#directory-structure"}},[t._v("#")]),t._v(" Directory Structure")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("├── Dockerfile\n├── Makefile\n├── README.md\n├── cmd\n│ └── server\n│ └── main.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# File containing the main method of the project")]),t._v("\n├── config "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Project configuration directory")]),t._v("\n│ ├── default.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Default configuration")]),t._v("\n│ ├── dev.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Development environment configuration")]),t._v("\n│ ├── local.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Local environment configuration")]),t._v("\n│ └── prod.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Production environment configuration")]),t._v("\n├── docker-compose.yaml "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# docker-compose, defines mysql and web containers")]),t._v("\n├── go.mod\n├── internal\n│ ├── controller "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Controller")]),t._v("\n│ │ └── demo_ctr.go\n│ ├── interface "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Interface directory")]),t._v("\n│ │ ├── domain "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Domain models")]),t._v("\n│ │ │ ├── demo.go\n│ │ │ ├── page.go\n│ │ │ └── user.go\n│ │ ├── entity "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Entity models")]),t._v("\n│ │ │ └── User.go\n│ │ └── "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Service interfaces")]),t._v("\n│ │ └── i_demo.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Typically one interface per file, file name starts with `i_`, interface name starts with `I`, e.g., `IDemo`")]),t._v("\n│ ├── master.go\n│ ├── middleware "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Middleware directory, can define unified processing logic such as authentication")]),t._v("\n│ │ ├── authorize.go\n│ │ └── pub.go\n│ ├── module "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Module directory")]),t._v("\n│ │ └── demo "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Demo module")]),t._v("\n│ │ ├── db.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Implementation of demo module's database interface")]),t._v("\n│ │ ├── demo_svc.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Demo Service, implementing `service.IDemo` interface")]),t._v("\n│ │ ├── error.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Error code definition for the current directory")]),t._v("\n│ │ └── i_db.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Database interface of the demo module")]),t._v("\n│ ├── pkg "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Public utilities directory")]),t._v("\n│ │ └── utils\n│ │ └── error.go\n│ ├── priest.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Not present when created by gone create, generated by running `make gone`")]),t._v("\n│ └── router "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Router directory")]),t._v("\n│ ├── auth_router.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Defines authenticated router groups")]),t._v("\n│ └── pub_router.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Defines unauthenticated router groups")]),t._v("\n├── scripts "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Script directory, used to store some scripts")]),t._v("\n│ └── mysql\n│ └── initdb.d "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# mysql initdb.d directory, all sql files under this directory will be executed when mysql defined in docker-compose starts for the first time")]),t._v("\n│ └── user.sql\n└── tests "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Integration test directory")]),t._v("\n └── api "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# API test directory")]),t._v("\n ├── demo.http\n ├── http-client.env.json\n └── user.http\n")])])]),s("h3",{attrs:{id:"project-features"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#project-features"}},[t._v("#")]),t._v(" Project Features")]),t._v(" "),s("ul",[s("li",[t._v("Ready to use, no additional configuration needed to run")]),t._v(" "),s("li",[t._v("Provides a "),s("code",[t._v("Dockerfile")]),t._v(" for easy deployment to various container environments")]),t._v(" "),s("li",[t._v("Integrated commands like gone, go, docker, and docker compose using Makefile")]),t._v(" "),s("li",[t._v("Automatically generates Priest functions for smoother development")]),t._v(" "),s("li",[t._v("Utilizes the gone framework, incorporating dependency injection")]),t._v(" "),s("li",[t._v("Decoupling through interface usage")]),t._v(" "),s("li",[t._v("Supports configuration writing for different environments")]),t._v(" "),s("li",[t._v("Integrated MySQL database")])]),t._v(" "),s("h3",{attrs:{id:"partial-code-explanation"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#partial-code-explanation"}},[t._v("#")]),t._v(" Partial Code Explanation")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// CRUD operations for user data under the demo module, mounted on authRouter for demonstration purposes")]),t._v("\n ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n pubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/users"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("POST")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Body injection, parses HTTP body into a struct based on contentType, supports json, xml, form-data, x-www-form-urlencoded, etc.")]),t._v("\n req "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("User "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ListUsers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/page"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n query domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("PageQuery "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Query injection")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("PageUsers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("query"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n id "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Url parameter injection, injected from the route defined as `:id`")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetUserById")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("PUT")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n id "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Url parameter injection, injected from the route defined as `:id`")]),t._v("\n req "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("User "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Body injection")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UpdateUserById")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("DELETE")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n id "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Url parameter injection, injected from the route defined as `:id`")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("DeleteUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),s("p",[t._v("The above code snippet is taken from the "),s("code",[t._v("internal/controller/demo_ctr.go")]),t._v(" file.")]),t._v(" "),s("h3",{attrs:{id:"http-injection"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#http-injection"}},[t._v("#")]),t._v(" HTTP Injection")]),t._v(" "),s("p",[t._v("As observed, "),s("strong",[t._v("Gone")]),t._v(" supports dependency injection on route handling functions. This is achieved by using an anonymous struct as the input parameter of the handling function and marking the struct attributes with special tags.\nThe injection tags used in the above code are:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v('gone:"http,body"')]),t._v(": Body injection, parses HTTP body into a struct based on contentType, supports json, xml, form-data, x-www-form-urlencoded, etc. The injected struct attribute should be of type "),s("strong",[t._v("struct")]),t._v(" or "),s("strong",[t._v("struct pointer")]),t._v(".")]),t._v(" "),s("li",[s("code",[t._v('gone:"http,query"')]),t._v(": Query injection, the injected struct attribute can be of type "),s("strong",[t._v("struct")]),t._v(", "),s("strong",[t._v("struct pointer")]),t._v(", "),s("strong",[t._v("string")]),t._v(", "),s("strong",[t._v("Number (int, uint, float64, etc.)")]),t._v(", or "),s("strong",[t._v("Slice of string or Number")]),t._v(".")]),t._v(" "),s("li",[s("code",[t._v('gone:"http,param"')]),t._v(": URL parameter injection, injected from the route defined as "),s("code",[t._v(":id")]),t._v(". The injected struct attribute should be of type "),s("strong",[t._v("string")]),t._v(" or "),s("strong",[t._v("Number")]),t._v(".")])]),t._v(" "),s("p",[t._v("Additionally, handling functions also support injection of some special structs or pointers (pointers are recommended):")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("gone.Content")]),t._v(": Request context")]),t._v(" "),s("li",[s("code",[t._v("http.Request")]),t._v(": HTTP request")]),t._v(" "),s("li",[s("code",[t._v("http.Header")]),t._v(": Request header")]),t._v(" "),s("li",[s("code",[t._v("url.Url")]),t._v(": URL")])]),t._v(" "),s("p",[t._v("The framework supports more injection tags and types, please refer to the documentation "),s("a",{attrs:{href:"https://goner.fun/en/references/http-inject.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("HTTP Injection"),s("OutboundLink")],1),t._v(".")]),t._v(" "),s("h3",{attrs:{id:"request-handling-function-parameters"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#request-handling-function-parameters"}},[t._v("#")]),t._v(" Request Handling Function Parameters")]),t._v(" "),s("p",[t._v("Request handling functions can have the following return formats:")]),t._v(" "),s("ol",[s("li",[t._v("No return parameters")]),t._v(" "),s("li",[t._v("Return a non-"),s("code",[t._v("error")]),t._v(" parameter")]),t._v(" "),s("li",[t._v("Return data and "),s("code",[t._v("error")])])])])}),[],!1,null,null,null);s.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/26.0f81f128.js b/assets/js/26.aebe581f.js similarity index 99% rename from assets/js/26.0f81f128.js rename to assets/js/26.aebe581f.js index 3d5fcf8..476f8c2 100644 --- a/assets/js/26.0f81f128.js +++ b/assets/js/26.aebe581f.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[26],{279:function(t,s,n){t.exports=n.p+"assets/img/image9.48d32078.png"},280:function(t,s,n){t.exports=n.p+"assets/img/image10.91a30027.png"},350:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"web-mysql"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#web-mysql"}},[t._v("#")]),t._v(" Web + MySQL")]),t._v(" "),s("p",[t._v("在本文中,我将演示如何创建一个可运行在生产环境的Web项目,并对项目做简单的介绍。项目的使用MySql作为数据库,使用docker-compose管理容器。")]),t._v(" "),s("h2",{attrs:{id:"安装gone辅助工具"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#安装gone辅助工具"}},[t._v("#")]),t._v(" 安装gone辅助工具")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),s("p",[t._v("关于gone命令,更多参考:"),s("a",{attrs:{href:"https://goner.fun/zh/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gone辅助工具"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"使用gone命令创建项目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用gone命令创建项目"}},[t._v("#")]),t._v(" 使用gone命令创建项目")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone create "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-t")]),t._v(" web+mysql web-mysql-docker\n")])])]),s("p",[t._v("上面命令会在当前目录中创建一个名为web-mysql-docker的目录。")]),t._v(" "),s("h2",{attrs:{id:"编译并运行"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#编译并运行"}},[t._v("#")]),t._v(" 编译并运行")]),t._v(" "),s("blockquote",[s("p",[t._v("假设你已经安装了"),s("code",[t._v("make")]),t._v(";如果没有安装请先安装,参考:"),s("a",{attrs:{href:"https://blog.csdn.net/waitdeng/article/details/138849321",target:"_blank",rel:"noopener noreferrer"}},[t._v("安装make"),s("OutboundLink")],1),t._v("。"),s("br"),t._v("\n建设你已经安装了"),s("code",[t._v("docker")]),t._v(" 和 "),s("code",[t._v("docker compose")]),t._v(";如果没有,参考: https://docs.docker.com/engine/install/。")])]),t._v(" "),s("p",[t._v("执行系列命令")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 进入项目目录")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" web-mysql-docker\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 生成Priest函数:https://goner.fun/zh/guide/auto-gen-priest.html")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" gone\n\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 启动MySql服务")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("docker")]),t._v(" compose up "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" mysql\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 编译并运行")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n")])])]),s("p",[t._v("日志打印如下:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("➜ web-mysql-docker "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" gone\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" install-gone\ngo "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\ngo mod tidy\ngo generate ./"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\ngo run cmd/server/main.go\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/heaven\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/cemetery\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/tracer/tracer\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/logrus/logger\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/config\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/logrus/logger\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("Use Env: "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("local")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("properties: /var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build521033176/b001/exe/config/default.properties not found. skipping\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("properties: /var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build521033176/b001/exe/config/local.properties not found. skipping\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/config\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/xorm/engine\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/cmux/server\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/proxy\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/router\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/sysProcessor\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/responser\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/server\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/httpInjector\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/controller/demoController\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/middleware/AuthorizeMiddleware\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/middleware/PubMiddleware\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/module/demo/db\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/module/demo/demoService\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/router/authRouter\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/router/pubRouter\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" Running "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"debug"')]),t._v(" mode. Switch to "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"release"')]),t._v(" mode "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" production.\n - using env: "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("GIN_MODE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("release\n - using code: gin.SetMode"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gin.ReleaseMode"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo/show --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/show --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/error --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/echo --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject-query --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject/:key --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" POST /api/inject-http-body --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject-http-struct --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" POST /api/users --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users/page --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" PUT /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" DELETE /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.576"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.3.1/goner/gin/server.go:46"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("Server Listen At :8080\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.576"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/xorm.io/xorm@v1.3.2/log/logger_context.go:90"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("PING DATABASE mysql\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.585"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.3.1/cemetery.go:329"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("Revive "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("Anonymous Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.585"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/works/gone-io/web-app/demo/web-mysql-docker/cmd/server/main.go:28"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("before start\n")])])]),s("h2",{attrs:{id:"测试接口"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#测试接口"}},[t._v("#")]),t._v(" 测试接口")]),t._v(" "),s("p",[t._v("我这里使用Goland内置Http Request插件测试。\n使用Goland打开项目,打开文件"),s("code",[t._v("tests/api/user.http")]),t._v(",选择"),s("code",[t._v("dev")]),t._v("环境运行,如下:\n"),s("img",{attrs:{src:n(279),alt:"运行"}})]),t._v(" "),s("p",[t._v("执行结果:\n"),s("img",{attrs:{src:n(280),alt:"结果"}})]),t._v(" "),s("h2",{attrs:{id:"项目简单介绍"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#项目简单介绍"}},[t._v("#")]),t._v(" 项目简单介绍")]),t._v(" "),s("h3",{attrs:{id:"目录结构"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#目录结构"}},[t._v("#")]),t._v(" 目录结构")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("├── Dockerfile\n├── Makefile\n├── README.md\n├── cmd\n│ └── server\n│ └── main.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#项目main方法所在文件")]),t._v("\n├── config "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#项目配置目录")]),t._v("\n│ ├── default.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#默认配置")]),t._v("\n│ ├── dev.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#开发环境配置")]),t._v("\n│ ├── local.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#本地环境配置")]),t._v("\n│ └── prod.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#生产环境配置")]),t._v("\n├── docker-compose.yaml "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# docker-compose,定义了mysql 和 web 两个容器")]),t._v("\n├── go.mod\n├── internal\n│ ├── controller "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#Controller")]),t._v("\n│ │ └── demo_ctr.go\n│ ├── interface "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#接口目录")]),t._v("\n│ │ ├── domain "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#领域模型")]),t._v("\n│ │ │ ├── demo.go\n│ │ │ ├── page.go\n│ │ │ └── user.go\n│ │ ├── entity "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#实体模型")]),t._v("\n│ │ │ └── User.go\n│ │ └── "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#服务接口")]),t._v("\n│ │ └── i_demo.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#一个文件一般只放一个接口,文件名以`i_开口`,接口名以 `I`卡头,比如`IDemo`")]),t._v("\n│ ├── master.go\n│ ├── middleware "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#中间件目录,可以定义鉴权等统一处理逻辑")]),t._v("\n│ │ ├── authorize.go\n│ │ └── pub.go\n│ ├── module "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#模块目录")]),t._v("\n│ │ └── demo "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#demo模块")]),t._v("\n│ │ ├── db.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#demo目录的数据库接口的实现")]),t._v("\n│ │ ├── demo_svc.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#demo Service,实现了`service.IDemo`接口")]),t._v("\n│ │ ├── error.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 当前目录错误码定义")]),t._v("\n│ │ └── i_db.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#demo目录的数据库接口")]),t._v("\n│ ├── pkg "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#公共工具目录")]),t._v("\n│ │ └── utils\n│ │ └── error.go\n│ ├── priest.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#gone create 创建是没有该文件,运行 `make gone`生成的")]),t._v("\n│ └── router "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#路由目录")]),t._v("\n│ ├── auth_router.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 定义了需要鉴权的的路由组")]),t._v("\n│ └── pub_router.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 定义了无需鉴权的的路由组")]),t._v("\n├── scripts "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 脚本目录,用于存放一些脚本")]),t._v("\n│ └── mysql\n│ └── initdb.d "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#mysql initdb.d目录,docker-compose中定义的mysql首次启动时 会执行该目录下所有sql文件")]),t._v("\n│ └── user.sql\n└── tests "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#集成测试目录")]),t._v("\n └── api "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#接口测试目录")]),t._v("\n ├── demo.http\n ├── http-client.env.json\n └── user.http\n")])])]),s("h3",{attrs:{id:"项目特点"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#项目特点"}},[t._v("#")]),t._v(" 项目特点")]),t._v(" "),s("ul",[s("li",[t._v("开箱可用,无需额外配置直接可以运行")]),t._v(" "),s("li",[t._v("生成了"),s("code",[t._v("Dockerfile")]),t._v(",方便部署到各种容器环境")]),t._v(" "),s("li",[t._v("使用Makefile整合了gone、go、docker、docker compose等命令")]),t._v(" "),s("li",[t._v("自动生成Priest函数,使开发更顺畅")]),t._v(" "),s("li",[t._v("使用了gone框架,引入了依赖注入")]),t._v(" "),s("li",[t._v("使用接口解耦")]),t._v(" "),s("li",[t._v("支持分环境编写配置")]),t._v(" "),s("li",[t._v("集成了MySQL数据库")])]),t._v(" "),s("h3",{attrs:{id:"部分代码讲解"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#部分代码讲解"}},[t._v("#")]),t._v(" 部分代码讲解")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// demo数据 user 的增删改查,挂载到authRouter只为方便演示")]),t._v("\n\tctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tpubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/users"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("POST")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Body注入,根据contentType将HTTP正文解析为一个结构体,支持json、xml、form-data、x-www-form-urlencoded 等 contentType")]),t._v("\n\t\t\treq "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("User "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ListUsers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/page"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tquery domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("PageQuery "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Query注入")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("PageUsers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("query"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tid "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Url参数注入,将注入路由上定义的`:id`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetUserById")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("PUT")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tid "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Url参数注入,将注入路由上定义的`:id`")]),t._v("\n\t\t\treq "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("User "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Body注入")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UpdateUserById")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("DELETE")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tid "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Url参数注入,将注入路由上定义的`:id`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("DeleteUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),s("p",[t._v("上面代码截取于"),s("code",[t._v("internal/controller/demo_ctr.go")]),t._v("文件。")]),t._v(" "),s("h3",{attrs:{id:"http-注入"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#http-注入"}},[t._v("#")]),t._v(" HTTP 注入")]),t._v(" "),s("p",[t._v("可以看到,"),s("strong",[t._v("Gone")]),t._v("在路由处理函数上也支持了"),s("strong",[t._v("依赖注入")]),t._v(";注入的方式是在使用一个匿名结构体作为处理函数的入参,并给结构体属性做特殊标记。\n上面代码用的注入标签:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v('gone:"http,body"')]),t._v(",Body注入,根据contentType将HTTP正文解析为一个结构体,支持json、xml、form-data、x-www-form-urlencoded 等 contentType,要求被注入的结构体属性的数据类型为"),s("strong",[t._v("结构体")]),t._v("或者"),s("strong",[t._v("结构体指针")]),t._v(";")]),t._v(" "),s("li",[s("code",[t._v('gone:"http,query"')]),t._v(",Query注入,被注入的结构体属性的数据类型可以为"),s("strong",[t._v("结构体")]),t._v("、"),s("strong",[t._v("结构体指针")]),t._v("、"),s("strong",[t._v("字符串")]),t._v("、"),s("strong",[t._v("Number(int、uint、float64 ...)")]),t._v(" 和 "),s("strong",[t._v("字符串或Number的Slice")]),t._v(";")]),t._v(" "),s("li",[s("code",[t._v('gone:"http,param"')]),t._v(",Url参数注入,将注入路由上定义的参数;要求被注入的结构体属性的数据类型为"),s("strong",[t._v("字符串")]),t._v("或"),s("strong",[t._v("Number类型")]),t._v("。")])]),t._v(" "),s("p",[t._v("下面对Query注入,句几个例子:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Q "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n Page "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`form:"page"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用form标签指定参数名为page,默认是属性名Page")]),t._v("\n PageSize "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`form:"pageSize"`')]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用form标签指定参数名为pageSize,默认是属性名PageSize")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("handle")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n page "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//未指定query参数名,去属性名为key")]),t._v("\n thePage "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=page"`')]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//指定query参数名为page")]),t._v("\n size "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=pageSize`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//指定query参数名为pageSize")]),t._v("\n\n q "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Q "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//被注入类型为一个结构体")]),t._v("\n keywords "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=keywords"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用数组结构,允许Query参数出现多次")]),t._v("\n oneKeyword "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=keywords"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//不使用数组,只获取Query中的第一个keyword")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("假设某个请求的Query为:"),s("code",[t._v("?page=10&pageSize=20&keywords=today&keywords=weather")]),t._v(",使用上面"),s("code",[t._v("handle")]),t._v("处理请求,参数"),s("code",[t._v("in")]),t._v("的值如下:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("in.page")]),t._v(" = 10")]),t._v(" "),s("li",[s("code",[t._v("in.thePage")]),t._v(" = 10")]),t._v(" "),s("li",[s("code",[t._v("in.size")]),t._v(" = 20")]),t._v(" "),s("li",[s("code",[t._v("in.q")]),t._v(" = {Page = 10, PageSize = 20}")]),t._v(" "),s("li",[s("code",[t._v("in.keywords")]),t._v(" = [today, weather]")]),t._v(" "),s("li",[s("code",[t._v("in.oneKeyword")]),t._v(" = today")])]),t._v(" "),s("p",[t._v("另外,处理函数还支持注入一些特殊结构体或指针(推荐使用指针):")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("gone.Content")]),t._v(" 请求上下文")]),t._v(" "),s("li",[s("code",[t._v("http.Request")]),t._v(" Http请求")]),t._v(" "),s("li",[s("code",[t._v("http.Header")]),t._v(" 请求头")]),t._v(" "),s("li",[s("code",[t._v("url.Url")]),t._v(" url")])]),t._v(" "),s("p",[t._v("框架还支持更多的注入标签和类型,请参考文档"),s("a",{attrs:{href:"https://goner.fun/zh/references/http-inject.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("http 注入说明"),s("OutboundLink")],1)]),t._v(" "),s("h3",{attrs:{id:"请求处理函数参数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#请求处理函数参数"}},[t._v("#")]),t._v(" 请求处理函数参数")]),t._v(" "),s("p",[t._v("请求处理函数返回参数可以为如下几种形式:")]),t._v(" "),s("ol",[s("li",[t._v("不返回参数")]),t._v(" "),s("li",[t._v("返回一个非"),s("code",[t._v("error")]),t._v("的参数")]),t._v(" "),s("li",[t._v("返回数据和"),s("code",[t._v("error")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[26],{279:function(t,s,n){t.exports=n.p+"assets/img/image9.48d32078.png"},280:function(t,s,n){t.exports=n.p+"assets/img/image10.91a30027.png"},357:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"web-mysql"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#web-mysql"}},[t._v("#")]),t._v(" Web + MySQL")]),t._v(" "),s("p",[t._v("在本文中,我将演示如何创建一个可运行在生产环境的Web项目,并对项目做简单的介绍。项目的使用MySql作为数据库,使用docker-compose管理容器。")]),t._v(" "),s("h2",{attrs:{id:"安装gone辅助工具"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#安装gone辅助工具"}},[t._v("#")]),t._v(" 安装gone辅助工具")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),s("p",[t._v("关于gone命令,更多参考:"),s("a",{attrs:{href:"https://goner.fun/zh/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gone辅助工具"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"使用gone命令创建项目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用gone命令创建项目"}},[t._v("#")]),t._v(" 使用gone命令创建项目")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone create "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-t")]),t._v(" web+mysql web-mysql-docker\n")])])]),s("p",[t._v("上面命令会在当前目录中创建一个名为web-mysql-docker的目录。")]),t._v(" "),s("h2",{attrs:{id:"编译并运行"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#编译并运行"}},[t._v("#")]),t._v(" 编译并运行")]),t._v(" "),s("blockquote",[s("p",[t._v("假设你已经安装了"),s("code",[t._v("make")]),t._v(";如果没有安装请先安装,参考:"),s("a",{attrs:{href:"https://blog.csdn.net/waitdeng/article/details/138849321",target:"_blank",rel:"noopener noreferrer"}},[t._v("安装make"),s("OutboundLink")],1),t._v("。"),s("br"),t._v("\n建设你已经安装了"),s("code",[t._v("docker")]),t._v(" 和 "),s("code",[t._v("docker compose")]),t._v(";如果没有,参考: https://docs.docker.com/engine/install/。")])]),t._v(" "),s("p",[t._v("执行系列命令")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 进入项目目录")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" web-mysql-docker\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 生成Priest函数:https://goner.fun/zh/guide/auto-gen-priest.html")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" gone\n\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 启动MySql服务")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("docker")]),t._v(" compose up "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" mysql\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 编译并运行")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n")])])]),s("p",[t._v("日志打印如下:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("➜ web-mysql-docker "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" gone\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" install-gone\ngo "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\ngo mod tidy\ngo generate ./"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\ngo run cmd/server/main.go\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/heaven\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/cemetery\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/tracer/tracer\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/logrus/logger\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/config\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/logrus/logger\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("Use Env: "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("local")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("properties: /var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build521033176/b001/exe/config/default.properties not found. skipping\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.574"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("properties: /var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build521033176/b001/exe/config/local.properties not found. skipping\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/config\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/config/propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/xorm/engine\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/cmux/server\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/proxy\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/router\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/sysProcessor\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/responser\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/server\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github.com/gone-io/gone/goner/gin/httpInjector\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/controller/demoController\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/middleware/AuthorizeMiddleware\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/middleware/PubMiddleware\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/module/demo/db\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/module/demo/demoService\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/router/authRouter\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.575"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive web-mysql/internal/router/pubRouter\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("WARNING"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" Running "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"debug"')]),t._v(" mode. Switch to "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"release"')]),t._v(" mode "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" production.\n - using env: "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("GIN_MODE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("release\n - using code: gin.SetMode"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gin.ReleaseMode"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo/show --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/show --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/error --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/demo2/echo --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func5 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject-query --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject/:key --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" POST /api/inject-http-body --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/inject-http-struct --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" POST /api/users --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users/page --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" GET /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" PUT /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GIN-debug"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" DELETE /api/users/:id --"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" github.com/gone-io/gone/goner/gin."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".Proxy."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("*proxy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(".proxyOne.func8 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("7")]),t._v(" handlers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.576"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.3.1/goner/gin/server.go:46"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("Server Listen At :8080\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.576"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/xorm.io/xorm@v1.3.2/log/logger_context.go:90"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("PING DATABASE mysql\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.585"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.3.1/cemetery.go:329"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("Revive "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("Anonymous Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2024")]),t._v("-05-14 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("12")]),t._v(":42:03.585"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("INFO"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("/Users/jim/works/gone-io/web-app/demo/web-mysql-docker/cmd/server/main.go:28"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v("before start\n")])])]),s("h2",{attrs:{id:"测试接口"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#测试接口"}},[t._v("#")]),t._v(" 测试接口")]),t._v(" "),s("p",[t._v("我这里使用Goland内置Http Request插件测试。\n使用Goland打开项目,打开文件"),s("code",[t._v("tests/api/user.http")]),t._v(",选择"),s("code",[t._v("dev")]),t._v("环境运行,如下:\n"),s("img",{attrs:{src:n(279),alt:"运行"}})]),t._v(" "),s("p",[t._v("执行结果:\n"),s("img",{attrs:{src:n(280),alt:"结果"}})]),t._v(" "),s("h2",{attrs:{id:"项目简单介绍"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#项目简单介绍"}},[t._v("#")]),t._v(" 项目简单介绍")]),t._v(" "),s("h3",{attrs:{id:"目录结构"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#目录结构"}},[t._v("#")]),t._v(" 目录结构")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("├── Dockerfile\n├── Makefile\n├── README.md\n├── cmd\n│ └── server\n│ └── main.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#项目main方法所在文件")]),t._v("\n├── config "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#项目配置目录")]),t._v("\n│ ├── default.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#默认配置")]),t._v("\n│ ├── dev.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#开发环境配置")]),t._v("\n│ ├── local.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#本地环境配置")]),t._v("\n│ └── prod.properties "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#生产环境配置")]),t._v("\n├── docker-compose.yaml "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# docker-compose,定义了mysql 和 web 两个容器")]),t._v("\n├── go.mod\n├── internal\n│ ├── controller "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#Controller")]),t._v("\n│ │ └── demo_ctr.go\n│ ├── interface "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#接口目录")]),t._v("\n│ │ ├── domain "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#领域模型")]),t._v("\n│ │ │ ├── demo.go\n│ │ │ ├── page.go\n│ │ │ └── user.go\n│ │ ├── entity "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#实体模型")]),t._v("\n│ │ │ └── User.go\n│ │ └── "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#服务接口")]),t._v("\n│ │ └── i_demo.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#一个文件一般只放一个接口,文件名以`i_开口`,接口名以 `I`卡头,比如`IDemo`")]),t._v("\n│ ├── master.go\n│ ├── middleware "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#中间件目录,可以定义鉴权等统一处理逻辑")]),t._v("\n│ │ ├── authorize.go\n│ │ └── pub.go\n│ ├── module "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#模块目录")]),t._v("\n│ │ └── demo "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#demo模块")]),t._v("\n│ │ ├── db.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#demo目录的数据库接口的实现")]),t._v("\n│ │ ├── demo_svc.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#demo Service,实现了`service.IDemo`接口")]),t._v("\n│ │ ├── error.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 当前目录错误码定义")]),t._v("\n│ │ └── i_db.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#demo目录的数据库接口")]),t._v("\n│ ├── pkg "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#公共工具目录")]),t._v("\n│ │ └── utils\n│ │ └── error.go\n│ ├── priest.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#gone create 创建是没有该文件,运行 `make gone`生成的")]),t._v("\n│ └── router "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#路由目录")]),t._v("\n│ ├── auth_router.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 定义了需要鉴权的的路由组")]),t._v("\n│ └── pub_router.go "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 定义了无需鉴权的的路由组")]),t._v("\n├── scripts "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 脚本目录,用于存放一些脚本")]),t._v("\n│ └── mysql\n│ └── initdb.d "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#mysql initdb.d目录,docker-compose中定义的mysql首次启动时 会执行该目录下所有sql文件")]),t._v("\n│ └── user.sql\n└── tests "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#集成测试目录")]),t._v("\n └── api "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#接口测试目录")]),t._v("\n ├── demo.http\n ├── http-client.env.json\n └── user.http\n")])])]),s("h3",{attrs:{id:"项目特点"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#项目特点"}},[t._v("#")]),t._v(" 项目特点")]),t._v(" "),s("ul",[s("li",[t._v("开箱可用,无需额外配置直接可以运行")]),t._v(" "),s("li",[t._v("生成了"),s("code",[t._v("Dockerfile")]),t._v(",方便部署到各种容器环境")]),t._v(" "),s("li",[t._v("使用Makefile整合了gone、go、docker、docker compose等命令")]),t._v(" "),s("li",[t._v("自动生成Priest函数,使开发更顺畅")]),t._v(" "),s("li",[t._v("使用了gone框架,引入了依赖注入")]),t._v(" "),s("li",[t._v("使用接口解耦")]),t._v(" "),s("li",[t._v("支持分环境编写配置")]),t._v(" "),s("li",[t._v("集成了MySQL数据库")])]),t._v(" "),s("h3",{attrs:{id:"部分代码讲解"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#部分代码讲解"}},[t._v("#")]),t._v(" 部分代码讲解")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// demo数据 user 的增删改查,挂载到authRouter只为方便演示")]),t._v("\n\tctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tpubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/users"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("POST")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Body注入,根据contentType将HTTP正文解析为一个结构体,支持json、xml、form-data、x-www-form-urlencoded 等 contentType")]),t._v("\n\t\t\treq "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("User "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ListUsers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/page"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tquery domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("PageQuery "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Query注入")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("PageUsers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("query"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tid "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Url参数注入,将注入路由上定义的`:id`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetUserById")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("PUT")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tid "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Url参数注入,将注入路由上定义的`:id`")]),t._v("\n\t\t\treq "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("User "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Body注入")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UpdateUserById")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("DELETE")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/:id"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tid "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,param"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//Url参数注入,将注入路由上定义的`:id`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("DeleteUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("id"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),s("p",[t._v("上面代码截取于"),s("code",[t._v("internal/controller/demo_ctr.go")]),t._v("文件。")]),t._v(" "),s("h3",{attrs:{id:"http-注入"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#http-注入"}},[t._v("#")]),t._v(" HTTP 注入")]),t._v(" "),s("p",[t._v("可以看到,"),s("strong",[t._v("Gone")]),t._v("在路由处理函数上也支持了"),s("strong",[t._v("依赖注入")]),t._v(";注入的方式是在使用一个匿名结构体作为处理函数的入参,并给结构体属性做特殊标记。\n上面代码用的注入标签:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v('gone:"http,body"')]),t._v(",Body注入,根据contentType将HTTP正文解析为一个结构体,支持json、xml、form-data、x-www-form-urlencoded 等 contentType,要求被注入的结构体属性的数据类型为"),s("strong",[t._v("结构体")]),t._v("或者"),s("strong",[t._v("结构体指针")]),t._v(";")]),t._v(" "),s("li",[s("code",[t._v('gone:"http,query"')]),t._v(",Query注入,被注入的结构体属性的数据类型可以为"),s("strong",[t._v("结构体")]),t._v("、"),s("strong",[t._v("结构体指针")]),t._v("、"),s("strong",[t._v("字符串")]),t._v("、"),s("strong",[t._v("Number(int、uint、float64 ...)")]),t._v(" 和 "),s("strong",[t._v("字符串或Number的Slice")]),t._v(";")]),t._v(" "),s("li",[s("code",[t._v('gone:"http,param"')]),t._v(",Url参数注入,将注入路由上定义的参数;要求被注入的结构体属性的数据类型为"),s("strong",[t._v("字符串")]),t._v("或"),s("strong",[t._v("Number类型")]),t._v("。")])]),t._v(" "),s("p",[t._v("下面对Query注入,句几个例子:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Q "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n Page "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`form:"page"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用form标签指定参数名为page,默认是属性名Page")]),t._v("\n PageSize "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`form:"pageSize"`')]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用form标签指定参数名为pageSize,默认是属性名PageSize")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("handle")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n page "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//未指定query参数名,去属性名为key")]),t._v("\n thePage "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=page"`')]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//指定query参数名为page")]),t._v("\n size "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=pageSize`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//指定query参数名为pageSize")]),t._v("\n\n q "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Q "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//被注入类型为一个结构体")]),t._v("\n keywords "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=keywords"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用数组结构,允许Query参数出现多次")]),t._v("\n oneKeyword "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=keywords"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//不使用数组,只获取Query中的第一个keyword")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("假设某个请求的Query为:"),s("code",[t._v("?page=10&pageSize=20&keywords=today&keywords=weather")]),t._v(",使用上面"),s("code",[t._v("handle")]),t._v("处理请求,参数"),s("code",[t._v("in")]),t._v("的值如下:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("in.page")]),t._v(" = 10")]),t._v(" "),s("li",[s("code",[t._v("in.thePage")]),t._v(" = 10")]),t._v(" "),s("li",[s("code",[t._v("in.size")]),t._v(" = 20")]),t._v(" "),s("li",[s("code",[t._v("in.q")]),t._v(" = {Page = 10, PageSize = 20}")]),t._v(" "),s("li",[s("code",[t._v("in.keywords")]),t._v(" = [today, weather]")]),t._v(" "),s("li",[s("code",[t._v("in.oneKeyword")]),t._v(" = today")])]),t._v(" "),s("p",[t._v("另外,处理函数还支持注入一些特殊结构体或指针(推荐使用指针):")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("gone.Content")]),t._v(" 请求上下文")]),t._v(" "),s("li",[s("code",[t._v("http.Request")]),t._v(" Http请求")]),t._v(" "),s("li",[s("code",[t._v("http.Header")]),t._v(" 请求头")]),t._v(" "),s("li",[s("code",[t._v("url.Url")]),t._v(" url")])]),t._v(" "),s("p",[t._v("框架还支持更多的注入标签和类型,请参考文档"),s("a",{attrs:{href:"https://goner.fun/zh/references/http-inject.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("http 注入说明"),s("OutboundLink")],1)]),t._v(" "),s("h3",{attrs:{id:"请求处理函数参数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#请求处理函数参数"}},[t._v("#")]),t._v(" 请求处理函数参数")]),t._v(" "),s("p",[t._v("请求处理函数返回参数可以为如下几种形式:")]),t._v(" "),s("ol",[s("li",[t._v("不返回参数")]),t._v(" "),s("li",[t._v("返回一个非"),s("code",[t._v("error")]),t._v("的参数")]),t._v(" "),s("li",[t._v("返回数据和"),s("code",[t._v("error")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/30.53f48173.js b/assets/js/30.6c8b9751.js similarity index 97% rename from assets/js/30.53f48173.js rename to assets/js/30.6c8b9751.js index 5d3e7a9..b37dcbd 100644 --- a/assets/js/30.53f48173.js +++ b/assets/js/30.6c8b9751.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[30],{322:function(t,e,o){"use strict";o.r(e);var r=o(10),a=Object(r.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"development-guide"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#development-guide"}},[t._v("#")]),t._v(" Development Guide")]),t._v(" "),e("h2",{attrs:{id:"core-concepts-of-gone"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#core-concepts-of-gone"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/core-concept.html"}},[t._v("Core Concepts of Gone")])],1),t._v(" "),e("h2",{attrs:{id:"what-injection-methods-does-gone-support"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#what-injection-methods-does-gone-support"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/goner-inject.html"}},[t._v("What Injection Methods Does Gone Support?")])],1),t._v(" "),e("h2",{attrs:{id:"how-to-gracefully-use-built-in-goners"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#how-to-gracefully-use-built-in-goners"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/use-inner-goner.html"}},[t._v("How to Gracefully Use Built-in Goners?")])],1),t._v(" "),e("h2",{attrs:{id:"supporting-configuration-files-via-built-in-goners"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#supporting-configuration-files-via-built-in-goners"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/config.html"}},[t._v("Supporting Configuration Files via Built-in Goners")])],1),t._v(" "),e("h2",{attrs:{id:"supporting-database-connections-via-built-in-goners"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#supporting-database-connections-via-built-in-goners"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/xorm.html"}},[t._v("Supporting Database Connections via Built-in Goners")])],1),t._v(" "),e("h2",{attrs:{id:"hook-functions"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#hook-functions"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/hooks.html"}},[t._v("Hook Functions")])],1),t._v(" "),e("h2",{attrs:{id:"logging-output"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#logging-output"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/logrus.html"}},[t._v("Logging Output")])],1),t._v(" "),e("h2",{attrs:{id:"tracing-logs-with-traceid"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#tracing-logs-with-traceid"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/tracer.html"}},[t._v("Tracing Logs with TraceID")])],1),t._v(" "),e("h2",{attrs:{id:"auto-generating-priests"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#auto-generating-priests"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/auto-gen-priest.html"}},[t._v("Auto-generating Priests")])],1)])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[30],{314:function(t,e,o){"use strict";o.r(e);var r=o(10),a=Object(r.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"development-guide"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#development-guide"}},[t._v("#")]),t._v(" Development Guide")]),t._v(" "),e("h2",{attrs:{id:"core-concepts-of-gone"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#core-concepts-of-gone"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/core-concept.html"}},[t._v("Core Concepts of Gone")])],1),t._v(" "),e("h2",{attrs:{id:"what-injection-methods-does-gone-support"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#what-injection-methods-does-gone-support"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/goner-inject.html"}},[t._v("What Injection Methods Does Gone Support?")])],1),t._v(" "),e("h2",{attrs:{id:"how-to-gracefully-use-built-in-goners"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#how-to-gracefully-use-built-in-goners"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/use-inner-goner.html"}},[t._v("How to Gracefully Use Built-in Goners?")])],1),t._v(" "),e("h2",{attrs:{id:"supporting-configuration-files-via-built-in-goners"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#supporting-configuration-files-via-built-in-goners"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/config.html"}},[t._v("Supporting Configuration Files via Built-in Goners")])],1),t._v(" "),e("h2",{attrs:{id:"supporting-database-connections-via-built-in-goners"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#supporting-database-connections-via-built-in-goners"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/xorm.html"}},[t._v("Supporting Database Connections via Built-in Goners")])],1),t._v(" "),e("h2",{attrs:{id:"hook-functions"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#hook-functions"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/hooks.html"}},[t._v("Hook Functions")])],1),t._v(" "),e("h2",{attrs:{id:"logging-output"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#logging-output"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/logrus.html"}},[t._v("Logging Output")])],1),t._v(" "),e("h2",{attrs:{id:"tracing-logs-with-traceid"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#tracing-logs-with-traceid"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/tracer.html"}},[t._v("Tracing Logs with TraceID")])],1),t._v(" "),e("h2",{attrs:{id:"auto-generating-priests"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#auto-generating-priests"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/guide/auto-gen-priest.html"}},[t._v("Auto-generating Priests")])],1)])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/32.29926225.js b/assets/js/32.33250e7a.js similarity index 99% rename from assets/js/32.29926225.js rename to assets/js/32.33250e7a.js index d31a37f..7cd66e0 100644 --- a/assets/js/32.29926225.js +++ b/assets/js/32.33250e7a.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[32],{314:function(t,n,e){"use strict";e.r(n);var a=e(10),s=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"configuring-with-built-in-goners-support"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuring-with-built-in-goners-support"}},[t._v("#")]),t._v(" Configuring with Built-in Goners Support")]),t._v(" "),n("p"),n("div",{staticClass:"table-of-contents"},[n("ul",[n("li",[n("a",{attrs:{href:"#example"}},[t._v("Example")]),n("ul",[n("li",[n("a",{attrs:{href:"#_1-create-a-mod"}},[t._v("1. Create a mod")])]),n("li",[n("a",{attrs:{href:"#_2-add-a-configuration-file"}},[t._v("2. Add a configuration file")])]),n("li",[n("a",{attrs:{href:"#_3-add-code"}},[t._v("3. Add code")])]),n("li",[n("a",{attrs:{href:"#_4-run"}},[t._v("4. Run")])])])]),n("li",[n("a",{attrs:{href:"#configuration-injection"}},[t._v("Configuration Injection")]),n("ul",[n("li",[n("a",{attrs:{href:"#tag-format-used"}},[t._v("Tag Format Used")])]),n("li",[n("a",{attrs:{href:"#supported-data-types-for-injection"}},[t._v("Supported Data Types for Injection")])]),n("li",[n("a",{attrs:{href:"#configuration-files"}},[t._v("Configuration Files")])])])])])]),n("p"),t._v(" "),n("p",[t._v("Gone provides a method to read configuration files using the built-in Goners. Currently, the configuration file format is only supported in "),n("code",[t._v(".properties")]),t._v(".")]),t._v(" "),n("h2",{attrs:{id:"example"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#example"}},[t._v("#")]),t._v(" Example")]),t._v(" "),n("blockquote",[n("p",[t._v("You can find the source code of the example "),n("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-config",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),n("OutboundLink")],1),t._v(".")])]),t._v(" "),n("h3",{attrs:{id:"_1-create-a-mod"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_1-create-a-mod"}},[t._v("#")]),t._v(" 1. Create a mod")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go mod init use-config\n")])])]),n("h3",{attrs:{id:"_2-add-a-configuration-file"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_2-add-a-configuration-file"}},[t._v("#")]),t._v(" 2. Add a configuration file")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" config\n"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" config/default.properties\n")])])]),n("p",[t._v("The content of the "),n("code",[t._v("config/default.properties")]),t._v(" file is as follows:")]),t._v(" "),n("div",{staticClass:"language-properties extra-class"},[n("pre",{pre:!0,attrs:{class:"language-properties"}},[n("code",[n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.int8")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("130")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10.222")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("config test")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.bool")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("true")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.duration")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10h")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.sub.x")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("100x")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.sub.y")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("200y")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[0].x")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("0000x")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[0].y")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("0000y")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[1].x")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("1111x")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[1].y")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("1111y")]),t._v("\n")])])]),n("h3",{attrs:{id:"_3-add-code"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_3-add-code"}},[t._v("#")]),t._v(" 3. Add code")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" main.go\n")])])]),n("p",[t._v("The content of the "),n("code",[t._v("main.go")]),t._v(" file is as follows:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"time"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SubConf "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tX "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`properties:"x"`')]),t._v("\n\tY "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`properties:"y"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" UseConfig "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int"`')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int8"`')]),t._v("\n\tprintInt "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int8"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// pointer to int")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.float64"`')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.string"`')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.bool"`')]),t._v("\n\tduration time"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Duration "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.duration"`')]),t._v("\n\tdefaultV "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.default,default=ok"`')]),t._v("\n\n\tsub "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("SubConf "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.sub"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// pointer to struct")]),t._v("\n\n\tsubs "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("SubConf "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.subs"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// array")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("UseConfig"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"int=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"int8=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"printInt=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("printInt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"float64=%f\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"string=%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"bool=%t\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"duration=%v\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("duration"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"defaultV=%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("defaultV"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"sub.x=%v\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("sub"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"subs=%v\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("subs"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("UseConfig"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h3",{attrs:{id:"_4-run"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_4-run"}},[t._v("#")]),t._v(" 4. Run")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go mod tidy\ngo run main.go\n")])])]),n("p",[t._v("The output will be as follows:")]),t._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("int=10\nint8=-126\nprintInt=130\nfloat64=10.222000\nstring=config test\nbool=true\nduration=10h0m0s\ndefaultV=ok\nsub.x=&{100x 200y}\nsubs=[{0000x 0000y} {1111x 1111y}]\n")])])]),n("h2",{attrs:{id:"configuration-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-injection"}},[t._v("#")]),t._v(" Configuration Injection")]),t._v(" "),n("p",[t._v('As seen from the example, configuration items can also be "dependency injected" into Goners.')]),t._v(" "),n("h3",{attrs:{id:"tag-format-used"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#tag-format-used"}},[t._v("#")]),t._v(" Tag Format Used")]),t._v(" "),n("p",[t._v("The tag format for configuration injection is as follows:")]),t._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v('gone:"config,${key},default=${defaultValue}"\n')])])]),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("Explanation:")]),t._v(" "),n("ol",[n("li",[t._v("The tag name remains "),n("code",[t._v("gone")]),t._v(".")]),t._v(" "),n("li",[n("code",[t._v("config")]),t._v(" is a fixed value, indicating that the property is a configuration.")]),t._v(" "),n("li",[n("code",[t._v("${key}")]),t._v(" represents the key in the configuration file.")]),t._v(" "),n("li",[n("code",[t._v("default=${defaultValue}")]),t._v(" is used to specify a default value, which can be omitted; "),n("code",[t._v("${defaultValue}")]),t._v(" is the default value. If no default value is specified and the corresponding key is missing in the configuration file, an error will be raised.")])])]),t._v(" "),n("h3",{attrs:{id:"supported-data-types-for-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#supported-data-types-for-injection"}},[t._v("#")]),t._v(" Supported Data Types for Injection")]),t._v(" "),n("blockquote",[n("p",[t._v("In the "),n("a",{attrs:{href:"https://goner.fun/guide/core-concept.html#goner-%E9%80%9D%E8%80%85",target:"_blank",rel:"noopener noreferrer"}},[t._v("Core Concepts - Goners"),n("OutboundLink")],1),t._v(", we mentioned that Goners can be injected into properties of other structures. Here, configuration, as a special case, can also be injected into properties of other structures. Its implementation is through "),n("a",{attrs:{href:"https://goner.fun/guide/core-concept.html#%F0%9F%A7%9B%F0%9F%8F%BB%E2%80%8D%E2%99%80%EF%B8%8Fvampire",target:"_blank",rel:"noopener noreferrer"}},[t._v("Vampire"),n("OutboundLink")],1),t._v(", if interested, you can refer to "),n("a",{attrs:{href:"https://github.com/gone-io/gone/tree/v0.1.5/goner/config",target:"_blank",rel:"noopener noreferrer"}},[t._v("this part of the source code"),n("OutboundLink")],1),t._v(".")])]),t._v(" "),n("p",[t._v("The supported types for properties are listed below:")]),t._v(" "),n("ol",[n("li",[t._v("Basic types\n"),n("ul",[n("li",[t._v("Boolean: bool")]),t._v(" "),n("li",[t._v("Integer types: int, int64, int32, int16, int8")]),t._v(" "),n("li",[t._v("Unsigned integer types: uint, uint64, uint32, uint16, uint8")]),t._v(" "),n("li",[t._v("Floating-point types: float64, float32")]),t._v(" "),n("li",[t._v("String type: string")])])])]),t._v(" "),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("For integer types and unsigned integer types, be cautious of the range they represent. If the number is too large, overflow may occur; for example, "),n("code",[t._v("int8")]),t._v(" represents the range "),n("code",[t._v("-128")]),t._v(" to "),n("code",[t._v("127")]),t._v(", so if a value larger than 127 is assigned, overflow will occur (assigning 128 will result in -128).")])]),t._v(" "),n("ol",{attrs:{start:"2"}},[n("li",[t._v("time.Duration\nFor convenient time parsing, "),n("code",[t._v("time.Duration")]),t._v(" type is supported in the configuration, and the following units can be used:\n"),n("ul",[n("li",[t._v("ns: nanoseconds")]),t._v(" "),n("li",[t._v("us: microseconds")]),t._v(" "),n("li",[t._v("ms: milliseconds")]),t._v(" "),n("li",[t._v("s: seconds")]),t._v(" "),n("li",[t._v("m: minutes")]),t._v(" "),n("li",[t._v("h: hours")])])])]),t._v(" "),n("p",[t._v("In the example, "),n("code",[t._v("my.conf.duration=10h")]),t._v(" represents 10 hours; "),n("code",[t._v("1h10m10s")]),t._v(" represents 1 hour, 10 minutes, and 10 seconds.")]),t._v(" "),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("Implementation uses "),n("code",[t._v("time.ParseDuration")]),t._v(", so you can refer to: "),n("a",{attrs:{href:"https://pkg.go.dev/time#ParseDuration",target:"_blank",rel:"noopener noreferrer"}},[t._v("https://pkg.go.dev/time#ParseDuration"),n("OutboundLink")],1),t._v(".")])]),t._v(" "),n("ol",{attrs:{start:"3"}},[n("li",[t._v("Struct types\nIn the example, the type of the configuration struct is provided. It needs to adhere to the following rules:\n"),n("ul",[n("li",[t._v("The properties in the struct to be configured must be public, i.e., starting with a capital letter.")]),t._v(" "),n("li",[t._v("Use the "),n("code",[t._v("properties")]),t._v(" tag to specify the name of the property.")]),t._v(" "),n("li",[t._v("Supports nesting.")])])])]),t._v(" "),n("p",[t._v("Explanation: In the example, the property "),n("code",[t._v("sub")]),t._v(" of "),n("code",[t._v("UseConfig")]),t._v(" reads the configuration key "),n("code",[t._v("my.conf.sub")]),t._v("; the type of "),n("code",[t._v("sub")]),t._v(" is "),n("code",[t._v("SubConf")]),t._v(", and the property "),n("code",[t._v("X")]),t._v(" is marked with the configuration name "),n("code",[t._v('properties:"x"')]),t._v(", so the value of "),n("code",[t._v("sub.X")]),t._v(" will be read from the configuration item "),n("code",[t._v("my.conf.sub.x")]),t._v(".")]),t._v(" "),n("ol",{attrs:{start:"4"}},[n("li",[t._v("Array types\nConfiguration injection supports the Slice type, and currently, the elements of the Slice support structs and pointers to structs. The key format for configuration is as follows:")])]),t._v(" "),n("div",{staticClass:"language-ini extra-class"},[n("pre",{pre:!0,attrs:{class:"language-ini"}},[n("code",[t._v("${injectConfigkey}[${index}].${structAttributeName}\n")])])]),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("Explanation")]),t._v(" "),n("ul",[n("li",[n("code",[t._v("${injectConfigkey}")]),t._v(" is the key of the item to be injected.")]),t._v(" "),n("li",[n("code",[t._v("${index}")]),t._v(" is the array index.")]),t._v(" "),n("li",[n("code",[t._v("${structAttributeName}")]),t._v(" is the value annotated on the property of the injected struct with the "),n("code",[t._v("properties")]),t._v(" tag.")])])]),t._v(" "),n("ol",{attrs:{start:"5"}},[n("li",[t._v("Pointer types\nSupports pointer types for injected properties.")])]),t._v(" "),n("h3",{attrs:{id:"configuration-files"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-files"}},[t._v("#")]),t._v(" Configuration Files")]),t._v(" "),n("h4",{attrs:{id:"configuration-file-directory"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-file-directory"}},[t._v("#")]),t._v(" Configuration File Directory")]),t._v(" "),n("p",[t._v("The directory where configuration files are stored is determined by three parts:")]),t._v(" "),n("ol",[n("li",[t._v("The executable file and the current working directory of the program.")]),t._v(" "),n("li",[t._v("Relative configuration directory\nThe relative configuration directory defaults to "),n("code",[t._v("config")]),t._v(", and can be changed by passing the "),n("code",[t._v("--conf $configDir")]),t._v(" parameter during startup.")])]),t._v(" "),n("p",[t._v("For example, if the compiled gone program is saved as "),n("code",[t._v("/app/gone-app")]),t._v(", and we run it from the "),n("code",[t._v("/home/degfy")]),t._v(" directory:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" /home/degfy/\n/app/gone-app\n")])])]),n("p",[t._v("And if the relative configuration directory is not modified by passing parameters, the configuration directory for the program would be:")]),t._v(" "),n("ul",[n("li",[t._v("/app/config")]),t._v(" "),n("li",[t._v("/home/degfy/config")])]),t._v(" "),n("h4",{attrs:{id:"default-configuration-file-path"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#default-configuration-file-path"}},[t._v("#")]),t._v(" Default Configuration File Path")]),t._v(" "),n("p",[t._v("Continuing from the previous example, the paths for configuration files would be:")]),t._v(" "),n("ul",[n("li",[t._v("/app/config/default.properties")]),t._v(" "),n("li",[t._v("/home/degfy/config/default.properties\nThese configuration files contain default configurations that do not change with the environment.")])]),t._v(" "),n("h4",{attrs:{id:"environment-specific-configuration-file-paths"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#environment-specific-configuration-file-paths"}},[t._v("#")]),t._v(" Environment-specific Configuration File Paths")]),t._v(" "),n("p",[t._v("During development, we typically use environment-specific configurations, such as:")]),t._v(" "),n("ul",[n("li",[t._v("local: Local development environment")]),t._v(" "),n("li",[t._v("dev: Development environment online")]),t._v(" "),n("li",[t._v("test: Testing environment online")]),t._v(" "),n("li",[t._v("prod: Production environment")])]),t._v(" "),n("p",[t._v("We can specify the current environment by setting the "),n("code",[t._v("ENV")]),t._v(" environment variable or passing the "),n("code",[t._v("--env $env")]),t._v(" parameter during startup. If neither is set, the default environment is "),n("code",[t._v("local")]),t._v(".\nContinuing from the previous example, the configuration files related to the environment would be:")]),t._v(" "),n("ul",[n("li",[t._v("/app/config/local.properties")]),t._v(" "),n("li",[t._v("/home/degfy/config/local.properties")])]),t._v(" "),n("h4",{attrs:{id:"configuration-loading-order"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-loading-order"}},[t._v("#")]),t._v(" Configuration Loading Order")]),t._v(" "),n("p",[t._v("As mentioned earlier, there are four configuration files when the program is started, and they are loaded in the following order:")]),t._v(" "),n("ol",[n("li",[t._v("/app/config/default.properties")]),t._v(" "),n("li",[t._v("/app/config/local.properties")]),t._v(" "),n("li",[t._v("/home/degfy/config/default.properties")]),t._v(" "),n("li",[t._v("/home/degfy/config/local.properties")])]),t._v(" "),n("p",[t._v("If the same configuration item exists in multiple files, the value from the file loaded later will override the value from the file loaded earlier. That is, environment-specific configurations override default configurations, and configurations from the current running directory override those from the program directory.")]),t._v(" "),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("Best Practices")]),t._v(" "),n("ol",[n("li",[t._v("Put all configurations in the default configuration file and override them in environment-specific configuration files as needed.")]),t._v(" "),n("li",[t._v('Design configurations with minimalism in mind and consider using a "convention over configuration" approach, where default values are provided whenever possible.')]),t._v(" "),n("li",[t._v('To make the code "ready out of the box," it\'s recommended to set up a complete configuration in '),n("code",[t._v("local.properties")]),t._v(" so that the program can run without any additional configuration, facilitating smooth startup for other team members who clone the codebase.")])])])])}),[],!1,null,null,null);n.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[32],{316:function(t,n,e){"use strict";e.r(n);var a=e(10),s=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"configuring-with-built-in-goners-support"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuring-with-built-in-goners-support"}},[t._v("#")]),t._v(" Configuring with Built-in Goners Support")]),t._v(" "),n("p"),n("div",{staticClass:"table-of-contents"},[n("ul",[n("li",[n("a",{attrs:{href:"#example"}},[t._v("Example")]),n("ul",[n("li",[n("a",{attrs:{href:"#_1-create-a-mod"}},[t._v("1. Create a mod")])]),n("li",[n("a",{attrs:{href:"#_2-add-a-configuration-file"}},[t._v("2. Add a configuration file")])]),n("li",[n("a",{attrs:{href:"#_3-add-code"}},[t._v("3. Add code")])]),n("li",[n("a",{attrs:{href:"#_4-run"}},[t._v("4. Run")])])])]),n("li",[n("a",{attrs:{href:"#configuration-injection"}},[t._v("Configuration Injection")]),n("ul",[n("li",[n("a",{attrs:{href:"#tag-format-used"}},[t._v("Tag Format Used")])]),n("li",[n("a",{attrs:{href:"#supported-data-types-for-injection"}},[t._v("Supported Data Types for Injection")])]),n("li",[n("a",{attrs:{href:"#configuration-files"}},[t._v("Configuration Files")])])])])])]),n("p"),t._v(" "),n("p",[t._v("Gone provides a method to read configuration files using the built-in Goners. Currently, the configuration file format is only supported in "),n("code",[t._v(".properties")]),t._v(".")]),t._v(" "),n("h2",{attrs:{id:"example"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#example"}},[t._v("#")]),t._v(" Example")]),t._v(" "),n("blockquote",[n("p",[t._v("You can find the source code of the example "),n("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-config",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),n("OutboundLink")],1),t._v(".")])]),t._v(" "),n("h3",{attrs:{id:"_1-create-a-mod"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_1-create-a-mod"}},[t._v("#")]),t._v(" 1. Create a mod")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go mod init use-config\n")])])]),n("h3",{attrs:{id:"_2-add-a-configuration-file"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_2-add-a-configuration-file"}},[t._v("#")]),t._v(" 2. Add a configuration file")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" config\n"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" config/default.properties\n")])])]),n("p",[t._v("The content of the "),n("code",[t._v("config/default.properties")]),t._v(" file is as follows:")]),t._v(" "),n("div",{staticClass:"language-properties extra-class"},[n("pre",{pre:!0,attrs:{class:"language-properties"}},[n("code",[n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.int8")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("130")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10.222")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("config test")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.bool")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("true")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.duration")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10h")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.sub.x")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("100x")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.sub.y")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("200y")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[0].x")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("0000x")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[0].y")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("0000y")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[1].x")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("1111x")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[1].y")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("1111y")]),t._v("\n")])])]),n("h3",{attrs:{id:"_3-add-code"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_3-add-code"}},[t._v("#")]),t._v(" 3. Add code")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" main.go\n")])])]),n("p",[t._v("The content of the "),n("code",[t._v("main.go")]),t._v(" file is as follows:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"time"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SubConf "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tX "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`properties:"x"`')]),t._v("\n\tY "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`properties:"y"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" UseConfig "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int"`')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int8"`')]),t._v("\n\tprintInt "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int8"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// pointer to int")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.float64"`')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.string"`')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.bool"`')]),t._v("\n\tduration time"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Duration "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.duration"`')]),t._v("\n\tdefaultV "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.default,default=ok"`')]),t._v("\n\n\tsub "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("SubConf "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.sub"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// pointer to struct")]),t._v("\n\n\tsubs "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("SubConf "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.subs"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// array")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("UseConfig"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"int=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"int8=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"printInt=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("printInt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"float64=%f\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"string=%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"bool=%t\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"duration=%v\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("duration"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"defaultV=%s\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("defaultV"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"sub.x=%v\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("sub"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"subs=%v\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("subs"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("UseConfig"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h3",{attrs:{id:"_4-run"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_4-run"}},[t._v("#")]),t._v(" 4. Run")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go mod tidy\ngo run main.go\n")])])]),n("p",[t._v("The output will be as follows:")]),t._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("int=10\nint8=-126\nprintInt=130\nfloat64=10.222000\nstring=config test\nbool=true\nduration=10h0m0s\ndefaultV=ok\nsub.x=&{100x 200y}\nsubs=[{0000x 0000y} {1111x 1111y}]\n")])])]),n("h2",{attrs:{id:"configuration-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-injection"}},[t._v("#")]),t._v(" Configuration Injection")]),t._v(" "),n("p",[t._v('As seen from the example, configuration items can also be "dependency injected" into Goners.')]),t._v(" "),n("h3",{attrs:{id:"tag-format-used"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#tag-format-used"}},[t._v("#")]),t._v(" Tag Format Used")]),t._v(" "),n("p",[t._v("The tag format for configuration injection is as follows:")]),t._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v('gone:"config,${key},default=${defaultValue}"\n')])])]),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("Explanation:")]),t._v(" "),n("ol",[n("li",[t._v("The tag name remains "),n("code",[t._v("gone")]),t._v(".")]),t._v(" "),n("li",[n("code",[t._v("config")]),t._v(" is a fixed value, indicating that the property is a configuration.")]),t._v(" "),n("li",[n("code",[t._v("${key}")]),t._v(" represents the key in the configuration file.")]),t._v(" "),n("li",[n("code",[t._v("default=${defaultValue}")]),t._v(" is used to specify a default value, which can be omitted; "),n("code",[t._v("${defaultValue}")]),t._v(" is the default value. If no default value is specified and the corresponding key is missing in the configuration file, an error will be raised.")])])]),t._v(" "),n("h3",{attrs:{id:"supported-data-types-for-injection"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#supported-data-types-for-injection"}},[t._v("#")]),t._v(" Supported Data Types for Injection")]),t._v(" "),n("blockquote",[n("p",[t._v("In the "),n("a",{attrs:{href:"https://goner.fun/guide/core-concept.html#goner-%E9%80%9D%E8%80%85",target:"_blank",rel:"noopener noreferrer"}},[t._v("Core Concepts - Goners"),n("OutboundLink")],1),t._v(", we mentioned that Goners can be injected into properties of other structures. Here, configuration, as a special case, can also be injected into properties of other structures. Its implementation is through "),n("a",{attrs:{href:"https://goner.fun/guide/core-concept.html#%F0%9F%A7%9B%F0%9F%8F%BB%E2%80%8D%E2%99%80%EF%B8%8Fvampire",target:"_blank",rel:"noopener noreferrer"}},[t._v("Vampire"),n("OutboundLink")],1),t._v(", if interested, you can refer to "),n("a",{attrs:{href:"https://github.com/gone-io/gone/tree/v0.1.5/goner/config",target:"_blank",rel:"noopener noreferrer"}},[t._v("this part of the source code"),n("OutboundLink")],1),t._v(".")])]),t._v(" "),n("p",[t._v("The supported types for properties are listed below:")]),t._v(" "),n("ol",[n("li",[t._v("Basic types\n"),n("ul",[n("li",[t._v("Boolean: bool")]),t._v(" "),n("li",[t._v("Integer types: int, int64, int32, int16, int8")]),t._v(" "),n("li",[t._v("Unsigned integer types: uint, uint64, uint32, uint16, uint8")]),t._v(" "),n("li",[t._v("Floating-point types: float64, float32")]),t._v(" "),n("li",[t._v("String type: string")])])])]),t._v(" "),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("For integer types and unsigned integer types, be cautious of the range they represent. If the number is too large, overflow may occur; for example, "),n("code",[t._v("int8")]),t._v(" represents the range "),n("code",[t._v("-128")]),t._v(" to "),n("code",[t._v("127")]),t._v(", so if a value larger than 127 is assigned, overflow will occur (assigning 128 will result in -128).")])]),t._v(" "),n("ol",{attrs:{start:"2"}},[n("li",[t._v("time.Duration\nFor convenient time parsing, "),n("code",[t._v("time.Duration")]),t._v(" type is supported in the configuration, and the following units can be used:\n"),n("ul",[n("li",[t._v("ns: nanoseconds")]),t._v(" "),n("li",[t._v("us: microseconds")]),t._v(" "),n("li",[t._v("ms: milliseconds")]),t._v(" "),n("li",[t._v("s: seconds")]),t._v(" "),n("li",[t._v("m: minutes")]),t._v(" "),n("li",[t._v("h: hours")])])])]),t._v(" "),n("p",[t._v("In the example, "),n("code",[t._v("my.conf.duration=10h")]),t._v(" represents 10 hours; "),n("code",[t._v("1h10m10s")]),t._v(" represents 1 hour, 10 minutes, and 10 seconds.")]),t._v(" "),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("Implementation uses "),n("code",[t._v("time.ParseDuration")]),t._v(", so you can refer to: "),n("a",{attrs:{href:"https://pkg.go.dev/time#ParseDuration",target:"_blank",rel:"noopener noreferrer"}},[t._v("https://pkg.go.dev/time#ParseDuration"),n("OutboundLink")],1),t._v(".")])]),t._v(" "),n("ol",{attrs:{start:"3"}},[n("li",[t._v("Struct types\nIn the example, the type of the configuration struct is provided. It needs to adhere to the following rules:\n"),n("ul",[n("li",[t._v("The properties in the struct to be configured must be public, i.e., starting with a capital letter.")]),t._v(" "),n("li",[t._v("Use the "),n("code",[t._v("properties")]),t._v(" tag to specify the name of the property.")]),t._v(" "),n("li",[t._v("Supports nesting.")])])])]),t._v(" "),n("p",[t._v("Explanation: In the example, the property "),n("code",[t._v("sub")]),t._v(" of "),n("code",[t._v("UseConfig")]),t._v(" reads the configuration key "),n("code",[t._v("my.conf.sub")]),t._v("; the type of "),n("code",[t._v("sub")]),t._v(" is "),n("code",[t._v("SubConf")]),t._v(", and the property "),n("code",[t._v("X")]),t._v(" is marked with the configuration name "),n("code",[t._v('properties:"x"')]),t._v(", so the value of "),n("code",[t._v("sub.X")]),t._v(" will be read from the configuration item "),n("code",[t._v("my.conf.sub.x")]),t._v(".")]),t._v(" "),n("ol",{attrs:{start:"4"}},[n("li",[t._v("Array types\nConfiguration injection supports the Slice type, and currently, the elements of the Slice support structs and pointers to structs. The key format for configuration is as follows:")])]),t._v(" "),n("div",{staticClass:"language-ini extra-class"},[n("pre",{pre:!0,attrs:{class:"language-ini"}},[n("code",[t._v("${injectConfigkey}[${index}].${structAttributeName}\n")])])]),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("Explanation")]),t._v(" "),n("ul",[n("li",[n("code",[t._v("${injectConfigkey}")]),t._v(" is the key of the item to be injected.")]),t._v(" "),n("li",[n("code",[t._v("${index}")]),t._v(" is the array index.")]),t._v(" "),n("li",[n("code",[t._v("${structAttributeName}")]),t._v(" is the value annotated on the property of the injected struct with the "),n("code",[t._v("properties")]),t._v(" tag.")])])]),t._v(" "),n("ol",{attrs:{start:"5"}},[n("li",[t._v("Pointer types\nSupports pointer types for injected properties.")])]),t._v(" "),n("h3",{attrs:{id:"configuration-files"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-files"}},[t._v("#")]),t._v(" Configuration Files")]),t._v(" "),n("h4",{attrs:{id:"configuration-file-directory"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-file-directory"}},[t._v("#")]),t._v(" Configuration File Directory")]),t._v(" "),n("p",[t._v("The directory where configuration files are stored is determined by three parts:")]),t._v(" "),n("ol",[n("li",[t._v("The executable file and the current working directory of the program.")]),t._v(" "),n("li",[t._v("Relative configuration directory\nThe relative configuration directory defaults to "),n("code",[t._v("config")]),t._v(", and can be changed by passing the "),n("code",[t._v("--conf $configDir")]),t._v(" parameter during startup.")])]),t._v(" "),n("p",[t._v("For example, if the compiled gone program is saved as "),n("code",[t._v("/app/gone-app")]),t._v(", and we run it from the "),n("code",[t._v("/home/degfy")]),t._v(" directory:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" /home/degfy/\n/app/gone-app\n")])])]),n("p",[t._v("And if the relative configuration directory is not modified by passing parameters, the configuration directory for the program would be:")]),t._v(" "),n("ul",[n("li",[t._v("/app/config")]),t._v(" "),n("li",[t._v("/home/degfy/config")])]),t._v(" "),n("h4",{attrs:{id:"default-configuration-file-path"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#default-configuration-file-path"}},[t._v("#")]),t._v(" Default Configuration File Path")]),t._v(" "),n("p",[t._v("Continuing from the previous example, the paths for configuration files would be:")]),t._v(" "),n("ul",[n("li",[t._v("/app/config/default.properties")]),t._v(" "),n("li",[t._v("/home/degfy/config/default.properties\nThese configuration files contain default configurations that do not change with the environment.")])]),t._v(" "),n("h4",{attrs:{id:"environment-specific-configuration-file-paths"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#environment-specific-configuration-file-paths"}},[t._v("#")]),t._v(" Environment-specific Configuration File Paths")]),t._v(" "),n("p",[t._v("During development, we typically use environment-specific configurations, such as:")]),t._v(" "),n("ul",[n("li",[t._v("local: Local development environment")]),t._v(" "),n("li",[t._v("dev: Development environment online")]),t._v(" "),n("li",[t._v("test: Testing environment online")]),t._v(" "),n("li",[t._v("prod: Production environment")])]),t._v(" "),n("p",[t._v("We can specify the current environment by setting the "),n("code",[t._v("ENV")]),t._v(" environment variable or passing the "),n("code",[t._v("--env $env")]),t._v(" parameter during startup. If neither is set, the default environment is "),n("code",[t._v("local")]),t._v(".\nContinuing from the previous example, the configuration files related to the environment would be:")]),t._v(" "),n("ul",[n("li",[t._v("/app/config/local.properties")]),t._v(" "),n("li",[t._v("/home/degfy/config/local.properties")])]),t._v(" "),n("h4",{attrs:{id:"configuration-loading-order"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#configuration-loading-order"}},[t._v("#")]),t._v(" Configuration Loading Order")]),t._v(" "),n("p",[t._v("As mentioned earlier, there are four configuration files when the program is started, and they are loaded in the following order:")]),t._v(" "),n("ol",[n("li",[t._v("/app/config/default.properties")]),t._v(" "),n("li",[t._v("/app/config/local.properties")]),t._v(" "),n("li",[t._v("/home/degfy/config/default.properties")]),t._v(" "),n("li",[t._v("/home/degfy/config/local.properties")])]),t._v(" "),n("p",[t._v("If the same configuration item exists in multiple files, the value from the file loaded later will override the value from the file loaded earlier. That is, environment-specific configurations override default configurations, and configurations from the current running directory override those from the program directory.")]),t._v(" "),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("Best Practices")]),t._v(" "),n("ol",[n("li",[t._v("Put all configurations in the default configuration file and override them in environment-specific configuration files as needed.")]),t._v(" "),n("li",[t._v('Design configurations with minimalism in mind and consider using a "convention over configuration" approach, where default values are provided whenever possible.')]),t._v(" "),n("li",[t._v('To make the code "ready out of the box," it\'s recommended to set up a complete configuration in '),n("code",[t._v("local.properties")]),t._v(" so that the program can run without any additional configuration, facilitating smooth startup for other team members who clone the codebase.")])])])])}),[],!1,null,null,null);n.default=s.exports}}]); \ No newline at end of file diff --git a/assets/js/33.59d0548b.js b/assets/js/33.31f40be6.js similarity index 99% rename from assets/js/33.59d0548b.js rename to assets/js/33.31f40be6.js index aa900e0..68d263c 100644 --- a/assets/js/33.59d0548b.js +++ b/assets/js/33.31f40be6.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[33],{325:function(t,e,s){"use strict";s.r(e);var n=s(10),a=Object(n.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"core-concepts-of-gone"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#core-concepts-of-gone"}},[t._v("#")]),t._v(" Core Concepts of Gone")]),t._v(" "),e("p",[t._v("\"Our code, after all, is just lifeless matter, unless it's resurrected in "),e("strong",[t._v("Heaven")]),t._v("; for that, we need to "),e("strong",[t._v("bury")]),t._v(" it in a "),e("strong",[t._v("Cemetery")]),t._v('."')]),t._v(" "),e("h2",{attrs:{id:"goner"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#goner"}},[t._v("#")]),t._v(" Goner")]),t._v(" "),e("p",[t._v("In the Gone framework, the most fundamental and core concept is "),e("strong",[t._v("Goner")]),t._v(", which refers to a structure anonymously embedded with "),e("code",[t._v("gone.Flag")]),t._v(". For example:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("Goner serves as a component in the Gone framework and is crucial for implementing dependency injection:")]),t._v(" "),e("ol",[e("li",[t._v("A Goner can be injected as a property into other structures.")]),t._v(" "),e("li",[t._v("The properties of a Goner can be injected into other types.")])]),t._v(" "),e("p",[t._v("The reason for embedding a "),e("code",[t._v("gone.Flag")]),t._v(" is to limit the scope of dependency injection, ensuring that injection occurs only among Goners, thereby providing a unified pattern for component implementation in the Gone framework.")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),e("p",[t._v("Below is the source code for Goner and gone.Flag:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Flag "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Flag"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("goneFlag")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner represents the deceased.")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Goner "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("goneFlag")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("As an interface, Goner demands that objects implementing it have a private method "),e("code",[t._v("goneFlag()")]),t._v(". Due to Go's visibility restrictions, it's not possible to implement the internally defined private method "),e("code",[t._v("goneFlag()")]),t._v(" outside the "),e("code",[t._v("github.com/gone-io/gone")]),t._v(" package. Therefore, a structure can only become a Goner by embedding "),e("code",[t._v("gone.Flag")]),t._v(". This might be a bit complex, but essentially, it means that implementing Goner can only be achieved by embedding "),e("code",[t._v("gone.Flag")]),t._v(", not by directly implementing the "),e("code",[t._v("goneFlag()")]),t._v(" method.")])]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),e("p",[t._v("When referring to multiple Goners, we use the plural form "),e("strong",[t._v("Goners")]),t._v(".")])]),t._v(" "),e("p",[t._v("The Gone framework also includes three special types of Goners:")]),t._v(" "),e("h3",{attrs:{id:"🔮-prophet"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#🔮-prophet"}},[t._v("#")]),t._v(" 🔮 Prophet")]),t._v(" "),e("p",[t._v("A special type of "),e("strong",[t._v("Goner")]),t._v(" that implements the "),e("strong",[e("code",[t._v("AfterRevive() AfterReviveError")])]),t._v(" method on regular "),e("strong",[t._v("Goners")]),t._v("; "),e("strong",[t._v("Prophet")]),t._v("'s "),e("strong",[t._v("AfterRevive")]),t._v(" is executed after a "),e("strong",[t._v("Goner")]),t._v(" is resurrected.")]),t._v(" "),e("p",[t._v("The Prophet interface is defined as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Prophet represents the prophet.")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Prophet "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive is executed after the Goner is revived.")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" AfterReviveError\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h3",{attrs:{id:"😇-angel"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#😇-angel"}},[t._v("#")]),t._v(" 😇 Angel")]),t._v(" "),e("p",[t._v("A special type of "),e("strong",[t._v("Goner")]),t._v(" possessing the angelic powers of "),e("strong",[e("code",[t._v("Start(Cemetery) error")])]),t._v(" on its left wing and "),e("strong",[e("code",[t._v("Stop(Cemetery) error")])]),t._v(" on its right wing, responsible for initiating (allocating resources, starting a service) and terminating (stopping a service, reclaiming resources) tasks, respectively.")]),t._v(" "),e("p",[t._v("The Angel interface is defined as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Angel "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Start")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Stop")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h3",{attrs:{id:"🧛🏻‍♀️-vampire"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#🧛🏻‍♀️-vampire"}},[t._v("#")]),t._v(" 🧛🏻‍♀️ Vampire")]),t._v(" "),e("p",[t._v("A special type of "),e("strong",[t._v("Goner")]),t._v(" with a unique ability — sucking with "),e("strong",[e("code",[t._v("Suck(conf string, v reflect.Value) SuckError")])]),t._v(". "),e("strong",[t._v("Suck")]),t._v(" enables injecting values that are not Goners into Goners' properties.")]),t._v(" "),e("p",[t._v("The Vampire interface is defined as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SuckError "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Vampire "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Suck")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("conf "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" v reflect"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Value"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" SuckError\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h2",{attrs:{id:"cemetery"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#cemetery"}},[t._v("#")]),t._v(" Cemetery")]),t._v(" "),e("p",[t._v("Cemetery is used to manage Goners, primarily providing methods for "),e("strong",[t._v("Burying")]),t._v(" and "),e("strong",[t._v("Reviving")]),t._v(" Goners. Its interface is defined as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Cemetery "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ... Other methods")]),t._v("\n\tGoner\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Goner"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("GonerId"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" Cemetery "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Burying a Goner in the Cemetery")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ReviveAllFromTombs revives all Goners.")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("ReviveAllFromTombs")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("From the code, it's evident that Cemetery itself is a Goner, automatically buried and resurrected when the Gone framework starts.")]),t._v(" "),e("h3",{attrs:{id:"burying"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#burying"}},[t._v("#")]),t._v(" Burying")]),t._v(" "),e("p",[t._v("Burying a Goner in a Cemetery means registering the Goner with the framework for later property injection. In code implementation, "),e("strong",[t._v("Bury")]),t._v(" is a public method of "),e("strong",[t._v("Cemetery")]),t._v(", typically called through the "),e("strong",[t._v("Priest")]),t._v(" function.")]),t._v(" "),e("h3",{attrs:{id:"reviving"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#reviving"}},[t._v("#")]),t._v(" Reviving")]),t._v(" "),e("p",[t._v("Reviving entails completing the injection of properties required by a Goner. In the "),e("code",[t._v("ReviveAllFromTombs() error")]),t._v(" function, all Goners buried in the Cemetery are attempted to be revived. If any property injection fails, the program panics.")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),e("p",[t._v("After reviving all Goners, "),e("strong",[t._v("ReviveAllFromTombs")]),t._v(" calls the "),e("strong",[t._v("AfterRevive")]),t._v(" method of all "),e("strong",[t._v("Prophets")]),t._v(".")])]),t._v(" "),e("h2",{attrs:{id:"heaven"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#heaven"}},[t._v("#")]),t._v(" Heaven")]),t._v(" "),e("p",[t._v("Heaven represents a Gone program, responsible for managing the program's startup, shutdown, and associated processes (resurrection completed before startup). It facilitates executing certain hook tasks before and after startup and before program termination. Heaven accepts a priest function to begin its operation, as shown below:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Call cemetery.Bury to bury Goners")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Or call other Priest functions")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// TODO")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("Or:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Call cemetery.Bury to bury Goners")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Or call other Priest functions")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// TODO")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//TODO: Perform operations after startup")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h2",{attrs:{id:"priest"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#priest"}},[t._v("#")]),t._v(" Priest")]),t._v(" "),e("p",[t._v("Priest is a function responsible for burying Goners in the Cemetery. Its definition is as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Priest "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n")])])]),e("p",[t._v("In the implementation of the "),e("strong",[t._v("Priest")]),t._v(" function, you can call "),e("strong",[t._v("cemetery.Bury")]),t._v(" to accomplish this, as shown below:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("aPriest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Jim"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"boss-jim"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Bob"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"worker-bob"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Anonymous burial, not specifying the GonerId of the buried Goner")]),t._v("\n\tcemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"X"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),e("p",[t._v("Alternatively, you can accomplish this by calling other "),e("strong",[t._v("Priest")]),t._v(" functions:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("a1Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("a2Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("aPriest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("a1Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("a2Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("If we develop a component package where multiple "),e("strong",[t._v("Goners")]),t._v(" are used to accomplish various functionalities, and we need to "),e("strong",[t._v("bury")]),t._v(" these "),e("strong",[t._v("Goners")]),t._v(" simultaneously when using them, we can write a "),e("strong",[t._v("Priest")]),t._v(" function to facilitate bulk "),e("strong",[t._v("burying")]),t._v(" of these "),e("strong",[t._v("Goners")]),t._v(" in business code.")]),t._v(" "),e("p",[t._v("That's exactly what we do with the built-in component package of the framework. Here's how it's done, along with the "),e("a",{attrs:{href:"https://github.com/gone-io/gone/blob/main/goner/priest.go",target:"_blank",rel:"noopener noreferrer"}},[t._v("code"),e("OutboundLink")],1),t._v(" and "),e("a",{attrs:{href:"https://goner.fun/goners/#%E6%A1%86%E6%9E%B6%E5%86%85%E7%BD%AEgoners",target:"_blank",rel:"noopener noreferrer"}},[t._v("documentation"),e("OutboundLink")],1),t._v(".")]),t._v(" "),e("p",[t._v("Additionally, we've developed a command-line utility called "),e("strong",[t._v("gone")]),t._v(", which scans for special comments "),e("code",[t._v("//go:gone")]),t._v(" to automatically generate "),e("strong",[t._v("Priest")]),t._v(" functions. You can refer to "),e("RouterLink",{attrs:{to:"/guide/auto-gen-priest.html"}},[t._v("Auto-generating Priest")]),t._v(" for more information.")],1)])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[33],{317:function(t,e,s){"use strict";s.r(e);var n=s(10),a=Object(n.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"core-concepts-of-gone"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#core-concepts-of-gone"}},[t._v("#")]),t._v(" Core Concepts of Gone")]),t._v(" "),e("p",[t._v("\"Our code, after all, is just lifeless matter, unless it's resurrected in "),e("strong",[t._v("Heaven")]),t._v("; for that, we need to "),e("strong",[t._v("bury")]),t._v(" it in a "),e("strong",[t._v("Cemetery")]),t._v('."')]),t._v(" "),e("h2",{attrs:{id:"goner"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#goner"}},[t._v("#")]),t._v(" Goner")]),t._v(" "),e("p",[t._v("In the Gone framework, the most fundamental and core concept is "),e("strong",[t._v("Goner")]),t._v(", which refers to a structure anonymously embedded with "),e("code",[t._v("gone.Flag")]),t._v(". For example:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("Goner serves as a component in the Gone framework and is crucial for implementing dependency injection:")]),t._v(" "),e("ol",[e("li",[t._v("A Goner can be injected as a property into other structures.")]),t._v(" "),e("li",[t._v("The properties of a Goner can be injected into other types.")])]),t._v(" "),e("p",[t._v("The reason for embedding a "),e("code",[t._v("gone.Flag")]),t._v(" is to limit the scope of dependency injection, ensuring that injection occurs only among Goners, thereby providing a unified pattern for component implementation in the Gone framework.")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),e("p",[t._v("Below is the source code for Goner and gone.Flag:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Flag "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Flag"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("goneFlag")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner represents the deceased.")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Goner "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("goneFlag")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("As an interface, Goner demands that objects implementing it have a private method "),e("code",[t._v("goneFlag()")]),t._v(". Due to Go's visibility restrictions, it's not possible to implement the internally defined private method "),e("code",[t._v("goneFlag()")]),t._v(" outside the "),e("code",[t._v("github.com/gone-io/gone")]),t._v(" package. Therefore, a structure can only become a Goner by embedding "),e("code",[t._v("gone.Flag")]),t._v(". This might be a bit complex, but essentially, it means that implementing Goner can only be achieved by embedding "),e("code",[t._v("gone.Flag")]),t._v(", not by directly implementing the "),e("code",[t._v("goneFlag()")]),t._v(" method.")])]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),e("p",[t._v("When referring to multiple Goners, we use the plural form "),e("strong",[t._v("Goners")]),t._v(".")])]),t._v(" "),e("p",[t._v("The Gone framework also includes three special types of Goners:")]),t._v(" "),e("h3",{attrs:{id:"🔮-prophet"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#🔮-prophet"}},[t._v("#")]),t._v(" 🔮 Prophet")]),t._v(" "),e("p",[t._v("A special type of "),e("strong",[t._v("Goner")]),t._v(" that implements the "),e("strong",[e("code",[t._v("AfterRevive() AfterReviveError")])]),t._v(" method on regular "),e("strong",[t._v("Goners")]),t._v("; "),e("strong",[t._v("Prophet")]),t._v("'s "),e("strong",[t._v("AfterRevive")]),t._v(" is executed after a "),e("strong",[t._v("Goner")]),t._v(" is resurrected.")]),t._v(" "),e("p",[t._v("The Prophet interface is defined as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Prophet represents the prophet.")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Prophet "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// AfterRevive is executed after the Goner is revived.")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" AfterReviveError\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h3",{attrs:{id:"😇-angel"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#😇-angel"}},[t._v("#")]),t._v(" 😇 Angel")]),t._v(" "),e("p",[t._v("A special type of "),e("strong",[t._v("Goner")]),t._v(" possessing the angelic powers of "),e("strong",[e("code",[t._v("Start(Cemetery) error")])]),t._v(" on its left wing and "),e("strong",[e("code",[t._v("Stop(Cemetery) error")])]),t._v(" on its right wing, responsible for initiating (allocating resources, starting a service) and terminating (stopping a service, reclaiming resources) tasks, respectively.")]),t._v(" "),e("p",[t._v("The Angel interface is defined as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Angel "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Start")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Stop")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h3",{attrs:{id:"🧛🏻‍♀️-vampire"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#🧛🏻‍♀️-vampire"}},[t._v("#")]),t._v(" 🧛🏻‍♀️ Vampire")]),t._v(" "),e("p",[t._v("A special type of "),e("strong",[t._v("Goner")]),t._v(" with a unique ability — sucking with "),e("strong",[e("code",[t._v("Suck(conf string, v reflect.Value) SuckError")])]),t._v(". "),e("strong",[t._v("Suck")]),t._v(" enables injecting values that are not Goners into Goners' properties.")]),t._v(" "),e("p",[t._v("The Vampire interface is defined as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SuckError "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Vampire "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Suck")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("conf "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" v reflect"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Value"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" SuckError\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h2",{attrs:{id:"cemetery"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#cemetery"}},[t._v("#")]),t._v(" Cemetery")]),t._v(" "),e("p",[t._v("Cemetery is used to manage Goners, primarily providing methods for "),e("strong",[t._v("Burying")]),t._v(" and "),e("strong",[t._v("Reviving")]),t._v(" Goners. Its interface is defined as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Cemetery "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ... Other methods")]),t._v("\n\tGoner\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Goner"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("GonerId"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" Cemetery "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Burying a Goner in the Cemetery")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ReviveAllFromTombs revives all Goners.")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("ReviveAllFromTombs")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("From the code, it's evident that Cemetery itself is a Goner, automatically buried and resurrected when the Gone framework starts.")]),t._v(" "),e("h3",{attrs:{id:"burying"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#burying"}},[t._v("#")]),t._v(" Burying")]),t._v(" "),e("p",[t._v("Burying a Goner in a Cemetery means registering the Goner with the framework for later property injection. In code implementation, "),e("strong",[t._v("Bury")]),t._v(" is a public method of "),e("strong",[t._v("Cemetery")]),t._v(", typically called through the "),e("strong",[t._v("Priest")]),t._v(" function.")]),t._v(" "),e("h3",{attrs:{id:"reviving"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#reviving"}},[t._v("#")]),t._v(" Reviving")]),t._v(" "),e("p",[t._v("Reviving entails completing the injection of properties required by a Goner. In the "),e("code",[t._v("ReviveAllFromTombs() error")]),t._v(" function, all Goners buried in the Cemetery are attempted to be revived. If any property injection fails, the program panics.")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),e("p",[t._v("After reviving all Goners, "),e("strong",[t._v("ReviveAllFromTombs")]),t._v(" calls the "),e("strong",[t._v("AfterRevive")]),t._v(" method of all "),e("strong",[t._v("Prophets")]),t._v(".")])]),t._v(" "),e("h2",{attrs:{id:"heaven"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#heaven"}},[t._v("#")]),t._v(" Heaven")]),t._v(" "),e("p",[t._v("Heaven represents a Gone program, responsible for managing the program's startup, shutdown, and associated processes (resurrection completed before startup). It facilitates executing certain hook tasks before and after startup and before program termination. Heaven accepts a priest function to begin its operation, as shown below:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Call cemetery.Bury to bury Goners")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Or call other Priest functions")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// TODO")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("Or:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Call cemetery.Bury to bury Goners")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Or call other Priest functions")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// TODO")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//TODO: Perform operations after startup")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h2",{attrs:{id:"priest"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#priest"}},[t._v("#")]),t._v(" Priest")]),t._v(" "),e("p",[t._v("Priest is a function responsible for burying Goners in the Cemetery. Its definition is as follows:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Priest "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n")])])]),e("p",[t._v("In the implementation of the "),e("strong",[t._v("Priest")]),t._v(" function, you can call "),e("strong",[t._v("cemetery.Bury")]),t._v(" to accomplish this, as shown below:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("aPriest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Jim"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"boss-jim"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Bob"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"worker-bob"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Anonymous burial, not specifying the GonerId of the buried Goner")]),t._v("\n\tcemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"X"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),e("p",[t._v("Alternatively, you can accomplish this by calling other "),e("strong",[t._v("Priest")]),t._v(" functions:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("a1Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("a2Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("aPriest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("a1Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("a2Priest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("If we develop a component package where multiple "),e("strong",[t._v("Goners")]),t._v(" are used to accomplish various functionalities, and we need to "),e("strong",[t._v("bury")]),t._v(" these "),e("strong",[t._v("Goners")]),t._v(" simultaneously when using them, we can write a "),e("strong",[t._v("Priest")]),t._v(" function to facilitate bulk "),e("strong",[t._v("burying")]),t._v(" of these "),e("strong",[t._v("Goners")]),t._v(" in business code.")]),t._v(" "),e("p",[t._v("That's exactly what we do with the built-in component package of the framework. Here's how it's done, along with the "),e("a",{attrs:{href:"https://github.com/gone-io/gone/blob/main/goner/priest.go",target:"_blank",rel:"noopener noreferrer"}},[t._v("code"),e("OutboundLink")],1),t._v(" and "),e("a",{attrs:{href:"https://goner.fun/goners/#%E6%A1%86%E6%9E%B6%E5%86%85%E7%BD%AEgoners",target:"_blank",rel:"noopener noreferrer"}},[t._v("documentation"),e("OutboundLink")],1),t._v(".")]),t._v(" "),e("p",[t._v("Additionally, we've developed a command-line utility called "),e("strong",[t._v("gone")]),t._v(", which scans for special comments "),e("code",[t._v("//go:gone")]),t._v(" to automatically generate "),e("strong",[t._v("Priest")]),t._v(" functions. You can refer to "),e("RouterLink",{attrs:{to:"/guide/auto-gen-priest.html"}},[t._v("Auto-generating Priest")]),t._v(" for more information.")],1)])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/34.783150ce.js b/assets/js/34.41f36afd.js similarity index 99% rename from assets/js/34.783150ce.js rename to assets/js/34.41f36afd.js index ab4dd36..3f905a8 100644 --- a/assets/js/34.783150ce.js +++ b/assets/js/34.41f36afd.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[34],{316:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"gone-s-hook-functions"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#gone-s-hook-functions"}},[t._v("#")]),t._v(" Gone's Hook Functions")]),t._v(" "),s("h2",{attrs:{id:"what-are-hook-functions"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#what-are-hook-functions"}},[t._v("#")]),t._v(" What are Hook Functions?")]),t._v(" "),s("p",[t._v("In the process of starting and stopping Gone, support is provided to register four types of functions that will be executed at specific times, known as Hook functions:")]),t._v(" "),s("ul",[s("li",[t._v("BeforeStart Hook function: Executes before Gone starts, registered using "),s("code",[t._v("BeforeStart")]),t._v(".")]),t._v(" "),s("li",[t._v("AfterStart Hook function: Executes after Gone starts, registered using "),s("code",[t._v("AfterStart")]),t._v(".")]),t._v(" "),s("li",[t._v("BeforeStop Hook function: Executes before Gone stops, registered using "),s("code",[t._v("BeforeStop")]),t._v(".")]),t._v(" "),s("li",[t._v("AfterStop Hook function: Executes after Gone stops, registered using "),s("code",[t._v("AfterStop")]),t._v(".")])]),t._v(" "),s("h2",{attrs:{id:"code-example"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#code-example"}},[t._v("#")]),t._v(" Code Example")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Jim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"boss-jim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Bob"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"worker-bob"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BeforeStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"First BeforeStart function"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BeforeStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tworker Worker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"worker-bob"`')]),t._v("\n\t\t\tboss Boss "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Second BeforeStart function"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Boss:"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Worker:"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BeforeStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Third BeforeStart function"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("The output of the above code is as follows:")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("Third BeforeStart function\nSecond BeforeStart function\nBoss: Jim\nWorker: Bob\nFirst BeforeStart function\n")])])]),s("h3",{attrs:{id:"rules-for-hook-functions"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#rules-for-hook-functions"}},[t._v("#")]),t._v(" Rules for Hook Functions")]),t._v(" "),s("ol",[s("li",[t._v("Multiple registrations of the same type of Hook function are allowed.")]),t._v(" "),s("li",[t._v("For "),s("code",[t._v("BeforeStart")]),t._v(" and "),s("code",[t._v("BeforeStop")]),t._v(" Hook functions, the ones registered later are executed first.")]),t._v(" "),s("li",[t._v("For "),s("code",[t._v("AfterStart")]),t._v(" and "),s("code",[t._v("AfterStop")]),t._v(" Hook functions, the ones registered earlier are executed first.")]),t._v(" "),s("li",[t._v("Hook functions can be registered using the "),s("code",[t._v("Preparer")]),t._v(" object returned by "),s("code",[t._v("gone.Prepare(priest)")]),t._v(", supporting chaining.")]),t._v(" "),s("li",[t._v("The types of functions that can be registered with the "),s("code",[t._v("Preparer")]),t._v(" object include:\n"),s("ul",[s("li",[s("strong",[t._v("Input Parameters:")]),t._v(" "),s("ul",[s("li",[t._v("No parameters")]),t._v(" "),s("li",[t._v("Anonymous struct parameters, with properties annotated with "),s("code",[t._v("gone")]),t._v(" tags automatically injected with corresponding values.")])])]),t._v(" "),s("li",[s("strong",[t._v("Return Parameters:")]),t._v(" "),s("ul",[s("li",[t._v("No return parameters")]),t._v(" "),s("li",[s("code",[t._v("error")]),t._v(" parameter; if the error parameter is not "),s("code",[t._v("nil")]),t._v(", the program will panic when it reaches the Hook, terminating execution.")])])])])])]),t._v(" "),s("h2",{attrs:{id:"gone-s-startup-process"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#gone-s-startup-process"}},[t._v("#")]),t._v(" Gone's Startup Process")]),t._v(" "),s("ol",[s("li",[t._v("Revive all "),s("strong",[t._v("buried")]),t._v(" Goners.")]),t._v(" "),s("li",[t._v("Execute the "),s("code",[t._v("AfterRevive")]),t._v(" method of all prophet Goners.")]),t._v(" "),s("li",[t._v("Register the "),s("code",[t._v("Start")]),t._v(" method of "),s("strong",[t._v("angels")]),t._v(" as BeforeStart Hook functions and the "),s("code",[t._v("Stop")]),t._v(" method as BeforeStop Hook functions.")]),t._v(" "),s("li",[t._v("Register Hook functions for business code.")]),t._v(" "),s("li",[t._v("Execute BeforeStart Hook functions in order.")]),t._v(" "),s("li",[t._v("Execute AfterStart Hook functions in order.")]),t._v(" "),s("li",[t._v("Wait for the program to end.")]),t._v(" "),s("li",[t._v("Execute BeforeStop Hook functions in order.")]),t._v(" "),s("li",[t._v("Execute AfterStop Hook functions in order.")])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[34],{320:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"gone-s-hook-functions"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#gone-s-hook-functions"}},[t._v("#")]),t._v(" Gone's Hook Functions")]),t._v(" "),s("h2",{attrs:{id:"what-are-hook-functions"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#what-are-hook-functions"}},[t._v("#")]),t._v(" What are Hook Functions?")]),t._v(" "),s("p",[t._v("In the process of starting and stopping Gone, support is provided to register four types of functions that will be executed at specific times, known as Hook functions:")]),t._v(" "),s("ul",[s("li",[t._v("BeforeStart Hook function: Executes before Gone starts, registered using "),s("code",[t._v("BeforeStart")]),t._v(".")]),t._v(" "),s("li",[t._v("AfterStart Hook function: Executes after Gone starts, registered using "),s("code",[t._v("AfterStart")]),t._v(".")]),t._v(" "),s("li",[t._v("BeforeStop Hook function: Executes before Gone stops, registered using "),s("code",[t._v("BeforeStop")]),t._v(".")]),t._v(" "),s("li",[t._v("AfterStop Hook function: Executes after Gone stops, registered using "),s("code",[t._v("AfterStop")]),t._v(".")])]),t._v(" "),s("h2",{attrs:{id:"code-example"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#code-example"}},[t._v("#")]),t._v(" Code Example")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Jim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"boss-jim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Bob"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"worker-bob"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BeforeStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"First BeforeStart function"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BeforeStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tworker Worker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"worker-bob"`')]),t._v("\n\t\t\tboss Boss "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Second BeforeStart function"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Boss:"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Worker:"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BeforeStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Third BeforeStart function"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("The output of the above code is as follows:")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("Third BeforeStart function\nSecond BeforeStart function\nBoss: Jim\nWorker: Bob\nFirst BeforeStart function\n")])])]),s("h3",{attrs:{id:"rules-for-hook-functions"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#rules-for-hook-functions"}},[t._v("#")]),t._v(" Rules for Hook Functions")]),t._v(" "),s("ol",[s("li",[t._v("Multiple registrations of the same type of Hook function are allowed.")]),t._v(" "),s("li",[t._v("For "),s("code",[t._v("BeforeStart")]),t._v(" and "),s("code",[t._v("BeforeStop")]),t._v(" Hook functions, the ones registered later are executed first.")]),t._v(" "),s("li",[t._v("For "),s("code",[t._v("AfterStart")]),t._v(" and "),s("code",[t._v("AfterStop")]),t._v(" Hook functions, the ones registered earlier are executed first.")]),t._v(" "),s("li",[t._v("Hook functions can be registered using the "),s("code",[t._v("Preparer")]),t._v(" object returned by "),s("code",[t._v("gone.Prepare(priest)")]),t._v(", supporting chaining.")]),t._v(" "),s("li",[t._v("The types of functions that can be registered with the "),s("code",[t._v("Preparer")]),t._v(" object include:\n"),s("ul",[s("li",[s("strong",[t._v("Input Parameters:")]),t._v(" "),s("ul",[s("li",[t._v("No parameters")]),t._v(" "),s("li",[t._v("Anonymous struct parameters, with properties annotated with "),s("code",[t._v("gone")]),t._v(" tags automatically injected with corresponding values.")])])]),t._v(" "),s("li",[s("strong",[t._v("Return Parameters:")]),t._v(" "),s("ul",[s("li",[t._v("No return parameters")]),t._v(" "),s("li",[s("code",[t._v("error")]),t._v(" parameter; if the error parameter is not "),s("code",[t._v("nil")]),t._v(", the program will panic when it reaches the Hook, terminating execution.")])])])])])]),t._v(" "),s("h2",{attrs:{id:"gone-s-startup-process"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#gone-s-startup-process"}},[t._v("#")]),t._v(" Gone's Startup Process")]),t._v(" "),s("ol",[s("li",[t._v("Revive all "),s("strong",[t._v("buried")]),t._v(" Goners.")]),t._v(" "),s("li",[t._v("Execute the "),s("code",[t._v("AfterRevive")]),t._v(" method of all prophet Goners.")]),t._v(" "),s("li",[t._v("Register the "),s("code",[t._v("Start")]),t._v(" method of "),s("strong",[t._v("angels")]),t._v(" as BeforeStart Hook functions and the "),s("code",[t._v("Stop")]),t._v(" method as BeforeStop Hook functions.")]),t._v(" "),s("li",[t._v("Register Hook functions for business code.")]),t._v(" "),s("li",[t._v("Execute BeforeStart Hook functions in order.")]),t._v(" "),s("li",[t._v("Execute AfterStart Hook functions in order.")]),t._v(" "),s("li",[t._v("Wait for the program to end.")]),t._v(" "),s("li",[t._v("Execute BeforeStop Hook functions in order.")]),t._v(" "),s("li",[t._v("Execute AfterStop Hook functions in order.")])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/35.c9e47661.js b/assets/js/35.1cb0dce8.js similarity index 99% rename from assets/js/35.c9e47661.js rename to assets/js/35.1cb0dce8.js index 1d2b410..6ea3d37 100644 --- a/assets/js/35.c9e47661.js +++ b/assets/js/35.1cb0dce8.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[35],{318:function(t,n,s){"use strict";s.r(n);var e=s(10),a=Object(e.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"how-to-gracefully-use-built-in-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#how-to-gracefully-use-built-in-goners"}},[t._v("#")]),t._v(" How to Gracefully Use Built-in Goners?")]),t._v(" "),n("p"),n("div",{staticClass:"table-of-contents"},[n("ul",[n("li",[n("a",{attrs:{href:"#built-in-goners"}},[t._v("Built-in Goners")])]),n("li",[n("a",{attrs:{href:"#the-priest-function"}},[t._v("The Priest Function")])]),n("li",[n("a",{attrs:{href:"#how-to-use"}},[t._v("How to Use")])]),n("li",[n("a",{attrs:{href:"#goneid-for-built-in-goners"}},[t._v("GoneId for Built-in Goners")])])])]),n("p"),t._v(" "),n("h2",{attrs:{id:"built-in-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#built-in-goners"}},[t._v("#")]),t._v(" Built-in Goners")]),t._v(" "),n("p",[t._v("To lower the entry barrier for using Gone, we have developed some "),n("RouterLink",{attrs:{to:"/goners/#built-in-framework-goners"}},[t._v("built-in Goners")]),t._v(" to provide basic functionality.")],1),t._v(" "),n("h2",{attrs:{id:"the-priest-function"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#the-priest-function"}},[t._v("#")]),t._v(" The "),n("code",[t._v("Priest")]),t._v(" Function")]),t._v(" "),n("p",[t._v("The "),n("code",[t._v("Priest")]),t._v(" function is defined within the gone framework, and it allows for the bulk burial of Goners. Additionally, the "),n("code",[t._v("Priest")]),t._v(" function can be nested, meaning A can call B, and B can call C. Therefore, after developing a set of features, you can provide a "),n("code",[t._v("Priest")]),t._v(" function that buries all the Goners used.")]),t._v(" "),n("p",[t._v("In fact, when developing built-in Goners for the framework, we adopt this approach. Additionally, for ease of use, we have defined some shortcuts in "),n("code",[t._v("goner/priest.go")]),t._v(", as shown below:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" goner\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/logrus"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/redis"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/schedule"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/tracer"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/urllib"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" tracer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" logrus"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GinPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" gin"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("XormPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" xorm"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" redis"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" schedule"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("UrllibPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" urllib"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"how-to-use"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#how-to-use"}},[t._v("#")]),t._v(" How to Use")]),t._v(" "),n("p",[t._v("This way, if we want to use basic logging, tracing, and configuration functionality, we only need to:")]),t._v(" "),n("ol",[n("li",[n("p",[t._v("Add "),n("code",[t._v("gone.BasePriest(cemetery)")]),t._v(" in the main "),n("code",[t._v("Priest")]),t._v(" function:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury Goners related to logging, tracing, and configuration")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Call other Priests")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),t._v(" "),n("li",[n("p",[t._v("If logging is needed, inject it into the necessary Goners:")])])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/logrus"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/domain"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemoService")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demoService"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" demoService "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tlogrus"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection to nested anonymous property")]),t._v("\n\n\tlog logrus"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection to nested log property")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoService"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Using inherited method")]),t._v("\n\tsvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Using method on property")]),t._v("\n\tsvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("When injecting built-in components, named injection should be used.")])]),t._v(" "),n("h2",{attrs:{id:"goneid-for-built-in-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#goneid-for-built-in-goners"}},[t._v("#")]),t._v(" GoneId for Built-in Goners")]),t._v(" "),n("p",[t._v("The GonerId for built-in Goners is centrally defined in "),n("code",[t._v("https://github.com/gone-io/gone/blob/main/ids.go")]),t._v(":")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" gone\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ID for built-in components in the Gone framework")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneHeaven ID of the Heaven component, which represents the program itself and is automatically injected when the Gone program starts")]),t._v("\n\tIdGoneHeaven "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-heaven"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneCemetery ID of the Cemetery component, which is essential for completing dependency injection and is automatically injected when the Gone program starts")]),t._v("\n\tIdGoneCemetery "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-cemetery"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneTestKit ID of the TestKit component, which is injected into the program when calling gone.Test or gone.TestAt; it should not be injected into non-test code")]),t._v("\n\tIdGoneTestKit "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-test-kit"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Configuration, logging, and Tracer together form the foundation of the Gone framework, and can be buried together using [goner.BasePriest](goner#BasePriest)")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdConfig ID of the configuration Goner, providing configuration capability")]),t._v("\n\tIdConfig "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneConfigure ID of the configurator Goner")]),t._v("\n\tIdGoneConfigure "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-configure"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneTracer ID of the Tracer Goner, providing logging and tracing capabilities")]),t._v("\n\tIdGoneTracer "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-tracer"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneLogger ID of the Logger Goner, used for logging")]),t._v("\n\tIdGoneLogger "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-logger"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneCumx [cmux Goner](/goner/cmux#Server) ID")]),t._v("\n\tIdGoneCumx "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-cumx"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneGin IDs related to Gin components, which can be buried together using [goner.GinPriest](goner#GinPriest)")]),t._v("\n\tIdGoneGin "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin"')]),t._v("\n\tIdGoneGinRouter "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-router"')]),t._v("\n\tIdGoneGinProcessor "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-processor"')]),t._v("\n\tIdGoneGinProxy "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-proxy"')]),t._v("\n\tIdGoneGinResponser "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-responser"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneXorm ID of the Xorm Goner, encapsulating xorm for database operations; can be buried using [goner.XormPriest](goner#XormPriest)")]),t._v("\n\tIdGoneXorm "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-xorm"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneRedisPool ID of the redis pool Goner; Redis-related Goners can be buried using [goner.RedisPriest](goner#RedisPriest)")]),t._v("\n\tIdGoneRedisPool "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-pool"')]),t._v("\n\tIdGoneRedisCache "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-cache"')]),t._v("\n\tIdGoneRedisKey "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-key"')]),t._v("\n\tIdGoneRedisLocker "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-locker"')]),t._v("\n\tIdGoneRedisProvider "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-provider"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneSchedule ID of the Scheduler Goner; can be buried using [goner.SchedulePriest](goner#SchedulePriest)")]),t._v("\n\tIdGoneSchedule "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-schedule"')]),t._v("\n\n\tIdGoneReq "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-urllib"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);n.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[35],{321:function(t,n,s){"use strict";s.r(n);var e=s(10),a=Object(e.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"how-to-gracefully-use-built-in-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#how-to-gracefully-use-built-in-goners"}},[t._v("#")]),t._v(" How to Gracefully Use Built-in Goners?")]),t._v(" "),n("p"),n("div",{staticClass:"table-of-contents"},[n("ul",[n("li",[n("a",{attrs:{href:"#built-in-goners"}},[t._v("Built-in Goners")])]),n("li",[n("a",{attrs:{href:"#the-priest-function"}},[t._v("The Priest Function")])]),n("li",[n("a",{attrs:{href:"#how-to-use"}},[t._v("How to Use")])]),n("li",[n("a",{attrs:{href:"#goneid-for-built-in-goners"}},[t._v("GoneId for Built-in Goners")])])])]),n("p"),t._v(" "),n("h2",{attrs:{id:"built-in-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#built-in-goners"}},[t._v("#")]),t._v(" Built-in Goners")]),t._v(" "),n("p",[t._v("To lower the entry barrier for using Gone, we have developed some "),n("RouterLink",{attrs:{to:"/goners/#built-in-framework-goners"}},[t._v("built-in Goners")]),t._v(" to provide basic functionality.")],1),t._v(" "),n("h2",{attrs:{id:"the-priest-function"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#the-priest-function"}},[t._v("#")]),t._v(" The "),n("code",[t._v("Priest")]),t._v(" Function")]),t._v(" "),n("p",[t._v("The "),n("code",[t._v("Priest")]),t._v(" function is defined within the gone framework, and it allows for the bulk burial of Goners. Additionally, the "),n("code",[t._v("Priest")]),t._v(" function can be nested, meaning A can call B, and B can call C. Therefore, after developing a set of features, you can provide a "),n("code",[t._v("Priest")]),t._v(" function that buries all the Goners used.")]),t._v(" "),n("p",[t._v("In fact, when developing built-in Goners for the framework, we adopt this approach. Additionally, for ease of use, we have defined some shortcuts in "),n("code",[t._v("goner/priest.go")]),t._v(", as shown below:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" goner\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/logrus"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/redis"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/schedule"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/tracer"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/urllib"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" tracer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" logrus"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GinPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" gin"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("XormPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" xorm"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" redis"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" schedule"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("UrllibPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" urllib"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"how-to-use"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#how-to-use"}},[t._v("#")]),t._v(" How to Use")]),t._v(" "),n("p",[t._v("This way, if we want to use basic logging, tracing, and configuration functionality, we only need to:")]),t._v(" "),n("ol",[n("li",[n("p",[t._v("Add "),n("code",[t._v("gone.BasePriest(cemetery)")]),t._v(" in the main "),n("code",[t._v("Priest")]),t._v(" function:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury Goners related to logging, tracing, and configuration")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Call other Priests")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),t._v(" "),n("li",[n("p",[t._v("If logging is needed, inject it into the necessary Goners:")])])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/logrus"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/domain"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemoService")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demoService"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" demoService "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tlogrus"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection to nested anonymous property")]),t._v("\n\n\tlog logrus"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection to nested log property")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoService"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Using inherited method")]),t._v("\n\tsvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Using method on property")]),t._v("\n\tsvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("div",{staticClass:"custom-block tip"},[n("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),n("p",[t._v("When injecting built-in components, named injection should be used.")])]),t._v(" "),n("h2",{attrs:{id:"goneid-for-built-in-goners"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#goneid-for-built-in-goners"}},[t._v("#")]),t._v(" GoneId for Built-in Goners")]),t._v(" "),n("p",[t._v("The GonerId for built-in Goners is centrally defined in "),n("code",[t._v("https://github.com/gone-io/gone/blob/main/ids.go")]),t._v(":")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" gone\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ID for built-in components in the Gone framework")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneHeaven ID of the Heaven component, which represents the program itself and is automatically injected when the Gone program starts")]),t._v("\n\tIdGoneHeaven "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-heaven"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneCemetery ID of the Cemetery component, which is essential for completing dependency injection and is automatically injected when the Gone program starts")]),t._v("\n\tIdGoneCemetery "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-cemetery"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneTestKit ID of the TestKit component, which is injected into the program when calling gone.Test or gone.TestAt; it should not be injected into non-test code")]),t._v("\n\tIdGoneTestKit "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-test-kit"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Configuration, logging, and Tracer together form the foundation of the Gone framework, and can be buried together using [goner.BasePriest](goner#BasePriest)")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdConfig ID of the configuration Goner, providing configuration capability")]),t._v("\n\tIdConfig "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneConfigure ID of the configurator Goner")]),t._v("\n\tIdGoneConfigure "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-configure"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneTracer ID of the Tracer Goner, providing logging and tracing capabilities")]),t._v("\n\tIdGoneTracer "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-tracer"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneLogger ID of the Logger Goner, used for logging")]),t._v("\n\tIdGoneLogger "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-logger"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneCumx [cmux Goner](/goner/cmux#Server) ID")]),t._v("\n\tIdGoneCumx "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-cumx"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneGin IDs related to Gin components, which can be buried together using [goner.GinPriest](goner#GinPriest)")]),t._v("\n\tIdGoneGin "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin"')]),t._v("\n\tIdGoneGinRouter "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-router"')]),t._v("\n\tIdGoneGinProcessor "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-processor"')]),t._v("\n\tIdGoneGinProxy "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-proxy"')]),t._v("\n\tIdGoneGinResponser "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-responser"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneXorm ID of the Xorm Goner, encapsulating xorm for database operations; can be buried using [goner.XormPriest](goner#XormPriest)")]),t._v("\n\tIdGoneXorm "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-xorm"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneRedisPool ID of the redis pool Goner; Redis-related Goners can be buried using [goner.RedisPriest](goner#RedisPriest)")]),t._v("\n\tIdGoneRedisPool "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-pool"')]),t._v("\n\tIdGoneRedisCache "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-cache"')]),t._v("\n\tIdGoneRedisKey "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-key"')]),t._v("\n\tIdGoneRedisLocker "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-locker"')]),t._v("\n\tIdGoneRedisProvider "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-provider"')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneSchedule ID of the Scheduler Goner; can be buried using [goner.SchedulePriest](goner#SchedulePriest)")]),t._v("\n\tIdGoneSchedule "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-schedule"')]),t._v("\n\n\tIdGoneReq "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-urllib"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);n.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/36.45687656.js b/assets/js/36.8a0a3897.js similarity index 99% rename from assets/js/36.45687656.js rename to assets/js/36.8a0a3897.js index 29510d7..518050f 100644 --- a/assets/js/36.45687656.js +++ b/assets/js/36.8a0a3897.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[36],{317:function(t,n,a){"use strict";a.r(n);var s=a(10),e=Object(s.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"logging-output"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#logging-output"}},[t._v("#")]),t._v(" Logging Output")]),t._v(" "),n("p",[t._v("In Gone, an internal Goner is provided for logging output - "),n("a",{attrs:{href:"github.com/gone-io/gone/tree/main/goner/logrus"}},[t._v("logrus")]),t._v(", which is implemented by wrapping the "),n("code",[t._v("github.com/sirupsen/logrus")]),t._v(" package as a Goner. It is hoped that other logging output packages will be encapsulated by contributors to provide more logging solutions.")]),t._v(" "),n("h2",{attrs:{id:"burying-related-goners-in-the-cemetery"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#burying-related-goners-in-the-cemetery"}},[t._v("#")]),t._v(" Burying Related Goners in the Cemetery")]),t._v(" "),n("blockquote",[n("p",[t._v("tip: To understand the core concepts and terminology of Gone, please read: "),n("a",{attrs:{href:"https://goner.fun/en/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Core Concepts of Gone"),n("OutboundLink")],1)])]),t._v(" "),n("p",[t._v("Here, we use the "),n("strong",[n("code",[t._v("BasePriest")])]),t._v(" from the package "),n("strong",[n("code",[t._v("github.com/gone-io/gone/tree/main/goner")])]),t._v(" to bury related Goners. In the "),n("code",[t._v("BasePriest")]),t._v(", Goners related to configuration and trace are also buried into the Cemetery, as these three packages are commonly used together.")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury other Goners")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"adding-related-configurations-in-the-configuration-file"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#adding-related-configurations-in-the-configuration-file"}},[t._v("#")]),t._v(" Adding Related Configurations in the Configuration File")]),t._v(" "),n("blockquote",[n("p",[t._v("tip: "),n("a",{attrs:{href:"https://goner.fun/en/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Supporting Configuration Files through Built-in Goners"),n("OutboundLink")],1)])]),t._v(" "),n("p",[n("strong",[t._v("Supported Configuration Items")])]),t._v(" "),n("ul",[n("li",[t._v("log.level: Log level, default is info; supported levels:\n"),n("ul",[n("li",[t._v("panic")]),t._v(" "),n("li",[t._v("fatal")]),t._v(" "),n("li",[t._v("error")]),t._v(" "),n("li",[t._v("warn or warning")]),t._v(" "),n("li",[t._v("info")]),t._v(" "),n("li",[t._v("debug")]),t._v(" "),n("li",[t._v("trace")])])]),t._v(" "),n("li",[t._v("log.report-caller: If true, log will print the file name and line number of the log output position, for example:\n2024-05-11 09:09:57.784|INFO|"),n("strong",[t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46")]),t._v("|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080")]),t._v(" "),n("li",[t._v("log.output: Log output location, default is stdout (standard output), supports stderr and a file path\n"),n("blockquote",[n("p",[n("strong",[t._v("Best Practice:")]),t._v(" Deploy the application in containers and directly output logs to standard output, collected by a log collection component such as EFK.")])])])]),t._v(" "),n("h2",{attrs:{id:"logging"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#logging"}},[t._v("#")]),t._v(" Logging")]),t._v(" "),n("p",[t._v("Use the "),n("code",[t._v("Info")]),t._v(" method to log:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" service "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n log logrus"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection into nested log attributes")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("service"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Business")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Log")]),t._v("\n svc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),n("p",[t._v("For logging at other levels, refer to the interface code:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Logger interface for logging")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Logger "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Tracef")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debugf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warnf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warningf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Errorf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatalf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panicf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Trace")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debug")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Info")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Print")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warn")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warning")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panic")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Traceln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debugln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infoln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warnln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warningln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Errorln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatalln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panicln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"log-format"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#log-format"}},[t._v("#")]),t._v(" Log Format")]),t._v(" "),n("p",[n("code",[t._v("${Log Output Time}|${Log Level}|${Source Code Position of Log Output}|${TraceId}|${Log Content}")])]),t._v(" "),n("p",[t._v("For example:")]),t._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("2024-05-11 09:09:57.784|INFO|**/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46**|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080\n")])])]),n("h2",{attrs:{id:"about-traceid"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#about-traceid"}},[t._v("#")]),t._v(" About TraceId")]),t._v(" "),n("p",[t._v("In web applications, we want a unified ID to identify logs generated by the same request. This unified ID is the TraceId. If this ID exists, when troubleshooting, we can search for logs using this ID to obtain all logs related to the request.")])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[36],{322:function(t,n,a){"use strict";a.r(n);var s=a(10),e=Object(s.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"logging-output"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#logging-output"}},[t._v("#")]),t._v(" Logging Output")]),t._v(" "),n("p",[t._v("In Gone, an internal Goner is provided for logging output - "),n("a",{attrs:{href:"github.com/gone-io/gone/tree/main/goner/logrus"}},[t._v("logrus")]),t._v(", which is implemented by wrapping the "),n("code",[t._v("github.com/sirupsen/logrus")]),t._v(" package as a Goner. It is hoped that other logging output packages will be encapsulated by contributors to provide more logging solutions.")]),t._v(" "),n("h2",{attrs:{id:"burying-related-goners-in-the-cemetery"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#burying-related-goners-in-the-cemetery"}},[t._v("#")]),t._v(" Burying Related Goners in the Cemetery")]),t._v(" "),n("blockquote",[n("p",[t._v("tip: To understand the core concepts and terminology of Gone, please read: "),n("a",{attrs:{href:"https://goner.fun/en/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Core Concepts of Gone"),n("OutboundLink")],1)])]),t._v(" "),n("p",[t._v("Here, we use the "),n("strong",[n("code",[t._v("BasePriest")])]),t._v(" from the package "),n("strong",[n("code",[t._v("github.com/gone-io/gone/tree/main/goner")])]),t._v(" to bury related Goners. In the "),n("code",[t._v("BasePriest")]),t._v(", Goners related to configuration and trace are also buried into the Cemetery, as these three packages are commonly used together.")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury other Goners")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"adding-related-configurations-in-the-configuration-file"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#adding-related-configurations-in-the-configuration-file"}},[t._v("#")]),t._v(" Adding Related Configurations in the Configuration File")]),t._v(" "),n("blockquote",[n("p",[t._v("tip: "),n("a",{attrs:{href:"https://goner.fun/en/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Supporting Configuration Files through Built-in Goners"),n("OutboundLink")],1)])]),t._v(" "),n("p",[n("strong",[t._v("Supported Configuration Items")])]),t._v(" "),n("ul",[n("li",[t._v("log.level: Log level, default is info; supported levels:\n"),n("ul",[n("li",[t._v("panic")]),t._v(" "),n("li",[t._v("fatal")]),t._v(" "),n("li",[t._v("error")]),t._v(" "),n("li",[t._v("warn or warning")]),t._v(" "),n("li",[t._v("info")]),t._v(" "),n("li",[t._v("debug")]),t._v(" "),n("li",[t._v("trace")])])]),t._v(" "),n("li",[t._v("log.report-caller: If true, log will print the file name and line number of the log output position, for example:\n2024-05-11 09:09:57.784|INFO|"),n("strong",[t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46")]),t._v("|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080")]),t._v(" "),n("li",[t._v("log.output: Log output location, default is stdout (standard output), supports stderr and a file path\n"),n("blockquote",[n("p",[n("strong",[t._v("Best Practice:")]),t._v(" Deploy the application in containers and directly output logs to standard output, collected by a log collection component such as EFK.")])])])]),t._v(" "),n("h2",{attrs:{id:"logging"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#logging"}},[t._v("#")]),t._v(" Logging")]),t._v(" "),n("p",[t._v("Use the "),n("code",[t._v("Info")]),t._v(" method to log:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" service "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n log logrus"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection into nested log attributes")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("service"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Business")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Log")]),t._v("\n svc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),n("p",[t._v("For logging at other levels, refer to the interface code:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Logger interface for logging")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Logger "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Tracef")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debugf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warnf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warningf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Errorf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatalf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panicf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Trace")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debug")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Info")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Print")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warn")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warning")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panic")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Traceln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debugln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infoln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warnln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warningln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Errorln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatalln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panicln")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"log-format"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#log-format"}},[t._v("#")]),t._v(" Log Format")]),t._v(" "),n("p",[n("code",[t._v("${Log Output Time}|${Log Level}|${Source Code Position of Log Output}|${TraceId}|${Log Content}")])]),t._v(" "),n("p",[t._v("For example:")]),t._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("2024-05-11 09:09:57.784|INFO|**/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46**|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080\n")])])]),n("h2",{attrs:{id:"about-traceid"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#about-traceid"}},[t._v("#")]),t._v(" About TraceId")]),t._v(" "),n("p",[t._v("In web applications, we want a unified ID to identify logs generated by the same request. This unified ID is the TraceId. If this ID exists, when troubleshooting, we can search for logs using this ID to obtain all logs related to the request.")])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/37.6a895754.js b/assets/js/37.f6f2df18.js similarity index 99% rename from assets/js/37.6a895754.js rename to assets/js/37.f6f2df18.js index b88df9b..4401041 100644 --- a/assets/js/37.6a895754.js +++ b/assets/js/37.f6f2df18.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[37],{328:function(t,s,n){"use strict";n.r(s);var e=n(10),a=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"using-redis-for-distributed-locking-and-caching"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#using-redis-for-distributed-locking-and-caching"}},[t._v("#")]),t._v(" Using Redis for Distributed Locking and Caching")]),t._v(" "),s("p",[t._v('In this article, we will share how to use distributed caching and distributed locking in Gone, where distributed locking includes a more flexible handling method — "smart lock". This method locks a processing function, periodically checks the remaining expiration time of the lock during function execution, and automatically renews the lock if necessary. The function automatically unlocks after execution.')]),t._v(" "),s("h2",{attrs:{id:"step-1-embedding-redis-related-goner-into-cemetery"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#step-1-embedding-redis-related-goner-into-cemetery"}},[t._v("#")]),t._v(" Step 1: Embedding Redis Related Goner into Cemetery")]),t._v(" "),s("blockquote",[s("p",[t._v("What is a Goner?\nWhat does it mean to bury?\nWhat is a Cemetery?\nRefer to "),s("a",{attrs:{href:"https://goner.fun/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Core Concepts of Gone"),s("OutboundLink")],1)])]),t._v(" "),s("p",[t._v("In the Priest function, add "),s("code",[t._v("_ = goner.RedisPriest(cemetery)")]),t._v(" as follows:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Using the goner.RedisPriest function to bury Redis-related Goner into Cemetery")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"step-2-adding-redis-configuration-to-the-configuration-file"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#step-2-adding-redis-configuration-to-the-configuration-file"}},[t._v("#")]),t._v(" Step 2: Adding Redis Configuration to the Configuration File")]),t._v(" "),s("p",[t._v("Create a configuration file "),s("code",[t._v("config/default.properties")]),t._v(" with the following contents:")]),t._v(" "),s("div",{staticClass:"language-properties extra-class"},[s("pre",{pre:!0,attrs:{class:"language-properties"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Redis service address in the format `host:port`")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("redis.server")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("localhost:6379")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Redis service password, default is empty if not configured")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("redis.password")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v("\n")])])]),s("blockquote",[s("p",[t._v("Note: The Redis service address should be set to a Redis service you can access.")])]),t._v(" "),s("p",[t._v("Additional configuration options:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("redis.max-idle")]),t._v(": maximum number of idle connections, default is 2 if not set")]),t._v(" "),s("li",[s("code",[t._v("redis.max-active")]),t._v(": maximum number of active connections, default is 10 if not set")]),t._v(" "),s("li",[s("code",[t._v("redis.db")]),t._v(": the database to use, default is 0 if not set")]),t._v(" "),s("li",[s("code",[t._v("redis.cache.prefix")]),t._v(": key prefix, if set, all CRUD operations on Redis will append this prefix using the format "),s("code",[t._v("${prefix}#${key}")]),t._v("; default is empty")])]),t._v(" "),s("blockquote",[s("p",[t._v("For more on configuration files, refer to: "),s("a",{attrs:{href:"https://goner.fun/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Support for Configuration Files Through Built-in Goners"),s("OutboundLink")],1)])]),t._v(" "),s("h2",{attrs:{id:"step-3-using-redis"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#step-3-using-redis"}},[t._v("#")]),t._v(" Step 3: Using Redis")]),t._v(" "),s("h3",{attrs:{id:"injecting-interfaces"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#injecting-interfaces"}},[t._v("#")]),t._v(" Injecting Interfaces")]),t._v(" "),s("p",[t._v("Inject the interfaces "),s("code",[t._v("redis.Cache")]),t._v(" and "),s("code",[t._v("redis.Locker")]),t._v(" into the structure where they are needed, their "),s("code",[t._v("GonerId")]),t._v(" are respectively: "),s("code",[t._v("gone-redis-cache")]),t._v(" and "),s("code",[t._v("gone-redis-locker")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" redisUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcache redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cache "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-cache"`')]),t._v("\n\tlocker redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Locker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-locker"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"using-distributed-cache"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#using-distributed-cache"}},[t._v("#")]),t._v(" Using Distributed Cache")]),t._v(" "),s("p",[t._v("Refer to the comments in the code below:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tkey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-address"')]),t._v("\n\tvalue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/gone-io/gone"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Setting the cache")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Put")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the cache key, type `string`")]),t._v("\n\t\tvalue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is the value to cache, type any; the passed value will be encoded to `[]byte` and sent to Redis")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The third parameter is the expiration time, type `time.Duration`; if omitted, no expiration time is set")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Getting the cache")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" getValue "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the cache key, type `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is a pointer to receive the cached value, type any; the value retrieved from Redis will be decoded into the type of the passed pointer")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"getValue:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Other methods on the interface:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("Remove(key string) (err error)")]),t._v(": used to delete a specific Redis key, supports wildcard")]),t._v(" "),s("li",[s("code",[t._v("Keys(key string) ([]string, error)")]),t._v(": used to find keys using a prefix or wildcard, ⚠️ use this method with caution")]),t._v(" "),s("li",[s("code",[t._v("Prefix() string")]),t._v(": get the current cache configuration's key prefix")])]),t._v(" "),s("h3",{attrs:{id:"using-distributed-lock"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#using-distributed-lock"}},[t._v("#")]),t._v(" Using Distributed Lock")]),t._v(" "),s("ol",[s("li",[t._v("Locking for a specific duration")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Attempt to acquire the lock and lock it for a duration")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first returned parameter is a function to unlock")]),t._v("\n\tunlock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TryLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the lock key, type `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is the lock's expiration time, type `time.Duration`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// After operations, you need to unlock")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unlock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Once the lock is acquired,business operations can be performed.")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2.")]),t._v(" Locking a function where the lock is automatically renewed "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" the operation does not finish"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" and it unlocks automatically once the operation is complete\n"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("``")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`go\nfunc (r *redisUser) LockFunc() {\n\tlockKey := "gone-lock-key"\n\terr := r.locker.LockAndDo(\n\t\tlockKey, // The first parameter is the lock key, type `')]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("`\n\t\tfunc() { // The second parameter is the function to be executed, type `")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`, representing an operation\n\t\t\t// Once the lock is acquired, business operations can be performed\n\t\t\t//todo\n\t\t\tprintln("do some options")\n\t\t},\n\t\t100*time.Second, // The third parameter is the lock\'s expiration time, type `')]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Duration"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("`; both the initial locking and subsequent renewals will use this value\n\t\t5*time.Second, // The fourth parameter is the interval for lock renewal, type `")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Duration`"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" periodically checks "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" the lock is about to expire"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" and renews the lock "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" it is within the next period\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("This approach is quite intelligent and is referred to as a “smart lock.” It is recommended for its ease of use and reduction in cognitive load.")]),t._v(" "),s("h2",{attrs:{id:"complete-example-code"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#complete-example-code"}},[t._v("#")]),t._v(" Complete Example Code")]),t._v(" "),s("p",[t._v("The source code for the example can be found "),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-redis",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),s("OutboundLink")],1)]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/redis"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"time"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Using the goner.RedisPriest function to embed Redis-related Goner into the Cemetery")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" redisUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcache redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cache "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-cache"`')]),t._v("\n\tlocker redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Locker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-locker"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tkey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-address"')]),t._v("\n\tvalue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/gone-io/gone"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Setting the cache")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Put")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the cache key, type `string`")]),t._v("\n\t\tvalue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is the value to cache, type any; the passed value will be encoded to `[]byte` and sent to Redis")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The third parameter is the expiration time, type `time.Duration`; if omitted, no expiration time is set")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Getting the cache")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" getValue "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the cache key, type `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is a pointer to receive the cached value, type any; the value retrieved from Redis will be decoded into the type of the passed pointer")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"getValue:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockTime")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Attempting to obtain the lock and lock it for a specific duration")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first returned parameter is a function to unlock")]),t._v("\n\tunlock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TryLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the lock key, type `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is the lock's expiration time, type `time.Duration`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// After operations, you need to unlock")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unlock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Once the lock is acquired, business operations can be performed")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockTime")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[37],{323:function(t,s,n){"use strict";n.r(s);var e=n(10),a=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"using-redis-for-distributed-locking-and-caching"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#using-redis-for-distributed-locking-and-caching"}},[t._v("#")]),t._v(" Using Redis for Distributed Locking and Caching")]),t._v(" "),s("p",[t._v('In this article, we will share how to use distributed caching and distributed locking in Gone, where distributed locking includes a more flexible handling method — "smart lock". This method locks a processing function, periodically checks the remaining expiration time of the lock during function execution, and automatically renews the lock if necessary. The function automatically unlocks after execution.')]),t._v(" "),s("h2",{attrs:{id:"step-1-embedding-redis-related-goner-into-cemetery"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#step-1-embedding-redis-related-goner-into-cemetery"}},[t._v("#")]),t._v(" Step 1: Embedding Redis Related Goner into Cemetery")]),t._v(" "),s("blockquote",[s("p",[t._v("What is a Goner?\nWhat does it mean to bury?\nWhat is a Cemetery?\nRefer to "),s("a",{attrs:{href:"https://goner.fun/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Core Concepts of Gone"),s("OutboundLink")],1)])]),t._v(" "),s("p",[t._v("In the Priest function, add "),s("code",[t._v("_ = goner.RedisPriest(cemetery)")]),t._v(" as follows:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Using the goner.RedisPriest function to bury Redis-related Goner into Cemetery")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"step-2-adding-redis-configuration-to-the-configuration-file"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#step-2-adding-redis-configuration-to-the-configuration-file"}},[t._v("#")]),t._v(" Step 2: Adding Redis Configuration to the Configuration File")]),t._v(" "),s("p",[t._v("Create a configuration file "),s("code",[t._v("config/default.properties")]),t._v(" with the following contents:")]),t._v(" "),s("div",{staticClass:"language-properties extra-class"},[s("pre",{pre:!0,attrs:{class:"language-properties"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Redis service address in the format `host:port`")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("redis.server")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("localhost:6379")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Redis service password, default is empty if not configured")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("redis.password")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v("\n")])])]),s("blockquote",[s("p",[t._v("Note: The Redis service address should be set to a Redis service you can access.")])]),t._v(" "),s("p",[t._v("Additional configuration options:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("redis.max-idle")]),t._v(": maximum number of idle connections, default is 2 if not set")]),t._v(" "),s("li",[s("code",[t._v("redis.max-active")]),t._v(": maximum number of active connections, default is 10 if not set")]),t._v(" "),s("li",[s("code",[t._v("redis.db")]),t._v(": the database to use, default is 0 if not set")]),t._v(" "),s("li",[s("code",[t._v("redis.cache.prefix")]),t._v(": key prefix, if set, all CRUD operations on Redis will append this prefix using the format "),s("code",[t._v("${prefix}#${key}")]),t._v("; default is empty")])]),t._v(" "),s("blockquote",[s("p",[t._v("For more on configuration files, refer to: "),s("a",{attrs:{href:"https://goner.fun/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Support for Configuration Files Through Built-in Goners"),s("OutboundLink")],1)])]),t._v(" "),s("h2",{attrs:{id:"step-3-using-redis"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#step-3-using-redis"}},[t._v("#")]),t._v(" Step 3: Using Redis")]),t._v(" "),s("h3",{attrs:{id:"injecting-interfaces"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#injecting-interfaces"}},[t._v("#")]),t._v(" Injecting Interfaces")]),t._v(" "),s("p",[t._v("Inject the interfaces "),s("code",[t._v("redis.Cache")]),t._v(" and "),s("code",[t._v("redis.Locker")]),t._v(" into the structure where they are needed, their "),s("code",[t._v("GonerId")]),t._v(" are respectively: "),s("code",[t._v("gone-redis-cache")]),t._v(" and "),s("code",[t._v("gone-redis-locker")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" redisUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcache redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cache "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-cache"`')]),t._v("\n\tlocker redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Locker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-locker"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"using-distributed-cache"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#using-distributed-cache"}},[t._v("#")]),t._v(" Using Distributed Cache")]),t._v(" "),s("p",[t._v("Refer to the comments in the code below:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tkey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-address"')]),t._v("\n\tvalue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/gone-io/gone"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Setting the cache")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Put")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the cache key, type `string`")]),t._v("\n\t\tvalue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is the value to cache, type any; the passed value will be encoded to `[]byte` and sent to Redis")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The third parameter is the expiration time, type `time.Duration`; if omitted, no expiration time is set")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Getting the cache")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" getValue "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the cache key, type `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is a pointer to receive the cached value, type any; the value retrieved from Redis will be decoded into the type of the passed pointer")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"getValue:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Other methods on the interface:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("Remove(key string) (err error)")]),t._v(": used to delete a specific Redis key, supports wildcard")]),t._v(" "),s("li",[s("code",[t._v("Keys(key string) ([]string, error)")]),t._v(": used to find keys using a prefix or wildcard, ⚠️ use this method with caution")]),t._v(" "),s("li",[s("code",[t._v("Prefix() string")]),t._v(": get the current cache configuration's key prefix")])]),t._v(" "),s("h3",{attrs:{id:"using-distributed-lock"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#using-distributed-lock"}},[t._v("#")]),t._v(" Using Distributed Lock")]),t._v(" "),s("ol",[s("li",[t._v("Locking for a specific duration")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Attempt to acquire the lock and lock it for a duration")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first returned parameter is a function to unlock")]),t._v("\n\tunlock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TryLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the lock key, type `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is the lock's expiration time, type `time.Duration`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// After operations, you need to unlock")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unlock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Once the lock is acquired,business operations can be performed.")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2.")]),t._v(" Locking a function where the lock is automatically renewed "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" the operation does not finish"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" and it unlocks automatically once the operation is complete\n"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("``")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`go\nfunc (r *redisUser) LockFunc() {\n\tlockKey := "gone-lock-key"\n\terr := r.locker.LockAndDo(\n\t\tlockKey, // The first parameter is the lock key, type `')]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("`\n\t\tfunc() { // The second parameter is the function to be executed, type `")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`, representing an operation\n\t\t\t// Once the lock is acquired, business operations can be performed\n\t\t\t//todo\n\t\t\tprintln("do some options")\n\t\t},\n\t\t100*time.Second, // The third parameter is the lock\'s expiration time, type `')]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Duration"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("`; both the initial locking and subsequent renewals will use this value\n\t\t5*time.Second, // The fourth parameter is the interval for lock renewal, type `")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Duration`"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" periodically checks "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" the lock is about to expire"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" and renews the lock "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" it is within the next period\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("This approach is quite intelligent and is referred to as a “smart lock.” It is recommended for its ease of use and reduction in cognitive load.")]),t._v(" "),s("h2",{attrs:{id:"complete-example-code"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#complete-example-code"}},[t._v("#")]),t._v(" Complete Example Code")]),t._v(" "),s("p",[t._v("The source code for the example can be found "),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-redis",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),s("OutboundLink")],1)]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/redis"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"time"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Using the goner.RedisPriest function to embed Redis-related Goner into the Cemetery")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" redisUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcache redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cache "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-cache"`')]),t._v("\n\tlocker redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Locker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-locker"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tkey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-address"')]),t._v("\n\tvalue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/gone-io/gone"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Setting the cache")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Put")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the cache key, type `string`")]),t._v("\n\t\tvalue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is the value to cache, type any; the passed value will be encoded to `[]byte` and sent to Redis")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The third parameter is the expiration time, type `time.Duration`; if omitted, no expiration time is set")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Getting the cache")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" getValue "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the cache key, type `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is a pointer to receive the cached value, type any; the value retrieved from Redis will be decoded into the type of the passed pointer")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"getValue:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockTime")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Attempting to obtain the lock and lock it for a specific duration")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first returned parameter is a function to unlock")]),t._v("\n\tunlock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TryLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The first parameter is the lock key, type `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The second parameter is the lock's expiration time, type `time.Duration`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// After operations, you need to unlock")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unlock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Once the lock is acquired, business operations can be performed")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockTime")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/38.b0c6b2b7.js b/assets/js/38.7878a347.js similarity index 99% rename from assets/js/38.b0c6b2b7.js rename to assets/js/38.7878a347.js index b7e4137..09ce18f 100644 --- a/assets/js/38.b0c6b2b7.js +++ b/assets/js/38.7878a347.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[38],{319:function(t,e,s){"use strict";s.r(e);var a=s(10),n=Object(a.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"trace-log-with-traceid"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#trace-log-with-traceid"}},[t._v("#")]),t._v(" Trace Log with traceId")]),t._v(" "),e("p",[t._v("In web applications, a single request may go through many business processes. To facilitate troubleshooting, we want all logs generated by different business processes to have a unified traceId. Having a traceId allows us to link all logs related to the entire business process, making it easier to trace and analyze where problems occur in the business flow.")]),t._v(" "),e("p",[t._v("In other open-source frameworks, it's generally recommended to pass a "),e("code",[t._v("context.Context")]),t._v(" parameter to "),e("strong",[t._v("all")]),t._v(" functions, which is also recommended by the official Golang documentation. However, we believe that adding this extra parameter to every function is burdensome. We aim to avoid passing additional parameters to every function just to print a traceId in logs. Therefore, in Gone, we provide a built-in Goner to achieve this functionality.")]),t._v(" "),e("h2",{attrs:{id:"burying-related-goners-in-the-cemetery"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#burying-related-goners-in-the-cemetery"}},[t._v("#")]),t._v(" Burying Related Goners in the Cemetery")]),t._v(" "),e("blockquote",[e("p",[t._v("tip: To understand the core concepts and terminology of Gone, please read: "),e("a",{attrs:{href:"https://goner.fun/en/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Core Concepts of Gone"),e("OutboundLink")],1)])]),t._v(" "),e("p",[t._v("Here, we use the "),e("strong",[e("code",[t._v("BasePriest")])]),t._v(" from the package "),e("strong",[e("code",[t._v("github.com/gone-io/gone/tree/main/goner")])]),t._v(" to bury related Goners. In the "),e("code",[t._v("BasePriest")]),t._v(", Goners related to "),e("code",[t._v("tracer")]),t._v(", "),e("code",[t._v("config")]),t._v(", and "),e("code",[t._v("logrus")]),t._v(" are all buried into the Cemetery, as these three packages are commonly used together.")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury other Goners")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h2",{attrs:{id:"simple-usage"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#simple-usage"}},[t._v("#")]),t._v(" Simple Usage")]),t._v(" "),e("p",[t._v("When the tracer is buried, when we print logs using the injected "),e("code",[t._v("logrus.Logger")]),t._v(" interface, a traceId will automatically be added to the logs.")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" service "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n log logrus"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection into nested log attributes")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("service"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Business")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Print log")]),t._v("\n\tsvc"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),e("p",[t._v("For example, the "),e("code",[t._v("061ad00f-8c0d-479c-bc4c-393e0cf2cca2")]),t._v(" is the traceId:")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("2024-05-11 09:09:57.784|INFO|**/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46**|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080\n")])])]),e("h2",{attrs:{id:"passing-traceid-across-goroutines"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#passing-traceid-across-goroutines"}},[t._v("#")]),t._v(" Passing TraceId Across Goroutines")]),t._v(" "),e("p",[t._v("In the previous example, it's normal if no new goroutines are used. If a new goroutine is started using the "),e("code",[t._v("go")]),t._v(" keyword, it will be noticed that the logs printed by the goroutine do not have a traceId. To solve this, inject the "),e("code",[t._v("tracer.Tracer")]),t._v(" interface and use the "),e("code",[t._v("Go")]),t._v(" method instead of the "),e("code",[t._v("go")]),t._v(" keyword to start a new goroutine.")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" service "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n log logrus"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection into nested log attributes")]),t._v("\n tracer"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Tracer "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-tracer"`')]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Inject tracer")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("service"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Business")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\tsvc"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Go")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Print log in a new goroutine")]),t._v("\n\t\tsvc"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"log in new goroutine"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),e("h2",{attrs:{id:"passing-traceid-across-processes-services"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#passing-traceid-across-processes-services"}},[t._v("#")]),t._v(" Passing TraceId Across Processes/Services")]),t._v(" "),e("p",[t._v("In microservices, a web request typically spans multiple microservices. Cross-service communication is generally done through:")]),t._v(" "),e("ol",[e("li",[t._v("Message middleware\nTo facilitate the passing of traceId in the message middleware and to facilitate the use of the message middleware to pass business events, we have open-sourced the "),e("a",{attrs:{href:"https://github.com/gone-io/emitter",target:"_blank",rel:"noopener noreferrer"}},[t._v("https://github.com/gone-io/emitter"),e("OutboundLink")],1),t._v(" repository. In this repository, we have implemented an adapter for "),e("strong",[t._v("Rocket MQ")]),t._v(", and plan to adapt to other mainstream message middleware such as "),e("strong",[t._v("Kafka")]),t._v(" and "),e("strong",[t._v("RabbitMQ")]),t._v(" in the future.")]),t._v(" "),e("li",[t._v("RPC calls/internal http calls\nUse the built-in Goner "),e("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/goner/urllib",target:"_blank",rel:"noopener noreferrer"}},[t._v("urllib"),e("OutboundLink")],1),t._v(" to send http requests to Gone Web programs, and the traceId will be automatically passed between services. Additionally, using the built-in "),e("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/goner/grpc",target:"_blank",rel:"noopener noreferrer"}},[t._v("grpc"),e("OutboundLink")],1),t._v(" to implement gRPC calls will also automatically pass the traceId. More RPC call support will be provided in the future.")])]),t._v(" "),e("h2",{attrs:{id:"multi-language-support"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#multi-language-support"}},[t._v("#")]),t._v(" Multi-language Support")]),t._v(" "),e("p",[t._v("To pass the traceId in an HTTP request, a special header "),e("code",[t._v("X-Trace-ID")]),t._v(' is added to carry the traceId. Therefore, if multiple programming languages are used, as long as the different services follow the rule of "attaching '),e("code",[t._v("X-Trace-ID")]),t._v(" when making requests on the client side and parsing "),e("code",[t._v("X-Trace-ID")]),t._v(' when processing requests on the server side," traceId can be seamlessly passed across services developed in different languages.'),e("br"),t._v("\nWe plan to develop packages in other languages to seamlessly integrate with other languages in the future.")])])}),[],!1,null,null,null);e.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[38],{324:function(t,e,s){"use strict";s.r(e);var a=s(10),n=Object(a.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"trace-log-with-traceid"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#trace-log-with-traceid"}},[t._v("#")]),t._v(" Trace Log with traceId")]),t._v(" "),e("p",[t._v("In web applications, a single request may go through many business processes. To facilitate troubleshooting, we want all logs generated by different business processes to have a unified traceId. Having a traceId allows us to link all logs related to the entire business process, making it easier to trace and analyze where problems occur in the business flow.")]),t._v(" "),e("p",[t._v("In other open-source frameworks, it's generally recommended to pass a "),e("code",[t._v("context.Context")]),t._v(" parameter to "),e("strong",[t._v("all")]),t._v(" functions, which is also recommended by the official Golang documentation. However, we believe that adding this extra parameter to every function is burdensome. We aim to avoid passing additional parameters to every function just to print a traceId in logs. Therefore, in Gone, we provide a built-in Goner to achieve this functionality.")]),t._v(" "),e("h2",{attrs:{id:"burying-related-goners-in-the-cemetery"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#burying-related-goners-in-the-cemetery"}},[t._v("#")]),t._v(" Burying Related Goners in the Cemetery")]),t._v(" "),e("blockquote",[e("p",[t._v("tip: To understand the core concepts and terminology of Gone, please read: "),e("a",{attrs:{href:"https://goner.fun/en/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Core Concepts of Gone"),e("OutboundLink")],1)])]),t._v(" "),e("p",[t._v("Here, we use the "),e("strong",[e("code",[t._v("BasePriest")])]),t._v(" from the package "),e("strong",[e("code",[t._v("github.com/gone-io/gone/tree/main/goner")])]),t._v(" to bury related Goners. In the "),e("code",[t._v("BasePriest")]),t._v(", Goners related to "),e("code",[t._v("tracer")]),t._v(", "),e("code",[t._v("config")]),t._v(", and "),e("code",[t._v("logrus")]),t._v(" are all buried into the Cemetery, as these three packages are commonly used together.")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury other Goners")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h2",{attrs:{id:"simple-usage"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#simple-usage"}},[t._v("#")]),t._v(" Simple Usage")]),t._v(" "),e("p",[t._v("When the tracer is buried, when we print logs using the injected "),e("code",[t._v("logrus.Logger")]),t._v(" interface, a traceId will automatically be added to the logs.")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" service "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n log logrus"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection into nested log attributes")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("service"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Business")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Print log")]),t._v("\n\tsvc"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),e("p",[t._v("For example, the "),e("code",[t._v("061ad00f-8c0d-479c-bc4c-393e0cf2cca2")]),t._v(" is the traceId:")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("2024-05-11 09:09:57.784|INFO|**/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46**|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080\n")])])]),e("h2",{attrs:{id:"passing-traceid-across-goroutines"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#passing-traceid-across-goroutines"}},[t._v("#")]),t._v(" Passing TraceId Across Goroutines")]),t._v(" "),e("p",[t._v("In the previous example, it's normal if no new goroutines are used. If a new goroutine is started using the "),e("code",[t._v("go")]),t._v(" keyword, it will be noticed that the logs printed by the goroutine do not have a traceId. To solve this, inject the "),e("code",[t._v("tracer.Tracer")]),t._v(" interface and use the "),e("code",[t._v("Go")]),t._v(" method instead of the "),e("code",[t._v("go")]),t._v(" keyword to start a new goroutine.")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" service "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n log logrus"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named injection into nested log attributes")]),t._v("\n tracer"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Tracer "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-tracer"`')]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Inject tracer")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("service"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Business")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\tsvc"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Go")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Print log in a new goroutine")]),t._v("\n\t\tsvc"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"log in new goroutine"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),e("h2",{attrs:{id:"passing-traceid-across-processes-services"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#passing-traceid-across-processes-services"}},[t._v("#")]),t._v(" Passing TraceId Across Processes/Services")]),t._v(" "),e("p",[t._v("In microservices, a web request typically spans multiple microservices. Cross-service communication is generally done through:")]),t._v(" "),e("ol",[e("li",[t._v("Message middleware\nTo facilitate the passing of traceId in the message middleware and to facilitate the use of the message middleware to pass business events, we have open-sourced the "),e("a",{attrs:{href:"https://github.com/gone-io/emitter",target:"_blank",rel:"noopener noreferrer"}},[t._v("https://github.com/gone-io/emitter"),e("OutboundLink")],1),t._v(" repository. In this repository, we have implemented an adapter for "),e("strong",[t._v("Rocket MQ")]),t._v(", and plan to adapt to other mainstream message middleware such as "),e("strong",[t._v("Kafka")]),t._v(" and "),e("strong",[t._v("RabbitMQ")]),t._v(" in the future.")]),t._v(" "),e("li",[t._v("RPC calls/internal http calls\nUse the built-in Goner "),e("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/goner/urllib",target:"_blank",rel:"noopener noreferrer"}},[t._v("urllib"),e("OutboundLink")],1),t._v(" to send http requests to Gone Web programs, and the traceId will be automatically passed between services. Additionally, using the built-in "),e("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/goner/grpc",target:"_blank",rel:"noopener noreferrer"}},[t._v("grpc"),e("OutboundLink")],1),t._v(" to implement gRPC calls will also automatically pass the traceId. More RPC call support will be provided in the future.")])]),t._v(" "),e("h2",{attrs:{id:"multi-language-support"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#multi-language-support"}},[t._v("#")]),t._v(" Multi-language Support")]),t._v(" "),e("p",[t._v("To pass the traceId in an HTTP request, a special header "),e("code",[t._v("X-Trace-ID")]),t._v(' is added to carry the traceId. Therefore, if multiple programming languages are used, as long as the different services follow the rule of "attaching '),e("code",[t._v("X-Trace-ID")]),t._v(" when making requests on the client side and parsing "),e("code",[t._v("X-Trace-ID")]),t._v(' when processing requests on the server side," traceId can be seamlessly passed across services developed in different languages.'),e("br"),t._v("\nWe plan to develop packages in other languages to seamlessly integrate with other languages in the future.")])])}),[],!1,null,null,null);e.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/39.6bf1044b.js b/assets/js/39.b67e7c16.js similarity index 99% rename from assets/js/39.6bf1044b.js rename to assets/js/39.b67e7c16.js index 1b669db..cc0e165 100644 --- a/assets/js/39.6bf1044b.js +++ b/assets/js/39.b67e7c16.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[39],{323:function(t,n,s){"use strict";s.r(n);var a=s(10),e=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"unit-testing"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#unit-testing"}},[t._v("#")]),t._v(" Unit Testing")]),t._v(" "),n("p",[t._v("In a dependency injection framework, how to conduct unit tests involves injecting dependencies before testing. If the test content is closely related to the injected content, consider mocking the related content. One way is to manually bury the mocked Goner into the system, and another way is to replace an already buried Goner using "),n("code",[t._v("cemetery.ReplaceBury")]),t._v(".")]),t._v(" "),n("h2",{attrs:{id:"assume-our-written-goner-is-as-follows"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#assume-our-written-goner-is-as-follows"}},[t._v("#")]),t._v(" Assume Our Written Goner is as Follows")]),t._v(" "),n("p",[t._v("Filename: goner.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pointNameA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example-test-point-a"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pointNameB "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example-test-point-b"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointA")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameA\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointB")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("X"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Y"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameB\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Point "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tX "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,example.test.point.a-x"`')]),t._v("\n\tY "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,example.test.point.a-y,default=200"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Line "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"example-test-point-a"`')]),t._v("\n\tB "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"example-test-point-b"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewLine")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointA")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointB")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewLine")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"we-can-write-a-test-file-as-follows"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#we-can-write-a-test-file-as-follows"}},[t._v("#")]),t._v(" We Can Write a Test File as Follows:")]),t._v(" "),n("p",[t._v("Filename: goner_test.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test_Line")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config default"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("TestAt")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("pointNameA"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("point "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("X"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Y"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config default"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("line "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("A"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Y"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"ReplaceBury"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("line "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("A"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("X"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tMock "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("X"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("ReplaceBury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mock")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameA"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"using-gomock-for-mock-testing"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#using-gomock-for-mock-testing"}},[t._v("#")]),t._v(" Using gomock for Mock Testing")]),t._v(" "),n("p",[t._v("To decouple, we recommend using interfaces for injection; another reason for recommending interface injection is that Go provides an interface-based mock solution, allowing all dependencies to be mocked. However, mock implementations generated by "),n("code",[t._v("mockgen")]),t._v(" are not "),n("code",[t._v("Goner")]),t._v(" and thus cannot be buried or injected; for this, we provide a solution in our utility tools.")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("gone mock "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${fromGoFile}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outGoFile}")]),t._v("\n")])])]),n("p",[t._v("The "),n("code",[t._v("gone mock")]),t._v(" command adds the "),n("code",[t._v("gone.Flag")]),t._v(" to a mock object generated by "),n("code",[t._v("mockgen")]),t._v(", making it a Goner that can enter the Cemetery.")]),t._v(" "),n("p",[t._v("Typically, add a "),n("code",[t._v("//go:generate")]),t._v(" comment on the interface that needs mocking, and let the generation process complete automatically with the "),n("code",[t._v("go generate ./...")]),t._v(" command. Here's an example:")]),t._v(" "),n("p",[t._v("Filename: i_point.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v('//go:generate sh -c "mockgen -package=mock -source=$GOFILE | gone mock -o mock/$GOFILE"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" IPoint "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The above "),n("code",[t._v('//go:generate sh -c "mockgen -package=mock -source=$GOFILE | gone mock -o mock/$GOFILE"')]),t._v(" command first generates a mock object for the interface using mockgen, then pipes it to "),n("code",[t._v("gone mock")]),t._v(" to add the "),n("code",[t._v("gone.Flag")]),t._v(" tag.")]),t._v(" "),n("blockquote",[n("p",[t._v("Note: Keep the versions of the mockgen tool and gomock package consistent;\nRun the following code to install the latest versions:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go get github.com/golang/mock/gomock\ngo get github.com/golang/mock/mockgen\n")])])]),n("p",[t._v("The gone utility tool needs to be installed; installation reference "),n("a",{attrs:{href:"https://goner.fun/zh/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gone Utility Tools"),n("OutboundLink")],1),t._v(".")])]),t._v(" "),n("p",[t._v("Now, let's give it a try. Create an empty directory, enter it, create the "),n("code",[t._v("i_test.go")]),t._v(" file as mentioned, and run the command in the current")]),t._v(" "),n("p",[t._v("directory:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go generate ./"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\n")])])]),n("p",[t._v("You will see that after running the command, the file "),n("code",[t._v("mock/i_point.go")]),t._v(" is generated.")]),t._v(" "),n("p",[t._v("Next, create a file named "),n("code",[t._v("origin_point.go")]),t._v(" with the following content:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" originPoint "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewOriginPoint")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("o "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("o "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Create another file named "),n("code",[t._v("distance_calculator.go")]),t._v(" with the following content:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"math"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDistanceCalculator")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("distanceCalculator"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" distanceCalculator "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\toriginPoint IPoint "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("distanceCalculator"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" CalculateDistance "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("FromOrigin")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\toriginX"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" originY "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" d"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" d"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" math"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sqrt")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("math"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Pow")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("originX"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" math"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Pow")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("originY"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The "),n("code",[t._v("distanceCalculator")]),t._v("'s business is to calculate the distance from the point "),n("code",[t._v("(x,y int)")]),t._v(" to "),n("code",[t._v("originPoint")]),t._v(", where "),n("code",[t._v("originPoint")]),t._v(" is injected. Now let's write the test function for "),n("code",[t._v("CalculateDistanceFromOrigin")]),t._v(" as follows:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example/test/mock"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/golang/mock/gomock"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test_distanceCalculator_CalculateDistanceFromOrigin")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Create a mock controller")]),t._v("\n\tcontroller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" gomock"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewController")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" controller"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Finish")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("distanceCalculator"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tdistance "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" d"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("CalculateDistanceFromOrigin")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" distance"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Create a mock object")]),t._v("\n\t\tpoint "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" mock"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewMockIPoint")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("controller"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tpoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("EXPECT")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Return")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tpoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("EXPECT")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Return")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury the mock object in the Cemetery")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The object under test also needs to be buried in the Cemetery")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDistanceCalculator")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[39],{325:function(t,n,s){"use strict";s.r(n);var a=s(10),e=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"unit-testing"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#unit-testing"}},[t._v("#")]),t._v(" Unit Testing")]),t._v(" "),n("p",[t._v("In a dependency injection framework, how to conduct unit tests involves injecting dependencies before testing. If the test content is closely related to the injected content, consider mocking the related content. One way is to manually bury the mocked Goner into the system, and another way is to replace an already buried Goner using "),n("code",[t._v("cemetery.ReplaceBury")]),t._v(".")]),t._v(" "),n("h2",{attrs:{id:"assume-our-written-goner-is-as-follows"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#assume-our-written-goner-is-as-follows"}},[t._v("#")]),t._v(" Assume Our Written Goner is as Follows")]),t._v(" "),n("p",[t._v("Filename: goner.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pointNameA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example-test-point-a"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pointNameB "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example-test-point-b"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointA")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameA\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointB")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("X"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Y"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameB\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Point "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tX "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,example.test.point.a-x"`')]),t._v("\n\tY "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,example.test.point.a-y,default=200"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Line "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"example-test-point-a"`')]),t._v("\n\tB "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"example-test-point-b"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewLine")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointA")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointB")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewLine")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"we-can-write-a-test-file-as-follows"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#we-can-write-a-test-file-as-follows"}},[t._v("#")]),t._v(" We Can Write a Test File as Follows:")]),t._v(" "),n("p",[t._v("Filename: goner_test.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test_Line")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config default"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("TestAt")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("pointNameA"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("point "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("X"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Y"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config default"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("line "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("A"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Y"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"ReplaceBury"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("line "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" line"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("A"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("X"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tMock "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("X"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("ReplaceBury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mock")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameA"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"using-gomock-for-mock-testing"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#using-gomock-for-mock-testing"}},[t._v("#")]),t._v(" Using gomock for Mock Testing")]),t._v(" "),n("p",[t._v("To decouple, we recommend using interfaces for injection; another reason for recommending interface injection is that Go provides an interface-based mock solution, allowing all dependencies to be mocked. However, mock implementations generated by "),n("code",[t._v("mockgen")]),t._v(" are not "),n("code",[t._v("Goner")]),t._v(" and thus cannot be buried or injected; for this, we provide a solution in our utility tools.")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("gone mock "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${fromGoFile}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outGoFile}")]),t._v("\n")])])]),n("p",[t._v("The "),n("code",[t._v("gone mock")]),t._v(" command adds the "),n("code",[t._v("gone.Flag")]),t._v(" to a mock object generated by "),n("code",[t._v("mockgen")]),t._v(", making it a Goner that can enter the Cemetery.")]),t._v(" "),n("p",[t._v("Typically, add a "),n("code",[t._v("//go:generate")]),t._v(" comment on the interface that needs mocking, and let the generation process complete automatically with the "),n("code",[t._v("go generate ./...")]),t._v(" command. Here's an example:")]),t._v(" "),n("p",[t._v("Filename: i_point.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v('//go:generate sh -c "mockgen -package=mock -source=$GOFILE | gone mock -o mock/$GOFILE"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" IPoint "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The above "),n("code",[t._v('//go:generate sh -c "mockgen -package=mock -source=$GOFILE | gone mock -o mock/$GOFILE"')]),t._v(" command first generates a mock object for the interface using mockgen, then pipes it to "),n("code",[t._v("gone mock")]),t._v(" to add the "),n("code",[t._v("gone.Flag")]),t._v(" tag.")]),t._v(" "),n("blockquote",[n("p",[t._v("Note: Keep the versions of the mockgen tool and gomock package consistent;\nRun the following code to install the latest versions:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go get github.com/golang/mock/gomock\ngo get github.com/golang/mock/mockgen\n")])])]),n("p",[t._v("The gone utility tool needs to be installed; installation reference "),n("a",{attrs:{href:"https://goner.fun/zh/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gone Utility Tools"),n("OutboundLink")],1),t._v(".")])]),t._v(" "),n("p",[t._v("Now, let's give it a try. Create an empty directory, enter it, create the "),n("code",[t._v("i_test.go")]),t._v(" file as mentioned, and run the command in the current")]),t._v(" "),n("p",[t._v("directory:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go generate ./"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\n")])])]),n("p",[t._v("You will see that after running the command, the file "),n("code",[t._v("mock/i_point.go")]),t._v(" is generated.")]),t._v(" "),n("p",[t._v("Next, create a file named "),n("code",[t._v("origin_point.go")]),t._v(" with the following content:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" originPoint "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewOriginPoint")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("o "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("o "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("Create another file named "),n("code",[t._v("distance_calculator.go")]),t._v(" with the following content:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"math"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDistanceCalculator")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("distanceCalculator"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" distanceCalculator "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\toriginPoint IPoint "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("distanceCalculator"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" CalculateDistance "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("FromOrigin")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\toriginX"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" originY "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" d"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" d"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("originPoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" math"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sqrt")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("math"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Pow")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("originX"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" math"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Pow")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("originY"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The "),n("code",[t._v("distanceCalculator")]),t._v("'s business is to calculate the distance from the point "),n("code",[t._v("(x,y int)")]),t._v(" to "),n("code",[t._v("originPoint")]),t._v(", where "),n("code",[t._v("originPoint")]),t._v(" is injected. Now let's write the test function for "),n("code",[t._v("CalculateDistanceFromOrigin")]),t._v(" as follows:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example/test/mock"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/golang/mock/gomock"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test_distanceCalculator_CalculateDistanceFromOrigin")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Create a mock controller")]),t._v("\n\tcontroller "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" gomock"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewController")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" controller"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Finish")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("distanceCalculator"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tdistance "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" d"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("CalculateDistanceFromOrigin")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" distance"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Create a mock object")]),t._v("\n\t\tpoint "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" mock"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewMockIPoint")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("controller"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tpoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("EXPECT")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Return")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tpoint"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("EXPECT")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Return")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury the mock object in the Cemetery")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("point"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The object under test also needs to be buried in the Cemetery")]),t._v("\n\t\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDistanceCalculator")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/40.cbfe057b.js b/assets/js/40.c4fa55ea.js similarity index 99% rename from assets/js/40.cbfe057b.js rename to assets/js/40.c4fa55ea.js index a7b9698..d3bf4b7 100644 --- a/assets/js/40.cbfe057b.js +++ b/assets/js/40.c4fa55ea.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[40],{327:function(t,s,a){"use strict";a.r(s);var e=a(10),n=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"supporting-database-operations-with-built-in-goners"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#supporting-database-operations-with-built-in-goners"}},[t._v("#")]),t._v(" Supporting Database Operations with Built-in Goners")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#example-with-mysql"}},[t._v("Example with MySQL")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-prepare-mysql-service"}},[t._v("1. Prepare MySQL Service")])]),s("li",[s("a",{attrs:{href:"#_2-create-module-and-configuration"}},[t._v("2. Create Module and Configuration")])]),s("li",[s("a",{attrs:{href:"#_3-write-code"}},[t._v("3. Write Code")])]),s("li",[s("a",{attrs:{href:"#_4-run-the-code"}},[t._v("4. Run the Code")])])])]),s("li",[s("a",{attrs:{href:"#points-to-note"}},[t._v("Points to Note")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-github-com-gone-io-gone-goner-is-a-wrapper-for-xorm-io-xorm"}},[t._v("1. github.com/gone-io/gone/goner is a wrapper for xorm.io/xorm")])]),s("li",[s("a",{attrs:{href:"#_2-injection-via-gone-xorm-gonerid"}},[t._v("2. Injection via gone-xorm GonerId")])]),s("li",[s("a",{attrs:{href:"#_3-pay-attention-to-imported-packages"}},[t._v("3. Pay Attention to Imported Packages")])])])])])]),s("p"),t._v(" "),s("h2",{attrs:{id:"example-with-mysql"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#example-with-mysql"}},[t._v("#")]),t._v(" Example with MySQL")]),t._v(" "),s("h3",{attrs:{id:"_1-prepare-mysql-service"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-prepare-mysql-service"}},[t._v("#")]),t._v(" 1. Prepare MySQL Service")]),t._v(" "),s("p",[t._v("You can quickly set up a MySQL service using Docker Compose. Create a "),s("code",[t._v("docker-compose.yaml")]),t._v(" file with the following content:")]),t._v(" "),s("div",{staticClass:"language-yaml extra-class"},[s("pre",{pre:!0,attrs:{class:"language-yaml"}},[s("code",[s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("version")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3.5"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("services")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("mysql")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("image")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" mysql"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8.3")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("restart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" unless"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v("stopped\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("environment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("MYSQL_ROOT_PASSWORD")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("123456")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("MYSQL_DATABASE")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" demo\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("volumes")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v(" ./data/mysql"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("/var/lib/mysql\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("ports")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3306:3306"')]),t._v("\n")])])]),s("p",[t._v("Run the following command in the terminal to start the MySQL service:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("docker-compose")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" docker-compose.yaml up "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v("\n")])])]),s("h3",{attrs:{id:"_2-create-module-and-configuration"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-create-module-and-configuration"}},[t._v("#")]),t._v(" 2. Create Module and Configuration")]),t._v(" "),s("p",[t._v("Execute the following commands to set up the project structure and configuration:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" use-rdb\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" use-rdb\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Initialize Go module")]),t._v("\ngo mod init use-rdb\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Create database configuration")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" config\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("cat")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">>")]),t._v(" config/default.properties"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("eof\n\n# Use MySQL database\ndatabase.driver-name=mysql\n\n# Data Source Name (DSN)\ndatabase.dsn=root:123456@tcp(localhost:3306)/demo?charset=utf8mb4&loc=Local\neof")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-write-code"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-write-code"}},[t._v("#")]),t._v(" 3. Write Code")]),t._v(" "),s("p",[t._v("Create a file named "),s("code",[t._v("main.go")]),t._v(" with the following code:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/go-sql-driver/mysql"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ⚠️ Import MySQL driver explicitly")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ⚠️ Import xorm package from gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Demo "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tId "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v("\n\tData "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SqlExecutor "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tdb xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("e "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("SqlExecutor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Execute")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Synchronize table structure")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sync")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("new")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tdemo "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hello gone"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Insert data")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Insert")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\tDemo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"The most Spring programmer-friendly Golang framework, dependency injection, integrates Web. "')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"demo: %v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Demo\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Read data")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Find")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"demo records:%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury xorm-related Goners into the cemetery using goner.XormPriest")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("XormPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("SqlExecutor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Execute after the Gone application starts")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\te SqlExecutor "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Execute")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"_4-run-the-code"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-run-the-code"}},[t._v("#")]),t._v(" 4. Run the Code")]),t._v(" "),s("p",[t._v("Run the following commands:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go mod tidy\ngo run main.go\n")])])]),s("p",[t._v("The running result is as follows:")]),t._v(" "),s("div",{staticClass:"language-log extra-class"},[s("div",{staticClass:"highlight-lines"},[s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("div",{staticClass:"highlighted"},[t._v(" ")]),s("div",{staticClass:"highlighted"},[t._v(" ")]),s("br")]),s("pre",{pre:!0,attrs:{class:"language-log"}},[s("code",[s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.767")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("heaven\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("cemetery\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("tracer"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("tracer\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logrus"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logger\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logrus"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logger\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("Use Env"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" local\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build1582606196/b001/exe/config/default.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build1582606196/b001/exe/config/local.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/works/gone-io/gone/example/use-rdb/config/local.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("xorm"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("engine\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive main"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("SqlExecutor\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.769")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/go/pkg/mod/xorm.io/xorm@v1.3.2/log/logger_context.go")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("90")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("PING DATABASE mysql\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.783")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/works/gone-io/gone/cemetery.go")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("307")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("\ndemo"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" hello gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),t._v("\ndemo records"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" hello gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v(" The most Spring programmer"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("friendly Golang framework"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" dependency injection"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" integrates Web"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"points-to-note"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#points-to-note"}},[t._v("#")]),t._v(" Points to Note")]),t._v(" "),s("h3",{attrs:{id:"_1-github-com-gone-io-gone-goner-is-a-wrapper-for-xorm-io-xorm"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-github-com-gone-io-gone-goner-is-a-wrapper-for-xorm-io-xorm"}},[t._v("#")]),t._v(" 1. "),s("code",[t._v("github.com/gone-io/gone/goner")]),t._v(" is a wrapper for "),s("code",[t._v("xorm.io/xorm")])]),t._v(" "),s("p",[t._v("The wrapper logic is roughly as follows: "),s("code",[t._v("xorm")]),t._v(" is wrapped as an "),s("a",{attrs:{href:"https://goner.fun/en/guide/core-concept.html#%F0%9F%98%87angel-%E5%A4%A9%E4%BD%BF",target:"_blank",rel:"noopener noreferrer"}},[t._v("Angel Goner"),s("OutboundLink")],1),t._v("; data connection is established in the "),s("code",[t._v("Start")]),t._v(" method, and the database connection is closed in the "),s("code",[t._v("Stop")]),t._v(" method. When using it, there is no need to import the "),s("code",[t._v("xorm.io/xorm")]),t._v(" package directly, only "),s("code",[t._v("github.com/gone-io/gone/goner")]),t._v(" needs to be imported. The wrapper relies on "),s("code",[t._v("github.com/gone-io/gone/tree/main/goner/config")]),t._v(" to implement configuration. The burial of configuration-related Goners is automatically completed in the "),s("code",[t._v("goner.XormPriest")]),t._v(" function.\nSupported configuration items in the configuration file:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("database.driver-name")]),t._v(": Name of the driver, supports mainstream databases like MySQL, PostgreSQL, etc. For details, refer to the "),s("a",{attrs:{href:"https://xorm.io/docs/1.engine/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm documentation"),s("OutboundLink")],1)]),t._v(" "),s("li",[s("code",[t._v("database.dsn")]),t._v(": Data source name, refer to the "),s("a",{attrs:{href:"https://xorm.io/docs/1.engine/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm documentation"),s("OutboundLink")],1)]),t._v(" "),s("li",[s("code",[t._v("database.max-idle-count")]),t._v(": Maximum number of idle connections in the connection pool")]),t._v(" "),s("li",[s("code",[t._v("database.max-open")]),t._v(": Maximum number of connections in the connection pool")]),t._v(" "),s("li",[s("code",[t._v("database.max-lifetime")]),t._v(": Maximum lifetime of a connection")]),t._v(" "),s("li",[s("code",[t._v("database.showSql")]),t._v(": Whether to print executed SQL statements")])]),t._v(" "),s("h3",{attrs:{id:"_2-injection-via-gone-xorm-gonerid"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-injection-via-gone-xorm-gonerid"}},[t._v("#")]),t._v(" 2. Injection via "),s("code",[t._v("gone-xorm")]),t._v(" "),s("strong",[t._v("GonerId")])]),t._v(" "),s("p",[t._v("In the Goner where the xorm engine is needed, use the "),s("code",[t._v('gone:"gone-xorm"')]),t._v(" tag to inject "),s("code",[t._v("xorm.Engine")]),t._v(", properties can be named or anonymous:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" XormUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named")]),t._v("\n db xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Or")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" XormUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Anonymous")]),t._v("\n xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[s("code",[t._v("xorm.Engine")]),t._v(' "inherits" the '),s("code",[t._v("xorm.io/xorm.EngineInterface")]),t._v(" interface, so "),s("code",[t._v("xorm.Engine")]),t._v(" supports all methods in the "),s("a",{attrs:{href:"https://xorm.io/docs/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm documentation"),s("OutboundLink")],1),t._v(".")]),t._v(" "),s("h3",{attrs:{id:"_3-pay-attention-to-imported-packages"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-pay-attention-to-imported-packages"}},[t._v("#")]),t._v(" 3. Pay Attention to Imported Packages")]),t._v(" "),s("ul",[s("li",[t._v("Import the database driver, which varies for different databases:")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/go-sql-driver/mysql"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("ul",[s("li",[t._v("Import the xorm package as "),s("code",[t._v("github.com/gone-io/gone/goner/xorm")]),t._v(", not "),s("code",[t._v("xorm.io/xorm")]),t._v(":")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v(" #📢⚠️Special attention needed"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" the xorm "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" wrapped by gone\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[40],{326:function(t,s,a){"use strict";a.r(s);var e=a(10),n=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"supporting-database-operations-with-built-in-goners"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#supporting-database-operations-with-built-in-goners"}},[t._v("#")]),t._v(" Supporting Database Operations with Built-in Goners")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#example-with-mysql"}},[t._v("Example with MySQL")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-prepare-mysql-service"}},[t._v("1. Prepare MySQL Service")])]),s("li",[s("a",{attrs:{href:"#_2-create-module-and-configuration"}},[t._v("2. Create Module and Configuration")])]),s("li",[s("a",{attrs:{href:"#_3-write-code"}},[t._v("3. Write Code")])]),s("li",[s("a",{attrs:{href:"#_4-run-the-code"}},[t._v("4. Run the Code")])])])]),s("li",[s("a",{attrs:{href:"#points-to-note"}},[t._v("Points to Note")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-github-com-gone-io-gone-goner-is-a-wrapper-for-xorm-io-xorm"}},[t._v("1. github.com/gone-io/gone/goner is a wrapper for xorm.io/xorm")])]),s("li",[s("a",{attrs:{href:"#_2-injection-via-gone-xorm-gonerid"}},[t._v("2. Injection via gone-xorm GonerId")])]),s("li",[s("a",{attrs:{href:"#_3-pay-attention-to-imported-packages"}},[t._v("3. Pay Attention to Imported Packages")])])])])])]),s("p"),t._v(" "),s("h2",{attrs:{id:"example-with-mysql"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#example-with-mysql"}},[t._v("#")]),t._v(" Example with MySQL")]),t._v(" "),s("h3",{attrs:{id:"_1-prepare-mysql-service"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-prepare-mysql-service"}},[t._v("#")]),t._v(" 1. Prepare MySQL Service")]),t._v(" "),s("p",[t._v("You can quickly set up a MySQL service using Docker Compose. Create a "),s("code",[t._v("docker-compose.yaml")]),t._v(" file with the following content:")]),t._v(" "),s("div",{staticClass:"language-yaml extra-class"},[s("pre",{pre:!0,attrs:{class:"language-yaml"}},[s("code",[s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("version")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3.5"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("services")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("mysql")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("image")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" mysql"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8.3")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("restart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" unless"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v("stopped\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("environment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("MYSQL_ROOT_PASSWORD")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("123456")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("MYSQL_DATABASE")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" demo\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("volumes")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v(" ./data/mysql"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("/var/lib/mysql\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("ports")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3306:3306"')]),t._v("\n")])])]),s("p",[t._v("Run the following command in the terminal to start the MySQL service:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("docker-compose")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" docker-compose.yaml up "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v("\n")])])]),s("h3",{attrs:{id:"_2-create-module-and-configuration"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-create-module-and-configuration"}},[t._v("#")]),t._v(" 2. Create Module and Configuration")]),t._v(" "),s("p",[t._v("Execute the following commands to set up the project structure and configuration:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" use-rdb\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" use-rdb\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Initialize Go module")]),t._v("\ngo mod init use-rdb\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Create database configuration")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" config\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("cat")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">>")]),t._v(" config/default.properties"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("eof\n\n# Use MySQL database\ndatabase.driver-name=mysql\n\n# Data Source Name (DSN)\ndatabase.dsn=root:123456@tcp(localhost:3306)/demo?charset=utf8mb4&loc=Local\neof")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-write-code"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-write-code"}},[t._v("#")]),t._v(" 3. Write Code")]),t._v(" "),s("p",[t._v("Create a file named "),s("code",[t._v("main.go")]),t._v(" with the following code:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/go-sql-driver/mysql"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ⚠️ Import MySQL driver explicitly")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ⚠️ Import xorm package from gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Demo "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tId "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v("\n\tData "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SqlExecutor "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tdb xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("e "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("SqlExecutor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Execute")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Synchronize table structure")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sync")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("new")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tdemo "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hello gone"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Insert data")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Insert")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\tDemo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"The most Spring programmer-friendly Golang framework, dependency injection, integrates Web. "')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"demo: %v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Demo\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Read data")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Find")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"demo records:%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Bury xorm-related Goners into the cemetery using goner.XormPriest")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("XormPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("SqlExecutor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Execute after the Gone application starts")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\te SqlExecutor "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Execute")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"_4-run-the-code"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-run-the-code"}},[t._v("#")]),t._v(" 4. Run the Code")]),t._v(" "),s("p",[t._v("Run the following commands:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go mod tidy\ngo run main.go\n")])])]),s("p",[t._v("The running result is as follows:")]),t._v(" "),s("div",{staticClass:"language-log extra-class"},[s("div",{staticClass:"highlight-lines"},[s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("div",{staticClass:"highlighted"},[t._v(" ")]),s("div",{staticClass:"highlighted"},[t._v(" ")]),s("br")]),s("pre",{pre:!0,attrs:{class:"language-log"}},[s("code",[s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.767")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("heaven\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("cemetery\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("tracer"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("tracer\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logrus"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logger\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logrus"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logger\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("Use Env"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" local\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build1582606196/b001/exe/config/default.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build1582606196/b001/exe/config/local.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/works/gone-io/gone/example/use-rdb/config/local.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("xorm"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("engine\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive main"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("SqlExecutor\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.769")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/go/pkg/mod/xorm.io/xorm@v1.3.2/log/logger_context.go")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("90")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("PING DATABASE mysql\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.783")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/works/gone-io/gone/cemetery.go")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("307")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("\ndemo"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" hello gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),t._v("\ndemo records"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" hello gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v(" The most Spring programmer"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("friendly Golang framework"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" dependency injection"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" integrates Web"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"points-to-note"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#points-to-note"}},[t._v("#")]),t._v(" Points to Note")]),t._v(" "),s("h3",{attrs:{id:"_1-github-com-gone-io-gone-goner-is-a-wrapper-for-xorm-io-xorm"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-github-com-gone-io-gone-goner-is-a-wrapper-for-xorm-io-xorm"}},[t._v("#")]),t._v(" 1. "),s("code",[t._v("github.com/gone-io/gone/goner")]),t._v(" is a wrapper for "),s("code",[t._v("xorm.io/xorm")])]),t._v(" "),s("p",[t._v("The wrapper logic is roughly as follows: "),s("code",[t._v("xorm")]),t._v(" is wrapped as an "),s("a",{attrs:{href:"https://goner.fun/en/guide/core-concept.html#%F0%9F%98%87angel-%E5%A4%A9%E4%BD%BF",target:"_blank",rel:"noopener noreferrer"}},[t._v("Angel Goner"),s("OutboundLink")],1),t._v("; data connection is established in the "),s("code",[t._v("Start")]),t._v(" method, and the database connection is closed in the "),s("code",[t._v("Stop")]),t._v(" method. When using it, there is no need to import the "),s("code",[t._v("xorm.io/xorm")]),t._v(" package directly, only "),s("code",[t._v("github.com/gone-io/gone/goner")]),t._v(" needs to be imported. The wrapper relies on "),s("code",[t._v("github.com/gone-io/gone/tree/main/goner/config")]),t._v(" to implement configuration. The burial of configuration-related Goners is automatically completed in the "),s("code",[t._v("goner.XormPriest")]),t._v(" function.\nSupported configuration items in the configuration file:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("database.driver-name")]),t._v(": Name of the driver, supports mainstream databases like MySQL, PostgreSQL, etc. For details, refer to the "),s("a",{attrs:{href:"https://xorm.io/docs/1.engine/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm documentation"),s("OutboundLink")],1)]),t._v(" "),s("li",[s("code",[t._v("database.dsn")]),t._v(": Data source name, refer to the "),s("a",{attrs:{href:"https://xorm.io/docs/1.engine/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm documentation"),s("OutboundLink")],1)]),t._v(" "),s("li",[s("code",[t._v("database.max-idle-count")]),t._v(": Maximum number of idle connections in the connection pool")]),t._v(" "),s("li",[s("code",[t._v("database.max-open")]),t._v(": Maximum number of connections in the connection pool")]),t._v(" "),s("li",[s("code",[t._v("database.max-lifetime")]),t._v(": Maximum lifetime of a connection")]),t._v(" "),s("li",[s("code",[t._v("database.showSql")]),t._v(": Whether to print executed SQL statements")])]),t._v(" "),s("h3",{attrs:{id:"_2-injection-via-gone-xorm-gonerid"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-injection-via-gone-xorm-gonerid"}},[t._v("#")]),t._v(" 2. Injection via "),s("code",[t._v("gone-xorm")]),t._v(" "),s("strong",[t._v("GonerId")])]),t._v(" "),s("p",[t._v("In the Goner where the xorm engine is needed, use the "),s("code",[t._v('gone:"gone-xorm"')]),t._v(" tag to inject "),s("code",[t._v("xorm.Engine")]),t._v(", properties can be named or anonymous:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" XormUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Named")]),t._v("\n db xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Or")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" XormUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Anonymous")]),t._v("\n xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[s("code",[t._v("xorm.Engine")]),t._v(' "inherits" the '),s("code",[t._v("xorm.io/xorm.EngineInterface")]),t._v(" interface, so "),s("code",[t._v("xorm.Engine")]),t._v(" supports all methods in the "),s("a",{attrs:{href:"https://xorm.io/docs/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm documentation"),s("OutboundLink")],1),t._v(".")]),t._v(" "),s("h3",{attrs:{id:"_3-pay-attention-to-imported-packages"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-pay-attention-to-imported-packages"}},[t._v("#")]),t._v(" 3. Pay Attention to Imported Packages")]),t._v(" "),s("ul",[s("li",[t._v("Import the database driver, which varies for different databases:")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/go-sql-driver/mysql"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("ul",[s("li",[t._v("Import the xorm package as "),s("code",[t._v("github.com/gone-io/gone/goner/xorm")]),t._v(", not "),s("code",[t._v("xorm.io/xorm")]),t._v(":")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v(" #📢⚠️Special attention needed"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" the xorm "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" wrapped by gone\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/41.c46402f6.js b/assets/js/41.0ef67c63.js similarity index 95% rename from assets/js/41.c46402f6.js rename to assets/js/41.0ef67c63.js index 4166de5..25c8fcd 100644 --- a/assets/js/41.c46402f6.js +++ b/assets/js/41.0ef67c63.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[41],{333:function(t,e,r){"use strict";r.r(e);var a=r(10),s=Object(a.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"quick-start"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#quick-start"}},[t._v("#")]),t._v(" Quick Start")]),t._v(" "),e("h2",{attrs:{id:"create-a-simple-web-project"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#create-a-simple-web-project"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/quick-start/simple.html"}},[t._v("Create a Simple Web Project")])],1),t._v(" "),e("h2",{attrs:{id:"create-a-production-ready-project-using-mysql"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#create-a-production-ready-project-using-mysql"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/quick-start/simple.html"}},[t._v("Create a Production-Ready Project Using MySQL")])],1),t._v(" "),e("h2",{attrs:{id:"more-examples"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#more-examples"}},[t._v("#")]),t._v(" "),e("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example",target:"_blank",rel:"noopener noreferrer"}},[t._v("More Examples"),e("OutboundLink")],1)])])}),[],!1,null,null,null);e.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[41],{327:function(t,e,r){"use strict";r.r(e);var a=r(10),s=Object(a.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"quick-start"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#quick-start"}},[t._v("#")]),t._v(" Quick Start")]),t._v(" "),e("h2",{attrs:{id:"create-a-simple-web-project"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#create-a-simple-web-project"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/quick-start/simple.html"}},[t._v("Create a Simple Web Project")])],1),t._v(" "),e("h2",{attrs:{id:"create-a-production-ready-project-using-mysql"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#create-a-production-ready-project-using-mysql"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/quick-start/simple.html"}},[t._v("Create a Production-Ready Project Using MySQL")])],1),t._v(" "),e("h2",{attrs:{id:"more-examples"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#more-examples"}},[t._v("#")]),t._v(" "),e("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example",target:"_blank",rel:"noopener noreferrer"}},[t._v("More Examples"),e("OutboundLink")],1)])])}),[],!1,null,null,null);e.default=s.exports}}]); \ No newline at end of file diff --git a/assets/js/42.1aed1e2b.js b/assets/js/42.1ad17145.js similarity index 99% rename from assets/js/42.1aed1e2b.js rename to assets/js/42.1ad17145.js index 1b878c7..3926b30 100644 --- a/assets/js/42.1aed1e2b.js +++ b/assets/js/42.1ad17145.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[42],{324:function(t,n,a){"use strict";a.r(n);var s=a(10),e=Object(s.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"creating-a-simple-web-project"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#creating-a-simple-web-project"}},[t._v("#")]),t._v(" Creating a Simple Web Project")]),t._v(" "),n("h2",{attrs:{id:"installing-the-gone-utility-tool"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#installing-the-gone-utility-tool"}},[t._v("#")]),t._v(" Installing the Gone Utility Tool")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),n("blockquote",[n("p",[t._v("After installation, you can use the gone command:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("gone "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v("\n")])])]),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("\t➜ demo gone "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v("\n\tNAME:\n\tgone - A new cli application\n\n\tUSAGE:\n\tgone "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("global options"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("command")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("command options"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("arguments"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n\tDESCRIPTION:\n\tgenerate gone code or generate gone app\n\n\tCOMMANDS:\n\tpriest "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-s")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${scanPackageDir}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-p")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${pkgName}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${funcName}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outputFilePath}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-w"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\tmock "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${fromGoFile}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outGoFile}")]),t._v("\n\tcreate "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-t "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${template}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-m "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${modName}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${appName}")]),t._v("\n\thelp, h Shows a list of commands or "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("help")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" one "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("command")]),t._v("\n\n\tGLOBAL OPTIONS:\n\t--help, "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v(" show "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("help")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("default: "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),n("p",[t._v("Supported functionalities:")]),t._v(" "),n("ol",[n("li",[t._v("create: Create a Gone app, currently only supports creating web apps.")]),t._v(" "),n("li",[t._v("priest: Automatically generate the "),n("strong",[t._v("Priest")]),t._v(" function for the project. "),n("RouterLink",{attrs:{to:"/"}},[t._v("Learn More")])],1),t._v(" "),n("li",[t._v("Generating mock code for testing.")])])]),t._v(" "),n("h2",{attrs:{id:"creating-a-web-project-and-running-the-code"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#creating-a-web-project-and-running-the-code"}},[t._v("#")]),t._v(" Creating a Web Project and Running the Code")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Create a project named web-app")]),t._v("\ngone create web-app\n"),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" web-app\n"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n")])])]),n("h2",{attrs:{id:"project-structure"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#project-structure"}},[t._v("#")]),t._v(" Project Structure")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("├── Dockerfile\n├── Makefile\n├── README.md\n├── cmd\n│ └── server\n│ └── main.go // Startup file, containing the main function.\n├── config // Project configuration directory, supporting "),n("span",{pre:!0,attrs:{class:"token variable"}},[n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("`")]),t._v(".properties"),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("`")])]),t._v(" files.\n│ ├── default.properties\n│ ├── dev.properties\n│ ├── local.properties\n│ └── prod.properties\n├── docker-compose.yaml\n├── go.mod\n├── internal\n│ ├── controller // Controller directory, "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" defining routes "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" files.\n│ │ └── demo_ctr.go\n│ ├── interface\n│ │ ├── domain // Directory "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" domain objects.\n│ │ │ ├── demo.go\n│ │ │ └── user.go\n│ │ └── "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v(" // Directory "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v(" interface definitions.\n│ │ └── i_demo.go\n│ ├── master.go\n│ ├── middleware // Middleware directory, "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" defining web middleware.\n│ │ ├── authorize.go\n│ │ └── pub.go\n│ ├── module // Module directory, each subdirectory implements a module's functionality, typically defined "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" internal/interface/service/.\n│ │ └── demo\n│ │ ├── demo_svc.go\n│ │ └── error.go\n│ ├── pkg\n│ │ └── utils\n│ │ └── error.go\n│ └── router // Define routers "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" this directory.\n│ ├── auth_router.go\n│ └── pub_router.go\n└── tests\n └── api\n └── demo.http\n")])])]),n("h2",{attrs:{id:"router"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#router"}},[t._v("#")]),t._v(" Router")]),t._v(" "),n("p",[t._v("In the directory "),n("code",[t._v("internal/router")]),t._v(", two "),n("code",[t._v("gin.IRouter")]),t._v("s are implemented:")]),t._v(" "),n("ul",[n("li",[t._v("pubRouter: Public router, endpoints mounted under this router can be accessed without authorization.")]),t._v(" "),n("li",[t._v("authRouter: Authenticated router, endpoints mounted under this router require authorization.")])]),t._v(" "),n("p",[t._v("Let's analyze the code in "),n("code",[t._v("internal/router/pub_router.go")]),t._v(":")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" router\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/middleware"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" IdRouterPub "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"router-pub"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPubRouter")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("pubRouter"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" IdRouterPub\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" pubRouter "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter\n\troot gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-gin-router"`')]),t._v("\n\tpub "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("middleware"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("PubMiddleware "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("pubRouter"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("root"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/api"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" r"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pub"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Next"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("ol",[n("li",[t._v("For routers, they need to implement the methods defined in "),n("code",[t._v("gone.IRouter")]),t._v(".")]),t._v(" "),n("li",[t._v("The struct "),n("code",[t._v("pubRouter")]),t._v(" embeds an "),n("code",[t._v("gone.IRouter")]),t._v(", which means it directly implements the "),n("code",[t._v("gone.IRouter")]),t._v(" interface. It is only assigned a value in "),n("code",[t._v("AfterRevive()")]),t._v(".")]),t._v(" "),n("li",[n("code",[t._v('r.IRouter = r.root.Group("/api", r.pub.Next)')]),t._v(" means the current router is a subrouter under the root router at "),n("code",[t._v("/api")]),t._v(", with an additional middleware "),n("code",[t._v("r.pub.Next")]),t._v(".")]),t._v(" "),n("li",[n("code",[t._v("root gone.IRouter")]),t._v(" is a framework-level Goner provided by the "),n("code",[t._v("github.com/gone-io/gone/goner/gin")]),t._v(" package, with a named injection "),n("code",[t._v("gone-gin-router")]),t._v(".")])]),t._v(" "),n("h2",{attrs:{id:"controller"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#controller"}},[t._v("#")]),t._v(" Controller")]),t._v(" "),n("p",[t._v("Below is the definition of the Controller interface:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Controller interface, implemented by business code to mount and handle routes")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// For usage, refer to [Sample Code](https://gitlab.openviewtech.com/gone/gone-example/-/tree/master/gone-app)")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Controller "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Mount Route mounting interface, this function will be called before service startup, and the implementation of this function should usually return `nil`")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" MountError\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("To write HTTP interfaces, we need to implement the "),n("code",[t._v("Controller")]),t._v(" interface and mount the interface routes in the "),n("code",[t._v("Mount")]),t._v(" method, as shown in the code in "),n("code",[t._v("internal/controller/demo_ctr.go")]),t._v(":")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" controller\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/service"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/pkg/utils"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemoController")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" demoController "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tdemoSvc service"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IDemo "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Dependency injection of service")]),t._v("\n\n\tauthRouter gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"router-auth"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Router injection")]),t._v("\n\tpubRouter gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"router-pub"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Router injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GinMountError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\tctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tauthRouter"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/demo"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/show"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("showDemo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tpubRouter"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/demo2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/show"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("showDemo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/error"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/echo"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("echo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("showDemo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Show")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("echo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Req "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tEcho "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`form:"echo"`')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" req Req\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" ctx"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bind")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("req"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewParameterError")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" utils"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ParameterParseError"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("req"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Echo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"service"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#service"}},[t._v("#")]),t._v(" Service")]),t._v(" "),n("p",[t._v("As per the standard, we require service interfaces to be defined in the "),n("code",[t._v("internal/interface/service")]),t._v(" directory. File names should begin with "),n("code",[t._v("i_")]),t._v(", and interface types should start with "),n("code",[t._v("I")]),t._v(", for example:")]),t._v(" "),n("p",[t._v("File: i_demo.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" service\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/domain"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" IDemo "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Show")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("DemoEntity"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The logic implementation of services is placed in the "),n("code",[t._v("internal/module")]),t._v(" directory, organized into modules.")]),t._v(" "),n("h2",{attrs:{id:"use-database"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#use-database"}},[t._v("#")]),t._v(" "),n("a",{attrs:{href:"https://goner.fun/guide/xorm.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Use Database"),n("OutboundLink")],1)])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[42],{329:function(t,n,a){"use strict";a.r(n);var s=a(10),e=Object(s.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"creating-a-simple-web-project"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#creating-a-simple-web-project"}},[t._v("#")]),t._v(" Creating a Simple Web Project")]),t._v(" "),n("h2",{attrs:{id:"installing-the-gone-utility-tool"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#installing-the-gone-utility-tool"}},[t._v("#")]),t._v(" Installing the Gone Utility Tool")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("go "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),n("blockquote",[n("p",[t._v("After installation, you can use the gone command:")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("gone "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v("\n")])])]),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("\t➜ demo gone "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v("\n\tNAME:\n\tgone - A new cli application\n\n\tUSAGE:\n\tgone "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("global options"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("command")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("command options"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("arguments"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n\tDESCRIPTION:\n\tgenerate gone code or generate gone app\n\n\tCOMMANDS:\n\tpriest "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-s")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${scanPackageDir}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-p")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${pkgName}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${funcName}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outputFilePath}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-w"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\tmock "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${fromGoFile}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outGoFile}")]),t._v("\n\tcreate "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-t "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${template}")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-m "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${modName}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${appName}")]),t._v("\n\thelp, h Shows a list of commands or "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("help")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" one "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("command")]),t._v("\n\n\tGLOBAL OPTIONS:\n\t--help, "),n("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v(" show "),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("help")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("default: "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),n("p",[t._v("Supported functionalities:")]),t._v(" "),n("ol",[n("li",[t._v("create: Create a Gone app, currently only supports creating web apps.")]),t._v(" "),n("li",[t._v("priest: Automatically generate the "),n("strong",[t._v("Priest")]),t._v(" function for the project. "),n("RouterLink",{attrs:{to:"/"}},[t._v("Learn More")])],1),t._v(" "),n("li",[t._v("Generating mock code for testing.")])])]),t._v(" "),n("h2",{attrs:{id:"creating-a-web-project-and-running-the-code"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#creating-a-web-project-and-running-the-code"}},[t._v("#")]),t._v(" Creating a Web Project and Running the Code")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# Create a project named web-app")]),t._v("\ngone create web-app\n"),n("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" web-app\n"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n")])])]),n("h2",{attrs:{id:"project-structure"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#project-structure"}},[t._v("#")]),t._v(" Project Structure")]),t._v(" "),n("div",{staticClass:"language-bash extra-class"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[t._v("├── Dockerfile\n├── Makefile\n├── README.md\n├── cmd\n│ └── server\n│ └── main.go // Startup file, containing the main function.\n├── config // Project configuration directory, supporting "),n("span",{pre:!0,attrs:{class:"token variable"}},[n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("`")]),t._v(".properties"),n("span",{pre:!0,attrs:{class:"token variable"}},[t._v("`")])]),t._v(" files.\n│ ├── default.properties\n│ ├── dev.properties\n│ ├── local.properties\n│ └── prod.properties\n├── docker-compose.yaml\n├── go.mod\n├── internal\n│ ├── controller // Controller directory, "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" defining routes "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" files.\n│ │ └── demo_ctr.go\n│ ├── interface\n│ │ ├── domain // Directory "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" domain objects.\n│ │ │ ├── demo.go\n│ │ │ └── user.go\n│ │ └── "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v(" // Directory "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v(" interface definitions.\n│ │ └── i_demo.go\n│ ├── master.go\n│ ├── middleware // Middleware directory, "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" defining web middleware.\n│ │ ├── authorize.go\n│ │ └── pub.go\n│ ├── module // Module directory, each subdirectory implements a module's functionality, typically defined "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" internal/interface/service/.\n│ │ └── demo\n│ │ ├── demo_svc.go\n│ │ └── error.go\n│ ├── pkg\n│ │ └── utils\n│ │ └── error.go\n│ └── router // Define routers "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" this directory.\n│ ├── auth_router.go\n│ └── pub_router.go\n└── tests\n └── api\n └── demo.http\n")])])]),n("h2",{attrs:{id:"router"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#router"}},[t._v("#")]),t._v(" Router")]),t._v(" "),n("p",[t._v("In the directory "),n("code",[t._v("internal/router")]),t._v(", two "),n("code",[t._v("gin.IRouter")]),t._v("s are implemented:")]),t._v(" "),n("ul",[n("li",[t._v("pubRouter: Public router, endpoints mounted under this router can be accessed without authorization.")]),t._v(" "),n("li",[t._v("authRouter: Authenticated router, endpoints mounted under this router require authorization.")])]),t._v(" "),n("p",[t._v("Let's analyze the code in "),n("code",[t._v("internal/router/pub_router.go")]),t._v(":")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" router\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/middleware"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" IdRouterPub "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"router-pub"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPubRouter")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("pubRouter"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" IdRouterPub\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" pubRouter "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter\n\troot gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-gin-router"`')]),t._v("\n\tpub "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("middleware"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("PubMiddleware "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("pubRouter"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("root"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/api"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" r"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pub"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Next"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("ol",[n("li",[t._v("For routers, they need to implement the methods defined in "),n("code",[t._v("gone.IRouter")]),t._v(".")]),t._v(" "),n("li",[t._v("The struct "),n("code",[t._v("pubRouter")]),t._v(" embeds an "),n("code",[t._v("gone.IRouter")]),t._v(", which means it directly implements the "),n("code",[t._v("gone.IRouter")]),t._v(" interface. It is only assigned a value in "),n("code",[t._v("AfterRevive()")]),t._v(".")]),t._v(" "),n("li",[n("code",[t._v('r.IRouter = r.root.Group("/api", r.pub.Next)')]),t._v(" means the current router is a subrouter under the root router at "),n("code",[t._v("/api")]),t._v(", with an additional middleware "),n("code",[t._v("r.pub.Next")]),t._v(".")]),t._v(" "),n("li",[n("code",[t._v("root gone.IRouter")]),t._v(" is a framework-level Goner provided by the "),n("code",[t._v("github.com/gone-io/gone/goner/gin")]),t._v(" package, with a named injection "),n("code",[t._v("gone-gin-router")]),t._v(".")])]),t._v(" "),n("h2",{attrs:{id:"controller"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#controller"}},[t._v("#")]),t._v(" Controller")]),t._v(" "),n("p",[t._v("Below is the definition of the Controller interface:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Controller interface, implemented by business code to mount and handle routes")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// For usage, refer to [Sample Code](https://gitlab.openviewtech.com/gone/gone-example/-/tree/master/gone-app)")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Controller "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Mount Route mounting interface, this function will be called before service startup, and the implementation of this function should usually return `nil`")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" MountError\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("To write HTTP interfaces, we need to implement the "),n("code",[t._v("Controller")]),t._v(" interface and mount the interface routes in the "),n("code",[t._v("Mount")]),t._v(" method, as shown in the code in "),n("code",[t._v("internal/controller/demo_ctr.go")]),t._v(":")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" controller\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/service"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/pkg/utils"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemoController")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" demoController "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tdemoSvc service"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IDemo "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Dependency injection of service")]),t._v("\n\n\tauthRouter gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"router-auth"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Router injection")]),t._v("\n\tpubRouter gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"router-pub"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Router injection")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GinMountError "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\tctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tauthRouter"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/demo"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/show"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("showDemo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tpubRouter"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/demo2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/show"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("showDemo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/error"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/echo"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("echo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("showDemo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Show")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("echo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Req "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tEcho "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`form:"echo"`')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" req Req\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" ctx"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bind")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("req"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewParameterError")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" utils"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ParameterParseError"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("req"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Echo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"service"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#service"}},[t._v("#")]),t._v(" Service")]),t._v(" "),n("p",[t._v("As per the standard, we require service interfaces to be defined in the "),n("code",[t._v("internal/interface/service")]),t._v(" directory. File names should begin with "),n("code",[t._v("i_")]),t._v(", and interface types should start with "),n("code",[t._v("I")]),t._v(", for example:")]),t._v(" "),n("p",[t._v("File: i_demo.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" service\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/domain"')]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" IDemo "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Show")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("DemoEntity"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("The logic implementation of services is placed in the "),n("code",[t._v("internal/module")]),t._v(" directory, organized into modules.")]),t._v(" "),n("h2",{attrs:{id:"use-database"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#use-database"}},[t._v("#")]),t._v(" "),n("a",{attrs:{href:"https://goner.fun/guide/xorm.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Use Database"),n("OutboundLink")],1)])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/43.b1a92a21.js b/assets/js/43.3c5cad35.js similarity index 93% rename from assets/js/43.b1a92a21.js rename to assets/js/43.3c5cad35.js index 1c3a727..baaf202 100644 --- a/assets/js/43.b1a92a21.js +++ b/assets/js/43.3c5cad35.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[43],{326:function(t,e,n){"use strict";n.r(e);var o=n(10),r=Object(o.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"reference-documentation"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#reference-documentation"}},[t._v("#")]),t._v(" Reference Documentation")]),t._v(" "),e("h2",{attrs:{id:"gone-tool"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#gone-tool"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/references/gone-tool.html"}},[t._v("Gone Tool")])],1),t._v(" "),e("h2",{attrs:{id:"http-injection-instructions"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-injection-instructions"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/references/http-inject.html"}},[t._v("HTTP Injection Instructions")])],1)])}),[],!1,null,null,null);e.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[43],{330:function(t,e,n){"use strict";n.r(e);var o=n(10),r=Object(o.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"reference-documentation"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#reference-documentation"}},[t._v("#")]),t._v(" Reference Documentation")]),t._v(" "),e("h2",{attrs:{id:"gone-tool"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#gone-tool"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/references/gone-tool.html"}},[t._v("Gone Tool")])],1),t._v(" "),e("h2",{attrs:{id:"http-injection-instructions"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-injection-instructions"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/references/http-inject.html"}},[t._v("HTTP Injection Instructions")])],1)])}),[],!1,null,null,null);e.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/44.bc6a6ca6.js b/assets/js/44.f7b7ef1b.js similarity index 98% rename from assets/js/44.bc6a6ca6.js rename to assets/js/44.f7b7ef1b.js index 07996f7..a612e42 100644 --- a/assets/js/44.bc6a6ca6.js +++ b/assets/js/44.f7b7ef1b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[44],{334:function(a,t,s){"use strict";s.r(t);var e=s(10),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h1",{attrs:{id:"gone-tool"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#gone-tool"}},[a._v("#")]),a._v(" Gone Tool")]),a._v(" "),t("h2",{attrs:{id:"installation"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#installation"}},[a._v("#")]),a._v(" Installation")]),a._v(" "),t("p",[a._v("Run the following command:")]),a._v(" "),t("div",{staticClass:"language-bash extra-class"},[t("pre",{pre:!0,attrs:{class:"language-bash"}},[t("code",[a._v("go "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),t("h2",{attrs:{id:"usage"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#usage"}},[a._v("#")]),a._v(" Usage")]),a._v(" "),t("h3",{attrs:{id:"testing-installation"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#testing-installation"}},[a._v("#")]),a._v(" Testing Installation")]),a._v(" "),t("p",[a._v("After successful installation, run "),t("code",[a._v("gone -h")]),a._v(" to verify the installation. You should see the following output:")]),a._v(" "),t("div",{staticClass:"language-bash extra-class"},[t("pre",{pre:!0,attrs:{class:"language-bash"}},[t("code",[a._v("➜ demo gone "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-h")]),a._v("\nNAME:\n gone - A new cli application\n\nUSAGE:\n gone "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("global options"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("command")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("command options"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("arguments"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v("."),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n\nDESCRIPTION:\n generate gone code or generate gone app\n\nCOMMANDS:\n priest "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-s")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${scanPackageDir}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-p")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${pkgName}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${funcName}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-o")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${outputFilePath}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-w"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n mock "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${fromGoFile}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-o")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${outGoFile}")]),a._v("\n create "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-t "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${template}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-m "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${modName}")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${appName}")]),a._v("\n help, h Shows a list of commands or "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("help")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token keyword"}},[a._v("for")]),a._v(" one "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("command")]),a._v("\n\nGLOBAL OPTIONS:\n --help, "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-h")]),a._v(" show "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("help")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("default: "),t("span",{pre:!0,attrs:{class:"token boolean"}},[a._v("false")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n")])])]),t("h3",{attrs:{id:"generate-project"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#generate-project"}},[a._v("#")]),a._v(" Generate Project")]),a._v(" "),t("h3",{attrs:{id:"generate-priest-function"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#generate-priest-function"}},[a._v("#")]),a._v(" Generate Priest Function")])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[44],{331:function(a,t,s){"use strict";s.r(t);var e=s(10),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h1",{attrs:{id:"gone-tool"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#gone-tool"}},[a._v("#")]),a._v(" Gone Tool")]),a._v(" "),t("h2",{attrs:{id:"installation"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#installation"}},[a._v("#")]),a._v(" Installation")]),a._v(" "),t("p",[a._v("Run the following command:")]),a._v(" "),t("div",{staticClass:"language-bash extra-class"},[t("pre",{pre:!0,attrs:{class:"language-bash"}},[t("code",[a._v("go "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),t("h2",{attrs:{id:"usage"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#usage"}},[a._v("#")]),a._v(" Usage")]),a._v(" "),t("h3",{attrs:{id:"testing-installation"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#testing-installation"}},[a._v("#")]),a._v(" Testing Installation")]),a._v(" "),t("p",[a._v("After successful installation, run "),t("code",[a._v("gone -h")]),a._v(" to verify the installation. You should see the following output:")]),a._v(" "),t("div",{staticClass:"language-bash extra-class"},[t("pre",{pre:!0,attrs:{class:"language-bash"}},[t("code",[a._v("➜ demo gone "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-h")]),a._v("\nNAME:\n gone - A new cli application\n\nUSAGE:\n gone "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("global options"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("command")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("command options"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("arguments"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v("."),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n\nDESCRIPTION:\n generate gone code or generate gone app\n\nCOMMANDS:\n priest "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-s")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${scanPackageDir}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-p")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${pkgName}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${funcName}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-o")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${outputFilePath}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-w"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n mock "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${fromGoFile}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-o")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${outGoFile}")]),a._v("\n create "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-t "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${template}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-m "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${modName}")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${appName}")]),a._v("\n help, h Shows a list of commands or "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("help")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token keyword"}},[a._v("for")]),a._v(" one "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("command")]),a._v("\n\nGLOBAL OPTIONS:\n --help, "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-h")]),a._v(" show "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("help")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("default: "),t("span",{pre:!0,attrs:{class:"token boolean"}},[a._v("false")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n")])])]),t("h3",{attrs:{id:"generate-project"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#generate-project"}},[a._v("#")]),a._v(" Generate Project")]),a._v(" "),t("h3",{attrs:{id:"generate-priest-function"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#generate-priest-function"}},[a._v("#")]),a._v(" Generate Priest Function")])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/45.beb54419.js b/assets/js/45.5d30e29b.js similarity index 99% rename from assets/js/45.beb54419.js rename to assets/js/45.5d30e29b.js index bc5c419..9729a70 100644 --- a/assets/js/45.beb54419.js +++ b/assets/js/45.5d30e29b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[45],{330:function(t,e,n){"use strict";n.r(e);var s=n(10),a=Object(s.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"http-injection-instructions"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-injection-instructions"}},[t._v("#")]),t._v(" HTTP Injection Instructions")]),t._v(" "),e("h2",{attrs:{id:"format-of-http-dependency-injection-tags"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#format-of-http-dependency-injection-tags"}},[t._v("#")]),t._v(" Format of HTTP Dependency Injection Tags")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v('${attributeName} ${attributeType} gone:"http,${kind}=${key}"\n')])])]),e("p",[t._v("Example:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("router"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/search"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n selects "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=select"`')]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The injected value of in.selects will be `[]int{1,2,3}`")]),t._v("\n fmt"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%v"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("selects"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),e("p",[t._v("In the above example:")]),t._v(" "),e("ul",[e("li",[e("code",[t._v("selects")]),t._v(" is the attribute name.")]),t._v(" "),e("li",[e("code",[t._v("[]int")]),t._v(" is the attribute type.")]),t._v(" "),e("li",[e("code",[t._v("query")]),t._v(" is the injection type.")]),t._v(" "),e("li",[e("code",[t._v("select")]),t._v(" is the injection key.")])]),t._v(" "),e("h2",{attrs:{id:"supported-injection-types-and-response-tags"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#supported-injection-types-and-response-tags"}},[t._v("#")]),t._v(" Supported Injection Types and Response Tags")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Attribute Type "),e("code",[t._v("${attributeType}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("Injection Type "),e("code",[t._v("${kind}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("Injection Key "),e("code",[t._v("${key}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("Context Injection")])]),t._v(" "),e("td",[e("code",[t._v("gone.Context")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Not recommended) Injects the gin request context object. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Context Injection")])]),t._v(" "),e("td",[e("code",[t._v("*gone.Context")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Recommended) Injects the gin request context pointer. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Request Injection")])]),t._v(" "),e("td",[e("code",[t._v("http.Request")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Not recommended) Injects the http.Request object. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Request Injection")])]),t._v(" "),e("td",[e("code",[t._v("*http.Request")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Recommended) Injects the http.Request pointer. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("URL Injection")])]),t._v(" "),e("td",[e("code",[t._v("url.URL")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Not recommended) Injects the url.URL. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("URL Injection")])]),t._v(" "),e("td",[e("code",[t._v("*url.URL")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Recommended) Injects the url.URL pointer. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Header Injection")])]),t._v(" "),e("td",[e("code",[t._v("http.Header")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Recommended) Injects the http.Header (request headers). "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Response Injection")])]),t._v(" "),e("td",[e("code",[t._v("gone.ResponseWriter")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Injects the gin.ResponseWriter (used to directly write response data). "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Body Injection")])]),t._v(" "),e("td",[t._v("Struct, Struct Pointer")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[e("code",[t._v("body")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("strong",[t._v("Body Injection")]),t._v("; parses the request body and injects it into the attribute. The injection type is "),e("code",[t._v("body")]),t._v(", and "),e("code",[t._v("${key}")]),t._v(" is not needed. The framework automatically determines the format (e.g., JSON, XML) based on "),e("code",[t._v("Content-Type")]),t._v(". Only one "),e("strong",[t._v("body injection")]),t._v(" is allowed per request handler.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Single Value Header Injection")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("header")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Defaults to field name")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Retrieves the request header with the key "),e("code",[t._v("${key}")]),t._v(". Attribute types support "),e("code",[t._v("string")]),t._v(", "),e("code",[t._v("int")]),t._v(", "),e("code",[t._v("uint")]),t._v(", "),e("code",[t._v("float64")]),t._v(", etc. If parsing fails, an argument error is returned.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("URL Parameter Injection")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("param")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Defaults to field name")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Retrieves the URL parameter with the key "),e("code",[t._v("${key}")]),t._v(" using "),e("code",[t._v("ctx.Param(key)")]),t._v(". Attribute types support "),e("code",[t._v("string")]),t._v(", "),e("code",[t._v("int")]),t._v(", "),e("code",[t._v("uint")]),t._v(", "),e("code",[t._v("float64")]),t._v(", etc. If parsing fails, an argument error is returned.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Query Parameter Injection")])]),t._v(" "),e("td",[t._v("number | string | []number | []string | Struct | Struct Pointer")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("query")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Defaults to field name")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Retrieves the query parameter with the key "),e("code",[t._v("${key}")]),t._v(" using "),e("code",[t._v("ctx.Query(key)")]),t._v(". Attribute types support "),e("code",[t._v("string")]),t._v(", "),e("code",[t._v("int")]),t._v(", "),e("code",[t._v("uint")]),t._v(", "),e("code",[t._v("float64")]),t._v(", etc., and "),e("strong",[t._v("supports arrays"),e("sup",[t._v("[1]")])]),t._v(". If parsing fails, an argument error is returned.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Cookie Injection")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("cookie")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Defaults to field name")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Retrieves the cookie with the key "),e("code",[t._v("${key}")]),t._v(" using "),e("code",[t._v("ctx.Context.Cookie(key)")]),t._v(". Attribute types support "),e("code",[t._v("string")]),t._v(", "),e("code",[t._v("int")]),t._v(", "),e("code",[t._v("uint")]),t._v(", "),e("code",[t._v("float64")]),t._v(", etc. If parsing fails, an argument error is returned.")])])])]),t._v(" "),e("h2",{attrs:{id:"notes"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#notes"}},[t._v("#")]),t._v(" Notes")]),t._v(" "),e("p",[t._v("[1]. Query parameter injection supports arrays. For example:\nIf the query is "),e("code",[t._v("?select=1&select=2&select=3")]),t._v(", the value of "),e("code",[t._v("in.selects")]),t._v(" in the code below will be "),e("code",[t._v("[]int{1,2,3}")]),t._v(".")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("router"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/search"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n selects "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=select"`')]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The injected value of in.selects will be `[]int{1,2,3}`")]),t._v("\n fmt"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%v"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("selects"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[45],{332:function(t,e,n){"use strict";n.r(e);var s=n(10),a=Object(s.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"http-injection-instructions"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-injection-instructions"}},[t._v("#")]),t._v(" HTTP Injection Instructions")]),t._v(" "),e("h2",{attrs:{id:"format-of-http-dependency-injection-tags"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#format-of-http-dependency-injection-tags"}},[t._v("#")]),t._v(" Format of HTTP Dependency Injection Tags")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v('${attributeName} ${attributeType} gone:"http,${kind}=${key}"\n')])])]),e("p",[t._v("Example:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("router"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/search"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n selects "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=select"`')]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The injected value of in.selects will be `[]int{1,2,3}`")]),t._v("\n fmt"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%v"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("selects"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),e("p",[t._v("In the above example:")]),t._v(" "),e("ul",[e("li",[e("code",[t._v("selects")]),t._v(" is the attribute name.")]),t._v(" "),e("li",[e("code",[t._v("[]int")]),t._v(" is the attribute type.")]),t._v(" "),e("li",[e("code",[t._v("query")]),t._v(" is the injection type.")]),t._v(" "),e("li",[e("code",[t._v("select")]),t._v(" is the injection key.")])]),t._v(" "),e("h2",{attrs:{id:"supported-injection-types-and-response-tags"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#supported-injection-types-and-response-tags"}},[t._v("#")]),t._v(" Supported Injection Types and Response Tags")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Attribute Type "),e("code",[t._v("${attributeType}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("Injection Type "),e("code",[t._v("${kind}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("Injection Key "),e("code",[t._v("${key}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("Context Injection")])]),t._v(" "),e("td",[e("code",[t._v("gone.Context")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Not recommended) Injects the gin request context object. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Context Injection")])]),t._v(" "),e("td",[e("code",[t._v("*gone.Context")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Recommended) Injects the gin request context pointer. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Request Injection")])]),t._v(" "),e("td",[e("code",[t._v("http.Request")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Not recommended) Injects the http.Request object. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Request Injection")])]),t._v(" "),e("td",[e("code",[t._v("*http.Request")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Recommended) Injects the http.Request pointer. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("URL Injection")])]),t._v(" "),e("td",[e("code",[t._v("url.URL")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Not recommended) Injects the url.URL. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("URL Injection")])]),t._v(" "),e("td",[e("code",[t._v("*url.URL")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Recommended) Injects the url.URL pointer. "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Header Injection")])]),t._v(" "),e("td",[e("code",[t._v("http.Header")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(Recommended) Injects the http.Header (request headers). "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Response Injection")])]),t._v(" "),e("td",[e("code",[t._v("gone.ResponseWriter")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Injects the gin.ResponseWriter (used to directly write response data). "),e("code",[t._v("${kind}")]),t._v(" and "),e("code",[t._v("${key}")]),t._v(" are not needed.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Body Injection")])]),t._v(" "),e("td",[t._v("Struct, Struct Pointer")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[e("code",[t._v("body")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("strong",[t._v("Body Injection")]),t._v("; parses the request body and injects it into the attribute. The injection type is "),e("code",[t._v("body")]),t._v(", and "),e("code",[t._v("${key}")]),t._v(" is not needed. The framework automatically determines the format (e.g., JSON, XML) based on "),e("code",[t._v("Content-Type")]),t._v(". Only one "),e("strong",[t._v("body injection")]),t._v(" is allowed per request handler.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Single Value Header Injection")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("header")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Defaults to field name")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Retrieves the request header with the key "),e("code",[t._v("${key}")]),t._v(". Attribute types support "),e("code",[t._v("string")]),t._v(", "),e("code",[t._v("int")]),t._v(", "),e("code",[t._v("uint")]),t._v(", "),e("code",[t._v("float64")]),t._v(", etc. If parsing fails, an argument error is returned.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("URL Parameter Injection")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("param")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Defaults to field name")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Retrieves the URL parameter with the key "),e("code",[t._v("${key}")]),t._v(" using "),e("code",[t._v("ctx.Param(key)")]),t._v(". Attribute types support "),e("code",[t._v("string")]),t._v(", "),e("code",[t._v("int")]),t._v(", "),e("code",[t._v("uint")]),t._v(", "),e("code",[t._v("float64")]),t._v(", etc. If parsing fails, an argument error is returned.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Query Parameter Injection")])]),t._v(" "),e("td",[t._v("number | string | []number | []string | Struct | Struct Pointer")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("query")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Defaults to field name")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Retrieves the query parameter with the key "),e("code",[t._v("${key}")]),t._v(" using "),e("code",[t._v("ctx.Query(key)")]),t._v(". Attribute types support "),e("code",[t._v("string")]),t._v(", "),e("code",[t._v("int")]),t._v(", "),e("code",[t._v("uint")]),t._v(", "),e("code",[t._v("float64")]),t._v(", etc., and "),e("strong",[t._v("supports arrays"),e("sup",[t._v("[1]")])]),t._v(". If parsing fails, an argument error is returned.")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Cookie Injection")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("cookie")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Defaults to field name")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("Retrieves the cookie with the key "),e("code",[t._v("${key}")]),t._v(" using "),e("code",[t._v("ctx.Context.Cookie(key)")]),t._v(". Attribute types support "),e("code",[t._v("string")]),t._v(", "),e("code",[t._v("int")]),t._v(", "),e("code",[t._v("uint")]),t._v(", "),e("code",[t._v("float64")]),t._v(", etc. If parsing fails, an argument error is returned.")])])])]),t._v(" "),e("h2",{attrs:{id:"notes"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#notes"}},[t._v("#")]),t._v(" Notes")]),t._v(" "),e("p",[t._v("[1]. Query parameter injection supports arrays. For example:\nIf the query is "),e("code",[t._v("?select=1&select=2&select=3")]),t._v(", the value of "),e("code",[t._v("in.selects")]),t._v(" in the code below will be "),e("code",[t._v("[]int{1,2,3}")]),t._v(".")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("router"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/search"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n selects "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=select"`')]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The injected value of in.selects will be `[]int{1,2,3}`")]),t._v("\n fmt"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%v"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("selects"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/46.854b50d9.js b/assets/js/46.16f10eea.js similarity index 99% rename from assets/js/46.854b50d9.js rename to assets/js/46.16f10eea.js index b027cb9..b21f3e1 100644 --- a/assets/js/46.854b50d9.js +++ b/assets/js/46.16f10eea.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[46],{338:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"介绍"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#介绍"}},[t._v("#")]),t._v(" 介绍")]),t._v(" "),s("h2",{attrs:{id:"gone是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#gone是什么"}},[t._v("#")]),t._v(" Gone是什么")]),t._v(" "),s("p",[t._v("首先,"),s("strong",[t._v("Gone")]),t._v("是一个轻量的,基于"),s("strong",[t._v("Golang")]),t._v("的,"),s("strong",[t._v("依赖注入框架")]),t._v(",灵感来源于Java中的Spring Framework;其次,"),s("strong",[t._v("Gone")]),t._v("框架中包含了一系列内置组件,通过这些组件提供一整套Web开发方案,提供服务配置、日志追踪、服务调用、数据库访问、消息中间件等微服务常用能力。")]),t._v(" "),s("p",[t._v("下面使用"),s("strong",[t._v("Gone")]),t._v("来编写一个Web服务吧!")]),t._v(" "),s("h2",{attrs:{id:"web服务"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#web服务"}},[t._v("#")]),t._v(" Web服务")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 实现一个Goner,什么是Goner? => https://goner.fun/zh/guide/core-concept.html#goner-%E9%80%9D%E8%80%85")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" controller "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//goner 标记,匿名嵌入后,一个结构体就实现了Goner")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("RouteGroup "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-gin-router"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入根路由")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 实现 Mount 方法,挂载路由;框架会自动执行该方法")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("controller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GinMountError "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 定义请求结构体")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Req "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tMsg "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`json:"msg"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注册 `POST /hello` 的 处理函数")]),t._v("\n\tctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("POST")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/hello"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tto "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入http请求Query参数To")]),t._v("\n\t\treq "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Req "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入http请求Body")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" any "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" fmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sprintf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"to %s msg is: %s"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("to"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Msg"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//启动服务")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Serve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 调用框架内置组件,加载gin框架")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GinPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//将 一个controller类型的Goner埋葬到墓园")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//埋葬是什么意思? => https://goner.fun/zh/guide/core-concept.html#bury-%E5%9F%8B%E8%91%AC")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//墓园是什么意思? => https://goner.fun/zh/guide/core-concept.html#cemetery-%E5%A2%93%E5%9B%AD")]),t._v("\n\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("controller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("运行上面代码:"),s("code",[t._v("go run main.go")]),t._v(",程序将监听"),s("code",[t._v("8080")]),t._v("端口,使用curl测试:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("curl")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-X")]),t._v(" POST "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'http://localhost:8080/hello'")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("\\")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-H")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'Content-Type: application/json'")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("\\")]),t._v("\n\t--data-raw "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('\'{"msg": "你好呀?"}\'')]),t._v("\n")])])]),s("p",[t._v("结果如下:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"code"')]),t._v(":0,"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"data"')]),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"to msg is: 你好呀?"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"概念"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#概念"}},[t._v("#")]),t._v(" 概念")]),t._v(" "),s("blockquote",[s("p",[t._v("我们编写的代码终究只是死物,除非他们被运行起来。")])]),t._v(" "),s("p",[t._v("在Gone中,组件被抽象为"),s("strong",[t._v("Goner(逝者)")]),t._v(","),s("strong",[t._v("Goner")]),t._v("属性可以注入其他的"),s("strong",[t._v("Goner")]),t._v("。Gone启动前,需要将所有 "),s("strong",[t._v("Goners")]),t._v(" "),s("strong",[t._v("埋葬(Bury)"),s("strong",[t._v("到")]),t._v("墓园(cemetery)")]),t._v(";Gone启动后,会将所有 "),s("strong",[t._v("Goners")]),t._v(" "),s("strong",[t._v("复活")]),t._v(",建立一个 "),s("strong",[t._v("天国(Heaven)")]),t._v(",“天国的所有人都不再残缺,他们想要的必定得到满足”。")]),t._v(" "),s("p",[t._v("了解更多,请阅读 "),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Gone的核心概念"),s("OutboundLink")],1)])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[46],{333:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"介绍"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#介绍"}},[t._v("#")]),t._v(" 介绍")]),t._v(" "),s("h2",{attrs:{id:"gone是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#gone是什么"}},[t._v("#")]),t._v(" Gone是什么")]),t._v(" "),s("p",[t._v("首先,"),s("strong",[t._v("Gone")]),t._v("是一个轻量的,基于"),s("strong",[t._v("Golang")]),t._v("的,"),s("strong",[t._v("依赖注入框架")]),t._v(",灵感来源于Java中的Spring Framework;其次,"),s("strong",[t._v("Gone")]),t._v("框架中包含了一系列内置组件,通过这些组件提供一整套Web开发方案,提供服务配置、日志追踪、服务调用、数据库访问、消息中间件等微服务常用能力。")]),t._v(" "),s("p",[t._v("下面使用"),s("strong",[t._v("Gone")]),t._v("来编写一个Web服务吧!")]),t._v(" "),s("h2",{attrs:{id:"web服务"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#web服务"}},[t._v("#")]),t._v(" Web服务")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 实现一个Goner,什么是Goner? => https://goner.fun/zh/guide/core-concept.html#goner-%E9%80%9D%E8%80%85")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" controller "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//goner 标记,匿名嵌入后,一个结构体就实现了Goner")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("RouteGroup "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-gin-router"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入根路由")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 实现 Mount 方法,挂载路由;框架会自动执行该方法")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("controller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GinMountError "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 定义请求结构体")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Req "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tMsg "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`json:"msg"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注册 `POST /hello` 的 处理函数")]),t._v("\n\tctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("POST")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/hello"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tto "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入http请求Query参数To")]),t._v("\n\t\treq "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Req "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,body"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入http请求Body")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" any "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" fmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sprintf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"to %s msg is: %s"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("to"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Msg"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//启动服务")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Serve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 调用框架内置组件,加载gin框架")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GinPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//将 一个controller类型的Goner埋葬到墓园")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//埋葬是什么意思? => https://goner.fun/zh/guide/core-concept.html#bury-%E5%9F%8B%E8%91%AC")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//墓园是什么意思? => https://goner.fun/zh/guide/core-concept.html#cemetery-%E5%A2%93%E5%9B%AD")]),t._v("\n\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("controller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("运行上面代码:"),s("code",[t._v("go run main.go")]),t._v(",程序将监听"),s("code",[t._v("8080")]),t._v("端口,使用curl测试:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("curl")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-X")]),t._v(" POST "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'http://localhost:8080/hello'")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("\\")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-H")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'Content-Type: application/json'")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("\\")]),t._v("\n\t--data-raw "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('\'{"msg": "你好呀?"}\'')]),t._v("\n")])])]),s("p",[t._v("结果如下:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"code"')]),t._v(":0,"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"data"')]),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"to msg is: 你好呀?"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"概念"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#概念"}},[t._v("#")]),t._v(" 概念")]),t._v(" "),s("blockquote",[s("p",[t._v("我们编写的代码终究只是死物,除非他们被运行起来。")])]),t._v(" "),s("p",[t._v("在Gone中,组件被抽象为"),s("strong",[t._v("Goner(逝者)")]),t._v(","),s("strong",[t._v("Goner")]),t._v("属性可以注入其他的"),s("strong",[t._v("Goner")]),t._v("。Gone启动前,需要将所有 "),s("strong",[t._v("Goners")]),t._v(" "),s("strong",[t._v("埋葬(Bury)"),s("strong",[t._v("到")]),t._v("墓园(cemetery)")]),t._v(";Gone启动后,会将所有 "),s("strong",[t._v("Goners")]),t._v(" "),s("strong",[t._v("复活")]),t._v(",建立一个 "),s("strong",[t._v("天国(Heaven)")]),t._v(",“天国的所有人都不再残缺,他们想要的必定得到满足”。")]),t._v(" "),s("p",[t._v("了解更多,请阅读 "),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Gone的核心概念"),s("OutboundLink")],1)])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/47.1154a3e9.js b/assets/js/47.3f89e40b.js similarity index 98% rename from assets/js/47.1154a3e9.js rename to assets/js/47.3f89e40b.js index 1f1d268..199ac38 100644 --- a/assets/js/47.1154a3e9.js +++ b/assets/js/47.3f89e40b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[47],{331:function(e,t,r){"use strict";r.r(t);var o=r(10),v=Object(o.a)({},(function(){var e=this,t=e._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[t("h1",{attrs:{id:"goners"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#goners"}},[e._v("#")]),e._v(" Goners")]),e._v(" "),t("h2",{attrs:{id:"核心级goners"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#核心级goners"}},[e._v("#")]),e._v(" 核心级Goners")]),e._v(" "),t("blockquote",[t("p",[e._v("核心组件也是Goner,可以被其他Goner注入,这部分Goners,是Gone运行的和兴,是Gone运行不可或缺的部分。")])]),e._v(" "),t("table",[t("thead",[t("tr",[t("th",[e._v("接口名")]),e._v(" "),t("th",[e._v("实现")]),e._v(" "),t("th",[e._v("GoneId")]),e._v(" "),t("th",[e._v("功能介绍")])])]),e._v(" "),t("tbody",[t("tr",[t("td",[t("a",{attrs:{href:"https://pkg.go.dev/github.com/gone-io/gone#Heaven",target:"_blank",rel:"noopener noreferrer"}},[e._v("Heaven"),t("OutboundLink")],1)]),e._v(" "),t("td",[t("a",{attrs:{href:"https://github.com/gone-io/gone/blob/12ea8e3577fbed493766f522ab002136edf3805d/heaven.go#L65",target:"_blank",rel:"noopener noreferrer"}},[e._v("heaven"),t("OutboundLink")],1)]),e._v(" "),t("td",[e._v("gone-heaven")]),e._v(" "),t("td",[e._v("负责将Goner从cemetery中复活,执行安装的Hook函数,管理框架的启停流程和状态。")])]),e._v(" "),t("tr",[t("td",[t("a",{attrs:{href:"https://pkg.go.dev/github.com/gone-io/gone#Cemetery",target:"_blank",rel:"noopener noreferrer"}},[e._v("Cemetery"),t("OutboundLink")],1)]),e._v(" "),t("td",[t("a",{attrs:{href:"https://github.com/gone-io/gone/blob/12ea8e3577fbed493766f522ab002136edf3805d/cemetery.go#L17",target:"_blank",rel:"noopener noreferrer"}},[e._v("cemetery"),t("OutboundLink")],1)]),e._v(" "),t("td",[e._v("gone-cemetery")]),e._v(" "),t("td",[e._v("管理Goners,提供将Goner埋葬的Bury方法;依赖注入的逻辑主要在该结构体中实现。")])])])]),e._v(" "),t("h2",{attrs:{id:"框架内置goners"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#框架内置goners"}},[e._v("#")]),e._v(" 框架内置Goners")]),e._v(" "),t("p",[e._v("框架内置Goners,是为丰富Gone的功能而开发的,比如支持Web开发、支持数据库连接、支持Redis等…"),t("br"),e._v("\n代码实现在 "),t("a",{attrs:{href:"https://github.com/gone-io/gone/tree/v0.1.4/goner",target:"_blank",rel:"noopener noreferrer"}},[e._v("goner目录"),t("OutboundLink")],1),e._v(",该目录下的每个子目录分别实现了一个gone的特性,每个特性包含一个或多个Goner的定义和实现。")]),e._v(" "),t("p",[e._v("为了方便使用,我们在 "),t("a",{attrs:{href:"https://github.com/gone-io/gone/blob/v0.1.4/goner/priest.go",target:"_blank",rel:"noopener noreferrer"}},[e._v("goner/priest.go"),t("OutboundLink")],1),e._v(" 中定义了"),t("code",[e._v("Priest")]),e._v("函数,可以按功能直接批量埋葬相关Goners。")]),e._v(" "),t("table",[t("thead",[t("tr",[t("th",[e._v("目录/组件")]),e._v(" "),t("th",[e._v("实现功能")]),e._v(" "),t("th",[e._v("文档")])])]),e._v(" "),t("tbody",[t("tr",[t("td",[e._v("config")]),e._v(" "),t("td",[e._v("读取config目录下的配置文件,允许配置项注入到Goner")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/config.html"}},[e._v("通过内置Goners支持配置文件")])],1)]),e._v(" "),t("tr",[t("td",[e._v("logrus")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/sirupsen/logrus")]),e._v(",提供日志打印相关的方法,支持将日志按格式打印")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/logrus.html"}},[e._v("日志打印")])],1)]),e._v(" "),t("tr",[t("td",[e._v("tracer")]),e._v(" "),t("td",[e._v("日志追踪,提供traceId;在处理同一请求时,日志打印可以拥有相同的traceId")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/tracer.html"}},[e._v("使用traceId追踪日志")])],1)]),e._v(" "),t("tr",[t("td",[e._v("gin")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/gin-gonic/gin")]),e._v(",使gone支持web开发")]),e._v(" "),t("td",[e._v("-")])]),e._v(" "),t("tr",[t("td",[e._v("xorm")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("xorm.io/xorm")]),e._v(",用于操作数据")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/xorm.html"}},[e._v("通过内置Goners支持数据库连接")])],1)]),e._v(" "),t("tr",[t("td",[e._v("redis")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/gomodule/redigo/redis")]),e._v(",用于操作redis,提供redis缓存和redis分布式锁的功能")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/redis.html"}},[e._v("利用redis提供分布式锁和分布式缓存")])],1)]),e._v(" "),t("tr",[t("td",[e._v("schedule")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/robfig/cron/v3")]),e._v(",提供定时任务的能力")]),e._v(" "),t("td",[t("a",{attrs:{href:"https://goner.fun/zh/guide/schedule.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("用cron表达式配置定时任务"),t("OutboundLink")],1)])]),e._v(" "),t("tr",[t("td",[e._v("urllib")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/imroc/req/v3")]),e._v(",提供http调用能力")]),e._v(" "),t("td",[e._v("-")])]),e._v(" "),t("tr",[t("td",[e._v("grpc")]),e._v(" "),t("td",[e._v("提供开发grpc服务端和客户端的能力")]),e._v(" "),t("td",[e._v("-")])]),e._v(" "),t("tr",[t("td",[e._v("cmux")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/soheilhy/cmux")]),e._v(",是统一端口可以提供混合服务的能力")]),e._v(" "),t("td",[e._v("-")])])])]),e._v(" "),t("h2",{attrs:{id:"生态级-goners"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#生态级-goners"}},[e._v("#")]),e._v(" 生态级 Goners")]),e._v(" "),t("ul",[t("li",[t("a",{attrs:{href:"https://github.com/gone-io/emitter",target:"_blank",rel:"noopener noreferrer"}},[e._v("emitter"),t("OutboundLink")],1),e._v(",封装事件处理,可以用于 DDD 的 事件风暴")])])])}),[],!1,null,null,null);t.default=v.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[47],{334:function(e,t,r){"use strict";r.r(t);var o=r(10),v=Object(o.a)({},(function(){var e=this,t=e._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[t("h1",{attrs:{id:"goners"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#goners"}},[e._v("#")]),e._v(" Goners")]),e._v(" "),t("h2",{attrs:{id:"核心级goners"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#核心级goners"}},[e._v("#")]),e._v(" 核心级Goners")]),e._v(" "),t("blockquote",[t("p",[e._v("核心组件也是Goner,可以被其他Goner注入,这部分Goners,是Gone运行的和兴,是Gone运行不可或缺的部分。")])]),e._v(" "),t("table",[t("thead",[t("tr",[t("th",[e._v("接口名")]),e._v(" "),t("th",[e._v("实现")]),e._v(" "),t("th",[e._v("GoneId")]),e._v(" "),t("th",[e._v("功能介绍")])])]),e._v(" "),t("tbody",[t("tr",[t("td",[t("a",{attrs:{href:"https://pkg.go.dev/github.com/gone-io/gone#Heaven",target:"_blank",rel:"noopener noreferrer"}},[e._v("Heaven"),t("OutboundLink")],1)]),e._v(" "),t("td",[t("a",{attrs:{href:"https://github.com/gone-io/gone/blob/12ea8e3577fbed493766f522ab002136edf3805d/heaven.go#L65",target:"_blank",rel:"noopener noreferrer"}},[e._v("heaven"),t("OutboundLink")],1)]),e._v(" "),t("td",[e._v("gone-heaven")]),e._v(" "),t("td",[e._v("负责将Goner从cemetery中复活,执行安装的Hook函数,管理框架的启停流程和状态。")])]),e._v(" "),t("tr",[t("td",[t("a",{attrs:{href:"https://pkg.go.dev/github.com/gone-io/gone#Cemetery",target:"_blank",rel:"noopener noreferrer"}},[e._v("Cemetery"),t("OutboundLink")],1)]),e._v(" "),t("td",[t("a",{attrs:{href:"https://github.com/gone-io/gone/blob/12ea8e3577fbed493766f522ab002136edf3805d/cemetery.go#L17",target:"_blank",rel:"noopener noreferrer"}},[e._v("cemetery"),t("OutboundLink")],1)]),e._v(" "),t("td",[e._v("gone-cemetery")]),e._v(" "),t("td",[e._v("管理Goners,提供将Goner埋葬的Bury方法;依赖注入的逻辑主要在该结构体中实现。")])])])]),e._v(" "),t("h2",{attrs:{id:"框架内置goners"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#框架内置goners"}},[e._v("#")]),e._v(" 框架内置Goners")]),e._v(" "),t("p",[e._v("框架内置Goners,是为丰富Gone的功能而开发的,比如支持Web开发、支持数据库连接、支持Redis等…"),t("br"),e._v("\n代码实现在 "),t("a",{attrs:{href:"https://github.com/gone-io/gone/tree/v0.1.4/goner",target:"_blank",rel:"noopener noreferrer"}},[e._v("goner目录"),t("OutboundLink")],1),e._v(",该目录下的每个子目录分别实现了一个gone的特性,每个特性包含一个或多个Goner的定义和实现。")]),e._v(" "),t("p",[e._v("为了方便使用,我们在 "),t("a",{attrs:{href:"https://github.com/gone-io/gone/blob/v0.1.4/goner/priest.go",target:"_blank",rel:"noopener noreferrer"}},[e._v("goner/priest.go"),t("OutboundLink")],1),e._v(" 中定义了"),t("code",[e._v("Priest")]),e._v("函数,可以按功能直接批量埋葬相关Goners。")]),e._v(" "),t("table",[t("thead",[t("tr",[t("th",[e._v("目录/组件")]),e._v(" "),t("th",[e._v("实现功能")]),e._v(" "),t("th",[e._v("文档")])])]),e._v(" "),t("tbody",[t("tr",[t("td",[e._v("config")]),e._v(" "),t("td",[e._v("读取config目录下的配置文件,允许配置项注入到Goner")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/config.html"}},[e._v("通过内置Goners支持配置文件")])],1)]),e._v(" "),t("tr",[t("td",[e._v("logrus")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/sirupsen/logrus")]),e._v(",提供日志打印相关的方法,支持将日志按格式打印")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/logrus.html"}},[e._v("日志打印")])],1)]),e._v(" "),t("tr",[t("td",[e._v("tracer")]),e._v(" "),t("td",[e._v("日志追踪,提供traceId;在处理同一请求时,日志打印可以拥有相同的traceId")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/tracer.html"}},[e._v("使用traceId追踪日志")])],1)]),e._v(" "),t("tr",[t("td",[e._v("gin")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/gin-gonic/gin")]),e._v(",使gone支持web开发")]),e._v(" "),t("td",[e._v("-")])]),e._v(" "),t("tr",[t("td",[e._v("xorm")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("xorm.io/xorm")]),e._v(",用于操作数据")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/xorm.html"}},[e._v("通过内置Goners支持数据库连接")])],1)]),e._v(" "),t("tr",[t("td",[e._v("redis")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/gomodule/redigo/redis")]),e._v(",用于操作redis,提供redis缓存和redis分布式锁的功能")]),e._v(" "),t("td",[t("RouterLink",{attrs:{to:"/zh/guide/redis.html"}},[e._v("利用redis提供分布式锁和分布式缓存")])],1)]),e._v(" "),t("tr",[t("td",[e._v("schedule")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/robfig/cron/v3")]),e._v(",提供定时任务的能力")]),e._v(" "),t("td",[t("a",{attrs:{href:"https://goner.fun/zh/guide/schedule.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("用cron表达式配置定时任务"),t("OutboundLink")],1)])]),e._v(" "),t("tr",[t("td",[e._v("urllib")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/imroc/req/v3")]),e._v(",提供http调用能力")]),e._v(" "),t("td",[e._v("-")])]),e._v(" "),t("tr",[t("td",[e._v("grpc")]),e._v(" "),t("td",[e._v("提供开发grpc服务端和客户端的能力")]),e._v(" "),t("td",[e._v("-")])]),e._v(" "),t("tr",[t("td",[e._v("cmux")]),e._v(" "),t("td",[e._v("封装"),t("code",[e._v("github.com/soheilhy/cmux")]),e._v(",是统一端口可以提供混合服务的能力")]),e._v(" "),t("td",[e._v("-")])])])]),e._v(" "),t("h2",{attrs:{id:"生态级-goners"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#生态级-goners"}},[e._v("#")]),e._v(" 生态级 Goners")]),e._v(" "),t("ul",[t("li",[t("a",{attrs:{href:"https://github.com/gone-io/emitter",target:"_blank",rel:"noopener noreferrer"}},[e._v("emitter"),t("OutboundLink")],1),e._v(",封装事件处理,可以用于 DDD 的 事件风暴")])])])}),[],!1,null,null,null);t.default=v.exports}}]); \ No newline at end of file diff --git a/assets/js/49.8b4d3c1d.js b/assets/js/49.90396e69.js similarity index 99% rename from assets/js/49.8b4d3c1d.js rename to assets/js/49.90396e69.js index 47a7ed7..df7f78a 100644 --- a/assets/js/49.8b4d3c1d.js +++ b/assets/js/49.90396e69.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[49],{332:function(t,s,a){"use strict";a.r(s);var e=a(10),n=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"自动生成priest"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#自动生成priest"}},[t._v("#")]),t._v(" 自动生成Priest")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#小试牛刀"}},[t._v("小试牛刀")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-安装gone辅助工具"}},[t._v("1. 安装gone辅助工具")])]),s("li",[s("a",{attrs:{href:"#_2-编写goner"}},[t._v("2. 编写Goner")])]),s("li",[s("a",{attrs:{href:"#_3-生成代码"}},[t._v("3. 生成代码")])])])]),s("li",[s("a",{attrs:{href:"#最佳实践"}},[t._v("最佳实践")])])])]),t._v(" "),s("RouterLink",{attrs:{to:"/zh/guide/core-concept.html"}},[t._v("什么是Priest?")]),s("p"),t._v(" "),s("h2",{attrs:{id:"小试牛刀"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#小试牛刀"}},[t._v("#")]),t._v(" 小试牛刀")]),t._v(" "),s("p",[s("code",[t._v("gone priest")]),t._v("命令可以扫描代码中的特殊注释"),s("code",[t._v("//go:gone")]),t._v("生成Priest函数;"),s("code",[t._v("//go:gone")]),t._v("暂时只能用于标记"),s("code",[t._v("func () gone.Goner")]),t._v(" 和 "),s("code",[t._v("func () (gone.Goner, gone.GonerId)")]),t._v("这两种形式的函数,函数必须是公开(以大写字母开头)。")]),t._v(" "),s("h3",{attrs:{id:"_1-安装gone辅助工具"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-安装gone辅助工具"}},[t._v("#")]),t._v(" 1. 安装gone辅助工具")]),t._v(" "),s("p",[t._v("执行如下命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),s("p",[t._v("gone更多内容参考文档 "),s("RouterLink",{attrs:{to:"/zh/references/gone-tool.html"}},[t._v("gone辅助工具")])],1),t._v(" "),s("h3",{attrs:{id:"_2-编写goner"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-编写goner"}},[t._v("#")]),t._v(" 2. 编写Goner")]),t._v(" "),s("p",[t._v("创建项目,创建文件:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" demo\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" demo\ngo mod init demo\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" demo.go\n")])])]),s("p",[t._v("编辑demo.go文件代码如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Demo "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-生成代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-生成代码"}},[t._v("#")]),t._v(" 3. 生成代码")]),t._v(" "),s("p",[t._v("执行")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone priest "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-s")]),t._v(" ./ "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" Priest "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" priest.go "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-p")]),t._v(" demo\n")])])]),s("p",[t._v("将生成文件:priest.go\n内容如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Code generated by gone; DO NOT EDIT.")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"最佳实践"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#最佳实践"}},[t._v("#")]),t._v(" 最佳实践")]),t._v(" "),s("ul",[s("li",[t._v("创建一个MasterPriest函数,用于Gone框架的启动;")]),t._v(" "),s("li",[t._v("在MasterPriest函数中,调用项目依赖包的Priest函数;")]),t._v(" "),s("li",[t._v("将“gone priest”命令放到MasterPriest函数的"),s("code",[t._v("//go:generate")]),t._v("注释后,例如:")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" internal\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:generate gone priest -s . -p $GOPACKAGE -f Priest -o priest.go")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//调用项目依赖包的Priest函数")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GinPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//调用生成的Priest函数")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("blockquote",[s("p",[t._v("tips: 运行"),s("code",[t._v("go generate ./...")]),t._v(" 会执行 所有"),s("code",[t._v("//go:generate")]),t._v("注释后的命令;")])]),t._v(" "),s("ul",[s("li",[t._v("在MasterPriest函数中,调用调用生成的Priest函数;")]),t._v(" "),s("li",[t._v("git忽略掉生成文件,将生成的文件加入到"),s("code",[t._v(".gitignore")]),t._v("文件中。")])]),t._v(" "),s("p",[t._v("按照上面逻辑,我们编写了一个可供参考的Web空白项目"),s("a",{attrs:{href:"https://github.com/gone-io/examples/tree/main/empty",target:"_blank",rel:"noopener noreferrer"}},[t._v("Demo"),s("OutboundLink")],1),t._v(",已经放到github上,快点击打开吧;另外也可以运行"),s("code",[t._v("gone create web-app")]),t._v("生成一个空白项目,参考"),s("a",{attrs:{href:"https://goner.fun/zh/quick-start/",target:"_blank",rel:"noopener noreferrer"}},[t._v("快速开始\n"),s("OutboundLink")],1),t._v("。")])],1)}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[49],{336:function(t,s,a){"use strict";a.r(s);var e=a(10),n=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"自动生成priest"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#自动生成priest"}},[t._v("#")]),t._v(" 自动生成Priest")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#小试牛刀"}},[t._v("小试牛刀")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-安装gone辅助工具"}},[t._v("1. 安装gone辅助工具")])]),s("li",[s("a",{attrs:{href:"#_2-编写goner"}},[t._v("2. 编写Goner")])]),s("li",[s("a",{attrs:{href:"#_3-生成代码"}},[t._v("3. 生成代码")])])])]),s("li",[s("a",{attrs:{href:"#最佳实践"}},[t._v("最佳实践")])])])]),t._v(" "),s("RouterLink",{attrs:{to:"/zh/guide/core-concept.html"}},[t._v("什么是Priest?")]),s("p"),t._v(" "),s("h2",{attrs:{id:"小试牛刀"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#小试牛刀"}},[t._v("#")]),t._v(" 小试牛刀")]),t._v(" "),s("p",[s("code",[t._v("gone priest")]),t._v("命令可以扫描代码中的特殊注释"),s("code",[t._v("//go:gone")]),t._v("生成Priest函数;"),s("code",[t._v("//go:gone")]),t._v("暂时只能用于标记"),s("code",[t._v("func () gone.Goner")]),t._v(" 和 "),s("code",[t._v("func () (gone.Goner, gone.GonerId)")]),t._v("这两种形式的函数,函数必须是公开(以大写字母开头)。")]),t._v(" "),s("h3",{attrs:{id:"_1-安装gone辅助工具"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-安装gone辅助工具"}},[t._v("#")]),t._v(" 1. 安装gone辅助工具")]),t._v(" "),s("p",[t._v("执行如下命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),s("p",[t._v("gone更多内容参考文档 "),s("RouterLink",{attrs:{to:"/zh/references/gone-tool.html"}},[t._v("gone辅助工具")])],1),t._v(" "),s("h3",{attrs:{id:"_2-编写goner"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-编写goner"}},[t._v("#")]),t._v(" 2. 编写Goner")]),t._v(" "),s("p",[t._v("创建项目,创建文件:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" demo\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" demo\ngo mod init demo\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" demo.go\n")])])]),s("p",[t._v("编辑demo.go文件代码如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Demo "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-生成代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-生成代码"}},[t._v("#")]),t._v(" 3. 生成代码")]),t._v(" "),s("p",[t._v("执行")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone priest "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-s")]),t._v(" ./ "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" Priest "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" priest.go "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-p")]),t._v(" demo\n")])])]),s("p",[t._v("将生成文件:priest.go\n内容如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Code generated by gone; DO NOT EDIT.")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"最佳实践"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#最佳实践"}},[t._v("#")]),t._v(" 最佳实践")]),t._v(" "),s("ul",[s("li",[t._v("创建一个MasterPriest函数,用于Gone框架的启动;")]),t._v(" "),s("li",[t._v("在MasterPriest函数中,调用项目依赖包的Priest函数;")]),t._v(" "),s("li",[t._v("将“gone priest”命令放到MasterPriest函数的"),s("code",[t._v("//go:generate")]),t._v("注释后,例如:")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" internal\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:generate gone priest -s . -p $GOPACKAGE -f Priest -o priest.go")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//调用项目依赖包的Priest函数")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GinPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//调用生成的Priest函数")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("blockquote",[s("p",[t._v("tips: 运行"),s("code",[t._v("go generate ./...")]),t._v(" 会执行 所有"),s("code",[t._v("//go:generate")]),t._v("注释后的命令;")])]),t._v(" "),s("ul",[s("li",[t._v("在MasterPriest函数中,调用调用生成的Priest函数;")]),t._v(" "),s("li",[t._v("git忽略掉生成文件,将生成的文件加入到"),s("code",[t._v(".gitignore")]),t._v("文件中。")])]),t._v(" "),s("p",[t._v("按照上面逻辑,我们编写了一个可供参考的Web空白项目"),s("a",{attrs:{href:"https://github.com/gone-io/examples/tree/main/empty",target:"_blank",rel:"noopener noreferrer"}},[t._v("Demo"),s("OutboundLink")],1),t._v(",已经放到github上,快点击打开吧;另外也可以运行"),s("code",[t._v("gone create web-app")]),t._v("生成一个空白项目,参考"),s("a",{attrs:{href:"https://goner.fun/zh/quick-start/",target:"_blank",rel:"noopener noreferrer"}},[t._v("快速开始\n"),s("OutboundLink")],1),t._v("。")])],1)}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/50.a970a015.js b/assets/js/50.949cb554.js similarity index 99% rename from assets/js/50.a970a015.js rename to assets/js/50.949cb554.js index b426764..2c0a0b4 100644 --- a/assets/js/50.a970a015.js +++ b/assets/js/50.949cb554.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[50],{336:function(t,s,a){"use strict";a.r(s);var n=a(10),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"通过内置goners支持配置文件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#通过内置goners支持配置文件"}},[t._v("#")]),t._v(" 通过内置Goners支持配置文件")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#举个例子"}},[t._v("举个例子")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-创建mod"}},[t._v("1. 创建mod")])]),s("li",[s("a",{attrs:{href:"#_2-添加配置文件"}},[t._v("2. 添加配置文件")])]),s("li",[s("a",{attrs:{href:"#_3-添加代码"}},[t._v("3. 添加代码")])]),s("li",[s("a",{attrs:{href:"#_4-运行"}},[t._v("4. 运行")])])])]),s("li",[s("a",{attrs:{href:"#配置注入"}},[t._v("配置注入")]),s("ul",[s("li",[s("a",{attrs:{href:"#使用的标签格式"}},[t._v("使用的标签格式")])]),s("li",[s("a",{attrs:{href:"#支持注入的数据类型"}},[t._v("支持注入的数据类型")])]),s("li",[s("a",{attrs:{href:"#配置文件"}},[t._v("配置文件")])])])])])]),s("p"),t._v(" "),s("p",[t._v("在gone中提供了通过内置Goners读取配置文件的方法,配置文件格式暂时只支持"),s("code",[t._v(".properties")]),t._v("。")]),t._v(" "),s("h2",{attrs:{id:"举个例子"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#举个例子"}},[t._v("#")]),t._v(" 举个例子")]),t._v(" "),s("blockquote",[s("p",[t._v("例子的代码源代码可以在"),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-config",target:"_blank",rel:"noopener noreferrer"}},[t._v("这里"),s("OutboundLink")],1),t._v("找到。")])]),t._v(" "),s("h3",{attrs:{id:"_1-创建mod"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-创建mod"}},[t._v("#")]),t._v(" 1. 创建mod")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go mod init use-config\n")])])]),s("h3",{attrs:{id:"_2-添加配置文件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-添加配置文件"}},[t._v("#")]),t._v(" 2. 添加配置文件")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" config\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" config/default.properties\n")])])]),s("p",[t._v("config/default.properties 文件内容如下:")]),t._v(" "),s("div",{staticClass:"language-properties extra-class"},[s("pre",{pre:!0,attrs:{class:"language-properties"}},[s("code",[s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.int8")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("130")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10.222")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("config test")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.bool")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("true")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.duration")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10h")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.sub.x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("100x")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.sub.y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("200y")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[0].x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("0000x")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[0].y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("0000y")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[1].x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("1111x")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[1].y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("1111y")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-添加代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-添加代码"}},[t._v("#")]),t._v(" 3. 添加代码")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" main.go\n")])])]),s("p",[t._v("main.go 文件内容如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"time"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SubConf "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tX "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`properties:"x"`')]),t._v("\n\tY "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`properties:"y"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" UseConfig "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int8"`')]),t._v("\n\tprintInt "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int8"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//指针 指向int")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.float64"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.string"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.bool"`')]),t._v("\n\tduration time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Duration "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.duration"`')]),t._v("\n\tdefaultV "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.default,default=ok"`')]),t._v("\n\n\tsub "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("SubConf "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.sub"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//指针,指向结构体")]),t._v("\n\n\tsubs "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("SubConf "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.subs"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//数组")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("UseConfig"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"int=%d\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"int8=%d\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"printInt=%d\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("printInt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"float64=%f\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"string=%s\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"bool=%t\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"duration=%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("duration"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"defaultV=%s\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("defaultV"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"sub.x=%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("sub"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"subs=%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("subs"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("UseConfig"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"_4-运行"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-运行"}},[t._v("#")]),t._v(" 4. 运行")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go mod tidy\ngo run main.go\n")])])]),s("p",[t._v("运行结果如下:")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("int=10\nint8=-126\nprintInt=130\nfloat64=10.222000\nstring=config test\nbool=true\nduration=10h0m0s\ndefaultV=ok\nsub.x=&{100x 200y}\nsubs=[{0000x 0000y} {1111x 1111y}]\n")])])]),s("h2",{attrs:{id:"配置注入"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#配置注入"}},[t._v("#")]),t._v(" 配置注入")]),t._v(" "),s("p",[t._v("从例子中可以看到,配置项也可以通过“依赖注入”到Goner。")]),t._v(" "),s("h3",{attrs:{id:"使用的标签格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用的标签格式"}},[t._v("#")]),t._v(" 使用的标签格式")]),t._v(" "),s("p",[t._v("配置注入的标签格式如下:")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v('gone:"config,${key},default=${defaultValue}"\n')])])]),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("其中含义如下:")]),t._v(" "),s("ol",[s("li",[t._v("标签名依然为"),s("code",[t._v("gone")])]),t._v(" "),s("li",[s("code",[t._v("config")]),t._v("为固定值,表示该属性为配置")]),t._v(" "),s("li",[s("code",[t._v("${key}")]),t._v("为配置在配置文件中的key")]),t._v(" "),s("li",[s("code",[t._v("default=${defaultValue}")]),t._v("用于指定默认值,可以省略;"),s("code",[t._v("${defaultValue}")]),t._v("为默认值;如果没有指定默认值;如果配置文件中缺少对应key,则会报错")])])]),t._v(" "),s("h3",{attrs:{id:"支持注入的数据类型"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#支持注入的数据类型"}},[t._v("#")]),t._v(" 支持注入的数据类型")]),t._v(" "),s("blockquote",[s("p",[t._v("在 "),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html#goner-%E9%80%9D%E8%80%85",target:"_blank",rel:"noopener noreferrer"}},[t._v("核心概念-Goner"),s("OutboundLink")],1),t._v("中,我们讲到Goner可以被注入到其他结构体的属性上;这里,配置作为一种特殊情况,也可以被注入到其他结构体的属性上,他的实现是通过的"),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html#%F0%9F%A7%9B%F0%9F%8F%BB%E2%80%8D%E2%99%80%EF%B8%8Fvampire-%E5%90%B8%E8%A1%80%E9%AC%BC",target:"_blank",rel:"noopener noreferrer"}},[t._v("Vampire(吸血鬼)"),s("OutboundLink")],1),t._v(",如果感觉兴趣,可以看"),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/v0.1.5/goner/config",target:"_blank",rel:"noopener noreferrer"}},[t._v("这部分源代码"),s("OutboundLink")],1),t._v("。")])]),t._v(" "),s("p",[t._v("属性支持的类型,列举如下:")]),t._v(" "),s("ol",[s("li",[t._v("基础类型\n"),s("ul",[s("li",[t._v("布尔型:bool")]),t._v(" "),s("li",[t._v("整数类型:int, int64, int32, int16, int8")]),t._v(" "),s("li",[t._v("非负整数类型:uint, uint64, uint32, uint16, uint8")]),t._v(" "),s("li",[t._v("浮点型:float64, float32")]),t._v(" "),s("li",[t._v("字符串类型:string")])])])]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("整数类型和非负整数类型,需要注意数据结构表示的数的范围,数字过大可能会溢出;比如"),s("code",[t._v("int8")]),t._v("表示的范围是"),s("code",[t._v("-128")]),t._v(" ~ "),s("code",[t._v("127")]),t._v(",如果用其接收一个大于127的配置就会发生溢出(配置128将得到-128)。")])]),t._v(" "),s("ol",{attrs:{start:"2"}},[s("li",[t._v("time.Duration\n为方便时间的解析,支持了"),s("code",[t._v("time.Duration")]),t._v("类型的配置,可以使用下面的单位:\n"),s("ul",[s("li",[t._v("ns 纳秒")]),t._v(" "),s("li",[t._v("us 微秒")]),t._v(" "),s("li",[t._v("ms 毫秒")]),t._v(" "),s("li",[t._v("s 秒")]),t._v(" "),s("li",[t._v("m 分钟")]),t._v(" "),s("li",[t._v("h 小时")])])])]),t._v(" "),s("p",[t._v("在例子中,"),s("code",[t._v("my.conf.duration=10h")]),t._v("单位为h,表示10个小时;"),s("code",[t._v("1h10m10s")]),t._v("则表示1小时10分10秒。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("实现采用的"),s("code",[t._v("time.ParseDuration")]),t._v(",所以可以参考:"),s("a",{attrs:{href:"https://pkg.go.dev/time#ParseDuration",target:"_blank",rel:"noopener noreferrer"}},[t._v("https://pkg.go.dev/time#ParseDuration"),s("OutboundLink")],1)])]),t._v(" "),s("ol",{attrs:{start:"3"}},[s("li",[t._v("结构体类型\n在例子中,给出了配置结构体的类型,需要满足如下规则:\n"),s("ul",[s("li",[t._v("结构体中需要配置的属性为公开的,即大写字母打头")]),t._v(" "),s("li",[t._v("使用"),s("code",[t._v("properties")]),t._v("标签指定属性的名字")]),t._v(" "),s("li",[t._v("支持嵌套")])])])]),t._v(" "),s("p",[t._v("说明:在例子中"),s("code",[t._v("UseConfig")]),t._v("的属性"),s("code",[t._v("sub")]),t._v("要读取的配置key为"),s("code",[t._v("my.conf.sub")]),t._v(";"),s("code",[t._v("sub")]),t._v("的类型为"),s("code",[t._v("SubConf")]),t._v(",标注了属性"),s("code",[t._v("X")]),t._v("的配置名为"),s("code",[t._v('properties:"x"')]),t._v(",那么"),s("code",[t._v("sub.X")]),t._v("的值将读取配置项"),s("code",[t._v("my.conf.sub.x")]),t._v("。")]),t._v(" "),s("ol",{attrs:{start:"4"}},[s("li",[t._v("数组类型\n配置的注入支持Slice类型,Slice的元素目前只支持结构体、结构体的指针;配置的key形式如下:")])]),t._v(" "),s("div",{staticClass:"language-ini extra-class"},[s("pre",{pre:!0,attrs:{class:"language-ini"}},[s("code",[t._v("${injectConfigkey}[${index}].${structAttributeName}\n")])])]),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("说明")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("${injectConfigkey}")]),t._v("为待注入项的key")]),t._v(" "),s("li",[s("code",[t._v("${index}")]),t._v("为数组下标")]),t._v(" "),s("li",[s("code",[t._v("${structAttributeName}")]),t._v("为被注入结构体的属性上的"),s("code",[t._v("properties")]),t._v("标注的值")])])]),t._v(" "),s("ol",{attrs:{start:"5"}},[s("li",[t._v("指针类型\n支持被注入属性的类型为指针。")])]),t._v(" "),s("h3",{attrs:{id:"配置文件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#配置文件"}},[t._v("#")]),t._v(" 配置文件")]),t._v(" "),s("h4",{attrs:{id:"配置文件目录"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#配置文件目录"}},[t._v("#")]),t._v(" 配置文件目录")]),t._v(" "),s("p",[t._v("配置文件存放的目录由三部分决定:")]),t._v(" "),s("ol",[s("li",[t._v("可执行文件和程序当前工作路径")]),t._v(" "),s("li",[t._v("相对配置目录\n相对配置目录默认是"),s("code",[t._v("config")]),t._v(",可以通过启动传参"),s("code",[t._v("--conf $configDir")]),t._v("来改变")])]),t._v(" "),s("p",[t._v("举个例子,如果编译后的gone程序保存为"),s("code",[t._v("/app/gone-app")]),t._v(",我们进入"),s("code",[t._v("/home/degfy")]),t._v("目录运行:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" /home/degfy/\n/app/gone-app\n")])])]),s("p",[t._v("并没有通过传参修改相对配置目录,那么该程序的配置目录为:")]),t._v(" "),s("ul",[s("li",[t._v("/app/config")]),t._v(" "),s("li",[t._v("/home/degfy/config")])]),t._v(" "),s("h4",{attrs:{id:"默认配置文件路径"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#默认配置文件路径"}},[t._v("#")]),t._v(" 默认配置文件路径")]),t._v(" "),s("p",[t._v("沿用前面的例子,配置文件的路径为:")]),t._v(" "),s("ul",[s("li",[t._v("/app/config/default.properties")]),t._v(" "),s("li",[t._v("/home/degfy/config/default.properties\n这个两个配置文件中的配置为默认配置,是不随环境改变而改变的。")])]),t._v(" "),s("h4",{attrs:{id:"环境相关配置文件路径"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#环境相关配置文件路径"}},[t._v("#")]),t._v(" 环境相关配置文件路径")]),t._v(" "),s("p",[t._v("开发过程中,我们一般会分环境配置,一般情况会分为:")]),t._v(" "),s("ul",[s("li",[t._v("local 本地开发环境")]),t._v(" "),s("li",[t._v("dev 线上开发环境")]),t._v(" "),s("li",[t._v("test 线上测试环境")]),t._v(" "),s("li",[t._v("prod 生成环境")])]),t._v(" "),s("p",[t._v("我们可以通过环境变量"),s("code",[t._v("ENV")]),t._v("或者在启动时传参"),s("code",[t._v("--nev $env")]),t._v("来指定当前环境,如果都没有设置,默认环境是"),s("code",[t._v("local")]),t._v("。\n沿用前面的例子,与环境相关的配置文件为:")]),t._v(" "),s("ul",[s("li",[t._v("/app/config/local.properties")]),t._v(" "),s("li",[t._v("/home/degfy/config/local.properties")])]),t._v(" "),s("h4",{attrs:{id:"配置加载的顺序"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#配置加载的顺序"}},[t._v("#")]),t._v(" 配置加载的顺序")]),t._v(" "),s("p",[t._v("从前面,我们可以得知我们启动时会存在4个配置文件,他们的加载顺序如下:")]),t._v(" "),s("ol",[s("li",[t._v("/app/config/default.properties")]),t._v(" "),s("li",[t._v("/app/config/local.properties")]),t._v(" "),s("li",[t._v("/home/degfy/config/default.properties")]),t._v(" "),s("li",[t._v("/home/degfy/config/local.properties")])]),t._v(" "),s("p",[t._v("如果这些配置文件中存在相同的配置项,后加载的值会先加载的值。也就是环境相关的配置会覆盖默认的配置,当前运行路径的配置会覆盖程序所在目录的配置。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("最佳实践")]),t._v(" "),s("ol",[s("li",[t._v("将所有配置放到默认配置文件中;在环境相关配置文件中根据环境的需要进行覆盖;")]),t._v(" "),s("li",[t._v("配置的设计应该尽量少,推荐采用“约定优配置”思路来进行设计,配置可以考虑赋予默认值;")]),t._v(" "),s("li",[t._v("为了使代码“开箱可用”,推荐在local.properties中设置完整的配置,让程序不需要任何其他的配置就能运行,让其他小伙伴clone代码后就能丝滑启动程序。")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[50],{337:function(t,s,a){"use strict";a.r(s);var n=a(10),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"通过内置goners支持配置文件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#通过内置goners支持配置文件"}},[t._v("#")]),t._v(" 通过内置Goners支持配置文件")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#举个例子"}},[t._v("举个例子")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-创建mod"}},[t._v("1. 创建mod")])]),s("li",[s("a",{attrs:{href:"#_2-添加配置文件"}},[t._v("2. 添加配置文件")])]),s("li",[s("a",{attrs:{href:"#_3-添加代码"}},[t._v("3. 添加代码")])]),s("li",[s("a",{attrs:{href:"#_4-运行"}},[t._v("4. 运行")])])])]),s("li",[s("a",{attrs:{href:"#配置注入"}},[t._v("配置注入")]),s("ul",[s("li",[s("a",{attrs:{href:"#使用的标签格式"}},[t._v("使用的标签格式")])]),s("li",[s("a",{attrs:{href:"#支持注入的数据类型"}},[t._v("支持注入的数据类型")])]),s("li",[s("a",{attrs:{href:"#配置文件"}},[t._v("配置文件")])])])])])]),s("p"),t._v(" "),s("p",[t._v("在gone中提供了通过内置Goners读取配置文件的方法,配置文件格式暂时只支持"),s("code",[t._v(".properties")]),t._v("。")]),t._v(" "),s("h2",{attrs:{id:"举个例子"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#举个例子"}},[t._v("#")]),t._v(" 举个例子")]),t._v(" "),s("blockquote",[s("p",[t._v("例子的代码源代码可以在"),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-config",target:"_blank",rel:"noopener noreferrer"}},[t._v("这里"),s("OutboundLink")],1),t._v("找到。")])]),t._v(" "),s("h3",{attrs:{id:"_1-创建mod"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-创建mod"}},[t._v("#")]),t._v(" 1. 创建mod")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go mod init use-config\n")])])]),s("h3",{attrs:{id:"_2-添加配置文件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-添加配置文件"}},[t._v("#")]),t._v(" 2. 添加配置文件")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" config\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" config/default.properties\n")])])]),s("p",[t._v("config/default.properties 文件内容如下:")]),t._v(" "),s("div",{staticClass:"language-properties extra-class"},[s("pre",{pre:!0,attrs:{class:"language-properties"}},[s("code",[s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.int8")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("130")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10.222")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("config test")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.bool")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("true")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.duration")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("10h")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.sub.x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("100x")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.sub.y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("200y")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[0].x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("0000x")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[0].y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("0000y")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[1].x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("1111x")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("my.conf.subs[1].y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("1111y")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-添加代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-添加代码"}},[t._v("#")]),t._v(" 3. 添加代码")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("touch")]),t._v(" main.go\n")])])]),s("p",[t._v("main.go 文件内容如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"time"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SubConf "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tX "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`properties:"x"`')]),t._v("\n\tY "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`properties:"y"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" UseConfig "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int8"`')]),t._v("\n\tprintInt "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.int8"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//指针 指向int")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.float64"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.string"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.bool"`')]),t._v("\n\tduration time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Duration "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.duration"`')]),t._v("\n\tdefaultV "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.default,default=ok"`')]),t._v("\n\n\tsub "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("SubConf "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.sub"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//指针,指向结构体")]),t._v("\n\n\tsubs "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("SubConf "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,my.conf.subs"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//数组")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("UseConfig"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"int=%d\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"int8=%d\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int8")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"printInt=%d\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("printInt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"float64=%f\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"string=%s\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"bool=%t\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("bool")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"duration=%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("duration"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"defaultV=%s\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("defaultV"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"sub.x=%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("sub"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"subs=%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" g"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("subs"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("UseConfig"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"_4-运行"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-运行"}},[t._v("#")]),t._v(" 4. 运行")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go mod tidy\ngo run main.go\n")])])]),s("p",[t._v("运行结果如下:")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("int=10\nint8=-126\nprintInt=130\nfloat64=10.222000\nstring=config test\nbool=true\nduration=10h0m0s\ndefaultV=ok\nsub.x=&{100x 200y}\nsubs=[{0000x 0000y} {1111x 1111y}]\n")])])]),s("h2",{attrs:{id:"配置注入"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#配置注入"}},[t._v("#")]),t._v(" 配置注入")]),t._v(" "),s("p",[t._v("从例子中可以看到,配置项也可以通过“依赖注入”到Goner。")]),t._v(" "),s("h3",{attrs:{id:"使用的标签格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用的标签格式"}},[t._v("#")]),t._v(" 使用的标签格式")]),t._v(" "),s("p",[t._v("配置注入的标签格式如下:")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v('gone:"config,${key},default=${defaultValue}"\n')])])]),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("其中含义如下:")]),t._v(" "),s("ol",[s("li",[t._v("标签名依然为"),s("code",[t._v("gone")])]),t._v(" "),s("li",[s("code",[t._v("config")]),t._v("为固定值,表示该属性为配置")]),t._v(" "),s("li",[s("code",[t._v("${key}")]),t._v("为配置在配置文件中的key")]),t._v(" "),s("li",[s("code",[t._v("default=${defaultValue}")]),t._v("用于指定默认值,可以省略;"),s("code",[t._v("${defaultValue}")]),t._v("为默认值;如果没有指定默认值;如果配置文件中缺少对应key,则会报错")])])]),t._v(" "),s("h3",{attrs:{id:"支持注入的数据类型"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#支持注入的数据类型"}},[t._v("#")]),t._v(" 支持注入的数据类型")]),t._v(" "),s("blockquote",[s("p",[t._v("在 "),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html#goner-%E9%80%9D%E8%80%85",target:"_blank",rel:"noopener noreferrer"}},[t._v("核心概念-Goner"),s("OutboundLink")],1),t._v("中,我们讲到Goner可以被注入到其他结构体的属性上;这里,配置作为一种特殊情况,也可以被注入到其他结构体的属性上,他的实现是通过的"),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html#%F0%9F%A7%9B%F0%9F%8F%BB%E2%80%8D%E2%99%80%EF%B8%8Fvampire-%E5%90%B8%E8%A1%80%E9%AC%BC",target:"_blank",rel:"noopener noreferrer"}},[t._v("Vampire(吸血鬼)"),s("OutboundLink")],1),t._v(",如果感觉兴趣,可以看"),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/v0.1.5/goner/config",target:"_blank",rel:"noopener noreferrer"}},[t._v("这部分源代码"),s("OutboundLink")],1),t._v("。")])]),t._v(" "),s("p",[t._v("属性支持的类型,列举如下:")]),t._v(" "),s("ol",[s("li",[t._v("基础类型\n"),s("ul",[s("li",[t._v("布尔型:bool")]),t._v(" "),s("li",[t._v("整数类型:int, int64, int32, int16, int8")]),t._v(" "),s("li",[t._v("非负整数类型:uint, uint64, uint32, uint16, uint8")]),t._v(" "),s("li",[t._v("浮点型:float64, float32")]),t._v(" "),s("li",[t._v("字符串类型:string")])])])]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("整数类型和非负整数类型,需要注意数据结构表示的数的范围,数字过大可能会溢出;比如"),s("code",[t._v("int8")]),t._v("表示的范围是"),s("code",[t._v("-128")]),t._v(" ~ "),s("code",[t._v("127")]),t._v(",如果用其接收一个大于127的配置就会发生溢出(配置128将得到-128)。")])]),t._v(" "),s("ol",{attrs:{start:"2"}},[s("li",[t._v("time.Duration\n为方便时间的解析,支持了"),s("code",[t._v("time.Duration")]),t._v("类型的配置,可以使用下面的单位:\n"),s("ul",[s("li",[t._v("ns 纳秒")]),t._v(" "),s("li",[t._v("us 微秒")]),t._v(" "),s("li",[t._v("ms 毫秒")]),t._v(" "),s("li",[t._v("s 秒")]),t._v(" "),s("li",[t._v("m 分钟")]),t._v(" "),s("li",[t._v("h 小时")])])])]),t._v(" "),s("p",[t._v("在例子中,"),s("code",[t._v("my.conf.duration=10h")]),t._v("单位为h,表示10个小时;"),s("code",[t._v("1h10m10s")]),t._v("则表示1小时10分10秒。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("实现采用的"),s("code",[t._v("time.ParseDuration")]),t._v(",所以可以参考:"),s("a",{attrs:{href:"https://pkg.go.dev/time#ParseDuration",target:"_blank",rel:"noopener noreferrer"}},[t._v("https://pkg.go.dev/time#ParseDuration"),s("OutboundLink")],1)])]),t._v(" "),s("ol",{attrs:{start:"3"}},[s("li",[t._v("结构体类型\n在例子中,给出了配置结构体的类型,需要满足如下规则:\n"),s("ul",[s("li",[t._v("结构体中需要配置的属性为公开的,即大写字母打头")]),t._v(" "),s("li",[t._v("使用"),s("code",[t._v("properties")]),t._v("标签指定属性的名字")]),t._v(" "),s("li",[t._v("支持嵌套")])])])]),t._v(" "),s("p",[t._v("说明:在例子中"),s("code",[t._v("UseConfig")]),t._v("的属性"),s("code",[t._v("sub")]),t._v("要读取的配置key为"),s("code",[t._v("my.conf.sub")]),t._v(";"),s("code",[t._v("sub")]),t._v("的类型为"),s("code",[t._v("SubConf")]),t._v(",标注了属性"),s("code",[t._v("X")]),t._v("的配置名为"),s("code",[t._v('properties:"x"')]),t._v(",那么"),s("code",[t._v("sub.X")]),t._v("的值将读取配置项"),s("code",[t._v("my.conf.sub.x")]),t._v("。")]),t._v(" "),s("ol",{attrs:{start:"4"}},[s("li",[t._v("数组类型\n配置的注入支持Slice类型,Slice的元素目前只支持结构体、结构体的指针;配置的key形式如下:")])]),t._v(" "),s("div",{staticClass:"language-ini extra-class"},[s("pre",{pre:!0,attrs:{class:"language-ini"}},[s("code",[t._v("${injectConfigkey}[${index}].${structAttributeName}\n")])])]),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("说明")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("${injectConfigkey}")]),t._v("为待注入项的key")]),t._v(" "),s("li",[s("code",[t._v("${index}")]),t._v("为数组下标")]),t._v(" "),s("li",[s("code",[t._v("${structAttributeName}")]),t._v("为被注入结构体的属性上的"),s("code",[t._v("properties")]),t._v("标注的值")])])]),t._v(" "),s("ol",{attrs:{start:"5"}},[s("li",[t._v("指针类型\n支持被注入属性的类型为指针。")])]),t._v(" "),s("h3",{attrs:{id:"配置文件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#配置文件"}},[t._v("#")]),t._v(" 配置文件")]),t._v(" "),s("h4",{attrs:{id:"配置文件目录"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#配置文件目录"}},[t._v("#")]),t._v(" 配置文件目录")]),t._v(" "),s("p",[t._v("配置文件存放的目录由三部分决定:")]),t._v(" "),s("ol",[s("li",[t._v("可执行文件和程序当前工作路径")]),t._v(" "),s("li",[t._v("相对配置目录\n相对配置目录默认是"),s("code",[t._v("config")]),t._v(",可以通过启动传参"),s("code",[t._v("--conf $configDir")]),t._v("来改变")])]),t._v(" "),s("p",[t._v("举个例子,如果编译后的gone程序保存为"),s("code",[t._v("/app/gone-app")]),t._v(",我们进入"),s("code",[t._v("/home/degfy")]),t._v("目录运行:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" /home/degfy/\n/app/gone-app\n")])])]),s("p",[t._v("并没有通过传参修改相对配置目录,那么该程序的配置目录为:")]),t._v(" "),s("ul",[s("li",[t._v("/app/config")]),t._v(" "),s("li",[t._v("/home/degfy/config")])]),t._v(" "),s("h4",{attrs:{id:"默认配置文件路径"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#默认配置文件路径"}},[t._v("#")]),t._v(" 默认配置文件路径")]),t._v(" "),s("p",[t._v("沿用前面的例子,配置文件的路径为:")]),t._v(" "),s("ul",[s("li",[t._v("/app/config/default.properties")]),t._v(" "),s("li",[t._v("/home/degfy/config/default.properties\n这个两个配置文件中的配置为默认配置,是不随环境改变而改变的。")])]),t._v(" "),s("h4",{attrs:{id:"环境相关配置文件路径"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#环境相关配置文件路径"}},[t._v("#")]),t._v(" 环境相关配置文件路径")]),t._v(" "),s("p",[t._v("开发过程中,我们一般会分环境配置,一般情况会分为:")]),t._v(" "),s("ul",[s("li",[t._v("local 本地开发环境")]),t._v(" "),s("li",[t._v("dev 线上开发环境")]),t._v(" "),s("li",[t._v("test 线上测试环境")]),t._v(" "),s("li",[t._v("prod 生成环境")])]),t._v(" "),s("p",[t._v("我们可以通过环境变量"),s("code",[t._v("ENV")]),t._v("或者在启动时传参"),s("code",[t._v("--nev $env")]),t._v("来指定当前环境,如果都没有设置,默认环境是"),s("code",[t._v("local")]),t._v("。\n沿用前面的例子,与环境相关的配置文件为:")]),t._v(" "),s("ul",[s("li",[t._v("/app/config/local.properties")]),t._v(" "),s("li",[t._v("/home/degfy/config/local.properties")])]),t._v(" "),s("h4",{attrs:{id:"配置加载的顺序"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#配置加载的顺序"}},[t._v("#")]),t._v(" 配置加载的顺序")]),t._v(" "),s("p",[t._v("从前面,我们可以得知我们启动时会存在4个配置文件,他们的加载顺序如下:")]),t._v(" "),s("ol",[s("li",[t._v("/app/config/default.properties")]),t._v(" "),s("li",[t._v("/app/config/local.properties")]),t._v(" "),s("li",[t._v("/home/degfy/config/default.properties")]),t._v(" "),s("li",[t._v("/home/degfy/config/local.properties")])]),t._v(" "),s("p",[t._v("如果这些配置文件中存在相同的配置项,后加载的值会先加载的值。也就是环境相关的配置会覆盖默认的配置,当前运行路径的配置会覆盖程序所在目录的配置。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("最佳实践")]),t._v(" "),s("ol",[s("li",[t._v("将所有配置放到默认配置文件中;在环境相关配置文件中根据环境的需要进行覆盖;")]),t._v(" "),s("li",[t._v("配置的设计应该尽量少,推荐采用“约定优配置”思路来进行设计,配置可以考虑赋予默认值;")]),t._v(" "),s("li",[t._v("为了使代码“开箱可用”,推荐在local.properties中设置完整的配置,让程序不需要任何其他的配置就能运行,让其他小伙伴clone代码后就能丝滑启动程序。")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/51.d3cfe23a.js b/assets/js/51.22673662.js similarity index 99% rename from assets/js/51.d3cfe23a.js rename to assets/js/51.22673662.js index 7fbc722..b77287c 100644 --- a/assets/js/51.d3cfe23a.js +++ b/assets/js/51.22673662.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[51],{337:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"gone的核心概念"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#gone的核心概念"}},[t._v("#")]),t._v(" Gone的核心概念")]),t._v(" "),s("p",[t._v("“我们编写的代码,终究只是死物,除非他在"),s("strong",[t._v("天国")]),t._v("被"),s("strong",[t._v("复活")]),t._v(",为此我们需要将他"),s("strong",[t._v("埋葬")]),t._v("在"),s("strong",[t._v("墓园")]),t._v("。”")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#goner-逝者"}},[t._v("Goner(逝者)")]),s("ul",[s("li",[s("a",{attrs:{href:"#🔮prophet-先知"}},[t._v("🔮Prophet(先知)")])]),s("li",[s("a",{attrs:{href:"#😇angel-天使"}},[t._v("😇Angel(天使)")])]),s("li",[s("a",{attrs:{href:"#🧛🏻‍♀️vampire-吸血鬼"}},[t._v("🧛🏻‍♀️Vampire(吸血鬼)")])])])]),s("li",[s("a",{attrs:{href:"#cemetery-墓园"}},[t._v("Cemetery(墓园)")]),s("ul",[s("li",[s("a",{attrs:{href:"#bury-埋葬"}},[t._v("Bury(埋葬)")])]),s("li",[s("a",{attrs:{href:"#revive-复活"}},[t._v("Revive(复活)")])])])]),s("li",[s("a",{attrs:{href:"#heaven-天国"}},[t._v("Heaven(天国)")])]),s("li",[s("a",{attrs:{href:"#priest-牧师"}},[t._v("Priest (牧师)")])])])]),s("p"),t._v(" "),s("h2",{attrs:{id:"goner-逝者"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#goner-逝者"}},[t._v("#")]),t._v(" Goner(逝者)")]),t._v(" "),s("p",[t._v("在Gone框架中,最基本的和最核心的概念就是 Goner,"),s("strong",[t._v("Goner 是指的匿名嵌入了 "),s("code",[t._v("gone.Flag")]),t._v(" 的结构体")]),t._v("。举个例子:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Goner是Gone框架中的组件,是实现依赖注入的关键:")]),t._v(" "),s("ol",[s("li",[t._v("Goner可以作为属性被注入到其他结构体")]),t._v(" "),s("li",[t._v("Goner的属性可以被其他类型注入")])]),t._v(" "),s("p",[t._v("为什么需要内嵌一个 "),s("code",[t._v("gone.Flag")]),t._v("?是因为我们希望限制依赖注入的范围,让依赖注入只发生在Goners之间,让Gone框架的组件实现有一个统一的模式。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("下面是Goner和gone.Flag的源代码:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Flag "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Flag"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("goneFlag")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner 逝者")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Goner "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("goneFlag")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Goner作为接口,要求实现它的“对象”拥有一个私有的方法"),s("code",[t._v("goneFlag()")]),t._v(";由于go语言可见性的限制,不能在"),s("code",[t._v("github.com/gone-io/gone")]),t._v("以外的包中实现其内部定义的私有方法;一个结构体要成为Goner,只能通过内嵌"),s("code",[t._v("gone.Flag")]),t._v("才能“继承”私有的方法"),s("code",[t._v("goneFlag()")]),t._v("。这段话可能有些不好理解,其实就是说Goner的实现只能通过内嵌gone.Flag来完成,不能通过实现"),s("code",[t._v("goneFlag()")]),t._v("方法来完成。")])]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("多个"),s("strong",[t._v("Goner")]),t._v(",我们使用其复数形式("),s("strong",[t._v("Goners")]),t._v(")表示。")])]),t._v(" "),s("p",[t._v("在Gone框架中,还包含了三类特殊的Goner,定义如下:")]),t._v(" "),s("h3",{attrs:{id:"🔮prophet-先知"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#🔮prophet-先知"}},[t._v("#")]),t._v(" 🔮Prophet(先知)")]),t._v(" "),s("p",[t._v("一种特殊的 "),s("strong",[t._v("Goner")]),t._v(",在普通 "),s("strong",[t._v("Goner")]),t._v(" 上实现了 "),s("strong",[s("code",[t._v("AfterRevive() AfterReviveError")])]),t._v(" 方法就是 "),s("strong",[t._v("Prophet(先知)")]),t._v(";"),s("strong",[t._v("AfterRevive")]),t._v(" 会在 "),s("strong",[t._v("Goner")]),t._v(" 被复活后被执行。")]),t._v(" "),s("p",[t._v("Prophet接口定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Prophet 先知")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Prophet "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//AfterRevive 在Goner复活后会被执行")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" AfterReviveError\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"😇angel-天使"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#😇angel-天使"}},[t._v("#")]),t._v(" 😇Angel(天使)")]),t._v(" "),s("p",[t._v("一种特殊的 "),s("strong",[t._v("Goner")]),t._v(",拥有天使左翼"),s("code",[t._v("Start(Cemetery) error")]),t._v(" 和 天使右翼"),s("code",[t._v("Stop(Cemetery) error")]),t._v(",左翼负责生(用于分配资源,启动某项服务),右翼负责死(用于终止某项服务,回收资源)。")]),t._v(" "),s("p",[t._v("Angel接口定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Angel "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Start")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Stop")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"🧛🏻‍♀️vampire-吸血鬼"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#🧛🏻‍♀️vampire-吸血鬼"}},[t._v("#")]),t._v(" 🧛🏻‍♀️Vampire(吸血鬼)")]),t._v(" "),s("p",[t._v("一种特殊的 "),s("strong",[t._v("Goner")]),t._v(",拥有特殊能力——吸血"),s("code",[t._v("Suck(conf string, v reflect.Value) SuckError")]),t._v("。"),s("strong",[t._v("Suck")]),t._v("可以将不是"),s("strong",[t._v("Goner")]),t._v("的值赋予注入给Goner属性。")]),t._v(" "),s("p",[t._v("Vampire接口定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SuckError "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Vampire "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Suck")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("conf "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" v reflect"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" SuckError\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"cemetery-墓园"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#cemetery-墓园"}},[t._v("#")]),t._v(" Cemetery(墓园)")]),t._v(" "),s("p",[t._v("Cemetery用于管理Goners,主要提供Bury(埋葬)和 revive(复活)的方法,其接口定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Cemetery "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ... 其他方法")]),t._v("\n\tGoner\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("GonerId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" Cemetery "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 埋葬,将逝者埋葬到墓园")]),t._v("\n\n\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//ReviveAllFromTombs 复活所有Goner")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ReviveAllFromTombs")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("从代码上可以看到Cemetery本身也是一个Goner,在Gone框架启动时他会被自动埋葬和复活。")]),t._v(" "),s("h3",{attrs:{id:"bury-埋葬"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#bury-埋葬"}},[t._v("#")]),t._v(" Bury(埋葬)")]),t._v(" "),s("p",[t._v("将Goner "),s("strong",[t._v("埋葬")]),t._v(" 到 "),s("strong",[t._v("Cemetery")]),t._v(" 就是将Goner注册到框架,以待后续完成属性的注入;在代码实现上,"),s("strong",[t._v("Bury")]),t._v("是"),s("strong",[t._v("Cemetery")]),t._v("上的公开方法,一般在通过 "),s("strong",[t._v("Priest")]),t._v(" 函数调用该方法。")]),t._v(" "),s("h3",{attrs:{id:"revive-复活"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#revive-复活"}},[t._v("#")]),t._v(" Revive(复活)")]),t._v(" "),s("p",[t._v("Revive(复活)指的是Goner所有需要注入的属性完成注入的过程。在函数"),s("code",[t._v("ReviveAllFromTombs() error")]),t._v("中,所有被"),s("strong",[t._v("埋葬")]),t._v("到"),s("strong",[t._v("Cemetery")]),t._v("的Goners都会被尝试复活,如果有属性不能正常注入,程序将panic。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[s("strong",[t._v("ReviveAllFromTombs")]),t._v("在完成了复活所有的"),s("strong",[t._v("Goners")]),t._v("后,会调用所有"),s("strong",[t._v("Prophet")]),t._v("的 "),s("strong",[t._v("AfterRevive")]),t._v("方法。")])]),t._v(" "),s("h2",{attrs:{id:"heaven-天国"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#heaven-天国"}},[t._v("#")]),t._v(" Heaven(天国)")]),t._v(" "),s("p",[t._v("Heaven(天国)代表了一个Gone程序,用于管理程序的启动、停止等状态和流程(复活在启动前完成),用于在启动前后以及程序停止前执行一些hook任务。Heaven接收一个牧师函数开始运行,例如:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 调用 cemetery.Bury 埋葬 Goner")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 或者 调用其他 Priest 函数")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// TODO")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("或者:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 调用 cemetery.Bury 埋葬 Goner")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 或者 调用其他 Priest 函数")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// TODO")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//TODO: 启动后执行一些操作")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"priest-牧师"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#priest-牧师"}},[t._v("#")]),t._v(" Priest (牧师)")]),t._v(" "),s("p",[t._v("Priest (牧师)是负责将"),s("strong",[t._v("Goner")]),t._v("埋葬到"),s("strong",[t._v("Cemetery")]),t._v("的函数,他的定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Priest "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n")])])]),s("p",[t._v("在"),s("strong",[t._v("Priest")]),t._v("函数实现上,可以调用 "),s("strong",[t._v("cemetery.Bury")]),t._v(" 来完成,如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tName "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("aPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Jim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"boss-jim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Bob"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"worker-bob"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//匿名埋葬,不指定被埋葬Goner的GonerId")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"X"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),s("p",[t._v("也可以通过调用其他的"),s("strong",[t._v("Priest")]),t._v("函数来完成:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("a1Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("a2Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("aPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("a1Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("a2Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("如果我们开发了一个组件包,其中使用了多个"),s("strong",[t._v("Goners")]),t._v("来完成响应的功能,使用时需要同时"),s("strong",[t._v("埋葬")]),t._v("这些"),s("strong",[t._v("Goners")]),t._v(",那么我们可以编写一个"),s("strong",[t._v("Priest")]),t._v("函数方便业务代码批量"),s("strong",[t._v("埋葬")]),t._v("这些"),s("strong",[t._v("Goners")]),t._v("。")]),t._v(" "),s("p",[t._v("框架内置的组件包,我们就是这样干的,"),s("a",{attrs:{href:"https://github.com/gone-io/gone/blob/main/goner/priest.go",target:"_blank",rel:"noopener noreferrer"}},[t._v("代码"),s("OutboundLink")],1),t._v(" 和 "),s("a",{attrs:{href:"https://goner.fun/zh/goners/#%E6%A1%86%E6%9E%B6%E5%86%85%E7%BD%AEgoners",target:"_blank",rel:"noopener noreferrer"}},[t._v("文档"),s("OutboundLink")],1),t._v("。")]),t._v(" "),s("p",[t._v("另外,我们开发了一个命令行辅助工具"),s("strong",[t._v("gone")]),t._v(",用于扫描特殊注释"),s("code",[t._v("//go:gone")]),t._v("自动生成牧师函数,参考"),s("RouterLink",{attrs:{to:"/zh/guide/auto-gen-priest.html"}},[t._v("自动生成Priest")]),t._v("。")],1)])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[51],{338:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"gone的核心概念"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#gone的核心概念"}},[t._v("#")]),t._v(" Gone的核心概念")]),t._v(" "),s("p",[t._v("“我们编写的代码,终究只是死物,除非他在"),s("strong",[t._v("天国")]),t._v("被"),s("strong",[t._v("复活")]),t._v(",为此我们需要将他"),s("strong",[t._v("埋葬")]),t._v("在"),s("strong",[t._v("墓园")]),t._v("。”")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#goner-逝者"}},[t._v("Goner(逝者)")]),s("ul",[s("li",[s("a",{attrs:{href:"#🔮prophet-先知"}},[t._v("🔮Prophet(先知)")])]),s("li",[s("a",{attrs:{href:"#😇angel-天使"}},[t._v("😇Angel(天使)")])]),s("li",[s("a",{attrs:{href:"#🧛🏻‍♀️vampire-吸血鬼"}},[t._v("🧛🏻‍♀️Vampire(吸血鬼)")])])])]),s("li",[s("a",{attrs:{href:"#cemetery-墓园"}},[t._v("Cemetery(墓园)")]),s("ul",[s("li",[s("a",{attrs:{href:"#bury-埋葬"}},[t._v("Bury(埋葬)")])]),s("li",[s("a",{attrs:{href:"#revive-复活"}},[t._v("Revive(复活)")])])])]),s("li",[s("a",{attrs:{href:"#heaven-天国"}},[t._v("Heaven(天国)")])]),s("li",[s("a",{attrs:{href:"#priest-牧师"}},[t._v("Priest (牧师)")])])])]),s("p"),t._v(" "),s("h2",{attrs:{id:"goner-逝者"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#goner-逝者"}},[t._v("#")]),t._v(" Goner(逝者)")]),t._v(" "),s("p",[t._v("在Gone框架中,最基本的和最核心的概念就是 Goner,"),s("strong",[t._v("Goner 是指的匿名嵌入了 "),s("code",[t._v("gone.Flag")]),t._v(" 的结构体")]),t._v("。举个例子:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Goner是Gone框架中的组件,是实现依赖注入的关键:")]),t._v(" "),s("ol",[s("li",[t._v("Goner可以作为属性被注入到其他结构体")]),t._v(" "),s("li",[t._v("Goner的属性可以被其他类型注入")])]),t._v(" "),s("p",[t._v("为什么需要内嵌一个 "),s("code",[t._v("gone.Flag")]),t._v("?是因为我们希望限制依赖注入的范围,让依赖注入只发生在Goners之间,让Gone框架的组件实现有一个统一的模式。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("下面是Goner和gone.Flag的源代码:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Flag "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Flag"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("goneFlag")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner 逝者")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Goner "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("goneFlag")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Goner作为接口,要求实现它的“对象”拥有一个私有的方法"),s("code",[t._v("goneFlag()")]),t._v(";由于go语言可见性的限制,不能在"),s("code",[t._v("github.com/gone-io/gone")]),t._v("以外的包中实现其内部定义的私有方法;一个结构体要成为Goner,只能通过内嵌"),s("code",[t._v("gone.Flag")]),t._v("才能“继承”私有的方法"),s("code",[t._v("goneFlag()")]),t._v("。这段话可能有些不好理解,其实就是说Goner的实现只能通过内嵌gone.Flag来完成,不能通过实现"),s("code",[t._v("goneFlag()")]),t._v("方法来完成。")])]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("多个"),s("strong",[t._v("Goner")]),t._v(",我们使用其复数形式("),s("strong",[t._v("Goners")]),t._v(")表示。")])]),t._v(" "),s("p",[t._v("在Gone框架中,还包含了三类特殊的Goner,定义如下:")]),t._v(" "),s("h3",{attrs:{id:"🔮prophet-先知"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#🔮prophet-先知"}},[t._v("#")]),t._v(" 🔮Prophet(先知)")]),t._v(" "),s("p",[t._v("一种特殊的 "),s("strong",[t._v("Goner")]),t._v(",在普通 "),s("strong",[t._v("Goner")]),t._v(" 上实现了 "),s("strong",[s("code",[t._v("AfterRevive() AfterReviveError")])]),t._v(" 方法就是 "),s("strong",[t._v("Prophet(先知)")]),t._v(";"),s("strong",[t._v("AfterRevive")]),t._v(" 会在 "),s("strong",[t._v("Goner")]),t._v(" 被复活后被执行。")]),t._v(" "),s("p",[t._v("Prophet接口定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Prophet 先知")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Prophet "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//AfterRevive 在Goner复活后会被执行")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" AfterReviveError\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"😇angel-天使"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#😇angel-天使"}},[t._v("#")]),t._v(" 😇Angel(天使)")]),t._v(" "),s("p",[t._v("一种特殊的 "),s("strong",[t._v("Goner")]),t._v(",拥有天使左翼"),s("code",[t._v("Start(Cemetery) error")]),t._v(" 和 天使右翼"),s("code",[t._v("Stop(Cemetery) error")]),t._v(",左翼负责生(用于分配资源,启动某项服务),右翼负责死(用于终止某项服务,回收资源)。")]),t._v(" "),s("p",[t._v("Angel接口定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Angel "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Start")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Stop")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"🧛🏻‍♀️vampire-吸血鬼"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#🧛🏻‍♀️vampire-吸血鬼"}},[t._v("#")]),t._v(" 🧛🏻‍♀️Vampire(吸血鬼)")]),t._v(" "),s("p",[t._v("一种特殊的 "),s("strong",[t._v("Goner")]),t._v(",拥有特殊能力——吸血"),s("code",[t._v("Suck(conf string, v reflect.Value) SuckError")]),t._v("。"),s("strong",[t._v("Suck")]),t._v("可以将不是"),s("strong",[t._v("Goner")]),t._v("的值赋予注入给Goner属性。")]),t._v(" "),s("p",[t._v("Vampire接口定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SuckError "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Vampire "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tGoner\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Suck")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("conf "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" v reflect"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" SuckError\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"cemetery-墓园"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#cemetery-墓园"}},[t._v("#")]),t._v(" Cemetery(墓园)")]),t._v(" "),s("p",[t._v("Cemetery用于管理Goners,主要提供Bury(埋葬)和 revive(复活)的方法,其接口定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Cemetery "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ... 其他方法")]),t._v("\n\tGoner\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("GonerId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" Cemetery "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 埋葬,将逝者埋葬到墓园")]),t._v("\n\n\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//ReviveAllFromTombs 复活所有Goner")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ReviveAllFromTombs")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("从代码上可以看到Cemetery本身也是一个Goner,在Gone框架启动时他会被自动埋葬和复活。")]),t._v(" "),s("h3",{attrs:{id:"bury-埋葬"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#bury-埋葬"}},[t._v("#")]),t._v(" Bury(埋葬)")]),t._v(" "),s("p",[t._v("将Goner "),s("strong",[t._v("埋葬")]),t._v(" 到 "),s("strong",[t._v("Cemetery")]),t._v(" 就是将Goner注册到框架,以待后续完成属性的注入;在代码实现上,"),s("strong",[t._v("Bury")]),t._v("是"),s("strong",[t._v("Cemetery")]),t._v("上的公开方法,一般在通过 "),s("strong",[t._v("Priest")]),t._v(" 函数调用该方法。")]),t._v(" "),s("h3",{attrs:{id:"revive-复活"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#revive-复活"}},[t._v("#")]),t._v(" Revive(复活)")]),t._v(" "),s("p",[t._v("Revive(复活)指的是Goner所有需要注入的属性完成注入的过程。在函数"),s("code",[t._v("ReviveAllFromTombs() error")]),t._v("中,所有被"),s("strong",[t._v("埋葬")]),t._v("到"),s("strong",[t._v("Cemetery")]),t._v("的Goners都会被尝试复活,如果有属性不能正常注入,程序将panic。")]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[s("strong",[t._v("ReviveAllFromTombs")]),t._v("在完成了复活所有的"),s("strong",[t._v("Goners")]),t._v("后,会调用所有"),s("strong",[t._v("Prophet")]),t._v("的 "),s("strong",[t._v("AfterRevive")]),t._v("方法。")])]),t._v(" "),s("h2",{attrs:{id:"heaven-天国"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#heaven-天国"}},[t._v("#")]),t._v(" Heaven(天国)")]),t._v(" "),s("p",[t._v("Heaven(天国)代表了一个Gone程序,用于管理程序的启动、停止等状态和流程(复活在启动前完成),用于在启动前后以及程序停止前执行一些hook任务。Heaven接收一个牧师函数开始运行,例如:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 调用 cemetery.Bury 埋葬 Goner")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 或者 调用其他 Priest 函数")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// TODO")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("或者:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 调用 cemetery.Bury 埋葬 Goner")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 或者 调用其他 Priest 函数")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// TODO")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//TODO: 启动后执行一些操作")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"priest-牧师"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#priest-牧师"}},[t._v("#")]),t._v(" Priest (牧师)")]),t._v(" "),s("p",[t._v("Priest (牧师)是负责将"),s("strong",[t._v("Goner")]),t._v("埋葬到"),s("strong",[t._v("Cemetery")]),t._v("的函数,他的定义如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Priest "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v("\n")])])]),s("p",[t._v("在"),s("strong",[t._v("Priest")]),t._v("函数实现上,可以调用 "),s("strong",[t._v("cemetery.Bury")]),t._v(" 来完成,如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tName "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tName "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("aPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Jim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"boss-jim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Bob"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"worker-bob"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//匿名埋葬,不指定被埋葬Goner的GonerId")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"X"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),s("p",[t._v("也可以通过调用其他的"),s("strong",[t._v("Priest")]),t._v("函数来完成:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("a1Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("a2Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("aPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("a1Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("a2Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("如果我们开发了一个组件包,其中使用了多个"),s("strong",[t._v("Goners")]),t._v("来完成响应的功能,使用时需要同时"),s("strong",[t._v("埋葬")]),t._v("这些"),s("strong",[t._v("Goners")]),t._v(",那么我们可以编写一个"),s("strong",[t._v("Priest")]),t._v("函数方便业务代码批量"),s("strong",[t._v("埋葬")]),t._v("这些"),s("strong",[t._v("Goners")]),t._v("。")]),t._v(" "),s("p",[t._v("框架内置的组件包,我们就是这样干的,"),s("a",{attrs:{href:"https://github.com/gone-io/gone/blob/main/goner/priest.go",target:"_blank",rel:"noopener noreferrer"}},[t._v("代码"),s("OutboundLink")],1),t._v(" 和 "),s("a",{attrs:{href:"https://goner.fun/zh/goners/#%E6%A1%86%E6%9E%B6%E5%86%85%E7%BD%AEgoners",target:"_blank",rel:"noopener noreferrer"}},[t._v("文档"),s("OutboundLink")],1),t._v("。")]),t._v(" "),s("p",[t._v("另外,我们开发了一个命令行辅助工具"),s("strong",[t._v("gone")]),t._v(",用于扫描特殊注释"),s("code",[t._v("//go:gone")]),t._v("自动生成牧师函数,参考"),s("RouterLink",{attrs:{to:"/zh/guide/auto-gen-priest.html"}},[t._v("自动生成Priest")]),t._v("。")],1)])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/53.e5a4d0a5.js b/assets/js/53.3a1ab83b.js similarity index 99% rename from assets/js/53.e5a4d0a5.js rename to assets/js/53.3a1ab83b.js index d759c20..a470bcb 100644 --- a/assets/js/53.e5a4d0a5.js +++ b/assets/js/53.3a1ab83b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[53],{345:function(t,s,n){"use strict";n.r(s);var e=n(10),a=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"如何优雅使用内置goners"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#如何优雅使用内置goners"}},[t._v("#")]),t._v(" 如何优雅使用内置Goners?")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#内置goners"}},[t._v("内置Goners")])]),s("li",[s("a",{attrs:{href:"#priest-函数"}},[t._v("Priest函数")])]),s("li",[s("a",{attrs:{href:"#如何使用"}},[t._v("如何使用")])]),s("li",[s("a",{attrs:{href:"#内置goner的goneid"}},[t._v("内置Goner的GoneId")])])])]),s("p"),t._v(" "),s("h2",{attrs:{id:"内置goners"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#内置goners"}},[t._v("#")]),t._v(" 内置Goners")]),t._v(" "),s("p",[t._v("为了降低Gone的使用门槛,我们开发了一些"),s("RouterLink",{attrs:{to:"/zh/goners/#框架内置goners"}},[t._v("内置Goners")]),t._v(",用于提供一些基础的功能。")],1),t._v(" "),s("h2",{attrs:{id:"priest函数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#priest函数"}},[t._v("#")]),t._v(" "),s("code",[t._v("Priest")]),t._v("函数")]),t._v(" "),s("p",[t._v("在gone框架内定义了"),s("code",[t._v("Priest")]),t._v("函数,在该函数里可以批量的埋葬用到的Goner;另外"),s("code",[t._v("Priest")]),t._v("函数可以嵌套,即A可以调用B,B可以调用C。那么,在我们开完一组功能后,可以提供一个"),s("code",[t._v("Priest")]),t._v("函数,将用到所有Goner批量埋葬。")]),t._v(" "),s("p",[t._v("实际上,在开发框架内置Goners,我们就采用这样的方式;另外为了方便调用,还在"),s("code",[t._v("goner/priest.go")]),t._v("中定义了一些快捷方式,代码如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" goner\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/logrus"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/redis"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/schedule"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/tracer"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/urllib"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" tracer"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" logrus"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GinPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("XormPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" schedule"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UrllibPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" urllib"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"如何使用"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#如何使用"}},[t._v("#")]),t._v(" 如何使用")]),t._v(" "),s("p",[t._v("这样,我们如果要使用基本的日志、trace、配置功能,我们只需要:")]),t._v(" "),s("ol",[s("li",[s("p",[t._v("在主"),s("code",[t._v("Priest")]),t._v("函数中增加"),s("code",[t._v("gone.BasePriest(cemetery)")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 埋葬与日志、trace和配置相关的Goners")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//调用其他 Priest")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),t._v(" "),s("li",[s("p",[t._v("如果需要打印日志,在需要的Goner上注入")])])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/logrus"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/domain"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemoService")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demoService"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" demoService "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tlogrus"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//具名注入到 嵌套的匿名属性上")]),t._v("\n\n\tlog logrus"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//具名注入到 嵌套的log属性上")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoService"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用继承的方法")]),t._v("\n\tsvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用属性上的方法")]),t._v("\n\tsvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("注入内置组件,应该使用具名注入")])]),t._v(" "),s("h2",{attrs:{id:"内置goner的goneid"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#内置goner的goneid"}},[t._v("#")]),t._v(" 内置Goner的GoneId")]),t._v(" "),s("p",[t._v("内置Goner的GonerId,集中定义在"),s("code",[t._v("https://github.com/gone-io/gone/blob/main/ids.go")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" gone\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Gone框架中的内置组件ID")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneHeaven 天堂组件的ID,代码了程序本身,Gone程序启动时默认注入")]),t._v("\n\tIdGoneHeaven "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-heaven"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneCemetery 坟墓组件的ID,是完成依赖注入的关键组件,Gone程序启动时默认注入")]),t._v("\n\tIdGoneCemetery "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-cemetery"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneTestKit 测试箱,调用 gone.Test 或者 gone.TestAt 时,会将测试箱注入到程序;非测试代码中不应该注入该组件")]),t._v("\n\tIdGoneTestKit "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-test-kit"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 配置、日志、Tracer 一起构成Gone框架的基础Goner,可以使用 [goner.BasePriest](goner#BasePriest) 牧师函数批量安葬")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdConfig 配置 Goner 的ID,提过能配置能力")]),t._v("\n\tIdConfig "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneConfigure 配置器 Goner 的ID")]),t._v("\n\tIdGoneConfigure "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-configure"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneTracer Tracer Goner 的ID,提供日志追踪能力")]),t._v("\n\tIdGoneTracer "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-tracer"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneLogger 日志 Goner 的ID,用于日志打印")]),t._v("\n\tIdGoneLogger "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-logger"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneCumx [cmux Goner](/goner/cmux#Server) ID")]),t._v("\n\tIdGoneCumx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-cumx"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneGin Gin相关的组件ID,可以使用 [goner.GinPriest](goner#GinPriest) 牧师函数批量安葬")]),t._v("\n\tIdGoneGin "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin"')]),t._v("\n\tIdGoneGinRouter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-router"')]),t._v("\n\tIdGoneGinProcessor "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-processor"')]),t._v("\n\tIdGoneGinProxy "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-proxy"')]),t._v("\n\tIdGoneGinResponser "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-responser"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneXorm Xorm Goner 的ID,封装了xorm,用于操作数据库;使用 [goner.XormPriest](goner#XormPriest) 牧师函数安葬")]),t._v("\n\tIdGoneXorm "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-xorm"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneRedisPool redis pool goner; redis 相关 Goner,使用 [goner.RedisPriest](goner#RedisPriest) 牧师函数安葬")]),t._v("\n\tIdGoneRedisPool "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-pool"')]),t._v("\n\tIdGoneRedisCache "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-cache"')]),t._v("\n\tIdGoneRedisKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-key"')]),t._v("\n\tIdGoneRedisLocker "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-locker"')]),t._v("\n\tIdGoneRedisProvider "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-provider"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneSchedule 定时器Goner;使用 [goner.SchedulePriest](goner#SchedulePriest) 牧师函数安葬")]),t._v("\n\tIdGoneSchedule "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-schedule"')]),t._v("\n\n\tIdGoneReq "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-urllib"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[53],{342:function(t,s,n){"use strict";n.r(s);var e=n(10),a=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"如何优雅使用内置goners"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#如何优雅使用内置goners"}},[t._v("#")]),t._v(" 如何优雅使用内置Goners?")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#内置goners"}},[t._v("内置Goners")])]),s("li",[s("a",{attrs:{href:"#priest-函数"}},[t._v("Priest函数")])]),s("li",[s("a",{attrs:{href:"#如何使用"}},[t._v("如何使用")])]),s("li",[s("a",{attrs:{href:"#内置goner的goneid"}},[t._v("内置Goner的GoneId")])])])]),s("p"),t._v(" "),s("h2",{attrs:{id:"内置goners"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#内置goners"}},[t._v("#")]),t._v(" 内置Goners")]),t._v(" "),s("p",[t._v("为了降低Gone的使用门槛,我们开发了一些"),s("RouterLink",{attrs:{to:"/zh/goners/#框架内置goners"}},[t._v("内置Goners")]),t._v(",用于提供一些基础的功能。")],1),t._v(" "),s("h2",{attrs:{id:"priest函数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#priest函数"}},[t._v("#")]),t._v(" "),s("code",[t._v("Priest")]),t._v("函数")]),t._v(" "),s("p",[t._v("在gone框架内定义了"),s("code",[t._v("Priest")]),t._v("函数,在该函数里可以批量的埋葬用到的Goner;另外"),s("code",[t._v("Priest")]),t._v("函数可以嵌套,即A可以调用B,B可以调用C。那么,在我们开完一组功能后,可以提供一个"),s("code",[t._v("Priest")]),t._v("函数,将用到所有Goner批量埋葬。")]),t._v(" "),s("p",[t._v("实际上,在开发框架内置Goners,我们就采用这样的方式;另外为了方便调用,还在"),s("code",[t._v("goner/priest.go")]),t._v("中定义了一些快捷方式,代码如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" goner\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/logrus"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/redis"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/schedule"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/tracer"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/urllib"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" tracer"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" logrus"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GinPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("XormPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" schedule"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UrllibPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" urllib"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"如何使用"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#如何使用"}},[t._v("#")]),t._v(" 如何使用")]),t._v(" "),s("p",[t._v("这样,我们如果要使用基本的日志、trace、配置功能,我们只需要:")]),t._v(" "),s("ol",[s("li",[s("p",[t._v("在主"),s("code",[t._v("Priest")]),t._v("函数中增加"),s("code",[t._v("gone.BasePriest(cemetery)")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 埋葬与日志、trace和配置相关的Goners")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//调用其他 Priest")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),t._v(" "),s("li",[s("p",[t._v("如果需要打印日志,在需要的Goner上注入")])])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" demo\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/logrus"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/domain"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemoService")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demoService"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" demoService "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tlogrus"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//具名注入到 嵌套的匿名属性上")]),t._v("\n\n\tlog logrus"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//具名注入到 嵌套的log属性上")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoService"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用继承的方法")]),t._v("\n\tsvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用属性上的方法")]),t._v("\n\tsvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("注入内置组件,应该使用具名注入")])]),t._v(" "),s("h2",{attrs:{id:"内置goner的goneid"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#内置goner的goneid"}},[t._v("#")]),t._v(" 内置Goner的GoneId")]),t._v(" "),s("p",[t._v("内置Goner的GonerId,集中定义在"),s("code",[t._v("https://github.com/gone-io/gone/blob/main/ids.go")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" gone\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Gone框架中的内置组件ID")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneHeaven 天堂组件的ID,代码了程序本身,Gone程序启动时默认注入")]),t._v("\n\tIdGoneHeaven "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-heaven"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneCemetery 坟墓组件的ID,是完成依赖注入的关键组件,Gone程序启动时默认注入")]),t._v("\n\tIdGoneCemetery "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-cemetery"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneTestKit 测试箱,调用 gone.Test 或者 gone.TestAt 时,会将测试箱注入到程序;非测试代码中不应该注入该组件")]),t._v("\n\tIdGoneTestKit "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-test-kit"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 配置、日志、Tracer 一起构成Gone框架的基础Goner,可以使用 [goner.BasePriest](goner#BasePriest) 牧师函数批量安葬")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdConfig 配置 Goner 的ID,提过能配置能力")]),t._v("\n\tIdConfig "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneConfigure 配置器 Goner 的ID")]),t._v("\n\tIdGoneConfigure "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-configure"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneTracer Tracer Goner 的ID,提供日志追踪能力")]),t._v("\n\tIdGoneTracer "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-tracer"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneLogger 日志 Goner 的ID,用于日志打印")]),t._v("\n\tIdGoneLogger "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-logger"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneCumx [cmux Goner](/goner/cmux#Server) ID")]),t._v("\n\tIdGoneCumx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-cumx"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneGin Gin相关的组件ID,可以使用 [goner.GinPriest](goner#GinPriest) 牧师函数批量安葬")]),t._v("\n\tIdGoneGin "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin"')]),t._v("\n\tIdGoneGinRouter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-router"')]),t._v("\n\tIdGoneGinProcessor "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-processor"')]),t._v("\n\tIdGoneGinProxy "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-proxy"')]),t._v("\n\tIdGoneGinResponser "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gin-responser"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneXorm Xorm Goner 的ID,封装了xorm,用于操作数据库;使用 [goner.XormPriest](goner#XormPriest) 牧师函数安葬")]),t._v("\n\tIdGoneXorm "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-xorm"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//IdGoneRedisPool redis pool goner; redis 相关 Goner,使用 [goner.RedisPriest](goner#RedisPriest) 牧师函数安葬")]),t._v("\n\tIdGoneRedisPool "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-pool"')]),t._v("\n\tIdGoneRedisCache "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-cache"')]),t._v("\n\tIdGoneRedisKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-key"')]),t._v("\n\tIdGoneRedisLocker "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-locker"')]),t._v("\n\tIdGoneRedisProvider "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-redis-provider"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// IdGoneSchedule 定时器Goner;使用 [goner.SchedulePriest](goner#SchedulePriest) 牧师函数安葬")]),t._v("\n\tIdGoneSchedule "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-schedule"')]),t._v("\n\n\tIdGoneReq "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-urllib"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/54.c98cd893.js b/assets/js/54.e66d95f9.js similarity index 99% rename from assets/js/54.c98cd893.js rename to assets/js/54.e66d95f9.js index 496d428..14d0335 100644 --- a/assets/js/54.c98cd893.js +++ b/assets/js/54.e66d95f9.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[54],{351:function(t,s,a){"use strict";a.r(s);var n=a(10),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"日志输出"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#日志输出"}},[t._v("#")]),t._v(" 日志输出")]),t._v(" "),s("p",[t._v("在Gone中,提供了一个内置Goner用于日志输出——"),s("a",{attrs:{href:"github.com/gone-io/gone/tree/main/goner/logrus"}},[t._v("logrus")]),t._v(",是通过将"),s("code",[t._v("github.com/sirupsen/logrus")]),t._v("包封装为Goner实现的。希望有小伙伴封装其他的日志输出包,提供更多的日志解决方法。")]),t._v(" "),s("h2",{attrs:{id:"将相关goners埋葬到cemetery"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#将相关goners埋葬到cemetery"}},[t._v("#")]),t._v(" 将相关Goners埋葬到Cemetery")]),t._v(" "),s("blockquote",[s("p",[t._v("tip: 了解Gone的核心概念和术语请阅读:"),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Gone的核心概念"),s("OutboundLink")],1)])]),t._v(" "),s("p",[t._v("在这里,我们采用"),s("code",[t._v("github.com/gone-io/gone/tree/main/goner")]),t._v("包中的 "),s("strong",[s("code",[t._v("BasePriest")])]),t._v(" 来完成相关Goners的埋葬。在"),s("code",[t._v("BasePriest")]),t._v("中同时被埋葬到Cemetery还包括配置和trace相关的Goners,这三个包一般一起使用。")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//埋葬其他Goners")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"在配置文件中添加相关配置"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#在配置文件中添加相关配置"}},[t._v("#")]),t._v(" 在配置文件中添加相关配置")]),t._v(" "),s("blockquote",[s("p",[t._v("tip: "),s("a",{attrs:{href:"https://goner.fun/zh/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("通过内置Goners支持配置文件"),s("OutboundLink")],1)])]),t._v(" "),s("p",[s("strong",[t._v("支持的配置项")])]),t._v(" "),s("ul",[s("li",[s("p",[t._v("log.level,日志级别,默认为info;支持的级别:")]),t._v(" "),s("ul",[s("li",[t._v("panic")]),t._v(" "),s("li",[t._v("fatal")]),t._v(" "),s("li",[t._v("error")]),t._v(" "),s("li",[t._v("warn 或者 warning")]),t._v(" "),s("li",[t._v("info")]),t._v(" "),s("li",[t._v("debug")]),t._v(" "),s("li",[t._v("trace")])])]),t._v(" "),s("li",[s("p",[t._v("log.report-caller,如果为true日志将打印调用日志输出位置的文件名和行号,例如:")]),t._v(" "),s("p",[t._v("2024-05-11 09:09:57.784|INFO|"),s("strong",[t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46")]),t._v("|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080")])]),t._v(" "),s("li",[s("p",[t._v("log.output,日志输出的位置,默认为stdout(标准输出),支持stderr 和 一个文件路径")]),t._v(" "),s("blockquote",[s("p",[s("strong",[t._v("最佳实践:")]),t._v(" 将应用部署在容器中,日志直接输出到标准输出,由收集组件采集日志,比较成熟的方法比如EFK")])])])]),t._v(" "),s("h2",{attrs:{id:"打印日志"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#打印日志"}},[t._v("#")]),t._v(" 打印日志")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("Info")]),t._v("方法打印日志:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" service "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n log logrus"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//具名注入到 嵌套的log属性上")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("service"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Business")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//打印日志")]),t._v("\n\tsvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),s("p",[t._v("其他级别的日志打印,参考接口代码:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Logger 日志接口")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Logger "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Tracef")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debugf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warnf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warningf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Errorf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatalf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panicf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Trace")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debug")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Print")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warn")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warning")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panic")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Traceln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debugln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infoln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warnln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warningln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Errorln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatalln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panicln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"日志的格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#日志的格式"}},[t._v("#")]),t._v(" 日志的格式")]),t._v(" "),s("p",[s("code",[t._v("${日志输出时间}|${日志级别}|${打印日志的源代码位置}|${TraceId}|${日志内容}")])]),t._v(" "),s("p",[t._v("例如:")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("2024-05-11 09:09:57.784|INFO|**/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46**|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080\n")])])]),s("h2",{attrs:{id:"关于traceid"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#关于traceid"}},[t._v("#")]),t._v(" 关于TraceId")]),t._v(" "),s("p",[t._v("在web应用中,我们希望有一个统一的编号来标识同一请求产生的日志。这个统一的Id,就是TraceId,如果有这个Id,排查问题时,我们只需要使用这个Id搜索日志,就可以获取请求的所有日志。")])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[54],{343:function(t,s,a){"use strict";a.r(s);var n=a(10),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"日志输出"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#日志输出"}},[t._v("#")]),t._v(" 日志输出")]),t._v(" "),s("p",[t._v("在Gone中,提供了一个内置Goner用于日志输出——"),s("a",{attrs:{href:"github.com/gone-io/gone/tree/main/goner/logrus"}},[t._v("logrus")]),t._v(",是通过将"),s("code",[t._v("github.com/sirupsen/logrus")]),t._v("包封装为Goner实现的。希望有小伙伴封装其他的日志输出包,提供更多的日志解决方法。")]),t._v(" "),s("h2",{attrs:{id:"将相关goners埋葬到cemetery"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#将相关goners埋葬到cemetery"}},[t._v("#")]),t._v(" 将相关Goners埋葬到Cemetery")]),t._v(" "),s("blockquote",[s("p",[t._v("tip: 了解Gone的核心概念和术语请阅读:"),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Gone的核心概念"),s("OutboundLink")],1)])]),t._v(" "),s("p",[t._v("在这里,我们采用"),s("code",[t._v("github.com/gone-io/gone/tree/main/goner")]),t._v("包中的 "),s("strong",[s("code",[t._v("BasePriest")])]),t._v(" 来完成相关Goners的埋葬。在"),s("code",[t._v("BasePriest")]),t._v("中同时被埋葬到Cemetery还包括配置和trace相关的Goners,这三个包一般一起使用。")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("MasterPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("BasePriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//埋葬其他Goners")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"在配置文件中添加相关配置"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#在配置文件中添加相关配置"}},[t._v("#")]),t._v(" 在配置文件中添加相关配置")]),t._v(" "),s("blockquote",[s("p",[t._v("tip: "),s("a",{attrs:{href:"https://goner.fun/zh/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("通过内置Goners支持配置文件"),s("OutboundLink")],1)])]),t._v(" "),s("p",[s("strong",[t._v("支持的配置项")])]),t._v(" "),s("ul",[s("li",[s("p",[t._v("log.level,日志级别,默认为info;支持的级别:")]),t._v(" "),s("ul",[s("li",[t._v("panic")]),t._v(" "),s("li",[t._v("fatal")]),t._v(" "),s("li",[t._v("error")]),t._v(" "),s("li",[t._v("warn 或者 warning")]),t._v(" "),s("li",[t._v("info")]),t._v(" "),s("li",[t._v("debug")]),t._v(" "),s("li",[t._v("trace")])])]),t._v(" "),s("li",[s("p",[t._v("log.report-caller,如果为true日志将打印调用日志输出位置的文件名和行号,例如:")]),t._v(" "),s("p",[t._v("2024-05-11 09:09:57.784|INFO|"),s("strong",[t._v("/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46")]),t._v("|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080")])]),t._v(" "),s("li",[s("p",[t._v("log.output,日志输出的位置,默认为stdout(标准输出),支持stderr 和 一个文件路径")]),t._v(" "),s("blockquote",[s("p",[s("strong",[t._v("最佳实践:")]),t._v(" 将应用部署在容器中,日志直接输出到标准输出,由收集组件采集日志,比较成熟的方法比如EFK")])])])]),t._v(" "),s("h2",{attrs:{id:"打印日志"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#打印日志"}},[t._v("#")]),t._v(" 打印日志")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("Info")]),t._v("方法打印日志:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" service "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n log logrus"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Logger "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-logger"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//具名注入到 嵌套的log属性上")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("svc "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("service"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Business")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//打印日志")]),t._v("\n\tsvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("log"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"input content is %s"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" input"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n")])])]),s("p",[t._v("其他级别的日志打印,参考接口代码:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Logger 日志接口")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Logger "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Tracef")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debugf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infof")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warnf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warningf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Errorf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatalf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panicf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("format "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Trace")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debug")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Print")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warn")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warning")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panic")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Traceln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Debugln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Infoln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warnln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Warningln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Errorln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Fatalln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Panicln")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("args "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"日志的格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#日志的格式"}},[t._v("#")]),t._v(" 日志的格式")]),t._v(" "),s("p",[s("code",[t._v("${日志输出时间}|${日志级别}|${打印日志的源代码位置}|${TraceId}|${日志内容}")])]),t._v(" "),s("p",[t._v("例如:")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("2024-05-11 09:09:57.784|INFO|**/Users/jim/go/pkg/mod/github.com/gone-io/gone@v0.1.4/goner/gin/server.go:46**|061ad00f-8c0d-479c-bc4c-393e0cf2cca2|Server Listen At :8080\n")])])]),s("h2",{attrs:{id:"关于traceid"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#关于traceid"}},[t._v("#")]),t._v(" 关于TraceId")]),t._v(" "),s("p",[t._v("在web应用中,我们希望有一个统一的编号来标识同一请求产生的日志。这个统一的Id,就是TraceId,如果有这个Id,排查问题时,我们只需要使用这个Id搜索日志,就可以获取请求的所有日志。")])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/55.3500f1ea.js b/assets/js/55.c864038b.js similarity index 99% rename from assets/js/55.3500f1ea.js rename to assets/js/55.c864038b.js index 344720d..dbd9d62 100644 --- a/assets/js/55.3500f1ea.js +++ b/assets/js/55.c864038b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[55],{342:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"利用redis提供分布式锁和分布式缓存"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#利用redis提供分布式锁和分布式缓存"}},[t._v("#")]),t._v(" 利用redis提供分布式锁和分布式缓存")]),t._v(" "),s("p",[t._v("在本文中,我们将分享在gone中如何使用分布式缓存和分布式锁,其中分布式锁中实现了一种较为自由的处理方式———“智能锁”,对一个处理函数进行上锁,函数执行中会周期性检测锁过期的剩余时间并自动给锁续期,函数执行完后会自动解锁。")]),t._v(" "),s("h2",{attrs:{id:"第一步-将redis相关goner埋葬到cemetery"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#第一步-将redis相关goner埋葬到cemetery"}},[t._v("#")]),t._v(" 第一步:将redis相关Goner埋葬到Cemetery")]),t._v(" "),s("blockquote",[s("p",[t._v("什么是 Goner?\n什么是 埋葬?\n什么是 Cemetery?\n参考 "),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Gone的核心概念"),s("OutboundLink")],1)])]),t._v(" "),s("p",[t._v("在Priest函数中增加"),s("code",[t._v("_ = goner.RedisPriest(cemetery)")]),t._v(",如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.RedisPriest 函数,将 redis 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"第二步-在配置文件中增加redis相关配置"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#第二步-在配置文件中增加redis相关配置"}},[t._v("#")]),t._v(" 第二步:在配置文件中增加redis相关配置")]),t._v(" "),s("p",[t._v("创建配置文件 "),s("code",[t._v("config/default.properties")]),t._v(",内容如下:")]),t._v(" "),s("div",{staticClass:"language-properties extra-class"},[s("pre",{pre:!0,attrs:{class:"language-properties"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# redis服务地址,格式为 `host:port`")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("redis.server")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("localhost:6379")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# redis服务密码,不配置默认为空")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("redis.password")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v("\n")])])]),s("blockquote",[s("p",[t._v("其中,redis服务地址需要改你能访问到的redis服务地址。")])]),t._v(" "),s("p",[t._v("更多配置:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("redis.max-idle")]),t._v(":最大空闲链接数,不配置默认为2")]),t._v(" "),s("li",[s("code",[t._v("redis.max-active")]),t._v(":最大活跃链接数,不配置默认为10")]),t._v(" "),s("li",[s("code",[t._v("redis.db")]),t._v(":使用的db,不配置默认为0")]),t._v(" "),s("li",[s("code",[t._v("redis.cache.prefix")]),t._v(":key前缀,如果设置了,对redis的增删改查都会拼接该前缀,拼接方式"),s("code",[t._v("${prefix}#${key}")]),t._v(";默认为空")])]),t._v(" "),s("blockquote",[s("p",[t._v("关于配置文件,更多参考:"),s("a",{attrs:{href:"https://goner.fun/zh/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("通过内置Goners支持配置文件"),s("OutboundLink")],1)])]),t._v(" "),s("h2",{attrs:{id:"第三步-使用redis"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#第三步-使用redis"}},[t._v("#")]),t._v(" 第三步,使用redis")]),t._v(" "),s("h3",{attrs:{id:"注入接口"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#注入接口"}},[t._v("#")]),t._v(" 注入接口")]),t._v(" "),s("p",[t._v("在需要使用的结构体中注入 接口"),s("code",[t._v("redis.redis.Cache")]),t._v("和 "),s("code",[t._v("redis.Locker")]),t._v(",他们的"),s("code",[t._v("GonerId")]),t._v("分别为:"),s("code",[t._v("gone-redis-cache")]),t._v("和"),s("code",[t._v("gone-redis-locker")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" redisUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcache redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cache "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-cache"`')]),t._v("\n\tlocker redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Locker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-locker"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"使用分布是缓存"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用分布是缓存"}},[t._v("#")]),t._v(" 使用分布是缓存")]),t._v(" "),s("p",[t._v("请看下面代码中的注释:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tkey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-address"')]),t._v("\n\tvalue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/gone-io/gone"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//设置缓存")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Put")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 缓存的key,类型为 `string`")]),t._v("\n\t\tvalue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第二参数为 需要缓存的值,类型为any,可以是任意类型;传入的值会被编码为 `[]byte` 发往redis")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第三个参数为 过期时间,类型为 `time.Duration`;省略,表示不设置过期时间")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取缓存")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" getValue "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 缓存的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二参数为指针,接收获取缓存的值,类型为any,可以是任意类型;从redis获取的值会被解码为传入的指针类型")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"getValue:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("接口上的其他方法:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("Remove(key string) (err error)")]),t._v(":用于删除redis某个key,支持通配符")]),t._v(" "),s("li",[s("code",[t._v("Keys(key string) ([]string, error)")]),t._v(":使用前缀或者通配符查询存在哪些key,⚠️该方法慎用")]),t._v(" "),s("li",[s("code",[t._v("Prefix() string")]),t._v(":获取当前缓存配置的key前缀")])]),t._v(" "),s("h3",{attrs:{id:"使用分布时锁"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用分布时锁"}},[t._v("#")]),t._v(" 使用分布时锁")]),t._v(" "),s("ol",[s("li",[t._v("锁定一段时间")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//尝试获取锁 并 锁定一段时间")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//返回的第一个参数为一个解锁的函数")]),t._v("\n\tunlock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TryLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 锁的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二参数为 锁的过期时间,类型为 `time.Duration`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//操作完后,需要解锁")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unlock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取锁成功后,可以进行业务操作")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("blockquote",[s("p",[t._v("这种方式,使用锁需要保证在锁定的时间内能够执行完所有操作,否则由于锁过期可能会导致问题。")])]),t._v(" "),s("ol",{attrs:{start:"2"}},[s("li",[t._v("锁定一个操作,操作没结束会自动给锁续期,操作结束自动解锁")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockAndDo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 锁的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二个参数为 需要执行的函数,类型为 `func()`,代表一个操作")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取锁成功后,可以进行业务操作")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"do some options"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第三个参数为 锁的过期时间,类型为 `time.Duration`;第一次加锁和后续锁续期都将使用该值")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第四个参数为 锁续期的间隔时间,类型为 `time.Duration`;周期性检查所是否将过期,如果在下个周期内会过期则对锁续期")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("这种方式比较智能,姑且将其称为“智能锁”吧!\n推荐使用这种方式,可以无脑使用,降低使用的心智负担。")]),t._v(" "),s("h2",{attrs:{id:"上面例子完整代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#上面例子完整代码"}},[t._v("#")]),t._v(" 上面例子完整代码")]),t._v(" "),s("p",[t._v("例子的源代码可以在"),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-redis",target:"_blank",rel:"noopener noreferrer"}},[t._v("这里"),s("OutboundLink")],1),t._v("找到")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/redis"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"time"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.RedisPriest 函数,将 redis 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" redisUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcache redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cache "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-cache"`')]),t._v("\n\tlocker redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Locker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-locker"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tkey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-address"')]),t._v("\n\tvalue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/gone-io/gone"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//设置缓存")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Put")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 缓存的key,类型为 `string`")]),t._v("\n\t\tvalue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第二参数为 需要缓存的值,类型为any,可以是任意类型;传入的值会被编码为 `[]byte` 发往redis")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第三个参数为 过期时间,类型为 `time.Duration`;省略,表示不设置过期时间")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取缓存")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" getValue "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 缓存的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二参数为指针,接收获取缓存的值,类型为any,可以是任意类型;从redis获取的值会被解码为传入的指针类型")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"getValue:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockTime")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//尝试获取锁 并 锁定一段时间")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//返回的第一个参数为一个解锁的函数")]),t._v("\n\tunlock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TryLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 锁的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二参数为 锁的过期时间,类型为 `time.Duration`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//操作完后,需要解锁")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unlock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取锁成功后,可以进行业务操作")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockAndDo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 锁的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二个参数为 需要执行的函数,类型为 `func()`,代表一个操作")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取锁成功后,可以进行业务操作")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"do some options"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第三个参数为 锁的过期时间,类型为 `time.Duration`;第一次加锁和后续锁续期都将使用该值")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第四个参数为 锁续期的间隔时间,类型为 `time.Duration`;周期性检查所是否将过期,如果在下个周期内会过期则对锁续期")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockTime")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[55],{344:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"利用redis提供分布式锁和分布式缓存"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#利用redis提供分布式锁和分布式缓存"}},[t._v("#")]),t._v(" 利用redis提供分布式锁和分布式缓存")]),t._v(" "),s("p",[t._v("在本文中,我们将分享在gone中如何使用分布式缓存和分布式锁,其中分布式锁中实现了一种较为自由的处理方式———“智能锁”,对一个处理函数进行上锁,函数执行中会周期性检测锁过期的剩余时间并自动给锁续期,函数执行完后会自动解锁。")]),t._v(" "),s("h2",{attrs:{id:"第一步-将redis相关goner埋葬到cemetery"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#第一步-将redis相关goner埋葬到cemetery"}},[t._v("#")]),t._v(" 第一步:将redis相关Goner埋葬到Cemetery")]),t._v(" "),s("blockquote",[s("p",[t._v("什么是 Goner?\n什么是 埋葬?\n什么是 Cemetery?\n参考 "),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Gone的核心概念"),s("OutboundLink")],1)])]),t._v(" "),s("p",[t._v("在Priest函数中增加"),s("code",[t._v("_ = goner.RedisPriest(cemetery)")]),t._v(",如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.RedisPriest 函数,将 redis 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"第二步-在配置文件中增加redis相关配置"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#第二步-在配置文件中增加redis相关配置"}},[t._v("#")]),t._v(" 第二步:在配置文件中增加redis相关配置")]),t._v(" "),s("p",[t._v("创建配置文件 "),s("code",[t._v("config/default.properties")]),t._v(",内容如下:")]),t._v(" "),s("div",{staticClass:"language-properties extra-class"},[s("pre",{pre:!0,attrs:{class:"language-properties"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# redis服务地址,格式为 `host:port`")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("redis.server")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token value attr-value"}},[t._v("localhost:6379")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# redis服务密码,不配置默认为空")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token key attr-name"}},[t._v("redis.password")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v("\n")])])]),s("blockquote",[s("p",[t._v("其中,redis服务地址需要改你能访问到的redis服务地址。")])]),t._v(" "),s("p",[t._v("更多配置:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("redis.max-idle")]),t._v(":最大空闲链接数,不配置默认为2")]),t._v(" "),s("li",[s("code",[t._v("redis.max-active")]),t._v(":最大活跃链接数,不配置默认为10")]),t._v(" "),s("li",[s("code",[t._v("redis.db")]),t._v(":使用的db,不配置默认为0")]),t._v(" "),s("li",[s("code",[t._v("redis.cache.prefix")]),t._v(":key前缀,如果设置了,对redis的增删改查都会拼接该前缀,拼接方式"),s("code",[t._v("${prefix}#${key}")]),t._v(";默认为空")])]),t._v(" "),s("blockquote",[s("p",[t._v("关于配置文件,更多参考:"),s("a",{attrs:{href:"https://goner.fun/zh/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("通过内置Goners支持配置文件"),s("OutboundLink")],1)])]),t._v(" "),s("h2",{attrs:{id:"第三步-使用redis"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#第三步-使用redis"}},[t._v("#")]),t._v(" 第三步,使用redis")]),t._v(" "),s("h3",{attrs:{id:"注入接口"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#注入接口"}},[t._v("#")]),t._v(" 注入接口")]),t._v(" "),s("p",[t._v("在需要使用的结构体中注入 接口"),s("code",[t._v("redis.redis.Cache")]),t._v("和 "),s("code",[t._v("redis.Locker")]),t._v(",他们的"),s("code",[t._v("GonerId")]),t._v("分别为:"),s("code",[t._v("gone-redis-cache")]),t._v("和"),s("code",[t._v("gone-redis-locker")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" redisUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcache redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cache "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-cache"`')]),t._v("\n\tlocker redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Locker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-locker"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"使用分布是缓存"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用分布是缓存"}},[t._v("#")]),t._v(" 使用分布是缓存")]),t._v(" "),s("p",[t._v("请看下面代码中的注释:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tkey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-address"')]),t._v("\n\tvalue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/gone-io/gone"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//设置缓存")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Put")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 缓存的key,类型为 `string`")]),t._v("\n\t\tvalue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第二参数为 需要缓存的值,类型为any,可以是任意类型;传入的值会被编码为 `[]byte` 发往redis")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第三个参数为 过期时间,类型为 `time.Duration`;省略,表示不设置过期时间")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取缓存")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" getValue "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 缓存的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二参数为指针,接收获取缓存的值,类型为any,可以是任意类型;从redis获取的值会被解码为传入的指针类型")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"getValue:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("接口上的其他方法:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("Remove(key string) (err error)")]),t._v(":用于删除redis某个key,支持通配符")]),t._v(" "),s("li",[s("code",[t._v("Keys(key string) ([]string, error)")]),t._v(":使用前缀或者通配符查询存在哪些key,⚠️该方法慎用")]),t._v(" "),s("li",[s("code",[t._v("Prefix() string")]),t._v(":获取当前缓存配置的key前缀")])]),t._v(" "),s("h3",{attrs:{id:"使用分布时锁"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用分布时锁"}},[t._v("#")]),t._v(" 使用分布时锁")]),t._v(" "),s("ol",[s("li",[t._v("锁定一段时间")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//尝试获取锁 并 锁定一段时间")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//返回的第一个参数为一个解锁的函数")]),t._v("\n\tunlock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TryLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 锁的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二参数为 锁的过期时间,类型为 `time.Duration`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//操作完后,需要解锁")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unlock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取锁成功后,可以进行业务操作")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("blockquote",[s("p",[t._v("这种方式,使用锁需要保证在锁定的时间内能够执行完所有操作,否则由于锁过期可能会导致问题。")])]),t._v(" "),s("ol",{attrs:{start:"2"}},[s("li",[t._v("锁定一个操作,操作没结束会自动给锁续期,操作结束自动解锁")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockAndDo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 锁的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二个参数为 需要执行的函数,类型为 `func()`,代表一个操作")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取锁成功后,可以进行业务操作")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"do some options"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第三个参数为 锁的过期时间,类型为 `time.Duration`;第一次加锁和后续锁续期都将使用该值")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第四个参数为 锁续期的间隔时间,类型为 `time.Duration`;周期性检查所是否将过期,如果在下个周期内会过期则对锁续期")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("这种方式比较智能,姑且将其称为“智能锁”吧!\n推荐使用这种方式,可以无脑使用,降低使用的心智负担。")]),t._v(" "),s("h2",{attrs:{id:"上面例子完整代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#上面例子完整代码"}},[t._v("#")]),t._v(" 上面例子完整代码")]),t._v(" "),s("p",[t._v("例子的源代码可以在"),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-redis",target:"_blank",rel:"noopener noreferrer"}},[t._v("这里"),s("OutboundLink")],1),t._v("找到")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/redis"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"time"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.RedisPriest 函数,将 redis 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("RedisPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" redisUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcache redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cache "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-cache"`')]),t._v("\n\tlocker redis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Locker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-redis-locker"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tkey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-address"')]),t._v("\n\tvalue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/gone-io/gone"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//设置缓存")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Put")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 缓存的key,类型为 `string`")]),t._v("\n\t\tvalue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第二参数为 需要缓存的值,类型为any,可以是任意类型;传入的值会被编码为 `[]byte` 发往redis")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第三个参数为 过期时间,类型为 `time.Duration`;省略,表示不设置过期时间")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取缓存")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" getValue "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tkey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 缓存的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二参数为指针,接收获取缓存的值,类型为any,可以是任意类型;从redis获取的值会被解码为传入的指针类型")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"getValue:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" getValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockTime")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//尝试获取锁 并 锁定一段时间")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//返回的第一个参数为一个解锁的函数")]),t._v("\n\tunlock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TryLock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 锁的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二参数为 锁的过期时间,类型为 `time.Duration`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//操作完后,需要解锁")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unlock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取锁成功后,可以进行业务操作")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlockKey "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-lock-key"')]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("locker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockAndDo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tlockKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第一个参数为 锁的key,类型为 `string`")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第二个参数为 需要执行的函数,类型为 `func()`,代表一个操作")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//获取锁成功后,可以进行业务操作")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"do some options"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第三个参数为 锁的过期时间,类型为 `time.Duration`;第一次加锁和后续锁续期都将使用该值")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("time"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Second"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//第四个参数为 锁续期的间隔时间,类型为 `time.Duration`;周期性检查所是否将过期,如果在下个周期内会过期则对锁续期")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"err:%v"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("redisUser "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("UseCache")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("LockTime")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/56.6625755d.js b/assets/js/56.a43d6a5e.js similarity index 99% rename from assets/js/56.6625755d.js rename to assets/js/56.a43d6a5e.js index 273873b..527c415 100644 --- a/assets/js/56.6625755d.js +++ b/assets/js/56.a43d6a5e.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[56],{344:function(t,n,s){"use strict";s.r(n);var a=s(10),e=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"用cron表达式配置定时任务"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#用cron表达式配置定时任务"}},[t._v("#")]),t._v(" 用cron表达式配置定时任务")]),t._v(" "),n("p",[t._v("定时任务对于Web项目基本上时标配,可以通过Gone的内置组件来实现定时任务,支持"),n("code",[t._v("cron")]),t._v("表达式。在Web项目中代码一般都是多节点运行,我们使用了redis作为分布式锁来保证任务每次执行只在一个节点上进行,所以需要先准备redis服务,关于redis相关内容请参考:"),n("a",{attrs:{href:"https://goner.fun/zh/guide/redis.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("利用redis提供分布式锁和分布式缓存"),n("OutboundLink")],1),t._v("。另外定时任务还可以和框架“配置注入”的特性结合,将cron表达式放到配置文件中,参考"),n("a",{attrs:{href:"https://goner.fun/zh/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("通过内置Goners支持配置文件"),n("OutboundLink")],1),t._v("。")]),t._v(" "),n("h2",{attrs:{id:"将相关goners埋葬到cemetery"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#将相关goners埋葬到cemetery"}},[t._v("#")]),t._v(" 将相关Goners埋葬到Cemetery")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[t._v("\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.SchedulePriest 函数,将 定时任务 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),n("h2",{attrs:{id:"编写定时任务执行的job函数"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#编写定时任务执行的job函数"}},[t._v("#")]),t._v(" 编写定时任务执行的Job函数")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" sch "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("job1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo 定时任务逻辑")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"设置定时任务"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#设置定时任务"}},[t._v("#")]),t._v(" 设置定时任务")]),t._v(" "),n("p",[t._v("实现"),n("code",[t._v("Cron(run schedule.RunFuncOnceAt)")]),t._v(",框架会扫描结构体上的该方法并自动执行,在该方法中设置定时任务。")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Cron")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("run schedule"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("RunFuncOnceAt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 run `RunFuncOnceAt`设置定时任务,")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"*/5 * * * * *"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// cron 表达式,表示每5秒执行一次")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//需要设置一个唯一标识,用于 分布式锁加锁")]),t._v("\n\t\tsch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("job1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 定时任务逻辑")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("完整的demo代码如下:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/schedule"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.SchedulePriest 函数,将 定时任务 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" sch "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("job1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo 定时任务逻辑")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1 execute"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Cron")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("run schedule"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("RunFuncOnceAt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 run `RunFuncOnceAt`设置定时任务,")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"*/5 * * * * *"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// cron 表达式,表示每5秒执行一次")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//需要设置一个唯一标识,用于 分布式锁加锁")]),t._v("\n\t\tsch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("job1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 定时任务逻辑")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Serve")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("上面代码会每隔5s打印:"),n("code",[t._v("job1 execute")]),t._v(",是不是很简单?")]),t._v(" "),n("h2",{attrs:{id:"将定时配置放到配置文件中"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#将定时配置放到配置文件中"}},[t._v("#")]),t._v(" 将定时配置放到配置文件中")]),t._v(" "),n("p",[t._v("将定时配置放到配置文件中,代码上只需要做如下3点修改:")]),t._v(" "),n("ol",[n("li",[t._v("将配置文件支持的相关Goner 埋葬到 Cemetery 中")]),t._v(" "),n("li",[t._v("注入放到配置文件的定时任务配置")]),t._v(" "),n("li",[t._v("使用从配置文件注入的定时配置设置定时任务")])]),t._v(" "),n("p",[t._v("修改后的代码如下:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/schedule"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.SchedulePriest 函数,将 定时任务 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//1.将配置文件支持的相关Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" sch "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcron "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,cron.job1,default=*/5 * * * * *"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//2. 注入放到配置文件的定时任务配置")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("job1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo 定时任务逻辑")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1 execute"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Cron")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("run schedule"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("RunFuncOnceAt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 run `RunFuncOnceAt`设置定时任务,")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tsch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cron"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 3. 使用从配置文件注入的定时配置")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//需要设置一个唯一标识,用于 分布式锁加锁")]),t._v("\n\t\tsch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("job1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 定时任务逻辑")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Serve")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[56],{345:function(t,n,s){"use strict";s.r(n);var a=s(10),e=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"用cron表达式配置定时任务"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#用cron表达式配置定时任务"}},[t._v("#")]),t._v(" 用cron表达式配置定时任务")]),t._v(" "),n("p",[t._v("定时任务对于Web项目基本上时标配,可以通过Gone的内置组件来实现定时任务,支持"),n("code",[t._v("cron")]),t._v("表达式。在Web项目中代码一般都是多节点运行,我们使用了redis作为分布式锁来保证任务每次执行只在一个节点上进行,所以需要先准备redis服务,关于redis相关内容请参考:"),n("a",{attrs:{href:"https://goner.fun/zh/guide/redis.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("利用redis提供分布式锁和分布式缓存"),n("OutboundLink")],1),t._v("。另外定时任务还可以和框架“配置注入”的特性结合,将cron表达式放到配置文件中,参考"),n("a",{attrs:{href:"https://goner.fun/zh/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("通过内置Goners支持配置文件"),n("OutboundLink")],1),t._v("。")]),t._v(" "),n("h2",{attrs:{id:"将相关goners埋葬到cemetery"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#将相关goners埋葬到cemetery"}},[t._v("#")]),t._v(" 将相关Goners埋葬到Cemetery")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[t._v("\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.SchedulePriest 函数,将 定时任务 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),n("h2",{attrs:{id:"编写定时任务执行的job函数"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#编写定时任务执行的job函数"}},[t._v("#")]),t._v(" 编写定时任务执行的Job函数")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" sch "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("job1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo 定时任务逻辑")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"设置定时任务"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#设置定时任务"}},[t._v("#")]),t._v(" 设置定时任务")]),t._v(" "),n("p",[t._v("实现"),n("code",[t._v("Cron(run schedule.RunFuncOnceAt)")]),t._v(",框架会扫描结构体上的该方法并自动执行,在该方法中设置定时任务。")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Cron")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("run schedule"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("RunFuncOnceAt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 run `RunFuncOnceAt`设置定时任务,")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"*/5 * * * * *"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// cron 表达式,表示每5秒执行一次")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//需要设置一个唯一标识,用于 分布式锁加锁")]),t._v("\n\t\tsch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("job1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 定时任务逻辑")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("完整的demo代码如下:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/schedule"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.SchedulePriest 函数,将 定时任务 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" sch "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("job1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo 定时任务逻辑")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1 execute"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Cron")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("run schedule"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("RunFuncOnceAt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 run `RunFuncOnceAt`设置定时任务,")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"*/5 * * * * *"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// cron 表达式,表示每5秒执行一次")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//需要设置一个唯一标识,用于 分布式锁加锁")]),t._v("\n\t\tsch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("job1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 定时任务逻辑")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Serve")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("上面代码会每隔5s打印:"),n("code",[t._v("job1 execute")]),t._v(",是不是很简单?")]),t._v(" "),n("h2",{attrs:{id:"将定时配置放到配置文件中"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#将定时配置放到配置文件中"}},[t._v("#")]),t._v(" 将定时配置放到配置文件中")]),t._v(" "),n("p",[t._v("将定时配置放到配置文件中,代码上只需要做如下3点修改:")]),t._v(" "),n("ol",[n("li",[t._v("将配置文件支持的相关Goner 埋葬到 Cemetery 中")]),t._v(" "),n("li",[t._v("注入放到配置文件的定时任务配置")]),t._v(" "),n("li",[t._v("使用从配置文件注入的定时配置设置定时任务")])]),t._v(" "),n("p",[t._v("修改后的代码如下:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/schedule"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 goner.SchedulePriest 函数,将 定时任务 相关的Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("SchedulePriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//1.将配置文件支持的相关Goner 埋葬到 Cemetery 中")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" sch "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\tcron "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,cron.job1,default=*/5 * * * * *"`')]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//2. 注入放到配置文件的定时任务配置")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("job1")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//todo 定时任务逻辑")]),t._v("\n\tfmt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1 execute"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sch "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("sch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Cron")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("run schedule"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("RunFuncOnceAt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用 run `RunFuncOnceAt`设置定时任务,")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("run")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tsch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("cron"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 3. 使用从配置文件注入的定时配置")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"job1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//需要设置一个唯一标识,用于 分布式锁加锁")]),t._v("\n\t\tsch"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("job1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 定时任务逻辑")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Serve")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/58.ee4ff1db.js b/assets/js/58.c000a904.js similarity index 99% rename from assets/js/58.ee4ff1db.js rename to assets/js/58.c000a904.js index 56d7a1f..2488852 100644 --- a/assets/js/58.ee4ff1db.js +++ b/assets/js/58.c000a904.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[58],{343:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"单元测试"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#单元测试"}},[t._v("#")]),t._v(" 单元测试")]),t._v(" "),s("p",[t._v("在一个依赖注入框架中如何进行单元测试,将依赖项先注入后再测试;如果测试内容和注入内容强相关,可以考虑对相关内容做mock;一种方式是手动将mock后的Goner埋葬到系统,另外一种方式时将已经埋葬的Goner,使用"),s("code",[t._v("cemetery.ReplaceBury")]),t._v("做替换性埋葬。")]),t._v(" "),s("h2",{attrs:{id:"假设我们编写的goner如下"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#假设我们编写的goner如下"}},[t._v("#")]),t._v(" 假设我们编写的Goner如下")]),t._v(" "),s("p",[t._v("文件名:goner.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pointNameA "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example-test-point-a"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pointNameB "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example-test-point-b"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointA")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameA\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointB")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("X"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameB\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Point "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tX "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,example.test.point.a-x"`')]),t._v("\n\tY "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,example.test.point.a-y,default=200"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Line "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tA "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"example-test-point-a"`')]),t._v("\n\tB "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"example-test-point-b"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewLine")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointA")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointB")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewLine")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"我们可以编写测试文件如下"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#我们可以编写测试文件如下"}},[t._v("#")]),t._v(" 我们可以编写测试文件如下:")]),t._v(" "),s("p",[t._v("文件名:goner_test.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test_Line")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config default"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TestAt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("pointNameA"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("point "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("X"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config default"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("line "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("A"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"ReplaceBury"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("line "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("A"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("X"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tMock "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("X"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ReplaceBury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameA"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"使用gomock做mock测试"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用gomock做mock测试"}},[t._v("#")]),t._v(" 使用gomock做mock测试")]),t._v(" "),s("p",[t._v("为了解耦,我们推荐使用接口进行注入;实际上推荐接口注入的另一个原因是,go语言提供了基于接口的mock方案,我们可以将依赖的内容都mock起来。然而使用"),s("code",[t._v("mockgen")]),t._v("生成的mock实现,不是"),s("code",[t._v("Goner")]),t._v(",无法被埋葬,所以也无法注入;为此,我们在辅助工具中提供了解决方案。")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone mock "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${fromGoFile}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outGoFile}")]),t._v("\n")])])]),s("p",[s("code",[t._v("gone mock")]),t._v(" 命令可以在一个"),s("code",[t._v("mockgen")]),t._v("生成的mock对象中增加"),s("code",[t._v("gone.Flag")]),t._v(",让其变成一个Goner,可以进入Cemetery。")]),t._v(" "),s("p",[t._v("一般的使用方法是,在需要mock的接口上加"),s("code",[t._v("//go:generate")]),t._v("注释,让生成过程在"),s("code",[t._v("go generate ./...")]),t._v("命令时自动完成,下面是一个例子:")]),t._v(" "),s("p",[t._v("文件名:i_point.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('//go:generate sh -c "mockgen -package=mock -source=$GOFILE|gone mock -o mock/$GOFILE"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" IPoint "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("上面"),s("code",[t._v('//go:generate sh -c "mockgen -package=mock -source=$GOFILE|gone mock -o mock/$GOFILE"')]),t._v("的作用是,先用mock为该接口生成一个mock对象,然后通过管道传递给"),s("code",[t._v("gone mock")]),t._v("添加"),s("code",[t._v("gone.Flag")]),t._v("标记。")]),t._v(" "),s("blockquote",[s("p",[t._v("注意mockgen工具和gomock包的版本需要保持一致;\n运行下面代码,安装最新版本:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go get github.com/golang/mock/gomock\ngo get github.com/golang/mock/mockgen\n")])])]),s("p",[t._v("需要安装gone辅助工具;安装参考 "),s("a",{attrs:{href:"https://goner.fun/zh/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gone辅助工具"),s("OutboundLink")],1),t._v("。")])]),t._v(" "),s("p",[t._v("好让,我们来试试吧,创建一个空目录并在进入后,将上文件"),s("code",[t._v("i_test.go")]),t._v("创建出来,让后在当前目录运行命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go generate ./"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\n")])])]),s("p",[t._v("可以看到,命令运行完后,将生成文件"),s("code",[t._v("mock/i_point.go")]),t._v("。")]),t._v(" "),s("p",[t._v("下面我们创建一个 "),s("code",[t._v("origin_point.go")]),t._v("文件,内容如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" originPoint "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewOriginPoint")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("o "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("o "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("在创建一个名为"),s("code",[t._v("distance_calculator.go")]),t._v("的文件,内容如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"math"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDistanceCalculator")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("distanceCalculator"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" distanceCalculator "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\toriginPoint IPoint "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("distanceCalculator"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("CalculateDistanceFromOrigin")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\toriginX"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" originY "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" math"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sqrt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("math"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Pow")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("originX"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" math"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Pow")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("originY"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[s("code",[t._v("distanceCalculator")]),t._v(" 的业务是计算"),s("code",[t._v("(x,y int)")]),t._v("到originPoint点的距离,"),s("code",[t._v("originPoint")]),t._v("是依赖注入的;现在我们来编写"),s("code",[t._v("CalculateDistanceFromOrigin")]),t._v("的测试函数如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example/test/mock"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/golang/mock/gomock"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test_distanceCalculator_CalculateDistanceFromOrigin")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//创建mock控制器")]),t._v("\n\tcontroller "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" gomock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewController")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" controller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Finish")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("distanceCalculator"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tdistance "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("CalculateDistanceFromOrigin")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" distance"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//创建mock对象")]),t._v("\n\t\tpoint "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" mock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewMockIPoint")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("controller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tpoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("EXPECT")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tpoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("EXPECT")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//将mock对象埋葬到Cemetery")]),t._v("\n\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//被测试的对象也需要埋葬到Cemetery")]),t._v("\n\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDistanceCalculator")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[58],{347:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"单元测试"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#单元测试"}},[t._v("#")]),t._v(" 单元测试")]),t._v(" "),s("p",[t._v("在一个依赖注入框架中如何进行单元测试,将依赖项先注入后再测试;如果测试内容和注入内容强相关,可以考虑对相关内容做mock;一种方式是手动将mock后的Goner埋葬到系统,另外一种方式时将已经埋葬的Goner,使用"),s("code",[t._v("cemetery.ReplaceBury")]),t._v("做替换性埋葬。")]),t._v(" "),s("h2",{attrs:{id:"假设我们编写的goner如下"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#假设我们编写的goner如下"}},[t._v("#")]),t._v(" 假设我们编写的Goner如下")]),t._v(" "),s("p",[t._v("文件名:goner.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pointNameA "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example-test-point-a"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pointNameB "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example-test-point-b"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointA")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameA\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointB")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("X"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameB\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Point "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tX "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,example.test.point.a-x"`')]),t._v("\n\tY "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,example.test.point.a-y,default=200"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Line "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tA "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"example-test-point-a"`')]),t._v("\n\tB "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"example-test-point-b"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Say")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewLine")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointA")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPointB")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewLine")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"我们可以编写测试文件如下"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#我们可以编写测试文件如下"}},[t._v("#")]),t._v(" 我们可以编写测试文件如下:")]),t._v(" "),s("p",[t._v("文件名:goner_test.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test_Line")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config default"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("TestAt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("pointNameA"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("point "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("X"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config default"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("line "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("A"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"ReplaceBury"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("line "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" line"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("A"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("X"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tMock "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("X"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ReplaceBury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mock")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" pointNameA"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"使用gomock做mock测试"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#使用gomock做mock测试"}},[t._v("#")]),t._v(" 使用gomock做mock测试")]),t._v(" "),s("p",[t._v("为了解耦,我们推荐使用接口进行注入;实际上推荐接口注入的另一个原因是,go语言提供了基于接口的mock方案,我们可以将依赖的内容都mock起来。然而使用"),s("code",[t._v("mockgen")]),t._v("生成的mock实现,不是"),s("code",[t._v("Goner")]),t._v(",无法被埋葬,所以也无法注入;为此,我们在辅助工具中提供了解决方案。")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone mock "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${fromGoFile}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outGoFile}")]),t._v("\n")])])]),s("p",[s("code",[t._v("gone mock")]),t._v(" 命令可以在一个"),s("code",[t._v("mockgen")]),t._v("生成的mock对象中增加"),s("code",[t._v("gone.Flag")]),t._v(",让其变成一个Goner,可以进入Cemetery。")]),t._v(" "),s("p",[t._v("一般的使用方法是,在需要mock的接口上加"),s("code",[t._v("//go:generate")]),t._v("注释,让生成过程在"),s("code",[t._v("go generate ./...")]),t._v("命令时自动完成,下面是一个例子:")]),t._v(" "),s("p",[t._v("文件名:i_point.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('//go:generate sh -c "mockgen -package=mock -source=$GOFILE|gone mock -o mock/$GOFILE"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" IPoint "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("上面"),s("code",[t._v('//go:generate sh -c "mockgen -package=mock -source=$GOFILE|gone mock -o mock/$GOFILE"')]),t._v("的作用是,先用mock为该接口生成一个mock对象,然后通过管道传递给"),s("code",[t._v("gone mock")]),t._v("添加"),s("code",[t._v("gone.Flag")]),t._v("标记。")]),t._v(" "),s("blockquote",[s("p",[t._v("注意mockgen工具和gomock包的版本需要保持一致;\n运行下面代码,安装最新版本:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go get github.com/golang/mock/gomock\ngo get github.com/golang/mock/mockgen\n")])])]),s("p",[t._v("需要安装gone辅助工具;安装参考 "),s("a",{attrs:{href:"https://goner.fun/zh/references/gone-tool.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gone辅助工具"),s("OutboundLink")],1),t._v("。")])]),t._v(" "),s("p",[t._v("好让,我们来试试吧,创建一个空目录并在进入后,将上文件"),s("code",[t._v("i_test.go")]),t._v("创建出来,让后在当前目录运行命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go generate ./"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\n")])])]),s("p",[t._v("可以看到,命令运行完后,将生成文件"),s("code",[t._v("mock/i_point.go")]),t._v("。")]),t._v(" "),s("p",[t._v("下面我们创建一个 "),s("code",[t._v("origin_point.go")]),t._v("文件,内容如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" originPoint "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewOriginPoint")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("o "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("o "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("200")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("在创建一个名为"),s("code",[t._v("distance_calculator.go")]),t._v("的文件,内容如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"math"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDistanceCalculator")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("distanceCalculator"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" distanceCalculator "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\n\toriginPoint IPoint "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("distanceCalculator"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("CalculateDistanceFromOrigin")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("float64")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\toriginX"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" originY "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("originPoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" math"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sqrt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("math"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Pow")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("originX"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" math"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Pow")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("originY"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[s("code",[t._v("distanceCalculator")]),t._v(" 的业务是计算"),s("code",[t._v("(x,y int)")]),t._v("到originPoint点的距离,"),s("code",[t._v("originPoint")]),t._v("是依赖注入的;现在我们来编写"),s("code",[t._v("CalculateDistanceFromOrigin")]),t._v("的测试函数如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" test\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"example/test/mock"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/golang/mock/gomock"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test_distanceCalculator_CalculateDistanceFromOrigin")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//创建mock控制器")]),t._v("\n\tcontroller "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" gomock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewController")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("defer")]),t._v(" controller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Finish")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("distanceCalculator"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tdistance "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("CalculateDistanceFromOrigin")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\tassert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("float64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" distance"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//创建mock对象")]),t._v("\n\t\tpoint "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" mock"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewMockIPoint")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("controller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tpoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("EXPECT")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetX")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tpoint"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("EXPECT")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetY")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//将mock对象埋葬到Cemetery")]),t._v("\n\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("point"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//被测试的对象也需要埋葬到Cemetery")]),t._v("\n\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDistanceCalculator")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/59.24b0be9b.js b/assets/js/59.212d162e.js similarity index 99% rename from assets/js/59.24b0be9b.js rename to assets/js/59.212d162e.js index 1748d9f..7d38f49 100644 --- a/assets/js/59.24b0be9b.js +++ b/assets/js/59.212d162e.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[59],{347:function(t,s,a){"use strict";a.r(s);var n=a(10),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"通过内置goners支持数据库操作"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#通过内置goners支持数据库操作"}},[t._v("#")]),t._v(" 通过内置Goners支持数据库操作")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#以mysql举个例子-源代码在-这里-https-github-com-gone-io-gone-tree-main-example-use-rdb-可以找到"}},[t._v("以Mysql举个例子,源代码在这里可以找到")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-准备mysql服务-可以使用docker-compose快速启动一个mysql服务"}},[t._v("1.准备mysql服务,可以使用docker-compose快速启动一个Mysql服务")])]),s("li",[s("a",{attrs:{href:"#_2-创建mod和配置"}},[t._v("2. 创建mod和配置")])]),s("li",[s("a",{attrs:{href:"#_3-编写代码如下"}},[t._v("3. 编写代码如下:")])]),s("li",[s("a",{attrs:{href:"#_3-运行代码"}},[t._v("3. 运行代码")])])])]),s("li",[s("a",{attrs:{href:"#需要注意的点"}},[t._v("需要注意的点")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-github-com-gone-io-gone-goner-是对-xorm-io-xorm-的封装"}},[t._v("1. github.com/gone-io/gone/goner 是对 xorm.io/xorm 的封装")])]),s("li",[s("a",{attrs:{href:"#_2-通过-gone-xorm-gonerid-注入"}},[t._v("2. 通过gone-xormGonerId注入")])]),s("li",[s("a",{attrs:{href:"#_3-注意导入的包"}},[t._v("3. 注意导入的包")])])])])])]),s("p"),t._v(" "),s("h2",{attrs:{id:"以mysql举个例子-源代码在这里可以找到"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#以mysql举个例子-源代码在这里可以找到"}},[t._v("#")]),t._v(" 以Mysql举个例子,源代码在"),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-rdb",target:"_blank",rel:"noopener noreferrer"}},[t._v("这里"),s("OutboundLink")],1),t._v("可以找到")]),t._v(" "),s("h3",{attrs:{id:"_1-准备mysql服务-可以使用docker-compose快速启动一个mysql服务"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-准备mysql服务-可以使用docker-compose快速启动一个mysql服务"}},[t._v("#")]),t._v(" 1.准备mysql服务,可以使用docker-compose快速启动一个Mysql服务")]),t._v(" "),s("p",[t._v("docker-compose.yaml 内容如下:")]),t._v(" "),s("div",{staticClass:"language-yaml extra-class"},[s("pre",{pre:!0,attrs:{class:"language-yaml"}},[s("code",[s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("version")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3.5"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("services")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("mysql")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("image")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" mysql"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8.3")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("restart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" unless"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v("stopped\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("environment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("MYSQL_ROOT_PASSWORD")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("123456")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("MYSQL_DATABASE")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" demo\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("volumes")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v(" ./data/mysql"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("/var/lib/mysql\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("ports")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3306:3306"')]),t._v("\n")])])]),s("p",[t._v("命令行执行下面代码,启动mysql服务:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("docker-compose")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" docker-compose.yaml up "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v("\n")])])]),s("h3",{attrs:{id:"_2-创建mod和配置"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-创建mod和配置"}},[t._v("#")]),t._v(" 2. 创建mod和配置")]),t._v(" "),s("p",[t._v("执行如下命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" use-rdb\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" use-rdb\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 创建mod")]),t._v("\ngo mod init use-rdb\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 创建数据库配置")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" config\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("cat")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">>")]),t._v(" config/default.properties"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("eof\n\n# 配置使用mysql数据库\ndatabase.driver-name=mysql\n\n#数据源\ndatabase.dsn=root:123456@tcp(localhost:3306)/demo?charset=utf8mb4&loc=Local\neof")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-编写代码如下"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-编写代码如下"}},[t._v("#")]),t._v(" 3. 编写代码如下:")]),t._v(" "),s("p",[t._v("文件名:main.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/go-sql-driver/mysql"')]),t._v(" #📢⚠️需要特别注意,需要引入mysql的驱动\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v(" #📢⚠️需要特别注意,导入的是gone封装的xorm包\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Demo "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tId "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v("\n\tData "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SqlExecutor "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tdb xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("e "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("SqlExecutor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Execute")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 同步表结构")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sync")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("new")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tdemo "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hello gone"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 插入数据")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Insert")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" \n Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"The most Spring programmer-friendly Golang framework, dependency injection, integrates Web. "')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"demo: %v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Demo\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 读取数据")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Find")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"demo records:%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 通过 goner.XormPriest 将xorm相关的Goner埋葬到 cemetery")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("XormPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("SqlExecutor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 在Gone启动完成后执行")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\te SqlExecutor "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Execute")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-运行代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-运行代码"}},[t._v("#")]),t._v(" 3. 运行代码")]),t._v(" "),s("p",[t._v("执行如下命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go mod tidy\ngo run main.go\n")])])]),s("p",[t._v("运行结果如下:")]),t._v(" "),s("div",{staticClass:"language-log extra-class"},[s("div",{staticClass:"highlight-lines"},[s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("div",{staticClass:"highlighted"},[t._v(" ")]),s("div",{staticClass:"highlighted"},[t._v(" ")]),s("br")]),s("pre",{pre:!0,attrs:{class:"language-log"}},[s("code",[s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.767")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("heaven\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("cemetery\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("tracer"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("tracer\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logrus"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logger\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logrus"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logger\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("Use Env"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" local\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build1582606196/b001/exe/config/default.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build1582606196/b001/exe/config/local.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/works/gone-io/gone/example/use-rdb/config/local.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("xorm"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("engine\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive main"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("SqlExecutor\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.769")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/go/pkg/mod/xorm.io/xorm@v1.3.2/log/logger_context.go")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("90")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("PING DATABASE mysql\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.783")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/works/gone-io/gone/cemetery.go")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("307")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("\ndemo"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" hello gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),t._v("\ndemo records"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" hello gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v(" The most Spring programmer"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("friendly Golang framework"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" dependency injection"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" integrates Web"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"需要注意的点"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#需要注意的点"}},[t._v("#")]),t._v(" 需要注意的点")]),t._v(" "),s("h3",{attrs:{id:"_1-github-com-gone-io-gone-goner-是对-xorm-io-xorm-的封装"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-github-com-gone-io-gone-goner-是对-xorm-io-xorm-的封装"}},[t._v("#")]),t._v(" 1. "),s("code",[t._v("github.com/gone-io/gone/goner")]),t._v(" 是对 "),s("code",[t._v("xorm.io/xorm")]),t._v(" 的封装")]),t._v(" "),s("p",[t._v("封装的大概逻辑是:将xorm包装为一个"),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html#%F0%9F%98%87angel-%E5%A4%A9%E4%BD%BF",target:"_blank",rel:"noopener noreferrer"}},[t._v("Angel Goner"),s("OutboundLink")],1),t._v(";在Start方法中完成数据的连接;在Stop方法中关闭数据库连接。使用时不需要导入"),s("code",[t._v("xorm.io/xorm")]),t._v("包,只需要导入"),s("code",[t._v("github.com/gone-io/gone/goner")]),t._v("即可。封装中依赖了"),s("code",[t._v("github.com/gone-io/gone/tree/main/goner/config")]),t._v("来实现配置,在"),s("code",[t._v("goner.XormPriest")]),t._v("函数中已经自动完成了配置相关的Goner的"),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html#bury-%E5%9F%8B%E8%91%AC",target:"_blank",rel:"noopener noreferrer"}},[t._v("埋葬"),s("OutboundLink")],1),t._v("。\n配置文件中支持的配置项:")]),t._v(" "),s("ul",[s("li",[t._v("database.driver-name 驱动的名称,支持 mysql、postgres 等主流数据库,具体可以参考 "),s("a",{attrs:{href:"https://xorm.io/zh/docs/chapter-01/1.engine/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm文档"),s("OutboundLink")],1)]),t._v(" "),s("li",[t._v("database.dsn 数据源,参考 "),s("a",{attrs:{href:"https://xorm.io/zh/docs/chapter-01/1.engine/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm文档"),s("OutboundLink")],1)]),t._v(" "),s("li",[t._v("database.max-idle-count 连接池,最大空闲连接数")]),t._v(" "),s("li",[t._v("database.max-open 连接池,最大连接数")]),t._v(" "),s("li",[t._v("database.max-lifetime 最大生存时间")]),t._v(" "),s("li",[t._v("database.showSql 是否打印执行的SQL")])]),t._v(" "),s("h3",{attrs:{id:"_2-通过gone-xormgonerid注入"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-通过gone-xormgonerid注入"}},[t._v("#")]),t._v(" 2. 通过"),s("code",[t._v("gone-xorm")]),s("strong",[t._v("GonerId")]),t._v("注入")]),t._v(" "),s("p",[t._v("在需要使用xorm引擎的Goner中,使用"),s("code",[t._v('gone:"gone-xorm"')]),t._v("标签注入"),s("code",[t._v("xorm.Engine")]),t._v(",属性可以具名也可以匿名:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" XormUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//具名")]),t._v("\n db xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 或者")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" XormUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//匿名")]),t._v("\n xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("在"),s("code",[t._v("xorm.Engine")]),t._v("中“继承”了"),s("code",[t._v("xorm.io/xorm.EngineInterface")]),t._v("接口,所以"),s("code",[t._v("xorm.Engine")]),t._v("支持"),s("a",{attrs:{href:"https://xorm.io/zh/docs/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm文档"),s("OutboundLink")],1),t._v("中的所有方法。")]),t._v(" "),s("h3",{attrs:{id:"_3-注意导入的包"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-注意导入的包"}},[t._v("#")]),t._v(" 3. 注意导入的包")]),t._v(" "),s("ul",[s("li",[t._v("需要导入数据库的驱动,不同数据库导入不一样:")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/go-sql-driver/mysql"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("ul",[s("li",[t._v("导入的xorm包是:"),s("code",[t._v("github.com/gone-io/gone/goner/xorm")]),t._v(",不是"),s("code",[t._v("xorm.io/xorm")]),t._v(":")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v(" #📢⚠️需要特别注意,导入的是gone封装的xorm包\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[59],{348:function(t,s,a){"use strict";a.r(s);var n=a(10),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"通过内置goners支持数据库操作"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#通过内置goners支持数据库操作"}},[t._v("#")]),t._v(" 通过内置Goners支持数据库操作")]),t._v(" "),s("p"),s("div",{staticClass:"table-of-contents"},[s("ul",[s("li",[s("a",{attrs:{href:"#以mysql举个例子-源代码在-这里-https-github-com-gone-io-gone-tree-main-example-use-rdb-可以找到"}},[t._v("以Mysql举个例子,源代码在这里可以找到")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-准备mysql服务-可以使用docker-compose快速启动一个mysql服务"}},[t._v("1.准备mysql服务,可以使用docker-compose快速启动一个Mysql服务")])]),s("li",[s("a",{attrs:{href:"#_2-创建mod和配置"}},[t._v("2. 创建mod和配置")])]),s("li",[s("a",{attrs:{href:"#_3-编写代码如下"}},[t._v("3. 编写代码如下:")])]),s("li",[s("a",{attrs:{href:"#_3-运行代码"}},[t._v("3. 运行代码")])])])]),s("li",[s("a",{attrs:{href:"#需要注意的点"}},[t._v("需要注意的点")]),s("ul",[s("li",[s("a",{attrs:{href:"#_1-github-com-gone-io-gone-goner-是对-xorm-io-xorm-的封装"}},[t._v("1. github.com/gone-io/gone/goner 是对 xorm.io/xorm 的封装")])]),s("li",[s("a",{attrs:{href:"#_2-通过-gone-xorm-gonerid-注入"}},[t._v("2. 通过gone-xormGonerId注入")])]),s("li",[s("a",{attrs:{href:"#_3-注意导入的包"}},[t._v("3. 注意导入的包")])])])])])]),s("p"),t._v(" "),s("h2",{attrs:{id:"以mysql举个例子-源代码在这里可以找到"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#以mysql举个例子-源代码在这里可以找到"}},[t._v("#")]),t._v(" 以Mysql举个例子,源代码在"),s("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example/use-rdb",target:"_blank",rel:"noopener noreferrer"}},[t._v("这里"),s("OutboundLink")],1),t._v("可以找到")]),t._v(" "),s("h3",{attrs:{id:"_1-准备mysql服务-可以使用docker-compose快速启动一个mysql服务"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-准备mysql服务-可以使用docker-compose快速启动一个mysql服务"}},[t._v("#")]),t._v(" 1.准备mysql服务,可以使用docker-compose快速启动一个Mysql服务")]),t._v(" "),s("p",[t._v("docker-compose.yaml 内容如下:")]),t._v(" "),s("div",{staticClass:"language-yaml extra-class"},[s("pre",{pre:!0,attrs:{class:"language-yaml"}},[s("code",[s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("version")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3.5"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("services")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("mysql")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("image")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" mysql"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8.3")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("restart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" unless"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v("stopped\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("environment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("MYSQL_ROOT_PASSWORD")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("123456")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("MYSQL_DATABASE")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" demo\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("volumes")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v(" ./data/mysql"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("/var/lib/mysql\n "),s("span",{pre:!0,attrs:{class:"token key atrule"}},[t._v("ports")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3306:3306"')]),t._v("\n")])])]),s("p",[t._v("命令行执行下面代码,启动mysql服务:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("docker-compose")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" docker-compose.yaml up "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v("\n")])])]),s("h3",{attrs:{id:"_2-创建mod和配置"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-创建mod和配置"}},[t._v("#")]),t._v(" 2. 创建mod和配置")]),t._v(" "),s("p",[t._v("执行如下命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" use-rdb\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" use-rdb\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 创建mod")]),t._v("\ngo mod init use-rdb\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 创建数据库配置")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("mkdir")]),t._v(" config\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("cat")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">>")]),t._v(" config/default.properties"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("eof\n\n# 配置使用mysql数据库\ndatabase.driver-name=mysql\n\n#数据源\ndatabase.dsn=root:123456@tcp(localhost:3306)/demo?charset=utf8mb4&loc=Local\neof")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-编写代码如下"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-编写代码如下"}},[t._v("#")]),t._v(" 3. 编写代码如下:")]),t._v(" "),s("p",[t._v("文件名:main.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/go-sql-driver/mysql"')]),t._v(" #📢⚠️需要特别注意,需要引入mysql的驱动\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v(" #📢⚠️需要特别注意,导入的是gone封装的xorm包\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Demo "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tId "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int64")]),t._v("\n\tData "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" SqlExecutor "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tdb xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("e "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("SqlExecutor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Execute")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 同步表结构")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Sync")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("new")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tdemo "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hello gone"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 插入数据")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Insert")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" \n Demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("Data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"The most Spring programmer-friendly Golang framework, dependency injection, integrates Web. "')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"demo: %v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" demo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("Demo\n\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 读取数据")]),t._v("\n\terr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("db"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Find")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"demo records:%v\\n"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 通过 goner.XormPriest 将xorm相关的Goner埋葬到 cemetery")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("XormPriest")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("SqlExecutor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 在Gone启动完成后执行")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\te SqlExecutor "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Execute")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h3",{attrs:{id:"_3-运行代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-运行代码"}},[t._v("#")]),t._v(" 3. 运行代码")]),t._v(" "),s("p",[t._v("执行如下命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go mod tidy\ngo run main.go\n")])])]),s("p",[t._v("运行结果如下:")]),t._v(" "),s("div",{staticClass:"language-log extra-class"},[s("div",{staticClass:"highlight-lines"},[s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("br"),s("div",{staticClass:"highlighted"},[t._v(" ")]),s("div",{staticClass:"highlighted"},[t._v(" ")]),s("br")]),s("pre",{pre:!0,attrs:{class:"language-log"}},[s("code",[s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.767")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("heaven\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("cemetery\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("tracer"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("tracer\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logrus"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logger\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logrus"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("logger\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("Use Env"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" local\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build1582606196/b001/exe/config/default.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/var/folders/jv/rn9b7nhs2ls1n1j_lqj005r80000gn/T/go-build1582606196/b001/exe/config/local.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level warning important"}},[t._v("WARNING")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token property"}},[t._v("properties:")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/works/gone-io/gone/example/use-rdb/config/local.properties")]),t._v(" not found"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" skipping\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("propertiesConfigure\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive github"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("com"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("io"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("goner"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("xorm"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("engine\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.768")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Init"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive main"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("SqlExecutor\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.769")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/go/pkg/mod/xorm.io/xorm@v1.3.2/log/logger_context.go")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("90")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("PING DATABASE mysql\n"),s("span",{pre:!0,attrs:{class:"token date number"}},[t._v("2024-05-10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token time number"}},[t._v("16:56:52.783")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token level info keyword"}},[t._v("INFO")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token file-path string"}},[t._v("/Users/jim/works/gone-io/gone/cemetery.go")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("307")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("Revive "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("\ndemo"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" hello gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),t._v("\ndemo records"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" hello gone"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v(" The most Spring programmer"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("friendly Golang framework"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" dependency injection"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" integrates Web"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"需要注意的点"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#需要注意的点"}},[t._v("#")]),t._v(" 需要注意的点")]),t._v(" "),s("h3",{attrs:{id:"_1-github-com-gone-io-gone-goner-是对-xorm-io-xorm-的封装"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-github-com-gone-io-gone-goner-是对-xorm-io-xorm-的封装"}},[t._v("#")]),t._v(" 1. "),s("code",[t._v("github.com/gone-io/gone/goner")]),t._v(" 是对 "),s("code",[t._v("xorm.io/xorm")]),t._v(" 的封装")]),t._v(" "),s("p",[t._v("封装的大概逻辑是:将xorm包装为一个"),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html#%F0%9F%98%87angel-%E5%A4%A9%E4%BD%BF",target:"_blank",rel:"noopener noreferrer"}},[t._v("Angel Goner"),s("OutboundLink")],1),t._v(";在Start方法中完成数据的连接;在Stop方法中关闭数据库连接。使用时不需要导入"),s("code",[t._v("xorm.io/xorm")]),t._v("包,只需要导入"),s("code",[t._v("github.com/gone-io/gone/goner")]),t._v("即可。封装中依赖了"),s("code",[t._v("github.com/gone-io/gone/tree/main/goner/config")]),t._v("来实现配置,在"),s("code",[t._v("goner.XormPriest")]),t._v("函数中已经自动完成了配置相关的Goner的"),s("a",{attrs:{href:"https://goner.fun/zh/guide/core-concept.html#bury-%E5%9F%8B%E8%91%AC",target:"_blank",rel:"noopener noreferrer"}},[t._v("埋葬"),s("OutboundLink")],1),t._v("。\n配置文件中支持的配置项:")]),t._v(" "),s("ul",[s("li",[t._v("database.driver-name 驱动的名称,支持 mysql、postgres 等主流数据库,具体可以参考 "),s("a",{attrs:{href:"https://xorm.io/zh/docs/chapter-01/1.engine/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm文档"),s("OutboundLink")],1)]),t._v(" "),s("li",[t._v("database.dsn 数据源,参考 "),s("a",{attrs:{href:"https://xorm.io/zh/docs/chapter-01/1.engine/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm文档"),s("OutboundLink")],1)]),t._v(" "),s("li",[t._v("database.max-idle-count 连接池,最大空闲连接数")]),t._v(" "),s("li",[t._v("database.max-open 连接池,最大连接数")]),t._v(" "),s("li",[t._v("database.max-lifetime 最大生存时间")]),t._v(" "),s("li",[t._v("database.showSql 是否打印执行的SQL")])]),t._v(" "),s("h3",{attrs:{id:"_2-通过gone-xormgonerid注入"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-通过gone-xormgonerid注入"}},[t._v("#")]),t._v(" 2. 通过"),s("code",[t._v("gone-xorm")]),s("strong",[t._v("GonerId")]),t._v("注入")]),t._v(" "),s("p",[t._v("在需要使用xorm引擎的Goner中,使用"),s("code",[t._v('gone:"gone-xorm"')]),t._v("标签注入"),s("code",[t._v("xorm.Engine")]),t._v(",属性可以具名也可以匿名:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" XormUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//具名")]),t._v("\n db xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 或者")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" XormUser "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//匿名")]),t._v("\n xorm"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Engine "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-xorm"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("在"),s("code",[t._v("xorm.Engine")]),t._v("中“继承”了"),s("code",[t._v("xorm.io/xorm.EngineInterface")]),t._v("接口,所以"),s("code",[t._v("xorm.Engine")]),t._v("支持"),s("a",{attrs:{href:"https://xorm.io/zh/docs/",target:"_blank",rel:"noopener noreferrer"}},[t._v("xorm文档"),s("OutboundLink")],1),t._v("中的所有方法。")]),t._v(" "),s("h3",{attrs:{id:"_3-注意导入的包"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-注意导入的包"}},[t._v("#")]),t._v(" 3. 注意导入的包")]),t._v(" "),s("ul",[s("li",[t._v("需要导入数据库的驱动,不同数据库导入不一样:")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/go-sql-driver/mysql"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("ul",[s("li",[t._v("导入的xorm包是:"),s("code",[t._v("github.com/gone-io/gone/goner/xorm")]),t._v(",不是"),s("code",[t._v("xorm.io/xorm")]),t._v(":")])]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/xorm"')]),t._v(" #📢⚠️需要特别注意,导入的是gone封装的xorm包\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/60.b2299f78.js b/assets/js/60.6d695687.js similarity index 95% rename from assets/js/60.b2299f78.js rename to assets/js/60.6d695687.js index f03e99a..2b39bc8 100644 --- a/assets/js/60.b2299f78.js +++ b/assets/js/60.6d695687.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[60],{348:function(t,r,a){"use strict";a.r(r);var e=a(10),s=Object(e.a)({},(function(){var t=this,r=t._self._c;return r("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[r("h1",{attrs:{id:"快速开始"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#快速开始"}},[t._v("#")]),t._v(" 快速开始")]),t._v(" "),r("h2",{attrs:{id:"创建一个简单的web项目"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#创建一个简单的web项目"}},[t._v("#")]),t._v(" "),r("RouterLink",{attrs:{to:"/zh/quick-start/simple.html"}},[t._v("创建一个简单的Web项目")])],1),t._v(" "),r("h2",{attrs:{id:"创建一个使用mysql做数据库-可以应用到生产环境的项目"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#创建一个使用mysql做数据库-可以应用到生产环境的项目"}},[t._v("#")]),t._v(" "),r("RouterLink",{attrs:{to:"/zh/quick-start/simple.html"}},[t._v("创建一个使用MySql做数据库,可以应用到生产环境的项目")])],1),t._v(" "),r("h2",{attrs:{id:"更多例子"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#更多例子"}},[t._v("#")]),t._v(" "),r("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example",target:"_blank",rel:"noopener noreferrer"}},[t._v("更多例子"),r("OutboundLink")],1)])])}),[],!1,null,null,null);r.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[60],{349:function(t,r,a){"use strict";a.r(r);var e=a(10),s=Object(e.a)({},(function(){var t=this,r=t._self._c;return r("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[r("h1",{attrs:{id:"快速开始"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#快速开始"}},[t._v("#")]),t._v(" 快速开始")]),t._v(" "),r("h2",{attrs:{id:"创建一个简单的web项目"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#创建一个简单的web项目"}},[t._v("#")]),t._v(" "),r("RouterLink",{attrs:{to:"/zh/quick-start/simple.html"}},[t._v("创建一个简单的Web项目")])],1),t._v(" "),r("h2",{attrs:{id:"创建一个使用mysql做数据库-可以应用到生产环境的项目"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#创建一个使用mysql做数据库-可以应用到生产环境的项目"}},[t._v("#")]),t._v(" "),r("RouterLink",{attrs:{to:"/zh/quick-start/simple.html"}},[t._v("创建一个使用MySql做数据库,可以应用到生产环境的项目")])],1),t._v(" "),r("h2",{attrs:{id:"更多例子"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#更多例子"}},[t._v("#")]),t._v(" "),r("a",{attrs:{href:"https://github.com/gone-io/gone/tree/main/example",target:"_blank",rel:"noopener noreferrer"}},[t._v("更多例子"),r("OutboundLink")],1)])])}),[],!1,null,null,null);r.default=s.exports}}]); \ No newline at end of file diff --git a/assets/js/61.ed8050cd.js b/assets/js/61.ed8050cd.js new file mode 100644 index 0000000..8c8fe97 --- /dev/null +++ b/assets/js/61.ed8050cd.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[61],{356:function(t,n,s){"use strict";s.r(n);var a=s(10),e=Object(a.a)({},(function(){var t=this,n=t._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[n("h1",{attrs:{id:"封装一个goner调用gpt"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#封装一个goner调用gpt"}},[t._v("#")]),t._v(" 封装一个Goner调用GPT")]),t._v(" "),n("p",[t._v("下面例子的代码已经开源在:https://github.com/gone-io/gpt;如果需要,可以导入使用:"),n("code",[t._v("go get -u github.com/gone-io/gpt")]),t._v("。")]),t._v(" "),n("h2",{attrs:{id:"定义用于依赖注入的接口"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#定义用于依赖注入的接口"}},[t._v("#")]),t._v(" 定义用于依赖注入的接口")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" ChatGPT "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateCompletion")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tctx context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\trequest openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("CompletionRequest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("response openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("CompletionResponse"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateChatCompletion")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tctx context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\trequest openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatCompletionRequest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("response openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatCompletionResponse"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"实现这个接口并嵌入gone-flag"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#实现这个接口并嵌入gone-flag"}},[t._v("#")]),t._v(" 实现这个接口并嵌入"),n("code",[t._v("gone.Flag")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" chatGPTClient "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\t"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Client\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("上面代码,通过嵌入"),n("code",[t._v("*openai.Client")]),t._v(",实现了"),n("code",[t._v("ChatGPT")]),t._v("接口,同时通过嵌入"),n("code",[t._v("gone.Flag")]),t._v("实现了Goner接口,使得这个结构体可以注入到依赖注入中。")]),t._v(" "),n("h2",{attrs:{id:"设计配置项"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#设计配置项"}},[t._v("#")]),t._v(" 设计配置项")]),t._v(" "),n("ul",[n("li",[n("code",[t._v("openai.base")]),t._v(":配置OpenAI的API地址")]),t._v(" "),n("li",[n("code",[t._v("openai.token")]),t._v(":配置OpenAI的API密钥")])]),t._v(" "),n("p",[t._v("我们希望可以将这两个配置注入到我们实现的"),n("code",[t._v("chatGPTClient")]),t._v("结构体中,如下:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" chatGPTClient "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\t"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Client\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//从配置文件中注入`openai.base`配置项")]),t._v("\n\topenaiBase "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,openai.base"`')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//从配置文件中注入`openai.token`配置项")]),t._v("\n\topenaiToken "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,openai.token"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"使chatgptclient实现接口afterrevive-error函数-称为-先知"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#使chatgptclient实现接口afterrevive-error函数-称为-先知"}},[t._v("#")]),t._v(" 使chatGPTClient实现接口"),n("code",[t._v("AfterRevive() error")]),t._v("函数,称为“先知”")]),t._v(" "),n("p",[n("code",[t._v("AfterRevive")]),t._v("方法会在"),n("code",[t._v("gone")]),t._v("框架初始化时调用,用于初始化"),n("code",[t._v("chatGPTClient")]),t._v("结构体中的"),n("code",[t._v("*openai.Client")]),t._v("字段。")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("chatGPTClient"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tconf "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("DefaultConfig")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("openaiToken"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tconf"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("BaseURL "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("openaiBase\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Client "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewClientWithConfig")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("conf"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("好了,到此我们就基本完成了我们的目标:封装一个Goner用于调用GPT。")]),t._v(" "),n("p",[t._v("但是为了方便用户使用我们还需要做下面工作。")]),t._v(" "),n("h2",{attrs:{id:"方便用户使用"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#方便用户使用"}},[t._v("#")]),t._v(" 方便用户使用")]),t._v(" "),n("ol",[n("li",[n("p",[t._v("定义用于注入的键值,方便用户按GonerId注入\n我们这里定义为:"),n("code",[t._v("gone-gpt")])])]),t._v(" "),n("li",[n("p",[t._v("为了方便用户埋葬这个Goner,我们定义一个开放的New函数")])])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewChatGPTClient returns a new Goner which is ChatGPT client.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewChatGPTClient")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("chatGPTClient"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gpt"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("ol",{attrs:{start:"3"}},[n("li",[t._v("前面我们用到了配置注入,我们实际上依赖了Gone框架中的配置模块,我们希望用户在埋葬我们定义chatGPTClient时能顺便将配置相关的Goner也埋葬了,所以我们再定义一个Priest函数,如下:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Priest 用于埋葬chatGPTClient和其依赖的Goner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用config.Priest来埋葬Gone配置模块相关的Goner")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//埋葬chatGPTClient")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewChatGPTClient")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"完整的疯转代码如下"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#完整的疯转代码如下"}},[t._v("#")]),t._v(" 完整的疯转代码如下")]),t._v(" "),n("p",[t._v("文件名:gpt.go")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" gpt\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"context"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/config"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/sashabaranov/go-openai"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" ChatGPT "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateCompletion")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tctx context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\trequest openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("CompletionRequest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("response openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("CompletionResponse"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateChatCompletion")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t\tctx context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\trequest openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatCompletionRequest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("response openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatCompletionResponse"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// NewChatGPTClient returns a new Goner which is ChatGPT client.")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewChatGPTClient")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("chatGPTClient"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"gone-gpt"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Priest 用于埋葬chatGPTClient和其依赖的Goner")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//使用config.Priest来埋葬Gone配置模块相关的Goner")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("_")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" config"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Priest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//埋葬chatGPTClient")]),t._v("\n\tcemetery"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewChatGPTClient")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" chatGPTClient "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\t"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Client\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//从配置文件中注入`openai.base`配置项")]),t._v("\n\topenaiBase "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,openai.base"`')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//从配置文件中注入`openai.token`配置项")]),t._v("\n\topenaiToken "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"config,openai.token"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("chatGPTClient"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tconf "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("DefaultConfig")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("openaiToken"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tconf"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("BaseURL "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" g"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("openaiBase\n\tg"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Client "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewClientWithConfig")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("conf"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("h2",{attrs:{id:"编写测试"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#编写测试"}},[t._v("#")]),t._v(" 编写测试")]),t._v(" "),n("p",[t._v("建立测试文件: "),n("code",[t._v("gpt_test.go")]),t._v("\n内容如下:")]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" gpt\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/stretchr/testify/assert"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"testing"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("TestPriest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("testing"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("T"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gpt "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("chatGPTClient"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tassert"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("NotNil")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gpt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Client"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" Priest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),n("p",[t._v("实际上,我们的封装只是做了对openai.Client的初始化,我们只需要测试配置是否正确即可。")]),t._v(" "),n("h2",{attrs:{id:"使用和编写示例"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#使用和编写示例"}},[t._v("#")]),t._v(" 使用和编写示例")]),t._v(" "),n("ol",[n("li",[t._v("在配置文件中,写入配置项,参考"),n("a",{attrs:{href:"https://goner.fun/zh/guide/config.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("通过内置Goners支持配置文件"),n("OutboundLink")],1)]),t._v(" "),n("li",[t._v("在需要使用的结构体中注入ChatGPT并调用相关接口,代码示例如下:")])]),t._v(" "),n("div",{staticClass:"language-go extra-class"},[n("pre",{pre:!0,attrs:{class:"language-go"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" example\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"context"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gpt"')]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/sashabaranov/go-openai"')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Chat "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tgPT gpt"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatGPT "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-gpt"`')]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Chat"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("Use")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ask "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tresponse"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" c"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("gPT"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("CreateChatCompletion")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("context"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("TODO")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatCompletionRequest"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tModel"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GPT3Dot5Turbo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\tMessages"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatCompletionMessage"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tRole"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatMessageRoleSystem"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t\t\tContent"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"you are a helpful chatbot"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tRole"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" openai"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChatMessageRoleUser"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t\t\tContent"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" ask"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" err\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("println")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("response"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Choices"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Message"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Content"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);n.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/61.33bf0752.js b/assets/js/62.e74f2329.js similarity index 99% rename from assets/js/61.33bf0752.js rename to assets/js/62.e74f2329.js index b2138ff..6cdbc5c 100644 --- a/assets/js/61.33bf0752.js +++ b/assets/js/62.e74f2329.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[61],{353:function(t,s,a){"use strict";a.r(s);var e=a(10),r=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"jwt-mysql-redis-schedule"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#jwt-mysql-redis-schedule"}},[t._v("#")]),t._v(" JWT + MySQL + Redis + Schedule")]),t._v(" "),s("p",[t._v("在本章节中,我们将在"),s("a",{attrs:{href:"https://goner.fun/zh/quick-start/mysql.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("上一个例子"),s("OutboundLink")],1),t._v("的基础上增加:使用JWT鉴权,Redis做缓存,集成定时任务的Web项目。")]),t._v(" "),s("h2",{attrs:{id:"业务和接口说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#业务和接口说明"}},[t._v("#")]),t._v(" 业务和接口说明")]),t._v(" "),s("p",[t._v("在这个例子中,我们将实现如下功能和接口:")]),t._v(" "),s("ol",[s("li",[t._v("我们将用户分为管理员和普通用户两种角色,管理员可以管理用户,普通用户只能查看自己的信息。")])]),t._v(" "),s("p",[t._v("下面是普通用户的接口:")]),t._v(" "),s("ul",[s("li",[s("p",[t._v("用户注册接口")]),t._v(" "),s("ul",[s("li",[t._v("请求")])]),t._v(" "),s("div",{staticClass:"language-http extra-class"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[s("span",{pre:!0,attrs:{class:"token request-line"}},[s("span",{pre:!0,attrs:{class:"token method property"}},[t._v("POST")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token request-target url"}},[t._v("/api/users/register")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token http-version property"}},[t._v("HTTP/1.1")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("application/json")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token application-json"}},[t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string-property property"}},[t._v('"username"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string-property property"}},[t._v('"password"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"123456"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string-property property"}},[t._v('"email"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin@goner.fun"')]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string-property property"}},[t._v('"verifyCode"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"123456"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),s("ul",[s("li",[t._v("应答\n"),s("ul",[s("li",[t._v("状态码:200")]),t._v(" "),s("li",[t._v("返回内容"),s("div",{staticClass:"language-json extra-class"},[s("pre",{pre:!0,attrs:{class:"language-json"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"code"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"data"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"id"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])])])])]),t._v(" "),s("li",[s("p",[t._v("用户登录接口")]),t._v(" "),s("div",{staticClass:"language-http extra-class"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[s("span",{pre:!0,attrs:{class:"token request-line"}},[s("span",{pre:!0,attrs:{class:"token method property"}},[t._v("POST")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token request-target url"}},[t._v("/api/users/login")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token http-version property"}},[t._v("HTTP/1.1")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("application/json")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token application-json"}},[t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"username"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"password"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"123456"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])]),t._v(" "),s("li",[s("p",[t._v("获取当前用户信息接口")]),t._v(" "),s("div",{staticClass:"language-http extra-class"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[s("span",{pre:!0,attrs:{class:"token request-line"}},[s("span",{pre:!0,attrs:{class:"token method property"}},[t._v("GET")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token request-target url"}},[t._v("/api/users/info")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token http-version property"}},[t._v("HTTP/1.1")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Authorization")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("Bearer ")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("application/json")])]),t._v("\n")])])])]),t._v(" "),s("li",[s("p",[t._v("修改当前用户信息接口")]),t._v(" "),s("div",{staticClass:"language-http extra-class"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[s("span",{pre:!0,attrs:{class:"token request-line"}},[s("span",{pre:!0,attrs:{class:"token method property"}},[t._v("PUT")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token request-target url"}},[t._v("/api/users/info")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token http-version property"}},[t._v("HTTP/1.1")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Authorization")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("Bearer ")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("application/json")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token application-json"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"username"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"email"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin@goner.fun"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])])])])])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[62],{350:function(t,s,a){"use strict";a.r(s);var e=a(10),r=Object(e.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"jwt-mysql-redis-schedule"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#jwt-mysql-redis-schedule"}},[t._v("#")]),t._v(" JWT + MySQL + Redis + Schedule")]),t._v(" "),s("p",[t._v("在本章节中,我们将在"),s("a",{attrs:{href:"https://goner.fun/zh/quick-start/mysql.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("上一个例子"),s("OutboundLink")],1),t._v("的基础上增加:使用JWT鉴权,Redis做缓存,集成定时任务的Web项目。")]),t._v(" "),s("h2",{attrs:{id:"业务和接口说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#业务和接口说明"}},[t._v("#")]),t._v(" 业务和接口说明")]),t._v(" "),s("p",[t._v("在这个例子中,我们将实现如下功能和接口:")]),t._v(" "),s("ol",[s("li",[t._v("我们将用户分为管理员和普通用户两种角色,管理员可以管理用户,普通用户只能查看自己的信息。")])]),t._v(" "),s("p",[t._v("下面是普通用户的接口:")]),t._v(" "),s("ul",[s("li",[s("p",[t._v("用户注册接口")]),t._v(" "),s("ul",[s("li",[t._v("请求")])]),t._v(" "),s("div",{staticClass:"language-http extra-class"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[s("span",{pre:!0,attrs:{class:"token request-line"}},[s("span",{pre:!0,attrs:{class:"token method property"}},[t._v("POST")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token request-target url"}},[t._v("/api/users/register")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token http-version property"}},[t._v("HTTP/1.1")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("application/json")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token application-json"}},[t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string-property property"}},[t._v('"username"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string-property property"}},[t._v('"password"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"123456"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string-property property"}},[t._v('"email"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin@goner.fun"')]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string-property property"}},[t._v('"verifyCode"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"123456"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])]),s("ul",[s("li",[t._v("应答\n"),s("ul",[s("li",[t._v("状态码:200")]),t._v(" "),s("li",[t._v("返回内容"),s("div",{staticClass:"language-json extra-class"},[s("pre",{pre:!0,attrs:{class:"language-json"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"code"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"data"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"id"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])])])])]),t._v(" "),s("li",[s("p",[t._v("用户登录接口")]),t._v(" "),s("div",{staticClass:"language-http extra-class"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[s("span",{pre:!0,attrs:{class:"token request-line"}},[s("span",{pre:!0,attrs:{class:"token method property"}},[t._v("POST")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token request-target url"}},[t._v("/api/users/login")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token http-version property"}},[t._v("HTTP/1.1")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("application/json")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token application-json"}},[t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"username"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"password"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"123456"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])]),t._v(" "),s("li",[s("p",[t._v("获取当前用户信息接口")]),t._v(" "),s("div",{staticClass:"language-http extra-class"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[s("span",{pre:!0,attrs:{class:"token request-line"}},[s("span",{pre:!0,attrs:{class:"token method property"}},[t._v("GET")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token request-target url"}},[t._v("/api/users/info")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token http-version property"}},[t._v("HTTP/1.1")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Authorization")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("Bearer ")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("application/json")])]),t._v("\n")])])])]),t._v(" "),s("li",[s("p",[t._v("修改当前用户信息接口")]),t._v(" "),s("div",{staticClass:"language-http extra-class"},[s("pre",{pre:!0,attrs:{class:"language-http"}},[s("code",[s("span",{pre:!0,attrs:{class:"token request-line"}},[s("span",{pre:!0,attrs:{class:"token method property"}},[t._v("PUT")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token request-target url"}},[t._v("/api/users/info")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token http-version property"}},[t._v("HTTP/1.1")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Authorization")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("Bearer ")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token header"}},[s("span",{pre:!0,attrs:{class:"token header-name keyword"}},[t._v("Content-Type")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token header-value"}},[t._v("application/json")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token application-json"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"username"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token property"}},[t._v('"email"')]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"admin@goner.fun"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])])])])])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/62.4643b7af.js b/assets/js/63.319ab042.js similarity index 99% rename from assets/js/62.4643b7af.js rename to assets/js/63.319ab042.js index a042930..efc4033 100644 --- a/assets/js/62.4643b7af.js +++ b/assets/js/63.319ab042.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[62],{349:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"一个极简例子"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#一个极简例子"}},[t._v("#")]),t._v(" 一个极简例子")]),t._v(" "),s("p",[t._v("代码如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner标志,匿名内嵌`gone.Flag`表示该结构体为一个Goner")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("w "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Do")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"worker do"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner标志,匿名内嵌`gone.Flag`表示该结构体为一个Goner")]),t._v("\n\n\tseller "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入Worker")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("b "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Do")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"boss do"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tb"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("seller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Do")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//AfterStart 是一个hook函数,关于hook函数请参考文档:https://goner.fun/zh/guide/hooks.html")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tboss "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Boss "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入Boss")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Do")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("在这个例子中,在Gone的准备阶段,通过"),s("a",{attrs:{href:"http://localhost:8080/zh/guide/core-concept.html#bury-%E5%9F%8B%E8%91%AC",target:"_blank",rel:"noopener noreferrer"}},[s("strong",[t._v("埋葬")]),s("OutboundLink")],1),t._v("的方式将 Boss 和 Worker 导入到框架。在框架启动后,老板开始工作"),s("code",[t._v("in.boss.Do()")]),t._v(";老板工作中调用销售开始工作"),s("code",[t._v("b.seller.Do()")]),t._v("。")])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[63],{351:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"一个极简例子"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#一个极简例子"}},[t._v("#")]),t._v(" 一个极简例子")]),t._v(" "),s("p",[t._v("代码如下:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" main\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"fmt"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Worker "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner标志,匿名内嵌`gone.Flag`表示该结构体为一个Goner")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("w "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Do")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"worker do"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Boss "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Goner标志,匿名内嵌`gone.Flag`表示该结构体为一个Goner")]),t._v("\n\n\tseller "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Worker "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入Worker")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("b "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Do")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tfmt"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"boss do"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tb"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("seller"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Do")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Prepare")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cemetery gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Cemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcemetery"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bury")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("Worker"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//AfterStart 是一个hook函数,关于hook函数请参考文档:https://goner.fun/zh/guide/hooks.html")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tboss "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("Boss "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入Boss")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("boss"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Do")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Run")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("在这个例子中,在Gone的准备阶段,通过"),s("a",{attrs:{href:"http://localhost:8080/zh/guide/core-concept.html#bury-%E5%9F%8B%E8%91%AC",target:"_blank",rel:"noopener noreferrer"}},[s("strong",[t._v("埋葬")]),s("OutboundLink")],1),t._v("的方式将 Boss 和 Worker 导入到框架。在框架启动后,老板开始工作"),s("code",[t._v("in.boss.Do()")]),t._v(";老板工作中调用销售开始工作"),s("code",[t._v("b.seller.Do()")]),t._v("。")])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/63.b5e58410.js b/assets/js/64.2552e43b.js similarity index 99% rename from assets/js/63.b5e58410.js rename to assets/js/64.2552e43b.js index 6a495f6..25bbcd6 100644 --- a/assets/js/63.b5e58410.js +++ b/assets/js/64.2552e43b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[63],{352:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"web-项目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#web-项目"}},[t._v("#")]),t._v(" Web 项目")]),t._v(" "),s("h2",{attrs:{id:"安装gone辅助工具"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#安装gone辅助工具"}},[t._v("#")]),t._v(" 安装gone辅助工具")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),s("blockquote",[s("p",[t._v("安装可以使用gone命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v("\n")])])]),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("\t➜ demo gone "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v("\n\tNAME:\n\tgone - A new cli application\n\n\tUSAGE:\n\tgone "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("global options"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("command")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("command options"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("arguments"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n\tDESCRIPTION:\n\tgenerate gone code or generate gone app\n\n\tCOMMANDS:\n\tpriest "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-s")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${scanPackageDir}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-p")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${pkgName}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${funcName}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outputFilePath}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-w"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\tmock "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${fromGoFile}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outGoFile}")]),t._v("\n\tcreate "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-t "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${template}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-m "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${modName}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${appName}")]),t._v("\n\thelp, h Shows a list of commands or "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("help")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" one "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("command")]),t._v("\n\n\tGLOBAL OPTIONS:\n\t--help, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v(" show "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("help")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("default: "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("p",[t._v("支持的功能:")]),t._v(" "),s("ol",[s("li",[t._v("create,创建一个gone app,暂时只支持创建web app")]),t._v(" "),s("li",[t._v("priest,为项目自动生成 "),s("strong",[t._v("Priest")]),t._v(" 函数,"),s("RouterLink",{attrs:{to:"/zh/"}},[t._v("了解更多")])],1),t._v(" "),s("li",[t._v("生成用于测试的mock代码")])])]),t._v(" "),s("h2",{attrs:{id:"创建一个web项目并运行代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#创建一个web项目并运行代码"}},[t._v("#")]),t._v(" 创建一个web项目并运行代码")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 创将一个名为 web-app 的项目")]),t._v("\ngone create web-app\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" web-app\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n")])])]),s("h2",{attrs:{id:"项目结构"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#项目结构"}},[t._v("#")]),t._v(" 项目结构")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("➜ xxx tree\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(".")]),t._v("\n├── Dockerfile\n├── Makefile\n├── README.md\n├── cmd\n│ └── server\n│ └── main.go\n├── config\n│ ├── default.properties\n│ ├── dev.properties\n│ ├── local.properties\n│ └── prod.properties\n├── docker-compose.yaml\n├── go.mod\n├── internal\n│ ├── controller\n│ │ └── demo_ctr.go\n│ ├── interface\n│ │ ├── domain\n│ │ │ ├── demo.go\n│ │ │ └── user.go\n│ │ └── "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v("\n│ │ └── i_demo.go\n│ ├── master.go\n│ ├── middleware\n│ │ ├── authorize.go\n│ │ └── pub.go\n│ ├── module\n│ │ └── demo\n│ │ ├── demo_svc.go\n│ │ └── error.go\n│ ├── pkg\n│ │ └── utils\n│ │ └── error.go\n│ └── router\n│ ├── auth_router.go\n│ └── pub_router.go\n└── tests\n └── api\n └── demo.http\n\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" directories, "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("23")]),t._v(" files\n")])])]),s("ul",[s("li",[t._v("cmd/server/main.go: 启动文件,main函数所在文件")]),t._v(" "),s("li",[t._v("config/: 项目配置文件目录,支持"),s("code",[t._v(".properties")]),t._v("文件")]),t._v(" "),s("li",[t._v("internal/router/: 在该目录定义路由器")]),t._v(" "),s("li",[t._v("internal/middleware/: 中间件目录,如果需要定义web中间件,在该目录编写")]),t._v(" "),s("li",[t._v("internal/controller/: controller目录,在该目录中的文件定义路由")]),t._v(" "),s("li",[t._v("internal/interface/service/: 该目录放服务的接口定义")]),t._v(" "),s("li",[t._v("internal/domain/: 该目录放领域对象")]),t._v(" "),s("li",[t._v("internal/entity/: 该目录放一些无逻辑的结构体,类似于Java 的POJO")]),t._v(" "),s("li",[t._v("internal/module/: 模块目录,下面的每一个子目录实现一个模块的功能,一般是internal/interface/service/中定义的服务的业务实现;")]),t._v(" "),s("li",[t._v("internal/pkg/: 在该目录可以放一些项目共用的工具代码")]),t._v(" "),s("li",[t._v("internal/master.go: 存放"),s("strong",[t._v("MasterPriest")]),t._v("函数")]),t._v(" "),s("li",[t._v("internal/priest.go: gone priest 命令生成的 "),s("strong",[t._v("Priest")]),t._v("函数,用于"),s("strong",[t._v("埋葬")]),t._v("所有Goner")])]),t._v(" "),s("h2",{attrs:{id:"router"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#router"}},[t._v("#")]),t._v(" Router")]),t._v(" "),s("p",[t._v("在目录"),s("code",[t._v("internal/router")]),t._v("中分别实现了两个"),s("code",[t._v("gin.IRouter")]),t._v(":")]),t._v(" "),s("ul",[s("li",[t._v("pubRouter,公开的路由,挂载在该路由下的接口,请求将无需授权即可访问。")]),t._v(" "),s("li",[t._v("authRouter,鉴权的路由,挂载在该路由下的接口,请求必须先要经过授权。")])]),t._v(" "),s("p",[t._v("我们来分析"),s("code",[t._v("internal/router/pub_router.go")]),t._v("的代码:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" router\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/middleware"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" IdRouterPub "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"router-pub"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPubRouter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("pubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" IdRouterPub\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" pubRouter "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tgin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter\n\troot gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-gin-router"`')]),t._v("\n\tpub "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("middleware"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("PubMiddleware "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("pubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/api"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pub"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Next"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ol",[s("li",[t._v("对于router,需要实现了"),s("code",[t._v("gin.IRouter")]),t._v("接口中定义的方法;")]),t._v(" "),s("li",[t._v("结构体"),s("code",[t._v("pubRouter")]),t._v("内嵌了一个"),s("code",[t._v("gin.IRouter")]),t._v(",就等于直接实现了"),s("code",[t._v("gin.IRouter")]),t._v("接口,只在"),s("code",[t._v("AfterRevive()")]),t._v("中将其赋予一个值就可以了;")]),t._v(" "),s("li",[s("code",[t._v('r.IRouter = r.root.Group("/api", r.pub.Next)')]),t._v("意思是当前路由是根路由下"),s("code",[t._v("/api")]),t._v("的子路由,并且默认的增加了一个中间"),s("code",[t._v("r.pub.Next")]),t._v(";")]),t._v(" "),s("li",[s("code",[t._v("root gin.IRouter")]),t._v("是一个Gone框架中"),s("code",[t._v("github.com/gone-io/gone/goner/gin")]),t._v("包提供的一个框架级Goner,具名注入的"),s("code",[t._v("gone-gin-router")]),t._v("。")])]),t._v(" "),s("h2",{attrs:{id:"controller"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#controller"}},[t._v("#")]),t._v(" Controller")]),t._v(" "),s("p",[t._v("下面是Controller接口的定义:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Controller 控制器接口,由业务代码编码实现,用于挂载和处理路由")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 使用方式参考 [示例代码](https://gitlab.openviewtech.com/gone/gone-example/-/tree/master/gone-app)")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Controller "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Mount 路由挂载接口,改接口会在服务启动前被调用,该函数的实现通常情况应该返回`nil`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" MountError\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("编写http接口,我们需要实现"),s("code",[t._v("Controller")]),t._v("接口,在"),s("code",[t._v("Mount")]),t._v("方法中实现接口路由的挂载,如"),s("code",[t._v("internal/controller/demo_ctr.go")]),t._v("的代码:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" controller\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/service"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/pkg/utils"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemoController")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" demoController "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tdemoSvc service"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IDemo "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入依赖的服务")]),t._v("\n\n\tauthRouter gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"router-auth"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入路由器")]),t._v("\n\tpubRouter gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"router-pub"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入路由器")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("MountError "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//需要鉴权的路由分组")]),t._v("\n\tctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tauthRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/demo"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/show"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("showDemo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//不需要鉴权的路由分组")]),t._v("\n\tctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tpubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/demo2"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/show"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("showDemo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/error"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/echo"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("echo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("showDemo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Show")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("echo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Req "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tEcho "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`form:"echo"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" req Req\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bind")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewParameterError")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" utils"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ParameterParseError"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Echo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"service"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#service"}},[t._v("#")]),t._v(" Service")]),t._v(" "),s("p",[t._v("规范上,我们要求将服务的接口定义在"),s("code",[t._v("internal/interface/service")]),t._v("目录,文件名以"),s("code",[t._v("i_")]),t._v("打头,接口类型以"),s("code",[t._v("I")]),t._v("打头,例如:\n文件:i_demo.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" service\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/domain"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" IDemo "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Show")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("DemoEntity"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("服务的逻辑实现,放到"),s("code",[t._v("internal/module")]),t._v("目录分模块实现。")]),t._v(" "),s("h2",{attrs:{id:"数据库操作"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#数据库操作"}},[t._v("#")]),t._v(" 数据库操作")]),t._v(" "),s("p",[t._v("在下一个例子中,我们将构建使用MySQL作为数据的Web项目。")])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[64],{352:function(t,s,n){"use strict";n.r(s);var a=n(10),e=Object(a.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"web-项目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#web-项目"}},[t._v("#")]),t._v(" Web 项目")]),t._v(" "),s("h2",{attrs:{id:"安装gone辅助工具"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#安装gone辅助工具"}},[t._v("#")]),t._v(" 安装gone辅助工具")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("go "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),s("blockquote",[s("p",[t._v("安装可以使用gone命令:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("gone "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v("\n")])])]),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("\t➜ demo gone "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v("\n\tNAME:\n\tgone - A new cli application\n\n\tUSAGE:\n\tgone "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("global options"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("command")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("command options"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("arguments"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n\tDESCRIPTION:\n\tgenerate gone code or generate gone app\n\n\tCOMMANDS:\n\tpriest "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-s")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${scanPackageDir}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-p")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${pkgName}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${funcName}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outputFilePath}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-w"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\tmock "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${fromGoFile}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-o")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${outGoFile}")]),t._v("\n\tcreate "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-t "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${template}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-m "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${modName}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[t._v("${appName}")]),t._v("\n\thelp, h Shows a list of commands or "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("help")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" one "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("command")]),t._v("\n\n\tGLOBAL OPTIONS:\n\t--help, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-h")]),t._v(" show "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("help")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("default: "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("p",[t._v("支持的功能:")]),t._v(" "),s("ol",[s("li",[t._v("create,创建一个gone app,暂时只支持创建web app")]),t._v(" "),s("li",[t._v("priest,为项目自动生成 "),s("strong",[t._v("Priest")]),t._v(" 函数,"),s("RouterLink",{attrs:{to:"/zh/"}},[t._v("了解更多")])],1),t._v(" "),s("li",[t._v("生成用于测试的mock代码")])])]),t._v(" "),s("h2",{attrs:{id:"创建一个web项目并运行代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#创建一个web项目并运行代码"}},[t._v("#")]),t._v(" 创建一个web项目并运行代码")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 创将一个名为 web-app 的项目")]),t._v("\ngone create web-app\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" web-app\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),t._v(" run\n")])])]),s("h2",{attrs:{id:"项目结构"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#项目结构"}},[t._v("#")]),t._v(" 项目结构")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("➜ xxx tree\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(".")]),t._v("\n├── Dockerfile\n├── Makefile\n├── README.md\n├── cmd\n│ └── server\n│ └── main.go\n├── config\n│ ├── default.properties\n│ ├── dev.properties\n│ ├── local.properties\n│ └── prod.properties\n├── docker-compose.yaml\n├── go.mod\n├── internal\n│ ├── controller\n│ │ └── demo_ctr.go\n│ ├── interface\n│ │ ├── domain\n│ │ │ ├── demo.go\n│ │ │ └── user.go\n│ │ └── "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("service")]),t._v("\n│ │ └── i_demo.go\n│ ├── master.go\n│ ├── middleware\n│ │ ├── authorize.go\n│ │ └── pub.go\n│ ├── module\n│ │ └── demo\n│ │ ├── demo_svc.go\n│ │ └── error.go\n│ ├── pkg\n│ │ └── utils\n│ │ └── error.go\n│ └── router\n│ ├── auth_router.go\n│ └── pub_router.go\n└── tests\n └── api\n └── demo.http\n\n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" directories, "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("23")]),t._v(" files\n")])])]),s("ul",[s("li",[t._v("cmd/server/main.go: 启动文件,main函数所在文件")]),t._v(" "),s("li",[t._v("config/: 项目配置文件目录,支持"),s("code",[t._v(".properties")]),t._v("文件")]),t._v(" "),s("li",[t._v("internal/router/: 在该目录定义路由器")]),t._v(" "),s("li",[t._v("internal/middleware/: 中间件目录,如果需要定义web中间件,在该目录编写")]),t._v(" "),s("li",[t._v("internal/controller/: controller目录,在该目录中的文件定义路由")]),t._v(" "),s("li",[t._v("internal/interface/service/: 该目录放服务的接口定义")]),t._v(" "),s("li",[t._v("internal/domain/: 该目录放领域对象")]),t._v(" "),s("li",[t._v("internal/entity/: 该目录放一些无逻辑的结构体,类似于Java 的POJO")]),t._v(" "),s("li",[t._v("internal/module/: 模块目录,下面的每一个子目录实现一个模块的功能,一般是internal/interface/service/中定义的服务的业务实现;")]),t._v(" "),s("li",[t._v("internal/pkg/: 在该目录可以放一些项目共用的工具代码")]),t._v(" "),s("li",[t._v("internal/master.go: 存放"),s("strong",[t._v("MasterPriest")]),t._v("函数")]),t._v(" "),s("li",[t._v("internal/priest.go: gone priest 命令生成的 "),s("strong",[t._v("Priest")]),t._v("函数,用于"),s("strong",[t._v("埋葬")]),t._v("所有Goner")])]),t._v(" "),s("h2",{attrs:{id:"router"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#router"}},[t._v("#")]),t._v(" Router")]),t._v(" "),s("p",[t._v("在目录"),s("code",[t._v("internal/router")]),t._v("中分别实现了两个"),s("code",[t._v("gin.IRouter")]),t._v(":")]),t._v(" "),s("ul",[s("li",[t._v("pubRouter,公开的路由,挂载在该路由下的接口,请求将无需授权即可访问。")]),t._v(" "),s("li",[t._v("authRouter,鉴权的路由,挂载在该路由下的接口,请求必须先要经过授权。")])]),t._v(" "),s("p",[t._v("我们来分析"),s("code",[t._v("internal/router/pub_router.go")]),t._v("的代码:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" router\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/middleware"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" IdRouterPub "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"router-pub"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewPubRouter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("GonerId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("pubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" IdRouterPub\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" pubRouter "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tgin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter\n\troot gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"gone-gin-router"`')]),t._v("\n\tpub "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("middleware"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("PubMiddleware "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("r "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("pubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("AfterRevive")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("AfterReviveError "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/api"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" r"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pub"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Next"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ol",[s("li",[t._v("对于router,需要实现了"),s("code",[t._v("gin.IRouter")]),t._v("接口中定义的方法;")]),t._v(" "),s("li",[t._v("结构体"),s("code",[t._v("pubRouter")]),t._v("内嵌了一个"),s("code",[t._v("gin.IRouter")]),t._v(",就等于直接实现了"),s("code",[t._v("gin.IRouter")]),t._v("接口,只在"),s("code",[t._v("AfterRevive()")]),t._v("中将其赋予一个值就可以了;")]),t._v(" "),s("li",[s("code",[t._v('r.IRouter = r.root.Group("/api", r.pub.Next)')]),t._v("意思是当前路由是根路由下"),s("code",[t._v("/api")]),t._v("的子路由,并且默认的增加了一个中间"),s("code",[t._v("r.pub.Next")]),t._v(";")]),t._v(" "),s("li",[s("code",[t._v("root gin.IRouter")]),t._v("是一个Gone框架中"),s("code",[t._v("github.com/gone-io/gone/goner/gin")]),t._v("包提供的一个框架级Goner,具名注入的"),s("code",[t._v("gone-gin-router")]),t._v("。")])]),t._v(" "),s("h2",{attrs:{id:"controller"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#controller"}},[t._v("#")]),t._v(" Controller")]),t._v(" "),s("p",[t._v("下面是Controller接口的定义:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Controller 控制器接口,由业务代码编码实现,用于挂载和处理路由")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 使用方式参考 [示例代码](https://gitlab.openviewtech.com/gone/gone-example/-/tree/master/gone-app)")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Controller "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Mount 路由挂载接口,改接口会在服务启动前被调用,该函数的实现通常情况应该返回`nil`")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" MountError\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("编写http接口,我们需要实现"),s("code",[t._v("Controller")]),t._v("接口,在"),s("code",[t._v("Mount")]),t._v("方法中实现接口路由的挂载,如"),s("code",[t._v("internal/controller/demo_ctr.go")]),t._v("的代码:")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" controller\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/service"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/pkg/utils"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone"')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/gone-io/gone/goner/gin"')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//go:gone")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewDemoController")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Goner "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" demoController "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tgone"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Flag\n\tdemoSvc service"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IDemo "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"*"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入依赖的服务")]),t._v("\n\n\tauthRouter gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"router-auth"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入路由器")]),t._v("\n\tpubRouter gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("IRouter "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"router-pub"`')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入路由器")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Mount")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("MountError "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//需要鉴权的路由分组")]),t._v("\n\tctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tauthRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/demo"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/show"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("showDemo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//不需要鉴权的路由分组")]),t._v("\n\tctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\tpubRouter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Group")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/demo2"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/show"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("showDemo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/error"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/echo"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("echo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("showDemo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Show")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctr "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("demoController"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("echo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Context"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" Req "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tEcho "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('`form:"echo"`')]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" req Req\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Bind")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" err "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" gin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("NewParameterError")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" utils"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ParameterParseError"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" ctr"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("demoSvc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("req"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Echo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("h2",{attrs:{id:"service"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#service"}},[t._v("#")]),t._v(" Service")]),t._v(" "),s("p",[t._v("规范上,我们要求将服务的接口定义在"),s("code",[t._v("internal/interface/service")]),t._v("目录,文件名以"),s("code",[t._v("i_")]),t._v("打头,接口类型以"),s("code",[t._v("I")]),t._v("打头,例如:\n文件:i_demo.go")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" service\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"web-app/internal/interface/domain"')]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("type")]),t._v(" IDemo "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Show")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("domain"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("DemoEntity"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Echo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("input "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("string")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("any"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("服务的逻辑实现,放到"),s("code",[t._v("internal/module")]),t._v("目录分模块实现。")]),t._v(" "),s("h2",{attrs:{id:"数据库操作"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#数据库操作"}},[t._v("#")]),t._v(" 数据库操作")]),t._v(" "),s("p",[t._v("在下一个例子中,我们将构建使用MySQL作为数据的Web项目。")])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/64.14ea12bb.js b/assets/js/65.724a7158.js similarity index 92% rename from assets/js/64.14ea12bb.js rename to assets/js/65.724a7158.js index d1aa06c..145ba88 100644 --- a/assets/js/64.14ea12bb.js +++ b/assets/js/65.724a7158.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[64],{354:function(t,e,r){"use strict";r.r(e);var s=r(10),a=Object(s.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"参考文档"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#参考文档"}},[t._v("#")]),t._v(" 参考文档")]),t._v(" "),e("h2",{attrs:{id:"gone辅助工具"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#gone辅助工具"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/zh/references/gone-tool.html"}},[t._v("gone辅助工具")])],1),t._v(" "),e("h2",{attrs:{id:"http-注入说明"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-注入说明"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/zh/references/http-inject.html"}},[t._v("http 注入说明")])],1)])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[65],{353:function(t,e,r){"use strict";r.r(e);var s=r(10),a=Object(s.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"参考文档"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#参考文档"}},[t._v("#")]),t._v(" 参考文档")]),t._v(" "),e("h2",{attrs:{id:"gone辅助工具"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#gone辅助工具"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/zh/references/gone-tool.html"}},[t._v("gone辅助工具")])],1),t._v(" "),e("h2",{attrs:{id:"http-注入说明"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-注入说明"}},[t._v("#")]),t._v(" "),e("RouterLink",{attrs:{to:"/zh/references/http-inject.html"}},[t._v("http 注入说明")])],1)])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/65.8844f655.js b/assets/js/66.c52e7abe.js similarity index 98% rename from assets/js/65.8844f655.js rename to assets/js/66.c52e7abe.js index c8ed040..6d8e51c 100644 --- a/assets/js/65.8844f655.js +++ b/assets/js/66.c52e7abe.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[65],{356:function(a,t,s){"use strict";s.r(t);var e=s(10),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h1",{attrs:{id:"gone辅助工具"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#gone辅助工具"}},[a._v("#")]),a._v(" gone辅助工具")]),a._v(" "),t("h2",{attrs:{id:"安装"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#安装"}},[a._v("#")]),a._v(" 安装")]),a._v(" "),t("p",[a._v("执行如下命令:")]),a._v(" "),t("div",{staticClass:"language-bash extra-class"},[t("pre",{pre:!0,attrs:{class:"language-bash"}},[t("code",[a._v("go "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),t("h2",{attrs:{id:"使用"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#使用"}},[a._v("#")]),a._v(" 使用")]),a._v(" "),t("h3",{attrs:{id:"测试是否正常安装"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#测试是否正常安装"}},[a._v("#")]),a._v(" 测试是否正常安装")]),a._v(" "),t("p",[a._v("成功安装后,执行"),t("code",[a._v("gone -h")]),a._v(",建获得如下结果:")]),a._v(" "),t("div",{staticClass:"language-bash extra-class"},[t("pre",{pre:!0,attrs:{class:"language-bash"}},[t("code",[a._v("➜ demo gone "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-h")]),a._v("\nNAME:\n gone - A new cli application\n\nUSAGE:\n gone "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("global options"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("command")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("command options"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("arguments"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v("."),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n\nDESCRIPTION:\n generate gone code or generate gone app\n\nCOMMANDS:\n priest "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-s")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${scanPackageDir}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-p")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${pkgName}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${funcName}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-o")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${outputFilePath}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-w"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n mock "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${fromGoFile}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-o")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${outGoFile}")]),a._v("\n create "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-t "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${template}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-m "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${modName}")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${appName}")]),a._v("\n help, h Shows a list of commands or "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("help")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token keyword"}},[a._v("for")]),a._v(" one "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("command")]),a._v("\n\nGLOBAL OPTIONS:\n --help, "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-h")]),a._v(" show "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("help")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("default: "),t("span",{pre:!0,attrs:{class:"token boolean"}},[a._v("false")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n")])])]),t("h3",{attrs:{id:"生成项目"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#生成项目"}},[a._v("#")]),a._v(" 生成项目")]),a._v(" "),t("h3",{attrs:{id:"生成priest函数"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#生成priest函数"}},[a._v("#")]),a._v(" 生成Priest函数")])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[66],{354:function(a,t,s){"use strict";s.r(t);var e=s(10),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h1",{attrs:{id:"gone辅助工具"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#gone辅助工具"}},[a._v("#")]),a._v(" gone辅助工具")]),a._v(" "),t("h2",{attrs:{id:"安装"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#安装"}},[a._v("#")]),a._v(" 安装")]),a._v(" "),t("p",[a._v("执行如下命令:")]),a._v(" "),t("div",{staticClass:"language-bash extra-class"},[t("pre",{pre:!0,attrs:{class:"language-bash"}},[t("code",[a._v("go "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" github.com/gone-io/gone/tools/gone@latest\n")])])]),t("h2",{attrs:{id:"使用"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#使用"}},[a._v("#")]),a._v(" 使用")]),a._v(" "),t("h3",{attrs:{id:"测试是否正常安装"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#测试是否正常安装"}},[a._v("#")]),a._v(" 测试是否正常安装")]),a._v(" "),t("p",[a._v("成功安装后,执行"),t("code",[a._v("gone -h")]),a._v(",建获得如下结果:")]),a._v(" "),t("div",{staticClass:"language-bash extra-class"},[t("pre",{pre:!0,attrs:{class:"language-bash"}},[t("code",[a._v("➜ demo gone "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-h")]),a._v("\nNAME:\n gone - A new cli application\n\nUSAGE:\n gone "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("global options"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("command")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("command options"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("arguments"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v("."),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n\nDESCRIPTION:\n generate gone code or generate gone app\n\nCOMMANDS:\n priest "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-s")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${scanPackageDir}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-p")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${pkgName}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${funcName}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-o")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${outputFilePath}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-w"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n mock "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${fromGoFile}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-o")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${outGoFile}")]),a._v("\n create "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-t "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${template}")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-m "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${modName}")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${appName}")]),a._v("\n help, h Shows a list of commands or "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("help")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token keyword"}},[a._v("for")]),a._v(" one "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("command")]),a._v("\n\nGLOBAL OPTIONS:\n --help, "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-h")]),a._v(" show "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("help")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("default: "),t("span",{pre:!0,attrs:{class:"token boolean"}},[a._v("false")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n")])])]),t("h3",{attrs:{id:"生成项目"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#生成项目"}},[a._v("#")]),a._v(" 生成项目")]),a._v(" "),t("h3",{attrs:{id:"生成priest函数"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#生成priest函数"}},[a._v("#")]),a._v(" 生成Priest函数")])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/66.47b08fb9.js b/assets/js/67.4bfbe334.js similarity index 99% rename from assets/js/66.47b08fb9.js rename to assets/js/67.4bfbe334.js index 59e2026..eb73d76 100644 --- a/assets/js/66.47b08fb9.js +++ b/assets/js/67.4bfbe334.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[66],{355:function(t,e,n){"use strict";n.r(e);var s=n(10),a=Object(s.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"http-注入说明"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-注入说明"}},[t._v("#")]),t._v(" http 注入说明")]),t._v(" "),e("h2",{attrs:{id:"http-依赖注入标签的格式"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-依赖注入标签的格式"}},[t._v("#")]),t._v(" http 依赖注入标签的格式")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v('${attributeName} ${attributeType} gone:"http,${kind}=${key}"\n')])])]),e("p",[t._v("举例:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("router"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/search"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("function")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n selects "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=select"`')]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入值in.selects为`[]int{1,2,3}`")]),t._v("\n fmt"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%v"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("selects"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),e("p",[t._v("上面例子中,")]),t._v(" "),e("ul",[e("li",[e("code",[t._v("selects")]),t._v("为属性名(attributeName);")]),t._v(" "),e("li",[e("code",[t._v("[]int")]),t._v("为属性类型(attributeType);")]),t._v(" "),e("li",[e("code",[t._v("query")]),t._v("为注入类型(kind);")]),t._v(" "),e("li",[e("code",[t._v("select")]),t._v("为注入键值(key)。")])]),t._v(" "),e("h2",{attrs:{id:"支持注入的类型和响应标签"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#支持注入的类型和响应标签"}},[t._v("#")]),t._v(" 支持注入的类型和响应标签")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("名称")]),t._v(" "),e("th",[t._v("属性类型"),e("code",[t._v("${attributeType}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("注入类型"),e("code",[t._v("${kind}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("注入键值"),e("code",[t._v("${key}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("说明")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("上下文注入")])]),t._v(" "),e("td",[e("code",[t._v("gone.Context")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(不推荐)注入gin请求上下文对象,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("上下文注入")])]),t._v(" "),e("td",[e("code",[t._v("*gone.Context")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(推荐)注入gin请求上下文指针,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("请求注入")])]),t._v(" "),e("td",[e("code",[t._v("http.Request")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("不推荐)注入http.Request对象,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("请求注入")])]),t._v(" "),e("td",[e("code",[t._v("*http.Request")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(推荐)注入http.Request指针,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("地址注入")])]),t._v(" "),e("td",[e("code",[t._v("url.URL")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(不推荐)注入url.URL,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("地址注入")])]),t._v(" "),e("td",[e("code",[t._v("*url.URL")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(推荐)注入url.URL指针,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("请求头注入")])]),t._v(" "),e("td",[e("code",[t._v("http.Header")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(推荐)注入http.Header(请求头),不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("响应注入")])]),t._v(" "),e("td",[e("code",[t._v("gone.ResponseWriter")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("注入gin.ResponseWriter(用于直接写入响应数据),不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Body注入")])]),t._v(" "),e("td",[t._v("结构体、结构体指针")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[e("code",[t._v("body")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("strong",[t._v("body注入")]),t._v(";将请求body解析后注入到属性,注入类型为 "),e("code",[t._v("body")]),t._v(",不需要“注入键值"),e("code",[t._v("${key}")]),t._v("”;框架根据"),e("code",[t._v("Content-Type")]),t._v("自动判定是json还是xml等格式;每个请求处理函数只允许存在一个"),e("strong",[t._v("body注入")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("请求头单值注入")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("header")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("缺省取字段名")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("以键值"),e("code",[t._v("${key}")]),t._v("为"),e("code",[t._v("key")]),t._v("获取请求头,属性类型支持"),e("code",[t._v("string")]),t._v("和"),e("code",[t._v("int")]),t._v(","),e("code",[t._v("uint")]),t._v(","),e("code",[t._v("float64")]),t._v("等数字类型,解析不了会返回参数错误")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("URL参数注入")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("param")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("缺省取字段名")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("以“注入键值"),e("code",[t._v("${key}")]),t._v("”为"),e("code",[t._v("key")]),t._v("调用函数"),e("code",[t._v("ctx.Param(key)")]),t._v("获取Url中定义的参数值,属性类型支持"),e("code",[t._v("string")]),t._v("和"),e("code",[t._v("int")]),t._v(","),e("code",[t._v("uint")]),t._v(","),e("code",[t._v("float64")]),t._v("等数字类型,解析不了会返回参数错误")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Query参数注入")])]),t._v(" "),e("td",[t._v("number | string | []number | []string | 结构体 | 结构体指针")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("query")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("缺省取字段名")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("以“注入键值"),e("code",[t._v("${key}")]),t._v("”为"),e("code",[t._v("key")]),t._v("调用函数"),e("code",[t._v("ctx.Query(key)")]),t._v("获取Query中的参数,属性类型支持"),e("code",[t._v("string")]),t._v("和"),e("code",[t._v("int")]),t._v(","),e("code",[t._v("uint")]),t._v(","),e("code",[t._v("float64")]),t._v("等数字类型,"),e("strong",[t._v("支持数组"),e("sub",[t._v("[1]")])]),t._v(",解析不了会返回参数错误")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Cookie注入")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("cookie")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("缺省取字段名")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("以“注入键值"),e("code",[t._v("${key}")]),t._v("”为"),e("code",[t._v("key")]),t._v("调用函数"),e("code",[t._v("ctx.Context.Cookie(key)")]),t._v("获取Cookie的值,属性类型支持"),e("code",[t._v("string")]),t._v("和"),e("code",[t._v("int")]),t._v(","),e("code",[t._v("uint")]),t._v(","),e("code",[t._v("float64")]),t._v("等数字类型,解析不了会返回参数错误")])])])]),t._v(" "),e("h2",{attrs:{id:"备注"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#备注"}},[t._v("#")]),t._v(" 备注")]),t._v(" "),e("p",[t._v("[1]. query参数注入支持数组,举例说明如下:\n如果请求的query为"),e("code",[t._v("?select=1&select=2&select=3")]),t._v(",下面代码中的 "),e("code",[t._v("in.selects")]),t._v(" 的值将会为 "),e("code",[t._v("[]int{1,2,3}")]),t._v("。")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("router"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/search"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("function")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n selects "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=select"`')]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入值in.selects为`[]int{1,2,3}`")]),t._v("\n fmt"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%v"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("selects"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[67],{355:function(t,e,n){"use strict";n.r(e);var s=n(10),a=Object(s.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"http-注入说明"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-注入说明"}},[t._v("#")]),t._v(" http 注入说明")]),t._v(" "),e("h2",{attrs:{id:"http-依赖注入标签的格式"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#http-依赖注入标签的格式"}},[t._v("#")]),t._v(" http 依赖注入标签的格式")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v('${attributeName} ${attributeType} gone:"http,${kind}=${key}"\n')])])]),e("p",[t._v("举例:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("router"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/search"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("function")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n selects "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=select"`')]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入值in.selects为`[]int{1,2,3}`")]),t._v("\n fmt"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%v"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("selects"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),e("p",[t._v("上面例子中,")]),t._v(" "),e("ul",[e("li",[e("code",[t._v("selects")]),t._v("为属性名(attributeName);")]),t._v(" "),e("li",[e("code",[t._v("[]int")]),t._v("为属性类型(attributeType);")]),t._v(" "),e("li",[e("code",[t._v("query")]),t._v("为注入类型(kind);")]),t._v(" "),e("li",[e("code",[t._v("select")]),t._v("为注入键值(key)。")])]),t._v(" "),e("h2",{attrs:{id:"支持注入的类型和响应标签"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#支持注入的类型和响应标签"}},[t._v("#")]),t._v(" 支持注入的类型和响应标签")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("名称")]),t._v(" "),e("th",[t._v("属性类型"),e("code",[t._v("${attributeType}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("注入类型"),e("code",[t._v("${kind}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("注入键值"),e("code",[t._v("${key}")])]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("说明")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("上下文注入")])]),t._v(" "),e("td",[e("code",[t._v("gone.Context")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(不推荐)注入gin请求上下文对象,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("上下文注入")])]),t._v(" "),e("td",[e("code",[t._v("*gone.Context")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(推荐)注入gin请求上下文指针,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("请求注入")])]),t._v(" "),e("td",[e("code",[t._v("http.Request")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("不推荐)注入http.Request对象,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("请求注入")])]),t._v(" "),e("td",[e("code",[t._v("*http.Request")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(推荐)注入http.Request指针,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("地址注入")])]),t._v(" "),e("td",[e("code",[t._v("url.URL")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(不推荐)注入url.URL,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("地址注入")])]),t._v(" "),e("td",[e("code",[t._v("*url.URL")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(推荐)注入url.URL指针,不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("请求头注入")])]),t._v(" "),e("td",[e("code",[t._v("http.Header")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("(推荐)注入http.Header(请求头),不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("响应注入")])]),t._v(" "),e("td",[e("code",[t._v("gone.ResponseWriter")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("注入gin.ResponseWriter(用于直接写入响应数据),不需要类型"),e("code",[t._v("${kind}")]),t._v("和键值"),e("code",[t._v("${key}")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Body注入")])]),t._v(" "),e("td",[t._v("结构体、结构体指针")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[e("code",[t._v("body")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("/")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("strong",[t._v("body注入")]),t._v(";将请求body解析后注入到属性,注入类型为 "),e("code",[t._v("body")]),t._v(",不需要“注入键值"),e("code",[t._v("${key}")]),t._v("”;框架根据"),e("code",[t._v("Content-Type")]),t._v("自动判定是json还是xml等格式;每个请求处理函数只允许存在一个"),e("strong",[t._v("body注入")]),t._v("。")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("请求头单值注入")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("header")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("缺省取字段名")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("以键值"),e("code",[t._v("${key}")]),t._v("为"),e("code",[t._v("key")]),t._v("获取请求头,属性类型支持"),e("code",[t._v("string")]),t._v("和"),e("code",[t._v("int")]),t._v(","),e("code",[t._v("uint")]),t._v(","),e("code",[t._v("float64")]),t._v("等数字类型,解析不了会返回参数错误")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("URL参数注入")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("param")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("缺省取字段名")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("以“注入键值"),e("code",[t._v("${key}")]),t._v("”为"),e("code",[t._v("key")]),t._v("调用函数"),e("code",[t._v("ctx.Param(key)")]),t._v("获取Url中定义的参数值,属性类型支持"),e("code",[t._v("string")]),t._v("和"),e("code",[t._v("int")]),t._v(","),e("code",[t._v("uint")]),t._v(","),e("code",[t._v("float64")]),t._v("等数字类型,解析不了会返回参数错误")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Query参数注入")])]),t._v(" "),e("td",[t._v("number | string | []number | []string | 结构体 | 结构体指针")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("query")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("缺省取字段名")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("以“注入键值"),e("code",[t._v("${key}")]),t._v("”为"),e("code",[t._v("key")]),t._v("调用函数"),e("code",[t._v("ctx.Query(key)")]),t._v("获取Query中的参数,属性类型支持"),e("code",[t._v("string")]),t._v("和"),e("code",[t._v("int")]),t._v(","),e("code",[t._v("uint")]),t._v(","),e("code",[t._v("float64")]),t._v("等数字类型,"),e("strong",[t._v("支持数组"),e("sub",[t._v("[1]")])]),t._v(",解析不了会返回参数错误")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("Cookie注入")])]),t._v(" "),e("td",[t._v("number | string")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("cookie")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("缺省取字段名")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("以“注入键值"),e("code",[t._v("${key}")]),t._v("”为"),e("code",[t._v("key")]),t._v("调用函数"),e("code",[t._v("ctx.Context.Cookie(key)")]),t._v("获取Cookie的值,属性类型支持"),e("code",[t._v("string")]),t._v("和"),e("code",[t._v("int")]),t._v(","),e("code",[t._v("uint")]),t._v(","),e("code",[t._v("float64")]),t._v("等数字类型,解析不了会返回参数错误")])])])]),t._v(" "),e("h2",{attrs:{id:"备注"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#备注"}},[t._v("#")]),t._v(" 备注")]),t._v(" "),e("p",[t._v("[1]. query参数注入支持数组,举例说明如下:\n如果请求的query为"),e("code",[t._v("?select=1&select=2&select=3")]),t._v(",下面代码中的 "),e("code",[t._v("in.selects")]),t._v(" 的值将会为 "),e("code",[t._v("[]int{1,2,3}")]),t._v("。")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("router"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GET")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/search"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("function")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("in "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n selects "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('`gone:"http,query=select"`')]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注入值in.selects为`[]int{1,2,3}`")]),t._v("\n fmt"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Printf")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%v"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" in"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("selects"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])])])}),[],!1,null,null,null);e.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/67.6d7875af.js b/assets/js/68.0c6bca44.js similarity index 99% rename from assets/js/67.6d7875af.js rename to assets/js/68.0c6bca44.js index c7499d2..4141b20 100644 --- a/assets/js/67.6d7875af.js +++ b/assets/js/68.0c6bca44.js @@ -1,3 +1,3 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[67],{303:function(t,e,n){ +(window.webpackJsonp=window.webpackJsonp||[]).push([[68],{303:function(t,e,n){ /*! For license information please see mermaid.min.js.LICENSE.txt */ "undefined"!=typeof self&&self,t.exports=(()=>{var t={1362:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,6],n=[1,7],r=[1,8],i=[1,9],a=[1,12],o=[1,11],s=[1,15,24],c=[1,19],u=[1,31],l=[1,34],h=[1,32],f=[1,33],d=[1,35],p=[1,36],y=[1,37],g=[1,38],m=[1,41],v=[1,42],b=[1,43],_=[1,44],x=[15,24],w=[1,56],k=[1,57],T=[1,58],E=[1,59],C=[1,60],S=[1,61],A=[15,24,31,38,39,47,50,51,52,53,54,55,60,62],M=[15,24,29,31,38,39,43,47,50,51,52,53,54,55,60,62,77,78,79,80],N=[7,8,9,10,15,18,22,24],D=[47,77,78,79,80],O=[47,54,55,77,78,79,80],B=[47,50,51,52,53,77,78,79,80],L=[15,24,31],I=[1,93],R={trace:function(){},yy:{},symbols_:{error:2,start:3,mermaidDoc:4,direction:5,directive:6,direction_tb:7,direction_bt:8,direction_rl:9,direction_lr:10,graphConfig:11,openDirective:12,typeDirective:13,closeDirective:14,NEWLINE:15,":":16,argDirective:17,open_directive:18,type_directive:19,arg_directive:20,close_directive:21,CLASS_DIAGRAM:22,statements:23,EOF:24,statement:25,className:26,alphaNumToken:27,classLiteralName:28,GENERICTYPE:29,relationStatement:30,LABEL:31,classStatement:32,methodStatement:33,annotationStatement:34,clickStatement:35,cssClassStatement:36,CLASS:37,STYLE_SEPARATOR:38,STRUCT_START:39,members:40,STRUCT_STOP:41,ANNOTATION_START:42,ANNOTATION_END:43,MEMBER:44,SEPARATOR:45,relation:46,STR:47,relationType:48,lineType:49,AGGREGATION:50,EXTENSION:51,COMPOSITION:52,DEPENDENCY:53,LINE:54,DOTTED_LINE:55,CALLBACK:56,LINK:57,LINK_TARGET:58,CLICK:59,CALLBACK_NAME:60,CALLBACK_ARGS:61,HREF:62,CSSCLASS:63,commentToken:64,textToken:65,graphCodeTokens:66,textNoTagsToken:67,TAGSTART:68,TAGEND:69,"==":70,"--":71,PCT:72,DEFAULT:73,SPACE:74,MINUS:75,keywords:76,UNICODE_TEXT:77,NUM:78,ALPHA:79,BQUOTE_STR:80,$accept:0,$end:1},terminals_:{2:"error",7:"direction_tb",8:"direction_bt",9:"direction_rl",10:"direction_lr",15:"NEWLINE",16:":",18:"open_directive",19:"type_directive",20:"arg_directive",21:"close_directive",22:"CLASS_DIAGRAM",24:"EOF",29:"GENERICTYPE",31:"LABEL",37:"CLASS",38:"STYLE_SEPARATOR",39:"STRUCT_START",41:"STRUCT_STOP",42:"ANNOTATION_START",43:"ANNOTATION_END",44:"MEMBER",45:"SEPARATOR",47:"STR",50:"AGGREGATION",51:"EXTENSION",52:"COMPOSITION",53:"DEPENDENCY",54:"LINE",55:"DOTTED_LINE",56:"CALLBACK",57:"LINK",58:"LINK_TARGET",59:"CLICK",60:"CALLBACK_NAME",61:"CALLBACK_ARGS",62:"HREF",63:"CSSCLASS",66:"graphCodeTokens",68:"TAGSTART",69:"TAGEND",70:"==",71:"--",72:"PCT",73:"DEFAULT",74:"SPACE",75:"MINUS",76:"keywords",77:"UNICODE_TEXT",78:"NUM",79:"ALPHA",80:"BQUOTE_STR"},productions_:[0,[3,1],[3,1],[3,2],[5,1],[5,1],[5,1],[5,1],[4,1],[6,4],[6,6],[12,1],[13,1],[17,1],[14,1],[11,4],[23,1],[23,2],[23,3],[26,1],[26,1],[26,2],[26,2],[26,2],[25,1],[25,2],[25,1],[25,1],[25,1],[25,1],[25,1],[25,1],[25,1],[32,2],[32,4],[32,5],[32,7],[34,4],[40,1],[40,2],[33,1],[33,2],[33,1],[33,1],[30,3],[30,4],[30,4],[30,5],[46,3],[46,2],[46,2],[46,1],[48,1],[48,1],[48,1],[48,1],[49,1],[49,1],[35,3],[35,4],[35,3],[35,4],[35,4],[35,5],[35,3],[35,4],[35,4],[35,5],[35,3],[35,4],[35,4],[35,5],[36,3],[64,1],[64,1],[65,1],[65,1],[65,1],[65,1],[65,1],[65,1],[65,1],[67,1],[67,1],[67,1],[67,1],[27,1],[27,1],[27,1],[28,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 4:r.setDirection("TB");break;case 5:r.setDirection("BT");break;case 6:r.setDirection("RL");break;case 7:r.setDirection("LR");break;case 11:r.parseDirective("%%{","open_directive");break;case 12:r.parseDirective(a[s],"type_directive");break;case 13:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 14:r.parseDirective("}%%","close_directive","class");break;case 19:case 20:this.$=a[s];break;case 21:this.$=a[s-1]+a[s];break;case 22:case 23:this.$=a[s-1]+"~"+a[s];break;case 24:r.addRelation(a[s]);break;case 25:a[s-1].title=r.cleanupLabel(a[s]),r.addRelation(a[s-1]);break;case 33:r.addClass(a[s]);break;case 34:r.addClass(a[s-2]),r.setCssClass(a[s-2],a[s]);break;case 35:r.addClass(a[s-3]),r.addMembers(a[s-3],a[s-1]);break;case 36:r.addClass(a[s-5]),r.setCssClass(a[s-5],a[s-3]),r.addMembers(a[s-5],a[s-1]);break;case 37:r.addAnnotation(a[s],a[s-2]);break;case 38:this.$=[a[s]];break;case 39:a[s].push(a[s-1]),this.$=a[s];break;case 40:case 42:case 43:break;case 41:r.addMember(a[s-1],r.cleanupLabel(a[s]));break;case 44:this.$={id1:a[s-2],id2:a[s],relation:a[s-1],relationTitle1:"none",relationTitle2:"none"};break;case 45:this.$={id1:a[s-3],id2:a[s],relation:a[s-1],relationTitle1:a[s-2],relationTitle2:"none"};break;case 46:this.$={id1:a[s-3],id2:a[s],relation:a[s-2],relationTitle1:"none",relationTitle2:a[s-1]};break;case 47:this.$={id1:a[s-4],id2:a[s],relation:a[s-2],relationTitle1:a[s-3],relationTitle2:a[s-1]};break;case 48:this.$={type1:a[s-2],type2:a[s],lineType:a[s-1]};break;case 49:this.$={type1:"none",type2:a[s],lineType:a[s-1]};break;case 50:this.$={type1:a[s-1],type2:"none",lineType:a[s]};break;case 51:this.$={type1:"none",type2:"none",lineType:a[s]};break;case 52:this.$=r.relationType.AGGREGATION;break;case 53:this.$=r.relationType.EXTENSION;break;case 54:this.$=r.relationType.COMPOSITION;break;case 55:this.$=r.relationType.DEPENDENCY;break;case 56:this.$=r.lineType.LINE;break;case 57:this.$=r.lineType.DOTTED_LINE;break;case 58:case 64:this.$=a[s-2],r.setClickEvent(a[s-1],a[s]);break;case 59:case 65:this.$=a[s-3],r.setClickEvent(a[s-2],a[s-1]),r.setTooltip(a[s-2],a[s]);break;case 60:case 68:this.$=a[s-2],r.setLink(a[s-1],a[s]);break;case 61:case 69:this.$=a[s-3],r.setLink(a[s-2],a[s-1],a[s]);break;case 62:case 70:this.$=a[s-3],r.setLink(a[s-2],a[s-1]),r.setTooltip(a[s-2],a[s]);break;case 63:case 71:this.$=a[s-4],r.setLink(a[s-3],a[s-2],a[s]),r.setTooltip(a[s-3],a[s-1]);break;case 66:this.$=a[s-3],r.setClickEvent(a[s-2],a[s-1],a[s]);break;case 67:this.$=a[s-4],r.setClickEvent(a[s-3],a[s-2],a[s-1]),r.setTooltip(a[s-3],a[s]);break;case 72:r.setCssClass(a[s-1],a[s])}},table:[{3:1,4:2,5:3,6:4,7:e,8:n,9:r,10:i,11:5,12:10,18:a,22:o},{1:[3]},{1:[2,1]},{1:[2,2]},{3:13,4:2,5:3,6:4,7:e,8:n,9:r,10:i,11:5,12:10,18:a,22:o},{1:[2,8]},t(s,[2,4]),t(s,[2,5]),t(s,[2,6]),t(s,[2,7]),{13:14,19:[1,15]},{15:[1,16]},{19:[2,11]},{1:[2,3]},{14:17,16:[1,18],21:c},t([16,21],[2,12]),{5:29,6:28,7:e,8:n,9:r,10:i,12:10,18:a,23:20,25:21,26:30,27:39,28:40,30:22,32:23,33:24,34:25,35:26,36:27,37:u,42:l,44:h,45:f,56:d,57:p,59:y,63:g,77:m,78:v,79:b,80:_},{15:[1,45]},{17:46,20:[1,47]},{15:[2,14]},{24:[1,48]},{15:[1,49],24:[2,16]},t(x,[2,24],{31:[1,50]}),t(x,[2,26]),t(x,[2,27]),t(x,[2,28]),t(x,[2,29]),t(x,[2,30]),t(x,[2,31]),t(x,[2,32]),t(x,[2,40],{46:51,48:54,49:55,31:[1,53],47:[1,52],50:w,51:k,52:T,53:E,54:C,55:S}),{26:62,27:39,28:40,77:m,78:v,79:b,80:_},t(x,[2,42]),t(x,[2,43]),{27:63,77:m,78:v,79:b},{26:64,27:39,28:40,77:m,78:v,79:b,80:_},{26:65,27:39,28:40,77:m,78:v,79:b,80:_},{26:66,27:39,28:40,77:m,78:v,79:b,80:_},{47:[1,67]},t(A,[2,19],{27:39,28:40,26:68,29:[1,69],77:m,78:v,79:b,80:_}),t(A,[2,20],{29:[1,70]}),t(M,[2,86]),t(M,[2,87]),t(M,[2,88]),t([15,24,29,31,38,39,47,50,51,52,53,54,55,60,62],[2,89]),t(N,[2,9]),{14:71,21:c},{21:[2,13]},{1:[2,15]},{5:29,6:28,7:e,8:n,9:r,10:i,12:10,18:a,23:72,24:[2,17],25:21,26:30,27:39,28:40,30:22,32:23,33:24,34:25,35:26,36:27,37:u,42:l,44:h,45:f,56:d,57:p,59:y,63:g,77:m,78:v,79:b,80:_},t(x,[2,25]),{26:73,27:39,28:40,47:[1,74],77:m,78:v,79:b,80:_},{46:75,48:54,49:55,50:w,51:k,52:T,53:E,54:C,55:S},t(x,[2,41]),{49:76,54:C,55:S},t(D,[2,51],{48:77,50:w,51:k,52:T,53:E}),t(O,[2,52]),t(O,[2,53]),t(O,[2,54]),t(O,[2,55]),t(B,[2,56]),t(B,[2,57]),t(x,[2,33],{38:[1,78],39:[1,79]}),{43:[1,80]},{47:[1,81]},{47:[1,82]},{60:[1,83],62:[1,84]},{27:85,77:m,78:v,79:b},t(A,[2,21]),t(A,[2,22]),t(A,[2,23]),{15:[1,86]},{24:[2,18]},t(L,[2,44]),{26:87,27:39,28:40,77:m,78:v,79:b,80:_},{26:88,27:39,28:40,47:[1,89],77:m,78:v,79:b,80:_},t(D,[2,50],{48:90,50:w,51:k,52:T,53:E}),t(D,[2,49]),{27:91,77:m,78:v,79:b},{40:92,44:I},{26:94,27:39,28:40,77:m,78:v,79:b,80:_},t(x,[2,58],{47:[1,95]}),t(x,[2,60],{47:[1,97],58:[1,96]}),t(x,[2,64],{47:[1,98],61:[1,99]}),t(x,[2,68],{47:[1,101],58:[1,100]}),t(x,[2,72]),t(N,[2,10]),t(L,[2,46]),t(L,[2,45]),{26:102,27:39,28:40,77:m,78:v,79:b,80:_},t(D,[2,48]),t(x,[2,34],{39:[1,103]}),{41:[1,104]},{40:105,41:[2,38],44:I},t(x,[2,37]),t(x,[2,59]),t(x,[2,61]),t(x,[2,62],{58:[1,106]}),t(x,[2,65]),t(x,[2,66],{47:[1,107]}),t(x,[2,69]),t(x,[2,70],{58:[1,108]}),t(L,[2,47]),{40:109,44:I},t(x,[2,35]),{41:[2,39]},t(x,[2,63]),t(x,[2,67]),t(x,[2,71]),{41:[1,110]},t(x,[2,36])],defaultActions:{2:[2,1],3:[2,2],5:[2,8],12:[2,11],13:[2,3],19:[2,14],47:[2,13],48:[2,15],72:[2,18],105:[2,39]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},F={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),18;case 1:return 7;case 2:return 8;case 3:return 9;case 4:return 10;case 5:return this.begin("type_directive"),19;case 6:return this.popState(),this.begin("arg_directive"),16;case 7:return this.popState(),this.popState(),21;case 8:return 20;case 9:case 10:case 12:case 19:break;case 11:return 15;case 13:case 14:return 22;case 15:return this.begin("struct"),39;case 16:return"EOF_IN_STRUCT";case 17:return"OPEN_IN_STRUCT";case 18:return this.popState(),41;case 20:return"MEMBER";case 21:return 37;case 22:return 63;case 23:return 56;case 24:return 57;case 25:return 59;case 26:return 42;case 27:return 43;case 28:this.begin("generic");break;case 29:case 32:case 35:case 38:case 41:case 44:this.popState();break;case 30:return"GENERICTYPE";case 31:this.begin("string");break;case 33:return"STR";case 34:this.begin("bqstring");break;case 36:return"BQUOTE_STR";case 37:this.begin("href");break;case 39:return 62;case 40:this.begin("callback_name");break;case 42:this.popState(),this.begin("callback_args");break;case 43:return 60;case 45:return 61;case 46:case 47:case 48:case 49:return 58;case 50:case 51:return 51;case 52:case 53:return 53;case 54:return 52;case 55:return 50;case 56:return 54;case 57:return 55;case 58:return 31;case 59:return 38;case 60:return 75;case 61:return"DOT";case 62:return"PLUS";case 63:return 72;case 64:case 65:return"EQUALS";case 66:return 79;case 67:return"PUNCTUATION";case 68:return 78;case 69:return 77;case 70:return 74;case 71:return 24}},rules:[/^(?:%%\{)/,/^(?:.*direction\s+TB[^\n]*)/,/^(?:.*direction\s+BT[^\n]*)/,/^(?:.*direction\s+RL[^\n]*)/,/^(?:.*direction\s+LR[^\n]*)/,/^(?:((?:(?!\}%%)[^:.])*))/,/^(?::)/,/^(?:\}%%)/,/^(?:((?:(?!\}%%).|\n)*))/,/^(?:%%(?!\{)*[^\n]*(\r?\n?)+)/,/^(?:%%[^\n]*(\r?\n)*)/,/^(?:\s*(\r?\n)+)/,/^(?:\s+)/,/^(?:classDiagram-v2\b)/,/^(?:classDiagram\b)/,/^(?:[{])/,/^(?:$)/,/^(?:[{])/,/^(?:[}])/,/^(?:[\n])/,/^(?:[^{}\n]*)/,/^(?:class\b)/,/^(?:cssClass\b)/,/^(?:callback\b)/,/^(?:link\b)/,/^(?:click\b)/,/^(?:<<)/,/^(?:>>)/,/^(?:[~])/,/^(?:[~])/,/^(?:[^~]*)/,/^(?:["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:[`])/,/^(?:[`])/,/^(?:[^`]+)/,/^(?:href[\s]+["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:call[\s]+)/,/^(?:\([\s]*\))/,/^(?:\()/,/^(?:[^(]*)/,/^(?:\))/,/^(?:[^)]*)/,/^(?:_self\b)/,/^(?:_blank\b)/,/^(?:_parent\b)/,/^(?:_top\b)/,/^(?:\s*<\|)/,/^(?:\s*\|>)/,/^(?:\s*>)/,/^(?:\s*<)/,/^(?:\s*\*)/,/^(?:\s*o\b)/,/^(?:--)/,/^(?:\.\.)/,/^(?::{1}[^:\n;]+)/,/^(?::{3})/,/^(?:-)/,/^(?:\.)/,/^(?:\+)/,/^(?:%)/,/^(?:=)/,/^(?:=)/,/^(?:\w+)/,/^(?:[!"#$%&'*+,-.`?\\/])/,/^(?:[0-9]+)/,/^(?:[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC])/,/^(?:\s)/,/^(?:$)/],conditions:{arg_directive:{rules:[7,8],inclusive:!1},type_directive:{rules:[6,7],inclusive:!1},open_directive:{rules:[5],inclusive:!1},callback_args:{rules:[44,45],inclusive:!1},callback_name:{rules:[41,42,43],inclusive:!1},href:{rules:[38,39],inclusive:!1},struct:{rules:[16,17,18,19,20],inclusive:!1},generic:{rules:[29,30],inclusive:!1},bqstring:{rules:[35,36],inclusive:!1},string:{rules:[32,33],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,9,10,11,12,13,14,15,21,22,23,24,25,26,27,28,31,34,37,40,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71],inclusive:!0}}};function P(){this.yy={}}return R.lexer=F,P.prototype=R,R.Parser=P,new P}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(8218).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},5890:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,2],n=[1,5],r=[6,9,11,23,41],i=[1,17],a=[1,20],o=[1,25],s=[1,26],c=[1,27],u=[1,28],l=[1,37],h=[23,38,39],f=[4,6,9,11,23,41],d=[34,35,36,37],p=[22,29],y=[1,55],g={trace:function(){},yy:{},symbols_:{error:2,start:3,ER_DIAGRAM:4,document:5,EOF:6,directive:7,line:8,SPACE:9,statement:10,NEWLINE:11,openDirective:12,typeDirective:13,closeDirective:14,":":15,argDirective:16,entityName:17,relSpec:18,role:19,BLOCK_START:20,attributes:21,BLOCK_STOP:22,ALPHANUM:23,attribute:24,attributeType:25,attributeName:26,attributeKeyType:27,attributeComment:28,ATTRIBUTE_WORD:29,ATTRIBUTE_KEY:30,COMMENT:31,cardinality:32,relType:33,ZERO_OR_ONE:34,ZERO_OR_MORE:35,ONE_OR_MORE:36,ONLY_ONE:37,NON_IDENTIFYING:38,IDENTIFYING:39,WORD:40,open_directive:41,type_directive:42,arg_directive:43,close_directive:44,$accept:0,$end:1},terminals_:{2:"error",4:"ER_DIAGRAM",6:"EOF",9:"SPACE",11:"NEWLINE",15:":",20:"BLOCK_START",22:"BLOCK_STOP",23:"ALPHANUM",29:"ATTRIBUTE_WORD",30:"ATTRIBUTE_KEY",31:"COMMENT",34:"ZERO_OR_ONE",35:"ZERO_OR_MORE",36:"ONE_OR_MORE",37:"ONLY_ONE",38:"NON_IDENTIFYING",39:"IDENTIFYING",40:"WORD",41:"open_directive",42:"type_directive",43:"arg_directive",44:"close_directive"},productions_:[0,[3,3],[3,2],[5,0],[5,2],[8,2],[8,1],[8,1],[8,1],[7,4],[7,6],[10,1],[10,5],[10,4],[10,3],[10,1],[17,1],[21,1],[21,2],[24,2],[24,3],[24,3],[24,4],[25,1],[26,1],[27,1],[28,1],[18,3],[32,1],[32,1],[32,1],[32,1],[33,1],[33,1],[19,1],[19,1],[12,1],[13,1],[16,1],[14,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 1:break;case 3:case 7:case 8:this.$=[];break;case 4:a[s-1].push(a[s]),this.$=a[s-1];break;case 5:case 6:case 16:case 23:case 24:case 25:case 35:this.$=a[s];break;case 12:r.addEntity(a[s-4]),r.addEntity(a[s-2]),r.addRelationship(a[s-4],a[s],a[s-2],a[s-3]);break;case 13:r.addEntity(a[s-3]),r.addAttributes(a[s-3],a[s-1]);break;case 14:r.addEntity(a[s-2]);break;case 15:r.addEntity(a[s]);break;case 17:this.$=[a[s]];break;case 18:a[s].push(a[s-1]),this.$=a[s];break;case 19:this.$={attributeType:a[s-1],attributeName:a[s]};break;case 20:this.$={attributeType:a[s-2],attributeName:a[s-1],attributeKeyType:a[s]};break;case 21:this.$={attributeType:a[s-2],attributeName:a[s-1],attributeComment:a[s]};break;case 22:this.$={attributeType:a[s-3],attributeName:a[s-2],attributeKeyType:a[s-1],attributeComment:a[s]};break;case 26:case 34:this.$=a[s].replace(/"/g,"");break;case 27:this.$={cardA:a[s],relType:a[s-1],cardB:a[s-2]};break;case 28:this.$=r.Cardinality.ZERO_OR_ONE;break;case 29:this.$=r.Cardinality.ZERO_OR_MORE;break;case 30:this.$=r.Cardinality.ONE_OR_MORE;break;case 31:this.$=r.Cardinality.ONLY_ONE;break;case 32:this.$=r.Identification.NON_IDENTIFYING;break;case 33:this.$=r.Identification.IDENTIFYING;break;case 36:r.parseDirective("%%{","open_directive");break;case 37:r.parseDirective(a[s],"type_directive");break;case 38:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 39:r.parseDirective("}%%","close_directive","er")}},table:[{3:1,4:e,7:3,12:4,41:n},{1:[3]},t(r,[2,3],{5:6}),{3:7,4:e,7:3,12:4,41:n},{13:8,42:[1,9]},{42:[2,36]},{6:[1,10],7:15,8:11,9:[1,12],10:13,11:[1,14],12:4,17:16,23:i,41:n},{1:[2,2]},{14:18,15:[1,19],44:a},t([15,44],[2,37]),t(r,[2,8],{1:[2,1]}),t(r,[2,4]),{7:15,10:21,12:4,17:16,23:i,41:n},t(r,[2,6]),t(r,[2,7]),t(r,[2,11]),t(r,[2,15],{18:22,32:24,20:[1,23],34:o,35:s,36:c,37:u}),t([6,9,11,15,20,23,34,35,36,37,41],[2,16]),{11:[1,29]},{16:30,43:[1,31]},{11:[2,39]},t(r,[2,5]),{17:32,23:i},{21:33,22:[1,34],24:35,25:36,29:l},{33:38,38:[1,39],39:[1,40]},t(h,[2,28]),t(h,[2,29]),t(h,[2,30]),t(h,[2,31]),t(f,[2,9]),{14:41,44:a},{44:[2,38]},{15:[1,42]},{22:[1,43]},t(r,[2,14]),{21:44,22:[2,17],24:35,25:36,29:l},{26:45,29:[1,46]},{29:[2,23]},{32:47,34:o,35:s,36:c,37:u},t(d,[2,32]),t(d,[2,33]),{11:[1,48]},{19:49,23:[1,51],40:[1,50]},t(r,[2,13]),{22:[2,18]},t(p,[2,19],{27:52,28:53,30:[1,54],31:y}),t([22,29,30,31],[2,24]),{23:[2,27]},t(f,[2,10]),t(r,[2,12]),t(r,[2,34]),t(r,[2,35]),t(p,[2,20],{28:56,31:y}),t(p,[2,21]),t([22,29,31],[2,25]),t(p,[2,26]),t(p,[2,22])],defaultActions:{5:[2,36],7:[2,2],20:[2,39],31:[2,38],37:[2,23],44:[2,18],47:[2,27]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},m={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),41;case 1:return this.begin("type_directive"),42;case 2:return this.popState(),this.begin("arg_directive"),15;case 3:return this.popState(),this.popState(),44;case 4:return 43;case 5:case 6:case 8:case 13:case 17:break;case 7:return 11;case 9:return 9;case 10:return 40;case 11:return 4;case 12:return this.begin("block"),20;case 14:return 30;case 15:return 29;case 16:return 31;case 18:return this.popState(),22;case 19:case 32:return e.yytext[0];case 20:case 24:return 34;case 21:case 25:return 35;case 22:case 26:return 36;case 23:return 37;case 27:case 29:case 30:return 38;case 28:return 39;case 31:return 23;case 33:return 6}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:[\s]+)/i,/^(?:"[^"]*")/i,/^(?:erDiagram\b)/i,/^(?:\{)/i,/^(?:\s+)/i,/^(?:(?:PK)|(?:FK))/i,/^(?:[A-Za-z][A-Za-z0-9\-_]*)/i,/^(?:"[^"]*")/i,/^(?:[\n]+)/i,/^(?:\})/i,/^(?:.)/i,/^(?:\|o\b)/i,/^(?:\}o\b)/i,/^(?:\}\|)/i,/^(?:\|\|)/i,/^(?:o\|)/i,/^(?:o\{)/i,/^(?:\|\{)/i,/^(?:\.\.)/i,/^(?:--)/i,/^(?:\.-)/i,/^(?:-\.)/i,/^(?:[A-Za-z][A-Za-z0-9\-_]*)/i,/^(?:.)/i,/^(?:$)/i],conditions:{open_directive:{rules:[1],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},block:{rules:[13,14,15,16,17,18,19],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,20,21,22,23,24,25,26,27,28,29,30,31,32,33],inclusive:!0}}};function v(){this.yy={}}return g.lexer=m,v.prototype=g,g.Parser=v,new v}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(8009).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},3602:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,9],n=[1,7],r=[1,6],i=[1,8],a=[1,20,21,22,23,38,47,59,60,79,80,81,82,83,84,88,98,99,102,104,105,111,112,113,114,115,116,117,118,119,120],o=[2,10],s=[1,20],c=[1,21],u=[1,22],l=[1,23],h=[1,30],f=[1,59],d=[1,45],p=[1,49],y=[1,33],g=[1,34],m=[1,35],v=[1,36],b=[1,37],_=[1,53],x=[1,60],w=[1,48],k=[1,50],T=[1,52],E=[1,56],C=[1,57],S=[1,38],A=[1,39],M=[1,40],N=[1,41],D=[1,58],O=[1,47],B=[1,51],L=[1,54],I=[1,55],R=[1,46],F=[1,63],P=[1,68],j=[1,20,21,22,23,38,42,47,59,60,79,80,81,82,83,84,88,98,99,102,104,105,111,112,113,114,115,116,117,118,119,120],Y=[1,72],z=[1,71],U=[1,73],q=[20,21,23,74,75],H=[1,94],$=[1,99],W=[1,102],V=[1,103],G=[1,96],X=[1,101],Z=[1,104],Q=[1,97],K=[1,109],J=[1,108],tt=[1,98],et=[1,100],nt=[1,105],rt=[1,106],it=[1,107],at=[1,110],ot=[20,21,22,23,74,75],st=[20,21,22,23,48,74,75],ct=[20,21,22,23,40,47,48,50,52,54,56,58,59,60,62,64,66,67,69,74,75,84,88,98,99,102,104,105,115,116,117,118,119,120],ut=[20,21,23],lt=[20,21,23,47,59,60,74,75,84,88,98,99,102,104,105,115,116,117,118,119,120],ht=[1,12,20,21,22,23,24,38,42,47,59,60,79,80,81,82,83,84,88,98,99,102,104,105,111,112,113,114,115,116,117,118,119,120],ft=[47,59,60,84,88,98,99,102,104,105,115,116,117,118,119,120],dt=[1,143],pt=[1,151],yt=[1,152],gt=[1,153],mt=[1,154],vt=[1,138],bt=[1,139],_t=[1,135],xt=[1,146],wt=[1,147],kt=[1,148],Tt=[1,149],Et=[1,150],Ct=[1,155],St=[1,156],At=[1,141],Mt=[1,144],Nt=[1,140],Dt=[1,137],Ot=[20,21,22,23,38,42,47,59,60,79,80,81,82,83,84,88,98,99,102,104,105,111,112,113,114,115,116,117,118,119,120],Bt=[1,159],Lt=[20,21,22,23,26,47,59,60,84,98,99,102,104,105,115,116,117,118,119,120],It=[20,21,22,23,24,26,38,40,41,42,47,51,53,55,57,59,60,61,63,65,66,68,70,74,75,79,80,81,82,83,84,85,88,98,99,102,104,105,106,107,115,116,117,118,119,120],Rt=[12,21,22,24],Ft=[22,99],Pt=[1,242],jt=[1,237],Yt=[1,238],zt=[1,246],Ut=[1,243],qt=[1,240],Ht=[1,239],$t=[1,241],Wt=[1,244],Vt=[1,245],Gt=[1,247],Xt=[1,265],Zt=[20,21,23,99],Qt=[20,21,22,23,59,60,79,95,98,99,102,103,104,105,106],Kt={trace:function(){},yy:{},symbols_:{error:2,start:3,mermaidDoc:4,directive:5,openDirective:6,typeDirective:7,closeDirective:8,separator:9,":":10,argDirective:11,open_directive:12,type_directive:13,arg_directive:14,close_directive:15,graphConfig:16,document:17,line:18,statement:19,SEMI:20,NEWLINE:21,SPACE:22,EOF:23,GRAPH:24,NODIR:25,DIR:26,FirstStmtSeperator:27,ending:28,endToken:29,spaceList:30,spaceListNewline:31,verticeStatement:32,styleStatement:33,linkStyleStatement:34,classDefStatement:35,classStatement:36,clickStatement:37,subgraph:38,text:39,SQS:40,SQE:41,end:42,direction:43,link:44,node:45,vertex:46,AMP:47,STYLE_SEPARATOR:48,idString:49,PS:50,PE:51,"(-":52,"-)":53,STADIUMSTART:54,STADIUMEND:55,SUBROUTINESTART:56,SUBROUTINEEND:57,VERTEX_WITH_PROPS_START:58,ALPHA:59,COLON:60,PIPE:61,CYLINDERSTART:62,CYLINDEREND:63,DIAMOND_START:64,DIAMOND_STOP:65,TAGEND:66,TRAPSTART:67,TRAPEND:68,INVTRAPSTART:69,INVTRAPEND:70,linkStatement:71,arrowText:72,TESTSTR:73,START_LINK:74,LINK:75,textToken:76,STR:77,keywords:78,STYLE:79,LINKSTYLE:80,CLASSDEF:81,CLASS:82,CLICK:83,DOWN:84,UP:85,textNoTags:86,textNoTagsToken:87,DEFAULT:88,stylesOpt:89,alphaNum:90,CALLBACKNAME:91,CALLBACKARGS:92,HREF:93,LINK_TARGET:94,HEX:95,numList:96,INTERPOLATE:97,NUM:98,COMMA:99,style:100,styleComponent:101,MINUS:102,UNIT:103,BRKT:104,DOT:105,PCT:106,TAGSTART:107,alphaNumToken:108,idStringToken:109,alphaNumStatement:110,direction_tb:111,direction_bt:112,direction_rl:113,direction_lr:114,PUNCTUATION:115,UNICODE_TEXT:116,PLUS:117,EQUALS:118,MULT:119,UNDERSCORE:120,graphCodeTokens:121,ARROW_CROSS:122,ARROW_POINT:123,ARROW_CIRCLE:124,ARROW_OPEN:125,QUOTE:126,$accept:0,$end:1},terminals_:{2:"error",10:":",12:"open_directive",13:"type_directive",14:"arg_directive",15:"close_directive",20:"SEMI",21:"NEWLINE",22:"SPACE",23:"EOF",24:"GRAPH",25:"NODIR",26:"DIR",38:"subgraph",40:"SQS",41:"SQE",42:"end",47:"AMP",48:"STYLE_SEPARATOR",50:"PS",51:"PE",52:"(-",53:"-)",54:"STADIUMSTART",55:"STADIUMEND",56:"SUBROUTINESTART",57:"SUBROUTINEEND",58:"VERTEX_WITH_PROPS_START",59:"ALPHA",60:"COLON",61:"PIPE",62:"CYLINDERSTART",63:"CYLINDEREND",64:"DIAMOND_START",65:"DIAMOND_STOP",66:"TAGEND",67:"TRAPSTART",68:"TRAPEND",69:"INVTRAPSTART",70:"INVTRAPEND",73:"TESTSTR",74:"START_LINK",75:"LINK",77:"STR",79:"STYLE",80:"LINKSTYLE",81:"CLASSDEF",82:"CLASS",83:"CLICK",84:"DOWN",85:"UP",88:"DEFAULT",91:"CALLBACKNAME",92:"CALLBACKARGS",93:"HREF",94:"LINK_TARGET",95:"HEX",97:"INTERPOLATE",98:"NUM",99:"COMMA",102:"MINUS",103:"UNIT",104:"BRKT",105:"DOT",106:"PCT",107:"TAGSTART",111:"direction_tb",112:"direction_bt",113:"direction_rl",114:"direction_lr",115:"PUNCTUATION",116:"UNICODE_TEXT",117:"PLUS",118:"EQUALS",119:"MULT",120:"UNDERSCORE",122:"ARROW_CROSS",123:"ARROW_POINT",124:"ARROW_CIRCLE",125:"ARROW_OPEN",126:"QUOTE"},productions_:[0,[3,1],[3,2],[5,4],[5,6],[6,1],[7,1],[11,1],[8,1],[4,2],[17,0],[17,2],[18,1],[18,1],[18,1],[18,1],[18,1],[16,2],[16,2],[16,2],[16,3],[28,2],[28,1],[29,1],[29,1],[29,1],[27,1],[27,1],[27,2],[31,2],[31,2],[31,1],[31,1],[30,2],[30,1],[19,2],[19,2],[19,2],[19,2],[19,2],[19,2],[19,9],[19,6],[19,4],[19,1],[9,1],[9,1],[9,1],[32,3],[32,4],[32,2],[32,1],[45,1],[45,5],[45,3],[46,4],[46,6],[46,4],[46,4],[46,4],[46,8],[46,4],[46,4],[46,4],[46,6],[46,4],[46,4],[46,4],[46,4],[46,4],[46,1],[44,2],[44,3],[44,3],[44,1],[44,3],[71,1],[72,3],[39,1],[39,2],[39,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[78,1],[86,1],[86,2],[35,5],[35,5],[36,5],[37,2],[37,4],[37,3],[37,5],[37,2],[37,4],[37,4],[37,6],[37,2],[37,4],[37,2],[37,4],[37,4],[37,6],[33,5],[33,5],[34,5],[34,5],[34,9],[34,9],[34,7],[34,7],[96,1],[96,3],[89,1],[89,3],[100,1],[100,2],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[101,1],[76,1],[76,1],[76,1],[76,1],[76,1],[76,1],[87,1],[87,1],[87,1],[87,1],[49,1],[49,2],[90,1],[90,2],[110,1],[110,1],[110,1],[110,1],[43,1],[43,1],[43,1],[43,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[108,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[109,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1],[121,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 5:r.parseDirective("%%{","open_directive");break;case 6:r.parseDirective(a[s],"type_directive");break;case 7:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 8:r.parseDirective("}%%","close_directive","flowchart");break;case 10:case 36:case 37:case 38:case 39:case 40:this.$=[];break;case 11:a[s]!==[]&&a[s-1].push(a[s]),this.$=a[s-1];break;case 12:case 78:case 80:case 92:case 148:case 150:case 151:case 74:case 146:this.$=a[s];break;case 19:r.setDirection("TB"),this.$="TB";break;case 20:r.setDirection(a[s-1]),this.$=a[s-1];break;case 35:this.$=a[s-1].nodes;break;case 41:this.$=r.addSubGraph(a[s-6],a[s-1],a[s-4]);break;case 42:this.$=r.addSubGraph(a[s-3],a[s-1],a[s-3]);break;case 43:this.$=r.addSubGraph(void 0,a[s-1],void 0);break;case 48:r.addLink(a[s-2].stmt,a[s],a[s-1]),this.$={stmt:a[s],nodes:a[s].concat(a[s-2].nodes)};break;case 49:r.addLink(a[s-3].stmt,a[s-1],a[s-2]),this.$={stmt:a[s-1],nodes:a[s-1].concat(a[s-3].nodes)};break;case 50:this.$={stmt:a[s-1],nodes:a[s-1]};break;case 51:this.$={stmt:a[s],nodes:a[s]};break;case 52:case 119:case 121:this.$=[a[s]];break;case 53:this.$=a[s-4].concat(a[s]);break;case 54:this.$=[a[s-2]],r.setClass(a[s-2],a[s]);break;case 55:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"square");break;case 56:this.$=a[s-5],r.addVertex(a[s-5],a[s-2],"circle");break;case 57:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"ellipse");break;case 58:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"stadium");break;case 59:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"subroutine");break;case 60:this.$=a[s-7],r.addVertex(a[s-7],a[s-1],"rect",void 0,void 0,void 0,Object.fromEntries([[a[s-5],a[s-3]]]));break;case 61:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"cylinder");break;case 62:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"round");break;case 63:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"diamond");break;case 64:this.$=a[s-5],r.addVertex(a[s-5],a[s-2],"hexagon");break;case 65:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"odd");break;case 66:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"trapezoid");break;case 67:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"inv_trapezoid");break;case 68:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"lean_right");break;case 69:this.$=a[s-3],r.addVertex(a[s-3],a[s-1],"lean_left");break;case 70:this.$=a[s],r.addVertex(a[s]);break;case 71:a[s-1].text=a[s],this.$=a[s-1];break;case 72:case 73:a[s-2].text=a[s-1],this.$=a[s-2];break;case 75:var c=r.destructLink(a[s],a[s-2]);this.$={type:c.type,stroke:c.stroke,length:c.length,text:a[s-1]};break;case 76:c=r.destructLink(a[s]),this.$={type:c.type,stroke:c.stroke,length:c.length};break;case 77:this.$=a[s-1];break;case 79:case 93:case 149:case 147:this.$=a[s-1]+""+a[s];break;case 94:case 95:this.$=a[s-4],r.addClass(a[s-2],a[s]);break;case 96:this.$=a[s-4],r.setClass(a[s-2],a[s]);break;case 97:case 105:this.$=a[s-1],r.setClickEvent(a[s-1],a[s]);break;case 98:case 106:this.$=a[s-3],r.setClickEvent(a[s-3],a[s-2]),r.setTooltip(a[s-3],a[s]);break;case 99:this.$=a[s-2],r.setClickEvent(a[s-2],a[s-1],a[s]);break;case 100:this.$=a[s-4],r.setClickEvent(a[s-4],a[s-3],a[s-2]),r.setTooltip(a[s-4],a[s]);break;case 101:case 107:this.$=a[s-1],r.setLink(a[s-1],a[s]);break;case 102:case 108:this.$=a[s-3],r.setLink(a[s-3],a[s-2]),r.setTooltip(a[s-3],a[s]);break;case 103:case 109:this.$=a[s-3],r.setLink(a[s-3],a[s-2],a[s]);break;case 104:case 110:this.$=a[s-5],r.setLink(a[s-5],a[s-4],a[s]),r.setTooltip(a[s-5],a[s-2]);break;case 111:this.$=a[s-4],r.addVertex(a[s-2],void 0,void 0,a[s]);break;case 112:case 114:this.$=a[s-4],r.updateLink(a[s-2],a[s]);break;case 113:this.$=a[s-4],r.updateLink([a[s-2]],a[s]);break;case 115:this.$=a[s-8],r.updateLinkInterpolate([a[s-6]],a[s-2]),r.updateLink([a[s-6]],a[s]);break;case 116:this.$=a[s-8],r.updateLinkInterpolate(a[s-6],a[s-2]),r.updateLink(a[s-6],a[s]);break;case 117:this.$=a[s-6],r.updateLinkInterpolate([a[s-4]],a[s]);break;case 118:this.$=a[s-6],r.updateLinkInterpolate(a[s-4],a[s]);break;case 120:case 122:a[s-2].push(a[s]),this.$=a[s-2];break;case 124:this.$=a[s-1]+a[s];break;case 152:this.$="v";break;case 153:this.$="-";break;case 154:this.$={stmt:"dir",value:"TB"};break;case 155:this.$={stmt:"dir",value:"BT"};break;case 156:this.$={stmt:"dir",value:"RL"};break;case 157:this.$={stmt:"dir",value:"LR"}}},table:[{3:1,4:2,5:3,6:5,12:e,16:4,21:n,22:r,24:i},{1:[3]},{1:[2,1]},{3:10,4:2,5:3,6:5,12:e,16:4,21:n,22:r,24:i},t(a,o,{17:11}),{7:12,13:[1,13]},{16:14,21:n,22:r,24:i},{16:15,21:n,22:r,24:i},{25:[1,16],26:[1,17]},{13:[2,5]},{1:[2,2]},{1:[2,9],18:18,19:19,20:s,21:c,22:u,23:l,32:24,33:25,34:26,35:27,36:28,37:29,38:h,43:31,45:32,46:42,47:f,49:43,59:d,60:p,79:y,80:g,81:m,82:v,83:b,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,111:S,112:A,113:M,114:N,115:D,116:O,117:B,118:L,119:I,120:R},{8:61,10:[1,62],15:F},t([10,15],[2,6]),t(a,[2,17]),t(a,[2,18]),t(a,[2,19]),{20:[1,65],21:[1,66],22:P,27:64,30:67},t(j,[2,11]),t(j,[2,12]),t(j,[2,13]),t(j,[2,14]),t(j,[2,15]),t(j,[2,16]),{9:69,20:Y,21:z,23:U,44:70,71:74,74:[1,75],75:[1,76]},{9:77,20:Y,21:z,23:U},{9:78,20:Y,21:z,23:U},{9:79,20:Y,21:z,23:U},{9:80,20:Y,21:z,23:U},{9:81,20:Y,21:z,23:U},{9:83,20:Y,21:z,22:[1,82],23:U},t(j,[2,44]),t(q,[2,51],{30:84,22:P}),{22:[1,85]},{22:[1,86]},{22:[1,87]},{22:[1,88]},{26:H,47:$,59:W,60:V,77:[1,92],84:G,90:91,91:[1,89],93:[1,90],98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(j,[2,154]),t(j,[2,155]),t(j,[2,156]),t(j,[2,157]),t(ot,[2,52],{48:[1,111]}),t(st,[2,70],{109:123,40:[1,112],47:f,50:[1,113],52:[1,114],54:[1,115],56:[1,116],58:[1,117],59:d,60:p,62:[1,118],64:[1,119],66:[1,120],67:[1,121],69:[1,122],84:_,88:x,98:w,99:k,102:T,104:E,105:C,115:D,116:O,117:B,118:L,119:I,120:R}),t(ct,[2,146]),t(ct,[2,171]),t(ct,[2,172]),t(ct,[2,173]),t(ct,[2,174]),t(ct,[2,175]),t(ct,[2,176]),t(ct,[2,177]),t(ct,[2,178]),t(ct,[2,179]),t(ct,[2,180]),t(ct,[2,181]),t(ct,[2,182]),t(ct,[2,183]),t(ct,[2,184]),t(ct,[2,185]),t(ct,[2,186]),{9:124,20:Y,21:z,23:U},{11:125,14:[1,126]},t(ut,[2,8]),t(a,[2,20]),t(a,[2,26]),t(a,[2,27]),{21:[1,127]},t(lt,[2,34],{30:128,22:P}),t(j,[2,35]),{45:129,46:42,47:f,49:43,59:d,60:p,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,115:D,116:O,117:B,118:L,119:I,120:R},t(ht,[2,45]),t(ht,[2,46]),t(ht,[2,47]),t(ft,[2,74],{72:130,61:[1,132],73:[1,131]}),{22:dt,24:pt,26:yt,38:gt,39:133,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t([47,59,60,61,73,84,88,98,99,102,104,105,115,116,117,118,119,120],[2,76]),t(j,[2,36]),t(j,[2,37]),t(j,[2,38]),t(j,[2,39]),t(j,[2,40]),{22:dt,24:pt,26:yt,38:gt,39:157,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(Ot,o,{17:158}),t(q,[2,50],{47:Bt}),{26:H,47:$,59:W,60:V,84:G,90:160,95:[1,161],98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},{88:[1,162],96:163,98:[1,164]},{26:H,47:$,59:W,60:V,84:G,88:[1,165],90:166,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},{26:H,47:$,59:W,60:V,84:G,90:167,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ut,[2,97],{22:[1,168],92:[1,169]}),t(ut,[2,101],{22:[1,170]}),t(ut,[2,105],{108:95,110:172,22:[1,171],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,115:tt,116:et,117:nt,118:rt,119:it,120:at}),t(ut,[2,107],{22:[1,173]}),t(Lt,[2,148]),t(Lt,[2,150]),t(Lt,[2,151]),t(Lt,[2,152]),t(Lt,[2,153]),t(It,[2,158]),t(It,[2,159]),t(It,[2,160]),t(It,[2,161]),t(It,[2,162]),t(It,[2,163]),t(It,[2,164]),t(It,[2,165]),t(It,[2,166]),t(It,[2,167]),t(It,[2,168]),t(It,[2,169]),t(It,[2,170]),{47:f,49:174,59:d,60:p,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,115:D,116:O,117:B,118:L,119:I,120:R},{22:dt,24:pt,26:yt,38:gt,39:175,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:177,42:mt,47:$,50:[1,176],59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:178,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:179,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:180,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{59:[1,181]},{22:dt,24:pt,26:yt,38:gt,39:182,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:183,42:mt,47:$,59:W,60:V,64:[1,184],66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:185,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:186,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:187,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ct,[2,147]),t(Rt,[2,3]),{8:188,15:F},{15:[2,7]},t(a,[2,28]),t(lt,[2,33]),t(q,[2,48],{30:189,22:P}),t(ft,[2,71],{22:[1,190]}),{22:[1,191]},{22:dt,24:pt,26:yt,38:gt,39:192,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,66:vt,74:bt,75:[1,193],76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(It,[2,78]),t(It,[2,80]),t(It,[2,136]),t(It,[2,137]),t(It,[2,138]),t(It,[2,139]),t(It,[2,140]),t(It,[2,141]),t(It,[2,142]),t(It,[2,143]),t(It,[2,144]),t(It,[2,145]),t(It,[2,81]),t(It,[2,82]),t(It,[2,83]),t(It,[2,84]),t(It,[2,85]),t(It,[2,86]),t(It,[2,87]),t(It,[2,88]),t(It,[2,89]),t(It,[2,90]),t(It,[2,91]),{9:196,20:Y,21:z,22:dt,23:U,24:pt,26:yt,38:gt,40:[1,195],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{18:18,19:19,20:s,21:c,22:u,23:l,32:24,33:25,34:26,35:27,36:28,37:29,38:h,42:[1,197],43:31,45:32,46:42,47:f,49:43,59:d,60:p,79:y,80:g,81:m,82:v,83:b,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,111:S,112:A,113:M,114:N,115:D,116:O,117:B,118:L,119:I,120:R},{22:P,30:198},{22:[1,199],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,108:95,110:172,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:[1,200]},{22:[1,201]},{22:[1,202],99:[1,203]},t(Ft,[2,119]),{22:[1,204]},{22:[1,205],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,108:95,110:172,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:[1,206],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,108:95,110:172,115:tt,116:et,117:nt,118:rt,119:it,120:at},{77:[1,207]},t(ut,[2,99],{22:[1,208]}),{77:[1,209],94:[1,210]},{77:[1,211]},t(Lt,[2,149]),{77:[1,212],94:[1,213]},t(ot,[2,54],{109:123,47:f,59:d,60:p,84:_,88:x,98:w,99:k,102:T,104:E,105:C,115:D,116:O,117:B,118:L,119:I,120:R}),{22:dt,24:pt,26:yt,38:gt,41:[1,214],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:215,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,51:[1,216],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,53:[1,217],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,55:[1,218],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,57:[1,219],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{60:[1,220]},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,63:[1,221],66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,65:[1,222],66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,39:223,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,41:[1,224],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,66:vt,68:[1,225],70:[1,226],74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,66:vt,68:[1,228],70:[1,227],74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{9:229,20:Y,21:z,23:U},t(q,[2,49],{47:Bt}),t(ft,[2,73]),t(ft,[2,72]),{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,61:[1,230],66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ft,[2,75]),t(It,[2,79]),{22:dt,24:pt,26:yt,38:gt,39:231,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(Ot,o,{17:232}),t(j,[2,43]),{46:233,47:f,49:43,59:d,60:p,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,115:D,116:O,117:B,118:L,119:I,120:R},{22:Pt,59:jt,60:Yt,79:zt,89:234,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:248,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:249,95:Ut,97:[1,250],98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:251,95:Ut,97:[1,252],98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{98:[1,253]},{22:Pt,59:jt,60:Yt,79:zt,89:254,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:255,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{26:H,47:$,59:W,60:V,84:G,90:256,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ut,[2,98]),{77:[1,257]},t(ut,[2,102],{22:[1,258]}),t(ut,[2,103]),t(ut,[2,106]),t(ut,[2,108],{22:[1,259]}),t(ut,[2,109]),t(st,[2,55]),{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,51:[1,260],59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(st,[2,62]),t(st,[2,57]),t(st,[2,58]),t(st,[2,59]),{59:[1,261]},t(st,[2,61]),t(st,[2,63]),{22:dt,24:pt,26:yt,38:gt,42:mt,47:$,59:W,60:V,65:[1,262],66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(st,[2,65]),t(st,[2,66]),t(st,[2,68]),t(st,[2,67]),t(st,[2,69]),t(Rt,[2,4]),t([22,47,59,60,84,88,98,99,102,104,105,115,116,117,118,119,120],[2,77]),{22:dt,24:pt,26:yt,38:gt,41:[1,263],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{18:18,19:19,20:s,21:c,22:u,23:l,32:24,33:25,34:26,35:27,36:28,37:29,38:h,42:[1,264],43:31,45:32,46:42,47:f,49:43,59:d,60:p,79:y,80:g,81:m,82:v,83:b,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,111:S,112:A,113:M,114:N,115:D,116:O,117:B,118:L,119:I,120:R},t(ot,[2,53]),t(ut,[2,111],{99:Xt}),t(Zt,[2,121],{101:266,22:Pt,59:jt,60:Yt,79:zt,95:Ut,98:qt,102:Ht,103:$t,104:Wt,105:Vt,106:Gt}),t(Qt,[2,123]),t(Qt,[2,125]),t(Qt,[2,126]),t(Qt,[2,127]),t(Qt,[2,128]),t(Qt,[2,129]),t(Qt,[2,130]),t(Qt,[2,131]),t(Qt,[2,132]),t(Qt,[2,133]),t(Qt,[2,134]),t(Qt,[2,135]),t(ut,[2,112],{99:Xt}),t(ut,[2,113],{99:Xt}),{22:[1,267]},t(ut,[2,114],{99:Xt}),{22:[1,268]},t(Ft,[2,120]),t(ut,[2,94],{99:Xt}),t(ut,[2,95],{99:Xt}),t(ut,[2,96],{108:95,110:172,26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,115:tt,116:et,117:nt,118:rt,119:it,120:at}),t(ut,[2,100]),{94:[1,269]},{94:[1,270]},{51:[1,271]},{61:[1,272]},{65:[1,273]},{9:274,20:Y,21:z,23:U},t(j,[2,42]),{22:Pt,59:jt,60:Yt,79:zt,95:Ut,98:qt,100:275,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},t(Qt,[2,124]),{26:H,47:$,59:W,60:V,84:G,90:276,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},{26:H,47:$,59:W,60:V,84:G,90:277,98:X,99:Z,102:Q,104:K,105:J,108:95,110:93,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(ut,[2,104]),t(ut,[2,110]),t(st,[2,56]),{22:dt,24:pt,26:yt,38:gt,39:278,42:mt,47:$,59:W,60:V,66:vt,74:bt,76:134,77:_t,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},t(st,[2,64]),t(Ot,o,{17:279}),t(Zt,[2,122],{101:266,22:Pt,59:jt,60:Yt,79:zt,95:Ut,98:qt,102:Ht,103:$t,104:Wt,105:Vt,106:Gt}),t(ut,[2,117],{108:95,110:172,22:[1,280],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,115:tt,116:et,117:nt,118:rt,119:it,120:at}),t(ut,[2,118],{108:95,110:172,22:[1,281],26:H,47:$,59:W,60:V,84:G,98:X,99:Z,102:Q,104:K,105:J,115:tt,116:et,117:nt,118:rt,119:it,120:at}),{22:dt,24:pt,26:yt,38:gt,41:[1,282],42:mt,47:$,59:W,60:V,66:vt,74:bt,76:194,78:145,79:xt,80:wt,81:kt,82:Tt,83:Et,84:Ct,85:St,87:136,88:At,98:X,99:Z,102:Mt,104:K,105:J,106:Nt,107:Dt,108:142,115:tt,116:et,117:nt,118:rt,119:it,120:at},{18:18,19:19,20:s,21:c,22:u,23:l,32:24,33:25,34:26,35:27,36:28,37:29,38:h,42:[1,283],43:31,45:32,46:42,47:f,49:43,59:d,60:p,79:y,80:g,81:m,82:v,83:b,84:_,88:x,98:w,99:k,102:T,104:E,105:C,109:44,111:S,112:A,113:M,114:N,115:D,116:O,117:B,118:L,119:I,120:R},{22:Pt,59:jt,60:Yt,79:zt,89:284,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},{22:Pt,59:jt,60:Yt,79:zt,89:285,95:Ut,98:qt,100:235,101:236,102:Ht,103:$t,104:Wt,105:Vt,106:Gt},t(st,[2,60]),t(j,[2,41]),t(ut,[2,115],{99:Xt}),t(ut,[2,116],{99:Xt})],defaultActions:{2:[2,1],9:[2,5],10:[2,2],126:[2,7]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},Jt={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),12;case 1:return this.begin("type_directive"),13;case 2:return this.popState(),this.begin("arg_directive"),10;case 3:return this.popState(),this.popState(),15;case 4:return 14;case 5:case 6:break;case 7:this.begin("string");break;case 8:case 17:case 20:case 23:case 26:this.popState();break;case 9:return"STR";case 10:return 79;case 11:return 88;case 12:return 80;case 13:return 97;case 14:return 81;case 15:return 82;case 16:this.begin("href");break;case 18:return 93;case 19:this.begin("callbackname");break;case 21:this.popState(),this.begin("callbackargs");break;case 22:return 91;case 24:return 92;case 25:this.begin("click");break;case 27:return 83;case 28:case 29:return t.lex.firstGraph()&&this.begin("dir"),24;case 30:return 38;case 31:return 42;case 32:case 33:case 34:case 35:return 94;case 36:return this.popState(),25;case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 45:case 46:return this.popState(),26;case 47:return 111;case 48:return 112;case 49:return 113;case 50:return 114;case 51:return 98;case 52:return 104;case 53:return 48;case 54:return 60;case 55:return 47;case 56:return 20;case 57:return 99;case 58:return 119;case 59:case 60:case 61:return 75;case 62:case 63:case 64:return 74;case 65:return 52;case 66:return 53;case 67:return 54;case 68:return 55;case 69:return 56;case 70:return 57;case 71:return 58;case 72:return 62;case 73:return 63;case 74:return 102;case 75:return 105;case 76:return 120;case 77:return 117;case 78:return 106;case 79:case 80:return 118;case 81:return 107;case 82:return 66;case 83:return 85;case 84:return"SEP";case 85:return 84;case 86:return 59;case 87:return 68;case 88:return 67;case 89:return 70;case 90:return 69;case 91:return 115;case 92:return 116;case 93:return 61;case 94:return 50;case 95:return 51;case 96:return 40;case 97:return 41;case 98:return 64;case 99:return 65;case 100:return 126;case 101:return 21;case 102:return 22;case 103:return 23}},rules:[/^(?:%%\{)/,/^(?:((?:(?!\}%%)[^:.])*))/,/^(?::)/,/^(?:\}%%)/,/^(?:((?:(?!\}%%).|\n)*))/,/^(?:%%(?!\{)[^\n]*)/,/^(?:[^\}]%%[^\n]*)/,/^(?:["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:style\b)/,/^(?:default\b)/,/^(?:linkStyle\b)/,/^(?:interpolate\b)/,/^(?:classDef\b)/,/^(?:class\b)/,/^(?:href[\s]+["])/,/^(?:["])/,/^(?:[^"]*)/,/^(?:call[\s]+)/,/^(?:\([\s]*\))/,/^(?:\()/,/^(?:[^(]*)/,/^(?:\))/,/^(?:[^)]*)/,/^(?:click[\s]+)/,/^(?:[\s\n])/,/^(?:[^\s\n]*)/,/^(?:graph\b)/,/^(?:flowchart\b)/,/^(?:subgraph\b)/,/^(?:end\b\s*)/,/^(?:_self\b)/,/^(?:_blank\b)/,/^(?:_parent\b)/,/^(?:_top\b)/,/^(?:(\r?\n)*\s*\n)/,/^(?:\s*LR\b)/,/^(?:\s*RL\b)/,/^(?:\s*TB\b)/,/^(?:\s*BT\b)/,/^(?:\s*TD\b)/,/^(?:\s*BR\b)/,/^(?:\s*<)/,/^(?:\s*>)/,/^(?:\s*\^)/,/^(?:\s*v\b)/,/^(?:.*direction\s+TB[^\n]*)/,/^(?:.*direction\s+BT[^\n]*)/,/^(?:.*direction\s+RL[^\n]*)/,/^(?:.*direction\s+LR[^\n]*)/,/^(?:[0-9]+)/,/^(?:#)/,/^(?::::)/,/^(?::)/,/^(?:&)/,/^(?:;)/,/^(?:,)/,/^(?:\*)/,/^(?:\s*[xo<]?--+[-xo>]\s*)/,/^(?:\s*[xo<]?==+[=xo>]\s*)/,/^(?:\s*[xo<]?-?\.+-[xo>]?\s*)/,/^(?:\s*[xo<]?--\s*)/,/^(?:\s*[xo<]?==\s*)/,/^(?:\s*[xo<]?-\.\s*)/,/^(?:\(-)/,/^(?:-\))/,/^(?:\(\[)/,/^(?:\]\))/,/^(?:\[\[)/,/^(?:\]\])/,/^(?:\[\|)/,/^(?:\[\()/,/^(?:\)\])/,/^(?:-)/,/^(?:\.)/,/^(?:[\_])/,/^(?:\+)/,/^(?:%)/,/^(?:=)/,/^(?:=)/,/^(?:<)/,/^(?:>)/,/^(?:\^)/,/^(?:\\\|)/,/^(?:v\b)/,/^(?:[A-Za-z]+)/,/^(?:\\\])/,/^(?:\[\/)/,/^(?:\/\])/,/^(?:\[\\)/,/^(?:[!"#$%&'*+,-.`?\\_/])/,/^(?:[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6]|[\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377]|[\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5]|[\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA]|[\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE]|[\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA]|[\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0]|[\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977]|[\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2]|[\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A]|[\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39]|[\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8]|[\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C]|[\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C]|[\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99]|[\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0]|[\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D]|[\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3]|[\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10]|[\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1]|[\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81]|[\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3]|[\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6]|[\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A]|[\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081]|[\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D]|[\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0]|[\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310]|[\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C]|[\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711]|[\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7]|[\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C]|[\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16]|[\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF]|[\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC]|[\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D]|[\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D]|[\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3]|[\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F]|[\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128]|[\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184]|[\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3]|[\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6]|[\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE]|[\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C]|[\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D]|[\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC]|[\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B]|[\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788]|[\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805]|[\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB]|[\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28]|[\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5]|[\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4]|[\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E]|[\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D]|[\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36]|[\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D]|[\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]|[\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF]|[\uFFD2-\uFFD7\uFFDA-\uFFDC])/,/^(?:\|)/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:\{)/,/^(?:\})/,/^(?:")/,/^(?:(\r?\n)+)/,/^(?:\s)/,/^(?:$)/],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},callbackargs:{rules:[23,24],inclusive:!1},callbackname:{rules:[20,21,22],inclusive:!1},href:{rules:[17,18],inclusive:!1},click:{rules:[26,27],inclusive:!1},vertex:{rules:[],inclusive:!1},dir:{rules:[36,37,38,39,40,41,42,43,44,45,46],inclusive:!1},string:{rules:[8,9],inclusive:!1},INITIAL:{rules:[0,5,6,7,10,11,12,13,14,15,16,19,25,28,29,30,31,32,33,34,35,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103],inclusive:!0}}};function te(){this.yy={}}return Kt.lexer=Jt,te.prototype=Kt,Kt.Parser=te,new te}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(5354).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},9959:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,3],n=[1,5],r=[7,9,11,12,13,14,15,16,17,18,19,20,22,29,34],i=[1,15],a=[1,16],o=[1,17],s=[1,18],c=[1,19],u=[1,20],l=[1,21],h=[1,22],f=[1,23],d=[1,25],p=[1,27],y=[1,30],g=[5,7,9,11,12,13,14,15,16,17,18,19,20,22,29,34],m={trace:function(){},yy:{},symbols_:{error:2,start:3,directive:4,gantt:5,document:6,EOF:7,line:8,SPACE:9,statement:10,NL:11,dateFormat:12,inclusiveEndDates:13,topAxis:14,axisFormat:15,excludes:16,includes:17,todayMarker:18,title:19,section:20,clickStatement:21,taskTxt:22,taskData:23,openDirective:24,typeDirective:25,closeDirective:26,":":27,argDirective:28,click:29,callbackname:30,callbackargs:31,href:32,clickStatementDebug:33,open_directive:34,type_directive:35,arg_directive:36,close_directive:37,$accept:0,$end:1},terminals_:{2:"error",5:"gantt",7:"EOF",9:"SPACE",11:"NL",12:"dateFormat",13:"inclusiveEndDates",14:"topAxis",15:"axisFormat",16:"excludes",17:"includes",18:"todayMarker",19:"title",20:"section",22:"taskTxt",23:"taskData",27:":",29:"click",30:"callbackname",31:"callbackargs",32:"href",34:"open_directive",35:"type_directive",36:"arg_directive",37:"close_directive"},productions_:[0,[3,2],[3,3],[6,0],[6,2],[8,2],[8,1],[8,1],[8,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,1],[10,2],[10,1],[4,4],[4,6],[21,2],[21,3],[21,3],[21,4],[21,3],[21,4],[21,2],[33,2],[33,3],[33,3],[33,4],[33,3],[33,4],[33,2],[24,1],[25,1],[28,1],[26,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 2:return a[s-1];case 3:case 7:case 8:this.$=[];break;case 4:a[s-1].push(a[s]),this.$=a[s-1];break;case 5:case 6:this.$=a[s];break;case 9:r.setDateFormat(a[s].substr(11)),this.$=a[s].substr(11);break;case 10:r.enableInclusiveEndDates(),this.$=a[s].substr(18);break;case 11:r.TopAxis(),this.$=a[s].substr(8);break;case 12:r.setAxisFormat(a[s].substr(11)),this.$=a[s].substr(11);break;case 13:r.setExcludes(a[s].substr(9)),this.$=a[s].substr(9);break;case 14:r.setIncludes(a[s].substr(9)),this.$=a[s].substr(9);break;case 15:r.setTodayMarker(a[s].substr(12)),this.$=a[s].substr(12);break;case 16:r.setTitle(a[s].substr(6)),this.$=a[s].substr(6);break;case 17:r.addSection(a[s].substr(8)),this.$=a[s].substr(8);break;case 19:r.addTask(a[s-1],a[s]),this.$="task";break;case 23:this.$=a[s-1],r.setClickEvent(a[s-1],a[s],null);break;case 24:this.$=a[s-2],r.setClickEvent(a[s-2],a[s-1],a[s]);break;case 25:this.$=a[s-2],r.setClickEvent(a[s-2],a[s-1],null),r.setLink(a[s-2],a[s]);break;case 26:this.$=a[s-3],r.setClickEvent(a[s-3],a[s-2],a[s-1]),r.setLink(a[s-3],a[s]);break;case 27:this.$=a[s-2],r.setClickEvent(a[s-2],a[s],null),r.setLink(a[s-2],a[s-1]);break;case 28:this.$=a[s-3],r.setClickEvent(a[s-3],a[s-1],a[s]),r.setLink(a[s-3],a[s-2]);break;case 29:this.$=a[s-1],r.setLink(a[s-1],a[s]);break;case 30:case 36:this.$=a[s-1]+" "+a[s];break;case 31:case 32:case 34:this.$=a[s-2]+" "+a[s-1]+" "+a[s];break;case 33:case 35:this.$=a[s-3]+" "+a[s-2]+" "+a[s-1]+" "+a[s];break;case 37:r.parseDirective("%%{","open_directive");break;case 38:r.parseDirective(a[s],"type_directive");break;case 39:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 40:r.parseDirective("}%%","close_directive","gantt")}},table:[{3:1,4:2,5:e,24:4,34:n},{1:[3]},{3:6,4:2,5:e,24:4,34:n},t(r,[2,3],{6:7}),{25:8,35:[1,9]},{35:[2,37]},{1:[2,1]},{4:26,7:[1,10],8:11,9:[1,12],10:13,11:[1,14],12:i,13:a,14:o,15:s,16:c,17:u,18:l,19:h,20:f,21:24,22:d,24:4,29:p,34:n},{26:28,27:[1,29],37:y},t([27,37],[2,38]),t(r,[2,8],{1:[2,2]}),t(r,[2,4]),{4:26,10:31,12:i,13:a,14:o,15:s,16:c,17:u,18:l,19:h,20:f,21:24,22:d,24:4,29:p,34:n},t(r,[2,6]),t(r,[2,7]),t(r,[2,9]),t(r,[2,10]),t(r,[2,11]),t(r,[2,12]),t(r,[2,13]),t(r,[2,14]),t(r,[2,15]),t(r,[2,16]),t(r,[2,17]),t(r,[2,18]),{23:[1,32]},t(r,[2,20]),{30:[1,33],32:[1,34]},{11:[1,35]},{28:36,36:[1,37]},{11:[2,40]},t(r,[2,5]),t(r,[2,19]),t(r,[2,23],{31:[1,38],32:[1,39]}),t(r,[2,29],{30:[1,40]}),t(g,[2,21]),{26:41,37:y},{37:[2,39]},t(r,[2,24],{32:[1,42]}),t(r,[2,25]),t(r,[2,27],{31:[1,43]}),{11:[1,44]},t(r,[2,26]),t(r,[2,28]),t(g,[2,22])],defaultActions:{5:[2,37],6:[2,1],30:[2,40],37:[2,39]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},v={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),34;case 1:return this.begin("type_directive"),35;case 2:return this.popState(),this.begin("arg_directive"),27;case 3:return this.popState(),this.popState(),37;case 4:return 36;case 5:case 6:case 7:case 9:case 10:case 11:break;case 8:return 11;case 12:this.begin("href");break;case 13:case 16:case 19:case 22:this.popState();break;case 14:return 32;case 15:this.begin("callbackname");break;case 17:this.popState(),this.begin("callbackargs");break;case 18:return 30;case 20:return 31;case 21:this.begin("click");break;case 23:return 29;case 24:return 5;case 25:return 12;case 26:return 13;case 27:return 14;case 28:return 15;case 29:return 17;case 30:return 16;case 31:return 18;case 32:return"date";case 33:return 19;case 34:return 20;case 35:return 22;case 36:return 23;case 37:return 27;case 38:return 7;case 39:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)*[^\n]*)/i,/^(?:[^\}]%%*[^\n]*)/i,/^(?:%%*[^\n]*[\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:href[\s]+["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:call[\s]+)/i,/^(?:\([\s]*\))/i,/^(?:\()/i,/^(?:[^(]*)/i,/^(?:\))/i,/^(?:[^)]*)/i,/^(?:click[\s]+)/i,/^(?:[\s\n])/i,/^(?:[^\s\n]*)/i,/^(?:gantt\b)/i,/^(?:dateFormat\s[^#\n;]+)/i,/^(?:inclusiveEndDates\b)/i,/^(?:topAxis\b)/i,/^(?:axisFormat\s[^#\n;]+)/i,/^(?:includes\s[^#\n;]+)/i,/^(?:excludes\s[^#\n;]+)/i,/^(?:todayMarker\s[^\n;]+)/i,/^(?:\d\d\d\d-\d\d-\d\d\b)/i,/^(?:title\s[^#\n;]+)/i,/^(?:section\s[^#:\n;]+)/i,/^(?:[^#:\n;]+)/i,/^(?::[^#\n;]+)/i,/^(?::)/i,/^(?:$)/i,/^(?:.)/i],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},callbackargs:{rules:[19,20],inclusive:!1},callbackname:{rules:[16,17,18],inclusive:!1},href:{rules:[13,14],inclusive:!1},click:{rules:[22,23],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,15,21,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39],inclusive:!0}}};function b(){this.yy={}}return m.lexer=v,b.prototype=m,m.Parser=b,new b}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(6878).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},2553:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[2,3],n=[1,7],r=[7,12,15,17,19,20,21],i=[7,11,12,15,17,19,20,21],a=[2,20],o=[1,32],s={trace:function(){},yy:{},symbols_:{error:2,start:3,GG:4,":":5,document:6,EOF:7,DIR:8,options:9,body:10,OPT:11,NL:12,line:13,statement:14,COMMIT:15,commit_arg:16,BRANCH:17,ID:18,CHECKOUT:19,MERGE:20,RESET:21,reset_arg:22,STR:23,HEAD:24,reset_parents:25,CARET:26,$accept:0,$end:1},terminals_:{2:"error",4:"GG",5:":",7:"EOF",8:"DIR",11:"OPT",12:"NL",15:"COMMIT",17:"BRANCH",18:"ID",19:"CHECKOUT",20:"MERGE",21:"RESET",23:"STR",24:"HEAD",26:"CARET"},productions_:[0,[3,4],[3,5],[6,0],[6,2],[9,2],[9,1],[10,0],[10,2],[13,2],[13,1],[14,2],[14,2],[14,2],[14,2],[14,2],[16,0],[16,1],[22,2],[22,2],[25,0],[25,2]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 1:return a[s-1];case 2:return r.setDirection(a[s-3]),a[s-1];case 4:r.setOptions(a[s-1]),this.$=a[s];break;case 5:a[s-1]+=a[s],this.$=a[s-1];break;case 7:this.$=[];break;case 8:a[s-1].push(a[s]),this.$=a[s-1];break;case 9:this.$=a[s-1];break;case 11:r.commit(a[s]);break;case 12:r.branch(a[s]);break;case 13:r.checkout(a[s]);break;case 14:r.merge(a[s]);break;case 15:r.reset(a[s]);break;case 16:this.$="";break;case 17:this.$=a[s];break;case 18:this.$=a[s-1]+":"+a[s];break;case 19:this.$=a[s-1]+":"+r.count,r.count=0;break;case 20:r.count=0;break;case 21:r.count+=1}},table:[{3:1,4:[1,2]},{1:[3]},{5:[1,3],8:[1,4]},{6:5,7:e,9:6,12:n},{5:[1,8]},{7:[1,9]},t(r,[2,7],{10:10,11:[1,11]}),t(i,[2,6]),{6:12,7:e,9:6,12:n},{1:[2,1]},{7:[2,4],12:[1,15],13:13,14:14,15:[1,16],17:[1,17],19:[1,18],20:[1,19],21:[1,20]},t(i,[2,5]),{7:[1,21]},t(r,[2,8]),{12:[1,22]},t(r,[2,10]),{12:[2,16],16:23,23:[1,24]},{18:[1,25]},{18:[1,26]},{18:[1,27]},{18:[1,30],22:28,24:[1,29]},{1:[2,2]},t(r,[2,9]),{12:[2,11]},{12:[2,17]},{12:[2,12]},{12:[2,13]},{12:[2,14]},{12:[2,15]},{12:a,25:31,26:o},{12:a,25:33,26:o},{12:[2,18]},{12:a,25:34,26:o},{12:[2,19]},{12:[2,21]}],defaultActions:{9:[2,1],21:[2,2],23:[2,11],24:[2,17],25:[2,12],26:[2,13],27:[2,14],28:[2,15],31:[2,18],33:[2,19],34:[2,21]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},c={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return 12;case 1:case 2:case 3:break;case 4:return 4;case 5:return 15;case 6:return 17;case 7:return 20;case 8:return 21;case 9:return 19;case 10:case 11:return 8;case 12:return 5;case 13:return 26;case 14:this.begin("options");break;case 15:case 18:this.popState();break;case 16:return 11;case 17:this.begin("string");break;case 19:return 23;case 20:return 18;case 21:return 7}},rules:[/^(?:(\r?\n)+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:gitGraph\b)/i,/^(?:commit\b)/i,/^(?:branch\b)/i,/^(?:merge\b)/i,/^(?:reset\b)/i,/^(?:checkout\b)/i,/^(?:LR\b)/i,/^(?:BT\b)/i,/^(?::)/i,/^(?:\^)/i,/^(?:options\r?\n)/i,/^(?:end\r?\n)/i,/^(?:[^\n]+\r?\n)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[a-zA-Z][-_\.a-zA-Z0-9]*[-_a-zA-Z0-9])/i,/^(?:$)/i],conditions:{options:{rules:[15,16],inclusive:!1},string:{rules:[18,19],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,20,21],inclusive:!0}}};function u(){this.yy={}}return s.lexer=c,u.prototype=s,s.Parser=u,new u}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(8183).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},6765:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[6,9,10],n={trace:function(){},yy:{},symbols_:{error:2,start:3,info:4,document:5,EOF:6,line:7,statement:8,NL:9,showInfo:10,$accept:0,$end:1},terminals_:{2:"error",4:"info",6:"EOF",9:"NL",10:"showInfo"},productions_:[0,[3,3],[5,0],[5,2],[7,1],[7,1],[8,1]],performAction:function(t,e,n,r,i,a,o){switch(a.length,i){case 1:return r;case 4:break;case 6:r.setInfo(!0)}},table:[{3:1,4:[1,2]},{1:[3]},t(e,[2,2],{5:3}),{6:[1,4],7:5,8:6,9:[1,7],10:[1,8]},{1:[2,1]},t(e,[2,3]),t(e,[2,4]),t(e,[2,5]),t(e,[2,6])],defaultActions:{4:[2,1]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},r={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return 4;case 1:return 9;case 2:return"space";case 3:return 10;case 4:return 6;case 5:return"TXT"}},rules:[/^(?:info\b)/i,/^(?:[\s\n\r]+)/i,/^(?:[\s]+)/i,/^(?:showInfo\b)/i,/^(?:$)/i,/^(?:.)/i],conditions:{INITIAL:{rules:[0,1,2,3,4,5],inclusive:!0}}};function i(){this.yy={}}return n.lexer=r,i.prototype=n,n.Parser=i,new i}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(1428).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},7062:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,4],n=[1,5],r=[1,6],i=[1,7],a=[1,9],o=[1,11,13,20,21,22,23],s=[2,5],c=[1,6,11,13,20,21,22,23],u=[20,21,22],l=[2,8],h=[1,18],f=[1,19],d=[1,24],p=[6,20,21,22,23],y={trace:function(){},yy:{},symbols_:{error:2,start:3,eol:4,directive:5,PIE:6,document:7,showData:8,line:9,statement:10,txt:11,value:12,title:13,title_value:14,openDirective:15,typeDirective:16,closeDirective:17,":":18,argDirective:19,NEWLINE:20,";":21,EOF:22,open_directive:23,type_directive:24,arg_directive:25,close_directive:26,$accept:0,$end:1},terminals_:{2:"error",6:"PIE",8:"showData",11:"txt",12:"value",13:"title",14:"title_value",18:":",20:"NEWLINE",21:";",22:"EOF",23:"open_directive",24:"type_directive",25:"arg_directive",26:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,3],[7,0],[7,2],[9,2],[10,0],[10,2],[10,2],[10,1],[5,3],[5,5],[4,1],[4,1],[4,1],[15,1],[16,1],[19,1],[17,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 4:r.setShowData(!0);break;case 7:this.$=a[s-1];break;case 9:r.addSection(a[s-1],r.cleanupValue(a[s]));break;case 10:this.$=a[s].trim(),r.setTitle(this.$);break;case 17:r.parseDirective("%%{","open_directive");break;case 18:r.parseDirective(a[s],"type_directive");break;case 19:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 20:r.parseDirective("}%%","close_directive","pie")}},table:[{3:1,4:2,5:3,6:e,15:8,20:n,21:r,22:i,23:a},{1:[3]},{3:10,4:2,5:3,6:e,15:8,20:n,21:r,22:i,23:a},{3:11,4:2,5:3,6:e,15:8,20:n,21:r,22:i,23:a},t(o,s,{7:12,8:[1,13]}),t(c,[2,14]),t(c,[2,15]),t(c,[2,16]),{16:14,24:[1,15]},{24:[2,17]},{1:[2,1]},{1:[2,2]},t(u,l,{15:8,9:16,10:17,5:20,1:[2,3],11:h,13:f,23:a}),t(o,s,{7:21}),{17:22,18:[1,23],26:d},t([18,26],[2,18]),t(o,[2,6]),{4:25,20:n,21:r,22:i},{12:[1,26]},{14:[1,27]},t(u,[2,11]),t(u,l,{15:8,9:16,10:17,5:20,1:[2,4],11:h,13:f,23:a}),t(p,[2,12]),{19:28,25:[1,29]},t(p,[2,20]),t(o,[2,7]),t(u,[2,9]),t(u,[2,10]),{17:30,26:d},{26:[2,19]},t(p,[2,13])],defaultActions:{9:[2,17],10:[2,1],11:[2,2],29:[2,19]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},g={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),23;case 1:return this.begin("type_directive"),24;case 2:return this.popState(),this.begin("arg_directive"),18;case 3:return this.popState(),this.popState(),26;case 4:return 25;case 5:case 6:case 8:case 9:break;case 7:return 20;case 10:return this.begin("title"),13;case 11:return this.popState(),"title_value";case 12:this.begin("string");break;case 13:this.popState();break;case 14:return"txt";case 15:return 6;case 16:return 8;case 17:return"value";case 18:return 22}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n\r]+)/i,/^(?:%%[^\n]*)/i,/^(?:[\s]+)/i,/^(?:title\b)/i,/^(?:(?!\n||)*[^\n]*)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:pie\b)/i,/^(?:showData\b)/i,/^(?::[\s]*[\d]+(?:\.[\d]+)?)/i,/^(?:$)/i],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},title:{rules:[11],inclusive:!1},string:{rules:[13,14],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,12,15,16,17,18],inclusive:!0}}};function m(){this.yy={}}return y.lexer=g,m.prototype=y,y.Parser=m,new m}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(4551).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},3176:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,3],n=[1,5],r=[1,17],i=[2,10],a=[1,21],o=[1,22],s=[1,23],c=[1,24],u=[1,25],l=[1,26],h=[1,19],f=[1,27],d=[1,28],p=[1,31],y=[66,67],g=[5,8,14,35,36,37,38,39,40,48,55,57,66,67],m=[5,6,8,14,35,36,37,38,39,40,48,66,67],v=[1,51],b=[1,52],_=[1,53],x=[1,54],w=[1,55],k=[1,56],T=[1,57],E=[57,58],C=[1,69],S=[1,65],A=[1,66],M=[1,67],N=[1,68],D=[1,70],O=[1,74],B=[1,75],L=[1,72],I=[1,73],R=[5,8,14,35,36,37,38,39,40,48,66,67],F={trace:function(){},yy:{},symbols_:{error:2,start:3,directive:4,NEWLINE:5,RD:6,diagram:7,EOF:8,openDirective:9,typeDirective:10,closeDirective:11,":":12,argDirective:13,open_directive:14,type_directive:15,arg_directive:16,close_directive:17,requirementDef:18,elementDef:19,relationshipDef:20,requirementType:21,requirementName:22,STRUCT_START:23,requirementBody:24,ID:25,COLONSEP:26,id:27,TEXT:28,text:29,RISK:30,riskLevel:31,VERIFYMTHD:32,verifyType:33,STRUCT_STOP:34,REQUIREMENT:35,FUNCTIONAL_REQUIREMENT:36,INTERFACE_REQUIREMENT:37,PERFORMANCE_REQUIREMENT:38,PHYSICAL_REQUIREMENT:39,DESIGN_CONSTRAINT:40,LOW_RISK:41,MED_RISK:42,HIGH_RISK:43,VERIFY_ANALYSIS:44,VERIFY_DEMONSTRATION:45,VERIFY_INSPECTION:46,VERIFY_TEST:47,ELEMENT:48,elementName:49,elementBody:50,TYPE:51,type:52,DOCREF:53,ref:54,END_ARROW_L:55,relationship:56,LINE:57,END_ARROW_R:58,CONTAINS:59,COPIES:60,DERIVES:61,SATISFIES:62,VERIFIES:63,REFINES:64,TRACES:65,unqString:66,qString:67,$accept:0,$end:1},terminals_:{2:"error",5:"NEWLINE",6:"RD",8:"EOF",12:":",14:"open_directive",15:"type_directive",16:"arg_directive",17:"close_directive",23:"STRUCT_START",25:"ID",26:"COLONSEP",28:"TEXT",30:"RISK",32:"VERIFYMTHD",34:"STRUCT_STOP",35:"REQUIREMENT",36:"FUNCTIONAL_REQUIREMENT",37:"INTERFACE_REQUIREMENT",38:"PERFORMANCE_REQUIREMENT",39:"PHYSICAL_REQUIREMENT",40:"DESIGN_CONSTRAINT",41:"LOW_RISK",42:"MED_RISK",43:"HIGH_RISK",44:"VERIFY_ANALYSIS",45:"VERIFY_DEMONSTRATION",46:"VERIFY_INSPECTION",47:"VERIFY_TEST",48:"ELEMENT",51:"TYPE",53:"DOCREF",55:"END_ARROW_L",57:"LINE",58:"END_ARROW_R",59:"CONTAINS",60:"COPIES",61:"DERIVES",62:"SATISFIES",63:"VERIFIES",64:"REFINES",65:"TRACES",66:"unqString",67:"qString"},productions_:[0,[3,3],[3,2],[3,4],[4,3],[4,5],[9,1],[10,1],[13,1],[11,1],[7,0],[7,2],[7,2],[7,2],[7,2],[7,2],[18,5],[24,5],[24,5],[24,5],[24,5],[24,2],[24,1],[21,1],[21,1],[21,1],[21,1],[21,1],[21,1],[31,1],[31,1],[31,1],[33,1],[33,1],[33,1],[33,1],[19,5],[50,5],[50,5],[50,2],[50,1],[20,5],[20,5],[56,1],[56,1],[56,1],[56,1],[56,1],[56,1],[56,1],[22,1],[22,1],[27,1],[27,1],[29,1],[29,1],[49,1],[49,1],[52,1],[52,1],[54,1],[54,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 6:r.parseDirective("%%{","open_directive");break;case 7:r.parseDirective(a[s],"type_directive");break;case 8:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 9:r.parseDirective("}%%","close_directive","pie");break;case 10:this.$=[];break;case 16:r.addRequirement(a[s-3],a[s-4]);break;case 17:r.setNewReqId(a[s-2]);break;case 18:r.setNewReqText(a[s-2]);break;case 19:r.setNewReqRisk(a[s-2]);break;case 20:r.setNewReqVerifyMethod(a[s-2]);break;case 23:this.$=r.RequirementType.REQUIREMENT;break;case 24:this.$=r.RequirementType.FUNCTIONAL_REQUIREMENT;break;case 25:this.$=r.RequirementType.INTERFACE_REQUIREMENT;break;case 26:this.$=r.RequirementType.PERFORMANCE_REQUIREMENT;break;case 27:this.$=r.RequirementType.PHYSICAL_REQUIREMENT;break;case 28:this.$=r.RequirementType.DESIGN_CONSTRAINT;break;case 29:this.$=r.RiskLevel.LOW_RISK;break;case 30:this.$=r.RiskLevel.MED_RISK;break;case 31:this.$=r.RiskLevel.HIGH_RISK;break;case 32:this.$=r.VerifyType.VERIFY_ANALYSIS;break;case 33:this.$=r.VerifyType.VERIFY_DEMONSTRATION;break;case 34:this.$=r.VerifyType.VERIFY_INSPECTION;break;case 35:this.$=r.VerifyType.VERIFY_TEST;break;case 36:r.addElement(a[s-3]);break;case 37:r.setNewElementType(a[s-2]);break;case 38:r.setNewElementDocRef(a[s-2]);break;case 41:r.addRelationship(a[s-2],a[s],a[s-4]);break;case 42:r.addRelationship(a[s-2],a[s-4],a[s]);break;case 43:this.$=r.Relationships.CONTAINS;break;case 44:this.$=r.Relationships.COPIES;break;case 45:this.$=r.Relationships.DERIVES;break;case 46:this.$=r.Relationships.SATISFIES;break;case 47:this.$=r.Relationships.VERIFIES;break;case 48:this.$=r.Relationships.REFINES;break;case 49:this.$=r.Relationships.TRACES}},table:[{3:1,4:2,6:e,9:4,14:n},{1:[3]},{3:7,4:2,5:[1,6],6:e,9:4,14:n},{5:[1,8]},{10:9,15:[1,10]},{15:[2,6]},{3:11,4:2,6:e,9:4,14:n},{1:[2,2]},{4:16,5:r,7:12,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{11:29,12:[1,30],17:p},t([12,17],[2,7]),{1:[2,1]},{8:[1,32]},{4:16,5:r,7:33,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{4:16,5:r,7:34,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{4:16,5:r,7:35,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{4:16,5:r,7:36,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{4:16,5:r,7:37,8:i,9:4,14:n,18:13,19:14,20:15,21:18,27:20,35:a,36:o,37:s,38:c,39:u,40:l,48:h,66:f,67:d},{22:38,66:[1,39],67:[1,40]},{49:41,66:[1,42],67:[1,43]},{55:[1,44],57:[1,45]},t(y,[2,23]),t(y,[2,24]),t(y,[2,25]),t(y,[2,26]),t(y,[2,27]),t(y,[2,28]),t(g,[2,52]),t(g,[2,53]),t(m,[2,4]),{13:46,16:[1,47]},t(m,[2,9]),{1:[2,3]},{8:[2,11]},{8:[2,12]},{8:[2,13]},{8:[2,14]},{8:[2,15]},{23:[1,48]},{23:[2,50]},{23:[2,51]},{23:[1,49]},{23:[2,56]},{23:[2,57]},{56:50,59:v,60:b,61:_,62:x,63:w,64:k,65:T},{56:58,59:v,60:b,61:_,62:x,63:w,64:k,65:T},{11:59,17:p},{17:[2,8]},{5:[1,60]},{5:[1,61]},{57:[1,62]},t(E,[2,43]),t(E,[2,44]),t(E,[2,45]),t(E,[2,46]),t(E,[2,47]),t(E,[2,48]),t(E,[2,49]),{58:[1,63]},t(m,[2,5]),{5:C,24:64,25:S,28:A,30:M,32:N,34:D},{5:O,34:B,50:71,51:L,53:I},{27:76,66:f,67:d},{27:77,66:f,67:d},t(R,[2,16]),{26:[1,78]},{26:[1,79]},{26:[1,80]},{26:[1,81]},{5:C,24:82,25:S,28:A,30:M,32:N,34:D},t(R,[2,22]),t(R,[2,36]),{26:[1,83]},{26:[1,84]},{5:O,34:B,50:85,51:L,53:I},t(R,[2,40]),t(R,[2,41]),t(R,[2,42]),{27:86,66:f,67:d},{29:87,66:[1,88],67:[1,89]},{31:90,41:[1,91],42:[1,92],43:[1,93]},{33:94,44:[1,95],45:[1,96],46:[1,97],47:[1,98]},t(R,[2,21]),{52:99,66:[1,100],67:[1,101]},{54:102,66:[1,103],67:[1,104]},t(R,[2,39]),{5:[1,105]},{5:[1,106]},{5:[2,54]},{5:[2,55]},{5:[1,107]},{5:[2,29]},{5:[2,30]},{5:[2,31]},{5:[1,108]},{5:[2,32]},{5:[2,33]},{5:[2,34]},{5:[2,35]},{5:[1,109]},{5:[2,58]},{5:[2,59]},{5:[1,110]},{5:[2,60]},{5:[2,61]},{5:C,24:111,25:S,28:A,30:M,32:N,34:D},{5:C,24:112,25:S,28:A,30:M,32:N,34:D},{5:C,24:113,25:S,28:A,30:M,32:N,34:D},{5:C,24:114,25:S,28:A,30:M,32:N,34:D},{5:O,34:B,50:115,51:L,53:I},{5:O,34:B,50:116,51:L,53:I},t(R,[2,17]),t(R,[2,18]),t(R,[2,19]),t(R,[2,20]),t(R,[2,37]),t(R,[2,38])],defaultActions:{5:[2,6],7:[2,2],11:[2,1],32:[2,3],33:[2,11],34:[2,12],35:[2,13],36:[2,14],37:[2,15],39:[2,50],40:[2,51],42:[2,56],43:[2,57],47:[2,8],88:[2,54],89:[2,55],91:[2,29],92:[2,30],93:[2,31],95:[2,32],96:[2,33],97:[2,34],98:[2,35],100:[2,58],101:[2,59],103:[2,60],104:[2,61]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},P={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),14;case 1:return this.begin("type_directive"),15;case 2:return this.popState(),this.begin("arg_directive"),12;case 3:return this.popState(),this.popState(),17;case 4:return 16;case 5:return 5;case 6:case 7:case 8:break;case 9:return 8;case 10:return 6;case 11:return 23;case 12:return 34;case 13:return 26;case 14:return 25;case 15:return 28;case 16:return 30;case 17:return 32;case 18:return 35;case 19:return 36;case 20:return 37;case 21:return 38;case 22:return 39;case 23:return 40;case 24:return 41;case 25:return 42;case 26:return 43;case 27:return 44;case 28:return 45;case 29:return 46;case 30:return 47;case 31:return 48;case 32:return 59;case 33:return 60;case 34:return 61;case 35:return 62;case 36:return 63;case 37:return 64;case 38:return 65;case 39:return 51;case 40:return 53;case 41:return 55;case 42:return 58;case 43:return 57;case 44:this.begin("string");break;case 45:this.popState();break;case 46:return"qString";case 47:return e.yytext=e.yytext.trim(),66}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:(\r?\n)+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:$)/i,/^(?:requirementDiagram\b)/i,/^(?:\{)/i,/^(?:\})/i,/^(?::)/i,/^(?:id\b)/i,/^(?:text\b)/i,/^(?:risk\b)/i,/^(?:verifyMethod\b)/i,/^(?:requirement\b)/i,/^(?:functionalRequirement\b)/i,/^(?:interfaceRequirement\b)/i,/^(?:performanceRequirement\b)/i,/^(?:physicalRequirement\b)/i,/^(?:designConstraint\b)/i,/^(?:low\b)/i,/^(?:medium\b)/i,/^(?:high\b)/i,/^(?:analysis\b)/i,/^(?:demonstration\b)/i,/^(?:inspection\b)/i,/^(?:test\b)/i,/^(?:element\b)/i,/^(?:contains\b)/i,/^(?:copies\b)/i,/^(?:derives\b)/i,/^(?:satisfies\b)/i,/^(?:verifies\b)/i,/^(?:refines\b)/i,/^(?:traces\b)/i,/^(?:type\b)/i,/^(?:docref\b)/i,/^(?:<-)/i,/^(?:->)/i,/^(?:-)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[\w][^\r\n\{\<\>\-\=]*)/i],conditions:{close_directive:{rules:[],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},open_directive:{rules:[1],inclusive:!1},unqString:{rules:[],inclusive:!1},token:{rules:[],inclusive:!1},string:{rules:[45,46],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,47],inclusive:!0}}};function j(){this.yy={}}return F.lexer=P,j.prototype=F,F.Parser=j,new j}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(8800).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},6876:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,2],n=[1,3],r=[1,5],i=[1,7],a=[2,5],o=[1,15],s=[1,17],c=[1,18],u=[1,19],l=[1,21],h=[1,22],f=[1,23],d=[1,29],p=[1,30],y=[1,31],g=[1,32],m=[1,33],v=[1,34],b=[1,37],_=[1,38],x=[1,39],w=[1,40],k=[1,41],T=[1,42],E=[1,45],C=[1,4,5,16,20,22,23,24,30,32,33,34,35,36,38,40,41,42,46,47,48,49,57,67],S=[1,58],A=[4,5,16,20,22,23,24,30,32,33,34,35,36,38,42,46,47,48,49,57,67],M=[4,5,16,20,22,23,24,30,32,33,34,35,36,38,41,42,46,47,48,49,57,67],N=[4,5,16,20,22,23,24,30,32,33,34,35,36,38,40,42,46,47,48,49,57,67],D=[55,56,57],O=[1,4,5,7,16,20,22,23,24,30,32,33,34,35,36,38,40,41,42,46,47,48,49,57,67],B={trace:function(){},yy:{},symbols_:{error:2,start:3,SPACE:4,NEWLINE:5,directive:6,SD:7,document:8,line:9,statement:10,openDirective:11,typeDirective:12,closeDirective:13,":":14,argDirective:15,participant:16,actor:17,AS:18,restOfLine:19,participant_actor:20,signal:21,autonumber:22,activate:23,deactivate:24,note_statement:25,links_statement:26,link_statement:27,properties_statement:28,details_statement:29,title:30,text2:31,loop:32,end:33,rect:34,opt:35,alt:36,else_sections:37,par:38,par_sections:39,and:40,else:41,note:42,placement:43,over:44,actor_pair:45,links:46,link:47,properties:48,details:49,spaceList:50,",":51,left_of:52,right_of:53,signaltype:54,"+":55,"-":56,ACTOR:57,SOLID_OPEN_ARROW:58,DOTTED_OPEN_ARROW:59,SOLID_ARROW:60,DOTTED_ARROW:61,SOLID_CROSS:62,DOTTED_CROSS:63,SOLID_POINT:64,DOTTED_POINT:65,TXT:66,open_directive:67,type_directive:68,arg_directive:69,close_directive:70,$accept:0,$end:1},terminals_:{2:"error",4:"SPACE",5:"NEWLINE",7:"SD",14:":",16:"participant",18:"AS",19:"restOfLine",20:"participant_actor",22:"autonumber",23:"activate",24:"deactivate",30:"title",32:"loop",33:"end",34:"rect",35:"opt",36:"alt",38:"par",40:"and",41:"else",42:"note",44:"over",46:"links",47:"link",48:"properties",49:"details",51:",",52:"left_of",53:"right_of",55:"+",56:"-",57:"ACTOR",58:"SOLID_OPEN_ARROW",59:"DOTTED_OPEN_ARROW",60:"SOLID_ARROW",61:"DOTTED_ARROW",62:"SOLID_CROSS",63:"DOTTED_CROSS",64:"SOLID_POINT",65:"DOTTED_POINT",66:"TXT",67:"open_directive",68:"type_directive",69:"arg_directive",70:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,2],[8,0],[8,2],[9,2],[9,1],[9,1],[6,4],[6,6],[10,5],[10,3],[10,5],[10,3],[10,2],[10,1],[10,3],[10,3],[10,2],[10,2],[10,2],[10,2],[10,2],[10,3],[10,4],[10,4],[10,4],[10,4],[10,4],[10,1],[39,1],[39,4],[37,1],[37,4],[25,4],[25,4],[26,3],[27,3],[28,3],[29,3],[50,2],[50,1],[45,3],[45,1],[43,1],[43,1],[21,5],[21,5],[21,4],[17,1],[54,1],[54,1],[54,1],[54,1],[54,1],[54,1],[54,1],[54,1],[31,1],[11,1],[12,1],[15,1],[13,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 4:return r.apply(a[s]),a[s];case 5:case 9:this.$=[];break;case 6:a[s-1].push(a[s]),this.$=a[s-1];break;case 7:case 8:case 45:this.$=a[s];break;case 12:a[s-3].type="addParticipant",a[s-3].description=r.parseMessage(a[s-1]),this.$=a[s-3];break;case 13:a[s-1].type="addParticipant",this.$=a[s-1];break;case 14:a[s-3].type="addActor",a[s-3].description=r.parseMessage(a[s-1]),this.$=a[s-3];break;case 15:a[s-1].type="addActor",this.$=a[s-1];break;case 17:r.enableSequenceNumbers();break;case 18:this.$={type:"activeStart",signalType:r.LINETYPE.ACTIVE_START,actor:a[s-1]};break;case 19:this.$={type:"activeEnd",signalType:r.LINETYPE.ACTIVE_END,actor:a[s-1]};break;case 25:this.$=[{type:"setTitle",text:a[s-1]}];break;case 26:a[s-1].unshift({type:"loopStart",loopText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.LOOP_START}),a[s-1].push({type:"loopEnd",loopText:a[s-2],signalType:r.LINETYPE.LOOP_END}),this.$=a[s-1];break;case 27:a[s-1].unshift({type:"rectStart",color:r.parseMessage(a[s-2]),signalType:r.LINETYPE.RECT_START}),a[s-1].push({type:"rectEnd",color:r.parseMessage(a[s-2]),signalType:r.LINETYPE.RECT_END}),this.$=a[s-1];break;case 28:a[s-1].unshift({type:"optStart",optText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.OPT_START}),a[s-1].push({type:"optEnd",optText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.OPT_END}),this.$=a[s-1];break;case 29:a[s-1].unshift({type:"altStart",altText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.ALT_START}),a[s-1].push({type:"altEnd",signalType:r.LINETYPE.ALT_END}),this.$=a[s-1];break;case 30:a[s-1].unshift({type:"parStart",parText:r.parseMessage(a[s-2]),signalType:r.LINETYPE.PAR_START}),a[s-1].push({type:"parEnd",signalType:r.LINETYPE.PAR_END}),this.$=a[s-1];break;case 33:this.$=a[s-3].concat([{type:"and",parText:r.parseMessage(a[s-1]),signalType:r.LINETYPE.PAR_AND},a[s]]);break;case 35:this.$=a[s-3].concat([{type:"else",altText:r.parseMessage(a[s-1]),signalType:r.LINETYPE.ALT_ELSE},a[s]]);break;case 36:this.$=[a[s-1],{type:"addNote",placement:a[s-2],actor:a[s-1].actor,text:a[s]}];break;case 37:a[s-2]=[].concat(a[s-1],a[s-1]).slice(0,2),a[s-2][0]=a[s-2][0].actor,a[s-2][1]=a[s-2][1].actor,this.$=[a[s-1],{type:"addNote",placement:r.PLACEMENT.OVER,actor:a[s-2].slice(0,2),text:a[s]}];break;case 38:this.$=[a[s-1],{type:"addLinks",actor:a[s-1].actor,text:a[s]}];break;case 39:this.$=[a[s-1],{type:"addALink",actor:a[s-1].actor,text:a[s]}];break;case 40:this.$=[a[s-1],{type:"addProperties",actor:a[s-1].actor,text:a[s]}];break;case 41:this.$=[a[s-1],{type:"addDetails",actor:a[s-1].actor,text:a[s]}];break;case 44:this.$=[a[s-2],a[s]];break;case 46:this.$=r.PLACEMENT.LEFTOF;break;case 47:this.$=r.PLACEMENT.RIGHTOF;break;case 48:this.$=[a[s-4],a[s-1],{type:"addMessage",from:a[s-4].actor,to:a[s-1].actor,signalType:a[s-3],msg:a[s]},{type:"activeStart",signalType:r.LINETYPE.ACTIVE_START,actor:a[s-1]}];break;case 49:this.$=[a[s-4],a[s-1],{type:"addMessage",from:a[s-4].actor,to:a[s-1].actor,signalType:a[s-3],msg:a[s]},{type:"activeEnd",signalType:r.LINETYPE.ACTIVE_END,actor:a[s-4]}];break;case 50:this.$=[a[s-3],a[s-1],{type:"addMessage",from:a[s-3].actor,to:a[s-1].actor,signalType:a[s-2],msg:a[s]}];break;case 51:this.$={type:"addParticipant",actor:a[s]};break;case 52:this.$=r.LINETYPE.SOLID_OPEN;break;case 53:this.$=r.LINETYPE.DOTTED_OPEN;break;case 54:this.$=r.LINETYPE.SOLID;break;case 55:this.$=r.LINETYPE.DOTTED;break;case 56:this.$=r.LINETYPE.SOLID_CROSS;break;case 57:this.$=r.LINETYPE.DOTTED_CROSS;break;case 58:this.$=r.LINETYPE.SOLID_POINT;break;case 59:this.$=r.LINETYPE.DOTTED_POINT;break;case 60:this.$=r.parseMessage(a[s].trim().substring(1));break;case 61:r.parseDirective("%%{","open_directive");break;case 62:r.parseDirective(a[s],"type_directive");break;case 63:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 64:r.parseDirective("}%%","close_directive","sequence")}},table:[{3:1,4:e,5:n,6:4,7:r,11:6,67:i},{1:[3]},{3:8,4:e,5:n,6:4,7:r,11:6,67:i},{3:9,4:e,5:n,6:4,7:r,11:6,67:i},{3:10,4:e,5:n,6:4,7:r,11:6,67:i},t([1,4,5,16,20,22,23,24,30,32,34,35,36,38,42,46,47,48,49,57,67],a,{8:11}),{12:12,68:[1,13]},{68:[2,61]},{1:[2,1]},{1:[2,2]},{1:[2,3]},{1:[2,4],4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},{13:43,14:[1,44],70:E},t([14,70],[2,62]),t(C,[2,6]),{6:35,10:46,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},t(C,[2,8]),t(C,[2,9]),{17:47,57:T},{17:48,57:T},{5:[1,49]},t(C,[2,17]),{17:50,57:T},{17:51,57:T},{5:[1,52]},{5:[1,53]},{5:[1,54]},{5:[1,55]},{5:[1,56]},{31:57,66:S},{19:[1,59]},{19:[1,60]},{19:[1,61]},{19:[1,62]},{19:[1,63]},t(C,[2,31]),{54:64,58:[1,65],59:[1,66],60:[1,67],61:[1,68],62:[1,69],63:[1,70],64:[1,71],65:[1,72]},{43:73,44:[1,74],52:[1,75],53:[1,76]},{17:77,57:T},{17:78,57:T},{17:79,57:T},{17:80,57:T},t([5,18,51,58,59,60,61,62,63,64,65,66],[2,51]),{5:[1,81]},{15:82,69:[1,83]},{5:[2,64]},t(C,[2,7]),{5:[1,85],18:[1,84]},{5:[1,87],18:[1,86]},t(C,[2,16]),{5:[1,88]},{5:[1,89]},t(C,[2,20]),t(C,[2,21]),t(C,[2,22]),t(C,[2,23]),t(C,[2,24]),{5:[1,90]},{5:[2,60]},t(A,a,{8:91}),t(A,a,{8:92}),t(A,a,{8:93}),t(M,a,{37:94,8:95}),t(N,a,{39:96,8:97}),{17:100,55:[1,98],56:[1,99],57:T},t(D,[2,52]),t(D,[2,53]),t(D,[2,54]),t(D,[2,55]),t(D,[2,56]),t(D,[2,57]),t(D,[2,58]),t(D,[2,59]),{17:101,57:T},{17:103,45:102,57:T},{57:[2,46]},{57:[2,47]},{31:104,66:S},{31:105,66:S},{31:106,66:S},{31:107,66:S},t(O,[2,10]),{13:108,70:E},{70:[2,63]},{19:[1,109]},t(C,[2,13]),{19:[1,110]},t(C,[2,15]),t(C,[2,18]),t(C,[2,19]),t(C,[2,25]),{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[1,111],34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[1,112],34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[1,113],34:y,35:g,36:m,38:v,42:b,46:_,47:x,48:w,49:k,57:T,67:i},{33:[1,114]},{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[2,34],34:y,35:g,36:m,38:v,41:[1,115],42:b,46:_,47:x,48:w,49:k,57:T,67:i},{33:[1,116]},{4:o,5:s,6:35,9:14,10:16,11:6,16:c,17:36,20:u,21:20,22:l,23:h,24:f,25:24,26:25,27:26,28:27,29:28,30:d,32:p,33:[2,32],34:y,35:g,36:m,38:v,40:[1,117],42:b,46:_,47:x,48:w,49:k,57:T,67:i},{17:118,57:T},{17:119,57:T},{31:120,66:S},{31:121,66:S},{31:122,66:S},{51:[1,123],66:[2,45]},{5:[2,38]},{5:[2,39]},{5:[2,40]},{5:[2,41]},{5:[1,124]},{5:[1,125]},{5:[1,126]},t(C,[2,26]),t(C,[2,27]),t(C,[2,28]),t(C,[2,29]),{19:[1,127]},t(C,[2,30]),{19:[1,128]},{31:129,66:S},{31:130,66:S},{5:[2,50]},{5:[2,36]},{5:[2,37]},{17:131,57:T},t(O,[2,11]),t(C,[2,12]),t(C,[2,14]),t(M,a,{8:95,37:132}),t(N,a,{8:97,39:133}),{5:[2,48]},{5:[2,49]},{66:[2,44]},{33:[2,35]},{33:[2,33]}],defaultActions:{7:[2,61],8:[2,1],9:[2,2],10:[2,3],45:[2,64],58:[2,60],75:[2,46],76:[2,47],83:[2,63],104:[2,38],105:[2,39],106:[2,40],107:[2,41],120:[2,50],121:[2,36],122:[2,37],129:[2,48],130:[2,49],131:[2,44],132:[2,35],133:[2,33]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},L={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),67;case 1:return this.begin("type_directive"),68;case 2:return this.popState(),this.begin("arg_directive"),14;case 3:return this.popState(),this.popState(),70;case 4:return 69;case 5:case 39:case 52:return 5;case 6:case 7:case 8:case 9:case 10:break;case 11:return this.begin("ID"),16;case 12:return this.begin("ID"),20;case 13:return e.yytext=e.yytext.trim(),this.begin("ALIAS"),57;case 14:return this.popState(),this.popState(),this.begin("LINE"),18;case 15:return this.popState(),this.popState(),5;case 16:return this.begin("LINE"),32;case 17:return this.begin("LINE"),34;case 18:return this.begin("LINE"),35;case 19:return this.begin("LINE"),36;case 20:return this.begin("LINE"),41;case 21:return this.begin("LINE"),38;case 22:return this.begin("LINE"),40;case 23:return this.popState(),19;case 24:return 33;case 25:return 52;case 26:return 53;case 27:return 46;case 28:return 47;case 29:return 48;case 30:return 49;case 31:return 44;case 32:return 42;case 33:return this.begin("ID"),23;case 34:return this.begin("ID"),24;case 35:return 30;case 36:return 7;case 37:return 22;case 38:return 51;case 40:return e.yytext=e.yytext.trim(),57;case 41:return 60;case 42:return 61;case 43:return 58;case 44:return 59;case 45:return 62;case 46:return 63;case 47:return 64;case 48:return 65;case 49:return 66;case 50:return 55;case 51:return 56;case 53:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:((?!\n)\s)+)/i,/^(?:#[^\n]*)/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:participant\b)/i,/^(?:actor\b)/i,/^(?:[^\->:\n,;]+?(?=((?!\n)\s)+as(?!\n)\s|[#\n;]|$))/i,/^(?:as\b)/i,/^(?:(?:))/i,/^(?:loop\b)/i,/^(?:rect\b)/i,/^(?:opt\b)/i,/^(?:alt\b)/i,/^(?:else\b)/i,/^(?:par\b)/i,/^(?:and\b)/i,/^(?:(?:[:]?(?:no)?wrap)?[^#\n;]*)/i,/^(?:end\b)/i,/^(?:left of\b)/i,/^(?:right of\b)/i,/^(?:links\b)/i,/^(?:link\b)/i,/^(?:properties\b)/i,/^(?:details\b)/i,/^(?:over\b)/i,/^(?:note\b)/i,/^(?:activate\b)/i,/^(?:deactivate\b)/i,/^(?:title\b)/i,/^(?:sequenceDiagram\b)/i,/^(?:autonumber\b)/i,/^(?:,)/i,/^(?:;)/i,/^(?:[^\+\->:\n,;]+((?!(-x|--x|-\)|--\)))[\-]*[^\+\->:\n,;]+)*)/i,/^(?:->>)/i,/^(?:-->>)/i,/^(?:->)/i,/^(?:-->)/i,/^(?:-[x])/i,/^(?:--[x])/i,/^(?:-[\)])/i,/^(?:--[\)])/i,/^(?::(?:(?:no)?wrap)?[^#\n;]+)/i,/^(?:\+)/i,/^(?:-)/i,/^(?:$)/i,/^(?:.)/i],conditions:{open_directive:{rules:[1,8],inclusive:!1},type_directive:{rules:[2,3,8],inclusive:!1},arg_directive:{rules:[3,4,8],inclusive:!1},ID:{rules:[7,8,13],inclusive:!1},ALIAS:{rules:[7,8,14,15],inclusive:!1},LINE:{rules:[7,8,23],inclusive:!1},INITIAL:{rules:[0,5,6,8,9,10,11,12,16,17,18,19,20,21,22,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53],inclusive:!0}}};function I(){this.yy={}}return B.lexer=L,I.prototype=B,B.Parser=I,new I}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(1993).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},3584:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,2],n=[1,3],r=[1,5],i=[1,7],a=[2,5],o=[1,15],s=[1,17],c=[1,19],u=[1,20],l=[1,21],h=[1,22],f=[1,30],d=[1,23],p=[1,24],y=[1,25],g=[1,26],m=[1,27],v=[1,32],b=[1,33],_=[1,34],x=[1,35],w=[1,31],k=[1,38],T=[1,4,5,14,15,17,19,20,22,23,24,25,26,27,36,37,38,39,42,45],E=[1,4,5,12,13,14,15,17,19,20,22,23,24,25,26,27,36,37,38,39,42,45],C=[1,4,5,7,14,15,17,19,20,22,23,24,25,26,27,36,37,38,39,42,45],S=[4,5,14,15,17,19,20,22,23,24,25,26,27,36,37,38,39,42,45],A={trace:function(){},yy:{},symbols_:{error:2,start:3,SPACE:4,NL:5,directive:6,SD:7,document:8,line:9,statement:10,idStatement:11,DESCR:12,"--\x3e":13,HIDE_EMPTY:14,scale:15,WIDTH:16,COMPOSIT_STATE:17,STRUCT_START:18,STRUCT_STOP:19,STATE_DESCR:20,AS:21,ID:22,FORK:23,JOIN:24,CHOICE:25,CONCURRENT:26,note:27,notePosition:28,NOTE_TEXT:29,direction:30,openDirective:31,typeDirective:32,closeDirective:33,":":34,argDirective:35,direction_tb:36,direction_bt:37,direction_rl:38,direction_lr:39,eol:40,";":41,EDGE_STATE:42,left_of:43,right_of:44,open_directive:45,type_directive:46,arg_directive:47,close_directive:48,$accept:0,$end:1},terminals_:{2:"error",4:"SPACE",5:"NL",7:"SD",12:"DESCR",13:"--\x3e",14:"HIDE_EMPTY",15:"scale",16:"WIDTH",17:"COMPOSIT_STATE",18:"STRUCT_START",19:"STRUCT_STOP",20:"STATE_DESCR",21:"AS",22:"ID",23:"FORK",24:"JOIN",25:"CHOICE",26:"CONCURRENT",27:"note",29:"NOTE_TEXT",34:":",36:"direction_tb",37:"direction_bt",38:"direction_rl",39:"direction_lr",41:";",42:"EDGE_STATE",43:"left_of",44:"right_of",45:"open_directive",46:"type_directive",47:"arg_directive",48:"close_directive"},productions_:[0,[3,2],[3,2],[3,2],[3,2],[8,0],[8,2],[9,2],[9,1],[9,1],[10,1],[10,2],[10,3],[10,4],[10,1],[10,2],[10,1],[10,4],[10,3],[10,6],[10,1],[10,1],[10,1],[10,1],[10,4],[10,4],[10,1],[10,1],[6,3],[6,5],[30,1],[30,1],[30,1],[30,1],[40,1],[40,1],[11,1],[11,1],[28,1],[28,1],[31,1],[32,1],[35,1],[33,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 4:return r.setRootDoc(a[s]),a[s];case 5:this.$=[];break;case 6:"nl"!=a[s]&&(a[s-1].push(a[s]),this.$=a[s-1]);break;case 7:case 8:case 36:case 37:this.$=a[s];break;case 9:this.$="nl";break;case 10:this.$={stmt:"state",id:a[s],type:"default",description:""};break;case 11:this.$={stmt:"state",id:a[s-1],type:"default",description:r.trimColon(a[s])};break;case 12:this.$={stmt:"relation",state1:{stmt:"state",id:a[s-2],type:"default",description:""},state2:{stmt:"state",id:a[s],type:"default",description:""}};break;case 13:this.$={stmt:"relation",state1:{stmt:"state",id:a[s-3],type:"default",description:""},state2:{stmt:"state",id:a[s-1],type:"default",description:""},description:a[s].substr(1).trim()};break;case 17:this.$={stmt:"state",id:a[s-3],type:"default",description:"",doc:a[s-1]};break;case 18:var c=a[s],u=a[s-2].trim();if(a[s].match(":")){var l=a[s].split(":");c=l[0],u=[u,l[1]]}this.$={stmt:"state",id:c,type:"default",description:u};break;case 19:this.$={stmt:"state",id:a[s-3],type:"default",description:a[s-5],doc:a[s-1]};break;case 20:this.$={stmt:"state",id:a[s],type:"fork"};break;case 21:this.$={stmt:"state",id:a[s],type:"join"};break;case 22:this.$={stmt:"state",id:a[s],type:"choice"};break;case 23:this.$={stmt:"state",id:r.getDividerId(),type:"divider"};break;case 24:this.$={stmt:"state",id:a[s-1].trim(),note:{position:a[s-2].trim(),text:a[s].trim()}};break;case 30:r.setDirection("TB"),this.$={stmt:"dir",value:"TB"};break;case 31:r.setDirection("BT"),this.$={stmt:"dir",value:"BT"};break;case 32:r.setDirection("RL"),this.$={stmt:"dir",value:"RL"};break;case 33:r.setDirection("LR"),this.$={stmt:"dir",value:"LR"};break;case 40:r.parseDirective("%%{","open_directive");break;case 41:r.parseDirective(a[s],"type_directive");break;case 42:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 43:r.parseDirective("}%%","close_directive","state")}},table:[{3:1,4:e,5:n,6:4,7:r,31:6,45:i},{1:[3]},{3:8,4:e,5:n,6:4,7:r,31:6,45:i},{3:9,4:e,5:n,6:4,7:r,31:6,45:i},{3:10,4:e,5:n,6:4,7:r,31:6,45:i},t([1,4,5,14,15,17,20,22,23,24,25,26,27,36,37,38,39,42,45],a,{8:11}),{32:12,46:[1,13]},{46:[2,40]},{1:[2,1]},{1:[2,2]},{1:[2,3]},{1:[2,4],4:o,5:s,6:28,9:14,10:16,11:18,14:c,15:u,17:l,20:h,22:f,23:d,24:p,25:y,26:g,27:m,30:29,31:6,36:v,37:b,38:_,39:x,42:w,45:i},{33:36,34:[1,37],48:k},t([34,48],[2,41]),t(T,[2,6]),{6:28,10:39,11:18,14:c,15:u,17:l,20:h,22:f,23:d,24:p,25:y,26:g,27:m,30:29,31:6,36:v,37:b,38:_,39:x,42:w,45:i},t(T,[2,8]),t(T,[2,9]),t(T,[2,10],{12:[1,40],13:[1,41]}),t(T,[2,14]),{16:[1,42]},t(T,[2,16],{18:[1,43]}),{21:[1,44]},t(T,[2,20]),t(T,[2,21]),t(T,[2,22]),t(T,[2,23]),{28:45,29:[1,46],43:[1,47],44:[1,48]},t(T,[2,26]),t(T,[2,27]),t(E,[2,36]),t(E,[2,37]),t(T,[2,30]),t(T,[2,31]),t(T,[2,32]),t(T,[2,33]),t(C,[2,28]),{35:49,47:[1,50]},t(C,[2,43]),t(T,[2,7]),t(T,[2,11]),{11:51,22:f,42:w},t(T,[2,15]),t(S,a,{8:52}),{22:[1,53]},{22:[1,54]},{21:[1,55]},{22:[2,38]},{22:[2,39]},{33:56,48:k},{48:[2,42]},t(T,[2,12],{12:[1,57]}),{4:o,5:s,6:28,9:14,10:16,11:18,14:c,15:u,17:l,19:[1,58],20:h,22:f,23:d,24:p,25:y,26:g,27:m,30:29,31:6,36:v,37:b,38:_,39:x,42:w,45:i},t(T,[2,18],{18:[1,59]}),{29:[1,60]},{22:[1,61]},t(C,[2,29]),t(T,[2,13]),t(T,[2,17]),t(S,a,{8:62}),t(T,[2,24]),t(T,[2,25]),{4:o,5:s,6:28,9:14,10:16,11:18,14:c,15:u,17:l,19:[1,63],20:h,22:f,23:d,24:p,25:y,26:g,27:m,30:29,31:6,36:v,37:b,38:_,39:x,42:w,45:i},t(T,[2,19])],defaultActions:{7:[2,40],8:[2,1],9:[2,2],10:[2,3],47:[2,38],48:[2,39],50:[2,42]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},M={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:case 26:return 36;case 1:case 27:return 37;case 2:case 28:return 38;case 3:case 29:return 39;case 4:return this.begin("open_directive"),45;case 5:return this.begin("type_directive"),46;case 6:return this.popState(),this.begin("arg_directive"),34;case 7:return this.popState(),this.popState(),48;case 8:return 47;case 9:case 10:case 12:case 13:case 14:case 15:case 39:case 45:break;case 11:case 59:return 5;case 16:return this.pushState("SCALE"),15;case 17:return 16;case 18:case 33:case 36:this.popState();break;case 19:this.pushState("STATE");break;case 20:case 23:return this.popState(),e.yytext=e.yytext.slice(0,-8).trim(),23;case 21:case 24:return this.popState(),e.yytext=e.yytext.slice(0,-8).trim(),24;case 22:case 25:return this.popState(),e.yytext=e.yytext.slice(0,-10).trim(),25;case 30:this.begin("STATE_STRING");break;case 31:return this.popState(),this.pushState("STATE_ID"),"AS";case 32:case 47:return this.popState(),"ID";case 34:return"STATE_DESCR";case 35:return 17;case 37:return this.popState(),this.pushState("struct"),18;case 38:return this.popState(),19;case 40:return this.begin("NOTE"),27;case 41:return this.popState(),this.pushState("NOTE_ID"),43;case 42:return this.popState(),this.pushState("NOTE_ID"),44;case 43:this.popState(),this.pushState("FLOATING_NOTE");break;case 44:return this.popState(),this.pushState("FLOATING_NOTE_ID"),"AS";case 46:return"NOTE_TEXT";case 48:return this.popState(),this.pushState("NOTE_TEXT"),22;case 49:return this.popState(),e.yytext=e.yytext.substr(2).trim(),29;case 50:return this.popState(),e.yytext=e.yytext.slice(0,-8).trim(),29;case 51:case 52:return 7;case 53:return 14;case 54:return 42;case 55:return 22;case 56:return e.yytext=e.yytext.trim(),12;case 57:return 13;case 58:return 26;case 60:return"INVALID"}},rules:[/^(?:.*direction\s+TB[^\n]*)/i,/^(?:.*direction\s+BT[^\n]*)/i,/^(?:.*direction\s+RL[^\n]*)/i,/^(?:.*direction\s+LR[^\n]*)/i,/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:[\s]+)/i,/^(?:((?!\n)\s)+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:scale\s+)/i,/^(?:\d+)/i,/^(?:\s+width\b)/i,/^(?:state\s+)/i,/^(?:.*<>)/i,/^(?:.*<>)/i,/^(?:.*<>)/i,/^(?:.*\[\[fork\]\])/i,/^(?:.*\[\[join\]\])/i,/^(?:.*\[\[choice\]\])/i,/^(?:.*direction\s+TB[^\n]*)/i,/^(?:.*direction\s+BT[^\n]*)/i,/^(?:.*direction\s+RL[^\n]*)/i,/^(?:.*direction\s+LR[^\n]*)/i,/^(?:["])/i,/^(?:\s*as\s+)/i,/^(?:[^\n\{]*)/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[^\n\s\{]+)/i,/^(?:\n)/i,/^(?:\{)/i,/^(?:\})/i,/^(?:[\n])/i,/^(?:note\s+)/i,/^(?:left of\b)/i,/^(?:right of\b)/i,/^(?:")/i,/^(?:\s*as\s*)/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[^\n]*)/i,/^(?:\s*[^:\n\s\-]+)/i,/^(?:\s*:[^:\n;]+)/i,/^(?:[\s\S]*?end note\b)/i,/^(?:stateDiagram\s+)/i,/^(?:stateDiagram-v2\s+)/i,/^(?:hide empty description\b)/i,/^(?:\[\*\])/i,/^(?:[^:\n\s\-\{]+)/i,/^(?:\s*:[^:\n;]+)/i,/^(?:-->)/i,/^(?:--)/i,/^(?:$)/i,/^(?:.)/i],conditions:{LINE:{rules:[13,14],inclusive:!1},close_directive:{rules:[13,14],inclusive:!1},arg_directive:{rules:[7,8,13,14],inclusive:!1},type_directive:{rules:[6,7,13,14],inclusive:!1},open_directive:{rules:[5,13,14],inclusive:!1},struct:{rules:[13,14,19,26,27,28,29,38,39,40,54,55,56,57,58],inclusive:!1},FLOATING_NOTE_ID:{rules:[47],inclusive:!1},FLOATING_NOTE:{rules:[44,45,46],inclusive:!1},NOTE_TEXT:{rules:[49,50],inclusive:!1},NOTE_ID:{rules:[48],inclusive:!1},NOTE:{rules:[41,42,43],inclusive:!1},SCALE:{rules:[17,18],inclusive:!1},ALIAS:{rules:[],inclusive:!1},STATE_ID:{rules:[32],inclusive:!1},STATE_STRING:{rules:[33,34],inclusive:!1},FORK_STATE:{rules:[],inclusive:!1},STATE:{rules:[13,14,20,21,22,23,24,25,30,31,35,36,37],inclusive:!1},ID:{rules:[13,14],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,9,10,11,12,14,15,16,19,37,40,51,52,53,54,55,56,57,59,60],inclusive:!0}}};function N(){this.yy={}}return A.lexer=M,N.prototype=A,A.Parser=N,new N}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(3069).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},9763:(t,e,n)=>{t=n.nmd(t);var r=function(){var t=function(t,e,n,r){for(n=n||{},r=t.length;r--;n[t[r]]=e);return n},e=[1,2],n=[1,5],r=[6,9,11,17,18,19,21],i=[1,15],a=[1,16],o=[1,17],s=[1,21],c=[4,6,9,11,17,18,19,21],u={trace:function(){},yy:{},symbols_:{error:2,start:3,journey:4,document:5,EOF:6,directive:7,line:8,SPACE:9,statement:10,NEWLINE:11,openDirective:12,typeDirective:13,closeDirective:14,":":15,argDirective:16,title:17,section:18,taskName:19,taskData:20,open_directive:21,type_directive:22,arg_directive:23,close_directive:24,$accept:0,$end:1},terminals_:{2:"error",4:"journey",6:"EOF",9:"SPACE",11:"NEWLINE",15:":",17:"title",18:"section",19:"taskName",20:"taskData",21:"open_directive",22:"type_directive",23:"arg_directive",24:"close_directive"},productions_:[0,[3,3],[3,2],[5,0],[5,2],[8,2],[8,1],[8,1],[8,1],[7,4],[7,6],[10,1],[10,1],[10,2],[10,1],[12,1],[13,1],[16,1],[14,1]],performAction:function(t,e,n,r,i,a,o){var s=a.length-1;switch(i){case 1:return a[s-1];case 3:case 7:case 8:this.$=[];break;case 4:a[s-1].push(a[s]),this.$=a[s-1];break;case 5:case 6:this.$=a[s];break;case 11:r.setTitle(a[s].substr(6)),this.$=a[s].substr(6);break;case 12:r.addSection(a[s].substr(8)),this.$=a[s].substr(8);break;case 13:r.addTask(a[s-1],a[s]),this.$="task";break;case 15:r.parseDirective("%%{","open_directive");break;case 16:r.parseDirective(a[s],"type_directive");break;case 17:a[s]=a[s].trim().replace(/'/g,'"'),r.parseDirective(a[s],"arg_directive");break;case 18:r.parseDirective("}%%","close_directive","journey")}},table:[{3:1,4:e,7:3,12:4,21:n},{1:[3]},t(r,[2,3],{5:6}),{3:7,4:e,7:3,12:4,21:n},{13:8,22:[1,9]},{22:[2,15]},{6:[1,10],7:18,8:11,9:[1,12],10:13,11:[1,14],12:4,17:i,18:a,19:o,21:n},{1:[2,2]},{14:19,15:[1,20],24:s},t([15,24],[2,16]),t(r,[2,8],{1:[2,1]}),t(r,[2,4]),{7:18,10:22,12:4,17:i,18:a,19:o,21:n},t(r,[2,6]),t(r,[2,7]),t(r,[2,11]),t(r,[2,12]),{20:[1,23]},t(r,[2,14]),{11:[1,24]},{16:25,23:[1,26]},{11:[2,18]},t(r,[2,5]),t(r,[2,13]),t(c,[2,9]),{14:27,24:s},{24:[2,17]},{11:[1,28]},t(c,[2,10])],defaultActions:{5:[2,15],7:[2,2],21:[2,18],26:[2,17]},parseError:function(t,e){if(!e.recoverable){var n=new Error(t);throw n.hash=e,n}this.trace(t)},parse:function(t){var e=this,n=[0],r=[],i=[null],a=[],o=this.table,s="",c=0,u=0,l=0,h=2,f=1,d=a.slice.call(arguments,1),p=Object.create(this.lexer),y={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(y.yy[g]=this.yy[g]);p.setInput(t,y.yy),y.yy.lexer=p,y.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var m=p.yylloc;a.push(m);var v=p.options&&p.options.ranges;function b(){var t;return"number"!=typeof(t=r.pop()||p.lex()||f)&&(t instanceof Array&&(t=(r=t).pop()),t=e.symbols_[t]||t),t}"function"==typeof y.yy.parseError?this.parseError=y.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var _,x,w,k,T,E,C,S,A,M={};;){if(w=n[n.length-1],this.defaultActions[w]?k=this.defaultActions[w]:(null==_&&(_=b()),k=o[w]&&o[w][_]),void 0===k||!k.length||!k[0]){var N="";for(E in A=[],o[w])this.terminals_[E]&&E>h&&A.push("'"+this.terminals_[E]+"'");N=p.showPosition?"Parse error on line "+(c+1)+":\n"+p.showPosition()+"\nExpecting "+A.join(", ")+", got '"+(this.terminals_[_]||_)+"'":"Parse error on line "+(c+1)+": Unexpected "+(_==f?"end of input":"'"+(this.terminals_[_]||_)+"'"),this.parseError(N,{text:p.match,token:this.terminals_[_]||_,line:p.yylineno,loc:m,expected:A})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+w+", token: "+_);switch(k[0]){case 1:n.push(_),i.push(p.yytext),a.push(p.yylloc),n.push(k[1]),_=null,x?(_=x,x=null):(u=p.yyleng,s=p.yytext,c=p.yylineno,m=p.yylloc,l>0&&l--);break;case 2:if(C=this.productions_[k[1]][1],M.$=i[i.length-C],M._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},v&&(M._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),void 0!==(T=this.performAction.apply(M,[s,u,c,y.yy,k[1],i,a].concat(d))))return T;C&&(n=n.slice(0,-1*C*2),i=i.slice(0,-1*C),a=a.slice(0,-1*C)),n.push(this.productions_[k[1]][0]),i.push(M.$),a.push(M._$),S=o[n[n.length-2]][n[n.length-1]],n.push(S);break;case 3:return!0}}return!0}},l={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,n=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var r=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var i=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var n,r,i;if(this.options.backtrack_lexer&&(i={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(i.yylloc.range=this.yylloc.range.slice(0))),(r=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=r.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:r?r[r.length-1].length-r[r.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],n=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var a in i)this[a]=i[a];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,n,r;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var i=this._currentRules(),a=0;ae[0].length)){if(e=n,r=a,this.options.backtrack_lexer){if(!1!==(t=this.test_match(n,i[a])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,i[r]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){return this.next()||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{"case-insensitive":!0},performAction:function(t,e,n,r){switch(n){case 0:return this.begin("open_directive"),21;case 1:return this.begin("type_directive"),22;case 2:return this.popState(),this.begin("arg_directive"),15;case 3:return this.popState(),this.popState(),24;case 4:return 23;case 5:case 6:case 8:case 9:break;case 7:return 11;case 10:return 4;case 11:return 17;case 12:return 18;case 13:return 19;case 14:return 20;case 15:return 15;case 16:return 6;case 17:return"INVALID"}},rules:[/^(?:%%\{)/i,/^(?:((?:(?!\}%%)[^:.])*))/i,/^(?::)/i,/^(?:\}%%)/i,/^(?:((?:(?!\}%%).|\n)*))/i,/^(?:%(?!\{)[^\n]*)/i,/^(?:[^\}]%%[^\n]*)/i,/^(?:[\n]+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:journey\b)/i,/^(?:title\s[^#\n;]+)/i,/^(?:section\s[^#:\n;]+)/i,/^(?:[^#:\n;]+)/i,/^(?::[^#\n;]+)/i,/^(?::)/i,/^(?:$)/i,/^(?:.)/i],conditions:{open_directive:{rules:[1],inclusive:!1},type_directive:{rules:[2,3],inclusive:!1},arg_directive:{rules:[3,4],inclusive:!1},INITIAL:{rules:[0,5,6,7,8,9,10,11,12,13,14,15,16,17],inclusive:!0}}};function h(){this.yy={}}return u.lexer=l,h.prototype=u,u.Parser=h,new h}();e.parser=r,e.Parser=r.Parser,e.parse=function(){return r.parse.apply(r,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var r=n(9143).readFileSync(n(6470).normalize(t[1]),"utf8");return e.parser.parse(r)},n.c[n.s]===t&&e.main(process.argv.slice(1))},9609:t=>{"use strict";var e=/^(%20|\s)*(javascript|data)/im,n=/[^\x20-\x7E]/gim,r=/^([^:]+):/gm,i=[".","/"];t.exports={sanitizeUrl:function(t){if(!t)return"about:blank";var a,o,s=t.replace(n,"").trim();return function(t){return i.indexOf(t[0])>-1}(s)?s:(o=s.match(r))?(a=o[0],e.test(a)?"about:blank":s):"about:blank"}}},3841:t=>{t.exports=function(t,e){return t.intersect(e)}},7458:(t,e,n)=>{"use strict";n.d(e,{default:()=>sE});var r=n(1941),i=n.n(r),a={debug:1,info:2,warn:3,error:4,fatal:5},o={debug:function(){},info:function(){},warn:function(){},error:function(){},fatal:function(){}},s=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"fatal";isNaN(t)&&(t=t.toLowerCase(),void 0!==a[t]&&(t=a[t])),o.trace=function(){},o.debug=function(){},o.info=function(){},o.warn=function(){},o.error=function(){},o.fatal=function(){},t<=a.fatal&&(o.fatal=console.error?console.error.bind(console,c("FATAL"),"color: orange"):console.log.bind(console,"",c("FATAL"))),t<=a.error&&(o.error=console.error?console.error.bind(console,c("ERROR"),"color: orange"):console.log.bind(console,"",c("ERROR"))),t<=a.warn&&(o.warn=console.warn?console.warn.bind(console,c("WARN"),"color: orange"):console.log.bind(console,"",c("WARN"))),t<=a.info&&(o.info=console.info?console.info.bind(console,c("INFO"),"color: lightblue"):console.log.bind(console,"",c("INFO"))),t<=a.debug&&(o.debug=console.debug?console.debug.bind(console,c("DEBUG"),"color: lightgreen"):console.log.bind(console,"",c("DEBUG")))},c=function(t){var e=i()().format("ss.SSS");return"%c".concat(e," : ").concat(t," : ")};function u(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n=i)&&(n=i)}return n}function l(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n>e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n>i||void 0===n&&i>=i)&&(n=i)}return n}function h(t){return t}var f=1e-6;function d(t){return"translate("+t+",0)"}function p(t){return"translate(0,"+t+")"}function y(t){return e=>+t(e)}function g(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function m(){return!this.__axis}function v(t,e){var n=[],r=null,i=null,a=6,o=6,s=3,c="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,u=1===t||4===t?-1:1,l=4===t||2===t?"x":"y",v=1===t||3===t?d:p;function b(d){var p=null==r?e.ticks?e.ticks.apply(e,n):e.domain():r,b=null==i?e.tickFormat?e.tickFormat.apply(e,n):h:i,_=Math.max(a,0)+s,x=e.range(),w=+x[0]+c,k=+x[x.length-1]+c,T=(e.bandwidth?g:y)(e.copy(),c),E=d.selection?d.selection():d,C=E.selectAll(".domain").data([null]),S=E.selectAll(".tick").data(p,e).order(),A=S.exit(),M=S.enter().append("g").attr("class","tick"),N=S.select("line"),D=S.select("text");C=C.merge(C.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),S=S.merge(M),N=N.merge(M.append("line").attr("stroke","currentColor").attr(l+"2",u*a)),D=D.merge(M.append("text").attr("fill","currentColor").attr(l,u*_).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),d!==E&&(C=C.transition(d),S=S.transition(d),N=N.transition(d),D=D.transition(d),A=A.transition(d).attr("opacity",f).attr("transform",(function(t){return isFinite(t=T(t))?v(t+c):this.getAttribute("transform")})),M.attr("opacity",f).attr("transform",(function(t){var e=this.parentNode.__axis;return v((e&&isFinite(e=e(t))?e:T(t))+c)}))),A.remove(),C.attr("d",4===t||2===t?o?"M"+u*o+","+w+"H"+c+"V"+k+"H"+u*o:"M"+c+","+w+"V"+k:o?"M"+w+","+u*o+"V"+c+"H"+k+"V"+u*o:"M"+w+","+c+"H"+k),S.attr("opacity",1).attr("transform",(function(t){return v(T(t)+c)})),N.attr(l+"2",u*a),D.attr(l,u*_).text(b),E.filter(m).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),E.each((function(){this.__axis=T}))}return b.scale=function(t){return arguments.length?(e=t,b):e},b.ticks=function(){return n=Array.from(arguments),b},b.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),b):n.slice()},b.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),b):r&&r.slice()},b.tickFormat=function(t){return arguments.length?(i=t,b):i},b.tickSize=function(t){return arguments.length?(a=o=+t,b):a},b.tickSizeInner=function(t){return arguments.length?(a=+t,b):a},b.tickSizeOuter=function(t){return arguments.length?(o=+t,b):o},b.tickPadding=function(t){return arguments.length?(s=+t,b):s},b.offset=function(t){return arguments.length?(c=+t,b):c},b}function b(){}function _(t){return null==t?b:function(){return this.querySelector(t)}}function x(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function w(){return[]}function k(t){return null==t?w:function(){return this.querySelectorAll(t)}}function T(t){return function(){return this.matches(t)}}function E(t){return function(e){return e.matches(t)}}var C=Array.prototype.find;function S(){return this.firstElementChild}var A=Array.prototype.filter;function M(){return Array.from(this.children)}function N(t){return new Array(t.length)}function D(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function O(t){return function(){return t}}function B(t,e,n,r,i,a){for(var o,s=0,c=e.length,u=a.length;se?1:t>=e?0:NaN}D.prototype={constructor:D,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var P="http://www.w3.org/1999/xhtml";const j={svg:"http://www.w3.org/2000/svg",xhtml:P,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Y(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),j.hasOwnProperty(e)?{space:j[e],local:t}:t}function z(t){return function(){this.removeAttribute(t)}}function U(t){return function(){this.removeAttributeNS(t.space,t.local)}}function q(t,e){return function(){this.setAttribute(t,e)}}function H(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function $(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function W(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function V(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function G(t){return function(){this.style.removeProperty(t)}}function X(t,e,n){return function(){this.style.setProperty(t,e,n)}}function Z(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function Q(t,e){return t.style.getPropertyValue(e)||V(t).getComputedStyle(t,null).getPropertyValue(e)}function K(t){return function(){delete this[t]}}function J(t,e){return function(){this[t]=e}}function tt(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function et(t){return t.trim().split(/^|\s+/)}function nt(t){return t.classList||new rt(t)}function rt(t){this._node=t,this._names=et(t.getAttribute("class")||"")}function it(t,e){for(var n=nt(t),r=-1,i=e.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}function Et(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var Nt=[null];function Dt(t,e){this._groups=t,this._parents=e}function Ot(){return new Dt([[document.documentElement]],Nt)}Dt.prototype=Ot.prototype={constructor:Dt,select:function(t){"function"!=typeof t&&(t=_(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i=x&&(x=_+1);!(b=g[x])&&++x=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=F);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a1?this.each((null==e?G:"function"==typeof e?Z:X)(t,e,null==n?"":n)):Q(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?K:"function"==typeof e?tt:J)(t,e)):this.node()[t]},classed:function(t,e){var n=et(t+"");if(arguments.length<2){for(var r=nt(this.node()),i=-1,a=n.length;++i{}};function It(){for(var t,e=0,n=arguments.length,r={};e=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function Pt(t,e){for(var n,r=0,i=t.length;r0)for(var n,r,i=new Array(n),a=0;a=0&&e._call.call(void 0,t),e=e._next;--qt}()}finally{qt=0,function(){for(var t,e,n=zt,r=1/0;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:zt=e);Ut=t,re(r)}(),Vt=0}}function ne(){var t=Xt.now(),e=t-Wt;e>1e3&&(Gt-=e,Wt=t)}function re(t){qt||(Ht&&(Ht=clearTimeout(Ht)),t-Vt>24?(t<1/0&&(Ht=setTimeout(ee,t-Xt.now()-Gt)),$t&&($t=clearInterval($t))):($t||(Wt=Xt.now(),$t=setInterval(ne,1e3)),qt=1,Zt(ee)))}function ie(t,e,n){var r=new Jt;return e=null==e?0:+e,r.restart(n=>{r.stop(),t(n+e)},e,n),r}Jt.prototype=te.prototype={constructor:Jt,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?Qt():+n)+(null==e?0:+e),this._next||Ut===this||(Ut?Ut._next=this:zt=this,Ut=this),this._call=t,this._time=n,re()},stop:function(){this._call&&(this._call=null,this._time=1/0,re())}};var ae=Yt("start","end","cancel","interrupt"),oe=[];function se(t,e,n,r,i,a){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function a(c){var u,l,h,f;if(1!==n.state)return s();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return ie(a);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u0)throw new Error("too late; already scheduled");return n}function ue(t,e){var n=le(t,e);if(n.state>3)throw new Error("too late; already running");return n}function le(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function he(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var fe,de=180/Math.PI,pe={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function ye(t,e,n,r,i,a){var o,s,c;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),t*r180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:he(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,c),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:he(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,c),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:he(t,n)},{i:s-2,x:he(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,c),a=o=null,function(t){for(var e,n=-1,r=c.length;++n>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?ze(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?ze(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Ne.exec(t))?new He(e[1],e[2],e[3],1):(e=De.exec(t))?new He(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Oe.exec(t))?ze(e[1],e[2],e[3],e[4]):(e=Be.exec(t))?ze(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Le.exec(t))?Ge(e[1],e[2]/100,e[3]/100,1):(e=Ie.exec(t))?Ge(e[1],e[2]/100,e[3]/100,e[4]):Re.hasOwnProperty(t)?Ye(Re[t]):"transparent"===t?new He(NaN,NaN,NaN,0):null}function Ye(t){return new He(t>>16&255,t>>8&255,255&t,1)}function ze(t,e,n,r){return r<=0&&(t=e=n=NaN),new He(t,e,n,r)}function Ue(t){return t instanceof Te||(t=je(t)),t?new He((t=t.rgb()).r,t.g,t.b,t.opacity):new He}function qe(t,e,n,r){return 1===arguments.length?Ue(t):new He(t,e,n,null==r?1:r)}function He(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function $e(){return"#"+Ve(this.r)+Ve(this.g)+Ve(this.b)}function We(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function Ve(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function Ge(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Ze(t,e,n,r)}function Xe(t){if(t instanceof Ze)return new Ze(t.h,t.s,t.l,t.opacity);if(t instanceof Te||(t=je(t)),!t)return new Ze;if(t instanceof Ze)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new Ze(o,s,c,t.opacity)}function Ze(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function Qe(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function Ke(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}we(Te,je,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:Fe,formatHex:Fe,formatHsl:function(){return Xe(this).formatHsl()},formatRgb:Pe,toString:Pe}),we(He,qe,ke(Te,{brighter:function(t){return t=null==t?Ee:Math.pow(Ee,t),new He(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new He(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:$e,formatHex:$e,formatRgb:We,toString:We})),we(Ze,(function(t,e,n,r){return 1===arguments.length?Xe(t):new Ze(t,e,n,null==r?1:r)}),ke(Te,{brighter:function(t){return t=null==t?Ee:Math.pow(Ee,t),new Ze(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Ze(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new He(Qe(t>=240?t-240:t+120,i,r),Qe(t,i,r),Qe(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const Je=t=>()=>t;function tn(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Je(isNaN(t)?e:t)}const en=function t(e){var n=function(t){return 1==(t=+t)?tn:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):Je(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=qe(t)).r,(e=qe(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=tn(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function nn(t){return function(e){var n,r,i=e.length,a=new Array(i),o=new Array(i),s=new Array(i);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=ra&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:he(n,r)})),a=an.lastIndex;return a=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?ce:ue;return function(){var o=a(this,t),s=o.on;s!==r&&(i=(r=s).copy()).on(e,n),o.on=i}}var Tn=Bt.prototype.constructor;function En(t){return function(){this.style.removeProperty(t)}}function Cn(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}function Sn(t,e,n){var r,i;function a(){var a=e.apply(this,arguments);return a!==i&&(r=(i=a)&&Cn(t,a,n)),r}return a._value=e,a}function An(t){return function(e){this.textContent=t.call(this,e)}}function Mn(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&An(r)),e}return r._value=t,r}var Nn=0;function Dn(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function On(){return++Nn}var Bn=Bt.prototype;Dn.prototype=function(t){return Bt().transition(t)}.prototype={constructor:Dn,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=_(t));for(var r=this._groups,i=r.length,a=new Array(i),o=0;o2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete a[i]):o=!1;o&&delete t.__transition}}(this,t)}))},Bt.prototype.transition=function(t){var e,n;t instanceof Dn?(e=t._id,t=t._name):(e=On(),(n=Ln).time=Qt(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,a=0;a>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?ar(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?ar(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Gn.exec(t))?new cr(e[1],e[2],e[3],1):(e=Xn.exec(t))?new cr(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Zn.exec(t))?ar(e[1],e[2],e[3],e[4]):(e=Qn.exec(t))?ar(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Kn.exec(t))?fr(e[1],e[2]/100,e[3]/100,1):(e=Jn.exec(t))?fr(e[1],e[2]/100,e[3]/100,e[4]):tr.hasOwnProperty(t)?ir(tr[t]):"transparent"===t?new cr(NaN,NaN,NaN,0):null}function ir(t){return new cr(t>>16&255,t>>8&255,255&t,1)}function ar(t,e,n,r){return r<=0&&(t=e=n=NaN),new cr(t,e,n,r)}function or(t){return t instanceof Un||(t=rr(t)),t?new cr((t=t.rgb()).r,t.g,t.b,t.opacity):new cr}function sr(t,e,n,r){return 1===arguments.length?or(t):new cr(t,e,n,null==r?1:r)}function cr(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function ur(){return"#"+hr(this.r)+hr(this.g)+hr(this.b)}function lr(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function hr(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function fr(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new pr(t,e,n,r)}function dr(t){if(t instanceof pr)return new pr(t.h,t.s,t.l,t.opacity);if(t instanceof Un||(t=rr(t)),!t)return new pr;if(t instanceof pr)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new pr(o,s,c,t.opacity)}function pr(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function yr(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Yn(Un,rr,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:er,formatHex:er,formatHsl:function(){return dr(this).formatHsl()},formatRgb:nr,toString:nr}),Yn(cr,sr,zn(Un,{brighter:function(t){return t=null==t?qn:Math.pow(qn,t),new cr(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new cr(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:ur,formatHex:ur,formatRgb:lr,toString:lr})),Yn(pr,(function(t,e,n,r){return 1===arguments.length?dr(t):new pr(t,e,n,null==r?1:r)}),zn(Un,{brighter:function(t){return t=null==t?qn:Math.pow(qn,t),new pr(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new pr(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new cr(yr(t>=240?t-240:t+120,i,r),yr(t,i,r),yr(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const gr=Math.PI/180,mr=180/Math.PI,vr=6/29*3*(6/29);function br(t){if(t instanceof _r)return new _r(t.l,t.a,t.b,t.opacity);if(t instanceof Sr)return Ar(t);t instanceof cr||(t=or(t));var e,n,r=Tr(t.r),i=Tr(t.g),a=Tr(t.b),o=xr((.2225045*r+.7168786*i+.0606169*a)/1);return r===i&&i===a?e=n=o:(e=xr((.4360747*r+.3850649*i+.1430804*a)/.96422),n=xr((.0139322*r+.0971045*i+.7141733*a)/.82521)),new _r(116*o-16,500*(e-o),200*(o-n),t.opacity)}function _r(t,e,n,r){this.l=+t,this.a=+e,this.b=+n,this.opacity=+r}function xr(t){return t>.008856451679035631?Math.pow(t,1/3):t/vr+4/29}function wr(t){return t>6/29?t*t*t:vr*(t-4/29)}function kr(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function Tr(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function Er(t){if(t instanceof Sr)return new Sr(t.h,t.c,t.l,t.opacity);if(t instanceof _r||(t=br(t)),0===t.a&&0===t.b)return new Sr(NaN,0()=>t;function Nr(t,e){return function(n){return t+n*e}}function Dr(t,e){var n=e-t;return n?Nr(t,n):Mr(isNaN(t)?e:t)}function Or(t){return function(e,n){var r=t((e=Cr(e)).h,(n=Cr(n)).h),i=Dr(e.c,n.c),a=Dr(e.l,n.l),o=Dr(e.opacity,n.opacity);return function(t){return e.h=r(t),e.c=i(t),e.l=a(t),e.opacity=o(t),e+""}}}const Br=Or((function(t,e){var n=e-t;return n?Nr(t,n>180||n<-180?n-360*Math.round(n/360):n):Mr(isNaN(t)?e:t)}));Or(Dr);var Lr=Math.sqrt(50),Ir=Math.sqrt(10),Rr=Math.sqrt(2);function Fr(t,e,n){var r=(e-t)/Math.max(0,n),i=Math.floor(Math.log(r)/Math.LN10),a=r/Math.pow(10,i);return i>=0?(a>=Lr?10:a>=Ir?5:a>=Rr?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(a>=Lr?10:a>=Ir?5:a>=Rr?2:1)}function Pr(t,e,n){var r=Math.abs(e-t)/Math.max(0,n),i=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),a=r/i;return a>=Lr?i*=10:a>=Ir?i*=5:a>=Rr&&(i*=2),ee?1:t>=e?0:NaN}function Yr(t){let e=t,n=t,r=t;function i(t,e,i=0,a=t.length){if(i>>1;r(t[n],e)<0?i=n+1:a=n}while(it(e)-n,n=jr,r=(e,n)=>jr(t(e),n)),{left:i,center:function(t,n,r=0,a=t.length){const o=i(t,n,r,a-1);return o>r&&e(t[o-1],n)>-e(t[o],n)?o-1:o},right:function(t,e,i=0,a=t.length){if(i>>1;r(t[n],e)<=0?i=n+1:a=n}while(i>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?ui(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?ui(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Kr.exec(t))?new fi(e[1],e[2],e[3],1):(e=Jr.exec(t))?new fi(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=ti.exec(t))?ui(e[1],e[2],e[3],e[4]):(e=ei.exec(t))?ui(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=ni.exec(t))?gi(e[1],e[2]/100,e[3]/100,1):(e=ri.exec(t))?gi(e[1],e[2]/100,e[3]/100,e[4]):ii.hasOwnProperty(t)?ci(ii[t]):"transparent"===t?new fi(NaN,NaN,NaN,0):null}function ci(t){return new fi(t>>16&255,t>>8&255,255&t,1)}function ui(t,e,n,r){return r<=0&&(t=e=n=NaN),new fi(t,e,n,r)}function li(t){return t instanceof Wr||(t=si(t)),t?new fi((t=t.rgb()).r,t.g,t.b,t.opacity):new fi}function hi(t,e,n,r){return 1===arguments.length?li(t):new fi(t,e,n,null==r?1:r)}function fi(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function di(){return"#"+yi(this.r)+yi(this.g)+yi(this.b)}function pi(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function yi(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function gi(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new vi(t,e,n,r)}function mi(t){if(t instanceof vi)return new vi(t.h,t.s,t.l,t.opacity);if(t instanceof Wr||(t=si(t)),!t)return new vi;if(t instanceof vi)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new vi(o,s,c,t.opacity)}function vi(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function bi(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function _i(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}Hr(Wr,si,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:ai,formatHex:ai,formatHsl:function(){return mi(this).formatHsl()},formatRgb:oi,toString:oi}),Hr(fi,hi,$r(Wr,{brighter:function(t){return t=null==t?Vr:Math.pow(Vr,t),new fi(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new fi(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:di,formatHex:di,formatRgb:pi,toString:pi})),Hr(vi,(function(t,e,n,r){return 1===arguments.length?mi(t):new vi(t,e,n,null==r?1:r)}),$r(Wr,{brighter:function(t){return t=null==t?Vr:Math.pow(Vr,t),new vi(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new vi(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new fi(bi(t>=240?t-240:t+120,i,r),bi(t,i,r),bi(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const xi=t=>()=>t;function wi(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):xi(isNaN(t)?e:t)}const ki=function t(e){var n=function(t){return 1==(t=+t)?wi:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):xi(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=hi(t)).r,(e=hi(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=wi(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function Ti(t){return function(e){var n,r,i=e.length,a=new Array(i),o=new Array(i),s=new Array(i);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=ra&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:Si(n,r)})),a=Ni.lastIndex;return ae&&(n=t,t=e,e=n),u=function(n){return Math.max(t,Math.min(e,n))}),r=c>2?Yi:ji,i=a=null,h}function h(e){return null==e||isNaN(e=+e)?n:(i||(i=r(o.map(t),s,c)))(t(u(e)))}return h.invert=function(n){return u(e((a||(a=r(s,o.map(t),Si)))(n)))},h.domain=function(t){return arguments.length?(o=Array.from(t,Ii),l()):o.slice()},h.range=function(t){return arguments.length?(s=Array.from(t),l()):s.slice()},h.rangeRound=function(t){return s=Array.from(t),c=Li,l()},h.clamp=function(t){return arguments.length?(u=!!t||Fi,l()):u!==Fi},h.interpolate=function(t){return arguments.length?(c=t,l()):c},h.unknown=function(t){return arguments.length?(n=t,h):n},function(n,r){return t=n,e=r,l()}}()(Fi,Fi)}function qi(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}var Hi,$i=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Wi(t){if(!(e=$i.exec(t)))throw new Error("invalid format: "+t);var e;return new Vi({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function Vi(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function Gi(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function Xi(t){return(t=Gi(Math.abs(t)))?t[1]:NaN}function Zi(t,e){var n=Gi(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}Wi.prototype=Vi.prototype,Vi.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};const Qi={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>Zi(100*t,e),r:Zi,s:function(t,e){var n=Gi(t,e);if(!n)return t+"";var r=n[0],i=n[1],a=i-(Hi=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,o=r.length;return a===o?r:a>o?r+new Array(a-o+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+Gi(t,Math.max(0,e+a-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function Ki(t){return t}var Ji,ta,ea,na=Array.prototype.map,ra=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function ia(t){var e=t.domain;return t.ticks=function(t){var n=e();return function(t,e,n){var r,i,a,o,s=-1;if(n=+n,(t=+t)==(e=+e)&&n>0)return[t];if((r=e0){let n=Math.round(t/o),r=Math.round(e/o);for(n*oe&&--r,a=new Array(i=r-n+1);++se&&--r,a=new Array(i=r-n+1);++s0;){if((i=Fr(c,u,n))===r)return a[o]=c,a[s]=u,e(a);if(i>0)c=Math.floor(c/i)*i,u=Math.ceil(u/i)*i;else{if(!(i<0))break;c=Math.ceil(c*i)/i,u=Math.floor(u*i)/i}r=i}return t},t}Ji=function(t){var e,n,r=void 0===t.grouping||void 0===t.thousands?Ki:(e=na.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var i=t.length,a=[],o=0,s=e[0],c=0;i>0&&s>0&&(c+s+1>r&&(s=Math.max(1,r-c)),a.push(t.substring(i-=s,i+s)),!((c+=s+1)>r));)s=e[o=(o+1)%e.length];return a.reverse().join(n)}),i=void 0===t.currency?"":t.currency[0]+"",a=void 0===t.currency?"":t.currency[1]+"",o=void 0===t.decimal?".":t.decimal+"",s=void 0===t.numerals?Ki:function(t){return function(e){return e.replace(/[0-9]/g,(function(e){return t[+e]}))}}(na.call(t.numerals,String)),c=void 0===t.percent?"%":t.percent+"",u=void 0===t.minus?"−":t.minus+"",l=void 0===t.nan?"NaN":t.nan+"";function h(t){var e=(t=Wi(t)).fill,n=t.align,h=t.sign,f=t.symbol,d=t.zero,p=t.width,y=t.comma,g=t.precision,m=t.trim,v=t.type;"n"===v?(y=!0,v="g"):Qi[v]||(void 0===g&&(g=12),m=!0,v="g"),(d||"0"===e&&"="===n)&&(d=!0,e="0",n="=");var b="$"===f?i:"#"===f&&/[boxX]/.test(v)?"0"+v.toLowerCase():"",_="$"===f?a:/[%p]/.test(v)?c:"",x=Qi[v],w=/[defgprs%]/.test(v);function k(t){var i,a,c,f=b,k=_;if("c"===v)k=x(t)+k,t="";else{var T=(t=+t)<0||1/t<0;if(t=isNaN(t)?l:x(Math.abs(t),g),m&&(t=function(t){t:for(var e,n=t.length,r=1,i=-1;r0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t}(t)),T&&0==+t&&"+"!==h&&(T=!1),f=(T?"("===h?h:u:"-"===h||"("===h?"":h)+f,k=("s"===v?ra[8+Hi/3]:"")+k+(T&&"("===h?")":""),w)for(i=-1,a=t.length;++i(c=t.charCodeAt(i))||c>57){k=(46===c?o+t.slice(i+1):t.slice(i))+k,t=t.slice(0,i);break}}y&&!d&&(t=r(t,1/0));var E=f.length+t.length+k.length,C=E>1)+f+t+k+C.slice(E);break;default:t=C+f+t+k}return s(t)}return g=void 0===g?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),k.toString=function(){return t+""},k}return{format:h,formatPrefix:function(t,e){var n=h(((t=Wi(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(Xi(e)/3))),i=Math.pow(10,-r),a=ra[8+r/3];return function(t){return n(i*t)+a}}}}({thousands:",",grouping:[3],currency:["$",""]}),ta=Ji.format,ea=Ji.formatPrefix;class aa extends Map{constructor(t,e=sa){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=t)for(const[e,n]of t)this.set(e,n)}get(t){return super.get(oa(this,t))}has(t){return super.has(oa(this,t))}set(t,e){return super.set(function({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):(t.set(r,n),n)}(this,t),e)}delete(t){return super.delete(function({_intern:t,_key:e},n){const r=e(n);return t.has(r)&&(n=t.get(r),t.delete(r)),n}(this,t))}}function oa({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):n}function sa(t){return null!==t&&"object"==typeof t?t.valueOf():t}Set;const ca=Symbol("implicit"),ua=1e3,la=6e4,ha=36e5,fa=864e5,da=6048e5,pa=31536e6;var ya=new Date,ga=new Date;function ma(t,e,n,r){function i(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return i.floor=function(e){return t(e=new Date(+e)),e},i.ceil=function(n){return t(n=new Date(n-1)),e(n,1),t(n),n},i.round=function(t){var e=i(t),n=i.ceil(t);return t-e0))return s;do{s.push(o=new Date(+n)),e(n,a),t(n)}while(o=e)for(;t(e),!n(e);)e.setTime(e-1)}),(function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}))},n&&(i.count=function(e,r){return ya.setTime(+e),ga.setTime(+r),t(ya),t(ga),Math.floor(n(ya,ga))},i.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?function(e){return r(e)%t==0}:function(e){return i.count(0,e)%t==0}):i:null}),i}var va=ma((function(){}),(function(t,e){t.setTime(+t+e)}),(function(t,e){return e-t}));va.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?ma((function(e){e.setTime(Math.floor(e/t)*t)}),(function(e,n){e.setTime(+e+n*t)}),(function(e,n){return(n-e)/t})):va:null};const ba=va;va.range;var _a=ma((function(t){t.setTime(t-t.getMilliseconds())}),(function(t,e){t.setTime(+t+e*ua)}),(function(t,e){return(e-t)/ua}),(function(t){return t.getUTCSeconds()}));const xa=_a;_a.range;var wa=ma((function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*ua)}),(function(t,e){t.setTime(+t+e*la)}),(function(t,e){return(e-t)/la}),(function(t){return t.getMinutes()}));const ka=wa;wa.range;var Ta=ma((function(t){t.setTime(t-t.getMilliseconds()-t.getSeconds()*ua-t.getMinutes()*la)}),(function(t,e){t.setTime(+t+e*ha)}),(function(t,e){return(e-t)/ha}),(function(t){return t.getHours()}));const Ea=Ta;Ta.range;var Ca=ma(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*la)/fa,t=>t.getDate()-1);const Sa=Ca;function Aa(t){return ma((function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+7*e)}),(function(t,e){return(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*la)/da}))}Ca.range;var Ma=Aa(0),Na=Aa(1),Da=Aa(2),Oa=Aa(3),Ba=Aa(4),La=Aa(5),Ia=Aa(6),Ra=(Ma.range,Na.range,Da.range,Oa.range,Ba.range,La.range,Ia.range,ma((function(t){t.setDate(1),t.setHours(0,0,0,0)}),(function(t,e){t.setMonth(t.getMonth()+e)}),(function(t,e){return e.getMonth()-t.getMonth()+12*(e.getFullYear()-t.getFullYear())}),(function(t){return t.getMonth()})));const Fa=Ra;Ra.range;var Pa=ma((function(t){t.setMonth(0,1),t.setHours(0,0,0,0)}),(function(t,e){t.setFullYear(t.getFullYear()+e)}),(function(t,e){return e.getFullYear()-t.getFullYear()}),(function(t){return t.getFullYear()}));Pa.every=function(t){return isFinite(t=Math.floor(t))&&t>0?ma((function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)}),(function(e,n){e.setFullYear(e.getFullYear()+n*t)})):null};const ja=Pa;Pa.range;var Ya=ma((function(t){t.setUTCSeconds(0,0)}),(function(t,e){t.setTime(+t+e*la)}),(function(t,e){return(e-t)/la}),(function(t){return t.getUTCMinutes()}));const za=Ya;Ya.range;var Ua=ma((function(t){t.setUTCMinutes(0,0,0)}),(function(t,e){t.setTime(+t+e*ha)}),(function(t,e){return(e-t)/ha}),(function(t){return t.getUTCHours()}));const qa=Ua;Ua.range;var Ha=ma((function(t){t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+e)}),(function(t,e){return(e-t)/fa}),(function(t){return t.getUTCDate()-1}));const $a=Ha;function Wa(t){return ma((function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+7*e)}),(function(t,e){return(e-t)/da}))}Ha.range;var Va=Wa(0),Ga=Wa(1),Xa=Wa(2),Za=Wa(3),Qa=Wa(4),Ka=Wa(5),Ja=Wa(6),to=(Va.range,Ga.range,Xa.range,Za.range,Qa.range,Ka.range,Ja.range,ma((function(t){t.setUTCDate(1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCMonth(t.getUTCMonth()+e)}),(function(t,e){return e.getUTCMonth()-t.getUTCMonth()+12*(e.getUTCFullYear()-t.getUTCFullYear())}),(function(t){return t.getUTCMonth()})));const eo=to;to.range;var no=ma((function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)}),(function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()}),(function(t){return t.getUTCFullYear()}));no.every=function(t){return isFinite(t=Math.floor(t))&&t>0?ma((function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)}),(function(e,n){e.setUTCFullYear(e.getUTCFullYear()+n*t)})):null};const ro=no;function io(t,e,n,r,i,a){const o=[[xa,1,ua],[xa,5,5e3],[xa,15,15e3],[xa,30,3e4],[a,1,la],[a,5,3e5],[a,15,9e5],[a,30,18e5],[i,1,ha],[i,3,108e5],[i,6,216e5],[i,12,432e5],[r,1,fa],[r,2,1728e5],[n,1,da],[e,1,2592e6],[e,3,7776e6],[t,1,pa]];function s(e,n,r){const i=Math.abs(n-e)/r,a=Yr(([,,t])=>t).right(o,i);if(a===o.length)return t.every(Pr(e/pa,n/pa,r));if(0===a)return ba.every(Math.max(Pr(e,n,r),1));const[s,c]=o[i/o[a-1][2][t.toLowerCase(),e]))}function ko(t,e,n){var r=go.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function To(t,e,n){var r=go.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function Eo(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function Co(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function So(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function Ao(t,e,n){var r=go.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function Mo(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function No(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function Do(t,e,n){var r=go.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function Oo(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function Bo(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function Lo(t,e,n){var r=go.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function Io(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function Ro(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function Fo(t,e,n){var r=go.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function Po(t,e,n){var r=go.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function jo(t,e,n){var r=go.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function Yo(t,e,n){var r=mo.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function zo(t,e,n){var r=go.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function Uo(t,e,n){var r=go.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function qo(t,e){return bo(t.getDate(),e,2)}function Ho(t,e){return bo(t.getHours(),e,2)}function $o(t,e){return bo(t.getHours()%12||12,e,2)}function Wo(t,e){return bo(1+Sa.count(ja(t),t),e,3)}function Vo(t,e){return bo(t.getMilliseconds(),e,3)}function Go(t,e){return Vo(t,e)+"000"}function Xo(t,e){return bo(t.getMonth()+1,e,2)}function Zo(t,e){return bo(t.getMinutes(),e,2)}function Qo(t,e){return bo(t.getSeconds(),e,2)}function Ko(t){var e=t.getDay();return 0===e?7:e}function Jo(t,e){return bo(Ma.count(ja(t)-1,t),e,2)}function ts(t){var e=t.getDay();return e>=4||0===e?Ba(t):Ba.ceil(t)}function es(t,e){return t=ts(t),bo(Ba.count(ja(t),t)+(4===ja(t).getDay()),e,2)}function ns(t){return t.getDay()}function rs(t,e){return bo(Na.count(ja(t)-1,t),e,2)}function is(t,e){return bo(t.getFullYear()%100,e,2)}function as(t,e){return bo((t=ts(t)).getFullYear()%100,e,2)}function os(t,e){return bo(t.getFullYear()%1e4,e,4)}function ss(t,e){var n=t.getDay();return bo((t=n>=4||0===n?Ba(t):Ba.ceil(t)).getFullYear()%1e4,e,4)}function cs(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+bo(e/60|0,"0",2)+bo(e%60,"0",2)}function us(t,e){return bo(t.getUTCDate(),e,2)}function ls(t,e){return bo(t.getUTCHours(),e,2)}function hs(t,e){return bo(t.getUTCHours()%12||12,e,2)}function fs(t,e){return bo(1+$a.count(ro(t),t),e,3)}function ds(t,e){return bo(t.getUTCMilliseconds(),e,3)}function ps(t,e){return ds(t,e)+"000"}function ys(t,e){return bo(t.getUTCMonth()+1,e,2)}function gs(t,e){return bo(t.getUTCMinutes(),e,2)}function ms(t,e){return bo(t.getUTCSeconds(),e,2)}function vs(t){var e=t.getUTCDay();return 0===e?7:e}function bs(t,e){return bo(Va.count(ro(t)-1,t),e,2)}function _s(t){var e=t.getUTCDay();return e>=4||0===e?Qa(t):Qa.ceil(t)}function xs(t,e){return t=_s(t),bo(Qa.count(ro(t),t)+(4===ro(t).getUTCDay()),e,2)}function ws(t){return t.getUTCDay()}function ks(t,e){return bo(Ga.count(ro(t)-1,t),e,2)}function Ts(t,e){return bo(t.getUTCFullYear()%100,e,2)}function Es(t,e){return bo((t=_s(t)).getUTCFullYear()%100,e,2)}function Cs(t,e){return bo(t.getUTCFullYear()%1e4,e,4)}function Ss(t,e){var n=t.getUTCDay();return bo((t=n>=4||0===n?Qa(t):Qa.ceil(t)).getUTCFullYear()%1e4,e,4)}function As(){return"+0000"}function Ms(){return"%"}function Ns(t){return+t}function Ds(t){return Math.floor(+t/1e3)}function Os(t){return new Date(t)}function Bs(t){return t instanceof Date?+t:+new Date(+t)}function Ls(t,e,n,r,i,a,o,s,c,u){var l=Ui(),h=l.invert,f=l.domain,d=u(".%L"),p=u(":%S"),y=u("%I:%M"),g=u("%I %p"),m=u("%a %d"),v=u("%b %d"),b=u("%B"),_=u("%Y");function x(t){return(c(t)=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Ns,s:Ds,S:Qo,u:Ko,U:Jo,V:es,w:ns,W:rs,x:null,X:null,y:is,Y:os,Z:cs,"%":Ms},_={a:function(t){return o[t.getUTCDay()]},A:function(t){return a[t.getUTCDay()]},b:function(t){return c[t.getUTCMonth()]},B:function(t){return s[t.getUTCMonth()]},c:null,d:us,e:us,f:ps,g:Es,G:Ss,H:ls,I:hs,j:fs,L:ds,m:ys,M:gs,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Ns,s:Ds,S:ms,u:vs,U:bs,V:xs,w:ws,W:ks,x:null,X:null,y:Ts,Y:Cs,Z:As,"%":Ms},x={a:function(t,e,n){var r=d.exec(e.slice(n));return r?(t.w=p.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(t,e,n){var r=h.exec(e.slice(n));return r?(t.w=f.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(t,e,n){var r=m.exec(e.slice(n));return r?(t.m=v.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(t,e,n){var r=y.exec(e.slice(n));return r?(t.m=g.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(t,n,r){return T(t,e,n,r)},d:Bo,e:Bo,f:jo,g:Mo,G:Ao,H:Io,I:Io,j:Lo,L:Po,m:Oo,M:Ro,p:function(t,e,n){var r=u.exec(e.slice(n));return r?(t.p=l.get(r[0].toLowerCase()),n+r[0].length):-1},q:Do,Q:zo,s:Uo,S:Fo,u:To,U:Eo,V:Co,w:ko,W:So,x:function(t,e,r){return T(t,n,e,r)},X:function(t,e,n){return T(t,r,e,n)},y:Mo,Y:Ao,Z:No,"%":Yo};function w(t,e){return function(n){var r,i,a,o=[],s=-1,c=0,u=t.length;for(n instanceof Date||(n=new Date(+n));++s53)return null;"w"in a||(a.w=1),"Z"in a?(i=(r=lo(ho(a.y,0,1))).getUTCDay(),r=i>4||0===i?Ga.ceil(r):Ga(r),r=$a.offset(r,7*(a.V-1)),a.y=r.getUTCFullYear(),a.m=r.getUTCMonth(),a.d=r.getUTCDate()+(a.w+6)%7):(i=(r=uo(ho(a.y,0,1))).getDay(),r=i>4||0===i?Na.ceil(r):Na(r),r=Sa.offset(r,7*(a.V-1)),a.y=r.getFullYear(),a.m=r.getMonth(),a.d=r.getDate()+(a.w+6)%7)}else("W"in a||"U"in a)&&("w"in a||(a.w="u"in a?a.u%7:"W"in a?1:0),i="Z"in a?lo(ho(a.y,0,1)).getUTCDay():uo(ho(a.y,0,1)).getDay(),a.m=0,a.d="W"in a?(a.w+6)%7+7*a.W-(i+5)%7:a.w+7*a.U-(i+6)%7);return"Z"in a?(a.H+=a.Z/100|0,a.M+=a.Z%100,lo(a)):uo(a)}}function T(t,e,n,r){for(var i,a,o=0,s=e.length,c=n.length;o=c)return-1;if(37===(i=e.charCodeAt(o++))){if(i=e.charAt(o++),!(a=x[i in yo?e.charAt(o++):i])||(r=a(t,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}return b.x=w(n,b),b.X=w(r,b),b.c=w(e,b),_.x=w(n,_),_.X=w(r,_),_.c=w(e,_),{format:function(t){var e=w(t+="",b);return e.toString=function(){return t},e},parse:function(t){var e=k(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=w(t+="",_);return e.toString=function(){return t},e},utcParse:function(t){var e=k(t+="",!0);return e.toString=function(){return t},e}}}({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),po=fo.format,fo.parse,fo.utcFormat,fo.utcParse;var Us=Array.prototype.find;function qs(){return this.firstElementChild}var Hs=Array.prototype.filter;function $s(){return Array.from(this.children)}function Ws(t){return new Array(t.length)}function Vs(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function Gs(t){return function(){return t}}function Xs(t,e,n,r,i,a){for(var o,s=0,c=e.length,u=a.length;se?1:t>=e?0:NaN}Vs.prototype={constructor:Vs,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var tc="http://www.w3.org/1999/xhtml";const ec={svg:"http://www.w3.org/2000/svg",xhtml:tc,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function nc(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),ec.hasOwnProperty(e)?{space:ec[e],local:t}:t}function rc(t){return function(){this.removeAttribute(t)}}function ic(t){return function(){this.removeAttributeNS(t.space,t.local)}}function ac(t,e){return function(){this.setAttribute(t,e)}}function oc(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function sc(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function cc(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function uc(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function lc(t){return function(){this.style.removeProperty(t)}}function hc(t,e,n){return function(){this.style.setProperty(t,e,n)}}function fc(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function dc(t,e){return t.style.getPropertyValue(e)||uc(t).getComputedStyle(t,null).getPropertyValue(e)}function pc(t){return function(){delete this[t]}}function yc(t,e){return function(){this[t]=e}}function gc(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function mc(t){return t.trim().split(/^|\s+/)}function vc(t){return t.classList||new bc(t)}function bc(t){this._node=t,this._names=mc(t.getAttribute("class")||"")}function _c(t,e){for(var n=vc(t),r=-1,i=e.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}function zc(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var Wc=[null];function Vc(t,e){this._groups=t,this._parents=e}function Gc(){return new Vc([[document.documentElement]],Wc)}Vc.prototype=Gc.prototype={constructor:Vc,select:function(t){"function"!=typeof t&&(t=Rs(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i=x&&(x=_+1);!(b=g[x])&&++x=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=Js);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a1?this.each((null==e?lc:"function"==typeof e?fc:hc)(t,e,null==n?"":n)):dc(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?pc:"function"==typeof e?gc:yc)(t,e)):this.node()[t]},classed:function(t,e){var n=mc(t+"");if(arguments.length<2){for(var r=vc(this.node()),i=-1,a=n.length;++itu)if(Math.abs(l*s-c*u)>tu&&i){var f=n-a,d=r-o,p=s*s+c*c,y=f*f+d*d,g=Math.sqrt(p),m=Math.sqrt(h),v=i*Math.tan((Kc-Math.acos((p+h-y)/(2*g*m)))/2),b=v/m,_=v/g;Math.abs(b-1)>tu&&(this._+="L"+(t+b*u)+","+(e+b*l)),this._+="A"+i+","+i+",0,0,"+ +(l*f>u*d)+","+(this._x1=t+_*s)+","+(this._y1=e+_*c)}else this._+="L"+(this._x1=t)+","+(this._y1=e)},arc:function(t,e,n,r,i,a){t=+t,e=+e,a=!!a;var o=(n=+n)*Math.cos(r),s=n*Math.sin(r),c=t+o,u=e+s,l=1^a,h=a?r-i:i-r;if(n<0)throw new Error("negative radius: "+n);null===this._x1?this._+="M"+c+","+u:(Math.abs(this._x1-c)>tu||Math.abs(this._y1-u)>tu)&&(this._+="L"+c+","+u),n&&(h<0&&(h=h%Jc+Jc),h>eu?this._+="A"+n+","+n+",0,1,"+l+","+(t-o)+","+(e-s)+"A"+n+","+n+",0,1,"+l+","+(this._x1=c)+","+(this._y1=u):h>tu&&(this._+="A"+n+","+n+",0,"+ +(h>=Kc)+","+l+","+(this._x1=t+n*Math.cos(i))+","+(this._y1=e+n*Math.sin(i))))},rect:function(t,e,n,r){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)+"h"+ +n+"v"+ +r+"h"+-n+"Z"},toString:function(){return this._}};const iu=ru;function au(t){return function(){return t}}var ou=Math.abs,su=Math.atan2,cu=Math.cos,uu=Math.max,lu=Math.min,hu=Math.sin,fu=Math.sqrt,du=1e-12,pu=Math.PI,yu=pu/2,gu=2*pu;function mu(t){return t>1?0:t<-1?pu:Math.acos(t)}function vu(t){return t>=1?yu:t<=-1?-yu:Math.asin(t)}function bu(t){return t.innerRadius}function _u(t){return t.outerRadius}function xu(t){return t.startAngle}function wu(t){return t.endAngle}function ku(t){return t&&t.padAngle}function Tu(t,e,n,r,i,a,o,s){var c=n-t,u=r-e,l=o-i,h=s-a,f=h*c-l*u;if(!(f*fN*N+D*D&&(T=C,E=S),{cx:T,cy:E,x01:-l,y01:-h,x11:T*(i/x-1),y11:E*(i/x-1)}}function Cu(){var t=bu,e=_u,n=au(0),r=null,i=xu,a=wu,o=ku,s=null;function c(){var c,u,l=+t.apply(this,arguments),h=+e.apply(this,arguments),f=i.apply(this,arguments)-yu,d=a.apply(this,arguments)-yu,p=ou(d-f),y=d>f;if(s||(s=c=iu()),hdu)if(p>gu-du)s.moveTo(h*cu(f),h*hu(f)),s.arc(0,0,h,f,d,!y),l>du&&(s.moveTo(l*cu(d),l*hu(d)),s.arc(0,0,l,d,f,y));else{var g,m,v=f,b=d,_=f,x=d,w=p,k=p,T=o.apply(this,arguments)/2,E=T>du&&(r?+r.apply(this,arguments):fu(l*l+h*h)),C=lu(ou(h-l)/2,+n.apply(this,arguments)),S=C,A=C;if(E>du){var M=vu(E/l*hu(T)),N=vu(E/h*hu(T));(w-=2*M)>du?(_+=M*=y?1:-1,x-=M):(w=0,_=x=(f+d)/2),(k-=2*N)>du?(v+=N*=y?1:-1,b-=N):(k=0,v=b=(f+d)/2)}var D=h*cu(v),O=h*hu(v),B=l*cu(x),L=l*hu(x);if(C>du){var I,R=h*cu(b),F=h*hu(b),P=l*cu(_),j=l*hu(_);if(pdu?A>du?(g=Eu(P,j,D,O,h,A,y),m=Eu(R,F,B,L,h,A,y),s.moveTo(g.cx+g.x01,g.cy+g.y01),Adu&&w>du?S>du?(g=Eu(B,L,R,F,l,-S,y),m=Eu(D,O,P,j,l,-S,y),s.lineTo(g.cx+g.x01,g.cy+g.y01),St?1:e>=t?0:NaN}function Lu(t){return t}function Iu(){}function Ru(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function Fu(t){this._context=t}function Pu(t){return new Fu(t)}function ju(t){this._context=t}function Yu(t){this._context=t}function zu(t){this._context=t}function Uu(t){return t<0?-1:1}function qu(t,e,n){var r=t._x1-t._x0,i=e-t._x1,a=(t._y1-t._y0)/(r||i<0&&-0),o=(n-t._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(Uu(a)+Uu(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function Hu(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function $u(t,e,n){var r=t._x0,i=t._y0,a=t._x1,o=t._y1,s=(a-r)/3;t._context.bezierCurveTo(r+s,i+s*e,a-s,o-s*n,a,o)}function Wu(t){this._context=t}function Vu(t){this._context=new Gu(t)}function Gu(t){this._context=t}function Xu(t){this._context=t}function Zu(t){var e,n,r=t.length-1,i=new Array(r),a=new Array(r),o=new Array(r);for(i[0]=0,a[0]=2,o[0]=t[0]+2*t[1],e=1;e=0;--e)i[e]=(o[e]-i[e+1])/a[e];for(a[r-1]=(t[r]+i[r-1])/2,e=0;e=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};var Ku=new Date,Ju=new Date;function tl(t,e,n,r){function i(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return i.floor=function(e){return t(e=new Date(+e)),e},i.ceil=function(n){return t(n=new Date(n-1)),e(n,1),t(n),n},i.round=function(t){var e=i(t),n=i.ceil(t);return t-e0))return s;do{s.push(o=new Date(+n)),e(n,a),t(n)}while(o=e)for(;t(e),!n(e);)e.setTime(e-1)}),(function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}))},n&&(i.count=function(e,r){return Ku.setTime(+e),Ju.setTime(+r),t(Ku),t(Ju),Math.floor(n(Ku,Ju))},i.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?function(e){return r(e)%t==0}:function(e){return i.count(0,e)%t==0}):i:null}),i}const el=6048e5;function nl(t){return tl((function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+7*e)}),(function(t,e){return(e-t)/el}))}var rl=nl(0),il=nl(1),al=nl(2),ol=nl(3),sl=nl(4),cl=nl(5),ul=nl(6),ll=(rl.range,il.range,al.range,ol.range,sl.range,cl.range,ul.range,tl((function(t){t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+e)}),(function(t,e){return(e-t)/864e5}),(function(t){return t.getUTCDate()-1})));const hl=ll;function fl(t){return tl((function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+7*e)}),(function(t,e){return(e-t-6e4*(e.getTimezoneOffset()-t.getTimezoneOffset()))/el}))}ll.range;var dl=fl(0),pl=fl(1),yl=fl(2),gl=fl(3),ml=fl(4),vl=fl(5),bl=fl(6),_l=(dl.range,pl.range,yl.range,gl.range,ml.range,vl.range,bl.range,tl(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-6e4*(e.getTimezoneOffset()-t.getTimezoneOffset()))/864e5,t=>t.getDate()-1));const xl=_l;_l.range;var wl=tl((function(t){t.setMonth(0,1),t.setHours(0,0,0,0)}),(function(t,e){t.setFullYear(t.getFullYear()+e)}),(function(t,e){return e.getFullYear()-t.getFullYear()}),(function(t){return t.getFullYear()}));wl.every=function(t){return isFinite(t=Math.floor(t))&&t>0?tl((function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)}),(function(e,n){e.setFullYear(e.getFullYear()+n*t)})):null};const kl=wl;wl.range;var Tl=tl((function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)}),(function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()}),(function(t){return t.getUTCFullYear()}));Tl.every=function(t){return isFinite(t=Math.floor(t))&&t>0?tl((function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)}),(function(e,n){e.setUTCFullYear(e.getUTCFullYear()+n*t)})):null};const El=Tl;function Cl(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function Sl(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function Al(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}Tl.range;var Ml,Nl,Dl={"-":"",_:" ",0:"0"},Ol=/^\s*\d+/,Bl=/^%/,Ll=/[\\^$*+?|[\]().{}]/g;function Il(t,e,n){var r=t<0?"-":"",i=(r?-t:t)+"",a=i.length;return r+(a[t.toLowerCase(),e]))}function jl(t,e,n){var r=Ol.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function Yl(t,e,n){var r=Ol.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function zl(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function Ul(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function ql(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function Hl(t,e,n){var r=Ol.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function $l(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function Wl(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function Vl(t,e,n){var r=Ol.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function Gl(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function Xl(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function Zl(t,e,n){var r=Ol.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function Ql(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function Kl(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function Jl(t,e,n){var r=Ol.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function th(t,e,n){var r=Ol.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function eh(t,e,n){var r=Ol.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function nh(t,e,n){var r=Bl.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function rh(t,e,n){var r=Ol.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function ih(t,e,n){var r=Ol.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function ah(t,e){return Il(t.getDate(),e,2)}function oh(t,e){return Il(t.getHours(),e,2)}function sh(t,e){return Il(t.getHours()%12||12,e,2)}function ch(t,e){return Il(1+xl.count(kl(t),t),e,3)}function uh(t,e){return Il(t.getMilliseconds(),e,3)}function lh(t,e){return uh(t,e)+"000"}function hh(t,e){return Il(t.getMonth()+1,e,2)}function fh(t,e){return Il(t.getMinutes(),e,2)}function dh(t,e){return Il(t.getSeconds(),e,2)}function ph(t){var e=t.getDay();return 0===e?7:e}function yh(t,e){return Il(dl.count(kl(t)-1,t),e,2)}function gh(t){var e=t.getDay();return e>=4||0===e?ml(t):ml.ceil(t)}function mh(t,e){return t=gh(t),Il(ml.count(kl(t),t)+(4===kl(t).getDay()),e,2)}function vh(t){return t.getDay()}function bh(t,e){return Il(pl.count(kl(t)-1,t),e,2)}function _h(t,e){return Il(t.getFullYear()%100,e,2)}function xh(t,e){return Il((t=gh(t)).getFullYear()%100,e,2)}function wh(t,e){return Il(t.getFullYear()%1e4,e,4)}function kh(t,e){var n=t.getDay();return Il((t=n>=4||0===n?ml(t):ml.ceil(t)).getFullYear()%1e4,e,4)}function Th(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Il(e/60|0,"0",2)+Il(e%60,"0",2)}function Eh(t,e){return Il(t.getUTCDate(),e,2)}function Ch(t,e){return Il(t.getUTCHours(),e,2)}function Sh(t,e){return Il(t.getUTCHours()%12||12,e,2)}function Ah(t,e){return Il(1+hl.count(El(t),t),e,3)}function Mh(t,e){return Il(t.getUTCMilliseconds(),e,3)}function Nh(t,e){return Mh(t,e)+"000"}function Dh(t,e){return Il(t.getUTCMonth()+1,e,2)}function Oh(t,e){return Il(t.getUTCMinutes(),e,2)}function Bh(t,e){return Il(t.getUTCSeconds(),e,2)}function Lh(t){var e=t.getUTCDay();return 0===e?7:e}function Ih(t,e){return Il(rl.count(El(t)-1,t),e,2)}function Rh(t){var e=t.getUTCDay();return e>=4||0===e?sl(t):sl.ceil(t)}function Fh(t,e){return t=Rh(t),Il(sl.count(El(t),t)+(4===El(t).getUTCDay()),e,2)}function Ph(t){return t.getUTCDay()}function jh(t,e){return Il(il.count(El(t)-1,t),e,2)}function Yh(t,e){return Il(t.getUTCFullYear()%100,e,2)}function zh(t,e){return Il((t=Rh(t)).getUTCFullYear()%100,e,2)}function Uh(t,e){return Il(t.getUTCFullYear()%1e4,e,4)}function qh(t,e){var n=t.getUTCDay();return Il((t=n>=4||0===n?sl(t):sl.ceil(t)).getUTCFullYear()%1e4,e,4)}function Hh(){return"+0000"}function $h(){return"%"}function Wh(t){return+t}function Vh(t){return Math.floor(+t/1e3)}Ml=function(t){var e=t.dateTime,n=t.date,r=t.time,i=t.periods,a=t.days,o=t.shortDays,s=t.months,c=t.shortMonths,u=Fl(i),l=Pl(i),h=Fl(a),f=Pl(a),d=Fl(o),p=Pl(o),y=Fl(s),g=Pl(s),m=Fl(c),v=Pl(c),b={a:function(t){return o[t.getDay()]},A:function(t){return a[t.getDay()]},b:function(t){return c[t.getMonth()]},B:function(t){return s[t.getMonth()]},c:null,d:ah,e:ah,f:lh,g:xh,G:kh,H:oh,I:sh,j:ch,L:uh,m:hh,M:fh,p:function(t){return i[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Wh,s:Vh,S:dh,u:ph,U:yh,V:mh,w:vh,W:bh,x:null,X:null,y:_h,Y:wh,Z:Th,"%":$h},_={a:function(t){return o[t.getUTCDay()]},A:function(t){return a[t.getUTCDay()]},b:function(t){return c[t.getUTCMonth()]},B:function(t){return s[t.getUTCMonth()]},c:null,d:Eh,e:Eh,f:Nh,g:zh,G:qh,H:Ch,I:Sh,j:Ah,L:Mh,m:Dh,M:Oh,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Wh,s:Vh,S:Bh,u:Lh,U:Ih,V:Fh,w:Ph,W:jh,x:null,X:null,y:Yh,Y:Uh,Z:Hh,"%":$h},x={a:function(t,e,n){var r=d.exec(e.slice(n));return r?(t.w=p.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(t,e,n){var r=h.exec(e.slice(n));return r?(t.w=f.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(t,e,n){var r=m.exec(e.slice(n));return r?(t.m=v.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(t,e,n){var r=y.exec(e.slice(n));return r?(t.m=g.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(t,n,r){return T(t,e,n,r)},d:Xl,e:Xl,f:eh,g:$l,G:Hl,H:Ql,I:Ql,j:Zl,L:th,m:Gl,M:Kl,p:function(t,e,n){var r=u.exec(e.slice(n));return r?(t.p=l.get(r[0].toLowerCase()),n+r[0].length):-1},q:Vl,Q:rh,s:ih,S:Jl,u:Yl,U:zl,V:Ul,w:jl,W:ql,x:function(t,e,r){return T(t,n,e,r)},X:function(t,e,n){return T(t,r,e,n)},y:$l,Y:Hl,Z:Wl,"%":nh};function w(t,e){return function(n){var r,i,a,o=[],s=-1,c=0,u=t.length;for(n instanceof Date||(n=new Date(+n));++s53)return null;"w"in a||(a.w=1),"Z"in a?(i=(r=Sl(Al(a.y,0,1))).getUTCDay(),r=i>4||0===i?il.ceil(r):il(r),r=hl.offset(r,7*(a.V-1)),a.y=r.getUTCFullYear(),a.m=r.getUTCMonth(),a.d=r.getUTCDate()+(a.w+6)%7):(i=(r=Cl(Al(a.y,0,1))).getDay(),r=i>4||0===i?pl.ceil(r):pl(r),r=xl.offset(r,7*(a.V-1)),a.y=r.getFullYear(),a.m=r.getMonth(),a.d=r.getDate()+(a.w+6)%7)}else("W"in a||"U"in a)&&("w"in a||(a.w="u"in a?a.u%7:"W"in a?1:0),i="Z"in a?Sl(Al(a.y,0,1)).getUTCDay():Cl(Al(a.y,0,1)).getDay(),a.m=0,a.d="W"in a?(a.w+6)%7+7*a.W-(i+5)%7:a.w+7*a.U-(i+6)%7);return"Z"in a?(a.H+=a.Z/100|0,a.M+=a.Z%100,Sl(a)):Cl(a)}}function T(t,e,n,r){for(var i,a,o=0,s=e.length,c=n.length;o=c)return-1;if(37===(i=e.charCodeAt(o++))){if(i=e.charAt(o++),!(a=x[i in Dl?e.charAt(o++):i])||(r=a(t,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}return b.x=w(n,b),b.X=w(r,b),b.c=w(e,b),_.x=w(n,_),_.X=w(r,_),_.c=w(e,_),{format:function(t){var e=w(t+="",b);return e.toString=function(){return t},e},parse:function(t){var e=k(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=w(t+="",_);return e.toString=function(){return t},e},utcParse:function(t){var e=k(t+="",!0);return e.toString=function(){return t},e}}}({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),Nl=Ml.format,Ml.parse,Ml.utcFormat,Ml.utcParse;var Gh={value:()=>{}};function Xh(){for(var t,e=0,n=arguments.length,r={};e=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function Kh(t,e){for(var n,r=0,i=t.length;r0)for(var n,r,i=new Array(n),a=0;a=0&&e._call.call(void 0,t),e=e._next;--rf}()}finally{rf=0,function(){for(var t,e,n=ef,r=1/0;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:ef=e);nf=t,vf(r)}(),cf=0}}function mf(){var t=lf.now(),e=t-sf;e>1e3&&(uf-=e,sf=t)}function vf(t){rf||(af&&(af=clearTimeout(af)),t-cf>24?(t<1/0&&(af=setTimeout(gf,t-lf.now()-uf)),of&&(of=clearInterval(of))):(of||(sf=lf.now(),of=setInterval(mf,1e3)),rf=1,hf(gf)))}function bf(t,e,n){var r=new pf;return e=null==e?0:+e,r.restart(n=>{r.stop(),t(n+e)},e,n),r}pf.prototype=yf.prototype={constructor:pf,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?ff():+n)+(null==e?0:+e),this._next||nf===this||(nf?nf._next=this:ef=this,nf=this),this._call=t,this._time=n,vf()},stop:function(){this._call&&(this._call=null,this._time=1/0,vf())}};var _f=tf("start","end","cancel","interrupt"),xf=[];function wf(t,e,n,r,i,a){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function a(c){var u,l,h,f;if(1!==n.state)return s();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return bf(a);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u0)throw new Error("too late; already scheduled");return n}function Tf(t,e){var n=Ef(t,e);if(n.state>3)throw new Error("too late; already running");return n}function Ef(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function Cf(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var Sf,Af=180/Math.PI,Mf={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Nf(t,e,n,r,i,a){var o,s,c;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),t*r180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:Cf(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,c),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:Cf(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,c),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:Cf(t,n)},{i:s-2,x:Cf(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,c),a=o=null,function(t){for(var e,n=-1,r=c.length;++n=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=ra&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:Cf(n,r)})),a=zf.lastIndex;return a=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?kf:Tf;return function(){var o=a(this,t),s=o.on;s!==r&&(i=(r=s).copy()).on(e,n),o.on=i}}var od=Xc.prototype.constructor;function sd(t){return function(){this.style.removeProperty(t)}}function cd(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}function ud(t,e,n){var r,i;function a(){var a=e.apply(this,arguments);return a!==i&&(r=(i=a)&&cd(t,a,n)),r}return a._value=e,a}function ld(t){return function(e){this.textContent=t.call(this,e)}}function hd(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&ld(r)),e}return r._value=t,r}var fd=0;function dd(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function pd(){return++fd}var yd=Xc.prototype;dd.prototype=function(t){return Xc().transition(t)}.prototype={constructor:dd,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=Rs(t));for(var r=this._groups,i=r.length,a=new Array(i),o=0;o2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete a[i]):o=!1;o&&delete t.__transition}}(this,t)}))},Xc.prototype.transition=function(t){var e,n;t instanceof dd?(e=t._id,t=t._name):(e=pd(),(n=gd).time=ff(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,a=0;ae?1:t>=e?0:NaN}Nd.prototype={constructor:Nd,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var Fd="http://www.w3.org/1999/xhtml";const Pd={svg:"http://www.w3.org/2000/svg",xhtml:Fd,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function jd(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),Pd.hasOwnProperty(e)?{space:Pd[e],local:t}:t}function Yd(t){return function(){this.removeAttribute(t)}}function zd(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Ud(t,e){return function(){this.setAttribute(t,e)}}function qd(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Hd(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function $d(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function Wd(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Vd(t){return function(){this.style.removeProperty(t)}}function Gd(t,e,n){return function(){this.style.setProperty(t,e,n)}}function Xd(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function Zd(t,e){return t.style.getPropertyValue(e)||Wd(t).getComputedStyle(t,null).getPropertyValue(e)}function Qd(t){return function(){delete this[t]}}function Kd(t,e){return function(){this[t]=e}}function Jd(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function tp(t){return t.trim().split(/^|\s+/)}function ep(t){return t.classList||new np(t)}function np(t){this._node=t,this._names=tp(t.getAttribute("class")||"")}function rp(t,e){for(var n=ep(t),r=-1,i=e.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}function Tp(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var Mp=[null];function Np(t,e){this._groups=t,this._parents=e}function Dp(){return new Np([[document.documentElement]],Mp)}Np.prototype=Dp.prototype={constructor:Np,select:function(t){"function"!=typeof t&&(t=bd(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i=x&&(x=_+1);!(b=g[x])&&++x=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=Rd);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a1?this.each((null==e?Vd:"function"==typeof e?Xd:Gd)(t,e,null==n?"":n)):Zd(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?Qd:"function"==typeof e?Jd:Kd)(t,e)):this.node()[t]},classed:function(t,e){var n=tp(t+"");if(arguments.length<2){for(var r=ep(this.node()),i=-1,a=n.length;++i{}};function Lp(){for(var t,e=0,n=arguments.length,r={};e=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function Fp(t,e){for(var n,r=0,i=t.length;r0)for(var n,r,i=new Array(n),a=0;a=0&&e._call.call(void 0,t),e=e._next;--Up}()}finally{Up=0,function(){for(var t,e,n=Yp,r=1/0;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Yp=e);zp=t,ny(r)}(),Wp=0}}function ey(){var t=Gp.now(),e=t-$p;e>1e3&&(Vp-=e,$p=t)}function ny(t){Up||(qp&&(qp=clearTimeout(qp)),t-Wp>24?(t<1/0&&(qp=setTimeout(ty,t-Gp.now()-Vp)),Hp&&(Hp=clearInterval(Hp))):(Hp||($p=Gp.now(),Hp=setInterval(ey,1e3)),Up=1,Xp(ty)))}function ry(t,e,n){var r=new Kp;return e=null==e?0:+e,r.restart(n=>{r.stop(),t(n+e)},e,n),r}Kp.prototype=Jp.prototype={constructor:Kp,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?Zp():+n)+(null==e?0:+e),this._next||zp===this||(zp?zp._next=this:Yp=this,zp=this),this._call=t,this._time=n,ny()},stop:function(){this._call&&(this._call=null,this._time=1/0,ny())}};var iy=jp("start","end","cancel","interrupt"),ay=[];function oy(t,e,n,r,i,a){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function a(c){var u,l,h,f;if(1!==n.state)return s();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return ry(a);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u0)throw new Error("too late; already scheduled");return n}function cy(t,e){var n=uy(t,e);if(n.state>3)throw new Error("too late; already running");return n}function uy(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function ly(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var hy,fy=180/Math.PI,dy={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function py(t,e,n,r,i,a){var o,s,c;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),t*r180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:ly(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,c),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:ly(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,c),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:ly(t,n)},{i:s-2,x:ly(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,c),a=o=null,function(t){for(var e,n=-1,r=c.length;++n>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Yy(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Yy(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=My.exec(t))?new qy(e[1],e[2],e[3],1):(e=Ny.exec(t))?new qy(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Dy.exec(t))?Yy(e[1],e[2],e[3],e[4]):(e=Oy.exec(t))?Yy(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=By.exec(t))?Vy(e[1],e[2]/100,e[3]/100,1):(e=Ly.exec(t))?Vy(e[1],e[2]/100,e[3]/100,e[4]):Iy.hasOwnProperty(t)?jy(Iy[t]):"transparent"===t?new qy(NaN,NaN,NaN,0):null}function jy(t){return new qy(t>>16&255,t>>8&255,255&t,1)}function Yy(t,e,n,r){return r<=0&&(t=e=n=NaN),new qy(t,e,n,r)}function zy(t){return t instanceof ky||(t=Py(t)),t?new qy((t=t.rgb()).r,t.g,t.b,t.opacity):new qy}function Uy(t,e,n,r){return 1===arguments.length?zy(t):new qy(t,e,n,null==r?1:r)}function qy(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function Hy(){return"#"+Wy(this.r)+Wy(this.g)+Wy(this.b)}function $y(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function Wy(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function Vy(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Xy(t,e,n,r)}function Gy(t){if(t instanceof Xy)return new Xy(t.h,t.s,t.l,t.opacity);if(t instanceof ky||(t=Py(t)),!t)return new Xy;if(t instanceof Xy)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new Xy(o,s,c,t.opacity)}function Xy(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function Zy(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function Qy(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}xy(ky,Py,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:Ry,formatHex:Ry,formatHsl:function(){return Gy(this).formatHsl()},formatRgb:Fy,toString:Fy}),xy(qy,Uy,wy(ky,{brighter:function(t){return t=null==t?Ty:Math.pow(Ty,t),new qy(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new qy(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Hy,formatHex:Hy,formatRgb:$y,toString:$y})),xy(Xy,(function(t,e,n,r){return 1===arguments.length?Gy(t):new Xy(t,e,n,null==r?1:r)}),wy(ky,{brighter:function(t){return t=null==t?Ty:Math.pow(Ty,t),new Xy(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Xy(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new qy(Zy(t>=240?t-240:t+120,i,r),Zy(t,i,r),Zy(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const Ky=t=>()=>t;function Jy(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Ky(isNaN(t)?e:t)}const tg=function t(e){var n=function(t){return 1==(t=+t)?Jy:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):Ky(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=Uy(t)).r,(e=Uy(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=Jy(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function eg(t){return function(e){var n,r,i=e.length,a=new Array(i),o=new Array(i),s=new Array(i);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=ra&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:ly(n,r)})),a=rg.lastIndex;return a=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?sy:cy;return function(){var o=a(this,t),s=o.on;s!==r&&(i=(r=s).copy()).on(e,n),o.on=i}}var wg=Op.prototype.constructor;function kg(t){return function(){this.style.removeProperty(t)}}function Tg(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}function Eg(t,e,n){var r,i;function a(){var a=e.apply(this,arguments);return a!==i&&(r=(i=a)&&Tg(t,a,n)),r}return a._value=e,a}function Cg(t){return function(e){this.textContent=t.call(this,e)}}function Sg(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&Cg(r)),e}return r._value=t,r}var Ag=0;function Mg(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function Ng(){return++Ag}var Dg=Op.prototype;Mg.prototype=function(t){return Op().transition(t)}.prototype={constructor:Mg,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=bd(t));for(var r=this._groups,i=r.length,a=new Array(i),o=0;o2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete a[i]):o=!1;o&&delete t.__transition}}(this,t)}))},Op.prototype.transition=function(t){var e,n;t instanceof Mg?(e=t._id,t=t._name):(e=Ng(),(n=Og).time=Zp(),t=null==t?null:t+"");for(var r=this._groups,i=r.length,a=0;a2||im(Qg)>3?"":" "}function sm(t,e){for(;--e&&tm()&&!(Qg<48||Qg>102||Qg>57&&Qg<65||Qg>70&&Qg<97););return rm(t,nm()+(e<6&&32==em()&&32==tm()))}function cm(t,e){for(;tm()&&t+Qg!==57&&(t+Qg!==84||47!==em()););return"/*"+rm(e,Zg-1)+"*"+Rg(47===t?t:tm())}function um(t){for(;!im(em());)tm();return rm(t,Zg)}function lm(t){return function(t){return Kg="",t}(function t(e,n,r,i,a,o,s,c,u){for(var l=0,h=0,f=s,d=0,p=0,y=0,g=1,m=1,v=1,b=0,_="",x=a,w=o,k=i,T=_;m;)switch(y=b,b=tm()){case 40:if(108!=y&&58==T.charCodeAt(f-1)){-1!=jg(T+=Pg(am(b),"&","&\f"),"&\f")&&(v=-1);break}case 34:case 39:case 91:T+=am(b);break;case 9:case 10:case 13:case 32:T+=om(y);break;case 92:T+=sm(nm()-1,7);continue;case 47:switch(em()){case 42:case 47:Hg(fm(cm(tm(),nm()),n,r),u);break;default:T+="/"}break;case 123*g:c[l++]=Ug(T)*v;case 125*g:case 59:case 0:switch(b){case 0:case 125:m=0;case 59+h:p>0&&Ug(T)-f&&Hg(p>32?dm(T+";",i,r,f-1):dm(Pg(T," ","")+";",i,r,f-2),u);break;case 59:T+=";";default:if(Hg(k=hm(T,n,r,l,h,a,c,_,x=[],w=[],f),o),123===b)if(0===h)t(T,n,k,k,x,o,f,c,w);else switch(d){case 100:case 109:case 115:t(e,k,k,i&&Hg(hm(e,k,k,0,0,a,c,_,a,x=[],f),w),a,w,f,c,i?x:w);break;default:t(T,k,k,k,[""],w,0,c,w)}}l=h=p=0,g=v=1,_=T="",f=s;break;case 58:f=1+Ug(T),p=y;default:if(g<1)if(123==b)--g;else if(125==b&&0==g++&&125==(Qg=Zg>0?Yg(Kg,--Zg):0,Gg--,10===Qg&&(Gg=1,Vg--),Qg))continue;switch(T+=Rg(b),b*g){case 38:v=h>0?1:(T+="\f",-1);break;case 44:c[l++]=(Ug(T)-1)*v,v=1;break;case 64:45===em()&&(T+=am(tm())),d=em(),h=f=Ug(_=T+=um(nm())),b++;break;case 45:45===y&&2==Ug(T)&&(g=0)}}return o}("",null,null,null,[""],t=function(t){return Vg=Gg=1,Xg=Ug(Kg=t),Zg=0,[]}(t),0,[0],t))}function hm(t,e,n,r,i,a,o,s,c,u,l){for(var h=i-1,f=0===i?a:[""],d=qg(f),p=0,y=0,g=0;p0?f[m]+" "+v:Pg(v,/&\f/g,f[m])))&&(c[g++]=b);return Jg(t,e,n,0===i?"rule":s,c,u,l)}function fm(t,e,n){return Jg(t,e,n,"comm",Rg(Qg),zg(t,2,-2),0)}function dm(t,e,n,r){return Jg(t,e,n,"decl",zg(t,0,r),zg(t,r+1,-1),r)}var pm=n(9609),ym=n(7856),gm=n.n(ym),mm=function(t){var e=t.replace(/\\u[\dA-F]{4}/gi,(function(t){return String.fromCharCode(parseInt(t.replace(/\\u/g,""),16))}));return(e=(e=e.replace(/\\x([0-9a-f]{2})/gi,(function(t,e){return String.fromCharCode(parseInt(e,16))}))).replace(/\\[\d\d\d]{3}/gi,(function(t){return String.fromCharCode(parseInt(t.replace(/\\/g,""),8))}))).replace(/\\[\d\d\d]{2}/gi,(function(t){return String.fromCharCode(parseInt(t.replace(/\\/g,""),8))}))},vm=function(t){for(var e="",n=0;n>=0;){if(!((n=t.indexOf("=0)){e+=t,n=-1;break}e+=t.substr(0,n),(n=(t=t.substr(n+1)).indexOf("<\/script>"))>=0&&(n+=9,t=t.substr(n))}var r=mm(e);return(r=(r=(r=r.replace(/script>/gi,"#")).replace(/javascript:/gi,"#")).replace(/onerror=/gi,"onerror:")).replace(/')}if(void 0!==n)switch(y){case"flowchart":case"flowchart-v2":n(T,I_.bindFunctions);break;case"gantt":n(T,Fx.bindFunctions);break;case"class":case"classDiagram":n(T,Vv.bindFunctions);break;default:n(T)}else o.debug("CB = undefined!");mk.forEach((function(t){t()})),mk=[];var S="sandbox"===s.securityLevel?"#i"+t:"#d"+t,A=Zc(S).node();return null!==A&&"function"==typeof A.remove&&Zc(S).node().remove(),T},parse:function(t){var e=Av(),n=bv.detectInit(t,e);n&&o.debug("reinit ",n);var r,i=bv.detectType(t,e);switch(o.debug("Type "+i),i){case"git":(r=rw()).parser.yy=tw;break;case"flowchart":case"flowchart-v2":I_.clear(),(r=F_()).parser.yy=I_;break;case"sequence":(r=Gw()).parser.yy=gk;break;case"gantt":(r=zx()).parser.yy=Fx;break;case"class":case"classDiagram":(r=Jv()).parser.yy=Vv;break;case"state":case"stateDiagram":(r=Vk()).parser.yy=sT;break;case"info":o.debug("info info info"),(r=vw()).parser.yy=gw;break;case"pie":o.debug("pie"),(r=ww()).parser.yy=Cw;break;case"er":o.debug("er"),(r=r_()).parser.yy=e_;break;case"journey":o.debug("Journey"),(r=BT()).parser.yy=DT;break;case"requirement":case"requirementDiagram":o.debug("RequirementDiagram"),(r=Dw()).parser.yy=Fw}return r.parser.yy.graphType=i,r.parser.yy.parseError=function(t,e){throw{str:t,hash:e}},r.parse(t),r},parseDirective:function(t,e,n,r){try{if(void 0!==e)switch(e=e.trim(),n){case"open_directive":eE={};break;case"type_directive":eE.type=e.toLowerCase();break;case"arg_directive":eE.args=JSON.parse(e);break;case"close_directive":(function(t,e,n){switch(o.debug("Directive type=".concat(e.type," with args:"),e.args),e.type){case"init":case"initialize":["config"].forEach((function(t){void 0!==e.args[t]&&("flowchart-v2"===n&&(n="flowchart"),e.args[n]=e.args[t],delete e.args[t])})),o.debug("sanitize in handleDirective",e.args),mv(e.args),o.debug("sanitize in handleDirective (done)",e.args),e.args,Nv(e.args);break;case"wrap":case"nowrap":t&&t.setWrap&&t.setWrap("wrap"===e.type);break;case"themeCss":o.warn("themeCss encountered");break;default:o.warn("Unhandled directive: source: '%%{".concat(e.type,": ").concat(JSON.stringify(e.args?e.args:{}),"}%%"),e)}})(t,eE,r),eE=null}}catch(t){o.error("Error while rendering sequenceDiagram directive: ".concat(e," jison context: ").concat(n)),o.error(t.message)}},initialize:function(t){t&&t.fontFamily&&(t.themeVariables&&t.themeVariables.fontFamily||(t.themeVariables={fontFamily:t.fontFamily})),function(t){xv=uv({},t)}(t),t&&t.theme&&Fm[t.theme]?t.themeVariables=Fm[t.theme].getThemeVariables(t.themeVariables):t&&(t.themeVariables=Fm.default.getThemeVariables(t.themeVariables));var e="object"===JT(t)?function(t){return kv=uv({},wv),kv=uv(kv,t),t.theme&&(kv.themeVariables=Fm[t.theme].getThemeVariables(t.themeVariables)),Ev=Cv(kv,Tv),kv}(t):Sv();nE(e),s(e.logLevel)},reinitialize:function(){},getConfig:Av,setConfig:function(t){return uv(Ev,t),Av()},getSiteConfig:Sv,updateSiteConfig:function(t){return kv=uv(kv,t),Cv(kv,Tv),kv},reset:function(){Dv()},globalReset:function(){Dv(),nE(Av())},defaultConfig:wv});s(Av().logLevel),Dv(Av());const iE=rE;var aE=function(){oE.startOnLoad?iE.getConfig().startOnLoad&&oE.init():void 0===oE.startOnLoad&&(o.debug("In start, no config"),iE.getConfig().startOnLoad&&oE.init())};"undefined"!=typeof document&&window.addEventListener("load",(function(){aE()}),!1);var oE={startOnLoad:!0,htmlLabels:!0,mermaidAPI:iE,parse:iE.parse,render:iE.render,init:function(){var t,e,n=this,r=iE.getConfig();arguments.length>=2?(void 0!==arguments[0]&&(oE.sequenceConfig=arguments[0]),t=arguments[1]):t=arguments[0],"function"==typeof arguments[arguments.length-1]?(e=arguments[arguments.length-1],o.debug("Callback function found")):void 0!==r.mermaid&&("function"==typeof r.mermaid.callback?(e=r.mermaid.callback,o.debug("Callback function found")):o.debug("No Callback function found")),t=void 0===t?document.querySelectorAll(".mermaid"):"string"==typeof t?document.querySelectorAll(t):t instanceof window.Node?[t]:t,o.debug("Start On Load before: "+oE.startOnLoad),void 0!==oE.startOnLoad&&(o.debug("Start On Load inner: "+oE.startOnLoad),iE.updateSiteConfig({startOnLoad:oE.startOnLoad})),void 0!==oE.ganttConfig&&iE.updateSiteConfig({gantt:oE.ganttConfig});for(var i,a=new bv.initIdGeneratior(r.deterministicIds,r.deterministicIDSeed),s=function(r){var s=t[r];if(s.getAttribute("data-processed"))return"continue";s.setAttribute("data-processed",!0);var c="mermaid-".concat(a.next());i=s.innerHTML,i=bv.entityDecode(i).trim().replace(//gi,"
");var u=bv.detectInit(i);u&&o.debug("Detected early reinit: ",u);try{iE.render(c,i,(function(t,n){s.innerHTML=t,void 0!==e&&e(c),n&&n(s)}),s)}catch(t){o.warn("Syntax Error rendering"),o.warn(t),n.parseError&&n.parseError(t)}},c=0;c{t.exports={graphlib:n(6614),dagre:n(1463),intersect:n(8114),render:n(5787),util:n(8355),version:n(5689)}},9144:(t,e,n)=>{var r=n(8355);function i(t,e,n,i){var a=t.append("marker").attr("id",e).attr("viewBox","0 0 10 10").attr("refX",9).attr("refY",5).attr("markerUnits","strokeWidth").attr("markerWidth",8).attr("markerHeight",6).attr("orient","auto").append("path").attr("d","M 0 0 L 10 5 L 0 10 z").style("stroke-width",1).style("stroke-dasharray","1,0");r.applyStyle(a,n[i+"Style"]),n[i+"Class"]&&a.attr("class",n[i+"Class"])}t.exports={default:i,normal:i,vee:function(t,e,n,i){var a=t.append("marker").attr("id",e).attr("viewBox","0 0 10 10").attr("refX",9).attr("refY",5).attr("markerUnits","strokeWidth").attr("markerWidth",8).attr("markerHeight",6).attr("orient","auto").append("path").attr("d","M 0 0 L 10 5 L 0 10 L 4 5 z").style("stroke-width",1).style("stroke-dasharray","1,0");r.applyStyle(a,n[i+"Style"]),n[i+"Class"]&&a.attr("class",n[i+"Class"])},undirected:function(t,e,n,i){var a=t.append("marker").attr("id",e).attr("viewBox","0 0 10 10").attr("refX",9).attr("refY",5).attr("markerUnits","strokeWidth").attr("markerWidth",8).attr("markerHeight",6).attr("orient","auto").append("path").attr("d","M 0 5 L 10 5").style("stroke-width",1).style("stroke-dasharray","1,0");r.applyStyle(a,n[i+"Style"]),n[i+"Class"]&&a.attr("class",n[i+"Class"])}}},5632:(t,e,n)=>{var r=n(8355),i=n(4322),a=n(1322);t.exports=function(t,e){var n,o=e.nodes().filter((function(t){return r.isSubgraph(e,t)})),s=t.selectAll("g.cluster").data(o,(function(t){return t}));return s.selectAll("*").remove(),s.enter().append("g").attr("class","cluster").attr("id",(function(t){return e.node(t).id})).style("opacity",0),s=t.selectAll("g.cluster"),r.applyTransition(s,e).style("opacity",1),s.each((function(t){var n=e.node(t),r=i.select(this);i.select(this).append("rect");var o=r.append("g").attr("class","label");a(o,n,n.clusterLabelPos)})),s.selectAll("rect").each((function(t){var n=e.node(t),a=i.select(this);r.applyStyle(a,n.style)})),n=s.exit?s.exit():s.selectAll(null),r.applyTransition(n,e).style("opacity",0).remove(),s}},6315:(t,e,n)=>{"use strict";var r=n(1034),i=n(1322),a=n(8355),o=n(4322);t.exports=function(t,e){var n,s=t.selectAll("g.edgeLabel").data(e.edges(),(function(t){return a.edgeToId(t)})).classed("update",!0);return s.exit().remove(),s.enter().append("g").classed("edgeLabel",!0).style("opacity",0),(s=t.selectAll("g.edgeLabel")).each((function(t){var n=o.select(this);n.select(".label").remove();var a=e.edge(t),s=i(n,e.edge(t),0,0).classed("label",!0),c=s.node().getBBox();a.labelId&&s.attr("id",a.labelId),r.has(a,"width")||(a.width=c.width),r.has(a,"height")||(a.height=c.height)})),n=s.exit?s.exit():s.selectAll(null),a.applyTransition(n,e).style("opacity",0).remove(),s}},940:(t,e,n)=>{"use strict";var r=n(1034),i=n(7584),a=n(8355),o=n(4322);function s(t,e){var n=(o.line||o.svg.line)().x((function(t){return t.x})).y((function(t){return t.y}));return(n.curve||n.interpolate)(t.curve),n(e)}t.exports=function(t,e,n){var c=t.selectAll("g.edgePath").data(e.edges(),(function(t){return a.edgeToId(t)})).classed("update",!0),u=function(t,e){var n=t.enter().append("g").attr("class","edgePath").style("opacity",0);return n.append("path").attr("class","path").attr("d",(function(t){var n=e.edge(t),i=e.node(t.v).elem;return s(n,r.range(n.points.length).map((function(){return e=(t=i).getBBox(),{x:(n=t.ownerSVGElement.getScreenCTM().inverse().multiply(t.getScreenCTM()).translate(e.width/2,e.height/2)).e,y:n.f};var t,e,n})))})),n.append("defs"),n}(c,e);!function(t,e){var n=t.exit();a.applyTransition(n,e).style("opacity",0).remove()}(c,e);var l=void 0!==c.merge?c.merge(u):c;return a.applyTransition(l,e).style("opacity",1),l.each((function(t){var n=o.select(this),r=e.edge(t);r.elem=this,r.id&&n.attr("id",r.id),a.applyClass(n,r.class,(n.classed("update")?"update ":"")+"edgePath")})),l.selectAll("path.path").each((function(t){var n=e.edge(t);n.arrowheadId=r.uniqueId("arrowhead");var c=o.select(this).attr("marker-end",(function(){return"url("+(t=location.href,e=n.arrowheadId,t.split("#")[0]+"#"+e+")");var t,e})).style("fill","none");a.applyTransition(c,e).attr("d",(function(t){return function(t,e){var n=t.edge(e),r=t.node(e.v),a=t.node(e.w),o=n.points.slice(1,n.points.length-1);return o.unshift(i(r,o[0])),o.push(i(a,o[o.length-1])),s(n,o)}(e,t)})),a.applyStyle(c,n.style)})),l.selectAll("defs *").remove(),l.selectAll("defs").each((function(t){var r=e.edge(t);(0,n[r.arrowhead])(o.select(this),r.arrowheadId,r,"arrowhead")})),l}},607:(t,e,n)=>{"use strict";var r=n(1034),i=n(1322),a=n(8355),o=n(4322);t.exports=function(t,e,n){var s,c=e.nodes().filter((function(t){return!a.isSubgraph(e,t)})),u=t.selectAll("g.node").data(c,(function(t){return t})).classed("update",!0);return u.exit().remove(),u.enter().append("g").attr("class","node").style("opacity",0),(u=t.selectAll("g.node")).each((function(t){var s=e.node(t),c=o.select(this);a.applyClass(c,s.class,(c.classed("update")?"update ":"")+"node"),c.select("g.label").remove();var u=c.append("g").attr("class","label"),l=i(u,s),h=n[s.shape],f=r.pick(l.node().getBBox(),"width","height");s.elem=this,s.id&&c.attr("id",s.id),s.labelId&&u.attr("id",s.labelId),r.has(s,"width")&&(f.width=s.width),r.has(s,"height")&&(f.height=s.height),f.width+=s.paddingLeft+s.paddingRight,f.height+=s.paddingTop+s.paddingBottom,u.attr("transform","translate("+(s.paddingLeft-s.paddingRight)/2+","+(s.paddingTop-s.paddingBottom)/2+")");var d=o.select(this);d.select(".label-container").remove();var p=h(d,f,s).classed("label-container",!0);a.applyStyle(p,s.style);var y=p.node().getBBox();s.width=y.width,s.height=y.height})),s=u.exit?u.exit():u.selectAll(null),a.applyTransition(s,e).style("opacity",0).remove(),u}},4322:(t,e,n)=>{var r;if(!r)try{r=n(7188)}catch(t){}r||(r=window.d3),t.exports=r},1463:(t,e,n)=>{var r;try{r=n(681)}catch(t){}r||(r=window.dagre),t.exports=r},6614:(t,e,n)=>{var r;try{r=n(8282)}catch(t){}r||(r=window.graphlib),t.exports=r},8114:(t,e,n)=>{t.exports={node:n(7584),circle:n(6587),ellipse:n(3260),polygon:n(5337),rect:n(8049)}},6587:(t,e,n)=>{var r=n(3260);t.exports=function(t,e,n){return r(t,e,e,n)}},3260:t=>{t.exports=function(t,e,n,r){var i=t.x,a=t.y,o=i-r.x,s=a-r.y,c=Math.sqrt(e*e*s*s+n*n*o*o),u=Math.abs(e*n*o/c);r.x{function e(t,e){return t*e>0}t.exports=function(t,n,r,i){var a,o,s,c,u,l,h,f,d,p,y,g,m;if(a=n.y-t.y,s=t.x-n.x,u=n.x*t.y-t.x*n.y,d=a*r.x+s*r.y+u,p=a*i.x+s*i.y+u,!(0!==d&&0!==p&&e(d,p)||(o=i.y-r.y,c=r.x-i.x,l=i.x*r.y-r.x*i.y,h=o*t.x+c*t.y+l,f=o*n.x+c*n.y+l,0!==h&&0!==f&&e(h,f)||0==(y=a*c-o*s))))return g=Math.abs(y/2),{x:(m=s*l-c*u)<0?(m-g)/y:(m+g)/y,y:(m=o*u-a*l)<0?(m-g)/y:(m+g)/y}}},7584:t=>{t.exports=function(t,e){return t.intersect(e)}},5337:(t,e,n)=>{var r=n(6808);t.exports=function(t,e,n){var i=t.x,a=t.y,o=[],s=Number.POSITIVE_INFINITY,c=Number.POSITIVE_INFINITY;e.forEach((function(t){s=Math.min(s,t.x),c=Math.min(c,t.y)}));for(var u=i-t.width/2-s,l=a-t.height/2-c,h=0;h1&&o.sort((function(t,e){var r=t.x-n.x,i=t.y-n.y,a=Math.sqrt(r*r+i*i),o=e.x-n.x,s=e.y-n.y,c=Math.sqrt(o*o+s*s);return a{t.exports=function(t,e){var n,r,i=t.x,a=t.y,o=e.x-i,s=e.y-a,c=t.width/2,u=t.height/2;return Math.abs(s)*c>Math.abs(o)*u?(s<0&&(u=-u),n=0===s?0:u*o/s,r=u):(o<0&&(c=-c),n=c,r=0===o?0:c*s/o),{x:i+n,y:a+r}}},8284:(t,e,n)=>{var r=n(8355);t.exports=function(t,e){var n=t.append("foreignObject").attr("width","100000"),i=n.append("xhtml:div");i.attr("xmlns","http://www.w3.org/1999/xhtml");var a=e.label;switch(typeof a){case"function":i.insert(a);break;case"object":i.insert((function(){return a}));break;default:i.html(a)}r.applyStyle(i,e.labelStyle),i.style("display","inline-block"),i.style("white-space","nowrap");var o=i.node().getBoundingClientRect();return n.attr("width",o.width).attr("height",o.height),n}},1322:(t,e,n)=>{var r=n(7318),i=n(8284),a=n(8287);t.exports=function(t,e,n){var o=e.label,s=t.append("g");"svg"===e.labelType?a(s,e):"string"!=typeof o||"html"===e.labelType?i(s,e):r(s,e);var c,u=s.node().getBBox();switch(n){case"top":c=-e.height/2;break;case"bottom":c=e.height/2-u.height;break;default:c=-u.height/2}return s.attr("transform","translate("+-u.width/2+","+c+")"),s}},8287:(t,e,n)=>{var r=n(8355);t.exports=function(t,e){var n=t;return n.node().appendChild(e.label),r.applyStyle(n,e.labelStyle),n}},7318:(t,e,n)=>{var r=n(8355);t.exports=function(t,e){for(var n=t.append("text"),i=function(t){for(var e,n="",r=!1,i=0;i{var r;try{r={defaults:n(1747),each:n(6073),isFunction:n(3560),isPlainObject:n(8630),pick:n(9722),has:n(8721),range:n(6026),uniqueId:n(3955)}}catch(t){}r||(r=window._),t.exports=r},6381:(t,e,n)=>{"use strict";var r=n(8355),i=n(4322);t.exports=function(t,e){var n=t.filter((function(){return!i.select(this).classed("update")}));function a(t){var n=e.node(t);return"translate("+n.x+","+n.y+")"}n.attr("transform",a),r.applyTransition(t,e).style("opacity",1).attr("transform",a),r.applyTransition(n.selectAll("rect"),e).attr("width",(function(t){return e.node(t).width})).attr("height",(function(t){return e.node(t).height})).attr("x",(function(t){return-e.node(t).width/2})).attr("y",(function(t){return-e.node(t).height/2}))}},4577:(t,e,n)=>{"use strict";var r=n(8355),i=n(4322),a=n(1034);t.exports=function(t,e){function n(t){var n=e.edge(t);return a.has(n,"x")?"translate("+n.x+","+n.y+")":""}t.filter((function(){return!i.select(this).classed("update")})).attr("transform",n),r.applyTransition(t,e).style("opacity",1).attr("transform",n)}},4849:(t,e,n)=>{"use strict";var r=n(8355),i=n(4322);t.exports=function(t,e){function n(t){var n=e.node(t);return"translate("+n.x+","+n.y+")"}t.filter((function(){return!i.select(this).classed("update")})).attr("transform",n),r.applyTransition(t,e).style("opacity",1).attr("transform",n)}},5787:(t,e,n)=>{var r=n(1034),i=n(4322),a=n(1463).layout;t.exports=function(){var t=n(607),e=n(5632),i=n(6315),u=n(940),l=n(4849),h=n(4577),f=n(6381),d=n(4418),p=n(9144),y=function(n,y){!function(t){t.nodes().forEach((function(e){var n=t.node(e);r.has(n,"label")||t.children(e).length||(n.label=e),r.has(n,"paddingX")&&r.defaults(n,{paddingLeft:n.paddingX,paddingRight:n.paddingX}),r.has(n,"paddingY")&&r.defaults(n,{paddingTop:n.paddingY,paddingBottom:n.paddingY}),r.has(n,"padding")&&r.defaults(n,{paddingLeft:n.padding,paddingRight:n.padding,paddingTop:n.padding,paddingBottom:n.padding}),r.defaults(n,o),r.each(["paddingLeft","paddingRight","paddingTop","paddingBottom"],(function(t){n[t]=Number(n[t])})),r.has(n,"width")&&(n._prevWidth=n.width),r.has(n,"height")&&(n._prevHeight=n.height)})),t.edges().forEach((function(e){var n=t.edge(e);r.has(n,"label")||(n.label=""),r.defaults(n,s)}))}(y);var g=c(n,"output"),m=c(g,"clusters"),v=c(g,"edgePaths"),b=i(c(g,"edgeLabels"),y),_=t(c(g,"nodes"),y,d);a(y),l(_,y),h(b,y),u(v,y,p);var x=e(m,y);f(x,y),function(t){r.each(t.nodes(),(function(e){var n=t.node(e);r.has(n,"_prevWidth")?n.width=n._prevWidth:delete n.width,r.has(n,"_prevHeight")?n.height=n._prevHeight:delete n.height,delete n._prevWidth,delete n._prevHeight}))}(y)};return y.createNodes=function(e){return arguments.length?(t=e,y):t},y.createClusters=function(t){return arguments.length?(e=t,y):e},y.createEdgeLabels=function(t){return arguments.length?(i=t,y):i},y.createEdgePaths=function(t){return arguments.length?(u=t,y):u},y.shapes=function(t){return arguments.length?(d=t,y):d},y.arrows=function(t){return arguments.length?(p=t,y):p},y};var o={paddingLeft:10,paddingRight:10,paddingTop:10,paddingBottom:10,rx:0,ry:0,shape:"rect"},s={arrowhead:"normal",curve:i.curveLinear};function c(t,e){var n=t.select("g."+e);return n.empty()&&(n=t.append("g").attr("class",e)),n}},4418:(t,e,n)=>{"use strict";var r=n(8049),i=n(3260),a=n(6587),o=n(5337);t.exports={rect:function(t,e,n){var i=t.insert("rect",":first-child").attr("rx",n.rx).attr("ry",n.ry).attr("x",-e.width/2).attr("y",-e.height/2).attr("width",e.width).attr("height",e.height);return n.intersect=function(t){return r(n,t)},i},ellipse:function(t,e,n){var r=e.width/2,a=e.height/2,o=t.insert("ellipse",":first-child").attr("x",-e.width/2).attr("y",-e.height/2).attr("rx",r).attr("ry",a);return n.intersect=function(t){return i(n,r,a,t)},o},circle:function(t,e,n){var r=Math.max(e.width,e.height)/2,i=t.insert("circle",":first-child").attr("x",-e.width/2).attr("y",-e.height/2).attr("r",r);return n.intersect=function(t){return a(n,r,t)},i},diamond:function(t,e,n){var r=e.width*Math.SQRT2/2,i=e.height*Math.SQRT2/2,a=[{x:0,y:-i},{x:-r,y:0},{x:0,y:i},{x:r,y:0}],s=t.insert("polygon",":first-child").attr("points",a.map((function(t){return t.x+","+t.y})).join(" "));return n.intersect=function(t){return o(n,a,t)},s}}},8355:(t,e,n)=>{var r=n(1034);t.exports={isSubgraph:function(t,e){return!!t.children(e).length},edgeToId:function(t){return a(t.v)+":"+a(t.w)+":"+a(t.name)},applyStyle:function(t,e){e&&t.attr("style",e)},applyClass:function(t,e,n){e&&t.attr("class",e).attr("class",n+" "+t.attr("class"))},applyTransition:function(t,e){var n=e.graph();if(r.isPlainObject(n)){var i=n.transition;if(r.isFunction(i))return i(t)}return t}};var i=/:/g;function a(t){return t?String(t).replace(i,"\\:"):""}},5689:t=>{t.exports="0.6.4"},7188:(t,e,n)=>{"use strict";n.r(e),n.d(e,{FormatSpecifier:()=>rc,active:()=>Kr,arc:()=>rx,area:()=>ux,areaRadial:()=>vx,ascending:()=>i,autoType:()=>Do,axisBottom:()=>it,axisLeft:()=>at,axisRight:()=>rt,axisTop:()=>nt,bisect:()=>u,bisectLeft:()=>c,bisectRight:()=>s,bisector:()=>a,blob:()=>hs,brush:()=>Si,brushSelection:()=>Ti,brushX:()=>Ei,brushY:()=>Ci,buffer:()=>ds,chord:()=>Ri,clientPoint:()=>Nn,cluster:()=>_d,color:()=>We,contourDensity:()=>to,contours:()=>Ga,create:()=>N_,creator:()=>ie,cross:()=>f,csv:()=>vs,csvFormat:()=>vo,csvFormatBody:()=>bo,csvFormatRow:()=>xo,csvFormatRows:()=>_o,csvFormatValue:()=>wo,csvParse:()=>go,csvParseRows:()=>mo,cubehelix:()=>Pa,curveBasis:()=>Kx,curveBasisClosed:()=>tw,curveBasisOpen:()=>nw,curveBundle:()=>iw,curveCardinal:()=>sw,curveCardinalClosed:()=>uw,curveCardinalOpen:()=>hw,curveCatmullRom:()=>pw,curveCatmullRomClosed:()=>gw,curveCatmullRomOpen:()=>vw,curveLinear:()=>ax,curveLinearClosed:()=>_w,curveMonotoneX:()=>Aw,curveMonotoneY:()=>Mw,curveNatural:()=>Ow,curveStep:()=>Lw,curveStepAfter:()=>Rw,curveStepBefore:()=>Iw,customEvent:()=>ge,descending:()=>d,deviation:()=>g,dispatch:()=>ft,drag:()=>so,dragDisable:()=>Se,dragEnable:()=>Ae,dsv:()=>ms,dsvFormat:()=>po,easeBack:()=>as,easeBackIn:()=>rs,easeBackInOut:()=>as,easeBackOut:()=>is,easeBounce:()=>ts,easeBounceIn:()=>Jo,easeBounceInOut:()=>es,easeBounceOut:()=>ts,easeCircle:()=>Qo,easeCircleIn:()=>Xo,easeCircleInOut:()=>Qo,easeCircleOut:()=>Zo,easeCubic:()=>Gr,easeCubicIn:()=>Wr,easeCubicInOut:()=>Gr,easeCubicOut:()=>Vr,easeElastic:()=>cs,easeElasticIn:()=>ss,easeElasticInOut:()=>us,easeElasticOut:()=>cs,easeExp:()=>Go,easeExpIn:()=>Wo,easeExpInOut:()=>Go,easeExpOut:()=>Vo,easeLinear:()=>Bo,easePoly:()=>jo,easePolyIn:()=>Fo,easePolyInOut:()=>jo,easePolyOut:()=>Po,easeQuad:()=>Ro,easeQuadIn:()=>Lo,easeQuadInOut:()=>Ro,easeQuadOut:()=>Io,easeSin:()=>Ho,easeSinIn:()=>Uo,easeSinInOut:()=>Ho,easeSinOut:()=>qo,entries:()=>da,event:()=>le,extent:()=>m,forceCenter:()=>Ss,forceCollide:()=>Ys,forceLink:()=>qs,forceManyBody:()=>Gs,forceRadial:()=>Xs,forceSimulation:()=>Vs,forceX:()=>Zs,forceY:()=>Qs,format:()=>cc,formatDefaultLocale:()=>dc,formatLocale:()=>fc,formatPrefix:()=>uc,formatSpecifier:()=>nc,geoAlbers:()=>If,geoAlbersUsa:()=>Rf,geoArea:()=>uu,geoAzimuthalEqualArea:()=>Yf,geoAzimuthalEqualAreaRaw:()=>jf,geoAzimuthalEquidistant:()=>Uf,geoAzimuthalEquidistantRaw:()=>zf,geoBounds:()=>el,geoCentroid:()=>dl,geoCircle:()=>Tl,geoClipAntimeridian:()=>Rl,geoClipCircle:()=>Fl,geoClipExtent:()=>zl,geoClipRectangle:()=>Yl,geoConicConformal:()=>Gf,geoConicConformalRaw:()=>Vf,geoConicEqualArea:()=>Lf,geoConicEqualAreaRaw:()=>Bf,geoConicEquidistant:()=>Kf,geoConicEquidistantRaw:()=>Qf,geoContains:()=>ch,geoDistance:()=>Jl,geoEqualEarth:()=>ad,geoEqualEarthRaw:()=>id,geoEquirectangular:()=>Zf,geoEquirectangularRaw:()=>Xf,geoGnomonic:()=>sd,geoGnomonicRaw:()=>od,geoGraticule:()=>hh,geoGraticule10:()=>fh,geoIdentity:()=>cd,geoInterpolate:()=>dh,geoLength:()=>Zl,geoMercator:()=>Hf,geoMercatorRaw:()=>qf,geoNaturalEarth1:()=>ld,geoNaturalEarth1Raw:()=>ud,geoOrthographic:()=>fd,geoOrthographicRaw:()=>hd,geoPath:()=>gf,geoProjection:()=>Nf,geoProjectionMutator:()=>Df,geoRotation:()=>xl,geoStereographic:()=>pd,geoStereographicRaw:()=>dd,geoStream:()=>Zc,geoTransform:()=>mf,geoTransverseMercator:()=>gd,geoTransverseMercatorRaw:()=>yd,gray:()=>va,hcl:()=>Sa,hierarchy:()=>wd,histogram:()=>D,hsl:()=>rn,html:()=>Es,image:()=>_s,interpolate:()=>An,interpolateArray:()=>_n,interpolateBasis:()=>cn,interpolateBasisClosed:()=>un,interpolateBlues:()=>r_,interpolateBrBG:()=>yb,interpolateBuGn:()=>Bb,interpolateBuPu:()=>Ib,interpolateCividis:()=>p_,interpolateCool:()=>m_,interpolateCubehelix:()=>Lp,interpolateCubehelixDefault:()=>y_,interpolateCubehelixLong:()=>Ip,interpolateDate:()=>wn,interpolateDiscrete:()=>_p,interpolateGnBu:()=>Fb,interpolateGreens:()=>a_,interpolateGreys:()=>s_,interpolateHcl:()=>Dp,interpolateHclLong:()=>Op,interpolateHsl:()=>Sp,interpolateHslLong:()=>Ap,interpolateHue:()=>xp,interpolateInferno:()=>A_,interpolateLab:()=>Mp,interpolateMagma:()=>S_,interpolateNumber:()=>kn,interpolateNumberArray:()=>vn,interpolateObject:()=>Tn,interpolateOrRd:()=>jb,interpolateOranges:()=>d_,interpolatePRGn:()=>mb,interpolatePiYG:()=>bb,interpolatePlasma:()=>M_,interpolatePuBu:()=>qb,interpolatePuBuGn:()=>zb,interpolatePuOr:()=>xb,interpolatePuRd:()=>$b,interpolatePurples:()=>u_,interpolateRainbow:()=>b_,interpolateRdBu:()=>kb,interpolateRdGy:()=>Eb,interpolateRdPu:()=>Vb,interpolateRdYlBu:()=>Sb,interpolateRdYlGn:()=>Mb,interpolateReds:()=>h_,interpolateRgb:()=>pn,interpolateRgbBasis:()=>gn,interpolateRgbBasisClosed:()=>mn,interpolateRound:()=>wp,interpolateSinebow:()=>k_,interpolateSpectral:()=>Db,interpolateString:()=>Sn,interpolateTransformCss:()=>dr,interpolateTransformSvg:()=>pr,interpolateTurbo:()=>T_,interpolateViridis:()=>C_,interpolateWarm:()=>g_,interpolateYlGn:()=>Qb,interpolateYlGnBu:()=>Xb,interpolateYlOrBr:()=>Jb,interpolateYlOrRd:()=>e_,interpolateZoom:()=>Ep,interrupt:()=>ir,interval:()=>ek,isoFormat:()=>Jw,isoParse:()=>tk,json:()=>ws,keys:()=>ha,lab:()=>ba,lch:()=>Ca,line:()=>cx,lineRadial:()=>mx,linkHorizontal:()=>Sx,linkRadial:()=>Mx,linkVertical:()=>Ax,local:()=>O_,map:()=>ea,matcher:()=>mt,max:()=>I,mean:()=>R,median:()=>F,merge:()=>P,min:()=>j,mouse:()=>On,namespace:()=>Et,namespaces:()=>Tt,nest:()=>na,now:()=>qn,pack:()=>Vd,packEnclose:()=>Ad,packSiblings:()=>zd,pairs:()=>l,partition:()=>Jd,path:()=>$i,permute:()=>Y,pie:()=>fx,piecewise:()=>Rp,pointRadial:()=>bx,polygonArea:()=>Pp,polygonCentroid:()=>jp,polygonContains:()=>Hp,polygonHull:()=>qp,polygonLength:()=>$p,precisionFixed:()=>pc,precisionPrefix:()=>yc,precisionRound:()=>gc,quadtree:()=>Ls,quantile:()=>O,quantize:()=>Fp,radialArea:()=>vx,radialLine:()=>mx,randomBates:()=>Qp,randomExponential:()=>Kp,randomIrwinHall:()=>Zp,randomLogNormal:()=>Xp,randomNormal:()=>Gp,randomUniform:()=>Vp,range:()=>k,rgb:()=>Ze,ribbon:()=>Qi,scaleBand:()=>oy,scaleDiverging:()=>Qv,scaleDivergingLog:()=>Kv,scaleDivergingPow:()=>tb,scaleDivergingSqrt:()=>eb,scaleDivergingSymlog:()=>Jv,scaleIdentity:()=>wy,scaleImplicit:()=>iy,scaleLinear:()=>xy,scaleLog:()=>Dy,scaleOrdinal:()=>ay,scalePoint:()=>cy,scalePow:()=>Yy,scaleQuantile:()=>Uy,scaleQuantize:()=>qy,scaleSequential:()=>Hv,scaleSequentialLog:()=>$v,scaleSequentialPow:()=>Vv,scaleSequentialQuantile:()=>Xv,scaleSequentialSqrt:()=>Gv,scaleSequentialSymlog:()=>Wv,scaleSqrt:()=>zy,scaleSymlog:()=>Iy,scaleThreshold:()=>Hy,scaleTime:()=>Dv,scaleUtc:()=>zv,scan:()=>z,schemeAccent:()=>ib,schemeBlues:()=>n_,schemeBrBG:()=>pb,schemeBuGn:()=>Ob,schemeBuPu:()=>Lb,schemeCategory10:()=>rb,schemeDark2:()=>ab,schemeGnBu:()=>Rb,schemeGreens:()=>i_,schemeGreys:()=>o_,schemeOrRd:()=>Pb,schemeOranges:()=>f_,schemePRGn:()=>gb,schemePaired:()=>ob,schemePastel1:()=>sb,schemePastel2:()=>cb,schemePiYG:()=>vb,schemePuBu:()=>Ub,schemePuBuGn:()=>Yb,schemePuOr:()=>_b,schemePuRd:()=>Hb,schemePurples:()=>c_,schemeRdBu:()=>wb,schemeRdGy:()=>Tb,schemeRdPu:()=>Wb,schemeRdYlBu:()=>Cb,schemeRdYlGn:()=>Ab,schemeReds:()=>l_,schemeSet1:()=>ub,schemeSet2:()=>lb,schemeSet3:()=>hb,schemeSpectral:()=>Nb,schemeTableau10:()=>fb,schemeYlGn:()=>Zb,schemeYlGnBu:()=>Gb,schemeYlOrBr:()=>Kb,schemeYlOrRd:()=>t_,select:()=>Te,selectAll:()=>L_,selection:()=>ke,selector:()=>pt,selectorAll:()=>gt,set:()=>la,shuffle:()=>U,stack:()=>Yw,stackOffsetDiverging:()=>Uw,stackOffsetExpand:()=>zw,stackOffsetNone:()=>Fw,stackOffsetSilhouette:()=>qw,stackOffsetWiggle:()=>Hw,stackOrderAppearance:()=>$w,stackOrderAscending:()=>Vw,stackOrderDescending:()=>Xw,stackOrderInsideOut:()=>Zw,stackOrderNone:()=>Pw,stackOrderReverse:()=>Qw,stratify:()=>ip,style:()=>Rt,sum:()=>q,svg:()=>Cs,symbol:()=>Gx,symbolCircle:()=>Nx,symbolCross:()=>Dx,symbolDiamond:()=>Lx,symbolSquare:()=>jx,symbolStar:()=>Px,symbolTriangle:()=>zx,symbolWye:()=>Wx,symbols:()=>Vx,text:()=>ys,thresholdFreedmanDiaconis:()=>B,thresholdScott:()=>L,thresholdSturges:()=>N,tickFormat:()=>by,tickIncrement:()=>A,tickStep:()=>M,ticks:()=>S,timeDay:()=>bg,timeDays:()=>_g,timeFormat:()=>am,timeFormatDefaultLocale:()=>Cv,timeFormatLocale:()=>rm,timeFriday:()=>ug,timeFridays:()=>gg,timeHour:()=>wg,timeHours:()=>kg,timeInterval:()=>Vy,timeMillisecond:()=>Dg,timeMilliseconds:()=>Og,timeMinute:()=>Eg,timeMinutes:()=>Cg,timeMonday:()=>ag,timeMondays:()=>fg,timeMonth:()=>Ky,timeMonths:()=>Jy,timeParse:()=>om,timeSaturday:()=>lg,timeSaturdays:()=>mg,timeSecond:()=>Ag,timeSeconds:()=>Mg,timeSunday:()=>ig,timeSundays:()=>hg,timeThursday:()=>cg,timeThursdays:()=>yg,timeTuesday:()=>og,timeTuesdays:()=>dg,timeWednesday:()=>sg,timeWednesdays:()=>pg,timeWeek:()=>ig,timeWeeks:()=>hg,timeYear:()=>Xy,timeYears:()=>Zy,timeout:()=>Qn,timer:()=>Wn,timerFlush:()=>Vn,touch:()=>Dn,touches:()=>I_,transition:()=>qr,transpose:()=>H,tree:()=>hp,treemap:()=>gp,treemapBinary:()=>mp,treemapDice:()=>Kd,treemapResquarify:()=>bp,treemapSlice:()=>fp,treemapSliceDice:()=>vp,treemapSquarify:()=>yp,tsv:()=>bs,tsvFormat:()=>Co,tsvFormatBody:()=>So,tsvFormatRow:()=>Mo,tsvFormatRows:()=>Ao,tsvFormatValue:()=>No,tsvParse:()=>To,tsvParseRows:()=>Eo,utcDay:()=>Xg,utcDays:()=>Zg,utcFormat:()=>sm,utcFriday:()=>jg,utcFridays:()=>Wg,utcHour:()=>Rv,utcHours:()=>Fv,utcMillisecond:()=>Dg,utcMilliseconds:()=>Og,utcMinute:()=>jv,utcMinutes:()=>Yv,utcMonday:()=>Ig,utcMondays:()=>Ug,utcMonth:()=>Bv,utcMonths:()=>Lv,utcParse:()=>cm,utcSaturday:()=>Yg,utcSaturdays:()=>Vg,utcSecond:()=>Ag,utcSeconds:()=>Mg,utcSunday:()=>Lg,utcSundays:()=>zg,utcThursday:()=>Pg,utcThursdays:()=>$g,utcTuesday:()=>Rg,utcTuesdays:()=>qg,utcWednesday:()=>Fg,utcWednesdays:()=>Hg,utcWeek:()=>Lg,utcWeeks:()=>zg,utcYear:()=>Kg,utcYears:()=>Jg,values:()=>fa,variance:()=>y,version:()=>r,voronoi:()=>zk,window:()=>Ot,xml:()=>Ts,zip:()=>W,zoom:()=>eT,zoomIdentity:()=>$k,zoomTransform:()=>Wk});var r="5.16.0";function i(t,e){return te?1:t>=e?0:NaN}function a(t){var e;return 1===t.length&&(e=t,t=function(t,n){return i(e(t),n)}),{left:function(e,n,r,i){for(null==r&&(r=0),null==i&&(i=e.length);r>>1;t(e[a],n)<0?r=a+1:i=a}return r},right:function(e,n,r,i){for(null==r&&(r=0),null==i&&(i=e.length);r>>1;t(e[a],n)>0?i=a:r=a+1}return r}}}var o=a(i),s=o.right,c=o.left;const u=s;function l(t,e){null==e&&(e=h);for(var n=0,r=t.length-1,i=t[0],a=new Array(r<0?0:r);nt?1:e>=t?0:NaN}function p(t){return null===t?NaN:+t}function y(t,e){var n,r,i=t.length,a=0,o=-1,s=0,c=0;if(null==e)for(;++o1)return c/(a-1)}function g(t,e){var n=y(t,e);return n?Math.sqrt(n):n}function m(t,e){var n,r,i,a=t.length,o=-1;if(null==e){for(;++o=n)for(r=i=n;++on&&(r=n),i=n)for(r=i=n;++on&&(r=n),i0)return[t];if((r=e0)for(t=Math.ceil(t/o),e=Math.floor(e/o),a=new Array(i=Math.ceil(e-t+1));++s=0?(a>=T?10:a>=E?5:a>=C?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(a>=T?10:a>=E?5:a>=C?2:1)}function M(t,e,n){var r=Math.abs(e-t)/Math.max(0,n),i=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),a=r/i;return a>=T?i*=10:a>=E?i*=5:a>=C&&(i*=2),eh;)f.pop(),--d;var p,y=new Array(d+1);for(i=0;i<=d;++i)(p=y[i]=[]).x0=i>0?f[i-1]:l,p.x1=i=1)return+n(t[r-1],r-1,t);var r,i=(r-1)*e,a=Math.floor(i),o=+n(t[a],a,t);return o+(+n(t[a+1],a+1,t)-o)*(i-a)}}function B(t,e,n){return t=_.call(t,p).sort(i),Math.ceil((n-e)/(2*(O(t,.75)-O(t,.25))*Math.pow(t.length,-1/3)))}function L(t,e,n){return Math.ceil((n-e)/(3.5*g(t)*Math.pow(t.length,-1/3)))}function I(t,e){var n,r,i=t.length,a=-1;if(null==e){for(;++a=n)for(r=n;++ar&&(r=n)}else for(;++a=n)for(r=n;++ar&&(r=n);return r}function R(t,e){var n,r=t.length,i=r,a=-1,o=0;if(null==e)for(;++a=0;)for(e=(r=t[i]).length;--e>=0;)n[--o]=r[e];return n}function j(t,e){var n,r,i=t.length,a=-1;if(null==e){for(;++a=n)for(r=n;++an&&(r=n)}else for(;++a=n)for(r=n;++an&&(r=n);return r}function Y(t,e){for(var n=e.length,r=new Array(n);n--;)r[n]=t[e[n]];return r}function z(t,e){if(n=t.length){var n,r,a=0,o=0,s=t[o];for(null==e&&(e=i);++a=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))}function lt(t,e){for(var n,r=0,i=t.length;r0)for(var n,r,i=new Array(n),a=0;ae?1:t>=e?0:NaN}bt.prototype={constructor:bt,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var kt="http://www.w3.org/1999/xhtml";const Tt={svg:"http://www.w3.org/2000/svg",xhtml:kt,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Et(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),Tt.hasOwnProperty(e)?{space:Tt[e],local:t}:t}function Ct(t){return function(){this.removeAttribute(t)}}function St(t){return function(){this.removeAttributeNS(t.space,t.local)}}function At(t,e){return function(){this.setAttribute(t,e)}}function Mt(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Nt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function Dt(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function Ot(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Bt(t){return function(){this.style.removeProperty(t)}}function Lt(t,e,n){return function(){this.style.setProperty(t,e,n)}}function It(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function Rt(t,e){return t.style.getPropertyValue(e)||Ot(t).getComputedStyle(t,null).getPropertyValue(e)}function Ft(t){return function(){delete this[t]}}function Pt(t,e){return function(){this[t]=e}}function jt(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function Yt(t){return t.trim().split(/^|\s+/)}function zt(t){return t.classList||new Ut(t)}function Ut(t){this._node=t,this._names=Yt(t.getAttribute("class")||"")}function qt(t,e){for(var n=zt(t),r=-1,i=e.length;++r=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var ue={},le=null;function he(t,e,n){return t=fe(t,e,n),function(e){var n=e.relatedTarget;n&&(n===this||8&n.compareDocumentPosition(this))||t.call(this,e)}}function fe(t,e,n){return function(r){var i=le;le=r;try{t.call(this,this.__data__,e,n)}finally{le=i}}}function de(t){return t.trim().split(/^|\s+/).map((function(t){var e="",n=t.indexOf(".");return n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}}))}function pe(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r=x&&(x=_+1);!(b=m[x])&&++x=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=wt);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a1?this.each((null==e?Bt:"function"==typeof e?It:Lt)(t,e,null==n?"":n)):Rt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?Ft:"function"==typeof e?jt:Pt)(t,e)):this.node()[t]},classed:function(t,e){var n=Yt(t+"");if(arguments.length<2){for(var r=zt(this.node()),i=-1,a=n.length;++i>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Ge(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Ge(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Fe.exec(t))?new Qe(e[1],e[2],e[3],1):(e=Pe.exec(t))?new Qe(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=je.exec(t))?Ge(e[1],e[2],e[3],e[4]):(e=Ye.exec(t))?Ge(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=ze.exec(t))?en(e[1],e[2]/100,e[3]/100,1):(e=Ue.exec(t))?en(e[1],e[2]/100,e[3]/100,e[4]):qe.hasOwnProperty(t)?Ve(qe[t]):"transparent"===t?new Qe(NaN,NaN,NaN,0):null}function Ve(t){return new Qe(t>>16&255,t>>8&255,255&t,1)}function Ge(t,e,n,r){return r<=0&&(t=e=n=NaN),new Qe(t,e,n,r)}function Xe(t){return t instanceof De||(t=We(t)),t?new Qe((t=t.rgb()).r,t.g,t.b,t.opacity):new Qe}function Ze(t,e,n,r){return 1===arguments.length?Xe(t):new Qe(t,e,n,null==r?1:r)}function Qe(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function Ke(){return"#"+tn(this.r)+tn(this.g)+tn(this.b)}function Je(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function tn(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function en(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new an(t,e,n,r)}function nn(t){if(t instanceof an)return new an(t.h,t.s,t.l,t.opacity);if(t instanceof De||(t=We(t)),!t)return new an;if(t instanceof an)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n0&&c<1?0:o,new an(o,s,c,t.opacity)}function rn(t,e,n,r){return 1===arguments.length?nn(t):new an(t,e,n,null==r?1:r)}function an(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function on(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function sn(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}function cn(t){var e=t.length-1;return function(n){var r=n<=0?n=0:n>=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=r180||n<-180?n-360*Math.round(n/360):n):ln(isNaN(t)?e:t)}function dn(t,e){var n=e-t;return n?hn(t,n):ln(isNaN(t)?e:t)}Me(De,We,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:He,formatHex:He,formatHsl:function(){return nn(this).formatHsl()},formatRgb:$e,toString:$e}),Me(Qe,Ze,Ne(De,{brighter:function(t){return t=null==t?Oe:Math.pow(Oe,t),new Qe(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Qe(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Ke,formatHex:Ke,formatRgb:Je,toString:Je})),Me(an,rn,Ne(De,{brighter:function(t){return t=null==t?Oe:Math.pow(Oe,t),new an(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new an(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new Qe(on(t>=240?t-240:t+120,i,r),on(t,i,r),on(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));const pn=function t(e){var n=function(t){return 1==(t=+t)?dn:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):ln(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=Ze(t)).r,(e=Ze(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=dn(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function yn(t){return function(e){var n,r,i=e.length,a=new Array(i),o=new Array(i),s=new Array(i);for(n=0;na&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,c.push({i:o,x:kn(n,r)})),a=Cn.lastIndex;return a=0&&e._call.call(null,t),e=e._next;--In}function Gn(){jn=(Pn=zn.now())+Yn,In=Rn=0;try{Vn()}finally{In=0,function(){for(var t,e,n=Bn,r=1/0;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:Bn=e);Ln=t,Zn(r)}(),jn=0}}function Xn(){var t=zn.now(),e=t-Pn;e>1e3&&(Yn-=e,Pn=t)}function Zn(t){In||(Rn&&(Rn=clearTimeout(Rn)),t-jn>24?(t<1/0&&(Rn=setTimeout(Gn,t-zn.now()-Yn)),Fn&&(Fn=clearInterval(Fn))):(Fn||(Pn=zn.now(),Fn=setInterval(Xn,1e3)),In=1,Un(Gn)))}function Qn(t,e,n){var r=new $n;return e=null==e?0:+e,r.restart((function(n){r.stop(),t(n+e)}),e,n),r}$n.prototype=Wn.prototype={constructor:$n,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?qn():+n)+(null==e?0:+e),this._next||Ln===this||(Ln?Ln._next=this:Bn=this,Ln=this),this._call=t,this._time=n,Zn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Zn())}};var Kn=ft("start","end","cancel","interrupt"),Jn=[];function tr(t,e,n,r,i,a){var o=t.__transition;if(o){if(n in o)return}else t.__transition={};!function(t,e,n){var r,i=t.__transition;function a(c){var u,l,h,f;if(1!==n.state)return s();for(u in i)if((f=i[u]).name===n.name){if(3===f.state)return Qn(a);4===f.state?(f.state=6,f.timer.stop(),f.on.call("interrupt",t,t.__data__,f.index,f.group),delete i[u]):+u0)throw new Error("too late; already scheduled");return n}function nr(t,e){var n=rr(t,e);if(n.state>3)throw new Error("too late; already running");return n}function rr(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function ir(t,e){var n,r,i,a=t.__transition,o=!0;if(a){for(i in e=null==e?null:e+"",a)(n=a[i]).name===e?(r=n.state>2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(r?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete a[i]):o=!1;o&&delete t.__transition}}var ar,or,sr,cr,ur=180/Math.PI,lr={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function hr(t,e,n,r,i,a){var o,s,c;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(c=t*n+e*r)&&(n-=t*c,r-=e*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),t*r180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:kn(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,c),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:kn(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,c),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:kn(t,n)},{i:s-2,x:kn(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,c),a=o=null,function(t){for(var e,n=-1,r=c.length;++n=0&&(t=t.slice(0,e)),!t||"start"===t}))}(e)?er:nr;return function(){var o=a(this,t),s=o.on;s!==r&&(i=(r=s).copy()).on(e,n),o.on=i}}var Ir=ke.prototype.constructor;function Rr(t){return function(){this.style.removeProperty(t)}}function Fr(t,e,n){return function(r){this.style.setProperty(t,e.call(this,r),n)}}function Pr(t,e,n){var r,i;function a(){var a=e.apply(this,arguments);return a!==i&&(r=(i=a)&&Fr(t,a,n)),r}return a._value=e,a}function jr(t){return function(e){this.textContent=t.call(this,e)}}function Yr(t){var e,n;function r(){var r=t.apply(this,arguments);return r!==n&&(e=(n=r)&&jr(r)),e}return r._value=t,r}var zr=0;function Ur(t,e,n,r){this._groups=t,this._parents=e,this._name=n,this._id=r}function qr(t){return ke().transition(t)}function Hr(){return++zr}var $r=ke.prototype;function Wr(t){return t*t*t}function Vr(t){return--t*t*t+1}function Gr(t){return((t*=2)<=1?t*t*t:(t-=2)*t*t+2)/2}Ur.prototype=qr.prototype={constructor:Ur,select:function(t){var e=this._name,n=this._id;"function"!=typeof t&&(t=pt(t));for(var r=this._groups,i=r.length,a=new Array(i),o=0;o1&&n.name===e)return new Ur([[t]],Qr,e,+r);return null}function Jr(t){return function(){return t}}function ti(t,e,n){this.target=t,this.type=e,this.selection=n}function ei(){le.stopImmediatePropagation()}function ni(){le.preventDefault(),le.stopImmediatePropagation()}var ri={name:"drag"},ii={name:"space"},ai={name:"handle"},oi={name:"center"};function si(t){return[+t[0],+t[1]]}function ci(t){return[si(t[0]),si(t[1])]}function ui(t){return function(e){return Dn(e,le.touches,t)}}var li={name:"x",handles:["w","e"].map(vi),input:function(t,e){return null==t?null:[[+t[0],e[0][1]],[+t[1],e[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},hi={name:"y",handles:["n","s"].map(vi),input:function(t,e){return null==t?null:[[e[0][0],+t[0]],[e[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},fi={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(vi),input:function(t){return null==t?null:ci(t)},output:function(t){return t}},di={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},pi={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},yi={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},gi={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},mi={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function vi(t){return{type:t}}function bi(){return!le.ctrlKey&&!le.button}function _i(){var t=this.ownerSVGElement||this;return t.hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function xi(){return navigator.maxTouchPoints||"ontouchstart"in this}function wi(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function ki(t){return t[0][0]===t[1][0]||t[0][1]===t[1][1]}function Ti(t){var e=t.__brush;return e?e.dim.output(e.selection):null}function Ei(){return Ai(li)}function Ci(){return Ai(hi)}function Si(){return Ai(fi)}function Ai(t){var e,n=_i,r=bi,i=xi,a=!0,o=ft("start","brush","end"),s=6;function c(e){var n=e.property("__brush",y).selectAll(".overlay").data([vi("overlay")]);n.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",di.overlay).merge(n).each((function(){var t=wi(this).extent;Te(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])})),e.selectAll(".selection").data([vi("selection")]).enter().append("rect").attr("class","selection").attr("cursor",di.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var r=e.selectAll(".handle").data(t.handles,(function(t){return t.type}));r.exit().remove(),r.enter().append("rect").attr("class",(function(t){return"handle handle--"+t.type})).attr("cursor",(function(t){return di[t.type]})),e.each(u).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",f).filter(i).on("touchstart.brush",f).on("touchmove.brush",d).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(){var t=Te(this),e=wi(this).selection;e?(t.selectAll(".selection").style("display",null).attr("x",e[0][0]).attr("y",e[0][1]).attr("width",e[1][0]-e[0][0]).attr("height",e[1][1]-e[0][1]),t.selectAll(".handle").style("display",null).attr("x",(function(t){return"e"===t.type[t.type.length-1]?e[1][0]-s/2:e[0][0]-s/2})).attr("y",(function(t){return"s"===t.type[0]?e[1][1]-s/2:e[0][1]-s/2})).attr("width",(function(t){return"n"===t.type||"s"===t.type?e[1][0]-e[0][0]+s:s})).attr("height",(function(t){return"e"===t.type||"w"===t.type?e[1][1]-e[0][1]+s:s}))):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function l(t,e,n){var r=t.__brush.emitter;return!r||n&&r.clean?new h(t,e,n):r}function h(t,e,n){this.that=t,this.args=e,this.state=t.__brush,this.active=0,this.clean=n}function f(){if((!e||le.touches)&&r.apply(this,arguments)){var n,i,o,s,c,h,f,d,p,y,g,m=this,v=le.target.__data__.type,b="selection"===(a&&le.metaKey?v="overlay":v)?ri:a&&le.altKey?oi:ai,_=t===hi?null:gi[v],x=t===li?null:mi[v],w=wi(m),k=w.extent,T=w.selection,E=k[0][0],C=k[0][1],S=k[1][0],A=k[1][1],M=0,N=0,D=_&&x&&a&&le.shiftKey,O=le.touches?ui(le.changedTouches[0].identifier):On,B=O(m),L=B,I=l(m,arguments,!0).beforestart();"overlay"===v?(T&&(p=!0),w.selection=T=[[n=t===hi?E:B[0],o=t===li?C:B[1]],[c=t===hi?S:n,f=t===li?A:o]]):(n=T[0][0],o=T[0][1],c=T[1][0],f=T[1][1]),i=n,s=o,h=c,d=f;var R=Te(m).attr("pointer-events","none"),F=R.selectAll(".overlay").attr("cursor",di[v]);if(le.touches)I.moved=j,I.ended=z;else{var P=Te(le.view).on("mousemove.brush",j,!0).on("mouseup.brush",z,!0);a&&P.on("keydown.brush",U,!0).on("keyup.brush",q,!0),Se(le.view)}ei(),ir(m),u.call(m),I.start()}function j(){var t=O(m);!D||y||g||(Math.abs(t[0]-L[0])>Math.abs(t[1]-L[1])?g=!0:y=!0),L=t,p=!0,ni(),Y()}function Y(){var t;switch(M=L[0]-B[0],N=L[1]-B[1],b){case ii:case ri:_&&(M=Math.max(E-n,Math.min(S-c,M)),i=n+M,h=c+M),x&&(N=Math.max(C-o,Math.min(A-f,N)),s=o+N,d=f+N);break;case ai:_<0?(M=Math.max(E-n,Math.min(S-n,M)),i=n+M,h=c):_>0&&(M=Math.max(E-c,Math.min(S-c,M)),i=n,h=c+M),x<0?(N=Math.max(C-o,Math.min(A-o,N)),s=o+N,d=f):x>0&&(N=Math.max(C-f,Math.min(A-f,N)),s=o,d=f+N);break;case oi:_&&(i=Math.max(E,Math.min(S,n-M*_)),h=Math.max(E,Math.min(S,c+M*_))),x&&(s=Math.max(C,Math.min(A,o-N*x)),d=Math.max(C,Math.min(A,f+N*x)))}h0&&(n=i-M),x<0?f=d-N:x>0&&(o=s-N),b=ii,F.attr("cursor",di.selection),Y());break;default:return}ni()}function q(){switch(le.keyCode){case 16:D&&(y=g=D=!1,Y());break;case 18:b===oi&&(_<0?c=h:_>0&&(n=i),x<0?f=d:x>0&&(o=s),b=ai,Y());break;case 32:b===ii&&(le.altKey?(_&&(c=h-M*_,n=i+M*_),x&&(f=d-N*x,o=s+N*x),b=oi):(_<0?c=h:_>0&&(n=i),x<0?f=d:x>0&&(o=s),b=ai),F.attr("cursor",di[v]),Y());break;default:return}ni()}}function d(){l(this,arguments).moved()}function p(){l(this,arguments).ended()}function y(){var e=this.__brush||{selection:null};return e.extent=ci(n.apply(this,arguments)),e.dim=t,e}return c.move=function(e,n){e.selection?e.on("start.brush",(function(){l(this,arguments).beforestart().start()})).on("interrupt.brush end.brush",(function(){l(this,arguments).end()})).tween("brush",(function(){var e=this,r=e.__brush,i=l(e,arguments),a=r.selection,o=t.input("function"==typeof n?n.apply(this,arguments):n,r.extent),s=An(a,o);function c(t){r.selection=1===t&&null===o?null:s(t),u.call(e),i.brush()}return null!==a&&null!==o?c:c(1)})):e.each((function(){var e=this,r=arguments,i=e.__brush,a=t.input("function"==typeof n?n.apply(e,r):n,i.extent),o=l(e,r).beforestart();ir(e),i.selection=null===a?null:a,u.call(e),o.start().brush().end()}))},c.clear=function(t){c.move(t,null)},h.prototype={beforestart:function(){return 1==++this.active&&(this.state.emitter=this,this.starting=!0),this},start:function(){return this.starting?(this.starting=!1,this.emit("start")):this.emit("brush"),this},brush:function(){return this.emit("brush"),this},end:function(){return 0==--this.active&&(delete this.state.emitter,this.emit("end")),this},emit:function(e){ge(new ti(c,e,t.output(this.state.selection)),o.apply,o,[e,this.that,this.args])}},c.extent=function(t){return arguments.length?(n="function"==typeof t?t:Jr(ci(t)),c):n},c.filter=function(t){return arguments.length?(r="function"==typeof t?t:Jr(!!t),c):r},c.touchable=function(t){return arguments.length?(i="function"==typeof t?t:Jr(!!t),c):i},c.handleSize=function(t){return arguments.length?(s=+t,c):s},c.keyModifiers=function(t){return arguments.length?(a=!!t,c):a},c.on=function(){var t=o.on.apply(o,arguments);return t===o?c:t},c}var Mi=Math.cos,Ni=Math.sin,Di=Math.PI,Oi=Di/2,Bi=2*Di,Li=Math.max;function Ii(t){return function(e,n){return t(e.source.value+e.target.value,n.source.value+n.target.value)}}function Ri(){var t=0,e=null,n=null,r=null;function i(i){var a,o,s,c,u,l,h=i.length,f=[],d=k(h),p=[],y=[],g=y.groups=new Array(h),m=new Array(h*h);for(a=0,u=-1;++uzi)if(Math.abs(l*s-c*u)>zi&&i){var f=n-a,d=r-o,p=s*s+c*c,y=f*f+d*d,g=Math.sqrt(p),m=Math.sqrt(h),v=i*Math.tan((ji-Math.acos((p+h-y)/(2*g*m)))/2),b=v/m,_=v/g;Math.abs(b-1)>zi&&(this._+="L"+(t+b*u)+","+(e+b*l)),this._+="A"+i+","+i+",0,0,"+ +(l*f>u*d)+","+(this._x1=t+_*s)+","+(this._y1=e+_*c)}else this._+="L"+(this._x1=t)+","+(this._y1=e)},arc:function(t,e,n,r,i,a){t=+t,e=+e,a=!!a;var o=(n=+n)*Math.cos(r),s=n*Math.sin(r),c=t+o,u=e+s,l=1^a,h=a?r-i:i-r;if(n<0)throw new Error("negative radius: "+n);null===this._x1?this._+="M"+c+","+u:(Math.abs(this._x1-c)>zi||Math.abs(this._y1-u)>zi)&&(this._+="L"+c+","+u),n&&(h<0&&(h=h%Yi+Yi),h>Ui?this._+="A"+n+","+n+",0,1,"+l+","+(t-o)+","+(e-s)+"A"+n+","+n+",0,1,"+l+","+(this._x1=c)+","+(this._y1=u):h>zi&&(this._+="A"+n+","+n+",0,"+ +(h>=ji)+","+l+","+(this._x1=t+n*Math.cos(i))+","+(this._y1=e+n*Math.sin(i))))},rect:function(t,e,n,r){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)+"h"+ +n+"v"+ +r+"h"+-n+"Z"},toString:function(){return this._}};const $i=Hi;function Wi(t){return t.source}function Vi(t){return t.target}function Gi(t){return t.radius}function Xi(t){return t.startAngle}function Zi(t){return t.endAngle}function Qi(){var t=Wi,e=Vi,n=Gi,r=Xi,i=Zi,a=null;function o(){var o,s=Fi.call(arguments),c=t.apply(this,s),u=e.apply(this,s),l=+n.apply(this,(s[0]=c,s)),h=r.apply(this,s)-Oi,f=i.apply(this,s)-Oi,d=l*Mi(h),p=l*Ni(h),y=+n.apply(this,(s[0]=u,s)),g=r.apply(this,s)-Oi,m=i.apply(this,s)-Oi;if(a||(a=o=$i()),a.moveTo(d,p),a.arc(0,0,l,h,f),h===g&&f===m||(a.quadraticCurveTo(0,0,y*Mi(g),y*Ni(g)),a.arc(0,0,y,g,m)),a.quadraticCurveTo(0,0,d,p),a.closePath(),o)return a=null,o+""||null}return o.radius=function(t){return arguments.length?(n="function"==typeof t?t:Pi(+t),o):n},o.startAngle=function(t){return arguments.length?(r="function"==typeof t?t:Pi(+t),o):r},o.endAngle=function(t){return arguments.length?(i="function"==typeof t?t:Pi(+t),o):i},o.source=function(e){return arguments.length?(t=e,o):t},o.target=function(t){return arguments.length?(e=t,o):e},o.context=function(t){return arguments.length?(a=null==t?null:t,o):a},o}var Ki="$";function Ji(){}function ta(t,e){var n=new Ji;if(t instanceof Ji)t.each((function(t,e){n.set(e,t)}));else if(Array.isArray(t)){var r,i=-1,a=t.length;if(null==e)for(;++i=r.length)return null!=t&&n.sort(t),null!=e?e(n):n;for(var c,u,l,h=-1,f=n.length,d=r[i++],p=ea(),y=o();++hr.length)return n;var o,s=i[a-1];return null!=e&&a>=r.length?o=n.entries():(o=[],n.each((function(e,n){o.push({key:n,values:t(e,a)})}))),null!=s?o.sort((function(t,e){return s(t.key,e.key)})):o}(a(t,0,aa,oa),0)},key:function(t){return r.push(t),n},sortKeys:function(t){return i[r.length-1]=t,n},sortValues:function(e){return t=e,n},rollup:function(t){return e=t,n}}}function ra(){return{}}function ia(t,e,n){t[e]=n}function aa(){return ea()}function oa(t,e,n){t.set(e,n)}function sa(){}var ca=ea.prototype;function ua(t,e){var n=new sa;if(t instanceof sa)t.each((function(t){n.add(t)}));else if(t){var r=-1,i=t.length;if(null==e)for(;++r.008856451679035631?Math.pow(t,1/3):t/ga+4/29}function wa(t){return t>6/29?t*t*t:ga*(t-4/29)}function ka(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function Ta(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function Ea(t){if(t instanceof Aa)return new Aa(t.h,t.c,t.l,t.opacity);if(t instanceof _a||(t=ma(t)),0===t.a&&0===t.b)return new Aa(NaN,0r!=d>r&&n<(f-u)*(r-l)/(d-l)+u&&(i=-i)}return i}function $a(t,e,n){var r,i,a,o;return function(t,e,n){return(e[0]-t[0])*(n[1]-t[1])==(n[0]-t[0])*(e[1]-t[1])}(t,e,n)&&(i=t[r=+(t[0]===e[0])],a=n[r],o=e[r],i<=a&&a<=o||o<=a&&a<=i)}function Wa(){}var Va=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function Ga(){var t=1,e=1,n=N,r=s;function i(t){var e=n(t);if(Array.isArray(e))e=e.slice().sort(za);else{var r=m(t),i=r[0],o=r[1];e=M(i,o,e),e=k(Math.floor(i/e)*e,Math.floor(o/e)*e,e)}return e.map((function(e){return a(t,e)}))}function a(n,i){var a=[],s=[];return function(n,r,i){var a,s,c,u,l,h,f=new Array,d=new Array;for(a=s=-1,u=n[0]>=r,Va[u<<1].forEach(p);++a=r,Va[c|u<<1].forEach(p);for(Va[u<<0].forEach(p);++s=r,l=n[s*t]>=r,Va[u<<1|l<<2].forEach(p);++a=r,h=l,l=n[s*t+a+1]>=r,Va[c|u<<1|l<<2|h<<3].forEach(p);Va[u|l<<3].forEach(p)}for(a=-1,l=n[s*t]>=r,Va[l<<2].forEach(p);++a=r,Va[l<<2|h<<3].forEach(p);function p(t){var e,n,r=[t[0][0]+a,t[0][1]+s],c=[t[1][0]+a,t[1][1]+s],u=o(r),l=o(c);(e=d[u])?(n=f[l])?(delete d[e.end],delete f[n.start],e===n?(e.ring.push(c),i(e.ring)):f[e.start]=d[n.end]={start:e.start,end:n.end,ring:e.ring.concat(n.ring)}):(delete d[e.end],e.ring.push(c),d[e.end=l]=e):(e=f[l])?(n=d[u])?(delete f[e.start],delete d[n.end],e===n?(e.ring.push(c),i(e.ring)):f[n.start]=d[e.end]={start:n.start,end:e.end,ring:n.ring.concat(e.ring)}):(delete f[e.start],e.ring.unshift(r),f[e.start=u]=e):f[u]=d[l]={start:u,end:l,ring:[r,c]}}Va[l<<3].forEach(p)}(n,i,(function(t){r(t,n,i),function(t){for(var e=0,n=t.length,r=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];++e0?a.push([t]):s.push(t)})),s.forEach((function(t){for(var e,n=0,r=a.length;n0&&o0&&s0&&a>0))throw new Error("invalid size");return t=r,e=a,i},i.thresholds=function(t){return arguments.length?(n="function"==typeof t?t:Array.isArray(t)?Ua(Ya.call(t)):Ua(t),i):n},i.smooth=function(t){return arguments.length?(r=t?s:Wa,i):r===s},i}function Xa(t,e,n){for(var r=t.width,i=t.height,a=1+(n<<1),o=0;o=n&&(s>=a&&(c-=t.data[s-a+o*r]),e.data[s-n+o*r]=c/Math.min(s+1,r-1+a-s,a))}function Za(t,e,n){for(var r=t.width,i=t.height,a=1+(n<<1),o=0;o=n&&(s>=a&&(c-=t.data[o+(s-a)*r]),e.data[o+(s-n)*r]=c/Math.min(s+1,i-1+a-s,a))}function Qa(t){return t[0]}function Ka(t){return t[1]}function Ja(){return 1}function to(){var t=Qa,e=Ka,n=Ja,r=960,i=500,a=20,o=2,s=3*a,c=r+2*s>>o,u=i+2*s>>o,l=Ua(20);function h(r){var i=new Float32Array(c*u),h=new Float32Array(c*u);r.forEach((function(r,a,l){var h=+t(r,a,l)+s>>o,f=+e(r,a,l)+s>>o,d=+n(r,a,l);h>=0&&h=0&&f>o),Za({width:c,height:u,data:h},{width:c,height:u,data:i},a>>o),Xa({width:c,height:u,data:i},{width:c,height:u,data:h},a>>o),Za({width:c,height:u,data:h},{width:c,height:u,data:i},a>>o),Xa({width:c,height:u,data:i},{width:c,height:u,data:h},a>>o),Za({width:c,height:u,data:h},{width:c,height:u,data:i},a>>o);var d=l(i);if(!Array.isArray(d)){var p=I(i);d=M(0,p,d),(d=k(0,Math.floor(p/d)*d,d)).shift()}return Ga().thresholds(d).size([c,u])(i).map(f)}function f(t){return t.value*=Math.pow(2,-2*o),t.coordinates.forEach(d),t}function d(t){t.forEach(p)}function p(t){t.forEach(y)}function y(t){t[0]=t[0]*Math.pow(2,o)-s,t[1]=t[1]*Math.pow(2,o)-s}function g(){return c=r+2*(s=3*a)>>o,u=i+2*s>>o,h}return h.x=function(e){return arguments.length?(t="function"==typeof e?e:Ua(+e),h):t},h.y=function(t){return arguments.length?(e="function"==typeof t?t:Ua(+t),h):e},h.weight=function(t){return arguments.length?(n="function"==typeof t?t:Ua(+t),h):n},h.size=function(t){if(!arguments.length)return[r,i];var e=Math.ceil(t[0]),n=Math.ceil(t[1]);if(!(e>=0||e>=0))throw new Error("invalid size");return r=e,i=n,g()},h.cellSize=function(t){if(!arguments.length)return 1<=1))throw new Error("invalid cell size");return o=Math.floor(Math.log(t)/Math.LN2),g()},h.thresholds=function(t){return arguments.length?(l="function"==typeof t?t:Array.isArray(t)?Ua(Ya.call(t)):Ua(t),h):l},h.bandwidth=function(t){if(!arguments.length)return Math.sqrt(a*(a+1));if(!((t=+t)>=0))throw new Error("invalid bandwidth");return a=Math.round((Math.sqrt(4*t*t+1)-1)/2),g()},h}function eo(t){return function(){return t}}function no(t,e,n,r,i,a,o,s,c,u){this.target=t,this.type=e,this.subject=n,this.identifier=r,this.active=i,this.x=a,this.y=o,this.dx=s,this.dy=c,this._=u}function ro(){return!le.ctrlKey&&!le.button}function io(){return this.parentNode}function ao(t){return null==t?{x:le.x,y:le.y}:t}function oo(){return navigator.maxTouchPoints||"ontouchstart"in this}function so(){var t,e,n,r,i=ro,a=io,o=ao,s=oo,c={},u=ft("start","drag","end"),l=0,h=0;function f(t){t.on("mousedown.drag",d).filter(s).on("touchstart.drag",g).on("touchmove.drag",m).on("touchend.drag touchcancel.drag",v).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function d(){if(!r&&i.apply(this,arguments)){var o=b("mouse",a.apply(this,arguments),On,this,arguments);o&&(Te(le.view).on("mousemove.drag",p,!0).on("mouseup.drag",y,!0),Se(le.view),Ee(),n=!1,t=le.clientX,e=le.clientY,o("start"))}}function p(){if(Ce(),!n){var r=le.clientX-t,i=le.clientY-e;n=r*r+i*i>h}c.mouse("drag")}function y(){Te(le.view).on("mousemove.drag mouseup.drag",null),Ae(le.view,n),Ce(),c.mouse("end")}function g(){if(i.apply(this,arguments)){var t,e,n=le.changedTouches,r=a.apply(this,arguments),o=n.length;for(t=0;t=a?c=!0:10===(r=t.charCodeAt(o++))?u=!0:13===r&&(u=!0,10===t.charCodeAt(o)&&++o),t.slice(i+1,e-1).replace(/""/g,'"')}for(;o9999?"+"+fo(t,6):fo(t,4)}(t.getUTCFullYear())+"-"+fo(t.getUTCMonth()+1,2)+"-"+fo(t.getUTCDate(),2)+(i?"T"+fo(e,2)+":"+fo(n,2)+":"+fo(r,2)+"."+fo(i,3)+"Z":r?"T"+fo(e,2)+":"+fo(n,2)+":"+fo(r,2)+"Z":n||e?"T"+fo(e,2)+":"+fo(n,2)+"Z":"")}(t):e.test(t+="")?'"'+t.replace(/"/g,'""')+'"':t}return{parse:function(t,e){var n,i,a=r(t,(function(t,r){if(n)return n(t,r-1);i=t,n=e?function(t,e){var n=lo(t);return function(r,i){return e(n(r),i,t)}}(t,e):lo(t)}));return a.columns=i||[],a},parseRows:r,format:function(e,n){return null==n&&(n=ho(e)),[n.map(o).join(t)].concat(i(e,n)).join("\n")},formatBody:function(t,e){return null==e&&(e=ho(t)),i(t,e).join("\n")},formatRows:function(t){return t.map(a).join("\n")},formatRow:a,formatValue:o}}var yo=po(","),go=yo.parse,mo=yo.parseRows,vo=yo.format,bo=yo.formatBody,_o=yo.formatRows,xo=yo.formatRow,wo=yo.formatValue,ko=po("\t"),To=ko.parse,Eo=ko.parseRows,Co=ko.format,So=ko.formatBody,Ao=ko.formatRows,Mo=ko.formatRow,No=ko.formatValue;function Do(t){for(var e in t){var n,r,i=t[e].trim();if(i)if("true"===i)i=!0;else if("false"===i)i=!1;else if("NaN"===i)i=NaN;else if(isNaN(n=+i)){if(!(r=i.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)))continue;Oo&&r[4]&&!r[7]&&(i=i.replace(/-/g,"/").replace(/T/," ")),i=new Date(i)}else i=n;else i=null;t[e]=i}return t}var Oo=new Date("2019-01-01T00:00").getHours()||new Date("2019-07-01T00:00").getHours();function Bo(t){return+t}function Lo(t){return t*t}function Io(t){return t*(2-t)}function Ro(t){return((t*=2)<=1?t*t:--t*(2-t)+1)/2}var Fo=function t(e){function n(t){return Math.pow(t,e)}return e=+e,n.exponent=t,n}(3),Po=function t(e){function n(t){return 1-Math.pow(1-t,e)}return e=+e,n.exponent=t,n}(3),jo=function t(e){function n(t){return((t*=2)<=1?Math.pow(t,e):2-Math.pow(2-t,e))/2}return e=+e,n.exponent=t,n}(3),Yo=Math.PI,zo=Yo/2;function Uo(t){return 1==+t?1:1-Math.cos(t*zo)}function qo(t){return Math.sin(t*zo)}function Ho(t){return(1-Math.cos(Yo*t))/2}function $o(t){return 1.0009775171065494*(Math.pow(2,-10*t)-.0009765625)}function Wo(t){return $o(1-+t)}function Vo(t){return 1-$o(t)}function Go(t){return((t*=2)<=1?$o(1-t):2-$o(t-1))/2}function Xo(t){return 1-Math.sqrt(1-t*t)}function Zo(t){return Math.sqrt(1- --t*t)}function Qo(t){return((t*=2)<=1?1-Math.sqrt(1-t*t):Math.sqrt(1-(t-=2)*t)+1)/2}var Ko=7.5625;function Jo(t){return 1-ts(1-t)}function ts(t){return(t=+t)<.36363636363636365?Ko*t*t:t<.7272727272727273?Ko*(t-=.5454545454545454)*t+.75:t<.9090909090909091?Ko*(t-=.8181818181818182)*t+.9375:Ko*(t-=.9545454545454546)*t+.984375}function es(t){return((t*=2)<=1?1-ts(1-t):ts(t-1)+1)/2}var ns=1.70158,rs=function t(e){function n(t){return(t=+t)*t*(e*(t-1)+t)}return e=+e,n.overshoot=t,n}(ns),is=function t(e){function n(t){return--t*t*((t+1)*e+t)+1}return e=+e,n.overshoot=t,n}(ns),as=function t(e){function n(t){return((t*=2)<1?t*t*((e+1)*t-e):(t-=2)*t*((e+1)*t+e)+2)/2}return e=+e,n.overshoot=t,n}(ns),os=2*Math.PI,ss=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=os);function i(t){return e*$o(- --t)*Math.sin((r-t)/n)}return i.amplitude=function(e){return t(e,n*os)},i.period=function(n){return t(e,n)},i}(1,.3),cs=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=os);function i(t){return 1-e*$o(t=+t)*Math.sin((t+r)/n)}return i.amplitude=function(e){return t(e,n*os)},i.period=function(n){return t(e,n)},i}(1,.3),us=function t(e,n){var r=Math.asin(1/(e=Math.max(1,e)))*(n/=os);function i(t){return((t=2*t-1)<0?e*$o(-t)*Math.sin((r-t)/n):2-e*$o(t)*Math.sin((r+t)/n))/2}return i.amplitude=function(e){return t(e,n*os)},i.period=function(n){return t(e,n)},i}(1,.3);function ls(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.blob()}function hs(t,e){return fetch(t,e).then(ls)}function fs(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.arrayBuffer()}function ds(t,e){return fetch(t,e).then(fs)}function ps(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);return t.text()}function ys(t,e){return fetch(t,e).then(ps)}function gs(t){return function(e,n,r){return 2===arguments.length&&"function"==typeof n&&(r=n,n=void 0),ys(e,n).then((function(e){return t(e,r)}))}}function ms(t,e,n,r){3===arguments.length&&"function"==typeof n&&(r=n,n=void 0);var i=po(t);return ys(e,n).then((function(t){return i.parse(t,r)}))}var vs=gs(go),bs=gs(To);function _s(t,e){return new Promise((function(n,r){var i=new Image;for(var a in e)i[a]=e[a];i.onerror=r,i.onload=function(){n(i)},i.src=t}))}function xs(t){if(!t.ok)throw new Error(t.status+" "+t.statusText);if(204!==t.status&&205!==t.status)return t.json()}function ws(t,e){return fetch(t,e).then(xs)}function ks(t){return function(e,n){return ys(e,n).then((function(e){return(new DOMParser).parseFromString(e,t)}))}}const Ts=ks("application/xml");var Es=ks("text/html"),Cs=ks("image/svg+xml");function Ss(t,e){var n;function r(){var r,i,a=n.length,o=0,s=0;for(r=0;r=(a=(y+m)/2))?y=a:m=a,(l=n>=(o=(g+v)/2))?g=o:v=o,i=d,!(d=d[h=l<<1|u]))return i[h]=p,t;if(s=+t._x.call(null,d.data),c=+t._y.call(null,d.data),e===s&&n===c)return p.next=d,i?i[h]=p:t._root=p,t;do{i=i?i[h]=new Array(4):t._root=new Array(4),(u=e>=(a=(y+m)/2))?y=a:m=a,(l=n>=(o=(g+v)/2))?g=o:v=o}while((h=l<<1|u)==(f=(c>=o)<<1|s>=a));return i[f]=d,i[h]=p,t}function Ds(t,e,n,r,i){this.node=t,this.x0=e,this.y0=n,this.x1=r,this.y1=i}function Os(t){return t[0]}function Bs(t){return t[1]}function Ls(t,e,n){var r=new Is(null==e?Os:e,null==n?Bs:n,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function Is(t,e,n,r,i,a){this._x=t,this._y=e,this._x0=n,this._y0=r,this._x1=i,this._y1=a,this._root=void 0}function Rs(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var Fs=Ls.prototype=Is.prototype;function Ps(t){return t.x+t.vx}function js(t){return t.y+t.vy}function Ys(t){var e,n,r=1,i=1;function a(){for(var t,a,s,c,u,l,h,f=e.length,d=0;dc+d||iu+d||as.index){var p=c-o.x-o.vx,y=u-o.y-o.vy,g=p*p+y*y;gt.r&&(t.r=t[e].r)}function s(){if(e){var r,i,a=e.length;for(n=new Array(a),r=0;rl&&(l=r),ih&&(h=i));if(c>l||u>h)return this;for(this.cover(c,u).cover(l,h),n=0;nt||t>=i||r>e||e>=a;)switch(s=(ef||(a=c.y0)>d||(o=c.x1)=m)<<1|t>=g)&&(c=p[p.length-1],p[p.length-1]=p[p.length-1-u],p[p.length-1-u]=c)}else{var v=t-+this._x.call(null,y.data),b=e-+this._y.call(null,y.data),_=v*v+b*b;if(_=(s=(p+g)/2))?p=s:g=s,(l=o>=(c=(y+m)/2))?y=c:m=c,e=d,!(d=d[h=l<<1|u]))return this;if(!d.length)break;(e[h+1&3]||e[h+2&3]||e[h+3&3])&&(n=e,f=h)}for(;d.data!==t;)if(r=d,!(d=d.next))return this;return(i=d.next)&&delete d.next,r?(i?r.next=i:delete r.next,this):e?(i?e[h]=i:delete e[h],(d=e[0]||e[1]||e[2]||e[3])&&d===(e[3]||e[2]||e[1]||e[0])&&!d.length&&(n?n[f]=d:this._root=d),this):(this._root=i,this)},Fs.removeAll=function(t){for(var e=0,n=t.length;e1?(null==n?s.remove(t):s.set(t,d(n)),e):s.get(t)},find:function(e,n,r){var i,a,o,s,c,u=0,l=t.length;for(null==r?r=1/0:r*=r,u=0;u1?(u.on(t,n),e):u.on(t)}}}function Gs(){var t,e,n,r,i=As(-30),a=1,o=1/0,s=.81;function c(r){var i,a=t.length,o=Ls(t,Hs,$s).visitAfter(l);for(n=r,i=0;i=o)){(t.data!==e||t.next)&&(0===l&&(d+=(l=Ms())*l),0===h&&(d+=(h=Ms())*h),d1?r[0]+r.slice(2):r,+t.slice(n+1)]}function Js(t){return(t=Ks(Math.abs(t)))?t[1]:NaN}var tc,ec=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function nc(t){if(!(e=ec.exec(t)))throw new Error("invalid format: "+t);var e;return new rc({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function rc(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function ic(t,e){var n=Ks(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}nc.prototype=rc.prototype,rc.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};const ac={"%":function(t,e){return(100*t).toFixed(e)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:function(t,e){return t.toExponential(e)},f:function(t,e){return t.toFixed(e)},g:function(t,e){return t.toPrecision(e)},o:function(t){return Math.round(t).toString(8)},p:function(t,e){return ic(100*t,e)},r:ic,s:function(t,e){var n=Ks(t,e);if(!n)return t+"";var r=n[0],i=n[1],a=i-(tc=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,o=r.length;return a===o?r:a>o?r+new Array(a-o+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+Ks(t,Math.max(0,e+a-1))[0]},X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}};function oc(t){return t}var sc,cc,uc,lc=Array.prototype.map,hc=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function fc(t){var e,n,r=void 0===t.grouping||void 0===t.thousands?oc:(e=lc.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var i=t.length,a=[],o=0,s=e[0],c=0;i>0&&s>0&&(c+s+1>r&&(s=Math.max(1,r-c)),a.push(t.substring(i-=s,i+s)),!((c+=s+1)>r));)s=e[o=(o+1)%e.length];return a.reverse().join(n)}),i=void 0===t.currency?"":t.currency[0]+"",a=void 0===t.currency?"":t.currency[1]+"",o=void 0===t.decimal?".":t.decimal+"",s=void 0===t.numerals?oc:function(t){return function(e){return e.replace(/[0-9]/g,(function(e){return t[+e]}))}}(lc.call(t.numerals,String)),c=void 0===t.percent?"%":t.percent+"",u=void 0===t.minus?"-":t.minus+"",l=void 0===t.nan?"NaN":t.nan+"";function h(t){var e=(t=nc(t)).fill,n=t.align,h=t.sign,f=t.symbol,d=t.zero,p=t.width,y=t.comma,g=t.precision,m=t.trim,v=t.type;"n"===v?(y=!0,v="g"):ac[v]||(void 0===g&&(g=12),m=!0,v="g"),(d||"0"===e&&"="===n)&&(d=!0,e="0",n="=");var b="$"===f?i:"#"===f&&/[boxX]/.test(v)?"0"+v.toLowerCase():"",_="$"===f?a:/[%p]/.test(v)?c:"",x=ac[v],w=/[defgprs%]/.test(v);function k(t){var i,a,c,f=b,k=_;if("c"===v)k=x(t)+k,t="";else{var T=(t=+t)<0||1/t<0;if(t=isNaN(t)?l:x(Math.abs(t),g),m&&(t=function(t){t:for(var e,n=t.length,r=1,i=-1;r0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t}(t)),T&&0==+t&&"+"!==h&&(T=!1),f=(T?"("===h?h:u:"-"===h||"("===h?"":h)+f,k=("s"===v?hc[8+tc/3]:"")+k+(T&&"("===h?")":""),w)for(i=-1,a=t.length;++i(c=t.charCodeAt(i))||c>57){k=(46===c?o+t.slice(i+1):t.slice(i))+k,t=t.slice(0,i);break}}y&&!d&&(t=r(t,1/0));var E=f.length+t.length+k.length,C=E>1)+f+t+k+C.slice(E);break;default:t=C+f+t+k}return s(t)}return g=void 0===g?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),k.toString=function(){return t+""},k}return{format:h,formatPrefix:function(t,e){var n=h(((t=nc(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(Js(e)/3))),i=Math.pow(10,-r),a=hc[8+r/3];return function(t){return n(i*t)+a}}}}function dc(t){return sc=fc(t),cc=sc.format,uc=sc.formatPrefix,sc}function pc(t){return Math.max(0,-Js(Math.abs(t)))}function yc(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Js(e)/3)))-Js(Math.abs(t)))}function gc(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,Js(e)-Js(t))+1}function mc(){return new vc}function vc(){this.reset()}dc({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"}),vc.prototype={constructor:vc,reset:function(){this.s=this.t=0},add:function(t){_c(bc,t,this.t),_c(this,bc.s,this.s),this.s?this.t+=bc.t:this.s=bc.t},valueOf:function(){return this.s}};var bc=new vc;function _c(t,e,n){var r=t.s=e+n,i=r-e,a=r-i;t.t=e-a+(n-i)}var xc=1e-6,wc=1e-12,kc=Math.PI,Tc=kc/2,Ec=kc/4,Cc=2*kc,Sc=180/kc,Ac=kc/180,Mc=Math.abs,Nc=Math.atan,Dc=Math.atan2,Oc=Math.cos,Bc=Math.ceil,Lc=Math.exp,Ic=(Math.floor,Math.log),Rc=Math.pow,Fc=Math.sin,Pc=Math.sign||function(t){return t>0?1:t<0?-1:0},jc=Math.sqrt,Yc=Math.tan;function zc(t){return t>1?0:t<-1?kc:Math.acos(t)}function Uc(t){return t>1?Tc:t<-1?-Tc:Math.asin(t)}function qc(t){return(t=Fc(t/2))*t}function Hc(){}function $c(t,e){t&&Vc.hasOwnProperty(t.type)&&Vc[t.type](t,e)}var Wc={Feature:function(t,e){$c(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,i=n.length;++r=0?1:-1,i=r*n,a=Oc(e=(e*=Ac)/2+Ec),o=Fc(e),s=eu*o,c=tu*a+s*Oc(i),u=s*r*Fc(i);nu.add(Dc(u,c)),Jc=t,tu=a,eu=o}function uu(t){return ru.reset(),Zc(t,iu),2*ru}function lu(t){return[Dc(t[1],t[0]),Uc(t[2])]}function hu(t){var e=t[0],n=t[1],r=Oc(n);return[r*Oc(e),r*Fc(e),Fc(n)]}function fu(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function du(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function pu(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function yu(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function gu(t){var e=jc(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var mu,vu,bu,_u,xu,wu,ku,Tu,Eu,Cu,Su,Au,Mu,Nu,Du,Ou,Bu,Lu,Iu,Ru,Fu,Pu,ju,Yu,zu,Uu,qu=mc(),Hu={point:$u,lineStart:Vu,lineEnd:Gu,polygonStart:function(){Hu.point=Xu,Hu.lineStart=Zu,Hu.lineEnd=Qu,qu.reset(),iu.polygonStart()},polygonEnd:function(){iu.polygonEnd(),Hu.point=$u,Hu.lineStart=Vu,Hu.lineEnd=Gu,nu<0?(mu=-(bu=180),vu=-(_u=90)):qu>xc?_u=90:qu<-1e-6&&(vu=-90),Cu[0]=mu,Cu[1]=bu},sphere:function(){mu=-(bu=180),vu=-(_u=90)}};function $u(t,e){Eu.push(Cu=[mu=t,bu=t]),e_u&&(_u=e)}function Wu(t,e){var n=hu([t*Ac,e*Ac]);if(Tu){var r=du(Tu,n),i=du([r[1],-r[0],0],r);gu(i),i=lu(i);var a,o=t-xu,s=o>0?1:-1,c=i[0]*Sc*s,u=Mc(o)>180;u^(s*xu_u&&(_u=a):u^(s*xu<(c=(c+360)%360-180)&&c_u&&(_u=e)),u?tKu(mu,bu)&&(bu=t):Ku(t,bu)>Ku(mu,bu)&&(mu=t):bu>=mu?(tbu&&(bu=t)):t>xu?Ku(mu,t)>Ku(mu,bu)&&(bu=t):Ku(t,bu)>Ku(mu,bu)&&(mu=t)}else Eu.push(Cu=[mu=t,bu=t]);e_u&&(_u=e),Tu=n,xu=t}function Vu(){Hu.point=Wu}function Gu(){Cu[0]=mu,Cu[1]=bu,Hu.point=$u,Tu=null}function Xu(t,e){if(Tu){var n=t-xu;qu.add(Mc(n)>180?n+(n>0?360:-360):n)}else wu=t,ku=e;iu.point(t,e),Wu(t,e)}function Zu(){iu.lineStart()}function Qu(){Xu(wu,ku),iu.lineEnd(),Mc(qu)>xc&&(mu=-(bu=180)),Cu[0]=mu,Cu[1]=bu,Tu=null}function Ku(t,e){return(e-=t)<0?e+360:e}function Ju(t,e){return t[0]-e[0]}function tl(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:eKu(r[0],r[1])&&(r[1]=i[1]),Ku(i[0],r[1])>Ku(r[0],r[1])&&(r[0]=i[0])):a.push(r=i);for(o=-1/0,e=0,r=a[n=a.length-1];e<=n;r=i,++e)i=a[e],(s=Ku(r[1],i[0]))>o&&(o=s,mu=i[0],bu=r[1])}return Eu=Cu=null,mu===1/0||vu===1/0?[[NaN,NaN],[NaN,NaN]]:[[mu,vu],[bu,_u]]}var nl={sphere:Hc,point:rl,lineStart:al,lineEnd:cl,polygonStart:function(){nl.lineStart=ul,nl.lineEnd=ll},polygonEnd:function(){nl.lineStart=al,nl.lineEnd=cl}};function rl(t,e){t*=Ac;var n=Oc(e*=Ac);il(n*Oc(t),n*Fc(t),Fc(e))}function il(t,e,n){++Su,Mu+=(t-Mu)/Su,Nu+=(e-Nu)/Su,Du+=(n-Du)/Su}function al(){nl.point=ol}function ol(t,e){t*=Ac;var n=Oc(e*=Ac);Yu=n*Oc(t),zu=n*Fc(t),Uu=Fc(e),nl.point=sl,il(Yu,zu,Uu)}function sl(t,e){t*=Ac;var n=Oc(e*=Ac),r=n*Oc(t),i=n*Fc(t),a=Fc(e),o=Dc(jc((o=zu*a-Uu*i)*o+(o=Uu*r-Yu*a)*o+(o=Yu*i-zu*r)*o),Yu*r+zu*i+Uu*a);Au+=o,Ou+=o*(Yu+(Yu=r)),Bu+=o*(zu+(zu=i)),Lu+=o*(Uu+(Uu=a)),il(Yu,zu,Uu)}function cl(){nl.point=rl}function ul(){nl.point=hl}function ll(){fl(Pu,ju),nl.point=rl}function hl(t,e){Pu=t,ju=e,t*=Ac,e*=Ac,nl.point=fl;var n=Oc(e);Yu=n*Oc(t),zu=n*Fc(t),Uu=Fc(e),il(Yu,zu,Uu)}function fl(t,e){t*=Ac;var n=Oc(e*=Ac),r=n*Oc(t),i=n*Fc(t),a=Fc(e),o=zu*a-Uu*i,s=Uu*r-Yu*a,c=Yu*i-zu*r,u=jc(o*o+s*s+c*c),l=Uc(u),h=u&&-l/u;Iu+=h*o,Ru+=h*s,Fu+=h*c,Au+=l,Ou+=l*(Yu+(Yu=r)),Bu+=l*(zu+(zu=i)),Lu+=l*(Uu+(Uu=a)),il(Yu,zu,Uu)}function dl(t){Su=Au=Mu=Nu=Du=Ou=Bu=Lu=Iu=Ru=Fu=0,Zc(t,nl);var e=Iu,n=Ru,r=Fu,i=e*e+n*n+r*r;return ikc?t+Math.round(-t/Cc)*Cc:t,e]}function ml(t,e,n){return(t%=Cc)?e||n?yl(bl(t),_l(e,n)):bl(t):e||n?_l(e,n):gl}function vl(t){return function(e,n){return[(e+=t)>kc?e-Cc:e<-kc?e+Cc:e,n]}}function bl(t){var e=vl(t);return e.invert=vl(-t),e}function _l(t,e){var n=Oc(t),r=Fc(t),i=Oc(e),a=Fc(e);function o(t,e){var o=Oc(e),s=Oc(t)*o,c=Fc(t)*o,u=Fc(e),l=u*n+s*r;return[Dc(c*i-l*a,s*n-u*r),Uc(l*i+c*a)]}return o.invert=function(t,e){var o=Oc(e),s=Oc(t)*o,c=Fc(t)*o,u=Fc(e),l=u*i-c*a;return[Dc(c*i+u*a,s*n+l*r),Uc(l*n-s*r)]},o}function xl(t){function e(e){return(e=t(e[0]*Ac,e[1]*Ac))[0]*=Sc,e[1]*=Sc,e}return t=ml(t[0]*Ac,t[1]*Ac,t.length>2?t[2]*Ac:0),e.invert=function(e){return(e=t.invert(e[0]*Ac,e[1]*Ac))[0]*=Sc,e[1]*=Sc,e},e}function wl(t,e,n,r,i,a){if(n){var o=Oc(e),s=Fc(e),c=r*n;null==i?(i=e+r*Cc,a=e-c/2):(i=kl(o,i),a=kl(o,a),(r>0?ia)&&(i+=r*Cc));for(var u,l=i;r>0?l>a:l1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function Cl(t,e){return Mc(t[0]-e[0])=0;--a)i.point((l=u[a])[0],l[1]);else r(f.x,f.p.x,-1,i);f=f.p}u=(f=f.o).z,d=!d}while(!f.v);i.lineEnd()}}}function Ml(t){if(e=t.length){for(var e,n,r=0,i=t[0];++r=0?1:-1,E=T*k,C=E>kc,S=y*x;if(Nl.add(Dc(S*T*Fc(E),g*w+S*Oc(E))),o+=C?k+T*Cc:k,C^d>=n^b>=n){var A=du(hu(f),hu(v));gu(A);var M=du(a,A);gu(M);var N=(C^k>=0?-1:1)*Uc(M[2]);(r>N||r===N&&(A[0]||A[1]))&&(s+=C^k>=0?1:-1)}}return(o<-1e-6||o0){for(h||(i.polygonStart(),h=!0),i.lineStart(),t=0;t1&&2&c&&f.push(f.pop().concat(f.shift())),o.push(f.filter(Ll))}return f}}function Ll(t){return t.length>1}function Il(t,e){return((t=t.x)[0]<0?t[1]-Tc-xc:Tc-t[1])-((e=e.x)[0]<0?e[1]-Tc-xc:Tc-e[1])}const Rl=Bl((function(){return!0}),(function(t){var e,n=NaN,r=NaN,i=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(a,o){var s=a>0?kc:-kc,c=Mc(a-n);Mc(c-kc)0?Tc:-Tc),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(s,r),t.point(a,r),e=0):i!==s&&c>=kc&&(Mc(n-i)xc?Nc((Fc(e)*(a=Oc(r))*Fc(n)-Fc(r)*(i=Oc(e))*Fc(t))/(i*a*o)):(e+r)/2}(n,r,a,o),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(s,r),e=0),t.point(n=a,r=o),i=s},lineEnd:function(){t.lineEnd(),n=r=NaN},clean:function(){return 2-e}}}),(function(t,e,n,r){var i;if(null==t)i=n*Tc,r.point(-kc,i),r.point(0,i),r.point(kc,i),r.point(kc,0),r.point(kc,-i),r.point(0,-i),r.point(-kc,-i),r.point(-kc,0),r.point(-kc,i);else if(Mc(t[0]-e[0])>xc){var a=t[0]0,i=Mc(e)>xc;function a(t,n){return Oc(t)*Oc(n)>e}function o(t,n,r){var i=[1,0,0],a=du(hu(t),hu(n)),o=fu(a,a),s=a[0],c=o-s*s;if(!c)return!r&&t;var u=e*o/c,l=-e*s/c,h=du(i,a),f=yu(i,u);pu(f,yu(a,l));var d=h,p=fu(f,d),y=fu(d,d),g=p*p-y*(fu(f,f)-1);if(!(g<0)){var m=jc(g),v=yu(d,(-p-m)/y);if(pu(v,f),v=lu(v),!r)return v;var b,_=t[0],x=n[0],w=t[1],k=n[1];x<_&&(b=_,_=x,x=b);var T=x-_,E=Mc(T-kc)0^v[1]<(Mc(v[0]-_)kc^(_<=v[0]&&v[0]<=x)){var C=yu(d,(-p+m)/y);return pu(C,f),[v,lu(C)]}}}function s(e,n){var i=r?t:kc-t,a=0;return e<-i?a|=1:e>i&&(a|=2),n<-i?a|=4:n>i&&(a|=8),a}return Bl(a,(function(t){var e,n,c,u,l;return{lineStart:function(){u=c=!1,l=1},point:function(h,f){var d,p=[h,f],y=a(h,f),g=r?y?0:s(h,f):y?s(h+(h<0?kc:-kc),f):0;if(!e&&(u=c=y)&&t.lineStart(),y!==c&&(!(d=o(e,p))||Cl(e,d)||Cl(p,d))&&(p[2]=1),y!==c)l=0,y?(t.lineStart(),d=o(p,e),t.point(d[0],d[1])):(d=o(e,p),t.point(d[0],d[1],2),t.lineEnd()),e=d;else if(i&&e&&r^y){var m;g&n||!(m=o(p,e,!0))||(l=0,r?(t.lineStart(),t.point(m[0][0],m[0][1]),t.point(m[1][0],m[1][1]),t.lineEnd()):(t.point(m[1][0],m[1][1]),t.lineEnd(),t.lineStart(),t.point(m[0][0],m[0][1],3)))}!y||e&&Cl(e,p)||t.point(p[0],p[1]),e=p,c=y,n=g},lineEnd:function(){c&&t.lineEnd(),e=null},clean:function(){return l|(u&&c)<<1}}}),(function(e,r,i,a){wl(a,t,n,i,e,r)}),r?[0,-t]:[-kc,t-kc])}var Pl=1e9,jl=-Pl;function Yl(t,e,n,r){function i(i,a){return t<=i&&i<=n&&e<=a&&a<=r}function a(i,a,s,u){var l=0,h=0;if(null==i||(l=o(i,s))!==(h=o(a,s))||c(i,a)<0^s>0)do{u.point(0===l||3===l?t:n,l>1?r:e)}while((l=(l+s+4)%4)!==h);else u.point(a[0],a[1])}function o(r,i){return Mc(r[0]-t)0?0:3:Mc(r[0]-n)0?2:1:Mc(r[1]-e)0?1:0:i>0?3:2}function s(t,e){return c(t.x,e.x)}function c(t,e){var n=o(t,1),r=o(e,1);return n!==r?n-r:0===n?e[1]-t[1]:1===n?t[0]-e[0]:2===n?t[1]-e[1]:e[0]-t[0]}return function(o){var c,u,l,h,f,d,p,y,g,m,v,b=o,_=El(),x={point:w,lineStart:function(){x.point=k,u&&u.push(l=[]),m=!0,g=!1,p=y=NaN},lineEnd:function(){c&&(k(h,f),d&&g&&_.rejoin(),c.push(_.result())),x.point=w,g&&b.lineEnd()},polygonStart:function(){b=_,c=[],u=[],v=!0},polygonEnd:function(){var e=function(){for(var e=0,n=0,i=u.length;nr&&(f-a)*(r-o)>(d-o)*(t-a)&&++e:d<=r&&(f-a)*(r-o)<(d-o)*(t-a)&&--e;return e}(),n=v&&e,i=(c=P(c)).length;(n||i)&&(o.polygonStart(),n&&(o.lineStart(),a(null,null,1,o),o.lineEnd()),i&&Al(c,s,e,a,o),o.polygonEnd()),b=o,c=u=l=null}};function w(t,e){i(t,e)&&b.point(t,e)}function k(a,o){var s=i(a,o);if(u&&l.push([a,o]),m)h=a,f=o,d=s,m=!1,s&&(b.lineStart(),b.point(a,o));else if(s&&g)b.point(a,o);else{var c=[p=Math.max(jl,Math.min(Pl,p)),y=Math.max(jl,Math.min(Pl,y))],_=[a=Math.max(jl,Math.min(Pl,a)),o=Math.max(jl,Math.min(Pl,o))];!function(t,e,n,r,i,a){var o,s=t[0],c=t[1],u=0,l=1,h=e[0]-s,f=e[1]-c;if(o=n-s,h||!(o>0)){if(o/=h,h<0){if(o0){if(o>l)return;o>u&&(u=o)}if(o=i-s,h||!(o<0)){if(o/=h,h<0){if(o>l)return;o>u&&(u=o)}else if(h>0){if(o0)){if(o/=f,f<0){if(o0){if(o>l)return;o>u&&(u=o)}if(o=a-c,f||!(o<0)){if(o/=f,f<0){if(o>l)return;o>u&&(u=o)}else if(f>0){if(o0&&(t[0]=s+u*h,t[1]=c+u*f),l<1&&(e[0]=s+l*h,e[1]=c+l*f),!0}}}}}(c,_,t,e,n,r)?s&&(b.lineStart(),b.point(a,o),v=!1):(g||(b.lineStart(),b.point(c[0],c[1])),b.point(_[0],_[1]),s||b.lineEnd(),v=!1)}p=a,y=o,g=s}return x}}function zl(){var t,e,n,r=0,i=0,a=960,o=500;return n={stream:function(n){return t&&e===n?t:t=Yl(r,i,a,o)(e=n)},extent:function(s){return arguments.length?(r=+s[0][0],i=+s[0][1],a=+s[1][0],o=+s[1][1],t=e=null,n):[[r,i],[a,o]]}}}var Ul,ql,Hl,$l=mc(),Wl={sphere:Hc,point:Hc,lineStart:function(){Wl.point=Gl,Wl.lineEnd=Vl},lineEnd:Hc,polygonStart:Hc,polygonEnd:Hc};function Vl(){Wl.point=Wl.lineEnd=Hc}function Gl(t,e){Ul=t*=Ac,ql=Fc(e*=Ac),Hl=Oc(e),Wl.point=Xl}function Xl(t,e){t*=Ac;var n=Fc(e*=Ac),r=Oc(e),i=Mc(t-Ul),a=Oc(i),o=r*Fc(i),s=Hl*n-ql*r*a,c=ql*n+Hl*r*a;$l.add(Dc(jc(o*o+s*s),c)),Ul=t,ql=n,Hl=r}function Zl(t){return $l.reset(),Zc(t,Wl),+$l}var Ql=[null,null],Kl={type:"LineString",coordinates:Ql};function Jl(t,e){return Ql[0]=t,Ql[1]=e,Zl(Kl)}var th={Feature:function(t,e){return nh(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,i=n.length;++r0&&(i=Jl(t[a],t[a-1]))>0&&n<=i&&r<=i&&(n+r-i)*(1-Math.pow((n-r)/i,2))xc})).map(c)).concat(k(Bc(a/d)*d,i,d).filter((function(t){return Mc(t%y)>xc})).map(u))}return m.lines=function(){return v().map((function(t){return{type:"LineString",coordinates:t}}))},m.outline=function(){return{type:"Polygon",coordinates:[l(r).concat(h(o).slice(1),l(n).reverse().slice(1),h(s).reverse().slice(1))]}},m.extent=function(t){return arguments.length?m.extentMajor(t).extentMinor(t):m.extentMinor()},m.extentMajor=function(t){return arguments.length?(r=+t[0][0],n=+t[1][0],s=+t[0][1],o=+t[1][1],r>n&&(t=r,r=n,n=t),s>o&&(t=s,s=o,o=t),m.precision(g)):[[r,s],[n,o]]},m.extentMinor=function(n){return arguments.length?(e=+n[0][0],t=+n[1][0],a=+n[0][1],i=+n[1][1],e>t&&(n=e,e=t,t=n),a>i&&(n=a,a=i,i=n),m.precision(g)):[[e,a],[t,i]]},m.step=function(t){return arguments.length?m.stepMajor(t).stepMinor(t):m.stepMinor()},m.stepMajor=function(t){return arguments.length?(p=+t[0],y=+t[1],m):[p,y]},m.stepMinor=function(t){return arguments.length?(f=+t[0],d=+t[1],m):[f,d]},m.precision=function(f){return arguments.length?(g=+f,c=uh(a,i,90),u=lh(e,t,g),l=uh(s,o,90),h=lh(r,n,g),m):g},m.extentMajor([[-180,-89.999999],[180,89.999999]]).extentMinor([[-180,-80.000001],[180,80.000001]])}function fh(){return hh()()}function dh(t,e){var n=t[0]*Ac,r=t[1]*Ac,i=e[0]*Ac,a=e[1]*Ac,o=Oc(r),s=Fc(r),c=Oc(a),u=Fc(a),l=o*Oc(n),h=o*Fc(n),f=c*Oc(i),d=c*Fc(i),p=2*Uc(jc(qc(a-r)+o*c*qc(i-n))),y=Fc(p),g=p?function(t){var e=Fc(t*=p)/y,n=Fc(p-t)/y,r=n*l+e*f,i=n*h+e*d,a=n*s+e*u;return[Dc(i,r)*Sc,Dc(a,jc(r*r+i*i))*Sc]}:function(){return[n*Sc,r*Sc]};return g.distance=p,g}function ph(t){return t}var yh,gh,mh,vh,bh=mc(),_h=mc(),xh={point:Hc,lineStart:Hc,lineEnd:Hc,polygonStart:function(){xh.lineStart=wh,xh.lineEnd=Eh},polygonEnd:function(){xh.lineStart=xh.lineEnd=xh.point=Hc,bh.add(Mc(_h)),_h.reset()},result:function(){var t=bh/2;return bh.reset(),t}};function wh(){xh.point=kh}function kh(t,e){xh.point=Th,yh=mh=t,gh=vh=e}function Th(t,e){_h.add(vh*t-mh*e),mh=t,vh=e}function Eh(){Th(yh,gh)}const Ch=xh;var Sh=1/0,Ah=Sh,Mh=-Sh,Nh=Mh;const Dh={point:function(t,e){tMh&&(Mh=t),eNh&&(Nh=e)},lineStart:Hc,lineEnd:Hc,polygonStart:Hc,polygonEnd:Hc,result:function(){var t=[[Sh,Ah],[Mh,Nh]];return Mh=Nh=-(Ah=Sh=1/0),t}};var Oh,Bh,Lh,Ih,Rh=0,Fh=0,Ph=0,jh=0,Yh=0,zh=0,Uh=0,qh=0,Hh=0,$h={point:Wh,lineStart:Vh,lineEnd:Zh,polygonStart:function(){$h.lineStart=Qh,$h.lineEnd=Kh},polygonEnd:function(){$h.point=Wh,$h.lineStart=Vh,$h.lineEnd=Zh},result:function(){var t=Hh?[Uh/Hh,qh/Hh]:zh?[jh/zh,Yh/zh]:Ph?[Rh/Ph,Fh/Ph]:[NaN,NaN];return Rh=Fh=Ph=jh=Yh=zh=Uh=qh=Hh=0,t}};function Wh(t,e){Rh+=t,Fh+=e,++Ph}function Vh(){$h.point=Gh}function Gh(t,e){$h.point=Xh,Wh(Lh=t,Ih=e)}function Xh(t,e){var n=t-Lh,r=e-Ih,i=jc(n*n+r*r);jh+=i*(Lh+t)/2,Yh+=i*(Ih+e)/2,zh+=i,Wh(Lh=t,Ih=e)}function Zh(){$h.point=Wh}function Qh(){$h.point=Jh}function Kh(){tf(Oh,Bh)}function Jh(t,e){$h.point=tf,Wh(Oh=Lh=t,Bh=Ih=e)}function tf(t,e){var n=t-Lh,r=e-Ih,i=jc(n*n+r*r);jh+=i*(Lh+t)/2,Yh+=i*(Ih+e)/2,zh+=i,Uh+=(i=Ih*t-Lh*e)*(Lh+t),qh+=i*(Ih+e),Hh+=3*i,Wh(Lh=t,Ih=e)}const ef=$h;function nf(t){this._context=t}nf.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._context.moveTo(t,e),this._point=1;break;case 1:this._context.lineTo(t,e);break;default:this._context.moveTo(t+this._radius,e),this._context.arc(t,e,this._radius,0,Cc)}},result:Hc};var rf,af,of,sf,cf,uf=mc(),lf={point:Hc,lineStart:function(){lf.point=hf},lineEnd:function(){rf&&ff(af,of),lf.point=Hc},polygonStart:function(){rf=!0},polygonEnd:function(){rf=null},result:function(){var t=+uf;return uf.reset(),t}};function hf(t,e){lf.point=ff,af=sf=t,of=cf=e}function ff(t,e){sf-=t,cf-=e,uf.add(jc(sf*sf+cf*cf)),sf=t,cf=e}const df=lf;function pf(){this._string=[]}function yf(t){return"m0,"+t+"a"+t+","+t+" 0 1,1 0,"+-2*t+"a"+t+","+t+" 0 1,1 0,"+2*t+"z"}function gf(t,e){var n,r,i=4.5;function a(t){return t&&("function"==typeof i&&r.pointRadius(+i.apply(this,arguments)),Zc(t,n(r))),r.result()}return a.area=function(t){return Zc(t,n(Ch)),Ch.result()},a.measure=function(t){return Zc(t,n(df)),df.result()},a.bounds=function(t){return Zc(t,n(Dh)),Dh.result()},a.centroid=function(t){return Zc(t,n(ef)),ef.result()},a.projection=function(e){return arguments.length?(n=null==e?(t=null,ph):(t=e).stream,a):t},a.context=function(t){return arguments.length?(r=null==t?(e=null,new pf):new nf(e=t),"function"!=typeof i&&r.pointRadius(i),a):e},a.pointRadius=function(t){return arguments.length?(i="function"==typeof t?t:(r.pointRadius(+t),+t),a):i},a.projection(t).context(e)}function mf(t){return{stream:vf(t)}}function vf(t){return function(e){var n=new bf;for(var r in t)n[r]=t[r];return n.stream=e,n}}function bf(){}function _f(t,e,n){var r=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=r&&t.clipExtent(null),Zc(n,t.stream(Dh)),e(Dh.result()),null!=r&&t.clipExtent(r),t}function xf(t,e,n){return _f(t,(function(n){var r=e[1][0]-e[0][0],i=e[1][1]-e[0][1],a=Math.min(r/(n[1][0]-n[0][0]),i/(n[1][1]-n[0][1])),o=+e[0][0]+(r-a*(n[1][0]+n[0][0]))/2,s=+e[0][1]+(i-a*(n[1][1]+n[0][1]))/2;t.scale(150*a).translate([o,s])}),n)}function wf(t,e,n){return xf(t,[[0,0],e],n)}function kf(t,e,n){return _f(t,(function(n){var r=+e,i=r/(n[1][0]-n[0][0]),a=(r-i*(n[1][0]+n[0][0]))/2,o=-i*n[0][1];t.scale(150*i).translate([a,o])}),n)}function Tf(t,e,n){return _f(t,(function(n){var r=+e,i=r/(n[1][1]-n[0][1]),a=-i*n[0][0],o=(r-i*(n[1][1]+n[0][1]))/2;t.scale(150*i).translate([a,o])}),n)}pf.prototype={_radius:4.5,_circle:yf(4.5),pointRadius:function(t){return(t=+t)!==this._radius&&(this._radius=t,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._string.push("Z"),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._string.push("M",t,",",e),this._point=1;break;case 1:this._string.push("L",t,",",e);break;default:null==this._circle&&(this._circle=yf(this._radius)),this._string.push("M",t,",",e,this._circle)}},result:function(){if(this._string.length){var t=this._string.join("");return this._string=[],t}return null}},bf.prototype={constructor:bf,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var Ef=Oc(30*Ac);function Cf(t,e){return+e?function(t,e){function n(r,i,a,o,s,c,u,l,h,f,d,p,y,g){var m=u-r,v=l-i,b=m*m+v*v;if(b>4*e&&y--){var _=o+f,x=s+d,w=c+p,k=jc(_*_+x*x+w*w),T=Uc(w/=k),E=Mc(Mc(w)-1)e||Mc((m*M+v*N)/b-.5)>.3||o*f+s*d+c*p2?t[2]%360*Ac:0,M()):[g*Sc,m*Sc,v*Sc]},S.angle=function(t){return arguments.length?(b=t%360*Ac,M()):b*Sc},S.reflectX=function(t){return arguments.length?(_=t?-1:1,M()):_<0},S.reflectY=function(t){return arguments.length?(x=t?-1:1,M()):x<0},S.precision=function(t){return arguments.length?(o=Cf(s,C=t*t),N()):jc(C)},S.fitExtent=function(t,e){return xf(S,t,e)},S.fitSize=function(t,e){return wf(S,t,e)},S.fitWidth=function(t,e){return kf(S,t,e)},S.fitHeight=function(t,e){return Tf(S,t,e)},function(){return e=t.apply(this,arguments),S.invert=e.invert&&A,M()}}function Of(t){var e=0,n=kc/3,r=Df(t),i=r(e,n);return i.parallels=function(t){return arguments.length?r(e=t[0]*Ac,n=t[1]*Ac):[e*Sc,n*Sc]},i}function Bf(t,e){var n=Fc(t),r=(n+Fc(e))/2;if(Mc(r)=.12&&i<.234&&r>=-.425&&r<-.214?s:i>=.166&&i<.234&&r>=-.214&&r<-.115?c:o).invert(t)},l.stream=function(n){return t&&e===n?t:(r=[o.stream(e=n),s.stream(n),c.stream(n)],i=r.length,t={point:function(t,e){for(var n=-1;++n0?e<-Tc+xc&&(e=-Tc+xc):e>Tc-xc&&(e=Tc-xc);var n=i/Rc(Wf(e),r);return[n*Fc(r*t),i-n*Oc(r*t)]}return a.invert=function(t,e){var n=i-e,a=Pc(r)*jc(t*t+n*n),o=Dc(t,Mc(n))*Pc(n);return n*r<0&&(o-=kc*Pc(t)*Pc(n)),[o/r,2*Nc(Rc(i/a,1/r))-Tc]},a}function Gf(){return Of(Vf).scale(109.5).parallels([30,30])}function Xf(t,e){return[t,e]}function Zf(){return Nf(Xf).scale(152.63)}function Qf(t,e){var n=Oc(t),r=t===e?Fc(t):(n-Oc(e))/(e-t),i=n/r+t;if(Mc(r)2?t[2]+90:90]):[(t=n())[0],t[1],t[2]-90]},n([0,0,90]).scale(159.155)}function md(t,e){return t.parent===e.parent?1:2}function vd(t,e){return t+e.x}function bd(t,e){return Math.max(t,e.y)}function _d(){var t=md,e=1,n=1,r=!1;function i(i){var a,o=0;i.eachAfter((function(e){var n=e.children;n?(e.x=function(t){return t.reduce(vd,0)/t.length}(n),e.y=function(t){return 1+t.reduce(bd,0)}(n)):(e.x=a?o+=t(e,a):0,e.y=0,a=e)}));var s=function(t){for(var e;e=t.children;)t=e[0];return t}(i),c=function(t){for(var e;e=t.children;)t=e[e.length-1];return t}(i),u=s.x-t(s,c)/2,l=c.x+t(c,s)/2;return i.eachAfter(r?function(t){t.x=(t.x-i.x)*e,t.y=(i.y-t.y)*n}:function(t){t.x=(t.x-u)/(l-u)*e,t.y=(1-(i.y?t.y/i.y:1))*n})}return i.separation=function(e){return arguments.length?(t=e,i):t},i.size=function(t){return arguments.length?(r=!1,e=+t[0],n=+t[1],i):r?null:[e,n]},i.nodeSize=function(t){return arguments.length?(r=!0,e=+t[0],n=+t[1],i):r?[e,n]:null},i}function xd(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function wd(t,e){var n,r,i,a,o,s=new Cd(t),c=+t.value&&(s.value=t.value),u=[s];for(null==e&&(e=kd);n=u.pop();)if(c&&(n.value=+n.data.value),(i=e(n.data))&&(o=i.length))for(n.children=new Array(o),a=o-1;a>=0;--a)u.push(r=n.children[a]=new Cd(i[a])),r.parent=n,r.depth=n.depth+1;return s.eachBefore(Ed)}function kd(t){return t.children}function Td(t){t.data=t.data.data}function Ed(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function Cd(t){this.data=t,this.depth=this.height=0,this.parent=null}id.invert=function(t,e){for(var n,r=e,i=r*r,a=i*i*i,o=0;o<12&&(a=(i=(r-=n=(r*(Jf+td*i+a*(ed+nd*i))-e)/(Jf+3*td*i+a*(7*ed+9*nd*i)))*r)*i*i,!(Mc(n)xc&&--i>0);return[t/(.8707+(a=r*r)*(a*(a*a*a*(.003971-.001529*a)-.013791)-.131979)),r]},hd.invert=Pf(Uc),dd.invert=Pf((function(t){return 2*Nc(t)})),yd.invert=function(t,e){return[-e,2*Nc(Lc(t))-Tc]},Cd.prototype=wd.prototype={constructor:Cd,count:function(){return this.eachAfter(xd)},each:function(t){var e,n,r,i,a=this,o=[a];do{for(e=o.reverse(),o=[];a=e.pop();)if(t(a),n=a.children)for(r=0,i=n.length;r=0;--n)i.push(e[n]);return this},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),i=null;for(t=n.pop(),e=r.pop();t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each((function(e){t.push(e)})),t},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return wd(this).eachBefore(Td)}};var Sd=Array.prototype.slice;function Ad(t){for(var e,n,r=0,i=(t=function(t){for(var e,n,r=t.length;r;)n=Math.random()*r--|0,e=t[r],t[r]=t[n],t[n]=e;return t}(Sd.call(t))).length,a=[];r0&&n*n>r*r+i*i}function Od(t,e){for(var n=0;n(o*=o)?(r=(u+o-i)/(2*u),a=Math.sqrt(Math.max(0,o/u-r*r)),n.x=t.x-r*s-a*c,n.y=t.y-r*c+a*s):(r=(u+i-o)/(2*u),a=Math.sqrt(Math.max(0,i/u-r*r)),n.x=e.x+r*s-a*c,n.y=e.y+r*c+a*s)):(n.x=e.x+n.r,n.y=e.y)}function Fd(t,e){var n=t.r+e.r-1e-6,r=e.x-t.x,i=e.y-t.y;return n>0&&n*n>r*r+i*i}function Pd(t){var e=t._,n=t.next._,r=e.r+n.r,i=(e.x*n.r+n.x*e.r)/r,a=(e.y*n.r+n.y*e.r)/r;return i*i+a*a}function jd(t){this._=t,this.next=null,this.previous=null}function Yd(t){if(!(i=t.length))return 0;var e,n,r,i,a,o,s,c,u,l,h;if((e=t[0]).x=0,e.y=0,!(i>1))return e.r;if(n=t[1],e.x=-n.r,n.x=e.r,n.y=0,!(i>2))return e.r+n.r;Rd(n,e,r=t[2]),e=new jd(e),n=new jd(n),r=new jd(r),e.next=r.previous=n,n.next=e.previous=r,r.next=n.previous=e;t:for(s=3;s0)throw new Error("cycle");return a}return n.id=function(e){return arguments.length?(t=qd(e),n):t},n.parentId=function(t){return arguments.length?(e=qd(t),n):e},n}function ap(t,e){return t.parent===e.parent?1:2}function op(t){var e=t.children;return e?e[0]:t.t}function sp(t){var e=t.children;return e?e[e.length-1]:t.t}function cp(t,e,n){var r=n/(e.i-t.i);e.c-=r,e.s+=n,t.c+=r,e.z+=n,e.m+=n}function up(t,e,n){return t.a.parent===e.parent?t.a:n}function lp(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}function hp(){var t=ap,e=1,n=1,r=null;function i(i){var c=function(t){for(var e,n,r,i,a,o=new lp(t,0),s=[o];e=s.pop();)if(r=e._.children)for(e.children=new Array(a=r.length),i=a-1;i>=0;--i)s.push(n=e.children[i]=new lp(r[i],i)),n.parent=e;return(o.parent=new lp(null,0)).children=[o],o}(i);if(c.eachAfter(a),c.parent.m=-c.z,c.eachBefore(o),r)i.eachBefore(s);else{var u=i,l=i,h=i;i.eachBefore((function(t){t.xl.x&&(l=t),t.depth>h.depth&&(h=t)}));var f=u===l?1:t(u,l)/2,d=f-u.x,p=e/(l.x+f+d),y=n/(h.depth||1);i.eachBefore((function(t){t.x=(t.x+d)*p,t.y=t.depth*y}))}return i}function a(e){var n=e.children,r=e.parent.children,i=e.i?r[e.i-1]:null;if(n){!function(t){for(var e,n=0,r=0,i=t.children,a=i.length;--a>=0;)(e=i[a]).z+=n,e.m+=n,n+=e.s+(r+=e.c)}(e);var a=(n[0].z+n[n.length-1].z)/2;i?(e.z=i.z+t(e._,i._),e.m=e.z-a):e.z=a}else i&&(e.z=i.z+t(e._,i._));e.parent.A=function(e,n,r){if(n){for(var i,a=e,o=e,s=n,c=a.parent.children[0],u=a.m,l=o.m,h=s.m,f=c.m;s=sp(s),a=op(a),s&&a;)c=op(c),(o=sp(o)).a=e,(i=s.z+h-a.z-u+t(s._,a._))>0&&(cp(up(s,e,r),e,i),u+=i,l+=i),h+=s.m,u+=a.m,f+=c.m,l+=o.m;s&&!sp(o)&&(o.t=s,o.m+=h-l),a&&!op(c)&&(c.t=a,c.m+=u-f,r=e)}return r}(e,i,e.parent.A||r[0])}function o(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function s(t){t.x*=e,t.y=t.depth*n}return i.separation=function(e){return arguments.length?(t=e,i):t},i.size=function(t){return arguments.length?(r=!1,e=+t[0],n=+t[1],i):r?null:[e,n]},i.nodeSize=function(t){return arguments.length?(r=!0,e=+t[0],n=+t[1],i):r?[e,n]:null},i}function fp(t,e,n,r,i){for(var a,o=t.children,s=-1,c=o.length,u=t.value&&(i-n)/t.value;++sf&&(f=s),g=l*l*y,(d=Math.max(f/g,g/h))>p){l-=s;break}p=d}m.push(o={value:l,dice:c1?e:1)},n}(dp);function gp(){var t=yp,e=!1,n=1,r=1,i=[0],a=Hd,o=Hd,s=Hd,c=Hd,u=Hd;function l(t){return t.x0=t.y0=0,t.x1=n,t.y1=r,t.eachBefore(h),i=[0],e&&t.eachBefore(Qd),t}function h(e){var n=i[e.depth],r=e.x0+n,l=e.y0+n,h=e.x1-n,f=e.y1-n;h=n-1){var l=s[e];return l.x0=i,l.y0=a,l.x1=o,void(l.y1=c)}for(var h=u[e],f=r/2+h,d=e+1,p=n-1;d>>1;u[y]c-a){var v=(i*m+o*g)/r;t(e,d,g,i,a,v,c),t(d,n,m,v,a,o,c)}else{var b=(a*m+c*g)/r;t(e,d,g,i,a,o,b),t(d,n,m,i,b,o,c)}}(0,c,t.value,e,n,r,i)}function vp(t,e,n,r,i){(1&t.depth?fp:Kd)(t,e,n,r,i)}const bp=function t(e){function n(t,n,r,i,a){if((o=t._squarify)&&o.ratio===e)for(var o,s,c,u,l,h=-1,f=o.length,d=t.value;++h1?e:1)},n}(dp);function _p(t){var e=t.length;return function(n){return t[Math.max(0,Math.min(e-1,Math.floor(n*e)))]}}function xp(t,e){var n=fn(+t,+e);return function(t){var e=n(t);return e-360*Math.floor(e/360)}}function wp(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}var kp=Math.SQRT2;function Tp(t){return((t=Math.exp(t))+1/t)/2}function Ep(t,e){var n,r,i=t[0],a=t[1],o=t[2],s=e[0],c=e[1],u=e[2],l=s-i,h=c-a,f=l*l+h*h;if(f<1e-12)r=Math.log(u/o)/kp,n=function(t){return[i+t*l,a+t*h,o*Math.exp(kp*t*r)]};else{var d=Math.sqrt(f),p=(u*u-o*o+4*f)/(2*o*2*d),y=(u*u-o*o-4*f)/(2*u*2*d),g=Math.log(Math.sqrt(p*p+1)-p),m=Math.log(Math.sqrt(y*y+1)-y);r=(m-g)/kp,n=function(t){var e,n=t*r,s=Tp(g),c=o/(2*d)*(s*(e=kp*n+g,((e=Math.exp(2*e))-1)/(e+1))-function(t){return((t=Math.exp(t))-1/t)/2}(g));return[i+c*l,a+c*h,o*s/Tp(kp*n+g)]}}return n.duration=1e3*r,n}function Cp(t){return function(e,n){var r=t((e=rn(e)).h,(n=rn(n)).h),i=dn(e.s,n.s),a=dn(e.l,n.l),o=dn(e.opacity,n.opacity);return function(t){return e.h=r(t),e.s=i(t),e.l=a(t),e.opacity=o(t),e+""}}}const Sp=Cp(fn);var Ap=Cp(dn);function Mp(t,e){var n=dn((t=ba(t)).l,(e=ba(e)).l),r=dn(t.a,e.a),i=dn(t.b,e.b),a=dn(t.opacity,e.opacity);return function(e){return t.l=n(e),t.a=r(e),t.b=i(e),t.opacity=a(e),t+""}}function Np(t){return function(e,n){var r=t((e=Sa(e)).h,(n=Sa(n)).h),i=dn(e.c,n.c),a=dn(e.l,n.l),o=dn(e.opacity,n.opacity);return function(t){return e.h=r(t),e.c=i(t),e.l=a(t),e.opacity=o(t),e+""}}}const Dp=Np(fn);var Op=Np(dn);function Bp(t){return function e(n){function r(e,r){var i=t((e=Pa(e)).h,(r=Pa(r)).h),a=dn(e.s,r.s),o=dn(e.l,r.l),s=dn(e.opacity,r.opacity);return function(t){return e.h=i(t),e.s=a(t),e.l=o(Math.pow(t,n)),e.opacity=s(t),e+""}}return n=+n,r.gamma=e,r}(1)}const Lp=Bp(fn);var Ip=Bp(dn);function Rp(t,e){for(var n=0,r=e.length-1,i=e[0],a=new Array(r<0?0:r);n1&&Yp(t[n[r-2]],t[n[r-1]],t[i])<=0;)--r;n[r++]=i}return n.slice(0,r)}function qp(t){if((n=t.length)<3)return null;var e,n,r=new Array(n),i=new Array(n);for(e=0;e=0;--e)u.push(t[r[a[e]][2]]);for(e=+s;es!=u>s&&o<(c-n)*(s-r)/(u-r)+n&&(l=!l),c=n,u=r;return l}function $p(t){for(var e,n,r=-1,i=t.length,a=t[i-1],o=a[0],s=a[1],c=0;++r1);return t+n*a*Math.sqrt(-2*Math.log(i)/i)}}return n.source=t,n}(Wp),Xp=function t(e){function n(){var t=Gp.source(e).apply(this,arguments);return function(){return Math.exp(t())}}return n.source=t,n}(Wp),Zp=function t(e){function n(t){return function(){for(var n=0,r=0;rr&&(e=n,n=r,r=e),function(t){return Math.max(n,Math.min(r,t))}}function py(t,e,n){var r=t[0],i=t[1],a=e[0],o=e[1];return i2?yy:py,i=a=null,h}function h(e){return isNaN(e=+e)?n:(i||(i=r(o.map(t),s,c)))(t(u(e)))}return h.invert=function(n){return u(e((a||(a=r(s,o.map(t),kn)))(n)))},h.domain=function(t){return arguments.length?(o=ny.call(t,uy),u===hy||(u=dy(o)),l()):o.slice()},h.range=function(t){return arguments.length?(s=ry.call(t),l()):s.slice()},h.rangeRound=function(t){return s=ry.call(t),c=wp,l()},h.clamp=function(t){return arguments.length?(u=t?dy(o):hy,h):u!==hy},h.interpolate=function(t){return arguments.length?(c=t,l()):c},h.unknown=function(t){return arguments.length?(n=t,h):n},function(n,r){return t=n,e=r,l()}}function vy(t,e){return my()(t,e)}function by(t,e,n,r){var i,a=M(t,e,n);switch((r=nc(null==r?",f":r)).type){case"s":var o=Math.max(Math.abs(t),Math.abs(e));return null!=r.precision||isNaN(i=yc(a,o))||(r.precision=i),uc(r,o);case"":case"e":case"g":case"p":case"r":null!=r.precision||isNaN(i=gc(a,Math.max(Math.abs(t),Math.abs(e))))||(r.precision=i-("e"===r.type));break;case"f":case"%":null!=r.precision||isNaN(i=pc(a))||(r.precision=i-2*("%"===r.type))}return cc(r)}function _y(t){var e=t.domain;return t.ticks=function(t){var n=e();return S(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var r=e();return by(r[0],r[r.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var r,i=e(),a=0,o=i.length-1,s=i[a],c=i[o];return c0?r=A(s=Math.floor(s/r)*r,c=Math.ceil(c/r)*r,n):r<0&&(r=A(s=Math.ceil(s*r)/r,c=Math.floor(c*r)/r,n)),r>0?(i[a]=Math.floor(s/r)*r,i[o]=Math.ceil(c/r)*r,e(i)):r<0&&(i[a]=Math.ceil(s*r)/r,i[o]=Math.floor(c*r)/r,e(i)),t},t}function xy(){var t=vy(hy,hy);return t.copy=function(){return gy(t,xy())},Jp.apply(t,arguments),_y(t)}function wy(t){var e;function n(t){return isNaN(t=+t)?e:t}return n.invert=n,n.domain=n.range=function(e){return arguments.length?(t=ny.call(e,uy),n):t.slice()},n.unknown=function(t){return arguments.length?(e=t,n):e},n.copy=function(){return wy(t).unknown(e)},t=arguments.length?ny.call(t,uy):[0,1],_y(n)}function ky(t,e){var n,r=0,i=(t=t.slice()).length-1,a=t[r],o=t[i];return o0){for(;fc)break;y.push(h)}}else for(;f=1;--l)if(!((h=u*l)c)break;y.push(h)}}else y=S(f,d,Math.min(d-f,p)).map(n);return r?y.reverse():y},r.tickFormat=function(t,i){if(null==i&&(i=10===a?".0e":","),"function"!=typeof i&&(i=cc(i)),t===1/0)return i;null==t&&(t=10);var o=Math.max(1,a*t/r.ticks().length);return function(t){var r=t/n(Math.round(e(t)));return r*a0?r[i-1]:e[0],i=r?[i[r-1],n]:[i[o-1],i[o]]},o.unknown=function(e){return arguments.length?(t=e,o):o},o.thresholds=function(){return i.slice()},o.copy=function(){return qy().domain([e,n]).range(a).unknown(t)},Jp.apply(_y(o),arguments)}function Hy(){var t,e=[.5],n=[0,1],r=1;function i(i){return i<=i?n[u(e,i,0,r)]:t}return i.domain=function(t){return arguments.length?(e=ry.call(t),r=Math.min(e.length,n.length-1),i):e.slice()},i.range=function(t){return arguments.length?(n=ry.call(t),r=Math.min(e.length,n.length-1),i):n.slice()},i.invertExtent=function(t){var r=n.indexOf(t);return[e[r-1],e[r]]},i.unknown=function(e){return arguments.length?(t=e,i):t},i.copy=function(){return Hy().domain(e).range(n).unknown(t)},Jp.apply(i,arguments)}var $y=new Date,Wy=new Date;function Vy(t,e,n,r){function i(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return i.floor=function(e){return t(e=new Date(+e)),e},i.ceil=function(n){return t(n=new Date(n-1)),e(n,1),t(n),n},i.round=function(t){var e=i(t),n=i.ceil(t);return t-e0))return s;do{s.push(o=new Date(+n)),e(n,a),t(n)}while(o=e)for(;t(e),!n(e);)e.setTime(e-1)}),(function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}))},n&&(i.count=function(e,r){return $y.setTime(+e),Wy.setTime(+r),t($y),t(Wy),Math.floor(n($y,Wy))},i.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?function(e){return r(e)%t==0}:function(e){return i.count(0,e)%t==0}):i:null}),i}var Gy=Vy((function(t){t.setMonth(0,1),t.setHours(0,0,0,0)}),(function(t,e){t.setFullYear(t.getFullYear()+e)}),(function(t,e){return e.getFullYear()-t.getFullYear()}),(function(t){return t.getFullYear()}));Gy.every=function(t){return isFinite(t=Math.floor(t))&&t>0?Vy((function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)}),(function(e,n){e.setFullYear(e.getFullYear()+n*t)})):null};const Xy=Gy;var Zy=Gy.range,Qy=Vy((function(t){t.setDate(1),t.setHours(0,0,0,0)}),(function(t,e){t.setMonth(t.getMonth()+e)}),(function(t,e){return e.getMonth()-t.getMonth()+12*(e.getFullYear()-t.getFullYear())}),(function(t){return t.getMonth()}));const Ky=Qy;var Jy=Qy.range,tg=6e4,eg=36e5,ng=6048e5;function rg(t){return Vy((function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+7*e)}),(function(t,e){return(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*tg)/ng}))}var ig=rg(0),ag=rg(1),og=rg(2),sg=rg(3),cg=rg(4),ug=rg(5),lg=rg(6),hg=ig.range,fg=ag.range,dg=og.range,pg=sg.range,yg=cg.range,gg=ug.range,mg=lg.range,vg=Vy((function(t){t.setHours(0,0,0,0)}),(function(t,e){t.setDate(t.getDate()+e)}),(function(t,e){return(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*tg)/864e5}),(function(t){return t.getDate()-1}));const bg=vg;var _g=vg.range,xg=Vy((function(t){t.setTime(t-t.getMilliseconds()-1e3*t.getSeconds()-t.getMinutes()*tg)}),(function(t,e){t.setTime(+t+e*eg)}),(function(t,e){return(e-t)/eg}),(function(t){return t.getHours()}));const wg=xg;var kg=xg.range,Tg=Vy((function(t){t.setTime(t-t.getMilliseconds()-1e3*t.getSeconds())}),(function(t,e){t.setTime(+t+e*tg)}),(function(t,e){return(e-t)/tg}),(function(t){return t.getMinutes()}));const Eg=Tg;var Cg=Tg.range,Sg=Vy((function(t){t.setTime(t-t.getMilliseconds())}),(function(t,e){t.setTime(+t+1e3*e)}),(function(t,e){return(e-t)/1e3}),(function(t){return t.getUTCSeconds()}));const Ag=Sg;var Mg=Sg.range,Ng=Vy((function(){}),(function(t,e){t.setTime(+t+e)}),(function(t,e){return e-t}));Ng.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?Vy((function(e){e.setTime(Math.floor(e/t)*t)}),(function(e,n){e.setTime(+e+n*t)}),(function(e,n){return(n-e)/t})):Ng:null};const Dg=Ng;var Og=Ng.range;function Bg(t){return Vy((function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+7*e)}),(function(t,e){return(e-t)/ng}))}var Lg=Bg(0),Ig=Bg(1),Rg=Bg(2),Fg=Bg(3),Pg=Bg(4),jg=Bg(5),Yg=Bg(6),zg=Lg.range,Ug=Ig.range,qg=Rg.range,Hg=Fg.range,$g=Pg.range,Wg=jg.range,Vg=Yg.range,Gg=Vy((function(t){t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCDate(t.getUTCDate()+e)}),(function(t,e){return(e-t)/864e5}),(function(t){return t.getUTCDate()-1}));const Xg=Gg;var Zg=Gg.range,Qg=Vy((function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),(function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)}),(function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()}),(function(t){return t.getUTCFullYear()}));Qg.every=function(t){return isFinite(t=Math.floor(t))&&t>0?Vy((function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)}),(function(e,n){e.setUTCFullYear(e.getUTCFullYear()+n*t)})):null};const Kg=Qg;var Jg=Qg.range;function tm(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function em(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function nm(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}function rm(t){var e=t.dateTime,n=t.date,r=t.time,i=t.periods,a=t.days,o=t.shortDays,s=t.months,c=t.shortMonths,u=ym(i),l=gm(i),h=ym(a),f=gm(a),d=ym(o),p=gm(o),y=ym(s),g=gm(s),m=ym(c),v=gm(c),b={a:function(t){return o[t.getDay()]},A:function(t){return a[t.getDay()]},b:function(t){return c[t.getMonth()]},B:function(t){return s[t.getMonth()]},c:null,d:Fm,e:Fm,f:Um,g:Jm,G:ev,H:Pm,I:jm,j:Ym,L:zm,m:qm,M:Hm,p:function(t){return i[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:Tv,s:Ev,S:$m,u:Wm,U:Vm,V:Xm,w:Zm,W:Qm,x:null,X:null,y:Km,Y:tv,Z:nv,"%":kv},_={a:function(t){return o[t.getUTCDay()]},A:function(t){return a[t.getUTCDay()]},b:function(t){return c[t.getUTCMonth()]},B:function(t){return s[t.getUTCMonth()]},c:null,d:rv,e:rv,f:cv,g:bv,G:xv,H:iv,I:av,j:ov,L:sv,m:uv,M:lv,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:Tv,s:Ev,S:hv,u:fv,U:dv,V:yv,w:gv,W:mv,x:null,X:null,y:vv,Y:_v,Z:wv,"%":kv},x={a:function(t,e,n){var r=d.exec(e.slice(n));return r?(t.w=p[r[0].toLowerCase()],n+r[0].length):-1},A:function(t,e,n){var r=h.exec(e.slice(n));return r?(t.w=f[r[0].toLowerCase()],n+r[0].length):-1},b:function(t,e,n){var r=m.exec(e.slice(n));return r?(t.m=v[r[0].toLowerCase()],n+r[0].length):-1},B:function(t,e,n){var r=y.exec(e.slice(n));return r?(t.m=g[r[0].toLowerCase()],n+r[0].length):-1},c:function(t,n,r){return T(t,e,n,r)},d:Sm,e:Sm,f:Bm,g:km,G:wm,H:Mm,I:Mm,j:Am,L:Om,m:Cm,M:Nm,p:function(t,e,n){var r=u.exec(e.slice(n));return r?(t.p=l[r[0].toLowerCase()],n+r[0].length):-1},q:Em,Q:Im,s:Rm,S:Dm,u:vm,U:bm,V:_m,w:mm,W:xm,x:function(t,e,r){return T(t,n,e,r)},X:function(t,e,n){return T(t,r,e,n)},y:km,Y:wm,Z:Tm,"%":Lm};function w(t,e){return function(n){var r,i,a,o=[],s=-1,c=0,u=t.length;for(n instanceof Date||(n=new Date(+n));++s53)return null;"w"in a||(a.w=1),"Z"in a?(i=(r=em(nm(a.y,0,1))).getUTCDay(),r=i>4||0===i?Ig.ceil(r):Ig(r),r=Xg.offset(r,7*(a.V-1)),a.y=r.getUTCFullYear(),a.m=r.getUTCMonth(),a.d=r.getUTCDate()+(a.w+6)%7):(i=(r=tm(nm(a.y,0,1))).getDay(),r=i>4||0===i?ag.ceil(r):ag(r),r=bg.offset(r,7*(a.V-1)),a.y=r.getFullYear(),a.m=r.getMonth(),a.d=r.getDate()+(a.w+6)%7)}else("W"in a||"U"in a)&&("w"in a||(a.w="u"in a?a.u%7:"W"in a?1:0),i="Z"in a?em(nm(a.y,0,1)).getUTCDay():tm(nm(a.y,0,1)).getDay(),a.m=0,a.d="W"in a?(a.w+6)%7+7*a.W-(i+5)%7:a.w+7*a.U-(i+6)%7);return"Z"in a?(a.H+=a.Z/100|0,a.M+=a.Z%100,em(a)):tm(a)}}function T(t,e,n,r){for(var i,a,o=0,s=e.length,c=n.length;o=c)return-1;if(37===(i=e.charCodeAt(o++))){if(i=e.charAt(o++),!(a=x[i in um?e.charAt(o++):i])||(r=a(t,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}return b.x=w(n,b),b.X=w(r,b),b.c=w(e,b),_.x=w(n,_),_.X=w(r,_),_.c=w(e,_),{format:function(t){var e=w(t+="",b);return e.toString=function(){return t},e},parse:function(t){var e=k(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=w(t+="",_);return e.toString=function(){return t},e},utcParse:function(t){var e=k(t+="",!0);return e.toString=function(){return t},e}}}var im,am,om,sm,cm,um={"-":"",_:" ",0:"0"},lm=/^\s*\d+/,hm=/^%/,fm=/[\\^$*+?|[\]().{}]/g;function dm(t,e,n){var r=t<0?"-":"",i=(r?-t:t)+"",a=i.length;return r+(a68?1900:2e3),n+r[0].length):-1}function Tm(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function Em(t,e,n){var r=lm.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function Cm(t,e,n){var r=lm.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function Sm(t,e,n){var r=lm.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function Am(t,e,n){var r=lm.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function Mm(t,e,n){var r=lm.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function Nm(t,e,n){var r=lm.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function Dm(t,e,n){var r=lm.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function Om(t,e,n){var r=lm.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function Bm(t,e,n){var r=lm.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function Lm(t,e,n){var r=hm.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function Im(t,e,n){var r=lm.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function Rm(t,e,n){var r=lm.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function Fm(t,e){return dm(t.getDate(),e,2)}function Pm(t,e){return dm(t.getHours(),e,2)}function jm(t,e){return dm(t.getHours()%12||12,e,2)}function Ym(t,e){return dm(1+bg.count(Xy(t),t),e,3)}function zm(t,e){return dm(t.getMilliseconds(),e,3)}function Um(t,e){return zm(t,e)+"000"}function qm(t,e){return dm(t.getMonth()+1,e,2)}function Hm(t,e){return dm(t.getMinutes(),e,2)}function $m(t,e){return dm(t.getSeconds(),e,2)}function Wm(t){var e=t.getDay();return 0===e?7:e}function Vm(t,e){return dm(ig.count(Xy(t)-1,t),e,2)}function Gm(t){var e=t.getDay();return e>=4||0===e?cg(t):cg.ceil(t)}function Xm(t,e){return t=Gm(t),dm(cg.count(Xy(t),t)+(4===Xy(t).getDay()),e,2)}function Zm(t){return t.getDay()}function Qm(t,e){return dm(ag.count(Xy(t)-1,t),e,2)}function Km(t,e){return dm(t.getFullYear()%100,e,2)}function Jm(t,e){return dm((t=Gm(t)).getFullYear()%100,e,2)}function tv(t,e){return dm(t.getFullYear()%1e4,e,4)}function ev(t,e){var n=t.getDay();return dm((t=n>=4||0===n?cg(t):cg.ceil(t)).getFullYear()%1e4,e,4)}function nv(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+dm(e/60|0,"0",2)+dm(e%60,"0",2)}function rv(t,e){return dm(t.getUTCDate(),e,2)}function iv(t,e){return dm(t.getUTCHours(),e,2)}function av(t,e){return dm(t.getUTCHours()%12||12,e,2)}function ov(t,e){return dm(1+Xg.count(Kg(t),t),e,3)}function sv(t,e){return dm(t.getUTCMilliseconds(),e,3)}function cv(t,e){return sv(t,e)+"000"}function uv(t,e){return dm(t.getUTCMonth()+1,e,2)}function lv(t,e){return dm(t.getUTCMinutes(),e,2)}function hv(t,e){return dm(t.getUTCSeconds(),e,2)}function fv(t){var e=t.getUTCDay();return 0===e?7:e}function dv(t,e){return dm(Lg.count(Kg(t)-1,t),e,2)}function pv(t){var e=t.getUTCDay();return e>=4||0===e?Pg(t):Pg.ceil(t)}function yv(t,e){return t=pv(t),dm(Pg.count(Kg(t),t)+(4===Kg(t).getUTCDay()),e,2)}function gv(t){return t.getUTCDay()}function mv(t,e){return dm(Ig.count(Kg(t)-1,t),e,2)}function vv(t,e){return dm(t.getUTCFullYear()%100,e,2)}function bv(t,e){return dm((t=pv(t)).getUTCFullYear()%100,e,2)}function _v(t,e){return dm(t.getUTCFullYear()%1e4,e,4)}function xv(t,e){var n=t.getUTCDay();return dm((t=n>=4||0===n?Pg(t):Pg.ceil(t)).getUTCFullYear()%1e4,e,4)}function wv(){return"+0000"}function kv(){return"%"}function Tv(t){return+t}function Ev(t){return Math.floor(+t/1e3)}function Cv(t){return im=rm(t),am=im.format,om=im.parse,sm=im.utcFormat,cm=im.utcParse,im}Cv({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});var Sv=31536e6;function Av(t){return new Date(t)}function Mv(t){return t instanceof Date?+t:+new Date(+t)}function Nv(t,e,n,r,i,o,s,c,u){var l=vy(hy,hy),h=l.invert,f=l.domain,d=u(".%L"),p=u(":%S"),y=u("%I:%M"),g=u("%I %p"),m=u("%a %d"),v=u("%b %d"),b=u("%B"),_=u("%Y"),x=[[s,1,1e3],[s,5,5e3],[s,15,15e3],[s,30,3e4],[o,1,6e4],[o,5,3e5],[o,15,9e5],[o,30,18e5],[i,1,36e5],[i,3,108e5],[i,6,216e5],[i,12,432e5],[r,1,864e5],[r,2,1728e5],[n,1,6048e5],[e,1,2592e6],[e,3,7776e6],[t,1,Sv]];function w(a){return(s(a)1)&&(t-=Math.floor(t));var e=Math.abs(t-.5);return v_.h=360*t-100,v_.s=1.5-1.5*e,v_.l=.8-.9*e,v_+""}var __=Ze(),x_=Math.PI/3,w_=2*Math.PI/3;function k_(t){var e;return t=(.5-t)*Math.PI,__.r=255*(e=Math.sin(t))*e,__.g=255*(e=Math.sin(t+x_))*e,__.b=255*(e=Math.sin(t+w_))*e,__+""}function T_(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(34.61+t*(1172.33-t*(10793.56-t*(33300.12-t*(38394.49-14825.05*t)))))))+", "+Math.max(0,Math.min(255,Math.round(23.31+t*(557.33+t*(1225.33-t*(3574.96-t*(1073.77+707.56*t)))))))+", "+Math.max(0,Math.min(255,Math.round(27.2+t*(3211.1-t*(15327.97-t*(27814-t*(22569.18-6838.66*t)))))))+")"}function E_(t){var e=t.length;return function(n){return t[Math.max(0,Math.min(e-1,Math.floor(n*e)))]}}const C_=E_(nb("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));var S_=E_(nb("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),A_=E_(nb("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),M_=E_(nb("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));function N_(t){return Te(ie(t).call(document.documentElement))}var D_=0;function O_(){return new B_}function B_(){this._="@"+(++D_).toString(36)}function L_(t){return"string"==typeof t?new xe([document.querySelectorAll(t)],[document.documentElement]):new xe([null==t?[]:t],_e)}function I_(t,e){null==e&&(e=Mn().touches);for(var n=0,r=e?e.length:0,i=new Array(r);n1?0:t<-1?$_:Math.acos(t)}function X_(t){return t>=1?W_:t<=-1?-W_:Math.asin(t)}function Z_(t){return t.innerRadius}function Q_(t){return t.outerRadius}function K_(t){return t.startAngle}function J_(t){return t.endAngle}function tx(t){return t&&t.padAngle}function ex(t,e,n,r,i,a,o,s){var c=n-t,u=r-e,l=o-i,h=s-a,f=h*c-l*u;if(!(f*fN*N+D*D&&(T=C,E=S),{cx:T,cy:E,x01:-l,y01:-h,x11:T*(i/x-1),y11:E*(i/x-1)}}function rx(){var t=Z_,e=Q_,n=R_(0),r=null,i=K_,a=J_,o=tx,s=null;function c(){var c,u,l=+t.apply(this,arguments),h=+e.apply(this,arguments),f=i.apply(this,arguments)-W_,d=a.apply(this,arguments)-W_,p=F_(d-f),y=d>f;if(s||(s=c=$i()),hH_)if(p>V_-H_)s.moveTo(h*j_(f),h*U_(f)),s.arc(0,0,h,f,d,!y),l>H_&&(s.moveTo(l*j_(d),l*U_(d)),s.arc(0,0,l,d,f,y));else{var g,m,v=f,b=d,_=f,x=d,w=p,k=p,T=o.apply(this,arguments)/2,E=T>H_&&(r?+r.apply(this,arguments):q_(l*l+h*h)),C=z_(F_(h-l)/2,+n.apply(this,arguments)),S=C,A=C;if(E>H_){var M=X_(E/l*U_(T)),N=X_(E/h*U_(T));(w-=2*M)>H_?(_+=M*=y?1:-1,x-=M):(w=0,_=x=(f+d)/2),(k-=2*N)>H_?(v+=N*=y?1:-1,b-=N):(k=0,v=b=(f+d)/2)}var D=h*j_(v),O=h*U_(v),B=l*j_(x),L=l*U_(x);if(C>H_){var I,R=h*j_(b),F=h*U_(b),P=l*j_(_),j=l*U_(_);if(p<$_&&(I=ex(D,O,P,j,R,F,B,L))){var Y=D-I[0],z=O-I[1],U=R-I[0],q=F-I[1],H=1/U_(G_((Y*U+z*q)/(q_(Y*Y+z*z)*q_(U*U+q*q)))/2),$=q_(I[0]*I[0]+I[1]*I[1]);S=z_(C,(l-$)/(H-1)),A=z_(C,(h-$)/(H+1))}}k>H_?A>H_?(g=nx(P,j,D,O,h,A,y),m=nx(R,F,B,L,h,A,y),s.moveTo(g.cx+g.x01,g.cy+g.y01),AH_&&w>H_?S>H_?(g=nx(B,L,R,F,l,-S,y),m=nx(D,O,P,j,l,-S,y),s.lineTo(g.cx+g.x01,g.cy+g.y01),S=l;--h)s.point(g[h],m[h]);s.lineEnd(),s.areaEnd()}y&&(g[u]=+t(f,u,c),m[u]=+n(f,u,c),s.point(e?+e(f,u,c):g[u],r?+r(f,u,c):m[u]))}if(d)return s=null,d+""||null}function u(){return cx().defined(i).curve(o).context(a)}return c.x=function(n){return arguments.length?(t="function"==typeof n?n:R_(+n),e=null,c):t},c.x0=function(e){return arguments.length?(t="function"==typeof e?e:R_(+e),c):t},c.x1=function(t){return arguments.length?(e=null==t?null:"function"==typeof t?t:R_(+t),c):e},c.y=function(t){return arguments.length?(n="function"==typeof t?t:R_(+t),r=null,c):n},c.y0=function(t){return arguments.length?(n="function"==typeof t?t:R_(+t),c):n},c.y1=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:R_(+t),c):r},c.lineX0=c.lineY0=function(){return u().x(t).y(n)},c.lineY1=function(){return u().x(t).y(r)},c.lineX1=function(){return u().x(e).y(n)},c.defined=function(t){return arguments.length?(i="function"==typeof t?t:R_(!!t),c):i},c.curve=function(t){return arguments.length?(o=t,null!=a&&(s=o(a)),c):o},c.context=function(t){return arguments.length?(null==t?a=s=null:s=o(a=t),c):a},c}function lx(t,e){return et?1:e>=t?0:NaN}function hx(t){return t}function fx(){var t=hx,e=lx,n=null,r=R_(0),i=R_(V_),a=R_(0);function o(o){var s,c,u,l,h,f=o.length,d=0,p=new Array(f),y=new Array(f),g=+r.apply(this,arguments),m=Math.min(V_,Math.max(-V_,i.apply(this,arguments)-g)),v=Math.min(Math.abs(m)/f,a.apply(this,arguments)),b=v*(m<0?-1:1);for(s=0;s0&&(d+=h);for(null!=e?p.sort((function(t,n){return e(y[t],y[n])})):null!=n&&p.sort((function(t,e){return n(o[t],o[e])})),s=0,u=d?(m-f*b)/d:0;s0?h*u:0)+b,y[c]={data:o[c],index:s,value:h,startAngle:g,endAngle:l,padAngle:v};return y}return o.value=function(e){return arguments.length?(t="function"==typeof e?e:R_(+e),o):t},o.sortValues=function(t){return arguments.length?(e=t,n=null,o):e},o.sort=function(t){return arguments.length?(n=t,e=null,o):n},o.startAngle=function(t){return arguments.length?(r="function"==typeof t?t:R_(+t),o):r},o.endAngle=function(t){return arguments.length?(i="function"==typeof t?t:R_(+t),o):i},o.padAngle=function(t){return arguments.length?(a="function"==typeof t?t:R_(+t),o):a},o}ix.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}};var dx=yx(ax);function px(t){this._curve=t}function yx(t){function e(e){return new px(t(e))}return e._curve=t,e}function gx(t){var e=t.curve;return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t.curve=function(t){return arguments.length?e(yx(t)):e()._curve},t}function mx(){return gx(cx().curve(dx))}function vx(){var t=ux().curve(dx),e=t.curve,n=t.lineX0,r=t.lineX1,i=t.lineY0,a=t.lineY1;return t.angle=t.x,delete t.x,t.startAngle=t.x0,delete t.x0,t.endAngle=t.x1,delete t.x1,t.radius=t.y,delete t.y,t.innerRadius=t.y0,delete t.y0,t.outerRadius=t.y1,delete t.y1,t.lineStartAngle=function(){return gx(n())},delete t.lineX0,t.lineEndAngle=function(){return gx(r())},delete t.lineX1,t.lineInnerRadius=function(){return gx(i())},delete t.lineY0,t.lineOuterRadius=function(){return gx(a())},delete t.lineY1,t.curve=function(t){return arguments.length?e(yx(t)):e()._curve},t}function bx(t,e){return[(e=+e)*Math.cos(t-=Math.PI/2),e*Math.sin(t)]}px.prototype={areaStart:function(){this._curve.areaStart()},areaEnd:function(){this._curve.areaEnd()},lineStart:function(){this._curve.lineStart()},lineEnd:function(){this._curve.lineEnd()},point:function(t,e){this._curve.point(e*Math.sin(t),e*-Math.cos(t))}};var _x=Array.prototype.slice;function xx(t){return t.source}function wx(t){return t.target}function kx(t){var e=xx,n=wx,r=ox,i=sx,a=null;function o(){var o,s=_x.call(arguments),c=e.apply(this,s),u=n.apply(this,s);if(a||(a=o=$i()),t(a,+r.apply(this,(s[0]=c,s)),+i.apply(this,s),+r.apply(this,(s[0]=u,s)),+i.apply(this,s)),o)return a=null,o+""||null}return o.source=function(t){return arguments.length?(e=t,o):e},o.target=function(t){return arguments.length?(n=t,o):n},o.x=function(t){return arguments.length?(r="function"==typeof t?t:R_(+t),o):r},o.y=function(t){return arguments.length?(i="function"==typeof t?t:R_(+t),o):i},o.context=function(t){return arguments.length?(a=null==t?null:t,o):a},o}function Tx(t,e,n,r,i){t.moveTo(e,n),t.bezierCurveTo(e=(e+r)/2,n,e,i,r,i)}function Ex(t,e,n,r,i){t.moveTo(e,n),t.bezierCurveTo(e,n=(n+i)/2,r,n,r,i)}function Cx(t,e,n,r,i){var a=bx(e,n),o=bx(e,n=(n+i)/2),s=bx(r,n),c=bx(r,i);t.moveTo(a[0],a[1]),t.bezierCurveTo(o[0],o[1],s[0],s[1],c[0],c[1])}function Sx(){return kx(Tx)}function Ax(){return kx(Ex)}function Mx(){var t=kx(Cx);return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t}const Nx={draw:function(t,e){var n=Math.sqrt(e/$_);t.moveTo(n,0),t.arc(0,0,n,0,V_)}},Dx={draw:function(t,e){var n=Math.sqrt(e/5)/2;t.moveTo(-3*n,-n),t.lineTo(-n,-n),t.lineTo(-n,-3*n),t.lineTo(n,-3*n),t.lineTo(n,-n),t.lineTo(3*n,-n),t.lineTo(3*n,n),t.lineTo(n,n),t.lineTo(n,3*n),t.lineTo(-n,3*n),t.lineTo(-n,n),t.lineTo(-3*n,n),t.closePath()}};var Ox=Math.sqrt(1/3),Bx=2*Ox;const Lx={draw:function(t,e){var n=Math.sqrt(e/Bx),r=n*Ox;t.moveTo(0,-n),t.lineTo(r,0),t.lineTo(0,n),t.lineTo(-r,0),t.closePath()}};var Ix=Math.sin($_/10)/Math.sin(7*$_/10),Rx=Math.sin(V_/10)*Ix,Fx=-Math.cos(V_/10)*Ix;const Px={draw:function(t,e){var n=Math.sqrt(.8908130915292852*e),r=Rx*n,i=Fx*n;t.moveTo(0,-n),t.lineTo(r,i);for(var a=1;a<5;++a){var o=V_*a/5,s=Math.cos(o),c=Math.sin(o);t.lineTo(c*n,-s*n),t.lineTo(s*r-c*i,c*r+s*i)}t.closePath()}},jx={draw:function(t,e){var n=Math.sqrt(e),r=-n/2;t.rect(r,r,n,n)}};var Yx=Math.sqrt(3);const zx={draw:function(t,e){var n=-Math.sqrt(e/(3*Yx));t.moveTo(0,2*n),t.lineTo(-Yx*n,-n),t.lineTo(Yx*n,-n),t.closePath()}};var Ux=-.5,qx=Math.sqrt(3)/2,Hx=1/Math.sqrt(12),$x=3*(Hx/2+1);const Wx={draw:function(t,e){var n=Math.sqrt(e/$x),r=n/2,i=n*Hx,a=r,o=n*Hx+n,s=-a,c=o;t.moveTo(r,i),t.lineTo(a,o),t.lineTo(s,c),t.lineTo(Ux*r-qx*i,qx*r+Ux*i),t.lineTo(Ux*a-qx*o,qx*a+Ux*o),t.lineTo(Ux*s-qx*c,qx*s+Ux*c),t.lineTo(Ux*r+qx*i,Ux*i-qx*r),t.lineTo(Ux*a+qx*o,Ux*o-qx*a),t.lineTo(Ux*s+qx*c,Ux*c-qx*s),t.closePath()}};var Vx=[Nx,Dx,Lx,jx,Px,zx,Wx];function Gx(){var t=R_(Nx),e=R_(64),n=null;function r(){var r;if(n||(n=r=$i()),t.apply(this,arguments).draw(n,+e.apply(this,arguments)),r)return n=null,r+""||null}return r.type=function(e){return arguments.length?(t="function"==typeof e?e:R_(e),r):t},r.size=function(t){return arguments.length?(e="function"==typeof t?t:R_(+t),r):e},r.context=function(t){return arguments.length?(n=null==t?null:t,r):n},r}function Xx(){}function Zx(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function Qx(t){this._context=t}function Kx(t){return new Qx(t)}function Jx(t){this._context=t}function tw(t){return new Jx(t)}function ew(t){this._context=t}function nw(t){return new ew(t)}function rw(t,e){this._basis=new Qx(t),this._beta=e}Qx.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:Zx(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:Zx(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},Jx.prototype={areaStart:Xx,areaEnd:Xx,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x2=t,this._y2=e;break;case 1:this._point=2,this._x3=t,this._y3=e;break;case 2:this._point=3,this._x4=t,this._y4=e,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+e)/6);break;default:Zx(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},ew.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+t)/6,r=(this._y0+4*this._y1+e)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:Zx(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}},rw.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,e=this._y,n=t.length-1;if(n>0)for(var r,i=t[0],a=e[0],o=t[n]-i,s=e[n]-a,c=-1;++c<=n;)r=c/n,this._basis.point(this._beta*t[c]+(1-this._beta)*(i+r*o),this._beta*e[c]+(1-this._beta)*(a+r*s));this._x=this._y=null,this._basis.lineEnd()},point:function(t,e){this._x.push(+t),this._y.push(+e)}};const iw=function t(e){function n(t){return 1===e?new Qx(t):new rw(t,e)}return n.beta=function(e){return t(+e)},n}(.85);function aw(t,e,n){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-e),t._y2+t._k*(t._y1-n),t._x2,t._y2)}function ow(t,e){this._context=t,this._k=(1-e)/6}ow.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:aw(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2,this._x1=t,this._y1=e;break;case 2:this._point=3;default:aw(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const sw=function t(e){function n(t){return new ow(t,e)}return n.tension=function(e){return t(+e)},n}(0);function cw(t,e){this._context=t,this._k=(1-e)/6}cw.prototype={areaStart:Xx,areaEnd:Xx,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:aw(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const uw=function t(e){function n(t){return new cw(t,e)}return n.tension=function(e){return t(+e)},n}(0);function lw(t,e){this._context=t,this._k=(1-e)/6}lw.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:aw(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const hw=function t(e){function n(t){return new lw(t,e)}return n.tension=function(e){return t(+e)},n}(0);function fw(t,e,n){var r=t._x1,i=t._y1,a=t._x2,o=t._y2;if(t._l01_a>H_){var s=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,c=3*t._l01_a*(t._l01_a+t._l12_a);r=(r*s-t._x0*t._l12_2a+t._x2*t._l01_2a)/c,i=(i*s-t._y0*t._l12_2a+t._y2*t._l01_2a)/c}if(t._l23_a>H_){var u=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,l=3*t._l23_a*(t._l23_a+t._l12_a);a=(a*u+t._x1*t._l23_2a-e*t._l12_2a)/l,o=(o*u+t._y1*t._l23_2a-n*t._l12_2a)/l}t._context.bezierCurveTo(r,i,a,o,t._x2,t._y2)}function dw(t,e){this._context=t,this._alpha=e}dw.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3;default:fw(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const pw=function t(e){function n(t){return e?new dw(t,e):new ow(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function yw(t,e){this._context=t,this._alpha=e}yw.prototype={areaStart:Xx,areaEnd:Xx,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:fw(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const gw=function t(e){function n(t){return e?new yw(t,e):new cw(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function mw(t,e){this._context=t,this._alpha=e}mw.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:fw(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const vw=function t(e){function n(t){return e?new mw(t,e):new lw(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function bw(t){this._context=t}function _w(t){return new bw(t)}function xw(t){return t<0?-1:1}function ww(t,e,n){var r=t._x1-t._x0,i=e-t._x1,a=(t._y1-t._y0)/(r||i<0&&-0),o=(n-t._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(xw(a)+xw(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function kw(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function Tw(t,e,n){var r=t._x0,i=t._y0,a=t._x1,o=t._y1,s=(a-r)/3;t._context.bezierCurveTo(r+s,i+s*e,a-s,o-s*n,a,o)}function Ew(t){this._context=t}function Cw(t){this._context=new Sw(t)}function Sw(t){this._context=t}function Aw(t){return new Ew(t)}function Mw(t){return new Cw(t)}function Nw(t){this._context=t}function Dw(t){var e,n,r=t.length-1,i=new Array(r),a=new Array(r),o=new Array(r);for(i[0]=0,a[0]=2,o[0]=t[0]+2*t[1],e=1;e=0;--e)i[e]=(o[e]-i[e+1])/a[e];for(a[r-1]=(t[r]+i[r-1])/2,e=0;e1)for(var n,r,i,a=1,o=t[e[0]],s=o.length;a=0;)n[e]=e;return n}function jw(t,e){return t[e]}function Yw(){var t=R_([]),e=Pw,n=Fw,r=jw;function i(i){var a,o,s=t.apply(this,arguments),c=i.length,u=s.length,l=new Array(u);for(a=0;a0){for(var n,r,i,a=0,o=t[0].length;a0)for(var n,r,i,a,o,s,c=0,u=t[e[0]].length;c0?(r[0]=a,r[1]=a+=i):i<0?(r[1]=o,r[0]=o+=i):(r[0]=0,r[1]=i)}function qw(t,e){if((n=t.length)>0){for(var n,r=0,i=t[e[0]],a=i.length;r0&&(r=(n=t[e[0]]).length)>0){for(var n,r,i,a=0,o=1;oa&&(a=e,r=n);return r}function Vw(t){var e=t.map(Gw);return Pw(t).sort((function(t,n){return e[t]-e[n]}))}function Gw(t){for(var e,n=0,r=-1,i=t.length;++r=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};var Kw="%Y-%m-%dT%H:%M:%S.%LZ";const Jw=Date.prototype.toISOString?function(t){return t.toISOString()}:sm(Kw),tk=+new Date("2000-01-01T00:00:00.000Z")?function(t){var e=new Date(t);return isNaN(e)?null:e}:cm(Kw);function ek(t,e,n){var r=new $n,i=e;return null==e?(r.restart(t,e,n),r):(e=+e,n=null==n?qn():+n,r.restart((function a(o){o+=i,r.restart(a,i+=e,n),t(o)}),e,n),r)}function nk(t){return function(){return t}}function rk(t){return t[0]}function ik(t){return t[1]}function ak(){this._=null}function ok(t){t.U=t.C=t.L=t.R=t.P=t.N=null}function sk(t,e){var n=e,r=e.R,i=n.U;i?i.L===n?i.L=r:i.R=r:t._=r,r.U=i,n.U=r,n.R=r.L,n.R&&(n.R.U=n),r.L=n}function ck(t,e){var n=e,r=e.L,i=n.U;i?i.L===n?i.L=r:i.R=r:t._=r,r.U=i,n.U=r,n.L=r.R,n.L&&(n.L.U=n),r.R=n}function uk(t){for(;t.L;)t=t.L;return t}ak.prototype={constructor:ak,insert:function(t,e){var n,r,i;if(t){if(e.P=t,e.N=t.N,t.N&&(t.N.P=e),t.N=e,t.R){for(t=t.R;t.L;)t=t.L;t.L=e}else t.R=e;n=t}else this._?(t=uk(this._),e.P=null,e.N=t,t.P=t.L=e,n=t):(e.P=e.N=null,this._=e,n=null);for(e.L=e.R=null,e.U=n,e.C=!0,t=e;n&&n.C;)n===(r=n.U).L?(i=r.R)&&i.C?(n.C=i.C=!1,r.C=!0,t=r):(t===n.R&&(sk(this,n),n=(t=n).U),n.C=!1,r.C=!0,ck(this,r)):(i=r.L)&&i.C?(n.C=i.C=!1,r.C=!0,t=r):(t===n.L&&(ck(this,n),n=(t=n).U),n.C=!1,r.C=!0,sk(this,r)),n=t.U;this._.C=!1},remove:function(t){t.N&&(t.N.P=t.P),t.P&&(t.P.N=t.N),t.N=t.P=null;var e,n,r,i=t.U,a=t.L,o=t.R;if(n=a?o?uk(o):a:o,i?i.L===t?i.L=n:i.R=n:this._=n,a&&o?(r=n.C,n.C=t.C,n.L=a,a.U=n,n!==o?(i=n.U,n.U=t.U,t=n.R,i.L=t,n.R=o,o.U=n):(n.U=i,i=n,t=n.R)):(r=t.C,t=n),t&&(t.U=i),!r)if(t&&t.C)t.C=!1;else{do{if(t===this._)break;if(t===i.L){if((e=i.R).C&&(e.C=!1,i.C=!0,sk(this,i),e=i.R),e.L&&e.L.C||e.R&&e.R.C){e.R&&e.R.C||(e.L.C=!1,e.C=!0,ck(this,e),e=i.R),e.C=i.C,i.C=e.R.C=!1,sk(this,i),t=this._;break}}else if((e=i.L).C&&(e.C=!1,i.C=!0,ck(this,i),e=i.L),e.L&&e.L.C||e.R&&e.R.C){e.L&&e.L.C||(e.R.C=!1,e.C=!0,sk(this,e),e=i.L),e.C=i.C,i.C=e.L.C=!1,ck(this,i),t=this._;break}e.C=!0,t=i,i=i.U}while(!t.C);t&&(t.C=!1)}}};const lk=ak;function hk(t,e,n,r){var i=[null,null],a=Ik.push(i)-1;return i.left=t,i.right=e,n&&dk(i,t,e,n),r&&dk(i,e,t,r),Bk[t.index].halfedges.push(a),Bk[e.index].halfedges.push(a),i}function fk(t,e,n){var r=[e,n];return r.left=t,r}function dk(t,e,n,r){t[0]||t[1]?t.left===n?t[1]=r:t[0]=r:(t[0]=r,t.left=e,t.right=n)}function pk(t,e,n,r,i){var a,o=t[0],s=t[1],c=o[0],u=o[1],l=0,h=1,f=s[0]-c,d=s[1]-u;if(a=e-c,f||!(a>0)){if(a/=f,f<0){if(a0){if(a>h)return;a>l&&(l=a)}if(a=r-c,f||!(a<0)){if(a/=f,f<0){if(a>h)return;a>l&&(l=a)}else if(f>0){if(a0)){if(a/=d,d<0){if(a0){if(a>h)return;a>l&&(l=a)}if(a=i-u,d||!(a<0)){if(a/=d,d<0){if(a>h)return;a>l&&(l=a)}else if(d>0){if(a0||h<1)||(l>0&&(t[0]=[c+l*f,u+l*d]),h<1&&(t[1]=[c+h*f,u+h*d]),!0)}}}}}function yk(t,e,n,r,i){var a=t[1];if(a)return!0;var o,s,c=t[0],u=t.left,l=t.right,h=u[0],f=u[1],d=l[0],p=l[1],y=(h+d)/2,g=(f+p)/2;if(p===f){if(y=r)return;if(h>d){if(c){if(c[1]>=i)return}else c=[y,n];a=[y,i]}else{if(c){if(c[1]1)if(h>d){if(c){if(c[1]>=i)return}else c=[(n-s)/o,n];a=[(i-s)/o,i]}else{if(c){if(c[1]=r)return}else c=[e,o*e+s];a=[r,o*r+s]}else{if(c){if(c[0]=-Fk)){var d=c*c+u*u,p=l*l+h*h,y=(h*d-u*p)/f,g=(c*p-l*d)/f,m=_k.pop()||new xk;m.arc=t,m.site=i,m.x=y+o,m.y=(m.cy=g+s)+Math.sqrt(y*y+g*g),t.circle=m;for(var v=null,b=Lk._;b;)if(m.yRk)s=s.L;else{if(!((i=a-Dk(s,o))>Rk)){r>-Rk?(e=s.P,n=s):i>-Rk?(e=s,n=s.N):e=n=s;break}if(!s.R){e=s;break}s=s.R}!function(t){Bk[t.index]={site:t,halfedges:[]}}(t);var c=Ck(t);if(Ok.insert(e,c),e||n){if(e===n)return kk(e),n=Ck(e.site),Ok.insert(c,n),c.edge=n.edge=hk(e.site,c.site),wk(e),void wk(n);if(n){kk(e),kk(n);var u=e.site,l=u[0],h=u[1],f=t[0]-l,d=t[1]-h,p=n.site,y=p[0]-l,g=p[1]-h,m=2*(f*g-d*y),v=f*f+d*d,b=y*y+g*g,_=[(g*v-d*b)/m+l,(f*b-y*v)/m+h];dk(n.edge,u,p,_),c.edge=hk(u,t,null,_),n.edge=hk(t,p,null,_),wk(e),wk(n)}else c.edge=hk(e.site,c.site)}}function Nk(t,e){var n=t.site,r=n[0],i=n[1],a=i-e;if(!a)return r;var o=t.P;if(!o)return-1/0;var s=(n=o.site)[0],c=n[1],u=c-e;if(!u)return s;var l=s-r,h=1/a-1/u,f=l/u;return h?(-f+Math.sqrt(f*f-2*h*(l*l/(-2*u)-c+u/2+i-a/2)))/h+r:(r+s)/2}function Dk(t,e){var n=t.N;if(n)return Nk(n,e);var r=t.site;return r[1]===e?r[0]:1/0}var Ok,Bk,Lk,Ik,Rk=1e-6,Fk=1e-12;function Pk(t,e,n){return(t[0]-n[0])*(e[1]-t[1])-(t[0]-e[0])*(n[1]-t[1])}function jk(t,e){return e[1]-t[1]||e[0]-t[0]}function Yk(t,e){var n,r,i,a=t.sort(jk).pop();for(Ik=[],Bk=new Array(t.length),Ok=new lk,Lk=new lk;;)if(i=bk,a&&(!i||a[1]Rk||Math.abs(i[0][1]-i[1][1])>Rk)||delete Ik[a]}(o,s,c,u),function(t,e,n,r){var i,a,o,s,c,u,l,h,f,d,p,y,g=Bk.length,m=!0;for(i=0;iRk||Math.abs(y-f)>Rk)&&(c.splice(s,0,Ik.push(fk(o,d,Math.abs(p-t)Rk?[t,Math.abs(h-t)Rk?[Math.abs(f-r)Rk?[n,Math.abs(h-n)Rk?[Math.abs(f-e)=s)return null;var c=t-i.site[0],u=e-i.site[1],l=c*c+u*u;do{i=a.cells[r=o],o=null,i.halfedges.forEach((function(n){var r=a.edges[n],s=r.left;if(s!==i.site&&s||(s=r.right)){var c=t-s[0],u=e-s[1],h=c*c+u*u;hr?(r+i)/2:Math.min(0,r)||Math.max(0,i),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function eT(){var t,e,n=Xk,r=Zk,i=tT,a=Kk,o=Jk,s=[0,1/0],c=[[-1/0,-1/0],[1/0,1/0]],u=250,l=Ep,h=ft("start","zoom","end"),f=500,d=0;function p(t){t.property("__zoom",Qk).on("wheel.zoom",x).on("mousedown.zoom",w).on("dblclick.zoom",k).filter(o).on("touchstart.zoom",T).on("touchmove.zoom",E).on("touchend.zoom touchcancel.zoom",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(t,e){return(e=Math.max(s[0],Math.min(s[1],e)))===t.k?t:new Hk(e,t.x,t.y)}function g(t,e,n){var r=e[0]-n[0]*t.k,i=e[1]-n[1]*t.k;return r===t.x&&i===t.y?t:new Hk(t.k,r,i)}function m(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function v(t,e,n){t.on("start.zoom",(function(){b(this,arguments).start()})).on("interrupt.zoom end.zoom",(function(){b(this,arguments).end()})).tween("zoom",(function(){var t=this,i=arguments,a=b(t,i),o=r.apply(t,i),s=null==n?m(o):"function"==typeof n?n.apply(t,i):n,c=Math.max(o[1][0]-o[0][0],o[1][1]-o[0][1]),u=t.__zoom,h="function"==typeof e?e.apply(t,i):e,f=l(u.invert(s).concat(c/u.k),h.invert(s).concat(c/h.k));return function(t){if(1===t)t=h;else{var e=f(t),n=c/e[2];t=new Hk(n,s[0]-e[0]*n,s[1]-e[1]*n)}a.zoom(null,t)}}))}function b(t,e,n){return!n&&t.__zooming||new _(t,e)}function _(t,e){this.that=t,this.args=e,this.active=0,this.extent=r.apply(t,e),this.taps=0}function x(){if(n.apply(this,arguments)){var t=b(this,arguments),e=this.__zoom,r=Math.max(s[0],Math.min(s[1],e.k*Math.pow(2,a.apply(this,arguments)))),o=On(this);if(t.wheel)t.mouse[0][0]===o[0]&&t.mouse[0][1]===o[1]||(t.mouse[1]=e.invert(t.mouse[0]=o)),clearTimeout(t.wheel);else{if(e.k===r)return;t.mouse=[o,e.invert(o)],ir(this),t.start()}Gk(),t.wheel=setTimeout(u,150),t.zoom("mouse",i(g(y(e,r),t.mouse[0],t.mouse[1]),t.extent,c))}function u(){t.wheel=null,t.end()}}function w(){if(!e&&n.apply(this,arguments)){var t=b(this,arguments,!0),r=Te(le.view).on("mousemove.zoom",u,!0).on("mouseup.zoom",l,!0),a=On(this),o=le.clientX,s=le.clientY;Se(le.view),Vk(),t.mouse=[a,this.__zoom.invert(a)],ir(this),t.start()}function u(){if(Gk(),!t.moved){var e=le.clientX-o,n=le.clientY-s;t.moved=e*e+n*n>d}t.zoom("mouse",i(g(t.that.__zoom,t.mouse[0]=On(t.that),t.mouse[1]),t.extent,c))}function l(){r.on("mousemove.zoom mouseup.zoom",null),Ae(le.view,t.moved),Gk(),t.end()}}function k(){if(n.apply(this,arguments)){var t=this.__zoom,e=On(this),a=t.invert(e),o=t.k*(le.shiftKey?.5:2),s=i(g(y(t,o),e,a),r.apply(this,arguments),c);Gk(),u>0?Te(this).transition().duration(u).call(v,s,e):Te(this).call(p.transform,s)}}function T(){if(n.apply(this,arguments)){var e,r,i,a,o=le.touches,s=o.length,c=b(this,arguments,le.changedTouches.length===s);for(Vk(),r=0;r{t.exports={graphlib:n(574),layout:n(8123),debug:n(7570),util:{time:n(1138).time,notime:n(1138).notime},version:n(8177)}},1207:(t,e,n)=>{"use strict";var r=n(8436),i=n(4079);t.exports={run:function(t){var e="greedy"===t.graph().acyclicer?i(t,function(t){return function(e){return t.edge(e).weight}}(t)):function(t){var e=[],n={},i={};return r.forEach(t.nodes(),(function a(o){r.has(i,o)||(i[o]=!0,n[o]=!0,r.forEach(t.outEdges(o),(function(t){r.has(n,t.w)?e.push(t):a(t.w)})),delete n[o])})),e}(t);r.forEach(e,(function(e){var n=t.edge(e);t.removeEdge(e),n.forwardName=e.name,n.reversed=!0,t.setEdge(e.w,e.v,n,r.uniqueId("rev"))}))},undo:function(t){r.forEach(t.edges(),(function(e){var n=t.edge(e);if(n.reversed){t.removeEdge(e);var r=n.forwardName;delete n.reversed,delete n.forwardName,t.setEdge(e.w,e.v,n,r)}}))}}},1133:(t,e,n)=>{var r=n(8436),i=n(1138);function a(t,e,n,r,a,o){var s={width:0,height:0,rank:o,borderType:e},c=a[e][o-1],u=i.addDummyNode(t,"border",s,n);a[e][o]=u,t.setParent(u,r),c&&t.setEdge(c,u,{weight:1})}t.exports=function(t){r.forEach(t.children(),(function e(n){var i=t.children(n),o=t.node(n);if(i.length&&r.forEach(i,e),r.has(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(var s=o.minRank,c=o.maxRank+1;s{"use strict";var r=n(8436);function i(t){r.forEach(t.nodes(),(function(e){a(t.node(e))})),r.forEach(t.edges(),(function(e){a(t.edge(e))}))}function a(t){var e=t.width;t.width=t.height,t.height=e}function o(t){t.y=-t.y}function s(t){var e=t.x;t.x=t.y,t.y=e}t.exports={adjust:function(t){var e=t.graph().rankdir.toLowerCase();"lr"!==e&&"rl"!==e||i(t)},undo:function(t){var e=t.graph().rankdir.toLowerCase();"bt"!==e&&"rl"!==e||function(t){r.forEach(t.nodes(),(function(e){o(t.node(e))})),r.forEach(t.edges(),(function(e){var n=t.edge(e);r.forEach(n.points,o),r.has(n,"y")&&o(n)}))}(t),"lr"!==e&&"rl"!==e||(function(t){r.forEach(t.nodes(),(function(e){s(t.node(e))})),r.forEach(t.edges(),(function(e){var n=t.edge(e);r.forEach(n.points,s),r.has(n,"x")&&s(n)}))}(t),i(t))}}},7822:t=>{function e(){var t={};t._next=t._prev=t,this._sentinel=t}function n(t){t._prev._next=t._next,t._next._prev=t._prev,delete t._next,delete t._prev}function r(t,e){if("_next"!==t&&"_prev"!==t)return e}t.exports=e,e.prototype.dequeue=function(){var t=this._sentinel,e=t._prev;if(e!==t)return n(e),e},e.prototype.enqueue=function(t){var e=this._sentinel;t._prev&&t._next&&n(t),t._next=e._next,e._next._prev=t,e._next=t,t._prev=e},e.prototype.toString=function(){for(var t=[],e=this._sentinel,n=e._prev;n!==e;)t.push(JSON.stringify(n,r)),n=n._prev;return"["+t.join(", ")+"]"}},7570:(t,e,n)=>{var r=n(8436),i=n(1138),a=n(574).Graph;t.exports={debugOrdering:function(t){var e=i.buildLayerMatrix(t),n=new a({compound:!0,multigraph:!0}).setGraph({});return r.forEach(t.nodes(),(function(e){n.setNode(e,{label:e}),n.setParent(e,"layer"+t.node(e).rank)})),r.forEach(t.edges(),(function(t){n.setEdge(t.v,t.w,{},t.name)})),r.forEach(e,(function(t,e){var i="layer"+e;n.setNode(i,{rank:"same"}),r.reduce(t,(function(t,e){return n.setEdge(t,e,{style:"invis"}),e}))})),n}}},574:(t,e,n)=>{var r;try{r=n(8282)}catch(t){}r||(r=window.graphlib),t.exports=r},4079:(t,e,n)=>{var r=n(8436),i=n(574).Graph,a=n(7822);t.exports=function(t,e){if(t.nodeCount()<=1)return[];var n=function(t,e){var n=new i,o=0,s=0;r.forEach(t.nodes(),(function(t){n.setNode(t,{v:t,in:0,out:0})})),r.forEach(t.edges(),(function(t){var r=n.edge(t.v,t.w)||0,i=e(t),a=r+i;n.setEdge(t.v,t.w,a),s=Math.max(s,n.node(t.v).out+=i),o=Math.max(o,n.node(t.w).in+=i)}));var u=r.range(s+o+3).map((function(){return new a})),l=o+1;return r.forEach(n.nodes(),(function(t){c(u,l,n.node(t))})),{graph:n,buckets:u,zeroIdx:l}}(t,e||o),u=function(t,e,n){for(var r,i=[],a=e[e.length-1],o=e[0];t.nodeCount();){for(;r=o.dequeue();)s(t,e,n,r);for(;r=a.dequeue();)s(t,e,n,r);if(t.nodeCount())for(var c=e.length-2;c>0;--c)if(r=e[c].dequeue()){i=i.concat(s(t,e,n,r,!0));break}}return i}(n.graph,n.buckets,n.zeroIdx);return r.flatten(r.map(u,(function(e){return t.outEdges(e.v,e.w)})),!0)};var o=r.constant(1);function s(t,e,n,i,a){var o=a?[]:void 0;return r.forEach(t.inEdges(i.v),(function(r){var i=t.edge(r),s=t.node(r.v);a&&o.push({v:r.v,w:r.w}),s.out-=i,c(e,n,s)})),r.forEach(t.outEdges(i.v),(function(r){var i=t.edge(r),a=r.w,o=t.node(a);o.in-=i,c(e,n,o)})),t.removeNode(i.v),o}function c(t,e,n){n.out?n.in?t[n.out-n.in+e].enqueue(n):t[t.length-1].enqueue(n):t[0].enqueue(n)}},8123:(t,e,n)=>{"use strict";var r=n(8436),i=n(1207),a=n(5995),o=n(8093),s=n(1138).normalizeRanks,c=n(4219),u=n(1138).removeEmptyRanks,l=n(2981),h=n(1133),f=n(3258),d=n(3408),p=n(7873),y=n(1138),g=n(574).Graph;t.exports=function(t,e){var n=e&&e.debugTiming?y.time:y.notime;n("layout",(function(){var e=n(" buildLayoutGraph",(function(){return function(t){var e=new g({multigraph:!0,compound:!0}),n=C(t.graph());return e.setGraph(r.merge({},v,E(n,m),r.pick(n,b))),r.forEach(t.nodes(),(function(n){var i=C(t.node(n));e.setNode(n,r.defaults(E(i,_),x)),e.setParent(n,t.parent(n))})),r.forEach(t.edges(),(function(n){var i=C(t.edge(n));e.setEdge(n,r.merge({},k,E(i,w),r.pick(i,T)))})),e}(t)}));n(" runLayout",(function(){!function(t,e){e(" makeSpaceForEdgeLabels",(function(){!function(t){var e=t.graph();e.ranksep/=2,r.forEach(t.edges(),(function(n){var r=t.edge(n);r.minlen*=2,"c"!==r.labelpos.toLowerCase()&&("TB"===e.rankdir||"BT"===e.rankdir?r.width+=r.labeloffset:r.height+=r.labeloffset)}))}(t)})),e(" removeSelfEdges",(function(){!function(t){r.forEach(t.edges(),(function(e){if(e.v===e.w){var n=t.node(e.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:e,label:t.edge(e)}),t.removeEdge(e)}}))}(t)})),e(" acyclic",(function(){i.run(t)})),e(" nestingGraph.run",(function(){l.run(t)})),e(" rank",(function(){o(y.asNonCompoundGraph(t))})),e(" injectEdgeLabelProxies",(function(){!function(t){r.forEach(t.edges(),(function(e){var n=t.edge(e);if(n.width&&n.height){var r=t.node(e.v),i={rank:(t.node(e.w).rank-r.rank)/2+r.rank,e:e};y.addDummyNode(t,"edge-proxy",i,"_ep")}}))}(t)})),e(" removeEmptyRanks",(function(){u(t)})),e(" nestingGraph.cleanup",(function(){l.cleanup(t)})),e(" normalizeRanks",(function(){s(t)})),e(" assignRankMinMax",(function(){!function(t){var e=0;r.forEach(t.nodes(),(function(n){var i=t.node(n);i.borderTop&&(i.minRank=t.node(i.borderTop).rank,i.maxRank=t.node(i.borderBottom).rank,e=r.max(e,i.maxRank))})),t.graph().maxRank=e}(t)})),e(" removeEdgeLabelProxies",(function(){!function(t){r.forEach(t.nodes(),(function(e){var n=t.node(e);"edge-proxy"===n.dummy&&(t.edge(n.e).labelRank=n.rank,t.removeNode(e))}))}(t)})),e(" normalize.run",(function(){a.run(t)})),e(" parentDummyChains",(function(){c(t)})),e(" addBorderSegments",(function(){h(t)})),e(" order",(function(){d(t)})),e(" insertSelfEdges",(function(){!function(t){var e=y.buildLayerMatrix(t);r.forEach(e,(function(e){var n=0;r.forEach(e,(function(e,i){var a=t.node(e);a.order=i+n,r.forEach(a.selfEdges,(function(e){y.addDummyNode(t,"selfedge",{width:e.label.width,height:e.label.height,rank:a.rank,order:i+ ++n,e:e.e,label:e.label},"_se")})),delete a.selfEdges}))}))}(t)})),e(" adjustCoordinateSystem",(function(){f.adjust(t)})),e(" position",(function(){p(t)})),e(" positionSelfEdges",(function(){!function(t){r.forEach(t.nodes(),(function(e){var n=t.node(e);if("selfedge"===n.dummy){var r=t.node(n.e.v),i=r.x+r.width/2,a=r.y,o=n.x-i,s=r.height/2;t.setEdge(n.e,n.label),t.removeNode(e),n.label.points=[{x:i+2*o/3,y:a-s},{x:i+5*o/6,y:a-s},{x:i+o,y:a},{x:i+5*o/6,y:a+s},{x:i+2*o/3,y:a+s}],n.label.x=n.x,n.label.y=n.y}}))}(t)})),e(" removeBorderNodes",(function(){!function(t){r.forEach(t.nodes(),(function(e){if(t.children(e).length){var n=t.node(e),i=t.node(n.borderTop),a=t.node(n.borderBottom),o=t.node(r.last(n.borderLeft)),s=t.node(r.last(n.borderRight));n.width=Math.abs(s.x-o.x),n.height=Math.abs(a.y-i.y),n.x=o.x+n.width/2,n.y=i.y+n.height/2}})),r.forEach(t.nodes(),(function(e){"border"===t.node(e).dummy&&t.removeNode(e)}))}(t)})),e(" normalize.undo",(function(){a.undo(t)})),e(" fixupEdgeLabelCoords",(function(){!function(t){r.forEach(t.edges(),(function(e){var n=t.edge(e);if(r.has(n,"x"))switch("l"!==n.labelpos&&"r"!==n.labelpos||(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset}}))}(t)})),e(" undoCoordinateSystem",(function(){f.undo(t)})),e(" translateGraph",(function(){!function(t){var e=Number.POSITIVE_INFINITY,n=0,i=Number.POSITIVE_INFINITY,a=0,o=t.graph(),s=o.marginx||0,c=o.marginy||0;function u(t){var r=t.x,o=t.y,s=t.width,c=t.height;e=Math.min(e,r-s/2),n=Math.max(n,r+s/2),i=Math.min(i,o-c/2),a=Math.max(a,o+c/2)}r.forEach(t.nodes(),(function(e){u(t.node(e))})),r.forEach(t.edges(),(function(e){var n=t.edge(e);r.has(n,"x")&&u(n)})),e-=s,i-=c,r.forEach(t.nodes(),(function(n){var r=t.node(n);r.x-=e,r.y-=i})),r.forEach(t.edges(),(function(n){var a=t.edge(n);r.forEach(a.points,(function(t){t.x-=e,t.y-=i})),r.has(a,"x")&&(a.x-=e),r.has(a,"y")&&(a.y-=i)})),o.width=n-e+s,o.height=a-i+c}(t)})),e(" assignNodeIntersects",(function(){!function(t){r.forEach(t.edges(),(function(e){var n,r,i=t.edge(e),a=t.node(e.v),o=t.node(e.w);i.points?(n=i.points[0],r=i.points[i.points.length-1]):(i.points=[],n=o,r=a),i.points.unshift(y.intersectRect(a,n)),i.points.push(y.intersectRect(o,r))}))}(t)})),e(" reversePoints",(function(){!function(t){r.forEach(t.edges(),(function(e){var n=t.edge(e);n.reversed&&n.points.reverse()}))}(t)})),e(" acyclic.undo",(function(){i.undo(t)}))}(e,n)})),n(" updateInputGraph",(function(){!function(t,e){r.forEach(t.nodes(),(function(n){var r=t.node(n),i=e.node(n);r&&(r.x=i.x,r.y=i.y,e.children(n).length&&(r.width=i.width,r.height=i.height))})),r.forEach(t.edges(),(function(n){var i=t.edge(n),a=e.edge(n);i.points=a.points,r.has(a,"x")&&(i.x=a.x,i.y=a.y)})),t.graph().width=e.graph().width,t.graph().height=e.graph().height}(t,e)}))}))};var m=["nodesep","edgesep","ranksep","marginx","marginy"],v={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},b=["acyclicer","ranker","rankdir","align"],_=["width","height"],x={width:0,height:0},w=["minlen","weight","width","height","labeloffset"],k={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},T=["labelpos"];function E(t,e){return r.mapValues(r.pick(t,e),Number)}function C(t){var e={};return r.forEach(t,(function(t,n){e[n.toLowerCase()]=t})),e}},8436:(t,e,n)=>{var r;try{r={cloneDeep:n(361),constant:n(5703),defaults:n(1747),each:n(6073),filter:n(3105),find:n(3311),flatten:n(5564),forEach:n(4486),forIn:n(2620),has:n(8721),isUndefined:n(2353),last:n(928),map:n(5161),mapValues:n(6604),max:n(6162),merge:n(3857),min:n(3632),minBy:n(2762),now:n(7771),pick:n(9722),range:n(6026),reduce:n(4061),sortBy:n(9734),uniqueId:n(3955),values:n(2628),zipObject:n(7287)}}catch(t){}r||(r=window._),t.exports=r},2981:(t,e,n)=>{var r=n(8436),i=n(1138);function a(t,e,n,o,s,c,u){var l=t.children(u);if(l.length){var h=i.addBorderNode(t,"_bt"),f=i.addBorderNode(t,"_bb"),d=t.node(u);t.setParent(h,u),d.borderTop=h,t.setParent(f,u),d.borderBottom=f,r.forEach(l,(function(r){a(t,e,n,o,s,c,r);var i=t.node(r),l=i.borderTop?i.borderTop:r,d=i.borderBottom?i.borderBottom:r,p=i.borderTop?o:2*o,y=l!==d?1:s-c[u]+1;t.setEdge(h,l,{weight:p,minlen:y,nestingEdge:!0}),t.setEdge(d,f,{weight:p,minlen:y,nestingEdge:!0})})),t.parent(u)||t.setEdge(e,h,{weight:0,minlen:s+c[u]})}else u!==e&&t.setEdge(e,u,{weight:0,minlen:n})}t.exports={run:function(t){var e=i.addDummyNode(t,"root",{},"_root"),n=function(t){var e={};function n(i,a){var o=t.children(i);o&&o.length&&r.forEach(o,(function(t){n(t,a+1)})),e[i]=a}return r.forEach(t.children(),(function(t){n(t,1)})),e}(t),o=r.max(r.values(n))-1,s=2*o+1;t.graph().nestingRoot=e,r.forEach(t.edges(),(function(e){t.edge(e).minlen*=s}));var c=function(t){return r.reduce(t.edges(),(function(e,n){return e+t.edge(n).weight}),0)}(t)+1;r.forEach(t.children(),(function(r){a(t,e,s,c,o,n,r)})),t.graph().nodeRankFactor=s},cleanup:function(t){var e=t.graph();t.removeNode(e.nestingRoot),delete e.nestingRoot,r.forEach(t.edges(),(function(e){t.edge(e).nestingEdge&&t.removeEdge(e)}))}}},5995:(t,e,n)=>{"use strict";var r=n(8436),i=n(1138);t.exports={run:function(t){t.graph().dummyChains=[],r.forEach(t.edges(),(function(e){!function(t,e){var n,r,a,o=e.v,s=t.node(o).rank,c=e.w,u=t.node(c).rank,l=e.name,h=t.edge(e),f=h.labelRank;if(u!==s+1){for(t.removeEdge(e),a=0,++s;s{var r=n(8436);t.exports=function(t,e,n){var i,a={};r.forEach(n,(function(n){for(var r,o,s=t.parent(n);s;){if((r=t.parent(s))?(o=a[r],a[r]=s):(o=i,i=s),o&&o!==s)return void e.setEdge(o,s);s=r}}))}},5439:(t,e,n)=>{var r=n(8436);t.exports=function(t,e){return r.map(e,(function(e){var n=t.inEdges(e);if(n.length){var i=r.reduce(n,(function(e,n){var r=t.edge(n),i=t.node(n.v);return{sum:e.sum+r.weight*i.order,weight:e.weight+r.weight}}),{sum:0,weight:0});return{v:e,barycenter:i.sum/i.weight,weight:i.weight}}return{v:e}}))}},3128:(t,e,n)=>{var r=n(8436),i=n(574).Graph;t.exports=function(t,e,n){var a=function(t){for(var e;t.hasNode(e=r.uniqueId("_root")););return e}(t),o=new i({compound:!0}).setGraph({root:a}).setDefaultNodeLabel((function(e){return t.node(e)}));return r.forEach(t.nodes(),(function(i){var s=t.node(i),c=t.parent(i);(s.rank===e||s.minRank<=e&&e<=s.maxRank)&&(o.setNode(i),o.setParent(i,c||a),r.forEach(t[n](i),(function(e){var n=e.v===i?e.w:e.v,a=o.edge(n,i),s=r.isUndefined(a)?0:a.weight;o.setEdge(n,i,{weight:t.edge(e).weight+s})})),r.has(s,"minRank")&&o.setNode(i,{borderLeft:s.borderLeft[e],borderRight:s.borderRight[e]}))})),o}},6630:(t,e,n)=>{"use strict";var r=n(8436);function i(t,e,n){for(var i=r.zipObject(n,r.map(n,(function(t,e){return e}))),a=r.flatten(r.map(e,(function(e){return r.sortBy(r.map(t.outEdges(e),(function(e){return{pos:i[e.w],weight:t.edge(e).weight}})),"pos")})),!0),o=1;o0;)e%2&&(n+=c[e+1]),c[e=e-1>>1]+=t.weight;u+=t.weight*n}))),u}t.exports=function(t,e){for(var n=0,r=1;r{"use strict";var r=n(8436),i=n(2588),a=n(6630),o=n(1026),s=n(3128),c=n(5093),u=n(574).Graph,l=n(1138);function h(t,e,n){return r.map(e,(function(e){return s(t,e,n)}))}function f(t,e){var n=new u;r.forEach(t,(function(t){var i=t.graph().root,a=o(t,i,n,e);r.forEach(a.vs,(function(e,n){t.node(e).order=n})),c(t,n,a.vs)}))}function d(t,e){r.forEach(e,(function(e){r.forEach(e,(function(e,n){t.node(e).order=n}))}))}t.exports=function(t){var e=l.maxRank(t),n=h(t,r.range(1,e+1),"inEdges"),o=h(t,r.range(e-1,-1,-1),"outEdges"),s=i(t);d(t,s);for(var c,u=Number.POSITIVE_INFINITY,p=0,y=0;y<4;++p,++y){f(p%2?n:o,p%4>=2),s=l.buildLayerMatrix(t);var g=a(t,s);g{"use strict";var r=n(8436);t.exports=function(t){var e={},n=r.filter(t.nodes(),(function(e){return!t.children(e).length})),i=r.max(r.map(n,(function(e){return t.node(e).rank}))),a=r.map(r.range(i+1),(function(){return[]})),o=r.sortBy(n,(function(e){return t.node(e).rank}));return r.forEach(o,(function n(i){if(!r.has(e,i)){e[i]=!0;var o=t.node(i);a[o.rank].push(i),r.forEach(t.successors(i),n)}})),a}},9567:(t,e,n)=>{"use strict";var r=n(8436);t.exports=function(t,e){var n={};return r.forEach(t,(function(t,e){var i=n[t.v]={indegree:0,in:[],out:[],vs:[t.v],i:e};r.isUndefined(t.barycenter)||(i.barycenter=t.barycenter,i.weight=t.weight)})),r.forEach(e.edges(),(function(t){var e=n[t.v],i=n[t.w];r.isUndefined(e)||r.isUndefined(i)||(i.indegree++,e.out.push(n[t.w]))})),function(t){var e=[];function n(t){return function(e){var n,i,a,o;e.merged||(r.isUndefined(e.barycenter)||r.isUndefined(t.barycenter)||e.barycenter>=t.barycenter)&&(i=e,a=0,o=0,(n=t).weight&&(a+=n.barycenter*n.weight,o+=n.weight),i.weight&&(a+=i.barycenter*i.weight,o+=i.weight),n.vs=i.vs.concat(n.vs),n.barycenter=a/o,n.weight=o,n.i=Math.min(i.i,n.i),i.merged=!0)}}function i(e){return function(n){n.in.push(e),0==--n.indegree&&t.push(n)}}for(;t.length;){var a=t.pop();e.push(a),r.forEach(a.in.reverse(),n(a)),r.forEach(a.out,i(a))}return r.map(r.filter(e,(function(t){return!t.merged})),(function(t){return r.pick(t,["vs","i","barycenter","weight"])}))}(r.filter(n,(function(t){return!t.indegree})))}},1026:(t,e,n)=>{var r=n(8436),i=n(5439),a=n(9567),o=n(7304);t.exports=function t(e,n,s,c){var u=e.children(n),l=e.node(n),h=l?l.borderLeft:void 0,f=l?l.borderRight:void 0,d={};h&&(u=r.filter(u,(function(t){return t!==h&&t!==f})));var p=i(e,u);r.forEach(p,(function(n){if(e.children(n.v).length){var i=t(e,n.v,s,c);d[n.v]=i,r.has(i,"barycenter")&&(a=n,o=i,r.isUndefined(a.barycenter)?(a.barycenter=o.barycenter,a.weight=o.weight):(a.barycenter=(a.barycenter*a.weight+o.barycenter*o.weight)/(a.weight+o.weight),a.weight+=o.weight))}var a,o}));var y=a(p,s);!function(t,e){r.forEach(t,(function(t){t.vs=r.flatten(t.vs.map((function(t){return e[t]?e[t].vs:t})),!0)}))}(y,d);var g=o(y,c);if(h&&(g.vs=r.flatten([h,g.vs,f],!0),e.predecessors(h).length)){var m=e.node(e.predecessors(h)[0]),v=e.node(e.predecessors(f)[0]);r.has(g,"barycenter")||(g.barycenter=0,g.weight=0),g.barycenter=(g.barycenter*g.weight+m.order+v.order)/(g.weight+2),g.weight+=2}return g}},7304:(t,e,n)=>{var r=n(8436),i=n(1138);function a(t,e,n){for(var i;e.length&&(i=r.last(e)).i<=n;)e.pop(),t.push(i.vs),n++;return n}t.exports=function(t,e){var n,o=i.partition(t,(function(t){return r.has(t,"barycenter")})),s=o.lhs,c=r.sortBy(o.rhs,(function(t){return-t.i})),u=[],l=0,h=0,f=0;s.sort((n=!!e,function(t,e){return t.barycentere.barycenter?1:n?e.i-t.i:t.i-e.i})),f=a(u,c,f),r.forEach(s,(function(t){f+=t.vs.length,u.push(t.vs),l+=t.barycenter*t.weight,h+=t.weight,f=a(u,c,f)}));var d={vs:r.flatten(u,!0)};return h&&(d.barycenter=l/h,d.weight=h),d}},4219:(t,e,n)=>{var r=n(8436);t.exports=function(t){var e=function(t){var e={},n=0;return r.forEach(t.children(),(function i(a){var o=n;r.forEach(t.children(a),i),e[a]={low:o,lim:n++}})),e}(t);r.forEach(t.graph().dummyChains,(function(n){for(var r=t.node(n),i=r.edgeObj,a=function(t,e,n,r){var i,a,o=[],s=[],c=Math.min(e[n].low,e[r].low),u=Math.max(e[n].lim,e[r].lim);i=n;do{i=t.parent(i),o.push(i)}while(i&&(e[i].low>c||u>e[i].lim));for(a=i,i=r;(i=t.parent(i))!==a;)s.push(i);return{path:o.concat(s.reverse()),lca:a}}(t,e,i.v,i.w),o=a.path,s=a.lca,c=0,u=o[c],l=!0;n!==i.w;){if(r=t.node(n),l){for(;(u=o[c])!==s&&t.node(u).maxRank{"use strict";var r=n(8436),i=n(574).Graph,a=n(1138);function o(t,e){var n={};return r.reduce(e,(function(e,i){var a=0,o=0,s=e.length,u=r.last(i);return r.forEach(i,(function(e,l){var h=function(t,e){if(t.node(e).dummy)return r.find(t.predecessors(e),(function(e){return t.node(e).dummy}))}(t,e),f=h?t.node(h).order:s;(h||e===u)&&(r.forEach(i.slice(o,l+1),(function(e){r.forEach(t.predecessors(e),(function(r){var i=t.node(r),o=i.order;!(os)&&c(n,e,u)}))}))}return r.reduce(e,(function(e,n){var a,o=-1,s=0;return r.forEach(n,(function(r,c){if("border"===t.node(r).dummy){var u=t.predecessors(r);u.length&&(a=t.node(u[0]).order,i(n,s,c,o,a),s=c,o=a)}i(n,s,n.length,a,e.length)})),n})),n}function c(t,e,n){if(e>n){var r=e;e=n,n=r}var i=t[e];i||(t[e]=i={}),i[n]=!0}function u(t,e,n){if(e>n){var i=e;e=n,n=i}return r.has(t[e],n)}function l(t,e,n,i){var a={},o={},s={};return r.forEach(e,(function(t){r.forEach(t,(function(t,e){a[t]=t,o[t]=t,s[t]=e}))})),r.forEach(e,(function(t){var e=-1;r.forEach(t,(function(t){var c=i(t);if(c.length)for(var l=((c=r.sortBy(c,(function(t){return s[t]}))).length-1)/2,h=Math.floor(l),f=Math.ceil(l);h<=f;++h){var d=c[h];o[t]===t&&e{"use strict";var r=n(8436),i=n(1138),a=n(3573).positionX;t.exports=function(t){(function(t){var e=i.buildLayerMatrix(t),n=t.graph().ranksep,a=0;r.forEach(e,(function(e){var i=r.max(r.map(e,(function(e){return t.node(e).height})));r.forEach(e,(function(e){t.node(e).y=a+i/2})),a+=i+n}))})(t=i.asNonCompoundGraph(t)),r.forEach(a(t),(function(e,n){t.node(n).x=e}))}},300:(t,e,n)=>{"use strict";var r=n(8436),i=n(574).Graph,a=n(6681).slack;function o(t,e){return r.forEach(t.nodes(),(function n(i){r.forEach(e.nodeEdges(i),(function(r){var o=r.v,s=i===o?r.w:o;t.hasNode(s)||a(e,r)||(t.setNode(s,{}),t.setEdge(i,s,{}),n(s))}))})),t.nodeCount()}function s(t,e){return r.minBy(e.edges(),(function(n){if(t.hasNode(n.v)!==t.hasNode(n.w))return a(e,n)}))}function c(t,e,n){r.forEach(t.nodes(),(function(t){e.node(t).rank+=n}))}t.exports=function(t){var e,n,r=new i({directed:!1}),u=t.nodes()[0],l=t.nodeCount();for(r.setNode(u,{});o(r,t){"use strict";var r=n(6681).longestPath,i=n(300),a=n(2472);t.exports=function(t){switch(t.graph().ranker){case"network-simplex":default:!function(t){a(t)}(t);break;case"tight-tree":!function(t){r(t),i(t)}(t);break;case"longest-path":o(t)}};var o=r},2472:(t,e,n)=>{"use strict";var r=n(8436),i=n(300),a=n(6681).slack,o=n(6681).longestPath,s=n(574).alg.preorder,c=n(574).alg.postorder,u=n(1138).simplify;function l(t){t=u(t),o(t);var e,n=i(t);for(d(n),h(n,t);e=y(n);)m(n,t,e,g(n,t,e))}function h(t,e){var n=c(t,t.nodes());n=n.slice(0,n.length-1),r.forEach(n,(function(n){!function(t,e,n){var r=t.node(n).parent;t.edge(n,r).cutvalue=f(t,e,n)}(t,e,n)}))}function f(t,e,n){var i=t.node(n).parent,a=!0,o=e.edge(n,i),s=0;return o||(a=!1,o=e.edge(i,n)),s=o.weight,r.forEach(e.nodeEdges(n),(function(r){var o,c,u=r.v===n,l=u?r.w:r.v;if(l!==i){var h=u===a,f=e.edge(r).weight;if(s+=h?f:-f,o=n,c=l,t.hasEdge(o,c)){var d=t.edge(n,l).cutvalue;s+=h?-d:d}}})),s}function d(t,e){arguments.length<2&&(e=t.nodes()[0]),p(t,{},1,e)}function p(t,e,n,i,a){var o=n,s=t.node(i);return e[i]=!0,r.forEach(t.neighbors(i),(function(a){r.has(e,a)||(n=p(t,e,n,a,i))})),s.low=o,s.lim=n++,a?s.parent=a:delete s.parent,n}function y(t){return r.find(t.edges(),(function(e){return t.edge(e).cutvalue<0}))}function g(t,e,n){var i=n.v,o=n.w;e.hasEdge(i,o)||(i=n.w,o=n.v);var s=t.node(i),c=t.node(o),u=s,l=!1;s.lim>c.lim&&(u=c,l=!0);var h=r.filter(e.edges(),(function(e){return l===v(0,t.node(e.v),u)&&l!==v(0,t.node(e.w),u)}));return r.minBy(h,(function(t){return a(e,t)}))}function m(t,e,n,i){var a=n.v,o=n.w;t.removeEdge(a,o),t.setEdge(i.v,i.w,{}),d(t),h(t,e),function(t,e){var n=r.find(t.nodes(),(function(t){return!e.node(t).parent})),i=s(t,n);i=i.slice(1),r.forEach(i,(function(n){var r=t.node(n).parent,i=e.edge(n,r),a=!1;i||(i=e.edge(r,n),a=!0),e.node(n).rank=e.node(r).rank+(a?i.minlen:-i.minlen)}))}(t,e)}function v(t,e,n){return n.low<=e.lim&&e.lim<=n.lim}t.exports=l,l.initLowLimValues=d,l.initCutValues=h,l.calcCutValue=f,l.leaveEdge=y,l.enterEdge=g,l.exchangeEdges=m},6681:(t,e,n)=>{"use strict";var r=n(8436);t.exports={longestPath:function(t){var e={};r.forEach(t.sources(),(function n(i){var a=t.node(i);if(r.has(e,i))return a.rank;e[i]=!0;var o=r.min(r.map(t.outEdges(i),(function(e){return n(e.w)-t.edge(e).minlen})));return o!==Number.POSITIVE_INFINITY&&null!=o||(o=0),a.rank=o}))},slack:function(t,e){return t.node(e.w).rank-t.node(e.v).rank-t.edge(e).minlen}}},1138:(t,e,n)=>{"use strict";var r=n(8436),i=n(574).Graph;function a(t,e,n,i){var a;do{a=r.uniqueId(i)}while(t.hasNode(a));return n.dummy=e,t.setNode(a,n),a}function o(t){return r.max(r.map(t.nodes(),(function(e){var n=t.node(e).rank;if(!r.isUndefined(n))return n})))}t.exports={addDummyNode:a,simplify:function(t){var e=(new i).setGraph(t.graph());return r.forEach(t.nodes(),(function(n){e.setNode(n,t.node(n))})),r.forEach(t.edges(),(function(n){var r=e.edge(n.v,n.w)||{weight:0,minlen:1},i=t.edge(n);e.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})})),e},asNonCompoundGraph:function(t){var e=new i({multigraph:t.isMultigraph()}).setGraph(t.graph());return r.forEach(t.nodes(),(function(n){t.children(n).length||e.setNode(n,t.node(n))})),r.forEach(t.edges(),(function(n){e.setEdge(n,t.edge(n))})),e},successorWeights:function(t){var e=r.map(t.nodes(),(function(e){var n={};return r.forEach(t.outEdges(e),(function(e){n[e.w]=(n[e.w]||0)+t.edge(e).weight})),n}));return r.zipObject(t.nodes(),e)},predecessorWeights:function(t){var e=r.map(t.nodes(),(function(e){var n={};return r.forEach(t.inEdges(e),(function(e){n[e.v]=(n[e.v]||0)+t.edge(e).weight})),n}));return r.zipObject(t.nodes(),e)},intersectRect:function(t,e){var n,r,i=t.x,a=t.y,o=e.x-i,s=e.y-a,c=t.width/2,u=t.height/2;if(!o&&!s)throw new Error("Not possible to find intersection inside of the rectangle");return Math.abs(s)*c>Math.abs(o)*u?(s<0&&(u=-u),n=u*o/s,r=u):(o<0&&(c=-c),n=c,r=c*s/o),{x:i+n,y:a+r}},buildLayerMatrix:function(t){var e=r.map(r.range(o(t)+1),(function(){return[]}));return r.forEach(t.nodes(),(function(n){var i=t.node(n),a=i.rank;r.isUndefined(a)||(e[a][i.order]=n)})),e},normalizeRanks:function(t){var e=r.min(r.map(t.nodes(),(function(e){return t.node(e).rank})));r.forEach(t.nodes(),(function(n){var i=t.node(n);r.has(i,"rank")&&(i.rank-=e)}))},removeEmptyRanks:function(t){var e=r.min(r.map(t.nodes(),(function(e){return t.node(e).rank}))),n=[];r.forEach(t.nodes(),(function(r){var i=t.node(r).rank-e;n[i]||(n[i]=[]),n[i].push(r)}));var i=0,a=t.graph().nodeRankFactor;r.forEach(n,(function(e,n){r.isUndefined(e)&&n%a!=0?--i:i&&r.forEach(e,(function(e){t.node(e).rank+=i}))}))},addBorderNode:function(t,e,n,r){var i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),a(t,"border",i,e)},maxRank:o,partition:function(t,e){var n={lhs:[],rhs:[]};return r.forEach(t,(function(t){e(t)?n.lhs.push(t):n.rhs.push(t)})),n},time:function(t,e){var n=r.now();try{return e()}finally{console.log(t+" time: "+(r.now()-n)+"ms")}},notime:function(t,e){return e()}}},8177:t=>{t.exports="0.8.5"},7856:function(t){t.exports=function(){"use strict";var t=Object.hasOwnProperty,e=Object.setPrototypeOf,n=Object.isFrozen,r=Object.getPrototypeOf,i=Object.getOwnPropertyDescriptor,a=Object.freeze,o=Object.seal,s=Object.create,c="undefined"!=typeof Reflect&&Reflect,u=c.apply,l=c.construct;u||(u=function(t,e,n){return t.apply(e,n)}),a||(a=function(t){return t}),o||(o=function(t){return t}),l||(l=function(t,e){return new(Function.prototype.bind.apply(t,[null].concat(function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e1?n-1:0),i=1;i/gm),j=o(/^data-[\-\w.\u00B7-\uFFFF]/),Y=o(/^aria-[\-\w]+$/),z=o(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),U=o(/^(?:\w+script|data):/i),q=o(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function $(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e0&&void 0!==arguments[0]?arguments[0]:W(),n=function(e){return t(e)};if(n.version="2.3.5",n.removed=[],!e||!e.document||9!==e.document.nodeType)return n.isSupported=!1,n;var r=e.document,i=e.document,o=e.DocumentFragment,s=e.HTMLTemplateElement,c=e.Node,u=e.Element,l=e.NodeFilter,h=e.NamedNodeMap,w=void 0===h?e.NamedNodeMap||e.MozNamedAttrMap:h,G=e.HTMLFormElement,X=e.DOMParser,Z=e.trustedTypes,Q=u.prototype,K=E(Q,"cloneNode"),J=E(Q,"nextSibling"),tt=E(Q,"childNodes"),et=E(Q,"parentNode");if("function"==typeof s){var nt=i.createElement("template");nt.content&&nt.content.ownerDocument&&(i=nt.content.ownerDocument)}var rt=V(Z,r),it=rt?rt.createHTML(""):"",at=i,ot=at.implementation,st=at.createNodeIterator,ct=at.createDocumentFragment,ut=at.getElementsByTagName,lt=r.importNode,ht={};try{ht=T(i).documentMode?i.documentMode:{}}catch(t){}var ft={};n.isSupported="function"==typeof et&&ot&&void 0!==ot.createHTMLDocument&&9!==ht;var dt=F,pt=P,yt=j,gt=Y,mt=U,vt=q,bt=z,_t=null,xt=k({},[].concat($(C),$(S),$(A),$(N),$(O))),wt=null,kt=k({},[].concat($(B),$(L),$(I),$(R))),Tt=Object.seal(Object.create(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Et=null,Ct=null,St=!0,At=!0,Mt=!1,Nt=!1,Dt=!1,Ot=!1,Bt=!1,Lt=!1,It=!1,Rt=!1,Ft=!0,Pt=!0,jt=!1,Yt={},zt=null,Ut=k({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),qt=null,Ht=k({},["audio","video","img","source","image","track"]),$t=null,Wt=k({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Vt="http://www.w3.org/1998/Math/MathML",Gt="http://www.w3.org/2000/svg",Xt="http://www.w3.org/1999/xhtml",Zt=Xt,Qt=!1,Kt=void 0,Jt=["application/xhtml+xml","text/html"],te="text/html",ee=void 0,ne=null,re=i.createElement("form"),ie=function(t){return t instanceof RegExp||t instanceof Function},ae=function(t){ne&&ne===t||(t&&"object"===(void 0===t?"undefined":H(t))||(t={}),t=T(t),_t="ALLOWED_TAGS"in t?k({},t.ALLOWED_TAGS):xt,wt="ALLOWED_ATTR"in t?k({},t.ALLOWED_ATTR):kt,$t="ADD_URI_SAFE_ATTR"in t?k(T(Wt),t.ADD_URI_SAFE_ATTR):Wt,qt="ADD_DATA_URI_TAGS"in t?k(T(Ht),t.ADD_DATA_URI_TAGS):Ht,zt="FORBID_CONTENTS"in t?k({},t.FORBID_CONTENTS):Ut,Et="FORBID_TAGS"in t?k({},t.FORBID_TAGS):{},Ct="FORBID_ATTR"in t?k({},t.FORBID_ATTR):{},Yt="USE_PROFILES"in t&&t.USE_PROFILES,St=!1!==t.ALLOW_ARIA_ATTR,At=!1!==t.ALLOW_DATA_ATTR,Mt=t.ALLOW_UNKNOWN_PROTOCOLS||!1,Nt=t.SAFE_FOR_TEMPLATES||!1,Dt=t.WHOLE_DOCUMENT||!1,Lt=t.RETURN_DOM||!1,It=t.RETURN_DOM_FRAGMENT||!1,Rt=t.RETURN_TRUSTED_TYPE||!1,Bt=t.FORCE_BODY||!1,Ft=!1!==t.SANITIZE_DOM,Pt=!1!==t.KEEP_CONTENT,jt=t.IN_PLACE||!1,bt=t.ALLOWED_URI_REGEXP||bt,Zt=t.NAMESPACE||Xt,t.CUSTOM_ELEMENT_HANDLING&&ie(t.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Tt.tagNameCheck=t.CUSTOM_ELEMENT_HANDLING.tagNameCheck),t.CUSTOM_ELEMENT_HANDLING&&ie(t.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Tt.attributeNameCheck=t.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),t.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof t.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(Tt.allowCustomizedBuiltInElements=t.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),Kt=Kt=-1===Jt.indexOf(t.PARSER_MEDIA_TYPE)?te:t.PARSER_MEDIA_TYPE,ee="application/xhtml+xml"===Kt?function(t){return t}:y,Nt&&(At=!1),It&&(Lt=!0),Yt&&(_t=k({},[].concat($(O))),wt=[],!0===Yt.html&&(k(_t,C),k(wt,B)),!0===Yt.svg&&(k(_t,S),k(wt,L),k(wt,R)),!0===Yt.svgFilters&&(k(_t,A),k(wt,L),k(wt,R)),!0===Yt.mathMl&&(k(_t,N),k(wt,I),k(wt,R))),t.ADD_TAGS&&(_t===xt&&(_t=T(_t)),k(_t,t.ADD_TAGS)),t.ADD_ATTR&&(wt===kt&&(wt=T(wt)),k(wt,t.ADD_ATTR)),t.ADD_URI_SAFE_ATTR&&k($t,t.ADD_URI_SAFE_ATTR),t.FORBID_CONTENTS&&(zt===Ut&&(zt=T(zt)),k(zt,t.FORBID_CONTENTS)),Pt&&(_t["#text"]=!0),Dt&&k(_t,["html","head","body"]),_t.table&&(k(_t,["tbody"]),delete Et.tbody),a&&a(t),ne=t)},oe=k({},["mi","mo","mn","ms","mtext"]),se=k({},["foreignobject","desc","title","annotation-xml"]),ce=k({},S);k(ce,A),k(ce,M);var ue=k({},N);k(ue,D);var le=function(t){var e=et(t);e&&e.tagName||(e={namespaceURI:Xt,tagName:"template"});var n=y(t.tagName),r=y(e.tagName);if(t.namespaceURI===Gt)return e.namespaceURI===Xt?"svg"===n:e.namespaceURI===Vt?"svg"===n&&("annotation-xml"===r||oe[r]):Boolean(ce[n]);if(t.namespaceURI===Vt)return e.namespaceURI===Xt?"math"===n:e.namespaceURI===Gt?"math"===n&&se[r]:Boolean(ue[n]);if(t.namespaceURI===Xt){if(e.namespaceURI===Gt&&!se[r])return!1;if(e.namespaceURI===Vt&&!oe[r])return!1;var i=k({},["title","style","font","a","script"]);return!ue[n]&&(i[n]||!ce[n])}return!1},he=function(t){p(n.removed,{element:t});try{t.parentNode.removeChild(t)}catch(e){try{t.outerHTML=it}catch(e){t.remove()}}},fe=function(t,e){try{p(n.removed,{attribute:e.getAttributeNode(t),from:e})}catch(t){p(n.removed,{attribute:null,from:e})}if(e.removeAttribute(t),"is"===t&&!wt[t])if(Lt||It)try{he(e)}catch(t){}else try{e.setAttribute(t,"")}catch(t){}},de=function(t){var e=void 0,n=void 0;if(Bt)t=""+t;else{var r=g(t,/^[\r\n\t ]+/);n=r&&r[0]}"application/xhtml+xml"===Kt&&(t=''+t+"");var a=rt?rt.createHTML(t):t;if(Zt===Xt)try{e=(new X).parseFromString(a,Kt)}catch(t){}if(!e||!e.documentElement){e=ot.createDocument(Zt,"template",null);try{e.documentElement.innerHTML=Qt?"":a}catch(t){}}var o=e.body||e.documentElement;return t&&n&&o.insertBefore(i.createTextNode(n),o.childNodes[0]||null),Zt===Xt?ut.call(e,Dt?"html":"body")[0]:Dt?e.documentElement:o},pe=function(t){return st.call(t.ownerDocument||t,t,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT,null,!1)},ye=function(t){return t instanceof G&&("string"!=typeof t.nodeName||"string"!=typeof t.textContent||"function"!=typeof t.removeChild||!(t.attributes instanceof w)||"function"!=typeof t.removeAttribute||"function"!=typeof t.setAttribute||"string"!=typeof t.namespaceURI||"function"!=typeof t.insertBefore)},ge=function(t){return"object"===(void 0===c?"undefined":H(c))?t instanceof c:t&&"object"===(void 0===t?"undefined":H(t))&&"number"==typeof t.nodeType&&"string"==typeof t.nodeName},me=function(t,e,r){ft[t]&&f(ft[t],(function(t){t.call(n,e,r,ne)}))},ve=function(t){var e=void 0;if(me("beforeSanitizeElements",t,null),ye(t))return he(t),!0;if(g(t.nodeName,/[\u0080-\uFFFF]/))return he(t),!0;var r=ee(t.nodeName);if(me("uponSanitizeElement",t,{tagName:r,allowedTags:_t}),!ge(t.firstElementChild)&&(!ge(t.content)||!ge(t.content.firstElementChild))&&_(/<[/\w]/g,t.innerHTML)&&_(/<[/\w]/g,t.textContent))return he(t),!0;if("select"===r&&_(/