<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: immortalt</title>
    <description>The latest articles on DEV Community by immortalt (@immortalt).</description>
    <link>https://dev.to/immortalt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F253594%2F55b3f88c-7d4d-4eec-97bf-ac4c334e1173.png</url>
      <title>DEV Community: immortalt</title>
      <link>https://dev.to/immortalt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/immortalt"/>
    <language>en</language>
    <item>
      <title>Use pprof for golang program memory analysis</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:23:42 +0000</pubDate>
      <link>https://dev.to/immortalt/use-pprof-for-golang-program-memory-analysis-2cj6</link>
      <guid>https://dev.to/immortalt/use-pprof-for-golang-program-memory-analysis-2cj6</guid>
      <description>&lt;p&gt;When using golang to write complex projects, it is often useful to use multi-coroutine concurrency scenarios. At this&lt;br&gt;
time, it is easy to cause the problem of coroutine leaks due to negligence, and then produce similar memory leaks. This&lt;br&gt;
article focuses on the investigation of coroutine leaks, and provides ideas and practices for visual analysis of golang&lt;br&gt;
program memory.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction to pprof
&lt;/h2&gt;

&lt;p&gt;pprof is a tool for visualization and analysis of profiling data.&lt;br&gt;&lt;br&gt;
pprof reads a collection of profiling samples in profile.proto format and generates reports to visualize and help&lt;br&gt;
analyze the data. It can generate both text and graphical reports (through the use of the dot visualization package).&lt;/p&gt;
&lt;h2&gt;
  
  
  How to use pprof
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Add monitoring code
&lt;/h3&gt;

&lt;p&gt;First, we need to add monitoring code in the golang program, and expose it through the http interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="s"&gt;"net/http/pprof"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"net/http"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ListenAndServe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"0.0.0.0:8081"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;
    &lt;span class="c"&gt;// your code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we start the program that needs to be analyzed, and we are ready to analyze it.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to check the memory size of each module
&lt;/h3&gt;

&lt;p&gt;By analyzing the size of the memory occupied by each module and function, memory leaks can be found very effectively.&lt;/p&gt;

&lt;h4&gt;
  
  
  Command line method to generate visual analysis images
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;go&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;tool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pprof&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-alloc_space&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-cum&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;http://localhost:8081/debug/pprof/heap&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the command is run, enter &lt;code&gt;web&lt;/code&gt; in the console and press &lt;code&gt;Enter&lt;/code&gt;, and a svg picture will be opened with the&lt;br&gt;
default viewing software of &lt;code&gt;.svg&lt;/code&gt;, showing the memory usage diagram of each module. If you enter &lt;code&gt;web&lt;/code&gt; and report an&lt;br&gt;
error of &lt;code&gt;Failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in %PATH%&lt;/code&gt;, it is&lt;br&gt;
because &lt;code&gt;Graphviz&lt;/code&gt; is not installed on the computer, which is a component that image generation depends on. The solution&lt;br&gt;
is: Open &lt;a href="https://graphviz.gitlab.io/download/"&gt;https://graphviz.gitlab.io/download/&lt;/a&gt; and follow the prompts to download and install. After the installation is&lt;br&gt;
complete, for Windows, add the &lt;code&gt;bin&lt;/code&gt; folder of the Graphviz installation path after setting the environment variable&lt;br&gt;
path.&lt;/p&gt;

&lt;h4&gt;
  
  
  View specific data list in web browser
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:8081/debug/pprof/heap?debug=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to view the number of coroutines created by each module
&lt;/h3&gt;

