<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged run</title>
<link>https://coderlegion.com/tag/run</link>
<description>Powered by Question2Answer</description>
<item>
<title>Understanding Systemd.exec - Part 1: How to Secure Applications Running in Systemd?</title>
<link>https://coderlegion.com/16114/understanding-systemd-exec-part-1-how-to-secure-applications-running-in-systemd</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on GitHub. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;If you are running applications with systemd and want to restrict how they interact with Linux kernel features (like filesystem, processes, and capabilities), you can use the systemd.exec configuration options. &lt;/p&gt;

&lt;p&gt;In this article I will be going to explain how to use these options to secure your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are systemd.exec options?
&lt;/h2&gt;

&lt;p&gt;Systemd.exec options are a set of configuration options that are used to configure how a systemd service interacts with the Linux kernel. &lt;/p&gt;

&lt;p&gt;This feature is mainly used to provide security for the applications running in systemd.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why we need this option in first place?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Hardening services (Postgres, Nginx, workers, etc) which are mostly open to the internet&lt;/li&gt;
&lt;li&gt;Reducing blast radius after compromise &lt;/li&gt;
&lt;li&gt;Lightweight (no container overhead)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How is this different from Docker?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Works on a single process/service.&lt;/li&gt;
&lt;li&gt;Applies restrictions on top of the host.&lt;/li&gt;
&lt;li&gt;Uses kernel features (namespaces, cgroups, capabilities)&lt;/li&gt;
&lt;li&gt;Shares the same root filesystem (by default)&lt;/li&gt;
&lt;li&gt;No packaging, no images&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is the real usecase?
&lt;/h2&gt;

&lt;p&gt;Let's take an example of service.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;/etc/systemd/system/myapp.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside this file, we can control:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where the app runs&lt;/li&gt;
&lt;li&gt;Which user it runs as&lt;/li&gt;
&lt;li&gt;What it can access&lt;/li&gt;
&lt;li&gt;How secure / isolated it is&lt;/li&gt;
&lt;li&gt;What resources it can use&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Most common options
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Run a service as non-root (security)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Set &lt;code&gt;User=&lt;/code&gt; &lt;code&gt;Group=&lt;/code&gt; to a non-privileged user (e.g. &lt;code&gt;postgres&lt;/code&gt;, &lt;code&gt;www-data&lt;/code&gt;).&lt;br&gt;
This will prevent the service from running as root, which can lead to security vulnerabilities.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;postgres
&lt;span class=&quot;nv&quot;&gt;Group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Restrict filesystem access&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Set &lt;code&gt;ProtectSystem=&lt;/code&gt; &lt;code&gt;ProtectHome=&lt;/code&gt; &lt;code&gt;ReadWritePaths=&lt;/code&gt; &lt;code&gt;ReadOnlyPaths=&lt;/code&gt; to control filesystem access.&lt;br&gt;
This will make service only read/ write specifed directory.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;ProtectSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;strict
&lt;span class=&quot;nv&quot;&gt;ProtectHome&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ReadWritePaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/var/lib/postgresql
&lt;span class=&quot;nv&quot;&gt;ReadOnlyPaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/var/lib/postgresql/16/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Isolate runtime environment (like lightweight container)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Set &lt;code&gt;PrivateTmp=yes&lt;/code&gt; &lt;code&gt;NoNewPrivileges=yes&lt;/code&gt; to isolate runtime environment.&lt;br&gt;
As there is no container like docker this will be running in the host but under private tmp and no new privileges.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;PrivateTmp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NoNewPrivileges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Limit resources (avoid abuse / crashes)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Set &lt;code&gt;CPUQuota=&lt;/code&gt; &lt;code&gt;MemoryMax=&lt;/code&gt; &lt;code&gt;MemoryHigh=&lt;/code&gt; &lt;code&gt;MemoryLimit=&lt;/code&gt; &lt;code&gt;MemoryAccounting=&lt;/code&gt; to limit resources.&lt;br&gt;
If we want specific service to use only limited resources, we can use these options.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;CPUQuota&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;50%
&lt;span class=&quot;nv&quot;&gt;MemoryMax&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;512M
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Provide controlled writable directories
Set &lt;code&gt;ReadWritePaths=&lt;/code&gt; &lt;code&gt;ReadOnlyPaths=&lt;/code&gt; to control filesystem access.
This will make service only read/ write specifed directory.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;ReadWritePaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/var/lib/postgresql
&lt;span class=&quot;nv&quot;&gt;ReadOnlyPaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/var/lib/postgresql/16/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Drop dangerous privileges&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Set &lt;code&gt;CapabilityBoundingSet=&lt;/code&gt; to drop dangerous privileges.&lt;br&gt;
This will make service only able to run commands with specific privileges.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;CapabilityBoundingSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;CAP_NET_BIND_SERVICE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Run temporary / ephemeral services
Set &lt;code&gt;RuntimeDirectory=&lt;/code&gt; &lt;code&gt;StateDirectory=&lt;/code&gt; &lt;code&gt;LogsDirectory=&lt;/code&gt; to run temporary / ephemeral services.
This will run the service in a temporary / ephemeral directory.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;RuntimeDirectory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;myapp
&lt;span class=&quot;nv&quot;&gt;StateDirectory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;myapp
&lt;span class=&quot;nv&quot;&gt;LogsDirectory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;myapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Limit process / thread count
Set &lt;code&gt;TasksMax=&lt;/code&gt; to limit process / thread count.
This will make service only able to run with specific process / thread count.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;TasksMax&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Restrict access to system calls
Set &lt;code&gt;SystemCallFilter=&lt;/code&gt; &lt;code&gt;SystemCallArchitectures=&lt;/code&gt; to restrict access to system calls.
This will make service only able to use specific system calls.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;SystemCallFilter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;open,read,write,close
&lt;span class=&quot;nv&quot;&gt;SystemCallArchitectures&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Security measures for Docker Engine
Set &lt;code&gt;Delegate=yes&lt;/code&gt; to run Docker Engine with specific privileges.
This will make Docker Engine only able to run with specific privileges.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;nv&quot;&gt;Delegate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We could able to use systemd.exec options to secure application running in systemd.&lt;/p&gt;

