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":"Netutil","description":"","frontmatter":{},"headers":[],"relativePath":"api/packages/netutil.md","filePath":"api/packages/netutil.md"}'),e={name:"api/packages/netutil.md"},t=s("h1",{id:"Netutil",tabindex:"-1"},[a("Netutil "),s("a",{class:"header-anchor",href:"#Netutil","aria-label":'Permalink to "Netutil"'},"​")],-1),c=s("p",null,"netutil 网络包支持获取 ip 地址，发送 http 请求。",-1),r=s("div",{STYLE:"page-break-after: always;"},null,-1),y=s("h2",{id:"源码-",tabindex:"-1"},[a("源码: "),s("a",{class:"header-anchor",href:"#源码-","aria-label":'Permalink to "源码:"'},"​")],-1),F=s("ul",null,[s("li",null,[s("p",null,[s("a",{href:"https://github.com/duke-git/lancet/blob/main/netutil/net.go",target:"_blank",rel:"noreferrer"},"https://github.com/duke-git/lancet/blob/main/netutil/net.go")])]),s("li",null,[s("p",null,[s("a",{href:"https://github.com/duke-git/lancet/blob/main/netutil/http.go",target:"_blank",rel:"noreferrer"},"https://github.com/duke-git/lancet/blob/main/netutil/http.go")])])],-1),i=s("div",{STYLE:"page-break-after: always;"},null,-1),u=n(`<h2 id="用法-" tabindex="-1">用法: <a class="header-anchor" href="#用法-" aria-label="Permalink to &quot;用法:&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/netutil</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/netutil</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#999999;">)</span></span></code></pre></div>`,2),E=s("div",{STYLE:"page-break-after: always;"},null,-1),A=n('<h2 id="目录" tabindex="-1">目录 <a class="header-anchor" href="#目录" aria-label="Permalink to &quot;目录&quot;">​</a></h2><ul><li><a href="#ConvertMapToQueryString">ConvertMapToQueryString</a></li><li><a href="#EncodeUrl">EncodeUrl</a></li><li><a href="#GetInternalIp">GetInternalIp</a></li><li><a href="#GetIps">GetIps</a></li><li><a href="#GetMacAddrs">GetMacAddrs</a></li><li><a href="#GetPublicIpInfo">GetPublicIpInfo</a></li><li><a href="#GetRequestPublicIp">GetRequestPublicIp</a></li><li><a href="#IsPublicIP">IsPublicIP</a></li><li><a href="#IsInternalIP">IsInternalIP</a></li><li><a href="#HttpRequest">HttpRequest</a></li><li><a href="#HttpClient">HttpClient</a></li><li><a href="#SendRequest">SendRequest</a></li><li><a href="#DecodeResponse">DecodeResponse</a></li><li><a href="#StructToUrlValues">StructToUrlValues</a></li><li><a href="#HttpGet">HttpGet<sup>Deprecated</sup></a></li><li><a href="#HttpDelete">HttpDelete<sup>Deprecated</sup></a></li><li><a href="#HttpPost">HttpPost<sup>Deprecated</sup></a></li><li><a href="#HttpPut">HttpPut<sup>Deprecated</sup></a></li><li><a href="#HttpPatch">HttpPatch<sup>Deprecated</sup></a></li><li><a href="#ParseHttpResponse">ParseHttpResponse</a></li><li><a href="#DownloadFile">DownloadFile</a></li><li><a href="#UploadFile">UploadFile</a></li><li><a href="#IsPingConnected">IsPingConnected</a></li><li><a href="#IsTelnetConnected">IsTelnetConnected</a></li></ul>',2),d=s("div",{STYLE:"page-break-after: always;"},null,-1),q=n(`<link rel="stylesheet" type="text/css" href="/styles/api_doc.css"><h2 id="文档" tabindex="-1">文档 <a class="header-anchor" href="#文档" aria-label="Permalink to &quot;文档&quot;">​</a></h2><h3 id="ConvertMapToQueryString" tabindex="-1"><span id="ConvertMapToQueryString">ConvertMapToQueryString</span> <a class="header-anchor" href="#ConvertMapToQueryString" aria-label="Permalink to &quot;&lt;span id=&quot;ConvertMapToQueryString&quot;&gt;ConvertMapToQueryString&lt;/span&gt;&quot;">​</a></h3><p>将map转换成http查询字符串.</p><p><b>函数签名:</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;">ConvertMapToQueryString</span><span style="color:#F6F6F4;">(param </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;">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;">ConvertMapToQueryString</span><span style="color:#999999;">(</span><span style="color:#393A34;">param </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;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/jnNt_qoSnRi" target="_blank" rel="noreferrer">运行</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/netutil</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;"> m </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;">]any{</span></span>
<span class="line"><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;">        </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;">    qs </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">ConvertMapToQueryString</span><span style="color:#F6F6F4;">(m)</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;">(qs)</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;">// a=1&amp;b=2&amp;c=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/netutil</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;">m</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:#393A34;">any</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;">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:#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:#B07D48;">qs</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">ConvertMapToQueryString</span><span style="color:#999999;">(</span><span style="color:#393A34;">m</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;">qs</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;">// a=1&amp;b=2&amp;c=3</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="EncodeUrl" tabindex="-1"><span id="EncodeUrl">EncodeUrl</span> <a class="header-anchor" href="#EncodeUrl" aria-label="Permalink to &quot;&lt;span id=&quot;EncodeUrl&quot;&gt;EncodeUrl&lt;/span&gt;&quot;">​</a></h3><p>编码url query string的值</p><p><b>函数签名:</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;">EncodeUrl</span><span style="color:#F6F6F4;">(urlStr </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 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;">EncodeUrl</span><span style="color:#999999;">(</span><span style="color:#393A34;">urlStr </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 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>示例:<span class="run-container"><a href="https://go.dev/play/p/bsZ6BRC4uKI" target="_blank" rel="noreferrer">运行</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/netutil</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;">    urlAddr </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">http://www.lancet.com?a=1&amp;b=[2]</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    encodedUrl, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">EncodeUrl</span><span style="color:#F6F6F4;">(urlAddr)</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;">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;">(encodedUrl)</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;">// http://www.lancet.com?a=1&amp;b=%5B2%5D</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/netutil</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;">urlAddr</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;">http://www.lancet.com?a=1&amp;b=[2]</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">encodedUrl</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">EncodeUrl</span><span style="color:#999999;">(</span><span style="color:#393A34;">urlAddr</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;">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;">encodedUrl</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;">// http://www.lancet.com?a=1&amp;b=%5B2%5D</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="GetInternalIp" tabindex="-1"><span id="GetInternalIp">GetInternalIp</span> <a class="header-anchor" href="#GetInternalIp" aria-label="Permalink to &quot;&lt;span id=&quot;GetInternalIp&quot;&gt;GetInternalIp&lt;/span&gt;&quot;">​</a></h3><p>获取内部ip</p><p><b>函数签名:</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;">GetInternalIp</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;">GetInternalIp</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/fxnna_LLD9u" target="_blank" rel="noreferrer">运行</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;">net</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/netutil</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;">    internalIp </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">GetInternalIp</span><span style="color:#F6F6F4;">()</span></span>
<span class="line"><span style="color:#F6F6F4;">    ip </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> net.</span><span style="color:#97E1F1;">ParseIP</span><span style="color:#F6F6F4;">(internalIp)</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;">(ip)</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;">// 192.168.1.9</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;">net</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/netutil</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;">internalIp</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">GetInternalIp</span><span style="color:#999999;">()</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">ip</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> net</span><span style="color:#999999;">.</span><span style="color:#998418;">ParseIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">internalIp</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;">ip</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;">// 192.168.1.9</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="GetIps" tabindex="-1"><span id="GetIps">GetIps</span> <a class="header-anchor" href="#GetIps" aria-label="Permalink to &quot;&lt;span id=&quot;GetIps&quot;&gt;GetIps&lt;/span&gt;&quot;">​</a></h3><p>获取ipv4地址列表</p><p><b>函数签名:</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;">GetIps</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;">GetIps</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>示例:<span class="run-container"><a href="https://go.dev/play/p/NUFfcEmukx1" target="_blank" rel="noreferrer">运行</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;">net</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/netutil</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;">    ips </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">GetIps</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;">(ips)</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;">// [192.168.1.9]</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;">net</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/netutil</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;">ips</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">GetIps</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;">ips</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;">// [192.168.1.9]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="GetMacAddrs" tabindex="-1"><span id="GetMacAddrs">GetMacAddrs</span> <a class="header-anchor" href="#GetMacAddrs" aria-label="Permalink to &quot;&lt;span id=&quot;GetMacAddrs&quot;&gt;GetMacAddrs&lt;/span&gt;&quot;">​</a></h3><p>获取mac地址列</p><p><b>函数签名:</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;">GetMacAddrs</span><span style="color:#F6F6F4;">() []</span><span style="color:#97E1F1;font-style:italic;">string</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;">GetMacAddrs</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:#393A34;"> </span><span style="color:#999999;">{</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/Rq9UUBS_Xp1" target="_blank" rel="noreferrer">运行</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;">net</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/netutil</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;">    macAddrs </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">GetMacAddrs</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;">(macAddrs)</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;">// [18:31:bf:09:d1:56 76:ee:2a:e6:2e:0f 74:ee:2a:e6:2e:0f 74:ee:2a:e6:2e:0f]</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;">net</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/netutil</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;">macAddrs</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">GetMacAddrs</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;">macAddrs</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;">// [18:31:bf:09:d1:56 76:ee:2a:e6:2e:0f 74:ee:2a:e6:2e:0f 74:ee:2a:e6:2e:0f]</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="GetPublicIpInfo" tabindex="-1"><span id="GetPublicIpInfo">GetPublicIpInfo</span> <a class="header-anchor" href="#GetPublicIpInfo" aria-label="Permalink to &quot;&lt;span id=&quot;GetPublicIpInfo&quot;&gt;GetPublicIpInfo&lt;/span&gt;&quot;">​</a></h3><p>获取公网ip信息</p><p><b>函数签名:</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;">GetPublicIpInfo</span><span style="color:#F6F6F4;">() (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">PublicIpInfo, </span><span style="color:#97E1F1;font-style:italic;">error</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">PublicIpInfo</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;">    Status      </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;status&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    Country     </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;country&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    CountryCode </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;countryCode&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    Region      </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;region&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    RegionName  </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;regionName&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    City        </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;city&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    Lat         </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;lat&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    Lon         </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;lon&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    Isp         </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;isp&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    Org         </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;org&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    As          </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;as&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;query&quot;</span><span style="color:#DEE492;">\`</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;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">GetPublicIpInfo</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">PublicIpInfo</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">PublicIpInfo</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;">    Status      </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;status&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    Country     </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;country&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    CountryCode </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;countryCode&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    Region      </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;region&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    RegionName  </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;regionName&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    City        </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;city&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    Lat         </span><span style="color:#AB5959;">float64</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;lat&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    Lon         </span><span style="color:#AB5959;">float64</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;lon&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    Isp         </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;isp&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    Org         </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;org&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">    As          </span><span style="color:#AB5959;">string</span><span style="color:#393A34;">  </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;as&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;query&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/YDxIfozsRHR" target="_blank" rel="noreferrer">运行</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/netutil</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;">    publicIpInfo, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">GetPublicIpInfo</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;">(publicIpInfo)</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/netutil</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;">publicIpInfo</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">GetPublicIpInfo</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;">publicIpInfo</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="GetRequestPublicIp" tabindex="-1"><span id="GetRequestPublicIp">GetRequestPublicIp</span> <a class="header-anchor" href="#GetRequestPublicIp" aria-label="Permalink to &quot;&lt;span id=&quot;GetRequestPublicIp&quot;&gt;GetRequestPublicIp&lt;/span&gt;&quot;">​</a></h3><p>获取http请求ip</p><p><b>函数签名:</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;">GetRequestPublicIp</span><span style="color:#F6F6F4;">(req </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Request) </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;">GetRequestPublicIp</span><span style="color:#999999;">(</span><span style="color:#393A34;">req </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Request</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">string</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/kxU-YDc_eBo" target="_blank" rel="noreferrer">运行</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/netutil</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;">    ip </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">36.112.24.10</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    request </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> http.Request{</span></span>
<span class="line"><span style="color:#F6F6F4;">        Method: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">GET</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        Header: http.Header{</span></span>
<span class="line"><span style="color:#F6F6F4;">            </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">X-Forwarded-For</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: {ip},</span></span>
<span class="line"><span style="color:#F6F6F4;">        },</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    publicIp </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">GetRequestPublicIp</span><span style="color:#F6F6F4;">(</span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">request)</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;">(publicIp)</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;">// 36.112.24.10</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/netutil</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;">ip</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;">36.112.24.10</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">request</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Request</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        Method</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">GET</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        Header</span><span style="color:#999999;">:</span><span style="color:#393A34;"> http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Header</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;">X-Forwarded-For</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </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;">        </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;">publicIp</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">GetRequestPublicIp</span><span style="color:#999999;">(</span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">request</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;">publicIp</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;">// 36.112.24.10</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsPublicIP" tabindex="-1"><span id="IsPublicIP">IsPublicIP</span> <a class="header-anchor" href="#IsPublicIP" aria-label="Permalink to &quot;&lt;span id=&quot;IsPublicIP&quot;&gt;IsPublicIP&lt;/span&gt;&quot;">​</a></h3><p>判断ip是否是公共ip</p><p><b>函数签名:</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;">IsPublicIP</span><span style="color:#F6F6F4;">(IP net.IP) </span><span style="color:#97E1F1;font-style:italic;">bool</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;">IsPublicIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">IP net</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:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/nmktSQpJZnn" target="_blank" rel="noreferrer">运行</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;">net</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/netutil</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;">    ip1 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">IsPublicIP</span><span style="color:#F6F6F4;">(net.</span><span style="color:#97E1F1;">ParseIP</span><span style="color:#F6F6F4;">(</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;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">    ip2 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">IsPublicIP</span><span style="color:#F6F6F4;">(net.</span><span style="color:#97E1F1;">ParseIP</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">192.168.0.1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">    ip3 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">IsPublicIP</span><span style="color:#F6F6F4;">(net.</span><span style="color:#97E1F1;">ParseIP</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">36.112.24.10</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;">(ip1)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(ip2)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(ip3)</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;">// 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;">// 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;">net</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/netutil</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;">ip1</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsPublicIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">net</span><span style="color:#999999;">.</span><span style="color:#998418;">ParseIP</span><span style="color:#999999;">(</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>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">ip2</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsPublicIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">net</span><span style="color:#999999;">.</span><span style="color:#998418;">ParseIP</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">192.168.0.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;">ip3</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsPublicIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">net</span><span style="color:#999999;">.</span><span style="color:#998418;">ParseIP</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">36.112.24.10</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;">ip1</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;">ip2</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;">ip3</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;">// 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;">// true</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsInternalIP" tabindex="-1"><span id="IsInternalIP">IsInternalIP</span> <a class="header-anchor" href="#IsInternalIP" aria-label="Permalink to &quot;&lt;span id=&quot;IsInternalIP&quot;&gt;IsInternalIP&lt;/span&gt;&quot;">​</a></h3><p>判断ip是否是局域网ip.</p><p><b>函数签名:</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;">IsInternalIP</span><span style="color:#F6F6F4;">(IP net.IP) </span><span style="color:#97E1F1;font-style:italic;">bool</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;">IsInternalIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">IP net</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:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/sYGhXbgO4Cb" target="_blank" rel="noreferrer">运行</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;">net</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/netutil</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;">    ip1 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">IsInternalIP</span><span style="color:#F6F6F4;">(net.</span><span style="color:#97E1F1;">ParseIP</span><span style="color:#F6F6F4;">(</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;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">    ip2 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">IsInternalIP</span><span style="color:#F6F6F4;">(net.</span><span style="color:#97E1F1;">ParseIP</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">192.168.0.1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">))</span></span>
<span class="line"><span style="color:#F6F6F4;">    ip3 </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">IsInternalIP</span><span style="color:#F6F6F4;">(net.</span><span style="color:#97E1F1;">ParseIP</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">36.112.24.10</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;">(ip1)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(ip2)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(ip3)</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;">// 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;">net</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/netutil</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;">ip1</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsInternalIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">net</span><span style="color:#999999;">.</span><span style="color:#998418;">ParseIP</span><span style="color:#999999;">(</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>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">ip2</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsInternalIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">net</span><span style="color:#999999;">.</span><span style="color:#998418;">ParseIP</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">192.168.0.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;">ip3</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsInternalIP</span><span style="color:#999999;">(</span><span style="color:#393A34;">net</span><span style="color:#999999;">.</span><span style="color:#998418;">ParseIP</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">36.112.24.10</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;">ip1</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;">ip2</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;">ip3</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;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HttpRequest" tabindex="-1"><span id="HttpRequest">HttpRequest</span> <a class="header-anchor" href="#HttpRequest" aria-label="Permalink to &quot;&lt;span id=&quot;HttpRequest&quot;&gt;HttpRequest&lt;/span&gt;&quot;">​</a></h3><p>HttpRequest用于抽象HTTP请求实体的结构</p><p><b>函数签名:</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;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">HttpRequest</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;">    RawURL      </span><span style="color:#97E1F1;font-style:italic;">string</span></span>
<span class="line"><span style="color:#F6F6F4;">    Method      </span><span style="color:#97E1F1;font-style:italic;">string</span></span>
<span class="line"><span style="color:#F6F6F4;">    Headers     http.Header</span></span>
<span class="line"><span style="color:#F6F6F4;">    QueryParams url.Values</span></span>
<span class="line"><span style="color:#F6F6F4;">    FormData    url.Values</span></span>
<span class="line"><span style="color:#F6F6F4;">    Body        []</span><span style="color:#97E1F1;font-style:italic;">byte</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;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">HttpRequest</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;">    RawURL      </span><span style="color:#AB5959;">string</span></span>
<span class="line"><span style="color:#393A34;">    Method      </span><span style="color:#AB5959;">string</span></span>
<span class="line"><span style="color:#393A34;">    Headers     http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Header</span></span>
<span class="line"><span style="color:#393A34;">    QueryParams url</span><span style="color:#999999;">.</span><span style="color:#393A34;">Values</span></span>
<span class="line"><span style="color:#393A34;">    FormData    url</span><span style="color:#999999;">.</span><span style="color:#393A34;">Values</span></span>
<span class="line"><span style="color:#393A34;">    Body        </span><span style="color:#999999;">[]</span><span style="color:#AB5959;">byte</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/jUSgynekH7G" target="_blank" rel="noreferrer">运行</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;">net</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/netutil</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;">    header </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> http.Header{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    header.</span><span style="color:#97E1F1;">Add</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">Content-Type</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">multipart/form-data</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    postData </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> url.Values{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    postData.</span><span style="color:#97E1F1;">Add</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">userId</span><span style="color:#DEE492;">&quot;</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;">    postData.</span><span style="color:#97E1F1;">Add</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">title</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">testItem</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    request </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">netutil.HttpRequest{</span></span>
<span class="line"><span style="color:#F6F6F4;">        RawURL:   </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        Method:   </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">POST</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        Headers:  header,</span></span>
<span class="line"><span style="color:#F6F6F4;">        FormData: postData,</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</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;">net</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/netutil</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;">header</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Header</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    header</span><span style="color:#999999;">.</span><span style="color:#998418;">Add</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">Content-Type</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;">multipart/form-data</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:#B07D48;">postData</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> url</span><span style="color:#999999;">.</span><span style="color:#393A34;">Values</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    postData</span><span style="color:#999999;">.</span><span style="color:#998418;">Add</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">userId</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;">1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    postData</span><span style="color:#999999;">.</span><span style="color:#998418;">Add</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">title</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;">testItem</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:#B07D48;">request</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;">netutil</span><span style="color:#999999;">.</span><span style="color:#393A34;">HttpRequest</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        RawURL</span><span style="color:#999999;">:</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">https://jsonplaceholder.typicode.com/todos</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        Method</span><span style="color:#999999;">:</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">POST</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        Headers</span><span style="color:#999999;">:</span><span style="color:#393A34;">  header</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        FormData</span><span style="color:#999999;">:</span><span style="color:#393A34;"> postData</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:#999999;">}</span></span></code></pre></div><h3 id="HttpClient" tabindex="-1"><span id="HttpClient">HttpClient</span> <a class="header-anchor" href="#HttpClient" aria-label="Permalink to &quot;&lt;span id=&quot;HttpClient&quot;&gt;HttpClient&lt;/span&gt;&quot;">​</a></h3><p>HttpClient是用于发送HTTP请求的结构体。它可以用一些配置参数或无配置实例化.</p><p><b>函数签名:</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;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">HttpClient</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;">    </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Client</span></span>
<span class="line"><span style="color:#F6F6F4;">    TLS     </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">tls.Config</span></span>
<span class="line"><span style="color:#F6F6F4;">    Request </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Request</span></span>
<span class="line"><span style="color:#F6F6F4;">    Config  HttpClientConfig</span></span>
<span class="line"><span style="color:#F6F6F4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">HttpClientConfig</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;">    SSLEnabled       </span><span style="color:#97E1F1;font-style:italic;">bool</span></span>
<span class="line"><span style="color:#F6F6F4;">    TLSConfig        </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">tls.Config</span></span>
<span class="line"><span style="color:#F6F6F4;">    Compressed       </span><span style="color:#97E1F1;font-style:italic;">bool</span></span>
<span class="line"><span style="color:#F6F6F4;">    HandshakeTimeout time.Duration</span></span>
<span class="line"><span style="color:#F6F6F4;">    ResponseTimeout  time.Duration</span></span>
<span class="line"><span style="color:#F6F6F4;">    Verbose          </span><span style="color:#97E1F1;font-style:italic;">bool</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;">NewHttpClient</span><span style="color:#F6F6F4;">() </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">HttpClient</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">NewHttpClientWithConfig</span><span style="color:#F6F6F4;">(config </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">HttpClientConfig) </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">HttpClient</span></span></code></pre><pre class="shiki vitesse-light vp-code-light"><code><span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">HttpClient</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;">    </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Client</span></span>
<span class="line"><span style="color:#393A34;">    TLS     </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">tls</span><span style="color:#999999;">.</span><span style="color:#393A34;">Config</span></span>
<span class="line"><span style="color:#393A34;">    Request </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Request</span></span>
<span class="line"><span style="color:#393A34;">    Config  HttpClientConfig</span></span>
<span class="line"><span style="color:#999999;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">HttpClientConfig</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;">    SSLEnabled       </span><span style="color:#AB5959;">bool</span></span>
<span class="line"><span style="color:#393A34;">    TLSConfig        </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">tls</span><span style="color:#999999;">.</span><span style="color:#393A34;">Config</span></span>
<span class="line"><span style="color:#393A34;">    Compressed       </span><span style="color:#AB5959;">bool</span></span>
<span class="line"><span style="color:#393A34;">    HandshakeTimeout time</span><span style="color:#999999;">.</span><span style="color:#393A34;">Duration</span></span>
<span class="line"><span style="color:#393A34;">    ResponseTimeout  time</span><span style="color:#999999;">.</span><span style="color:#393A34;">Duration</span></span>
<span class="line"><span style="color:#393A34;">    Verbose          </span><span style="color:#AB5959;">bool</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;">NewHttpClient</span><span style="color:#999999;">()</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">HttpClient</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">NewHttpClientWithConfig</span><span style="color:#999999;">(</span><span style="color:#393A34;">config </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">HttpClientConfig</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">HttpClient</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/jUSgynekH7G" target="_blank" rel="noreferrer">运行</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;">net</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;">time</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/netutil</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;">    httpClientCfg </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.HttpClientConfig{</span></span>
<span class="line"><span style="color:#F6F6F4;">        SSLEnabled: </span><span style="color:#BF9EEE;">true</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        HandshakeTimeout:</span><span style="color:#BF9EEE;">10</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;"> time.Second</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    httpClient </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">NewHttpClientWithConfig</span><span style="color:#F6F6F4;">(</span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">httpClientCfg)</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;">net</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;">time</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/netutil</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;">httpClientCfg</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#393A34;">HttpClientConfig</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        SSLEnabled</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;">        HandshakeTimeout</span><span style="color:#999999;">:</span><span style="color:#2F798A;">10</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">*</span><span style="color:#393A34;"> time</span><span style="color:#999999;">.</span><span style="color:#393A34;">Second</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;">httpClient</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">NewHttpClientWithConfig</span><span style="color:#999999;">(</span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">httpClientCfg</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="SendRequest" tabindex="-1"><span id="SendRequest">SendRequest</span> <a class="header-anchor" href="#SendRequest" aria-label="Permalink to &quot;&lt;span id=&quot;SendRequest&quot;&gt;SendRequest&lt;/span&gt;&quot;">​</a></h3><p>HttpClient发送http请求</p><p><b>函数签名:</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;"> (client </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">HttpClient) </span><span style="color:#62E884;">SendRequest</span><span style="color:#F6F6F4;">(request </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">HttpRequest) (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Response, </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:#999999;">(</span><span style="color:#393A34;">client </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">HttpClient</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">SendRequest</span><span style="color:#999999;">(</span><span style="color:#393A34;">request </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">HttpRequest</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Response</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>示例:<span class="run-container"><a href="https://go.dev/play/p/jUSgynekH7G" target="_blank" rel="noreferrer">运行</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;">net</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;">time</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/netutil</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;">    request </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">netutil.HttpRequest{</span></span>
<span class="line"><span style="color:#F6F6F4;">        RawURL: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        Method: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">GET</span><span style="color:#DEE492;">&quot;</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;">    httpClient </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">NewHttpClient</span><span style="color:#F6F6F4;">()</span></span>
<span class="line"><span style="color:#F6F6F4;">    resp, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> httpClient.</span><span style="color:#97E1F1;">SendRequest</span><span style="color:#F6F6F4;">(request)</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 style="color:#F286C4;">||</span><span style="color:#F6F6F4;"> resp.StatusCode </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">200</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;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Todo</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;">        UserId    </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;userId&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Id        </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;id&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Title     </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;title&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Completed </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;completed&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;">var</span><span style="color:#F6F6F4;"> todo Todo</span></span>
<span class="line"><span style="color:#F6F6F4;">    err </span><span style="color:#F286C4;">=</span><span style="color:#F6F6F4;"> httpClient.</span><span style="color:#97E1F1;">DecodeResponse</span><span style="color:#F6F6F4;">(resp, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">todo)</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;">(todo.Id)</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></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;">net</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;">time</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/netutil</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;">request</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;">netutil</span><span style="color:#999999;">.</span><span style="color:#393A34;">HttpRequest</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        RawURL</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        Method</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">GET</span><span style="color:#B5695999;">&quot;</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;">httpClient</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">NewHttpClient</span><span style="color:#999999;">()</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">resp</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;"> httpClient</span><span style="color:#999999;">.</span><span style="color:#998418;">SendRequest</span><span style="color:#999999;">(</span><span style="color:#393A34;">request</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:#AB5959;">||</span><span style="color:#393A34;"> resp</span><span style="color:#999999;">.</span><span style="color:#393A34;">StatusCode </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">200</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;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Todo</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;">        UserId    </span><span style="color:#AB5959;">int</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;userId&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Id        </span><span style="color:#AB5959;">int</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;">        Title     </span><span style="color:#AB5959;">string</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;title&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Completed </span><span style="color:#AB5959;">bool</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;completed&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;">var</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">todo</span><span style="color:#393A34;"> Todo</span></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;"> httpClient</span><span style="color:#999999;">.</span><span style="color:#998418;">DecodeResponse</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">todo</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;">todo</span><span style="color:#999999;">.</span><span style="color:#393A34;">Id</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:#999999;">}</span></span></code></pre></div><h3 id="DecodeResponse" tabindex="-1"><span id="DecodeResponse">DecodeResponse</span> <a class="header-anchor" href="#DecodeResponse" aria-label="Permalink to &quot;&lt;span id=&quot;DecodeResponse&quot;&gt;DecodeResponse&lt;/span&gt;&quot;">​</a></h3><p>解析http响应体到目标结构体</p><p><b>函数签名:</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;"> (client </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">HttpClient) </span><span style="color:#62E884;">DecodeResponse</span><span style="color:#F6F6F4;">(resp </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Response, 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:#999999;">(</span><span style="color:#393A34;">client </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">HttpClient</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#59873A;">DecodeResponse</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Response</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>示例:<span class="run-container"><a href="https://go.dev/play/p/jUSgynekH7G" target="_blank" rel="noreferrer">运行</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;">net</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;">time</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/netutil</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;">    request </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">netutil.HttpRequest{</span></span>
<span class="line"><span style="color:#F6F6F4;">        RawURL: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        Method: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">GET</span><span style="color:#DEE492;">&quot;</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;">    httpClient </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">NewHttpClient</span><span style="color:#F6F6F4;">()</span></span>
<span class="line"><span style="color:#F6F6F4;">    resp, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> httpClient.</span><span style="color:#97E1F1;">SendRequest</span><span style="color:#F6F6F4;">(request)</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 style="color:#F286C4;">||</span><span style="color:#F6F6F4;"> resp.StatusCode </span><span style="color:#F286C4;">!=</span><span style="color:#F6F6F4;"> </span><span style="color:#BF9EEE;">200</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;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Todo</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;">        UserId    </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;userId&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Id        </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;id&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Title     </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;title&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Completed </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;completed&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;">var</span><span style="color:#F6F6F4;"> todo Todo</span></span>
<span class="line"><span style="color:#F6F6F4;">    err </span><span style="color:#F286C4;">=</span><span style="color:#F6F6F4;"> httpClient.</span><span style="color:#97E1F1;">DecodeResponse</span><span style="color:#F6F6F4;">(resp, </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">todo)</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;">(todo.Id)</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></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;">net</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;">time</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/netutil</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;">request</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;">netutil</span><span style="color:#999999;">.</span><span style="color:#393A34;">HttpRequest</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        RawURL</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        Method</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">GET</span><span style="color:#B5695999;">&quot;</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;">httpClient</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">NewHttpClient</span><span style="color:#999999;">()</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">resp</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;"> httpClient</span><span style="color:#999999;">.</span><span style="color:#998418;">SendRequest</span><span style="color:#999999;">(</span><span style="color:#393A34;">request</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:#AB5959;">||</span><span style="color:#393A34;"> resp</span><span style="color:#999999;">.</span><span style="color:#393A34;">StatusCode </span><span style="color:#AB5959;">!=</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">200</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;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Todo</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;">        UserId    </span><span style="color:#AB5959;">int</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;userId&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Id        </span><span style="color:#AB5959;">int</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;">        Title     </span><span style="color:#AB5959;">string</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;title&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Completed </span><span style="color:#AB5959;">bool</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;completed&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;">var</span><span style="color:#393A34;"> </span><span style="color:#B07D48;">todo</span><span style="color:#393A34;"> Todo</span></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;"> httpClient</span><span style="color:#999999;">.</span><span style="color:#998418;">DecodeResponse</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">&amp;</span><span style="color:#393A34;">todo</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;">todo</span><span style="color:#999999;">.</span><span style="color:#393A34;">Id</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:#999999;">}</span></span></code></pre></div><h3 id="StructToUrlValues" tabindex="-1"><span id="StructToUrlValues">StructToUrlValues</span> <a class="header-anchor" href="#StructToUrlValues" aria-label="Permalink to &quot;&lt;span id=&quot;StructToUrlValues&quot;&gt;StructToUrlValues&lt;/span&gt;&quot;">​</a></h3><p>将结构体转为url values, 仅转化结构体导出字段并且包含\`json\` tag</p><p><b>函数签名:</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;">StructToUrlValues</span><span style="color:#F6F6F4;">(targetStruct any) url.Values</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;">StructToUrlValues</span><span style="color:#999999;">(</span><span style="color:#393A34;">targetStruct any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> url</span><span style="color:#999999;">.</span><span style="color:#393A34;">Values</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/pFqMkM40w9z" target="_blank" rel="noreferrer">运行</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/netutil</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;">TodoQuery</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;">int</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;">        UserId </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;userId&quot;</span><span style="color:#DEE492;">\`</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,omitempty&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Status </span><span style="color:#97E1F1;font-style:italic;">string</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    item </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> TodoQuery{</span></span>
<span class="line"><span style="color:#F6F6F4;">        Id:     </span><span style="color:#BF9EEE;">1</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        UserId: </span><span style="color:#BF9EEE;">123</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;">test</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">        Status: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">completed</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">,</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    queryValues </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">StructToUrlValues</span><span style="color:#F6F6F4;">(item)</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;">(todoValues.</span><span style="color:#97E1F1;">Get</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">id</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;">(todoValues.</span><span style="color:#97E1F1;">Get</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">userId</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;">(todoValues.</span><span style="color:#97E1F1;">Get</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">name</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;">(todoValues.</span><span style="color:#97E1F1;">Get</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">status</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:#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;">// 123</span></span>
<span class="line"><span style="color:#F6F6F4;">    </span><span style="color:#7B7F8B;">// test</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></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/netutil</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;">TodoQuery</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;">int</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;">        UserId </span><span style="color:#AB5959;">int</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;userId&quot;</span><span style="color:#B5695999;">\`</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,omitempty&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Status </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 style="color:#393A34;">    </span><span style="color:#B07D48;">item</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> TodoQuery</span><span style="color:#999999;">{</span></span>
<span class="line"><span style="color:#393A34;">        Id</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;">        UserId</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#2F798A;">123</span><span style="color:#999999;">,</span></span>
<span class="line"><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;">test</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">,</span></span>
<span class="line"><span style="color:#393A34;">        Status</span><span style="color:#999999;">:</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">completed</span><span style="color:#B5695999;">&quot;</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;">queryValues</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">StructToUrlValues</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;">    fmt</span><span style="color:#999999;">.</span><span style="color:#998418;">Println</span><span style="color:#999999;">(</span><span style="color:#393A34;">todoValues</span><span style="color:#999999;">.</span><span style="color:#998418;">Get</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">id</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;">todoValues</span><span style="color:#999999;">.</span><span style="color:#998418;">Get</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">userId</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;">todoValues</span><span style="color:#999999;">.</span><span style="color:#998418;">Get</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">name</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;">todoValues</span><span style="color:#999999;">.</span><span style="color:#998418;">Get</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">status</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:#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;">// 123</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">// test</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#A0ADA0;">//</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HttpGet" tabindex="-1"><span id="HttpGet">HttpGet</span> <a class="header-anchor" href="#HttpGet" aria-label="Permalink to &quot;&lt;span id=&quot;HttpGet&quot;&gt;HttpGet&lt;/span&gt;&quot;">​</a></h3><p>发送http get请求。(已废弃:使用SendRequest)</p><p><b>函数签名:</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:#7B7F8B;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HttpGet</span><span style="color:#F6F6F4;">(url </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, params </span><span style="color:#F286C4;">...</span><span style="color:#F6F6F4;">any) (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Response, </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:#A0ADA0;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HttpGet</span><span style="color:#999999;">(</span><span style="color:#393A34;">url </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> params </span><span style="color:#AB5959;">...</span><span style="color:#393A34;">any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Response</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>示例:</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;">io/ioutil</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;">log</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/netutil</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;">    url </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    header </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;">string</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;">Content-Type</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">application/json</span><span style="color:#DEE492;">&quot;</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;">    resp, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">HttpGet</span><span style="color:#F6F6F4;">(url, header)</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;">        log.</span><span style="color:#97E1F1;">Fatal</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;">    body, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> ioutil.</span><span style="color:#97E1F1;">ReadAll</span><span style="color:#F6F6F4;">(resp.Body)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(body)</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;">io/ioutil</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;">log</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/netutil</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;">url</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;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">header</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;">string</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;">Content-Type</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;">application/json</span><span style="color:#B5695999;">&quot;</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;">resp</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">HttpGet</span><span style="color:#999999;">(</span><span style="color:#393A34;">url</span><span style="color:#999999;">,</span><span style="color:#393A34;"> header</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;">        log</span><span style="color:#999999;">.</span><span style="color:#998418;">Fatal</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;">    </span><span style="color:#B07D48;">body</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;"> ioutil</span><span style="color:#999999;">.</span><span style="color:#998418;">ReadAll</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp</span><span style="color:#999999;">.</span><span style="color:#393A34;">Body</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;">body</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HttpPost" tabindex="-1"><span id="HttpPost">HttpPost</span> <a class="header-anchor" href="#HttpPost" aria-label="Permalink to &quot;&lt;span id=&quot;HttpPost&quot;&gt;HttpPost&lt;/span&gt;&quot;">​</a></h3><p>发送http post请求。(已废弃:使用SendRequest)</p><p><b>函数签名:</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:#7B7F8B;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HttpPost</span><span style="color:#F6F6F4;">(url </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, params </span><span style="color:#F286C4;">...</span><span style="color:#F6F6F4;">any) (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Response, </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:#A0ADA0;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HttpPost</span><span style="color:#999999;">(</span><span style="color:#393A34;">url </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> params </span><span style="color:#AB5959;">...</span><span style="color:#393A34;">any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Response</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>示例:</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">    url </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    header </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;">string</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;">Content-Type</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">application/x-www-form-urlencoded</span><span style="color:#DEE492;">&quot;</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;">    postData </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> url.Values{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    postData.</span><span style="color:#97E1F1;">Add</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">userId</span><span style="color:#DEE492;">&quot;</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;">    postData.</span><span style="color:#97E1F1;">Add</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">title</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">TestToDo</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    resp, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">HttpPost</span><span style="color:#F6F6F4;">(apiUrl, header, </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;">, postData)</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;">        log.</span><span style="color:#97E1F1;">Fatal</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;">    body, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> ioutil.</span><span style="color:#97E1F1;">ReadAll</span><span style="color:#F6F6F4;">(resp.Body)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(body)</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">url</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;">https://jsonplaceholder.typicode.com/todos</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">header</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;">string</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;">Content-Type</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;">application/x-www-form-urlencoded</span><span style="color:#B5695999;">&quot;</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;">postData</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> url</span><span style="color:#999999;">.</span><span style="color:#393A34;">Values</span><span style="color:#999999;">{}</span></span>
<span class="line"><span style="color:#393A34;">    postData</span><span style="color:#999999;">.</span><span style="color:#998418;">Add</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">userId</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;">1</span><span style="color:#B5695999;">&quot;</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#393A34;">    postData</span><span style="color:#999999;">.</span><span style="color:#998418;">Add</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">title</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;">TestToDo</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:#B07D48;">resp</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">HttpPost</span><span style="color:#999999;">(</span><span style="color:#393A34;">apiUrl</span><span style="color:#999999;">,</span><span style="color:#393A34;"> header</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#999999;">,</span><span style="color:#393A34;"> postData</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;">        log</span><span style="color:#999999;">.</span><span style="color:#998418;">Fatal</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;">    </span><span style="color:#B07D48;">body</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;"> ioutil</span><span style="color:#999999;">.</span><span style="color:#998418;">ReadAll</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp</span><span style="color:#999999;">.</span><span style="color:#393A34;">Body</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;">body</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HttpPut" tabindex="-1"><span id="HttpPut">HttpPut</span> <a class="header-anchor" href="#HttpPut" aria-label="Permalink to &quot;&lt;span id=&quot;HttpPut&quot;&gt;HttpPut&lt;/span&gt;&quot;">​</a></h3><p>发送http put请求。(已废弃:使用SendRequest)</p><p><b>函数签名:</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:#7B7F8B;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HttpPut</span><span style="color:#F6F6F4;">(url </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, params </span><span style="color:#F286C4;">...</span><span style="color:#F6F6F4;">any) (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Response, </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:#A0ADA0;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HttpPut</span><span style="color:#999999;">(</span><span style="color:#393A34;">url </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> params </span><span style="color:#AB5959;">...</span><span style="color:#393A34;">any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Response</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>示例:</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">    url </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    header </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;">string</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;">Content-Type</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">application/json</span><span style="color:#DEE492;">&quot;</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;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Todo</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;">int</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;">        UserId </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;userId&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Title  </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;title&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    todo </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> Todo{</span><span style="color:#BF9EEE;">1</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;">TestPutToDo</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">}</span></span>
<span class="line"><span style="color:#F6F6F4;">    bodyParams, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> json.</span><span style="color:#97E1F1;">Marshal</span><span style="color:#F6F6F4;">(todo)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    resp, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">HttpPut</span><span style="color:#F6F6F4;">(url, header, </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;">, bodyParams)</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;">        log.</span><span style="color:#97E1F1;">Fatal</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;">    body, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> ioutil.</span><span style="color:#97E1F1;">ReadAll</span><span style="color:#F6F6F4;">(resp.Body)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(body)</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">url</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;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">header</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;">string</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;">Content-Type</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;">application/json</span><span style="color:#B5695999;">&quot;</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:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Todo</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;">int</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;">        UserId </span><span style="color:#AB5959;">int</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;userId&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Title  </span><span style="color:#AB5959;">string</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;title&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 style="color:#393A34;">    </span><span style="color:#B07D48;">todo</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> Todo</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;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">TestPutToDo</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;">bodyParams</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;"> json</span><span style="color:#999999;">.</span><span style="color:#998418;">Marshal</span><span style="color:#999999;">(</span><span style="color:#393A34;">todo</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">resp</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">HttpPut</span><span style="color:#999999;">(</span><span style="color:#393A34;">url</span><span style="color:#999999;">,</span><span style="color:#393A34;"> header</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#999999;">,</span><span style="color:#393A34;"> bodyParams</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;">        log</span><span style="color:#999999;">.</span><span style="color:#998418;">Fatal</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;">    </span><span style="color:#B07D48;">body</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;"> ioutil</span><span style="color:#999999;">.</span><span style="color:#998418;">ReadAll</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp</span><span style="color:#999999;">.</span><span style="color:#393A34;">Body</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;">body</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HttpDelete" tabindex="-1"><span id="HttpDelete">HttpDelete</span> <a class="header-anchor" href="#HttpDelete" aria-label="Permalink to &quot;&lt;span id=&quot;HttpDelete&quot;&gt;HttpDelete&lt;/span&gt;&quot;">​</a></h3><p>发送http delete请求。(已废弃:使用SendRequest)</p><p><b>函数签名:</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:#7B7F8B;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HttpDelete</span><span style="color:#F6F6F4;">(url </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, params </span><span style="color:#F286C4;">...</span><span style="color:#F6F6F4;">any) (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Response, </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:#A0ADA0;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HttpDelete</span><span style="color:#999999;">(</span><span style="color:#393A34;">url </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> params </span><span style="color:#AB5959;">...</span><span style="color:#393A34;">any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Response</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>示例:</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">    url </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    resp, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">HttpDelete</span><span style="color:#F6F6F4;">(url)</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;">        log.</span><span style="color:#97E1F1;">Fatal</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;">    body, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> ioutil.</span><span style="color:#97E1F1;">ReadAll</span><span style="color:#F6F6F4;">(resp.Body)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(body)</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">url</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;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">resp</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">HttpDelete</span><span style="color:#999999;">(</span><span style="color:#393A34;">url</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;">        log</span><span style="color:#999999;">.</span><span style="color:#998418;">Fatal</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;">    </span><span style="color:#B07D48;">body</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;"> ioutil</span><span style="color:#999999;">.</span><span style="color:#998418;">ReadAll</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp</span><span style="color:#999999;">.</span><span style="color:#393A34;">Body</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;">body</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="HttpPatch" tabindex="-1"><span id="HttpPatch">HttpPatch</span> <a class="header-anchor" href="#HttpPatch" aria-label="Permalink to &quot;&lt;span id=&quot;HttpPatch&quot;&gt;HttpPatch&lt;/span&gt;&quot;">​</a></h3><p>发送http patch请求。(已废弃:使用SendRequest)</p><p><b>函数签名:</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:#7B7F8B;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#7B7F8B;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#F286C4;">func</span><span style="color:#F6F6F4;"> </span><span style="color:#62E884;">HttpPatch</span><span style="color:#F6F6F4;">(url </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, params </span><span style="color:#F286C4;">...</span><span style="color:#F6F6F4;">any) (</span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Response, </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:#A0ADA0;">// params[0] http请求header，类型必须是http.Header或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[1] http查询字符串，类型必须是url.Values或者map[string]string</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[2] post请求体，类型必须是[]byte</span></span>
<span class="line"><span style="color:#A0ADA0;">// params[3] http client，类型必须是http.Client</span></span>
<span class="line"><span style="color:#1E754F;">func</span><span style="color:#393A34;"> </span><span style="color:#59873A;">HttpPatch</span><span style="color:#999999;">(</span><span style="color:#393A34;">url </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> params </span><span style="color:#AB5959;">...</span><span style="color:#393A34;">any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#999999;">(</span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Response</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>示例:</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">    url </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    header </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;">string</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;">Content-Type</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">application/json</span><span style="color:#DEE492;">&quot;</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;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Todo</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;">int</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;">        UserId </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;userId&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Title  </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;title&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">    }</span></span>
<span class="line"><span style="color:#F6F6F4;">    todo </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> Todo{</span><span style="color:#BF9EEE;">1</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;">TestPatchToDo</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">}</span></span>
<span class="line"><span style="color:#F6F6F4;">    bodyParams, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> json.</span><span style="color:#97E1F1;">Marshal</span><span style="color:#F6F6F4;">(todo)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F6F6F4;">    resp, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">HttpPatch</span><span style="color:#F6F6F4;">(url, header, </span><span style="color:#BF9EEE;">nil</span><span style="color:#F6F6F4;">, bodyParams)</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;">        log.</span><span style="color:#97E1F1;">Fatal</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;">    body, _ </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> ioutil.</span><span style="color:#97E1F1;">ReadAll</span><span style="color:#F6F6F4;">(resp.Body)</span></span>
<span class="line"><span style="color:#F6F6F4;">    fmt.</span><span style="color:#97E1F1;">Println</span><span style="color:#F6F6F4;">(body)</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">url</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;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">header</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;">string</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;">Content-Type</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;">application/json</span><span style="color:#B5695999;">&quot;</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:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Todo</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;">int</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;">        UserId </span><span style="color:#AB5959;">int</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;userId&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Title  </span><span style="color:#AB5959;">string</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;title&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 style="color:#393A34;">    </span><span style="color:#B07D48;">todo</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> Todo</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;">1</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">TestPatchToDo</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;">bodyParams</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;"> json</span><span style="color:#999999;">.</span><span style="color:#998418;">Marshal</span><span style="color:#999999;">(</span><span style="color:#393A34;">todo</span><span style="color:#999999;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">resp</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">HttpPatch</span><span style="color:#999999;">(</span><span style="color:#393A34;">url</span><span style="color:#999999;">,</span><span style="color:#393A34;"> header</span><span style="color:#999999;">,</span><span style="color:#393A34;"> </span><span style="color:#1E754F;">nil</span><span style="color:#999999;">,</span><span style="color:#393A34;"> bodyParams</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;">        log</span><span style="color:#999999;">.</span><span style="color:#998418;">Fatal</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;">    </span><span style="color:#B07D48;">body</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;"> ioutil</span><span style="color:#999999;">.</span><span style="color:#998418;">ReadAll</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp</span><span style="color:#999999;">.</span><span style="color:#393A34;">Body</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;">body</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="ParseHttpResponse" tabindex="-1"><span id="ParseHttpResponse">ParseHttpResponse</span> <a class="header-anchor" href="#ParseHttpResponse" aria-label="Permalink to &quot;&lt;span id=&quot;ParseHttpResponse&quot;&gt;ParseHttpResponse&lt;/span&gt;&quot;">​</a></h3><p>将http请求响应解码成特定struct值</p><p><b>函数签名:</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;">ParseHttpResponse</span><span style="color:#F6F6F4;">(resp </span><span style="color:#F286C4;">*</span><span style="color:#F6F6F4;">http.Response, obj 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;">ParseHttpResponse</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp </span><span style="color:#AB5959;">*</span><span style="color:#393A34;">http</span><span style="color:#999999;">.</span><span style="color:#393A34;">Response</span><span style="color:#999999;">,</span><span style="color:#393A34;"> obj any</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span></span></code></pre></div><p><b>示例:</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">    url </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#DEE492;">&quot;</span></span>
<span class="line"><span style="color:#F6F6F4;">    header </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;">string</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;">Content-Type</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">: </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">application/json</span><span style="color:#DEE492;">&quot;</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;">    resp, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">HttpGet</span><span style="color:#F6F6F4;">(url, header)</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;">        log.</span><span style="color:#97E1F1;">Fatal</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;">    </span><span style="color:#F286C4;">type</span><span style="color:#F6F6F4;"> </span><span style="color:#97E1F1;font-style:italic;">Todo</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;">int</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;">        UserId    </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;userId&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Title     </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;title&quot;</span><span style="color:#DEE492;">\`</span></span>
<span class="line"><span style="color:#F6F6F4;">        Completed </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;completed&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;">    toDoResp </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> </span><span style="color:#F286C4;">&amp;</span><span style="color:#F6F6F4;">Todo{}</span></span>
<span class="line"><span style="color:#F6F6F4;">    err </span><span style="color:#F286C4;">=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">ParseHttpResponse</span><span style="color:#F6F6F4;">(resp, toDoResp)</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;">        log.</span><span style="color:#97E1F1;">Fatal</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;">(toDoResp)</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;">encoding/json</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;">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;">io/ioutil</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;">log</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/netutil</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;">url</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;">https://jsonplaceholder.typicode.com/todos/1</span><span style="color:#B5695999;">&quot;</span></span>
<span class="line"><span style="color:#393A34;">    </span><span style="color:#B07D48;">header</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;">string</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;">Content-Type</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;">application/json</span><span style="color:#B5695999;">&quot;</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;">resp</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">HttpGet</span><span style="color:#999999;">(</span><span style="color:#393A34;">url</span><span style="color:#999999;">,</span><span style="color:#393A34;"> header</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;">        log</span><span style="color:#999999;">.</span><span style="color:#998418;">Fatal</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;">    </span><span style="color:#1E754F;">type</span><span style="color:#393A34;"> </span><span style="color:#2E8F82;">Todo</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;">int</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;">        UserId    </span><span style="color:#AB5959;">int</span><span style="color:#393A34;">    </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;userId&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Title     </span><span style="color:#AB5959;">string</span><span style="color:#393A34;"> </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;title&quot;</span><span style="color:#B5695999;">\`</span></span>
<span class="line"><span style="color:#393A34;">        Completed </span><span style="color:#AB5959;">bool</span><span style="color:#393A34;">   </span><span style="color:#B5695999;">\`</span><span style="color:#B56959;">json:&quot;completed&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;">toDoResp</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;">Todo</span><span style="color:#999999;">{}</span></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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">ParseHttpResponse</span><span style="color:#999999;">(</span><span style="color:#393A34;">resp</span><span style="color:#999999;">,</span><span style="color:#393A34;"> toDoResp</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;">        log</span><span style="color:#999999;">.</span><span style="color:#998418;">Fatal</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;">toDoResp</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="DownloadFile" tabindex="-1"><span id="DownloadFile">DownloadFile</span> <a class="header-anchor" href="#DownloadFile" aria-label="Permalink to &quot;&lt;span id=&quot;DownloadFile&quot;&gt;DownloadFile&lt;/span&gt;&quot;">​</a></h3><p>从指定的server地址下载文件。</p><p><b>函数签名:</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;">DownloadFile</span><span style="color:#F6F6F4;">(filepath </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, url </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></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;">DownloadFile</span><span style="color:#999999;">(</span><span style="color:#393A34;">filepath </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> url </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">error</span></span></code></pre></div><p><b>示例:</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/netutil</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;">    err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">DownloadFile</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">./lancet_logo.jpg</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b</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;">(err)</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/netutil</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;">err</span><span style="color:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">DownloadFile</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">./lancet_logo.jpg</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;">https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b</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;">err</span><span style="color:#999999;">)</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="UploadFile" tabindex="-1"><span id="UploadFile">UploadFile</span> <a class="header-anchor" href="#UploadFile" aria-label="Permalink to &quot;&lt;span id=&quot;UploadFile&quot;&gt;UploadFile&lt;/span&gt;&quot;">​</a></h3><p>将文件上传指定的server地址。</p><p><b>函数签名:</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;">UploadFile</span><span style="color:#F6F6F4;">(filepath </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, server </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;">UploadFile</span><span style="color:#999999;">(</span><span style="color:#393A34;">filepath </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> server </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>示例:</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/netutil</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;">    ok, err </span><span style="color:#F286C4;">:=</span><span style="color:#F6F6F4;"> netutil.</span><span style="color:#97E1F1;">UploadFile</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">./a.jpg</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">http://www.xxx.com/bucket/test</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;">(ok)</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></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/netutil</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;">ok</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">UploadFile</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">./a.jpg</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;">http://www.xxx.com/bucket/test</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;">ok</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:#999999;">}</span></span></code></pre></div><h3 id="IsPingConnected" tabindex="-1"><span id="IsPingConnected">IsPingConnected</span> <a class="header-anchor" href="#IsPingConnected" aria-label="Permalink to &quot;&lt;span id=&quot;IsPingConnected&quot;&gt;IsPingConnected&lt;/span&gt;&quot;">​</a></h3><p>检查能否ping通主机。</p><p><b>函数签名:</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;">IsPingConnected</span><span style="color:#F6F6F4;">(host </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></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;">IsPingConnected</span><span style="color:#999999;">(</span><span style="color:#393A34;">host </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/q8OzTijsA87" target="_blank" rel="noreferrer">运行</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/netutil</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;"> netutil.</span><span style="color:#97E1F1;">IsPingConnected</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">www.baidu.com</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;"> netutil.</span><span style="color:#97E1F1;">IsPingConnected</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">www.!@#&amp;&amp;&amp;.com</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>
<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;">// 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/netutil</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsPingConnected</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">www.baidu.com</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:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsPingConnected</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">www.!@#&amp;&amp;&amp;.com</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>
<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;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div><h3 id="IsTelnetConnected" tabindex="-1"><span id="IsTelnetConnected">IsTelnetConnected</span> <a class="header-anchor" href="#IsTelnetConnected" aria-label="Permalink to &quot;&lt;span id=&quot;IsTelnetConnected&quot;&gt;IsTelnetConnected&lt;/span&gt;&quot;">​</a></h3><p>检查能否telnet到主机。</p><p><b>函数签名:</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;">IsTelnetConnected</span><span style="color:#F6F6F4;">(host </span><span style="color:#97E1F1;font-style:italic;">string</span><span style="color:#F6F6F4;">, port </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></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;">IsTelnetConnected</span><span style="color:#999999;">(</span><span style="color:#393A34;">host </span><span style="color:#AB5959;">string</span><span style="color:#999999;">,</span><span style="color:#393A34;"> port </span><span style="color:#AB5959;">string</span><span style="color:#999999;">)</span><span style="color:#393A34;"> </span><span style="color:#AB5959;">bool</span></span></code></pre></div><p><b>示例:<span class="run-container"><a href="https://go.dev/play/p/yiLCGtQv_ZG" target="_blank" rel="noreferrer">运行</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/netutil</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;"> netutil.</span><span style="color:#97E1F1;">IsTelnetConnected</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">www.baidu.com</span><span style="color:#DEE492;">&quot;</span><span style="color:#F6F6F4;">, </span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">80</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;"> netutil.</span><span style="color:#97E1F1;">IsTelnetConnected</span><span style="color:#F6F6F4;">(</span><span style="color:#DEE492;">&quot;</span><span style="color:#E7EE98;">www.baidu.com</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>
<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>
<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;">// 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/netutil</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;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsTelnetConnected</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">www.baidu.com</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;">80</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:#393A34;"> </span><span style="color:#999999;">:=</span><span style="color:#393A34;"> netutil</span><span style="color:#999999;">.</span><span style="color:#998418;">IsTelnetConnected</span><span style="color:#999999;">(</span><span style="color:#B5695999;">&quot;</span><span style="color:#B56959;">www.baidu.com</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>
<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>
<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;">// false</span></span>
<span class="line"><span style="color:#999999;">}</span></span></code></pre></div>`,146),g=[t,c,r,y,F,i,u,E,A,d,q];function B(h,m,D,f,C,b){return p(),o("div",null,g)}const P=l(e,[["render",B]]);export{k as __pageData,P as default};