&lt;p&gt;By analyzing the number of coroutines created by each module and function, coroutine leaks can be checked very&lt;br&gt;
effectively. If there is coroutine leaks, the number of coroutines in the corresponding modules is astonishing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Command line method to generate visual analysis images
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;go&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;tool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pprof&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;http://localhost:8081/debug/pprof/goroutine&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the command runs, enter &lt;code&gt;web&lt;/code&gt; in the console and press &lt;code&gt;Enter&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  View specific data list in web browser
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:8081/debug/pprof/goroutine?debug=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;The above is an introduction to the simple use of pprof, I believe it will be helpful to troubleshoot memory leaks and&lt;br&gt;
coroutine leaks in golang. If you need more detailed usage, please refer to the official pprof documentation.&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>Common operations of Git</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:22:57 +0000</pubDate>
      <link>https://dev.to/immortalt/common-operations-of-git-5623</link>
      <guid>https://dev.to/immortalt/common-operations-of-git-5623</guid>
      <description>&lt;h3&gt;
  
  
  Commit code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"feat: xxxxxx"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to revoke after commit
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--soft&lt;/span&gt; HEAD^
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This successfully revoked the commit. Note that only the commit operation is&lt;br&gt;
withdrawn, and the code modification remains.&lt;/p&gt;
&lt;h4&gt;
  
  
  git reset parameters
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;--mixed&lt;/code&gt;&lt;br&gt;
do not delete the workspace to change the code, cancel the commit, and cancel the &lt;code&gt;git add .&lt;/code&gt; operation. This is the&lt;br&gt;
default parameter.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--soft&lt;/code&gt;&lt;br&gt;
do not delete the workspace to change the code, cancel the commit, and do not cancel the &lt;code&gt;git add .&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--hard&lt;/code&gt;&lt;br&gt;
delete workspace change code, revoke commit, revoke &lt;code&gt;git add .&lt;/code&gt;. After completing this operation, it is restored to the&lt;br&gt;
last commit state.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to migrate git repository to another git
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote set-url origin remote_git_address
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This method will only migrate the current branch to the new git.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to save username and password of git in Ubuntu
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano ~/.gitconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Edit the config file and set this config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[credential]  
    helper = store
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>devops</category>
    </item>
    <item>
      <title>Install Node.js on Linux</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:22:31 +0000</pubDate>
      <link>https://dev.to/immortalt/install-nodejs-on-linux-cd0</link>
      <guid>https://dev.to/immortalt/install-nodejs-on-linux-cd0</guid>
      <description>&lt;h2&gt;
  
  
  Using NodeSource
&lt;/h2&gt;

&lt;p&gt;Refer to the &lt;a href="https://github.com/nodesource/distributions/blob/master/README.md"&gt;NodeSource documentation&lt;/a&gt; for more&lt;br&gt;
information on the available versions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Node.js v14.x:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Using Ubuntu&lt;/span&gt;
curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://deb.nodesource.com/setup_14.x | &lt;span class="nb"&gt;sudo&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; bash -
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; nodejs

&lt;span class="c"&gt;# Using Debian, as root&lt;/span&gt;
curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://deb.nodesource.com/setup_14.x | bash -
apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Upgrade npm
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>node</category>
      <category>linux</category>
      <category>ubuntu</category>
      <category>devops</category>
    </item>
    <item>
      <title>Monitor status of nvme ssd in Ubuntu</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:21:57 +0000</pubDate>
      <link>https://dev.to/immortalt/monitor-status-of-nvme-ssd-in-ubuntu-2bj3</link>
      <guid>https://dev.to/immortalt/monitor-status-of-nvme-ssd-in-ubuntu-2bj3</guid>
      <description>&lt;p&gt;Install nvme-cli&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install nvme-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List disks&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nvme list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View the details of the hard drive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nvme smart-log /dev/nvme0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Auto refresh status&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo watch -n 1 nvme smart-log /dev/nvme0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only view the temperature info&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nvme smart-log /dev/nvme0 | grep "^temperature"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Online expansion of Ubuntu LVM disk</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:19:56 +0000</pubDate>
      <link>https://dev.to/immortalt/online-expansion-of-ubuntu-lvm-disk-28k3</link>
      <guid>https://dev.to/immortalt/online-expansion-of-ubuntu-lvm-disk-28k3</guid>
      <description>&lt;h2&gt;
  
  
  LVM overview
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EjdrszUU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ries0hnqilkzivyuo1d0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EjdrszUU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ries0hnqilkzivyuo1d0.png" alt="LVM" width="654" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Physical Volume (PV)
&lt;/h3&gt;