&lt;p&gt;But Until we integrate with real application and test these options, we can't be sure about the security.&lt;/p&gt;

&lt;p&gt;In the next article we will see how service react with integrations of these options.&lt;/p&gt;

&lt;p&gt;Reference Man Page Systemd : &lt;a href=&quot;https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.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%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;373&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/16114/understanding-systemd-exec-part-1-how-to-secure-applications-running-in-systemd</guid>
<pubDate>Sat, 02 May 2026 02:27:26 +0000</pubDate>
</item>
<item>
<title>Understanding Interface in Go</title>
<link>https://coderlegion.com/13378/understanding-interface-in-go</link>
<description>
&lt;p&gt;&lt;em&gt;Hello, I'm Ganesh Kumar. I'm working on &lt;a href=&quot;https://hexmos.com/livereview/git-lrc/&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;git-lrc&lt;/a&gt;: a Git hook for Checking AI generated code.AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In my previous post, I explained how methods works.&lt;/p&gt;

&lt;p&gt;In this article we will understand how to work with interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an interface?
&lt;/h2&gt;

&lt;p&gt;An interface is a type that defines a set of methods. It is used to define a contract for a type. It is an abstract signature of a type where we define the methods but not the implementation.&lt;br&gt;
&lt;/p&gt;

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

&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;area&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;float64&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rectangle&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;height&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;float64&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rectangle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;area&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;float64&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;width&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;height&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rectangle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rect&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;area&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~/exp/code/rd/go-exmaple&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;go run main.go 
200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Interface are container which contains two properties.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Dynamic Type&lt;/li&gt;
&lt;li&gt;Dynamic Value&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Dynamic Type and Dynamic Value
&lt;/h2&gt;

