import{_ as l,o as p,c as o,k as s,a,X as n}from"./chunks/framework.6e839c56.js";const k=JSON.parse('{"title":"Convertor","description":"","frontmatter":{},"headers":[],"relativePath":"en/api/packages/convertor.md","filePath":"en/api/packages/convertor.md"}'),e={name:"en/api/packages/convertor.md"},t=s("h1",{id:"Convertor",tabindex:"-1"},[a("Convertor "),s("a",{class:"header-anchor",href:"#Convertor","aria-label":'Permalink to "Convertor"'},"​")],-1),c=s("p",null,"Package convertor contains some functions for data type convertion.",-1),r=s("div",{STYLE:"page-break-after: always;"},null,-1),y=s("h2",{id:"Source-",tabindex:"-1"},[a("Source: "),s("a",{class:"header-anchor",href:"#Source-","aria-label":'Permalink to "Source:"'},"​")],-1),F=s("ul",null,[s("li",null,[s("a",{href:"https://github.com/duke-git/lancet/blob/main/convertor/convertor.go",target:"_blank",rel:"noreferrer"},"https://github.com/duke-git/lancet/blob/main/convertor/convertor.go")])],-1),i=s("div",{STYLE:"page-break-after: always;"},null,-1),u=n(`<h2 id="Usage-" tabindex="-1">Usage: <a class="header-anchor" href="#Usage-" aria-label="Permalink to &quot;Usage:&quot;">​</a></h2><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span></code></pre></div>`,2),A=s("div",{STYLE:"page-break-after: always;"},null,-1),E=n('<h2 id="Index" tabindex="-1">Index <a class="header-anchor" href="#Index" aria-label="Permalink to &quot;Index&quot;">​</a></h2><ul><li><a href="#ColorHexToRGB">ColorHexToRGB</a></li><li><a href="#ColorRGBToHex">ColorRGBToHex</a></li><li><a href="#ToBool">ToBool</a></li><li><a href="#ToBytes">ToBytes</a></li><li><a href="#ToChar">ToChar</a></li><li><a href="#ToChannel">ToChannel</a></li><li><a href="#ToFloat">ToFloat</a></li><li><a href="#ToInt">ToInt</a></li><li><a href="#ToJson">ToJson</a></li><li><a href="#ToMap">ToMap</a></li><li><a href="#ToPointer">ToPointer</a></li><li><a href="#ToString">ToString</a></li><li><a href="#StructToMap">StructToMap</a></li><li><a href="#MapToSlice">MapToSlice</a></li><li><a href="#EncodeByte">EncodeByte</a></li><li><a href="#DecodeByte">DecodeByte</a></li><li><a href="#DeepClone">DeepClone</a></li><li><a href="#CopyProperties">CopyProperties</a></li><li><a href="#ToInterface">ToInterface</a></li><li><a href="#Utf8ToGbk">Utf8ToGbk</a></li><li><a href="#GbkToUtf8">GbkToUtf8</a></li></ul>',2),d=s("div",{STYLE:"page-break-after: always;"},null,-1),B=n(`<link rel="stylesheet" type="text/css" href="/styles/api_doc.css"><h2 id="Documentation" tabindex="-1">Documentation <a class="header-anchor" href="#Documentation" aria-label="Permalink to &quot;Documentation&quot;">​</a></h2><h3 id="ColorHexToRGB" tabindex="-1"><span id="ColorHexToRGB">ColorHexToRGB</span> <a class="header-anchor" href="#ColorHexToRGB" aria-label="Permalink to &quot;&lt;span id=&quot;ColorHexToRGB&quot;&gt;ColorHexToRGB&lt;/span&gt;&quot;">​</a></h3><p>Convert color hex to color rgb.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ColorHexToRGB</span><span style="color:#F6F6F4;">(colorHex </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) (red, green, blue </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ColorHexToRGB</span><span style="color:#999999;">(</span><span style="color:#393A34;">colorHex </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">red</span><span style="color:#999999;">,</span><span style="color:#393A34;"> green</span><span style="color:#999999;">,</span><span style="color:#393A34;"> blue </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/o7_ft-JCJBV" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    colorHex </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">#003366</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    r, g, b </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ColorHexToRGB</span><span style="color:#F6F6F4;">(colorHex)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(r, g, b)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0 51 102</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">colorHex</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">#003366</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">r</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">g</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">b</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ColorHexToRGB</span><span style="color:#999999;">(</span><span style="color:#393A34;">colorHex</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">r</span><span style="color:#999999;">,</span><span style="color:#393A34;"> g</span><span style="color:#999999;">,</span><span style="color:#393A34;"> b</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0 51 102</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ColorRGBToHex" tabindex="-1"><span id="ColorRGBToHex">ColorRGBToHex</span> <a class="header-anchor" href="#ColorRGBToHex" aria-label="Permalink to &quot;&lt;span id=&quot;ColorRGBToHex&quot;&gt;ColorRGBToHex&lt;/span&gt;&quot;">​</a></h3><p>Convert color rgb to color hex.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ColorRGBToHex</span><span style="color:#F6F6F4;">(red, green, blue </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ColorRGBToHex</span><span style="color:#999999;">(</span><span style="color:#393A34;">red</span><span style="color:#999999;">,</span><span style="color:#393A34;"> green</span><span style="color:#999999;">,</span><span style="color:#393A34;"> blue </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/nzKS2Ro87J1" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    r </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span></span>
<span class="line"><span style="color:#F6F6F4;">    g </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">51</span></span>
<span class="line"><span style="color:#F6F6F4;">    b </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">102</span></span>
<span class="line"><span style="color:#F6F6F4;">    colorHex </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;">ColorRGBToHex</span><span style="color:#F6F6F4;">(r, g, b)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(colorHex)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// #003366</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">r</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">g</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">51</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">b</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">102</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">colorHex</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#998418;">ColorRGBToHex</span><span style="color:#999999;">(</span><span style="color:#393A34;">r</span><span style="color:#999999;">,</span><span style="color:#393A34;"> g</span><span style="color:#999999;">,</span><span style="color:#393A34;"> b</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">colorHex</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// #003366</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToBool" tabindex="-1"><span id="ToBool">ToBool</span> <a class="header-anchor" href="#ToBool" aria-label="Permalink to &quot;&lt;span id=&quot;ToBool&quot;&gt;ToBool&lt;/span&gt;&quot;">​</a></h3><p>Convert string to bool. Use strconv.ParseBool.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ToBool</span><span style="color:#F6F6F4;">(s </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) (</span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ToBool</span><span style="color:#999999;">(</span><span style="color:#393A34;">s </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">bool</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/ARht2WnGdIN" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    cases </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> []</span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">{</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">true</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">True</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">false</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">False</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">0</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">123</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">0.0</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abc</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">for</span><span style="color:#F6F6F4;"> i </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">; i </span><span style="color:#F286C4;">&lt;</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;">len</span><span style="color:#F6F6F4;">(cases); i</span><span style="color:#F286C4;">++</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        result, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToBool</span><span style="color:#F6F6F4;">(cases[i])</span></span>
<span class="line"><span style="color:#F6F6F4;">        fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">cases</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">string</span><span style="color:#999999;">{</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">true</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">True</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">false</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">False</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">0</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">123</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">0.0</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abc</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">for</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">i</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">;</span><span style="color:#393A34;"> i </span><span style="color:#AB5959;">&lt;</span><span style="color:#393A34;"> </span><span style="color:#998418;">len</span><span style="color:#999999;">(</span><span style="color:#393A34;">cases</span><span style="color:#999999;">);</span><span style="color:#393A34;"> i</span><span style="color:#AB5959;">++</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#B07D48;">result</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToBool</span><span style="color:#999999;">(</span><span style="color:#393A34;">cases</span><span style="color:#999999;">[</span><span style="color:#393A34;">i</span><span style="color:#999999;">])</span></span>
<span class="line"><span style="color:#393A34;">        fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToBytes" tabindex="-1"><span id="ToBytes">ToBytes</span> <a class="header-anchor" href="#ToBytes" aria-label="Permalink to &quot;&lt;span id=&quot;ToBytes&quot;&gt;ToBytes&lt;/span&gt;&quot;">​</a></h3><p>Convert value to byte slice.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ToBytes</span><span style="color:#F6F6F4;">(data any) ([]</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ToBytes</span><span style="color:#999999;">(</span><span style="color:#393A34;">data any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">([]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/fAMXYFDvOvr" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    bytesData, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToBytes</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abc</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> err </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(err)</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(bytesData)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// [97 98 99]</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">bytesData</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToBytes</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abc</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> err </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">err</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">bytesData</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// [97 98 99]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToChar" tabindex="-1"><span id="ToChar">ToChar</span> <a class="header-anchor" href="#ToChar" aria-label="Permalink to &quot;&lt;span id=&quot;ToChar&quot;&gt;ToChar&lt;/span&gt;&quot;">​</a></h3><p>Convert string to char slice.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ToChar</span><span style="color:#F6F6F4;">(s </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) []</span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ToChar</span><span style="color:#999999;">(</span><span style="color:#393A34;">s </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/JJ1SvbFkVdM" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    result1 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToChar</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result2 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToChar</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abc</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result3 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToChar</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">1 2#3</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result1)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result2)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result3)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// []</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// [a b c]</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// [1   2 # 3]</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result1</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToChar</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result2</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToChar</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abc</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result3</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToChar</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">1 2#3</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// []</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// [a b c]</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// [1   2 # 3]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToChannel" tabindex="-1"><span id="ToChannel">ToChannel</span> <a class="header-anchor" href="#ToChannel" aria-label="Permalink to &quot;&lt;span id=&quot;ToChannel&quot;&gt;ToChannel&lt;/span&gt;&quot;">​</a></h3><p>Convert a collection of elements to a read-only channel.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> ToChannel[T any](array []T) </span><span style="color:#F286C4;">&lt;-chan</span><span style="color:#F6F6F4;"> T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> ToChannel</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">](</span><span style="color:#393A34;">array </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&lt;-</span><span style="color:#1E754F;">chan</span><span style="color:#393A34;"> T</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/hOx_oYZbAnL" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    ch </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToChannel</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"><span style="color:#F6F6F4;">    result1 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&lt;-</span><span style="color:#F6F6F4;">ch</span></span>
<span class="line"><span style="color:#F6F6F4;">    result2 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&lt;-</span><span style="color:#F6F6F4;">ch</span></span>
<span class="line"><span style="color:#F6F6F4;">    result3 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&lt;-</span><span style="color:#F6F6F4;">ch</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result1)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result2)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result3)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 1</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 2</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">ch</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToChannel</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result1</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&lt;-</span><span style="color:#393A34;">ch</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result2</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&lt;-</span><span style="color:#393A34;">ch</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result3</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&lt;-</span><span style="color:#393A34;">ch</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result3</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 1</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 2</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToFloat" tabindex="-1"><span id="ToFloat">ToFloat</span> <a class="header-anchor" href="#ToFloat" aria-label="Permalink to &quot;&lt;span id=&quot;ToFloat&quot;&gt;ToFloat&lt;/span&gt;&quot;">​</a></h3><p>Convert value to a float64 value. If param is a invalid floatable, will return 0.0 and error. </p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ToFloat</span><span style="color:#F6F6F4;">(value any) (</span><span style="color:#97E1F1;font-style:italic;">float64</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ToFloat</span><span style="color:#999999;">(</span><span style="color:#393A34;">value any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">float64</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/4YTmPCibqHJ" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    result1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToFloat</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result2, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToFloat</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abc</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result3, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToFloat</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">-1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result4, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToFloat</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">-.11</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result5, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToFloat</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">1.23e3</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result6, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToFloat</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">true</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result1)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result2, err)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result3)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result4)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result5)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result6)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0 strconv.ParseFloat: parsing &quot;&quot;: invalid syntax</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// -1</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// -0.11</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 1230</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToFloat</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToFloat</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abc</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result3</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToFloat</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">-1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result4</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToFloat</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">-.11</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result5</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToFloat</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">1.23e3</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToFloat</span><span style="color:#999999;">(</span><span style="color:#1E754F;">true</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> err</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result4</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result6</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0 strconv.ParseFloat: parsing &quot;&quot;: invalid syntax</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// -1</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// -0.11</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 1230</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToInt" tabindex="-1"><span id="ToInt">ToInt</span> <a class="header-anchor" href="#ToInt" aria-label="Permalink to &quot;&lt;span id=&quot;ToInt&quot;&gt;ToInt&lt;/span&gt;&quot;">​</a></h3><p>Convert value to a int64 value. If param is a invalid intable, will return 0 and error. </p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ToInt</span><span style="color:#F6F6F4;">(value any) (</span><span style="color:#97E1F1;font-style:italic;">int64</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ToInt</span><span style="color:#999999;">(</span><span style="color:#393A34;">value any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">int64</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/9_h9vIt-QZ_b" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    result1, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToInt</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">123</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result2, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToInt</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">-123</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result3, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToInt</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">float64</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">12.3</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">    result4, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToInt</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abc</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result5, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToInt</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">true</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result1)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result2)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result3)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result4, err)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result5)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 123</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// -123</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 12</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0 strconv.ParseInt: parsing &quot;&quot;: invalid syntax</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToInt</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">123</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToInt</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">-123</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result3</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToInt</span><span style="color:#999999;">(</span><span style="color:#998418;">float64</span><span style="color:#999999;">(</span><span style="color:#2F798A;">12.3</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result4</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToInt</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abc</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result5</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToInt</span><span style="color:#999999;">(</span><span style="color:#1E754F;">true</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result4</span><span style="color:#999999;">,</span><span style="color:#393A34;"> err</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result5</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 123</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// -123</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 12</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0 strconv.ParseInt: parsing &quot;&quot;: invalid syntax</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToJson" tabindex="-1"><span id="ToJson">ToJson</span> <a class="header-anchor" href="#ToJson" aria-label="Permalink to &quot;&lt;span id=&quot;ToJson&quot;&gt;ToJson&lt;/span&gt;&quot;">​</a></h3><p>Convert interface to json string. If param can&#39;t be converted, will return &quot;&quot; and error. </p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ToJson</span><span style="color:#F6F6F4;">(value any) (</span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ToJson</span><span style="color:#999999;">(</span><span style="color:#393A34;">value any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/2rLIkMmXWvR" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    aMap </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">map</span><span style="color:#F6F6F4;">[</span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">a</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">b</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">c</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">}</span></span>
<span class="line"><span style="color:#F6F6F4;">    result, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;">ToJson</span><span style="color:#F6F6F4;">(aMap)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> err </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        fmt.</span><span style="color:#97E1F1;">Printf</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#BF9EEE;">%v</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, err)</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// {&quot;a&quot;:1,&quot;b&quot;:2,&quot;c&quot;:3}</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">aMap</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">map</span><span style="color:#999999;">[</span><span style="color:#AB5959;">string</span><span style="color:#999999;">]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">a</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">b</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">c</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">3</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#998418;">ToJson</span><span style="color:#999999;">(</span><span style="color:#393A34;">aMap</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> err </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Printf</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#A65E2B;">%v</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> err</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// {&quot;a&quot;:1,&quot;b&quot;:2,&quot;c&quot;:3}</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToMap" tabindex="-1"><span id="ToMap">ToMap</span> <a class="header-anchor" href="#ToMap" aria-label="Permalink to &quot;&lt;span id=&quot;ToMap&quot;&gt;ToMap&lt;/span&gt;&quot;">​</a></h3><p>Convert a slice of structs to a map based on iteratee function. </p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> ToMap[T any, K comparable, V any](array []T, iteratee </span><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;">(T) (K, V)) </span><span style="color:#F286C4;">map</span><span style="color:#F6F6F4;">[K]V</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> ToMap</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">,</span><span style="color:#393A34;"> K comparable</span><span style="color:#999999;">,</span><span style="color:#393A34;"> V any</span><span style="color:#999999;">](</span><span style="color:#393A34;">array </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> iteratee </span><span style="color:#1E754F;">func</span><span style="color:#999999;">(</span><span style="color:#393A34;">T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">K</span><span style="color:#999999;">,</span><span style="color:#393A34;"> V</span><span style="color:#999999;">))</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">map</span><span style="color:#999999;">[</span><span style="color:#393A34;">K</span><span style="color:#999999;">]</span><span style="color:#393A34;">V</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/tVFy7E-t24l" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Message</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        name </span><span style="color:#97E1F1;font-style:italic;">string</span></span>
<span class="line"><span style="color:#F6F6F4;">        code </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    messages </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> []Message{</span></span>
<span class="line"><span style="color:#F6F6F4;">        {name: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">Hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, code: </span><span style="color:#BF9EEE;">100</span><span style="color:#F6F6F4;">},</span></span>
<span class="line"><span style="color:#F6F6F4;">        {name: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">Hi</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, code: </span><span style="color:#BF9EEE;">101</span><span style="color:#F6F6F4;">},</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToMap</span><span style="color:#F6F6F4;">(messages, </span><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;">(msg Message) (</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">) {</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> msg.code, msg.name</span></span>
<span class="line"><span style="color:#F6F6F4;">    })</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// map[100:Hello 101:Hi]</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Message</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        name </span><span style="color:#AB5959;">string</span></span>
<span class="line"><span style="color:#393A34;">        code </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">messages</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">Message</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#999999;">{</span><span style="color:#393A34;">name</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">Hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> code</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">100</span><span style="color:#999999;">},</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#999999;">{</span><span style="color:#393A34;">name</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">Hi</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> code</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">101</span><span style="color:#999999;">},</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToMap</span><span style="color:#999999;">(</span><span style="color:#393A34;">messages</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">func</span><span style="color:#999999;">(</span><span style="color:#393A34;">msg Message</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">int</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> msg</span><span style="color:#999999;">.</span><span style="color:#393A34;">code</span><span style="color:#999999;">,</span><span style="color:#393A34;"> msg</span><span style="color:#999999;">.</span><span style="color:#393A34;">name</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">})</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// map[100:Hello 101:Hi]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToPointer" tabindex="-1"><span id="ToPointer">ToPointer</span> <a class="header-anchor" href="#ToPointer" aria-label="Permalink to &quot;&lt;span id=&quot;ToPointer&quot;&gt;ToPointer&lt;/span&gt;&quot;">​</a></h3><p>Returns a pointer to passed value. </p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> ToPointer[T any](value T) </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> ToPointer</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">](</span><span style="color:#393A34;">value T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/ASf_etHNlw1" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToPointer</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">123</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 123</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToPointer</span><span style="color:#999999;">(</span><span style="color:#2F798A;">123</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 123</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToString" tabindex="-1"><span id="ToString">ToString</span> <a class="header-anchor" href="#ToString" aria-label="Permalink to &quot;&lt;span id=&quot;ToString&quot;&gt;ToString&lt;/span&gt;&quot;">​</a></h3><p>ToString convert value to string, for number, string, []byte, will convert to string. For other type (slice, map, array, struct) will call json.Marshal</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ToString</span><span style="color:#F6F6F4;">(value any) </span><span style="color:#97E1F1;font-style:italic;">string</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ToString</span><span style="color:#999999;">(</span><span style="color:#393A34;">value any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/nF1zOOslpQq" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    result1 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToString</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result2 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToString</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result3 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToString</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result4 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToString</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">1.23</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result5 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToString</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">true</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result6 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToString</span><span style="color:#F6F6F4;">(</span><span style="color:#BF9EEE;">false</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    result7 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToString</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">})</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result1)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result2)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result3)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result4)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result5)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result6)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result7)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">//</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">//</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 1.23</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// [1,2,3]</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result1</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToString</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result2</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToString</span><span style="color:#999999;">(</span><span style="color:#1E754F;">nil</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result3</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToString</span><span style="color:#999999;">(</span><span style="color:#2F798A;">0</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result4</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToString</span><span style="color:#999999;">(</span><span style="color:#2F798A;">1.23</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result5</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToString</span><span style="color:#999999;">(</span><span style="color:#1E754F;">true</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result6</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToString</span><span style="color:#999999;">(</span><span style="color:#1E754F;">false</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result7</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToString</span><span style="color:#999999;">([]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">3</span><span style="color:#999999;">})</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result1</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result2</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result3</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result4</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result5</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result6</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result7</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">//</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">//</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 1.23</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// [1,2,3]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="StructToMap" tabindex="-1"><span id="StructToMap">StructToMap</span> <a class="header-anchor" href="#StructToMap" aria-label="Permalink to &quot;&lt;span id=&quot;StructToMap&quot;&gt;StructToMap&lt;/span&gt;&quot;">​</a></h3><p>Convert struct to map, only convert exported field, struct field tag \`json\` should be set.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">StructToMap</span><span style="color:#F6F6F4;">(value any) (</span><span style="color:#F286C4;">map</span><span style="color:#F6F6F4;">[</span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">]any, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">StructToMap</span><span style="color:#999999;">(</span><span style="color:#393A34;">value any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#1E754F;">map</span><span style="color:#999999;">[</span><span style="color:#AB5959;">string</span><span style="color:#999999;">]</span><span style="color:#393A34;">any</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/KYGYJqNUBOI" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">People</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        Name </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;name&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        age  </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    p </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> People{</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">test</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#BF9EEE;">100</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    pm, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">StructToMap</span><span style="color:#F6F6F4;">(p)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(pm)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// map[name:test]</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">People</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        Name </span><span style="color:#AB5959;">string</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;name&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        age  </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">p</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> People</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">test</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#2F798A;">100</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">pm</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">StructToMap</span><span style="color:#999999;">(</span><span style="color:#393A34;">p</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">pm</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// map[name:test]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="MapToSlice" tabindex="-1"><span id="MapToSlice">MapToSlice</span> <a class="header-anchor" href="#MapToSlice" aria-label="Permalink to &quot;&lt;span id=&quot;MapToSlice&quot;&gt;MapToSlice&lt;/span&gt;&quot;">​</a></h3><p>Convert a map to a slice based on iteratee function.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> MapToSlice[T any, K comparable, V any](aMap </span><span style="color:#F286C4;">map</span><span style="color:#F6F6F4;">[K]V, iteratee </span><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;">(K, V) T) []T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> MapToSlice</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">,</span><span style="color:#393A34;"> K comparable</span><span style="color:#999999;">,</span><span style="color:#393A34;"> V any</span><span style="color:#999999;">](</span><span style="color:#393A34;">aMap </span><span style="color:#1E754F;">map</span><span style="color:#999999;">[</span><span style="color:#393A34;">K</span><span style="color:#999999;">]</span><span style="color:#393A34;">V</span><span style="color:#999999;">,</span><span style="color:#393A34;"> iteratee </span><span style="color:#1E754F;">func</span><span style="color:#999999;">(</span><span style="color:#393A34;">K</span><span style="color:#999999;">,</span><span style="color:#393A34;"> V</span><span style="color:#999999;">)</span><span style="color:#393A34;"> T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">T</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/dmX4Ix5V6Wl" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    aMap </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">map</span><span style="color:#F6F6F4;">[</span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">a</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">b</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">c</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">}</span></span>
<span class="line"><span style="color:#F6F6F4;">    result </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;">MapToSlice</span><span style="color:#F6F6F4;">(aMap, </span><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;">(key </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, value </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">) </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">return</span><span style="color:#F6F6F4;"> key </span><span style="color:#F286C4;">+</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">:</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">+</span><span style="color:#F6F6F4;"> strconv.</span><span style="color:#97E1F1;">Itoa</span><span style="color:#F6F6F4;">(value)</span></span>
<span class="line"><span style="color:#F6F6F4;">    })</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result) </span><span style="color:#7B7F8B;">//[]string{&quot;a:1&quot;, &quot;b:2&quot;, &quot;c:3&quot;}</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">aMap</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">map</span><span style="color:#999999;">[</span><span style="color:#AB5959;">string</span><span style="color:#999999;">]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">a</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">b</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">c</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">3</span><span style="color:#999999;">}</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#998418;">MapToSlice</span><span style="color:#999999;">(</span><span style="color:#393A34;">aMap</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">func</span><span style="color:#999999;">(</span><span style="color:#393A34;">key </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> value </span><span style="color:#AB5959;">int</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">return</span><span style="color:#393A34;"> key </span><span style="color:#AB5959;">+</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">:</span><span style="color:#B5695999;">&quot;</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">+</span><span style="color:#393A34;"> strconv</span><span style="color:#999999;">.</span><span style="color:#998418;">Itoa</span><span style="color:#999999;">(</span><span style="color:#393A34;">value</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">})</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#A0ADA0;">//[]string{&quot;a:1&quot;, &quot;b:2&quot;, &quot;c:3&quot;}</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="EncodeByte" tabindex="-1"><span id="EncodeByte">EncodeByte</span> <a class="header-anchor" href="#EncodeByte" aria-label="Permalink to &quot;&lt;span id=&quot;EncodeByte&quot;&gt;EncodeByte&lt;/span&gt;&quot;">​</a></h3><p>Encode data to byte slice.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">EncodeByte</span><span style="color:#F6F6F4;">(data any) ([]</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">EncodeByte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">([]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/DVmM1G5JfuP" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    byteData, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">EncodeByte</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abc</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(byteData)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// [6 12 0 3 97 98 99]</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">byteData</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">EncodeByte</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abc</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">byteData</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// [6 12 0 3 97 98 99]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DecodeByte" tabindex="-1"><span id="DecodeByte">DecodeByte</span> <a class="header-anchor" href="#DecodeByte" aria-label="Permalink to &quot;&lt;span id=&quot;DecodeByte&quot;&gt;DecodeByte&lt;/span&gt;&quot;">​</a></h3><p>Decode byte data to target object. target should be a pointer instance.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">DecodeByte</span><span style="color:#F6F6F4;">(data []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">, target any) </span><span style="color:#97E1F1;font-style:italic;">error</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DecodeByte</span><span style="color:#999999;">(</span><span style="color:#393A34;">data </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">,</span><span style="color:#393A34;"> target any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/zI6xsmuQRbn" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">var</span><span style="color:#F6F6F4;"> result </span><span style="color:#97E1F1;font-style:italic;">string</span></span>
<span class="line"><span style="color:#F6F6F4;">    byteData </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">{</span><span style="color:#BF9EEE;">6</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">12</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">0</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">3</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">97</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">98</span><span style="color:#F6F6F4;">, </span><span style="color:#BF9EEE;">99</span><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">DecodeByte</span><span style="color:#F6F6F4;">(byteData, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">result)</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> err </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">return</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(result)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// abc</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">var</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">result</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">byteData</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">{</span><span style="color:#2F798A;">6</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">12</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">3</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">97</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">98</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">99</span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">DecodeByte</span><span style="color:#999999;">(</span><span style="color:#393A34;">byteData</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> err </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">return</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">result</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// abc</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DeepClone" tabindex="-1"><span id="DeepClone">DeepClone</span> <a class="header-anchor" href="#DeepClone" aria-label="Permalink to &quot;&lt;span id=&quot;DeepClone&quot;&gt;DeepClone&lt;/span&gt;&quot;">​</a></h3><p>Creates a deep copy of passed item, can&#39;t clone unexported field of struct.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> DeepClone[T any](src T) T</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> DeepClone</span><span style="color:#999999;">[</span><span style="color:#393A34;">T any</span><span style="color:#999999;">](</span><span style="color:#393A34;">src T</span><span style="color:#999999;">)</span><span style="color:#393A34;"> T</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/j4DP5dquxnk" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Struct</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        Str        </span><span style="color:#97E1F1;font-style:italic;">string</span></span>
<span class="line"><span style="color:#F6F6F4;">        Int        </span><span style="color:#97E1F1;font-style:italic;">int</span></span>
<span class="line"><span style="color:#F6F6F4;">        Float      </span><span style="color:#97E1F1;font-style:italic;">float64</span></span>
<span class="line"><span style="color:#F6F6F4;">        Bool       </span><span style="color:#97E1F1;font-style:italic;">bool</span></span>
<span class="line"><span style="color:#F6F6F4;">        Nil        </span><span style="color:#F286C4;">interface</span><span style="color:#F6F6F4;">{}</span></span>
<span class="line"><span style="color:#F6F6F4;">        unexported </span><span style="color:#97E1F1;font-style:italic;">string</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    cases </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> []</span><span style="color:#F286C4;">interface</span><span style="color:#F6F6F4;">{}{</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#BF9EEE;">true</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#BF9EEE;">0.1</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">map</span><span style="color:#F6F6F4;">[</span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">]</span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">{</span></span>
<span class="line"><span style="color:#F6F6F4;">            </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">a</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">            </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">b</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#BF9EEE;">2</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        },</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">Struct{</span></span>
<span class="line"><span style="color:#F6F6F4;">            Str:   </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">test</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">            Int:   </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">            Float: </span><span style="color:#BF9EEE;">0.1</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">            Bool:  </span><span style="color:#BF9EEE;">true</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">            Nil:   </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">            </span><span style="color:#7B7F8B;">// unexported: &quot;can&#39;t be cloned&quot;,</span></span>
<span class="line"><span style="color:#F6F6F4;">        },</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">for</span><span style="color:#F6F6F4;"> _, item </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">range</span><span style="color:#F6F6F4;"> cases {</span></span>
<span class="line"><span style="color:#F6F6F4;">        cloned </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">DeepClone</span><span style="color:#F6F6F4;">(item)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">        isPointerEqual </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">cloned </span><span style="color:#F286C4;">==</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">item</span></span>
<span class="line"><span style="color:#F6F6F4;">        fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(cloned, isPointerEqual)</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 1 false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 0.1 false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// map[a:1 b:2] false</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// &amp;{test 1 0.1 true &lt;nil&gt; } false</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Struct</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        Str        </span><span style="color:#AB5959;">string</span></span>
<span class="line"><span style="color:#393A34;">        Int        </span><span style="color:#AB5959;">int</span></span>
<span class="line"><span style="color:#393A34;">        Float      </span><span style="color:#AB5959;">float64</span></span>
<span class="line"><span style="color:#393A34;">        Bool       </span><span style="color:#AB5959;">bool</span></span>
<span class="line"><span style="color:#393A34;">        Nil        </span><span style="color:#1E754F;">interface</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">        unexported </span><span style="color:#AB5959;">string</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">cases</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#1E754F;">interface</span><span style="color:#999999;">{}{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">true</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#2F798A;">0.1</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">map</span><span style="color:#999999;">[</span><span style="color:#AB5959;">string</span><span style="color:#999999;">]</span><span style="color:#AB5959;">int</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">            </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">a</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">            </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">b</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">2</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#999999;">},</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">Struct</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">            Str</span><span style="color:#999999;">:</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">test</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">            Int</span><span style="color:#999999;">:</span><span style="color:#393A34;">   </span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">            Float</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">0.1</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">            Bool</span><span style="color:#999999;">:</span><span style="color:#393A34;">  </span><span style="color:#1E754F;">true</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">            Nil</span><span style="color:#999999;">:</span><span style="color:#393A34;">   </span><span style="color:#1E754F;">nil</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">            </span><span style="color:#A0ADA0;">// unexported: &quot;can&#39;t be cloned&quot;,</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#999999;">},</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">for</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">item</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">range</span><span style="color:#393A34;"> cases </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#B07D48;">cloned</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">DeepClone</span><span style="color:#999999;">(</span><span style="color:#393A34;">item</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#B07D48;">isPointerEqual</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">cloned </span><span style="color:#AB5959;">==</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">item</span></span>
<span class="line"><span style="color:#393A34;">        fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">cloned</span><span style="color:#999999;">,</span><span style="color:#393A34;"> isPointerEqual</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 1 false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 0.1 false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// map[a:1 b:2] false</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// &amp;{test 1 0.1 true &lt;nil&gt; } false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="CopyProperties" tabindex="-1"><span id="CopyProperties">CopyProperties</span> <a class="header-anchor" href="#CopyProperties" aria-label="Permalink to &quot;&lt;span id=&quot;CopyProperties&quot;&gt;CopyProperties&lt;/span&gt;&quot;">​</a></h3><p>Copies each field from the source struct into the destination struct. Use json.Marshal/Unmarshal, so json tag should be set for fields of dst and src struct.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> CopyProperties[T, U any](dst T, src U) (err </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> CopyProperties</span><span style="color:#999999;">[</span><span style="color:#393A34;">T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> U any</span><span style="color:#999999;">](</span><span style="color:#393A34;">dst T</span><span style="color:#999999;">,</span><span style="color:#393A34;"> src U</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">err </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/oZujoB5Sgg5" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Disk</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        Name    </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">  </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;name&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Total   </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">  </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;total&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Used    </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">  </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;used&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Percent </span><span style="color:#97E1F1;font-style:italic;">float64</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;percent&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">DiskVO</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        Name    </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">  </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;name&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Total   </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">  </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;total&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Used    </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">  </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;used&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Percent </span><span style="color:#97E1F1;font-style:italic;">float64</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;percent&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Indicator</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        Id      </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;id&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Ip      </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;ip&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        UpTime  </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;upTime&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        LoadAvg </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;loadAvg&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Cpu     </span><span style="color:#97E1F1;font-style:italic;">int</span><span style="color:#F6F6F4;">       </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;cpu&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Disk    []Disk    </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;disk&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Stop    </span><span style="color:#F286C4;">chan</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;-&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">IndicatorVO</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">struct</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        Id      </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">   </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;id&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Ip      </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">   </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;ip&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        UpTime  </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">   </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;upTime&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        LoadAvg </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">   </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;loadAvg&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Cpu     </span><span style="color:#97E1F1;font-style:italic;">int64</span><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;cpu&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Disk    []DiskVO </span><span style="color:#DEE492;">\`</span><span style="color:#E7EE98;">json:&quot;disk&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    indicator </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">Indicator{Id: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">001</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Ip: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">127.0.0.1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Cpu: </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">, Disk: []Disk{</span></span>
<span class="line"><span style="color:#F6F6F4;">        {Name: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">disk-001</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Total: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">100</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Used: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Percent: </span><span style="color:#BF9EEE;">10</span><span style="color:#F6F6F4;">},</span></span>
<span class="line"><span style="color:#F6F6F4;">        {Name: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">disk-002</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Total: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">200</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Used: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Percent: </span><span style="color:#BF9EEE;">20</span><span style="color:#F6F6F4;">},</span></span>
<span class="line"><span style="color:#F6F6F4;">        {Name: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">disk-003</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Total: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">300</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Used: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, Percent: </span><span style="color:#BF9EEE;">30</span><span style="color:#F6F6F4;">},</span></span>
<span class="line"><span style="color:#F6F6F4;">    }}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    indicatorVO </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> IndicatorVO{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">CopyProperties</span><span style="color:#F6F6F4;">(</span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">indicatorVO, indicator)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#F286C4;">if</span><span style="color:#F6F6F4;"> err </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;"> {</span></span>
<span class="line"><span style="color:#F6F6F4;">        </span><span style="color:#F286C4;">return</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(indicatorVO.Id)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(indicatorVO.Ip)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">len</span><span style="color:#F6F6F4;">(indicatorVO.Disk))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 001</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 127.0.0.1</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// 3</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Disk</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        Name    </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;name&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Total   </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;total&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Used    </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;used&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Percent </span><span style="color:#AB5959;">float64</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;percent&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">DiskVO</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        Name    </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;name&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Total   </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;total&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Used    </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;used&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Percent </span><span style="color:#AB5959;">float64</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;percent&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Indicator</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        Id      </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;id&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Ip      </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;ip&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        UpTime  </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;upTime&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        LoadAvg </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;loadAvg&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Cpu     </span><span style="color:#AB5959;">int</span><span style="color:#393A34;">       </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;cpu&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Disk    </span><span style="color:#999999;">[]</span><span style="color:#393A34;">Disk    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;disk&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Stop    </span><span style="color:#1E754F;">chan</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;-&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">IndicatorVO</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">struct</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        Id      </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;id&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Ip      </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;ip&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        UpTime  </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;upTime&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        LoadAvg </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;loadAvg&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Cpu     </span><span style="color:#AB5959;">int64</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;cpu&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Disk    </span><span style="color:#999999;">[]</span><span style="color:#393A34;">DiskVO </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;disk&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">indicator</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">Indicator</span><span style="color:#999999;">{</span><span style="color:#393A34;">Id</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">001</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Ip</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">127.0.0.1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Cpu</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Disk</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#393A34;">Disk</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#999999;">{</span><span style="color:#393A34;">Name</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">disk-001</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Total</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">100</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Used</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Percent</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">10</span><span style="color:#999999;">},</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#999999;">{</span><span style="color:#393A34;">Name</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">disk-002</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Total</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">200</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Used</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Percent</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">20</span><span style="color:#999999;">},</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#999999;">{</span><span style="color:#393A34;">Name</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">disk-003</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Total</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">300</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Used</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> Percent</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">30</span><span style="color:#999999;">},</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">indicatorVO</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> IndicatorVO</span><span style="color:#999999;">{}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">CopyProperties</span><span style="color:#999999;">(</span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">indicatorVO</span><span style="color:#999999;">,</span><span style="color:#393A34;"> indicator</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#1E754F;">if</span><span style="color:#393A34;"> err </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        </span><span style="color:#1E754F;">return</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">indicatorVO</span><span style="color:#999999;">.</span><span style="color:#393A34;">Id</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">indicatorVO</span><span style="color:#999999;">.</span><span style="color:#393A34;">Ip</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">len</span><span style="color:#999999;">(</span><span style="color:#393A34;">indicatorVO</span><span style="color:#999999;">.</span><span style="color:#393A34;">Disk</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 001</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 127.0.0.1</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// 3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ToInterface" tabindex="-1"><span id="ToInterface">ToInterface</span> <a class="header-anchor" href="#ToInterface" aria-label="Permalink to &quot;&lt;span id=&quot;ToInterface&quot;&gt;ToInterface&lt;/span&gt;&quot;">​</a></h3><p>Converts reflect value to its interface type.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">ToInterface</span><span style="color:#F6F6F4;">(v reflect.Value) (value </span><span style="color:#F286C4;">interface</span><span style="color:#F6F6F4;">{}, ok </span><span style="color:#97E1F1;font-style:italic;">bool</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">ToInterface</span><span style="color:#999999;">(</span><span style="color:#393A34;">v reflect</span><span style="color:#999999;">.</span><span style="color:#393A34;">Value</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#393A34;">value </span><span style="color:#1E754F;">interface</span><span style="color:#999999;">{},</span><span style="color:#393A34;"> ok </span><span style="color:#AB5959;">bool</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/syqw0-WG7Xd" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    val </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> reflect.</span><span style="color:#97E1F1;">ValueOf</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">abc</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    iVal, ok </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">ToInterface</span><span style="color:#F6F6F4;">(val)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Printf</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#BF9EEE;">%T</span><span style="color:#F286C4;">\\n</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, iVal)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Printf</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#BF9EEE;">%v</span><span style="color:#F286C4;">\\n</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, iVal)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(ok)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// string</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// abc</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true    </span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">val</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> reflect</span><span style="color:#999999;">.</span><span style="color:#998418;">ValueOf</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">abc</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">iVal</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">ok</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">ToInterface</span><span style="color:#999999;">(</span><span style="color:#393A34;">val</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Printf</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#A65E2B;">%T\\n</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> iVal</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Printf</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#A65E2B;">%v\\n</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span><span style="color:#393A34;"> iVal</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">ok</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// string</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// abc</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true    </span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="Utf8ToGbk" tabindex="-1"><span id="Utf8ToGbk">Utf8ToGbk</span> <a class="header-anchor" href="#Utf8ToGbk" aria-label="Permalink to &quot;&lt;span id=&quot;Utf8ToGbk&quot;&gt;Utf8ToGbk&lt;/span&gt;&quot;">​</a></h3><p>Converts utf8 encoding data to GBK encoding data.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">Utf8ToGbk</span><span style="color:#F6F6F4;">(bs []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) ([]</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">Utf8ToGbk</span><span style="color:#999999;">(</span><span style="color:#393A34;">bs </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">([]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/9FlIaFLArIL" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/validator</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    utf8Data </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> []</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F6F6F4;">    gbkData, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">Utf8ToGbk</span><span style="color:#F6F6F4;">(utf8Data)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(utf8.</span><span style="color:#97E1F1;">Valid</span><span style="color:#F6F6F4;">(utf8Data))</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(validator.</span><span style="color:#97E1F1;">IsGBK</span><span style="color:#F6F6F4;">(gbkData))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true   </span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/validator</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">utf8Data</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> </span><span style="color:#999999;">[]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">gbkData</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">Utf8ToGbk</span><span style="color:#999999;">(</span><span style="color:#393A34;">utf8Data</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">utf8</span><span style="color:#999999;">.</span><span style="color:#998418;">Valid</span><span style="color:#999999;">(</span><span style="color:#393A34;">utf8Data</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">validator</span><span style="color:#999999;">.</span><span style="color:#998418;">IsGBK</span><span style="color:#999999;">(</span><span style="color:#393A34;">gbkData</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true   </span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="GbkToUtf8" tabindex="-1"><span id="GbkToUtf8">GbkToUtf8</span> <a class="header-anchor" href="#GbkToUtf8" aria-label="Permalink to &quot;&lt;span id=&quot;GbkToUtf8&quot;&gt;GbkToUtf8&lt;/span&gt;&quot;">​</a></h3><p>Converts GBK encoding data to utf8 encoding data.</p><p><b>Signature:</b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">GbkToUtf8</span><span style="color:#F6F6F4;">(bs []</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">) ([]</span><span style="color:#97E1F1;font-style:italic;">byte</span><span style="color:#F6F6F4;">, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">GbkToUtf8</span><span style="color:#999999;">(</span><span style="color:#393A34;">bs </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">([]</span><span style="color:#AB5959;">byte</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span></code></pre></div><p><b>Example:<span class="run-container"><a href="https://go.dev/play/p/OphmHCN_9u8" target="_blank" rel="noreferrer">Run</a></span></b></p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki dracula-soft vp-code-dark"><code><span class="line"><span style="color:#F286C4;">package</span><span style="color:#F6F6F4;"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">import</span><span style="color:#F6F6F4;"> (</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">fmt</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">main</span><span style="color:#F6F6F4;">() {</span></span>
<span class="line"><span style="color:#F6F6F4;">    gbkData, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">Utf8ToGbk</span><span style="color:#F6F6F4;">([]</span><span style="color:#97E1F1;">byte</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">hello</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">    utf8Data, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> convertor.</span><span style="color:#97E1F1;">GbkToUtf8</span><span style="color:#F6F6F4;">(gbkData)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(utf8.</span><span style="color:#97E1F1;">Valid</span><span style="color:#F6F6F4;">(utf8Data))</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(</span><span style="color:#97E1F1;">string</span><span style="color:#F6F6F4;">(utf8Data))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// Output:</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// true</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// hello   </span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">package</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">import</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">fmt</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B5695999;">&quot;</span><span style="color:#59873A;">github.com/duke-git/lancet/v2/convertor</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">main</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">gbkData</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">Utf8ToGbk</span><span style="color:#999999;">([]</span><span style="color:#998418;">byte</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">hello</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">utf8Data</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">_</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> convertor</span><span style="color:#999999;">.</span><span style="color:#998418;">GbkToUtf8</span><span style="color:#999999;">(</span><span style="color:#393A34;">gbkData</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">utf8</span><span style="color:#999999;">.</span><span style="color:#998418;">Valid</span><span style="color:#999999;">(</span><span style="color:#393A34;">utf8Data</span><span style="color:#999999;">))</span></span>
<span class="line"><span style="color:#393A34;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#998418;">string</span><span style="color:#999999;">(</span><span style="color:#393A34;">utf8Data</span><span style="color:#999999;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// Output:</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// true</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// hello   </span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div>`,128),g=[t,c,r,y,F,i,u,A,E,d,B];function q(f,v,h,m,D,b){return p(),o("div",null,g)}const T=l(e,[["render",q]]);export{k as __pageData,T as default};