&lt;p&gt;Refers to a disk partition, or a device (such as RAID) that has the same function as a disk partition. It is the basic&lt;br&gt;
storage logical block of LVM, but compared with basic physical storage media (such as partitions, disks, etc.), it&lt;br&gt;
contains LVM-related Management parameters.&lt;/p&gt;
&lt;h3&gt;
  
  
  Volume Group (VG)
&lt;/h3&gt;

&lt;p&gt;Similar to a physical disk in a non-LVM system, it is composed of one or more physical volumes PV. One or more LVs (&lt;br&gt;
logical volumes) can be created on the volume group.&lt;/p&gt;
&lt;h3&gt;
  
  
  Logical Volume (LV)
&lt;/h3&gt;

&lt;p&gt;Similar to disk partitions in non-LVM systems, logical volumes are built on the volume group VG. A file system (such as&lt;br&gt;
/home or /usr, etc.) can be established on the logical volume LV.&lt;/p&gt;
&lt;h2&gt;
  
  
  LVM expansion operation
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Create a new primary partition
&lt;/h3&gt;

&lt;p&gt;If you expanded the hard disk size of the virtual machine, and you are still using one hard disk such as &lt;code&gt;/dev/sda&lt;/code&gt;, you&lt;br&gt;
can do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;fdisk /dev/sda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter &lt;code&gt;m&lt;/code&gt; to view the help, enter &lt;code&gt;n&lt;/code&gt; to create a new partition, select the primary partition, step by step, press &lt;code&gt;w&lt;/code&gt;&lt;br&gt;
to write and save, and get &lt;code&gt;/dev/sda2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can also add a new hard drive to the machine, and the new hard drive may be shown as &lt;code&gt;/dev/sdb&lt;/code&gt;. The operation of&lt;br&gt;
creating a new partition is similar.&lt;/p&gt;
&lt;h3&gt;
  
  
  Format the partition as ext4 format
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;mkfs &lt;span class="nt"&gt;-t&lt;/span&gt; ext4 /dev/sda2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;/dev/sda2&lt;/code&gt; represents the new partition, you can replace it with other paths according to your situation, for&lt;br&gt;
example &lt;code&gt;/dev/sdb1&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Find the VG Name
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~# vgdisplay
  &lt;span class="nt"&gt;---&lt;/span&gt; Volume group &lt;span class="nt"&gt;---&lt;/span&gt;
  VG Name               ubuntu--vg-root
  System ID
  Format                lvm2
  ......
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Add the new partition to the original VG of lvm
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vgextend ubuntu--vg-root /dev/sda2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Check the VG
&lt;/h3&gt;