&lt;p&gt;Dynamic type is the type of the value stored in the interface.&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight go&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;// 'i' is an empty interface. Currently, both its dynamic type and value are nil.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;any&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Value: %v &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; Type: %T&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;// Now we assign an integer to it.&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;// Dynamic Type becomes 'int', Dynamic Value becomes '42'&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;42&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Value: %v &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; Type: %T&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;// Now we assign a string to it.&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;// Dynamic Type becomes 'string', Dynamic Value becomes &quot;Hello&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Hello&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Value: %v &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; Type: %T&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;// Now we assign a float to it.&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;// Dynamic Type becomes 'float64', Dynamic Value becomes 3.14&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;3.14&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Value: %v &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; Type: %T&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~/exp/code/rd/go-exmaple&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;go run main.go 
Value: &amp;lt;nil&amp;gt;     Type: &amp;lt;nil&amp;gt;
Value: 42        Type: int
Value: Hello     Type: string
Value: 3.14      Type: float64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We can see that the dynamic type and dynamic value changes based on the value assigned to the interface.&lt;/p&gt;
&lt;h2&gt;
  
  
  Dynamic Type and Dynamic Value using reflection
&lt;/h2&gt;

&lt;p&gt;This is another way to get the dynamic type and dynamic value.&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight go&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;reflect&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;// A custom struct&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Name&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;interface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Alice&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;// Extracting the dynamic type&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;dynamicType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reflect&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TypeOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;// Extracting the dynamic value&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;dynamicValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reflect&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ValueOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Reflect Type:&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dynamicType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;         &lt;span class=&quot;c&quot;&gt;// main.User&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Reflect Value:&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dynamicValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;       &lt;span class=&quot;c&quot;&gt;// {Alice}&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;// You can even check the underlying &quot;Kind&quot; (e.g., struct, int, ptr)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Kind of Type:&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dynamicType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Kind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;  &lt;span class=&quot;c&quot;&gt;// struct&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~/exp/code/rd/go-exmaple&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;go run main.go 
Reflect Type: main.User
Reflect Value: &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;Alice&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
Kind of Type: struct
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This way we can get the dynamic type and dynamic value using reflection.&lt;/p&gt;
&lt;h2&gt;
  
  
  Type Assertion
&lt;/h2&gt;

&lt;p&gt;Type assertion is used to extract the dynamic value from the interface.&lt;/p&gt;

&lt;p&gt;This is the basic way to use type assertion.&lt;/p&gt;

&lt;p&gt;We try to extract the dynamic value from the interface. As, go is a static typed language, it will throw an error if the dynamic type is not the same as the type we are trying to extract.&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight go&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;interface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Hello&quot;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;float64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;float64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If we try to extract the dynamic value from the interface with a different type, it will throw an error. &lt;/p&gt;

&lt;p&gt;To avoid this we first check if the dynamic type is the same as the type we are trying to extract.&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~/exp/code/rd/go-exmaple&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;go run main.go 
Hello
Hello &lt;span class=&quot;nb&quot;&gt;true
&lt;/span&gt;0 &lt;span class=&quot;nb&quot;&gt;false
&lt;/span&gt;panic: interface conversion: interface &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt; is string, not float64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Usage of Type Switch
&lt;/h2&gt;

&lt;p&gt;Based on the dynamic type, we can extract the dynamic value from the interface.&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight go&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fmt&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;printTypeAndValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;interface&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{})&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Type: %T&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Value: %v&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;it is int %v&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;it is string %v&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;it is bool %v&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;unknown&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;// 'i' is an empty interface. Currently, both its dynamic type and value are nil.&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printTypeAndValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printTypeAndValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printTypeAndValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now we can see that based on the dynamic type, we can extract the dynamic value from the interface. We can print the value base on the dynamic type.&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~/exp/code/rd/go-exmaple&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;go run main.go 
Type: string    Value: Hello
it is string Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article we understood how interface works. We also understood how to use type assertion and type switch. &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://hexmos.com/livereview/git-lrc/&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.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%2Fifqf83t1qjl4u0g6aj4l.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;381&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; Check out: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;git-lrc&lt;/a&gt;&lt;br&gt;
Any feedback or contributors are welcome! It&amp;rsquo;s online, open-source, and ready for anyone to use.&lt;br&gt;
&amp;#11088; Star it on GitHub:&lt;br&gt;
&lt;/p&gt;
&lt;div class=&quot;ltag-github-readme-tag&quot;&gt;
  &lt;div class=&quot;readme-overview&quot;&gt;
    &lt;h2&gt;
      &lt;img src=&quot;https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg&quot; alt=&quot;GitHub logo&quot;&gt;
      &lt;a href=&quot;https://github.com/HexmosTech&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;
        HexmosTech
      &lt;/a&gt; / &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;
        git-lrc
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Free, Unlimited AI Code Reviews That Run on Commit
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class=&quot;ltag-github-body&quot;&gt;
    
&lt;div id=&quot;readme&quot; class=&quot;md&quot;&gt;
&lt;div&gt;
&lt;a rel=&quot;noopener noreferrer nofollow&quot; href=&quot;https://camo.githubusercontent.com/948c8f2d5cf41b48985cd364d48c3a2dc9bfbfd42eab3e0a9a1b3e61f5f17ce3/68747470733a2f2f6865786d6f732e636f6d2f66726565646576746f6f6c732f7075626c69632f6c725f6c6f676f2e737667&quot;&gt;&lt;img width=&quot;60&quot; alt=&quot;git-lrc logo&quot; src=&quot;https://camo.githubusercontent.com/948c8f2d5cf41b48985cd364d48c3a2dc9bfbfd42eab3e0a9a1b3e61f5f17ce3/68747470733a2f2f6865786d6f732e636f6d2f66726565646576746f6f6c732f7075626c69632f6c725f6c6f676f2e737667&quot;&gt;&lt;/a&gt;
&lt;p&gt;&lt;strong&gt;git-lrc&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Free, Unlimited AI Code Reviews That Run on Commit&lt;/strong&gt;&lt;/p&gt;
&lt;br&gt;
&lt;/div&gt;



&lt;div&gt;
&lt;a href=&quot;https://www.producthunt.com/products/git-lrc?embed=true&amp;amp;utm_source=badge-top-post-badge&amp;amp;utm_medium=badge&amp;amp;utm_campaign=badge-git-lrc&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;&lt;img alt=&quot;git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt&quot; width=&quot;250&quot; height=&quot;54&quot; src=&quot;https://camo.githubusercontent.com/87bf2d4283c1e0aa99e254bd17fefb1c67c0c0d39300043a243a4aa633b6cecc/68747470733a2f2f6170692e70726f6475637468756e742e636f6d2f776964676574732f656d6265642d696d6167652f76312f746f702d706f73742d62616467652e7376673f706f73745f69643d31303739323632267468656d653d6c6967687426706572696f643d6461696c7926743d31373731373439313730383638&quot;&gt;&lt;/a&gt;
&lt;/div&gt;




&lt;p&gt;AI agents write code fast. They also &lt;em&gt;silently remove logic&lt;/em&gt;, change behavior, and introduce bugs -- without telling you. You often find out in production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;git-lrc&lt;/code&gt; fixes this.&lt;/strong&gt; It hooks into &lt;code&gt;git commit&lt;/code&gt; and reviews every diff &lt;em&gt;before&lt;/em&gt; it lands. 60-second setup. Completely free.&lt;/p&gt;