&lt;p&gt;You should find that there are some free space in the volume group.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~# vgdisplay
  &lt;span class="nt"&gt;---&lt;/span&gt; Volume group &lt;span class="nt"&gt;---&lt;/span&gt;
  VG Name               ubuntu--vg-root
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             &lt;span class="nb"&gt;read&lt;/span&gt;/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               758.99 GiB
  PE Size               4.00 MiB
  Total PE              194302
  Alloc PE / Size       15103 / &amp;lt;59.00 GiB
  Free  PE / Size       179199 / &amp;lt;700.00 GiB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Check the LV
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~# lvdisplay
  &lt;span class="nt"&gt;---&lt;/span&gt; Logical volume &lt;span class="nt"&gt;---&lt;/span&gt;
  LV Path                /dev/ubuntu--vg-root/lv-root
  LV Name                lv-root
  VG Name                ubuntu--vg-root
  LV UUID                KiPSR5-XXvZ-JaXz-fyTw-EE0U-NV7E-6ohpCN
  LV Write Access        &lt;span class="nb"&gt;read&lt;/span&gt;/write
  LV Creation host, &lt;span class="nb"&gt;time &lt;/span&gt;ubuntu-server, 2018-11-15 06:06:41 +0000
  LV Status              available
  &lt;span class="c"&gt;# open                 1&lt;/span&gt;
  LV Size                45.00 GiB
  Current LE             11520
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently &lt;span class="nb"&gt;set &lt;/span&gt;to     256
  Block device           253:0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Extend the LV
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~# lvextend &lt;span class="nt"&gt;-L&lt;/span&gt; 700G /dev/ubuntu--vg-root/lv-root
  Size of logical volume ubuntu--vg-root/lv-root changed from 45.00 GiB &lt;span class="o"&gt;(&lt;/span&gt;11520 extents&lt;span class="o"&gt;)&lt;/span&gt; to 700.00 GiB &lt;span class="o"&gt;(&lt;/span&gt;179200 extents&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
  Logical volume ubuntu--vg-root/lv-root successfully resized.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Find the root file system name
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~# &lt;span class="nb"&gt;df&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt;
Filesystem                       Size  Used Avail Use% Mounted on
udev                              16G     0   16G   0% /dev
tmpfs                            3.2G   19M  3.2G   1% /run
/dev/mapper/ubuntu--vg-root       45G  5.3G   37G  13% /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Resize file system
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~# resize2fs &lt;span class="nt"&gt;-p&lt;/span&gt; /dev/mapper/ubuntu--vg-root
resize2fs 1.44.1 &lt;span class="o"&gt;(&lt;/span&gt;24-Mar-2018&lt;span class="o"&gt;)&lt;/span&gt;
Filesystem at /dev/mapper/ubuntu--vg-root is mounted on /&lt;span class="p"&gt;;&lt;/span&gt; on-line resizing required
old_desc_blocks &lt;span class="o"&gt;=&lt;/span&gt; 6, new_desc_blocks &lt;span class="o"&gt;=&lt;/span&gt; 88
The filesystem on /dev/mapper/ubuntu--vg-root is now 183500800 &lt;span class="o"&gt;(&lt;/span&gt;4k&lt;span class="o"&gt;)&lt;/span&gt; blocks long.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  View the latest hard drive size
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~# &lt;span class="nb"&gt;df&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt;
Filesystem                       Size  Used Avail Use% Mounted on
udev                              16G     0   16G   0% /dev
tmpfs                            3.2G   59M  3.1G   2% /run
/dev/mapper/ubuntu--vg-root      689G  5.4G  655G   1% /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to reduce the LV size
&lt;/h2&gt;

&lt;p&gt;You can use the &lt;code&gt;lvreduce&lt;/code&gt; command.&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>Monitor the temperature and health status of nvme ssd in Ubuntu</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:14:54 +0000</pubDate>
      <link>https://dev.to/immortalt/monitor-the-temperature-and-health-status-of-nvme-ssd-in-ubuntu-3l3j</link>
      <guid>https://dev.to/immortalt/monitor-the-temperature-and-health-status-of-nvme-ssd-in-ubuntu-3l3j</guid>
      <description>&lt;p&gt;Install nvme-cli&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install nvme-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List disks&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nvme list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View the details of the hard drive&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nvme smart-log /dev/nvme0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Auto refresh status&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo watch -n 1 nvme smart-log /dev/nvme0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only view the temperature info&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nvme smart-log /dev/nvme0 | grep "^temperature"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ubuntu</category>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>Imporve your Ubuntu Desktop's performance</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:14:24 +0000</pubDate>
      <link>https://dev.to/immortalt/imporve-your-ubuntu-desktops-performance-42c7</link>
      <guid>https://dev.to/immortalt/imporve-your-ubuntu-desktops-performance-42c7</guid>
      <description>&lt;p&gt;When you install the Ubuntu system on a physical machine, don't forget to do these things to improve your computer's&lt;br&gt;
performance.&lt;br&gt;&lt;br&gt;
My experiments found that the improvement was very noticeable, based on Ubuntu 20.10.&lt;/p&gt;

&lt;h2&gt;
  
  
  use s-tui to monitor and test your max CPU frequency
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9e5lxaxmog3u7ztixk90.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9e5lxaxmog3u7ztixk90.png" alt="s-tui"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  how to install
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;python3-pip stress
&lt;span class="nb"&gt;sudo &lt;/span&gt;pip3 &lt;span class="nb"&gt;install &lt;/span&gt;s-tui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  how to use
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;s-tui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the arrow keys and space bar to switch between Monitor mode and Stress mode. The Stress mode performs a&lt;br&gt;
stress test on the CPU.&lt;/p&gt;

&lt;h2&gt;
  
  
  use indicator-cpufreq to set your CPU frequency
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxis5ptxfvkb4nul99ig0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxis5ptxfvkb4nul99ig0.png" alt="indicator-cpufreq"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  how to install
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;indicator-cpufreq
&lt;span class="nb"&gt;sudo &lt;/span&gt;reboot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  how to use
&lt;/h3&gt;

&lt;p&gt;Look at the status bar icon in the upper right corner and click on the emerging icon to set the CPU's performance mode.&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>Create socks server on Ubuntu 20.04</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:11:33 +0000</pubDate>
      <link>https://dev.to/immortalt/create-socks-server-on-ubuntu-2004-lah</link>
      <guid>https://dev.to/immortalt/create-socks-server-on-ubuntu-2004-lah</guid>
      <description>&lt;p&gt;In daily life, we may need to create a socks server to provide network for other hosts.&lt;br&gt;&lt;br&gt;
I summarized the method of creating socks service through dante-server under Ubuntu 20.04.&lt;/p&gt;
&lt;h3&gt;
  
  
  install dante-server
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;dante-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  add user for dante-server
&lt;/h3&gt;

&lt;p&gt;Use this method to create a user to prevent it from logging in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;useradd &lt;span class="nt"&gt;-s&lt;/span&gt; /sbin/nologin dante-socks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Edit the configuration file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/danted.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;minimal configuration for dante-server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;logoutput: syslog stdout
internal: ztuku335yr port = 1080
external: ens3
user.notprivileged: dante-socks
clientmethod: none
socksmethod: none
#allow connections from local network
client pass {
        from: 10.0.0.229/24 to: 0.0.0.0/0
        log: error # connect disconnect
}
socks pass {  
        from: 0.0.0.0/0 to: 0.0.0.0/0
        command: bind connect udpassociate
        log: error # connect disconnect iooperation
}
socks pass {
        from: 0.0.0.0/0 to: 0.0.0.0/0
        command: bindreply udpreply
        log: error # connect disconnect iooperation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ubuntu</category>
      <category>tutorial</category>
      <category>devops</category>
    </item>
    <item>
      <title>Create a private Ubuntu mirror</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Fri, 03 Dec 2021 03:10:57 +0000</pubDate>
      <link>https://dev.to/immortalt/create-a-private-ubuntu-mirror-12a5</link>
      <guid>https://dev.to/immortalt/create-a-private-ubuntu-mirror-12a5</guid>
      <description>&lt;p&gt;To create a private Ubuntu image, the commonly used tools are debmirror and apt-mirror.&lt;br&gt;&lt;br&gt;
As of today, these two tools have their own advantages and disadvantages.&lt;/p&gt;
&lt;h2&gt;
  
  
  debmirror
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://help.ubuntu.com/community/Debmirror"&gt;debmirror document&lt;/a&gt;&lt;br&gt;&lt;br&gt;
debmirror has many downloading methods, and it will compare the local file with the file on the server before&lt;br&gt;
downloading so that only the missing files are downloaded. However, it does not seem to support multi-threaded&lt;br&gt;
downloading. Debmirror is downloaded one by one, so the download speed is relatively slow.&lt;/p&gt;
&lt;h2&gt;
  
  
  apt-mirror
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://apt-mirror.github.io/"&gt;apt-mirror document&lt;/a&gt;&lt;br&gt;&lt;br&gt;
apt-mirror supports 20 threads to download at the same time by default. If you choose a suitable mirror station, the&lt;br&gt;
download speed can reach the maximum of my network. However, it does not seem to make a comparison. Although it can&lt;br&gt;
speed up the download start speed, sometimes some files may be lost, resulting in an incomplete mirror, so the client&lt;br&gt;
cannot be updated.&lt;/p&gt;
&lt;h3&gt;
  
  
  how to write the config file
&lt;/h3&gt;

&lt;p&gt;In order to download the complete package, we need to modify the configuration file in &lt;code&gt;/etc/apt/mirror.list&lt;/code&gt;. Use this&lt;br&gt;
format to ensure that the i386 package will be downloaded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deb-amd64 http://mirrors.aliyun.com/ubuntu focal main restricted universe multiverse
deb-i386 http://mirrors.aliyun.com/ubuntu focal main restricted universe multiverse
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Combine them together
&lt;/h2&gt;

&lt;p&gt;Therefore, in order to achieve a balance between efficiency and completeness, we can combine apt-mirror and debmirror.&lt;br&gt;
We can first use apt-mirror to download quickly, then we can use debmirror to check and download the missing packages.&lt;br&gt;
Maybe this is the best way to download the Ubuntu mirror.&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>tutorial</category>
      <category>devops</category>
    </item>
    <item>
      <title>How to migrate mgo to qmgo</title>
      <dc:creator>immortalt</dc:creator>
      <pubDate>Wed, 23 Dec 2020 17:08:41 +0000</pubDate>
      <link>https://dev.to/immortalt/how-to-migrate-mgo-to-qmgo-501g</link>
      <guid>https://dev.to/immortalt/how-to-migrate-mgo-to-qmgo-501g</guid>
      <description>&lt;p&gt;&lt;a href="https://immortal-blog.github.io/"&gt;For more information, visit my new blog &lt;strong&gt;Immortal Blog&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why migrate to qmgo
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Mgo is a convenient library for golang to operate mongodb, but it does not support the latest features of mongodb,
such as Transaction.&lt;/li&gt;
&lt;li&gt;My old project is written in mgo. If I want to migrate to the official mongo-driver, its syntax is more primitive, the
usage difference is large, and the migration cost will be higher.&lt;/li&gt;
&lt;li&gt;I found a library called qmgo, which is based on the official mongo-driver package, but it is closer to mgo in terms
of syntax and suitable for simple and rude migrations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below I will record the methods used in the migration process, which I found out by myself. If you have any questions,&lt;br&gt;
please correct me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Batch replacement
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Batch replace &lt;code&gt;github.com/globalsign/mgo/bson&lt;/code&gt; with &lt;code&gt;go.mongodb.org/mongo-driver/bson&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;bson.NewObjectId()&lt;/code&gt; with &lt;code&gt;primitive.NewObjectID()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;bson.ObjectId&lt;/code&gt; with &lt;code&gt;primitive.ObjectID&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;.Find(bson.M&lt;/code&gt; with &lt;code&gt;.Find(c, bson.M&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;.Find(search&lt;/code&gt; to &lt;code&gt;.Find(c, search&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;.Insert(&lt;/code&gt; to &lt;code&gt;.InsertOne(c,&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;.Update(&lt;/code&gt; to &lt;code&gt;.UpdateOne(c,&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;.RemoveAll(&lt;/code&gt; to &lt;code&gt;.RemoveAll(c,&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;.Remove(&lt;/code&gt; to &lt;code&gt;.Remove(c,&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;errors.Is(err, mgo.ErrNotFound)&lt;/code&gt; with &lt;code&gt;qmgo.IsErrNoDocuments(err)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Batch replace &lt;code&gt;.EnsureIndex(mgo.Index{&lt;/code&gt; for
&lt;code&gt;.CreateOneIndex(c, options.IndexModel{&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Copy and paste
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Where there is no context, copy and paste everywhere &lt;code&gt;c := context.Background()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If it is in the interface method of gin, you can directly use gin's &lt;code&gt;c *gin.Context&lt;/code&gt; (but if multi-coroutine operation
needs to Copy gin's Context)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Function substitution
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Replace the bson.IsObjectIdHex() method:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"go.mongodb.org/mongo-driver/bson/primitive"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;IsObjectIDHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hex&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;primitive&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ObjectIDFromHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Replace the bson.ObjectIdHex() method:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"go.mongodb.org/mongo-driver/bson/primitive"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;ObjectIDHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hex&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;primitive&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ObjectID&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;primitive&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ObjectIDFromHex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;panic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid input to ObjectIDHex: %+v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These functions can be placed in the package of the auxiliary method or the package of the database operation, and then&lt;br&gt;
replace the references in batches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;At this point, the project completed the migration within two hours and started running smoothly.&lt;br&gt;&lt;br&gt;
Thanks to the author of qmgo for making the wheels for me.&lt;br&gt;&lt;br&gt;
If I have the opportunity, I will also open up some wheels.&lt;/p&gt;

</description>
      <category>go</category>
    </item>
  </channel>
</rss>