&lt;div class=&quot;markdown-heading&quot;&gt;
&lt;h2 class=&quot;heading-element&quot;&gt;See It In Action&lt;/h2&gt;
&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;See git-lrc catch serious security issues such as leaked credentials, expensive cloud
&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/13378/understanding-interface-in-go</guid>
<pubDate>Tue, 31 Mar 2026 22:11:11 +0000</pubDate>
</item>
<item>
<title>Democratizing AI: How DeepSeek’s Minimalist Models Deliver Enterprise-Grade Results</title>
<link>https://coderlegion.com/1291/democratizing-ai-how-deepseeks-minimalist-models-deliver-enterprise-grade-results</link>
<description>
&lt;img src=&quot;https://images.unsplash.com/photo-1597338770339-9860acd8406e?crop=entropy&amp;amp;cs=tinysrgb&amp;amp;fit=max&amp;amp;fm=jpg&amp;amp;ixid=M3wxMTc3M3wwfDF8c2VhcmNofDE0fHxwYXBlcnxlbnwwfHx8fDE3Mzg2MTM3MDl8MA&amp;amp;ixlib=rb-4.0.3&amp;amp;q=80&amp;amp;w=2000&quot; alt=&quot;Democratizing AI: How DeepSeek&amp;rsquo;s Minimalist Models Deliver Enterprise-Grade Results&quot;&gt;&lt;p&gt;&lt;em&gt;(A Technical Deep Dive for Resource-Constrained Environments)&lt;/em&gt;&lt;/p&gt;&lt;h2 id=&quot;introduction-the-rise-of-small-scale-ai&quot;&gt;Introduction: The Rise of Small-Scale AI&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://guptadeepak.com/deepseek-revolutionizing-ai-with-efficiency-innovation-and-affordability/&quot; rel=&quot;noreferrer nofollow&quot;&gt;DeepSeek&amp;rsquo;s latest optimizations&lt;/a&gt; prove you don&amp;rsquo;t need enterprise-grade hardware to harness advanced AI. Developers have refined smaller models like &lt;strong&gt;DeepSeek-R1 (8B)&lt;/strong&gt; and &lt;a href=&quot;https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite?ref=guptadeepak.com&quot; rel=&quot;noreferrer nofollow&quot;&gt;&lt;strong&gt;DeepSeek-V2-Lite&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; (2.4B active params)&lt;/strong&gt; to run efficiently on modest setups&amp;mdash;&lt;a href=&quot;https://martech.org/how-to-run-deepseek-locally-on-your-computer/?ref=guptadeepak.com&quot; rel=&quot;noreferrer nofollow&quot;&gt;think laptops and entry-level GPUs&lt;/a&gt;&amp;mdash;while delivering surprising performance. Here&amp;rsquo;s why this matters:&lt;/p&gt;&lt;h3 id=&quot;why-minimal-deepseek&quot;&gt;Why Minimal DeepSeek?&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Lightweight &amp;amp; Efficient&lt;/strong&gt;: The 8B model runs on 16GB RAM and basic CPUs, while quantized versions (e.g., 4-bit) cut VRAM needs by 75%.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Developer-Friendly&lt;/strong&gt;: Simplified installation via &lt;a href=&quot;https://ollama.com/?ref=guptadeepak.com&quot; rel=&quot;noreferrer nofollow&quot;&gt;Ollama&lt;/a&gt; or Docker&amp;mdash;no complex dependencies.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Cost-Effective&lt;/strong&gt;: MIT license and open-source weights enable free local deployment.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Outperforms larger dense models in coding, math, and reasoning tasks.&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;evolution-of-deepseek-minimal&quot;&gt;Evolution of DeepSeek Minimal&lt;/h2&gt;&lt;h3 id=&quot;architectural-breakthroughs&quot;&gt;&lt;a href=&quot;https://guptadeepak.com/deepseek-revolutionizing-ai-with-efficiency-innovation-and-affordability/&quot; rel=&quot;noreferrer nofollow&quot;&gt;Architectural Breakthroughs&lt;/a&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Sparse Activation&lt;/strong&gt;: Only 2.4B/8B parameters active per inference (vs dense 70B models).&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Hybrid Attention&lt;/strong&gt;: Combines grouped-query and sliding-window attention to reduce VRAM by 40%.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Dynamic Batching&lt;/strong&gt;: Adaptive batch sizing prevents OOM errors on low-RAM devices.&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;quantization-milestones&quot;&gt;&lt;strong&gt;Quantization Milestones&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;Developers achieved near-lossless compression through:&lt;/p&gt;
&amp;lt;!--kg-card-begin: html--&amp;gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Technique&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Memory Savings&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Performance Retention&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;4-bit GPTQ&lt;/td&gt;
&lt;td&gt;75%&lt;/td&gt;
&lt;td&gt;98% of FP32&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8-bit Dynamic (IQ4_XS)&lt;/td&gt;
&lt;td&gt;50%&lt;/td&gt;
&lt;td&gt;99.5% of FP16&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pruning + Distillation&lt;/td&gt;
&lt;td&gt;60%&lt;/td&gt;
&lt;td&gt;92% of original&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&amp;lt;!--kg-card-end: html--&amp;gt;
&lt;h2 id=&quot;installation-and-deployment&quot;&gt;Installation and Deployment&lt;/h2&gt;&lt;h3 id=&quot;1-how-to-install-quickly-under-5-minutes&quot;&gt;1. How to Install Quickly (Under 5 Minutes)&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Advanced Optimization&lt;/strong&gt;:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Use FP16 quantization: &lt;code&gt;ollama run deepseek-r1:8b --gpu --quantize fp16&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Reduce batch size to lower RAM usage.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;strong&gt;Ollama Quickstart&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;curl -fsSL &lt;a href=&quot;https://ollama.com/install.sh&quot; rel=&quot;nofollow&quot;&gt;https://ollama.com/install.sh&lt;/a&gt; | sh  # Install Ollama  
ollama run deepseek-r1:8b                     # Pull 8B model  
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Test immediately in your terminal or integrate with Open WebUI for a ChatGPT-like interface.&lt;/p&gt;&lt;h3 id=&quot;2-bare-metal-deployment&quot;&gt;&lt;strong&gt;2. Bare-Metal Deployment&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;: x86_64 CPU, 16GB RAM, Linux/WSL2&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git clone &lt;a href=&quot;https://github.com/deepseek-ai/minimal-deploy&quot; rel=&quot;nofollow&quot;&gt;https://github.com/deepseek-ai/minimal-deploy&lt;/a&gt;  
cd minimal-deploy &amp;amp;&amp;amp; ./install.sh --model=r1-8b --quant=4bit  
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;Key Flags&lt;/em&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code&gt;--quant&lt;/code&gt;: 4bit/8bit/fp16 (4bit needs 8GB VRAM)&lt;/li&gt;&lt;li&gt;&lt;code&gt;--context 4096&lt;/code&gt;: Adjust for long-document tasks&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;cloud-native-scaling&quot;&gt;&lt;strong&gt;Cloud-Native Scaling&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;Deploy on AWS Lambda (serverless) via pre-built container:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-dockerfile&quot;&gt;FROM deepseek/minimal-base:latest  
CMD [&quot;--api&quot;, &quot;0.0.0.0:8080&quot;, &quot;--quant&quot;, &quot;4bit&quot;]  
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;em&gt;Cost Analysis&lt;/em&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;1M tokens processed for $0.12 vs $0.48 (GPT-3.5 Turbo)&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;developer-improvements-cleaner-smarter-faster&quot;&gt;Developer Improvements: Cleaner, Smarter, Faster&lt;/h2&gt;&lt;p&gt;Recent updates showcase the community&amp;rsquo;s focus on efficiency:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Load Balancing&lt;/strong&gt;: DeepSeek-V3&amp;rsquo;s auxiliary-loss-free strategy minimizes performance drops during scaling.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Quantization&lt;/strong&gt;: 4-bit models (e.g., IQ4_XS) run smoothly on 24GB GPUs.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Code Hygiene&lt;/strong&gt;: PRs pruning unused variables and enhancing error handling.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Distillation&lt;/strong&gt;: Smaller models like DeepSeek-R1-1.5B retain 80% of the 70B model&amp;rsquo;s capability at 1/50th the size.&lt;/li&gt;&lt;/ul&gt;
&amp;lt;!--kg-card-begin: html--&amp;gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Model&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Hardware&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;DeepSeek-R1-8B&lt;/td&gt;
&lt;td&gt;16GB RAM, no GPU&lt;/td&gt;
&lt;td&gt;Coding, basic reasoning&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DeepSeek-V2-Lite&lt;/td&gt;
&lt;td&gt;24GB GPU (e.g., RTX 3090)&lt;/td&gt;
&lt;td&gt;Advanced NLP, fine-tuning&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IQ4_XS Quantized&lt;/td&gt;
&lt;td&gt;8GB VRAM&lt;/td&gt;
&lt;td&gt;Low-latency local inference&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&amp;lt;!--kg-card-end: html--&amp;gt;
&lt;h3 id=&quot;why-developers-love-this&quot;&gt;Why Developers Love This&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Privacy&lt;/strong&gt;: No cloud dependencies&amp;mdash;data stays local.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Customization&lt;/strong&gt;: Fine-tune models with LoRA on consumer GPUs.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Cost&lt;/strong&gt;: Runs 1M tokens for ~$0.10 vs. $0.40+ for cloud alternatives.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;#128295; &lt;strong&gt;Pro Tip&lt;/strong&gt;: Pair with Open WebUI for a polished interface:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;docker run -p 9783:8080 -v open-webui:/app/backend/data ghcr.io/open-webui/open-webui:main  
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;real-world-use-cases&quot;&gt;Real-World Use Cases&lt;/h2&gt;&lt;h3 id=&quot;embedded-medical-diagnostics&quot;&gt;Embedded Medical Diagnostics&lt;/h3&gt;&lt;p&gt;A Nairobi startup runs DeepSeek-V2-Lite on Jetson Nano devices:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;97% accuracy identifying malaria from cell images&lt;/li&gt;&lt;li&gt;300ms inference time using TensorRT optimizations&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;low-code-ai-assistants&quot;&gt;Low-Code AI Assistants&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;from deepseek_minimal import Assistant  
  
assistant = Assistant(model=&quot;r1-8b&quot;, quant=&quot;4bit&quot;)  
response = assistant.generate(&quot;Write Python code for binary search&quot;)  
print(response)  # Outputs code with Big-O analysis  
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;future-directions&quot;&gt;Future Directions&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://github.com/Jiayi-Pan/TinyZero?ref=guptadeepak.com&quot; rel=&quot;noreferrer nofollow&quot;&gt;&lt;strong&gt;TinyZero Integration&lt;/strong&gt;&lt;/a&gt;: Merging Jiayi Pan&amp;rsquo;s workflow engine for automated model updates&lt;/li&gt;&lt;li&gt;&lt;strong&gt;RISC-V Support&lt;/strong&gt;: ARM/RISC-V binaries expected Q3 2025&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Energy Efficiency&lt;/strong&gt;: Targeting 1W consumption for solar-powered deployments&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;ai-for-the-99&quot;&gt;AI for the 99%&lt;/h2&gt;&lt;p&gt;DeepSeek&amp;rsquo;s minimal versions exemplify the &lt;em&gt;&amp;ldquo;small is the new big&amp;rdquo;&lt;/em&gt; paradigm shift. With active contributions from 180+ developers (and growing), they&amp;rsquo;re proving that:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;You don&amp;rsquo;t need $100k GPUs for production-grade AI&lt;/li&gt;&lt;li&gt;Open-source collaboration beats closed-model scaling&lt;/li&gt;&lt;li&gt;Efficiency innovations benefit emerging markets most&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;While LLMs like GPT-4 dominate headlines, DeepSeek&amp;rsquo;s engineering team and open-source contributors have quietly revolutionized &lt;strong&gt;resource-efficient AI&lt;/strong&gt;. Their minimalist models (e.g., DeepSeek-R1-8B, DeepSeek-V2-Lite) now rival 70B-parameter models in coding and reasoning tasks while running on laptops or Raspberry Pis.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.deepseek.com/?ref=guptadeepak.com&quot; rel=&quot;noreferrer nofollow&quot;&gt;DeepSeek&amp;rsquo;s&lt;/a&gt; minimal versions exemplify how smart engineering can democratize AI. Whether you&amp;rsquo;re refining a side project or prototyping enterprise tools, these models prove that &amp;ldquo;small&amp;rdquo; doesn&amp;rsquo;t mean &amp;ldquo;limited.&amp;rdquo;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Try it now&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;ollama run deepseek-r1:8b  
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/1291/democratizing-ai-how-deepseeks-minimalist-models-deliver-enterprise-grade-results</guid>
<pubDate>Thu, 27 Feb 2025 21:19:32 +0000</pubDate>
</item>
</channel>
</rss>