PageSourceSearch

https://sazak.io/

html sazak.io collected 2026-10-04 19:29:15 UTC 1,184,262 bytes, 3 lines download raw bytes

1<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><link rel="preconnect" href="/" crossorigin=""/><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/><link rel="preload" as="image" href="/assets/articles/tracing-goroutines-in-realtime-with-ebpf-2026-03-31.jpeg"/><link rel="preload" as="image" href="/assets/articles/visual-guide-to-go-maps-hash-tables-2025-10-26.jpeg"/><link rel="preload" as="image" href="/assets/articles/an-applied-introduction-to-ebpf-with-go-2024-06-06.jpeg"/><link rel="preload" as="image" href="/assets/articles/visual-guide-to-slices-in-go-2024-03-25.jpeg"/><link rel="preload" as="image" href="/assets/articles/how-i-built-my-own-go-package-index---gosazakio-2024-03-10.jpeg"/><link rel="preload" as="image" href="/assets/articles/fantastic-side-projects-and-where-to-find-them-2023-09-03.jpeg"/><link rel="preload" as="image" href="/assets/articles/cloud-native-patterns-illustrated-fan-in-and-fan-out-2022-10-30.jpeg"/><link rel="preload" as="image" href="/assets/articles/gls-file-manager-on-terminal-with-go-2022-07-19.jpeg"/><link rel="stylesheet" href="/_next/static/chunks/03r7fign14sf2.css" data-precedence="next"/><link rel="stylesheet" href="/_next/static/chunks/0nxynu6o846p8.css" data-precedence="next"/><link rel="preload" as="script" fetchPriority="low" href="/_next/static/chunks/06lc7v63nh4m9.js"/>
1<script src="/_next/static/chunks/00.7t-hl750an.js" async=""></script>
1<script src="/_next/static/chunks/12bdbefynuz0u.js" async=""></script>
1<script src="/_next/static/chunks/0xkp45tjn.3ou.js" async=""></script>
1<script src="/_next/static/chunks/12u-95kp.6lkh.js" async=""></script>
1<script src="/_next/static/chunks/turbopack-11017~4ih3528.js" async=""></script>
1<script src="/_next/static/chunks/0~6uqz2cc7cgk.js" async=""></script>
1<script src="/_next/static/chunks/060eq880magqv.js" async=""></script>
1<script src="/_next/static/chunks/078gj~ojf_wnm.js" async=""></script>
1<script src="/_next/static/chunks/0zbvl-0n~576..js" async=""></script>
1<script src="/_next/static/chunks/0n6k61d0zylrv.js" async=""></script>
1<script src="/_next/static/chunks/079g-_hol5.sn.js" async=""></script>
1<script src="/_next/static/chunks/053s04cvac324.js" async=""></script>
1<link rel="preload" href="https://www.googletagmanager.com/gtag/js?id=G-9HLV2YYER8" as="script"/><meta name="theme-color" content="white"/><meta name="color-scheme" content="only light"/><title>Ozan Sazak</title><meta name="description" content="I&#x27;m a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog."/><link rel="manifest" href="/manifest.webmanifest"/><meta name="robots" content="index, follow"/><meta name="pinterest" content="nopin"/><link rel="canonical" href="https://sazak.io"/><meta property="og:title" content="Ozan Sazak"/><meta property="og:description" content="I&#x27;m a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog."/><meta property="og:url" content="https://sazak.io"/><meta property="og:site_name" content="Ozan Sazak"/><meta property="og:locale" content="en_IE"/><meta property="og:image" content="https://sazak.io/opengraph-image?3c9e8dae5c8d2000"/><meta property="og:image:type" content="image/png"/><meta property="og:image:width" content="1200"/><meta property="og:image:height" content="630"/><meta property="og:image:alt" content="I&#x27;m a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog."/><meta property="og:type" content="website"/><meta name="twitter:card" content="summary_large_image"/><meta name="twitter:site" content="@oznszk"/><meta name="twitter:creator" content="@oznszk"/><meta name="twitter:title" content="Ozan Sazak"/><meta name="twitter:description" content="I&#x27;m a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog."/><meta name="twitter:image" content="https://sazak.io/opengraph-image?3c9e8dae5c8d2000"/><meta name="twitter:image:alt" content="I&#x27;m a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog."/><meta name="twitter:image:type" content="image/png"/><meta name="twitter:image:width" content="1200"/><meta name="twitter:image:height" content="630"/><link rel="icon" href="/favicon.ico?favicon.0598-h8n1_7xt.ico" sizes="64x64" type="image/x-icon"/>
1<script src="/_next/static/chunks/03~yq9q893hmn.js" noModule=""></script>
1</head><body><div hidden=""><!--$--><!--/$--></div><main vaul-drawer-wrapper="" class="min-h-screen bg-white"><div class="xl:flex"><aside data-side-menu-root="true" class="shrink-0 overflow-hidden border-r border-zinc-200 bg-zinc-50 transition-[width] duration-300 ease-out xl:flex-col lg:w-60 xl:w-72 relative hidden xl:flex"><div class="scrollable-area relative w-full flex-1" data-scroll-role="sidebar"><div aria-hidden="false" class="min-h-full transition-[opacity,transform,filter] duration-200 ease-out translate-x-0 opacity-100 blur-0"><button type="button" aria-expanded="true" aria-label="Collapse Navigation sidebar" title="Collapse Navigation sidebar" class="absolute right-3 top-4 z-20 inline-flex h-8 w-8 items-center justify-center rounded-full border border-zinc-200 bg-white/95 text-zinc-600 shadow-sm backdrop-blur transition-all duration-300 hover:border-zinc-300 hover:text-zinc-950"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-panel-left-close "><rect width="18" height="18" x="3" y="3" rx="2"></rect><path d="M9 3v18"></path><path d="m16 15-3-3 3-3"></path></svg></button><div class="bg-zinc-50 p-3"><div class="flex w-full flex-col text-sm"><div class="flex flex-col gap-4"><a class="link-card inline-flex items-center gap-2 p-2" href="/"><img src="/assets/me.jpg" alt="Ozan Sazak" width="40" height="40" loading="lazy" class="rounded-full border shadow-sm"/><div class="flex flex-col"><span class="font-bold tracking-tight text-md" style="font-family:Nunito">Ozan Sazak</span><span class="text-gray-600" style="font-family:Nunito">Software Engineer</span></div></a><div class="flex flex-col gap-1"><a class="group flex items-center justify-between rounded-lg p-2 bg-black text-white" href="/"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-home "><path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg><span class="font-medium text-white">Home</span></span></a><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/articles"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pencil-line "><path d="M12 20h9"></path><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"></path><path d="m15 5 3 3"></path></svg><span class="font-medium">Articles</span></span><span class="h-5 w-5 place-content-center rounded border border-gray-200 bg-gray-100 text-xs font-medium text-gray-500 transition-colors duration-200 group-hover:border-gray-300 grid" title="Shortcut key: 8">8</span></a><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/series"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-bookmark "><path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"></path></svg><span class="font-medium">Series</span></span><span class="h-5 w-5 place-content-center rounded border border-gray-200 bg-gray-100 text-xs font-medium text-gray-500 transition-colors duration-200 group-hover:border-gray-300 grid" title="Shortcut key: 2">2</span></a><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/talks"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-mic2 "><path d="m12 8-9.04 9.06a2.82 2.82 0 1 0 3.98 3.98L16 12"></path><circle cx="17" cy="7" r="5"></circle></svg><span class="font-medium">Talks</span></span><span class="h-5 w-5 place-content-center rounded border border-gray-200 bg-gray-100 text-xs font-medium text-gray-500 transition-colors duration-200 group-hover:border-gray-300 grid" title="Shortcut key: 5">5</span></a><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/reading-groups"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewB
1ox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-handshake "><path d="m11 17 2 2a1 1 0 1 0 3-3"></path><path d="m14 14 2.5 2.5a1 1 0 1 0 3-3l-3.88-3.88a3 3 0 0 0-4.24 0l-.88.88a1 1 0 1 1-3-3l2.81-2.81a5.79 5.79 0 0 1 7.06-.87l.47.28a2 2 0 0 0 1.42.25L21 4"></path><path d="m21 3 1 11h-2"></path><path d="M3 3 2 14l6.5 6.5a1 1 0 1 0 3-3"></path><path d="M3 4h8"></path></svg><span class="font-medium">Reading Groups</span></span><span class="h-5 w-5 place-content-center rounded border border-gray-200 bg-gray-100 text-xs font-medium text-gray-500 transition-colors duration-200 group-hover:border-gray-300 grid" title="Shortcut key: 2">2</span></a><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/reading-list"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-book-plus "><path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20"></path><path d="M9 10h6"></path><path d="M12 7v6"></path></svg><span class="font-medium">Reading List</span></span><span class="h-5 w-5 place-content-center rounded border border-gray-200 bg-gray-100 text-xs font-medium text-gray-500 transition-colors duration-200 group-hover:border-gray-300 grid" title="Shortcut key: 24">24</span></a><hr class="my-3"/><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/photography"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-camera "><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"></path><circle cx="12" cy="13" r="3"></circle></svg><span class="font-medium">Photography</span></span><span class="h-5 w-5 place-content-center rounded border border-gray-200 bg-gray-100 text-xs font-medium text-gray-500 transition-colors duration-200 group-hover:border-gray-300 grid" title="Shortcut key: 16">16</span></a><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/gear"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-dumbbell "><path d="m6.5 6.5 11 11"></path><path d="m21 21-1-1"></path><path d="m3 3 1 1"></path><path d="m18 22 4-4"></path><path d="m2 6 4-4"></path><path d="m3 10 7-7"></path><path d="m14 21 7-7"></path></svg><span class="font-medium">Gear</span></span><span class="h-5 w-5 place-content-center rounded border border-gray-200 bg-gray-100 text-xs font-medium text-gray-500 transition-colors duration-200 group-hover:border-gray-300 grid" title="Shortcut key: 12">12</span></a><div class="group flex items-center justify-between rounded-lg p-2 text-gray-400"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-tent-tree "><circle cx="4" cy="4" r="2"></circle><path d="m14 5 3-3 3 3"></path><path d="m14 10 3-3 3 3"></path><path d="M17 14V2"></path><path d="M17 14H7l-5 8h20Z"></path><path d="M8 14v8"></path><path d="m9 14 5 8"></path></svg><span class="font-medium">Travel</span><span class="text-xs text-gray-500 px-1 rounded-md bg-indigo-400/40">soon</span></span></div><div class="group flex items-center justify-between rounded-lg p-2 text-gray-400"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-book-open "><path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"></path><path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"></path></svg><span class="font-medium">Reading Notes</span><span class="text-xs text-gray-500 px-1 rounded-md bg-indigo-400/40">soon</span></span></div></div></div><hr class="my-3"/><div class="flex flex-col gap-2 text-sm"><span class="px-2 text-xs font-medium leading-relaxed text-gray-600">Contact me</span><div class="flex flex-col gap-1"><a href="https://twitter.com/intent/user?screen_name=oznszk" target="_blank" rel="noopener noreferrer" class="flex items-center justify-between gap-2 rounded-lg p-2 hover:bg-gray-200"><span class="inline-flex items-center gap-2 font-medium"><svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#000000" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M4 4l11.733 16h4.267l-11.733 -16z"></path><path d="M4 20l6.768 -6.768m2.46 -2.46l6.772 -6.772"></path></svg> <!-- -->Twitter</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewB
1ox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-up-right "><path d="M7 7h10v10"></path><path d="M7 17 17 7"></path></svg></a><a href="https://github.com/ozansz" target="_blank" rel="noopener noreferrer" class="flex items-center justify-between gap-2 rounded-lg p-2 hover:bg-gray-200"><span class="inline-flex items-center gap-2 font-medium"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github "><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"></path><path d="M9 18c-4.51 2-5-2-7-2"></path></svg> <!-- -->GitHub</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-up-right "><path d="M7 7h10v10"></path><path d="M7 17 17 7"></path></svg></a><a href="https://www.linkedin.com/in/ozan-sazak/" target="_blank" rel="noopener noreferrer" class="flex items-center justify-between gap-2 rounded-lg p-2 hover:bg-gray-200"><span class="inline-flex items-center gap-2 font-medium"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-linkedin "><path d="M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-2-2 2 2 0 0 0-2 2v7h-4v-7a6 6 0 0 1 6-6z"></path><rect width="4" height="12" x="2" y="9"></rect><circle cx="4" cy="4" r="2"></circle></svg> <!-- -->LinkedIn</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-up-right "><path d="M7 7h10v10"></path><path d="M7 17 17 7"></path></svg></a><a href="https://www.instagram.com/ozan.sazak" target="_blank" rel="noopener noreferrer" class="flex items-center justify-between gap-2 rounded-lg p-2 hover:bg-gray-200"><span class="inline-flex items-center gap-2 font-medium"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-instagram "><rect width="20" height="20" x="2" y="2" rx="5" ry="5"></rect><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"></path><line x1="17.5" x2="17.51" y1="6.5" y2="6.5"></line></svg> <!-- -->Instagram</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-up-right "><path d="M7 7h10v10"></path><path d="M7 17 17 7"></path></svg></a></div></div><hr class="my-3"/><div class="flex flex-col gap-2 text-sm"><span class="px-2 text-xs font-medium leading-relaxed text-gray-600">Stay tuned</span><div class="flex flex-col gap-1"><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/rss.xml"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-rss "><path d="M4 11a9 9 0 0 1 9 9"></path><path d="M4 4a16 16 0 0 1 16 16"></path><circle cx="5" cy="19" r="1"></circle></svg><span class="font-medium">RSS Feed</span></span></a><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/atom.xml"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-atom "><circle cx="12" cy="12" r="1"></circle><path d="M20.2 20.2c2.04-2.03.02-7.36-4.5-11.9-4.54-4.52-9.87-6.54-11.9-4.5-2.04 2.03-.02 7.36 4.5 11.9 4.54 4.52 9.87 6.54 11.9 4.5Z"></path><path d="M15.7 15.7c4.52-4.54 6.54-9.87 4.5-11.9-2.03-2.04-7.36-.02-11.9 4.5-4.52 4.54-6.54 9.87-4.5 11.9 2.03 2.04 7.36.02 11.9-4.5Z"></path></svg><span class="font-medium">Atom Feed</span></span></a><a class="group flex items-center justify-between rounded-lg p-2 hover:bg-gray-200" href="/feed.json"><span class="flex items-center gap-2"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewB
1ox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-rss "><path d="M4 11a9 9 0 0 1 9 9"></path><path d="M4 4a16 16 0 0 1 16 16"></path><circle cx="5" cy="19" r="1"></circle></svg><span class="font-medium">JSON Feed</span></span></a></div></div></div></div></div></div></aside><div class="flex flex-1"><div class="scrollable-area relative w-full flex flex-col"><header class="sticky inset-x-0 top-0 z-10 mx-auto flex h-12 w-full shrink-0 items-center overflow-hidden bg-white text-sm font-medium xl:hidden"><div class="flex h-full w-full items-center px-3"><div class="flex w-full items-center justify-between gap-2"><div class="flex flex-1 items-center gap-1"><button type="button" aria-haspopup="dialog" aria-expanded="false" aria-controls="radix-_R_1alfjb_" data-state="closed" class="inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors duration-300 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950 disabled:pointer-events-none disabled:opacity-50 dark:focus-visible:ring-gray-300 hover:bg-gray-100 hover:text-gray-900 dark:hover:bg-gray-800 dark:hover:text-gray-50 h-9 w-9" title="Toggle drawer"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-menu "><line x1="4" x2="20" y1="12" y2="12"></line><line x1="4" x2="20" y1="6" y2="6"></line><line x1="4" x2="20" y1="18" y2="18"></line></svg></button><div class="flex flex-1 items-center justify-between"><span data-br="_R_aalfjb_" data-brr="0.35" style="display:inline-block;vertical-align:top;text-decoration:inherit;text-wrap:balance"><span class="line-clamp-2 font-semibold tracking-tight">Ozan Sazak</span></span>
1<script>self.__wrap_n=self.__wrap_n||(self.CSS&&CSS.supports("text-wrap","balance")?1:2);self.__wrap_b=(a,b,c)=>{let d=(c=c||document.querySelector(`[data-br="${a}"]`)).parentElement,e=a=>c.style.maxWidth=a+"px";c.style.maxWidth="";let f=d.clientWidth,g=d.clientHeight,h=f/2-.25,i=f+.5,j;if(f){for(e(h),h=Math.max(c.scrollWidth,h);h+1<i;)e(j=Math.round((h+i)/2)),d.clientHeight===g?i=j:h=j;e(i*b+f*(1-b))}c.__wrap_o||"u">typeof ResizeObserver&&(c.__wrap_o=new ResizeObserver(()=>{self.__wrap_b(0,+c.dataset.brr,c)})).observe(d)};self.__wrap_n!=1&&self.__wrap_b("_R_aalfjb_",0.35)</script>
1</div></div></div></div></header><div class="content-wrapper-home"><article class="content contentserver-rendered"><div class="mb-6 flex flex-col gap-3"><h1 as="h1" data-br="_R_1b5fjb_" data-brr="1" style="display:inline-block;vertical-align:top;text-decoration:inherit;text-wrap:balance">Hi! I&#x27;m Ozan 👋</h1>
1<script>self.__wrap_n=self.__wrap_n||(self.CSS&&CSS.supports("text-wrap","balance")?1:2);self.__wrap_b=(a,b,c)=>{let d=(c=c||document.querySelector(`[data-br="${a}"]`)).parentElement,e=a=>c.style.maxWidth=a+"px";c.style.maxWidth="";let f=d.clientWidth,g=d.clientHeight,h=f/2-.25,i=f+.5,j;if(f){for(e(h),h=Math.max(c.scrollWidth,h);h+1<i;)e(j=Math.round((h+i)/2)),d.clientHeight===g?i=j:h=j;e(i*b+f*(1-b))}c.__wrap_o||"u">typeof ResizeObserver&&(c.__wrap_o=new ResizeObserver(()=>{self.__wrap_b(0,+c.dataset.brr,c)})).observe(d)};self.__wrap_n!=1&&self.__wrap_b("_R_1b5fjb_",1)</script>
1<div class="flex flex-row justify-between"><div class="flex flex-row justify-start items-center"></div></div></div><div class="text-sm"><p>I&#x27;m a Software Engineer at <a href="https://datadoghq.com" class="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6d28d9)" target="_blank" rel="noopener noreferrer"><span>Datadog</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-dog "><path d="M10 5.172C10 3.782 8.423 2.679 6.5 3c-2.823.47-4.113 6.006-4 7 .08.703 1.725 1.722 3.656 1 1.261-.472 1.96-1.45 2.344-2.5"></path><path d="M14.267 5.172c0-1.39 1.577-2.493 3.5-2.172 2.823.47 4.113 6.006 4 7-.08.703-1.725 1.722-3.656 1-1.261-.472-1.855-1.45-2.239-2.5"></path><path d="M8 14v.5"></path><path d="M16 14v.5"></path><path d="M11.25 16.25h1.5L12 17l-.75-.75Z"></path><path d="M4.42 11.247A13.152 13.152 0 0 0 4 14.556C4 18.728 7.582 21 12 21s8-2.272 8-6.444c0-1.061-.162-2.2-.493-3.309m-9.243-6.082A8.801 8.801 0 0 1 12 5c.78 0 1.5.108 2.161.306"></path></svg></a>. I enjoy building stuff, not just software, and <a href="/articles" class="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90" style="text-decoration:none;background:linear-gradient(to right, #db2777, #c026d3)"><span>writing</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-pen-line "><path d="M12 20h9"></path><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"></path></svg></a> and <a href="/talks" class="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90" style="text-decoration:none;background:linear-gradient(to right, #9333ea, #db2777)"><span>talking</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-mic "><path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" x2="12" y1="19" y2="22"></line></svg></a> about them. Taking <a href="/photography" class="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90" style="text-decoration:none;background:linear-gradient(to right, #2563eb, #4f46e5)"><span>photos</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-camera "><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"></path><circle cx="12" cy="13" r="3"></circle></svg></a> while traveling, and making music (I was once in a rock band called <a href="https://youtu.be/EUp5wp3HO-s?si=kKvAD5vTJ8h87LxO&amp;t=164" class="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90" style="text-decoration:none;background:linear-gradient(to right, #d97706, #c2410c)" target="_blank" rel="noopener noreferrer"><span>METUllica</span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-music "><path d="M9 18V5l12-2v13"></path><circle cx="6" cy="18" r="3"></circle><circle cx="18" cy="16" r="3"></circle></svg></a> with my professors) are other things I love to do.</p>
2</div></article><div class="content"><a class="items-center justify-center rounded-md text-sm font-medium transition-colors duration-300 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950 disabled:pointer-events-none disabled:opacity-50 dark:focus-visible:ring-gray-300 text-gray-900 underline-offset-4 hover:underline dark:text-gray-50 h-9 py-2 inline px-0" href="/articles"><h2 class="mb-4 mt-8">Articles</h2></a><!--$?--><template id="B:0"></template><div class="grid place-content-center h-screen w-full"><div class="inline-block h-4 w-4 animate-spin rounded-full border-[2px] border-current border-t-transparent text-black" role="status" aria-label="loading"><span class="sr-only">Loading...</span></div></div><!--/$--></div></div></div><!--$--><!--/$--></div></div></main>
2<script>requestAnimationFrame(function(){$RT=performance.now()});</script>
2<script src="/_next/static/chunks/06lc7v63nh4m9.js" id="_R_" async=""></script>
2<div hidden id="S:0"><div class="text-sm"><div class="grid grid-cols-1 md:grid-cols-[4rem_1fr] py-2 font-medium text-gray-500"><span class="hidden text-left md:grid">Year</span><span><span class="grid grid-cols-4 items-start md:grid-cols-8"><span class="col-span-1 text-left hidden md:block">Date</span><span class="col-span-3 md:col-span-6">Title</span><span class="col-span-1 text-right">Views</span></span></span></div><div class="group/list-wrapper"><ul class="group/list list-none"><li class="group/list-item grid grid-cols-1 md:grid-cols-[4rem_1fr] p-0 group-hover/list-wrapper:text-gray-300"><span class="pointer-events-none hidden items-center tabular-nums transition-colors duration-300 group-hover/list:text-gray-900 md:grid border-t border-gray-200">2026</span><a class="group-hover/list-item:text-gray-900" href="/articles/tracing-goroutines-in-realtime-with-ebpf-2026-03-31"><span class="grid grid-cols-4 items-start gap-2 border-t border-gray-200 py-4 md:grid-cols-8"><div class="h-full col-span-1 tabular-nums hidden md:flex justify-start items-center text-left"><time dateTime="2026-03-31">31.03</time></div><span class="col-span-3 line-clamp-4 md:col-span-6"><div class="flex flex-row gap-4"><img src="/assets/articles/tracing-goroutines-in-realtime-with-ebpf-2026-03-31.jpeg" alt="Tracing Goroutines in Realtime with eBPF" class="smmax:hidden w-48 h-full object-cover rounded-lg group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100 transition-all duration-300"/><div class="flex flex-col gap-2"><span class="text-lg font-semibold" style="font-family:Nunito">Tracing Goroutines in Realtime with eBPF<!-- --> <!-- --> </span><div class="hidden md:flex flex-row flex-wrap gap-1 mt-2"><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #ea580c, #db2777)"><span>ebpf</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #ea580c, #db2777)"><span>bpftrace</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6366f1)"><span>go</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #ea580c, #db2777)"><span>linux</span></span></div></div></div></span><div class="h-full col-span-1 justify-start items-center text-right"><span><span class="h-full flex justify-end items-center tabular-nums" title="null views" style="opacity:0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-off "><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg></span></span></div></span></a></li></ul><ul class="group/list list-none"><li class="group/list-item grid grid-cols-1 md:grid-cols-[4rem_1fr] p-0 group-hover/list-wrapper:text-gray-300"><span class="pointer-events-none hidden items-center tabular-nums transition-colors duration-300 group-hover/list:text-gray-900 md:grid border-t border-gray-200">2025</span><a class="group-hover/list-item:text-gray-900" href="/articles/visual-guide-to-go-maps-hash-tables-2025-10-26"><span class="grid grid-cols-4 items-start gap-2 border-t border-gray-200 py-4 md:grid-cols-8"><div class="h-full col-span-1 tabular-nums hidden md:flex justify-start items-center text-left"><time dateTime="2025-10-26">26.10</time></div><span class="col-span-3 line-clamp-4 md:col-span-6"><div class="flex flex-row gap-4"><img src="/assets/articles/visual-guide-to-go-maps-hash-tables-2025-10-26.jpeg" alt="Visual Guide to Go Maps: Hash Tables" class="smmax:hidden w-48 h-full object-cover rounded-lg group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100 transition-all duration-300"/><div class="flex flex-col gap-2"><span class="text-lg font-semibold" style="font-family:Nunito">Visual Guide to Go Maps: Hash Tables<!-- --> <!-- --> </span><div class="hidden md:flex flex-row flex-wrap gap-1 mt-2"><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6366f1)"><span>go</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6366f1)"><span>maps</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #0284c7, #2563eb)"><span>data structures</span></span></div></div></div></span><div class="h-full col-span-1 justify-start items-center text-right"><span><span class="h-full flex justify-end items-center tabular-nums" title="null views" style="opacity:0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-off "><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg></span></span></div></span></a></li></ul><ul class="group/list list-none"><li class="group/list-item grid grid-cols-1 md:grid-cols-[4rem_1fr] p-0 group-hover/list-wrapper:text-gray-300"><span class="pointer-events-none hidden items-center tabular-nums transition-colors duration-300 group-hover/list:text-gray-900 md:grid border-t border-gray-200">2024</span><a class="group-hover/list-item:text-gray-900" href="/articles/an-applied-introduction-to-ebpf-with-go-2024-06-06"><span class="grid grid-cols-4 items-start gap-2 border-t border-gray-200 py-4 md:grid-cols-8"><div class="h-full col-span-1 tabular-nums hidden md:flex justify-start items-center text-left"><time dateTime="2024-06-06">06.06</time></div><span class="col-span-3 line-clamp-4 md:col-span-6"><div class="flex flex-row gap-4"><img src="/assets/articles/an-applied-introduction-to-ebpf-with-go-2024-06-06.jpeg" alt="An Applied Introduction to eBPF with Go" class="smmax:hidden w-48 h-full object-cover rounded-lg group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100 transition-all duration-300"/><div class="flex flex-col gap-2"><span class="text-lg font-semibold" style="font-family:Nunito">An Applied Introduction to eBPF with Go<!-- --> <!-- --> </span><div class="hidden md:flex flex-row flex-wrap gap-1 mt-2"><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6366f1)"><span>go</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #ea580c, #db2777)"><span>ebpf</span></span></div></div></div></span><div class="h-full col-span-1 justify-start items-center text-right"><span><span class="h-full flex justify-end items-center tabular-nums" title="null views" style="opacity:0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-off "><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg></span></span></div></span></a></li><li class="group/list-item grid grid-cols-1 md:grid-cols-[4rem_1fr] p-0 group-hover/list-wrapper:text-gray-300"><span class="pointer-events-none hidden items-center tabular-nums transition-colors duration-300 group-hover/list:text-gray-900 md:grid"></span><a class="group-hover/list-item:text-gray-900" href="/articles/visual-guide-to-slices-in-go-2024-03-25"><span class="grid grid-cols-4 items-start gap-2 border-t border-gray-200 py-4 md:grid-cols-8"><div class="h-full col-span-1 tabular-nums hidden md:flex justify-start items-center text-left"><time dateTime="2024-03-25">25.03</time></div><span class="col-span-3 line-clamp-4 md:col-span-6"><div class="flex flex-row gap-4"><img src="/assets/articles/visual-guide-to-slices-in-go-2024-03-25.jpeg" alt="Visual Guide to Slices in Go" class="smmax:hidden w-48 h-full object-cover rounded-lg group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100 transition-all duration-300"/><div class="flex flex-col gap-2"><span class="text-lg font-semibold" style="font-family:Nunito">Visual Guide to Slices in Go<!-- --> <!-- --> </span><div class="hidden md:flex flex-row flex-wrap gap-1 mt-2"><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6366f1)"><span>go</span></span></div></div></div></span><div class="h-full col-span-1 justify-start items-center text-right"><span><span class="h-full flex justify-end items-center tabular-nums" title="null views" style="opacity:0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-off "><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg></span></span></div></span></a></li><li class="group/list-item grid grid-cols-1 md:grid-cols-[4rem_1fr] p-0 group-hover/list-wrapper:text-gray-300"><span class="pointer-events-none hidden items-center tabular-nums transition-colors duration-300 group-hover/list:text-gray-900 md:grid"></span><a class="group-hover/list-item:text-gray-900" href="/articles/how-i-built-my-own-go-package-index---gosazakio-2024-03-10"><span class="grid grid-cols-4 items-start gap-2 border-t border-gray-200 py-4 md:grid-cols-8"><div class="h-full col-span-1 tabular-nums hidden md:flex justify-start items-center text-left"><time dateTime="2024-03-10">10.03</time></div><span class="col-span-3 line-clamp-4 md:col-span-6"><div class="flex flex-row gap-4"><img src="/assets/articles/how-i-built-my-own-go-package-index---gosazakio-2024-03-10.jpeg" alt="How I built my own Go package index - go.sazak.io" class="smmax:hidden w-48 h-full object-cover rounded-lg group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100 transition-all duration-300"/><div class="flex flex-col gap-2"><span class="text-lg font-semibold" style="font-family:Nunito">How I built my own Go package index - go.sazak.io<!-- --> <!-- --> </span><div class="hidden md:flex flex-row flex-wrap gap-1 mt-2"><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6366f1)"><span>go</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #ea580c, #db2777)"><span>nextjs</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #d97706, #c2410c)"><span>shadcn</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #ea580c, #db2777)"><span>tooling</span></span></div></div></div></span><div class="h-full col-span-1 justify-start items-center text-right"><span><span class="h-full flex justify-end items-center tabular-nums" title="null views" style="opacity:0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-off "><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg></span></span></div></span></a></li></ul><ul class="group/list list-none"><li class="group/list-item grid grid-cols-1 md:grid-cols-[4rem_1fr] p-0 group-hover/list-wrapper:text-gray-300"><span class="pointer-events-none hidden items-center tabular-nums transition-colors duration-300 group-hover/list:text-gray-900 md:grid border-t border-gray-200">2023</span><a class="group-hover/list-item:text-gray-900" href="/articles/fantastic-side-projects-and-where-to-find-them-2023-09-03"><span class="grid grid-cols-4 items-start gap-2 border-t border-gray-200 py-4 md:grid-cols-8"><div class="h-full col-span-1 tabular-nums hidden md:flex justify-start items-center text-left"><time dateTime="2023-09-03">03.09</time></div><span class="col-span-3 line-clamp-4 md:col-span-6"><div class="flex flex-row gap-4"><img src="/assets/articles/fantastic-side-projects-and-where-to-find-them-2023-09-03.jpeg" alt="Fantastic Side Projects and Where to Find Them" class="smmax:hidden w-48 h-full object-cover rounded-lg group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100 transition-all duration-300"/><div class="flex flex-col gap-2"><span class="text-lg font-semibold" style="font-family:Nunito">Fantastic Side Projects and Where to Find Them<!-- --> <!-- --> </span><div class="hidden md:flex flex-row flex-wrap gap-1 mt-2"><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #16a34a, #059669)"><span>programming</span></span></div></div></div></span><div class="h-full col-span-1 justi
2fy-start items-center text-right"><span><span class="h-full flex justify-end items-center tabular-nums" title="null views" style="opacity:0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-off "><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg></span></span></div></span></a></li></ul><ul class="group/list list-none"><li class="group/list-item grid grid-cols-1 md:grid-cols-[4rem_1fr] p-0 group-hover/list-wrapper:text-gray-300"><span class="pointer-events-none hidden items-center tabular-nums transition-colors duration-300 group-hover/list:text-gray-900 md:grid border-t border-gray-200">2022</span><a class="group-hover/list-item:text-gray-900" href="/articles/cloud-native-patterns-illustrated-fan-in-and-fan-out-2022-10-30"><span class="grid grid-cols-4 items-start gap-2 border-t border-gray-200 py-4 md:grid-cols-8"><div class="h-full col-span-1 tabular-nums hidden md:flex justify-start items-center text-left"><time dateTime="2022-10-30">30.10</time></div><span class="col-span-3 line-clamp-4 md:col-span-6"><div class="flex flex-row gap-4"><img src="/assets/articles/cloud-native-patterns-illustrated-fan-in-and-fan-out-2022-10-30.jpeg" alt="Cloud Native Patterns Illustrated: Fan-in and Fan-out" class="smmax:hidden w-48 h-full object-cover rounded-lg group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100 transition-all duration-300"/><div class="flex flex-col gap-2"><span class="text-lg font-semibold" style="font-family:Nunito">Cloud Native Patterns Illustrated: Fan-in and Fan-out<!-- --> <!-- --> </span><div class="hidden md:flex flex-row flex-wrap gap-1 mt-2"><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6366f1)"><span>go</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #d97706, #c2410c)"><span>concurrency</span></span></div></div></div></span><div class="h-full col-span-1 justify-start items-center text-right"><span><span class="h-full flex justify-end items-center tabular-nums" title="null views" style="opacity:0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-off "><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg></span></span></div></span></a></li><li class="group/list-item grid grid-cols-1 md:grid-cols-[4rem_1fr] p-0 group-hover/list-wrapper:text-gray-300"><span class="pointer-events-none hidden items-center tabular-nums transition-colors duration-300 group-hover/list:text-gray-900 md:grid"></span><a class="group-hover/list-item:text-gray-900" href="/articles/gls-file-manager-on-terminal-with-go-2022-07-19"><span class="grid grid-cols-4 items-start gap-2 border-t border-gray-200 py-4 md:grid-cols-8"><div class="h-full col-span-1 tabular-nums hidden md:flex justify-start items-center text-left"><time dateTime="2022-07-19">19.07</time></div><span class="col-span-3 line-clamp-4 md:col-span-6"><div class="flex flex-row gap-4"><img src="/assets/articles/gls-file-manager-on-terminal-with-go-2022-07-19.jpeg" alt="gls: File Manager on Terminal with Go" class="smmax:hidden w-48 h-full object-cover rounded-lg group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100 transition-all duration-300"/><div class="flex flex-col gap-2"><span class="text-lg font-semibold" style="font-family:Nunito">gls: File Manager on Terminal with Go<!-- --> <!-- --> </span><div class="hidden md:flex flex-row flex-wrap gap-1 mt-2"><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #7c3aed, #6366f1)"><span>go</span></span><span class="inline-flex items-center gap-1.5 rounded-full text-white font-medium transition-all hover:brightness-90 text-xs px-2 py-0.5 group-hover/list-wrapper:opacity-25 group-hover/list-item:!opacity-100" style="text-decoration:none;background:linear-gradient(to right, #16a34a, #059669)"><span>cli</span></span></div></div></div></span><div class="h-full col-span-1 justify-start items-center text-right"><span><span class="h-full flex justify-end items-center tabular-nums" title="null views" style="opacity:0"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-off "><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"></path><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"></path><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"></path><line x1="2" x2="22" y1="2" y2="22"></line></svg></span></span></div></span></a></li></ul></div></div></div>
2<script>$RB=[];$RV=function(a){$RT=performance.now();for(var b=0;b<a.length;b+=2){var c=a[b],e=a[b+1];null!==e.parentNode&&e.parentNode.removeChild(e);var f=c.parentNode;if(f){var g=c.previousSibling,h=0;do{if(c&&8===c.nodeType){var d=c.data;if("/$"===d||"/&"===d)if(0===h)break;else h--;else"$"!==d&&"$?"!==d&&"$~"!==d&&"$!"!==d&&"&"!==d||h++}d=c.nextSibling;f.removeChild(c);c=d}while(c);for(;e.firstChild;)f.insertBefore(e.firstChild,c);g.data="$";g._reactRetry&&requestAnimationFrame(g._reactRetry)}}a.length=0};
3$RC=function(a,b){if(b=document.getElementById(b))(a=document.getElementById(a))?(a.previousSibling.data="$~",$RB.push(a,b),2===$RB.length&&("number"!==typeof $RT?requestAnimationFrame($RV.bind(null,$RB)):(a=performance.now(),setTimeout($RV.bind(null,$RB),2300>a&&2E3<a?2300-a:$RT+300-a)))):b.parentNode.removeChild(b)};$RC("B:0","S:0")</script>
3<script>(self.__next_f=self.__next_f||[]).push([0])</script>
3<script>self.__next_f.push([1,"1:\"$Sreact.fragment\"\n4:I[922556,[\"/_next/static/chunks/0~6uqz2cc7cgk.js\",\"/_next/static/chunks/060eq880magqv.js\"],\"OutletBoundary\"]\n5:\"$Sreact.suspense\"\n7:I[922556,[\"/_next/static/chunks/0~6uqz2cc7cgk.js\",\"/_next/static/chunks/060eq880magqv.js\"],\"ViewportBoundary\"]\n9:I[922556,[\"/_next/static/chunks/0~6uqz2cc7cgk.js\",\"/_next/static/chunks/060eq880magqv.js\"],\"MetadataBoundary\"]\nb:I[332435,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\"],\"default\",1]\n:HL[\"/_next/static/chunks/03r7fign14sf2.css\",\"style\"]\n:HL[\"/_next/static/chunks/0nxynu6o846p8.css\",\"style\"]\n:HC[\"/\",\"\"]\n"])</script>
3<script>self.__next_f.push([1,"0:{\"P\":null,\"c\":[\"\",\"\"],\"q\":\"\",\"i\":false,\"f\":[[[\"\",{\"children\":[\"__PAGE__\",{}]},\"$undefined\",\"$undefined\",16],[[\"$\",\"$1\",\"c\",{\"children\":[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/chunks/03r7fign14sf2.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/chunks/0nxynu6o846p8.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-0\",{\"src\":\"/_next/static/chunks/078gj~ojf_wnm.js\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-1\",{\"src\":\"/_next/static/chunks/0zbvl-0n~576..js\",\"async\":true,\"nonce\":\"$undefined\"}]],\"$L2\"]}],{\"children\":[[\"$\",\"$1\",\"c\",{\"children\":[\"$L3\",[[\"$\",\"script\",\"script-0\",{\"src\":\"/_next/static/chunks/0n6k61d0zylrv.js\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-1\",{\"src\":\"/_next/static/chunks/079g-_hol5.sn.js\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-2\",{\"src\":\"/_next/static/chunks/053s04cvac324.js\",\"async\":true,\"nonce\":\"$undefined\"}]],[\"$\",\"$L4\",null,{\"children\":[\"$\",\"$5\",null,{\"name\":\"Next.MetadataOutlet\",\"children\":\"$@6\"}]}]]}],{},null,false,null]},null,false,null],[\"$\",\"$1\",\"h\",{\"children\":[null,[\"$\",\"$L7\",null,{\"children\":\"$L8\"}],[\"$\",\"div\",null,{\"hidden\":true,\"children\":[\"$\",\"$L9\",null,{\"children\":[\"$\",\"$5\",null,{\"name\":\"Next.Metadata\",\"children\":\"$La\"}]}]}],null]}],false]],\"m\":\"$undefined\",\"G\":[\"$b\",[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/chunks/03r7fign14sf2.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/chunks/0nxynu6o846p8.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}]]],\"S\":true,\"h\":null,\"s\":\"$undefined\",\"l\":\"$undefined\",\"p\":\"$undefined\",\"d\":\"$undefined\",\"b\":\"Bj08-3CBuk7-W1stxSjp9\"}\n"])</script>
3<script>self.__next_f.push([1,"c:I[793733,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\"],\"SideMenu\"]\nd:I[462504,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\",\"/_next/static/chunks/0n6k61d0zylrv.js\",\"/_next/static/chunks/079g-_hol5.sn.js\",\"/_next/static/chunks/053s04cvac324.js\"],\"\"]\ne:I[208555,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\"],\"NavigationLink\"]\n1b:I[310832,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\",\"/_next/static/chunks/0n6k61d0zylrv.js\",\"/_next/static/chunks/079g-_hol5.sn.js\",\"/_next/static/chunks/053s04cvac324.js\"],\"FloatingHeader\"]\n1c:I[861555,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\",\"/_next/static/chunks/0n6k61d0zylrv.js\",\"/_next/static/chunks/079g-_hol5.sn.js\",\"/_next/static/chunks/053s04cvac324.js\"],\"default\"]\n"])</script>
3<script>self.__next_f.push([1,"2:[\"$\",\"html\",null,{\"lang\":\"en\",\"suppressHydrationWarning\":true,\"children\":[\"$\",\"body\",null,{\"suppressHydrationWarning\":true,\"children\":[[\"$\",\"main\",null,{\"vaul-drawer-wrapper\":\"\",\"className\":\"min-h-screen bg-white\",\"children\":[\"$\",\"div\",null,{\"className\":\"xl:flex\",\"children\":[[\"$\",\"$Lc\",null,{\"className\":\"relative hidden xl:flex\",\"hideOnAdmin\":true,\"children\":[\"$\",\"div\",null,{\"className\":\"flex w-full flex-col text-sm\",\"children\":[[\"$\",\"div\",null,{\"className\":\"flex flex-col gap-4\",\"children\":[[\"$\",\"$Ld\",null,{\"href\":\"/\",\"className\":\"link-card inline-flex items-center gap-2 p-2\",\"children\":[[\"$\",\"img\",null,{\"src\":\"/assets/me.jpg\",\"alt\":\"Ozan Sazak\",\"width\":40,\"height\":40,\"loading\":\"lazy\",\"className\":\"rounded-full border shadow-sm\"}],[\"$\",\"div\",null,{\"className\":\"flex flex-col\",\"children\":[[\"$\",\"span\",null,{\"className\":\"font-bold tracking-tight text-md\",\"style\":{\"fontFamily\":\"Nunito\"},\"children\":\"Ozan Sazak\"}],[\"$\",\"span\",null,{\"className\":\"text-gray-600\",\"style\":{\"fontFamily\":\"Nunito\"},\"children\":\"Software Engineer\"}]]}]]}],[\"$\",\"div\",null,{\"className\":\"flex flex-col gap-1\",\"children\":[[\"$\",\"$Le\",\"/\",{\"href\":\"/\",\"label\":\"Home\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-home \",\"children\":[[\"$\",\"path\",\"y5dka4\",{\"d\":\"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z\"}],[\"$\",\"polyline\",\"e2us08\",{\"points\":\"9 22 9 12 15 12 15 22\"}],\"$undefined\"]}],\"shortcutNumber\":null,\"wip\":\"$undefined\",\"beta\":\"$undefined\",\"new_\":\"$undefined\"}],[\"$\",\"$Le\",\"/articles\",{\"href\":\"/articles\",\"label\":\"Articles\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-pencil-line \",\"children\":[[\"$\",\"path\",\"t2du7b\",{\"d\":\"M12 20h9\"}],[\"$\",\"path\",\"ymcmye\",{\"d\":\"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z\"}],[\"$\",\"path\",\"1w25hb\",{\"d\":\"m15 5 3 3\"}],\"$undefined\"]}],\"shortcutNumber\":8,\"wip\":\"$undefined\",\"beta\":\"$undefined\",\"new_\":false}],[\"$\",\"$Le\",\"/series\",{\"href\":\"/series\",\"label\":\"Series\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-bookmark \",\"children\":[[\"$\",\"path\",\"1fy3hk\",{\"d\":\"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z\"}],\"$undefined\"]}],\"shortcutNumber\":2,\"wip\":\"$undefined\",\"beta\":\"$undefined\",\"new_\":\"$undefined\"}],[\"$\",\"$Le\",\"/talks\",{\"href\":\"/talks\",\"label\":\"Talks\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-mic2 \",\"children\":[[\"$\",\"path\",\"zoua8r\",{\"d\":\"m12 8-9.04 9.06a2.82 2.82 0 1 0 3.98 3.98L16 12\"}],[\"$\",\"circle\",\"1fomce\",{\"cx\":\"17\",\"cy\":\"7\",\"r\":\"5\"}],\"$undefined\"]}],\"shortcutNumber\":5,\"wip\":\"$undefined\",\"beta\":\"$undefined\",\"new_\":\"$undefined\"}],[\"$\",\"$Le\",\"/reading-groups\",{\"href\":\"/reading-groups\",\"label\":\"Reading Groups\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\"
3:16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-handshake \",\"children\":[[\"$\",\"path\",\"efffak\",{\"d\":\"m11 17 2 2a1 1 0 1 0 3-3\"}],[\"$\",\"path\",\"9pr0kb\",{\"d\":\"m14 14 2.5 2.5a1 1 0 1 0 3-3l-3.88-3.88a3 3 0 0 0-4.24 0l-.88.88a1 1 0 1 1-3-3l2.81-2.81a5.79 5.79 0 0 1 7.06-.87l.47.28a2 2 0 0 0 1.42.25L21 4\"}],[\"$\",\"path\",\"1tisrp\",{\"d\":\"m21 3 1 11h-2\"}],[\"$\",\"path\",\"1uvwmv\",{\"d\":\"M3 3 2 14l6.5 6.5a1 1 0 1 0 3-3\"}],[\"$\",\"path\",\"1ep09j\",{\"d\":\"M3 4h8\"}],\"$undefined\"]}],\"shortcutNumber\":2,\"wip\":\"$undefined\",\"beta\":\"$undefined\",\"new_\":\"$undefined\"}],[\"$\",\"$Le\",\"/reading-list\",{\"href\":\"/reading-list\",\"label\":\"Reading List\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-book-plus \",\"children\":[[\"$\",\"path\",\"t4utmx\",{\"d\":\"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20\"}],[\"$\",\"path\",\"9gxzsh\",{\"d\":\"M9 10h6\"}],[\"$\",\"path\",\"lw1j43\",{\"d\":\"M12 7v6\"}],\"$undefined\"]}],\"shortcutNumber\":24,\"wip\":\"$undefined\",\"beta\":\"$undefined\",\"new_\":\"$undefined\"}],[\"$\",\"hr\",\"6\",{\"className\":\"my-3\"}],[\"$\",\"$Le\",\"/photography\",{\"href\":\"/photography\",\"label\":\"Photography\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-camera \",\"children\":[\"$Lf\",\"$L10\",\"$undefined\"]}],\"shortcutNumber\":16,\"wip\":\"$undefined\",\"beta\":\"$undefined\",\"new_\":\"$undefined\"}],\"$L11\",\"$L12\",\"$L13\"]}]]}],\"$L14\",\"$L15\",\"$L16\",\"$L17\"]}]}],\"$L18\"]}]}],\"$L19\",\"$L1a\"]}]}]\n"])</script>
3<script>self.__next_f.push([1,"3:[\"$\",\"div\",null,{\"id\":\"$undefined\",\"className\":\"scrollable-area relative w-full flex flex-col\",\"children\":[[\"$\",\"$L1b\",null,{\"title\":\"Ozan Sazak\"}],[\"$\",\"div\",null,{\"className\":\"content-wrapper-home\",\"children\":[[\"$\",\"article\",null,{\"className\":\"content contentserver-rendered\",\"children\":[[\"$\",\"div\",null,{\"className\":\"mb-6 flex flex-col gap-3\",\"children\":[[\"$\",\"$L1c\",null,{\"as\":\"h1\",\"children\":\"Hi! I'm Ozan 👋\"}],\"$undefined\",[\"$\",\"div\",null,{\"className\":\"flex flex-row justify-between\",\"children\":[[\"$\",\"div\",null,{\"className\":\"flex flex-row justify-start items-center\",\"children\":[\"$undefined\",\"$undefined\",\"$undefined\",\"$undefined\"]}],\"$undefined\"]}]]}],[\"$\",\"div\",null,{\"className\":\"text-sm\",\"children\":[[\"$\",\"p\",\"0\",{\"children\":[\"I'm a Software Engineer at \",[\"$\",\"a\",\"1\",{\"href\":\"https://datadoghq.com\",\"className\":\"inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90\",\"style\":{\"textDecoration\":\"none\",\"background\":\"linear-gradient(to right, #7c3aed, #6d28d9)\"},\"target\":\"_blank\",\"rel\":\"noopener noreferrer\",\"children\":[[\"$\",\"span\",null,{\"children\":\"Datadog\"}],[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-dog \",\"children\":[[\"$\",\"path\",\"19br0u\",{\"d\":\"M10 5.172C10 3.782 8.423 2.679 6.5 3c-2.823.47-4.113 6.006-4 7 .08.703 1.725 1.722 3.656 1 1.261-.472 1.96-1.45 2.344-2.5\"}],[\"$\",\"path\",\"11n1an\",{\"d\":\"M14.267 5.172c0-1.39 1.577-2.493 3.5-2.172 2.823.47 4.113 6.006 4 7-.08.703-1.725 1.722-3.656 1-1.261-.472-1.855-1.45-2.239-2.5\"}],[\"$\",\"path\",\"1nzgdb\",{\"d\":\"M8 14v.5\"}],[\"$\",\"path\",\"1lajdz\",{\"d\":\"M16 14v.5\"}],[\"$\",\"path\",\"12kq1m\",{\"d\":\"M11.25 16.25h1.5L12 17l-.75-.75Z\"}],[\"$\",\"path\",\"wsu29d\",{\"d\":\"M4.42 11.247A13.152 13.152 0 0 0 4 14.556C4 18.728 7.582 21 12 21s8-2.272 8-6.444c0-1.061-.162-2.2-.493-3.309m-9.243-6.082A8.801 8.801 0 0 1 12 5c.78 0 1.5.108 2.161.306\"}],\"$undefined\"]}],\"$undefined\"]}],\". I enjoy building stuff, not just software, and \",[\"$\",\"a\",\"3\",{\"href\":\"/articles\",\"className\":\"inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90\",\"style\":{\"textDecoration\":\"none\",\"background\":\"linear-gradient(to right, #db2777, #c026d3)\"},\"children\":[[\"$\",\"span\",null,{\"children\":\"writing\"}],[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-pen-line \",\"children\":[[\"$\",\"path\",\"t2du7b\",{\"d\":\"M12 20h9\"}],[\"$\",\"path\",\"ymcmye\",{\"d\":\"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z\"}],\"$undefined\"]}],\"$undefined\"]}],\" and \",[\"$\",\"a\",\"5\",{\"href\":\"/talks\",\"className\":\"inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90\",\"style\":{\"textDecoration\":\"none\",\"background\":\"linear-gradient(to right, #9333ea, #db2777)\"},\"children\":[[\"$\",\"span\",null,{\"children\":\"talking\"}],[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-mic \",\"children\":[[\"$\",\"path\",\"131961\",{\"d\":\"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z\"}],[\"$\",\"path\",\"1vc78b\",{\"d\":\"M19 10v2a7 7 0 0 1-14 0v-2\"}],[\"$\",\"line\",\"x3vr5v\",{\"x1\":\"12\",\"x2\":\"12\",\"y1\":\"19\",\"y2\":\"22\"}],\"$undefined\"]}],\"$undefined\"]}],\" about them. Taking \",[\"$\",\"a\",\"7\",{\"href\":\"/photography\",\"className\":\"inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90\",\"style\":{\"textDecoration\":\"none\",\"background\":\"linear-gradient(to right, #2563eb, #4f46e5)\"},\"children\":[[\"$\",\"span\",null,{\"children\":\"photos\"}],[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\"
3:16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-camera \",\"children\":[[\"$\",\"path\",\"1tc9qg\",{\"d\":\"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z\"}],\"$L1d\",\"$undefined\"]}],\"$undefined\"]}],\" while traveling, and making music (I was once in a rock band called \",\"$L1e\",\" with my professors) are other things I love to do.\"]}],\"\\n\"]}]]}],\"$L1f\"]}]]}]\n"])</script>
3<script>self.__next_f.push([1,"20:I[515838,[\"/_next/static/chunks/0~6uqz2cc7cgk.js\",\"/_next/static/chunks/060eq880magqv.js\"],\"default\"]\n21:I[7840,[\"/_next/static/chunks/0~6uqz2cc7cgk.js\",\"/_next/static/chunks/060eq880magqv.js\"],\"default\"]\n22:I[484768,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\"],\"Analytics\"]\n23:I[819335,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\"],\"GoogleAnalytics\"]\n24:I[569568,[\"/_next/static/chunks/078gj~ojf_wnm.js\",\"/_next/static/chunks/0zbvl-0n~576..js\",\"/_next/static/chunks/0n6k61d0zylrv.js\",\"/_next/static/chunks/079g-_hol5.sn.js\",\"/_next/static/chunks/053s04cvac324.js\"],\"WritingList\"]\nf:[\"$\",\"path\",\"1tc9qg\",{\"d\":\"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z\"}]\n10:[\"$\",\"circle\",\"1vg3eu\",{\"cx\":\"12\",\"cy\":\"13\",\"r\":\"3\"}]\n11:[\"$\",\"$Le\",\"/gear\",{\"href\":\"/gear\",\"label\":\"Gear\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-dumbbell \",\"children\":[[\"$\",\"path\",\"f7oqzb\",{\"d\":\"m6.5 6.5 11 11\"}],[\"$\",\"path\",\"cpc6if\",{\"d\":\"m21 21-1-1\"}],[\"$\",\"path\",\"d3rpuf\",{\"d\":\"m3 3 1 1\"}],[\"$\",\"path\",\"1e32o6\",{\"d\":\"m18 22 4-4\"}],[\"$\",\"path\",\"189tqz\",{\"d\":\"m2 6 4-4\"}],[\"$\",\"path\",\"1bxui2\",{\"d\":\"m3 10 7-7\"}],[\"$\",\"path\",\"16x78n\",{\"d\":\"m14 21 7-7\"}],\"$undefined\"]}],\"shortcutNumber\":12,\"wip\":\"$undefined\",\"beta\":\"$undefined\",\"new_\":\"$undefined\"}]\n12:[\"$\",\"$Le\",\"/travel\",{\"href\":\"/travel\",\"label\":\"Travel\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-tent-tree \",\"children\":[[\"$\",\"circle\",\"bt5ra8\",{\"cx\":\"4\",\"cy\":\"4\",\"r\":\"2\"}],[\"$\",\"path\",\"1sorif\",{\"d\":\"m14 5 3-3 3 3\"}],[\"$\",\"path\",\"1jyi9h\",{\"d\":\"m14 10 3-3 3 3\"}],[\"$\",\"path\",\"8ymqnk\",{\"d\":\"M17 14V2\"}],[\"$\",\"path\",\"13ar7p\",{\"d\":\"M17 14H7l-5 8h20Z\"}],[\"$\",\"path\",\"1ghmqk\",{\"d\":\"M8 14v8\"}],[\"$\",\"path\",\"13pgi6\",{\"d\":\"m9 14 5 8\"}],\"$undefined\"]}],\"shortcutNumber\":null,\"wip\":true,\"beta\":\"$undefined\",\"new_\":\"$undefined\"}]\n13:[\"$\",\"$Le\",\"/notes\",{\"href\":\"/notes\",\"label\":\"Reading Notes\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-book-open \",\"children\":[[\"$\",\"path\",\"vv98re\",{\"d\":\"M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z\"}],[\"$\",\"path\",\"1cyq3y\",{\"d\":\"M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z\"}],\"$undefined\"]}],\"shortcutNumber\":null,\"wip\":true,\"beta\":\"$undefined\",\"new_\":\"$undefined\"}]\n14:[\"$\",\"hr\",null,{\"className\":\"my-3\"}]\n"])</script>
3<script>self.__next_f.push([1,"15:[\"$\",\"div\",null,{\"className\":\"flex flex-col gap-2 text-sm\",\"children\":[[\"$\",\"span\",null,{\"className\":\"px-2 text-xs font-medium leading-relaxed text-gray-600\",\"children\":\"Contact me\"}],[\"$\",\"div\",null,{\"className\":\"flex flex-col gap-1\",\"children\":[[\"$\",\"$Le\",\"https://twitter.com/intent/user?screen_name=oznszk\",{\"href\":\"https://twitter.com/intent/user?screen_name=oznszk\",\"label\":\"Twitter\",\"icon\":[\"$\",\"svg\",null,{\"xmlns\":\"http://www.w3.org/2000/svg\",\"className\":\"h-4 w-4\",\"width\":\"44\",\"height\":\"44\",\"viewBox\":\"0 0 24 24\",\"strokeWidth\":\"1.5\",\"stroke\":\"#000000\",\"fill\":\"none\",\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"children\":[[\"$\",\"path\",null,{\"stroke\":\"none\",\"d\":\"M0 0h24v24H0z\",\"fill\":\"none\"}],[\"$\",\"path\",null,{\"d\":\"M4 4l11.733 16h4.267l-11.733 -16z\"}],[\"$\",\"path\",null,{\"d\":\"M4 20l6.768 -6.768m2.46 -2.46l6.772 -6.772\"}]]}]}],[\"$\",\"$Le\",\"https://github.com/ozansz\",{\"href\":\"https://github.com/ozansz\",\"label\":\"GitHub\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-github \",\"children\":[[\"$\",\"path\",\"tonef\",{\"d\":\"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4\"}],[\"$\",\"path\",\"9comsn\",{\"d\":\"M9 18c-4.51 2-5-2-7-2\"}],\"$undefined\"]}]}],[\"$\",\"$Le\",\"https://www.linkedin.com/in/ozan-sazak/\",{\"href\":\"https://www.linkedin.com/in/ozan-sazak/\",\"label\":\"LinkedIn\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-linkedin \",\"children\":[[\"$\",\"path\",\"c2jq9f\",{\"d\":\"M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-2-2 2 2 0 0 0-2 2v7h-4v-7a6 6 0 0 1 6-6z\"}],[\"$\",\"rect\",\"mk3on5\",{\"width\":\"4\",\"height\":\"12\",\"x\":\"2\",\"y\":\"9\"}],[\"$\",\"circle\",\"bt5ra8\",{\"cx\":\"4\",\"cy\":\"4\",\"r\":\"2\"}],\"$undefined\"]}]}],[\"$\",\"$Le\",\"https://www.instagram.com/ozan.sazak\",{\"href\":\"https://www.instagram.com/ozan.sazak\",\"label\":\"Instagram\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-instagram \",\"children\":[[\"$\",\"rect\",\"2e1cvw\",{\"width\":\"20\",\"height\":\"20\",\"x\":\"2\",\"y\":\"2\",\"rx\":\"5\",\"ry\":\"5\"}],[\"$\",\"path\",\"9exkf1\",{\"d\":\"M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z\"}],[\"$\",\"line\",\"r4j83e\",{\"x1\":\"17.5\",\"x2\":\"17.51\",\"y1\":\"6.5\",\"y2\":\"6.5\"}],\"$undefined\"]}]}]]}]]}]\n"])</script>
3<script>self.__next_f.push([1,"16:[\"$\",\"hr\",null,{\"className\":\"my-3\"}]\n"])</script>
3<script>self.__next_f.push([1,"17:[\"$\",\"div\",null,{\"className\":\"flex flex-col gap-2 text-sm\",\"children\":[[\"$\",\"span\",null,{\"className\":\"px-2 text-xs font-medium leading-relaxed text-gray-600\",\"children\":\"Stay tuned\"}],[\"$\",\"div\",null,{\"className\":\"flex flex-col gap-1\",\"children\":[[\"$\",\"$Le\",\"/rss.xml\",{\"href\":\"/rss.xml\",\"label\":\"RSS Feed\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-rss \",\"children\":[[\"$\",\"path\",\"pv89mb\",{\"d\":\"M4 11a9 9 0 0 1 9 9\"}],[\"$\",\"path\",\"k0647b\",{\"d\":\"M4 4a16 16 0 0 1 16 16\"}],[\"$\",\"circle\",\"bfqh0e\",{\"cx\":\"5\",\"cy\":\"19\",\"r\":\"1\"}],\"$undefined\"]}]}],[\"$\",\"$Le\",\"/atom.xml\",{\"href\":\"/atom.xml\",\"label\":\"Atom Feed\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-atom \",\"children\":[[\"$\",\"circle\",\"41hilf\",{\"cx\":\"12\",\"cy\":\"12\",\"r\":\"1\"}],[\"$\",\"path\",\"1l2ple\",{\"d\":\"M20.2 20.2c2.04-2.03.02-7.36-4.5-11.9-4.54-4.52-9.87-6.54-11.9-4.5-2.04 2.03-.02 7.36 4.5 11.9 4.54 4.52 9.87 6.54 11.9 4.5Z\"}],[\"$\",\"path\",\"1wam0m\",{\"d\":\"M15.7 15.7c4.52-4.54 6.54-9.87 4.5-11.9-2.03-2.04-7.36-.02-11.9 4.5-4.52 4.54-6.54 9.87-4.5 11.9 2.03 2.04 7.36.02 11.9-4.5Z\"}],\"$undefined\"]}]}],[\"$\",\"$Le\",\"/feed.json\",{\"href\":\"/feed.json\",\"label\":\"JSON Feed\",\"icon\":[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-rss \",\"children\":[[\"$\",\"path\",\"pv89mb\",{\"d\":\"M4 11a9 9 0 0 1 9 9\"}],[\"$\",\"path\",\"k0647b\",{\"d\":\"M4 4a16 16 0 0 1 16 16\"}],[\"$\",\"circle\",\"bfqh0e\",{\"cx\":\"5\",\"cy\":\"19\",\"r\":\"1\"}],\"$undefined\"]}]}]]}]]}]\n"])</script>
3<script>self.__next_f.push([1,"18:[\"$\",\"div\",null,{\"className\":\"flex flex-1\",\"children\":[\"$\",\"$L20\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L21\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"div\",null,{\"id\":\"scroll-area\",\"className\":\"scrollable-area relative w-full flex flex-col\",\"children\":[[\"$\",\"$L1b\",null,{\"scrollTitle\":\"Not found\"}],[\"$\",\"div\",null,{\"className\":\"content-wrapper\",\"children\":[\"$\",\"div\",null,{\"className\":\"content\",\"children\":[[\"$\",\"div\",null,{\"className\":\"mb-6\",\"children\":[[\"$\",\"$L1c\",null,{\"as\":\"h1\",\"children\":\"Not found\"}],\"$undefined\",[\"$\",\"div\",null,{\"className\":\"flex flex-row justify-between\",\"children\":[[\"$\",\"div\",null,{\"className\":\"flex flex-row justify-start items-center\",\"children\":[\"$undefined\",\"$undefined\",\"$undefined\",\"$undefined\"]}],\"$undefined\"]}]]}],[\"$\",\"p\",null,{\"children\":\"This link might be broken, deleted, or moved. Nevertheless, there’s nothing to see here...\"}]]}]}]]}],[]],\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]}]\n19:[\"$\",\"$L22\",null,{}]\n1a:[\"$\",\"$L23\",null,{\"gaId\":\"G-9HLV2YYER8\"}]\n1d:[\"$\",\"circle\",\"1vg3eu\",{\"cx\":\"12\",\"cy\":\"13\",\"r\":\"3\"}]\n1e:[\"$\",\"a\",\"9\",{\"href\":\"https://youtu.be/EUp5wp3HO-s?si=kKvAD5vTJ8h87LxO\u0026t=164\",\"className\":\"inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-base text-white font-medium transition-all hover:brightness-90\",\"style\":{\"textDecoration\":\"none\",\"background\":\"linear-gradient(to right, #d97706, #c2410c)\"},\"target\":\"_blank\",\"rel\":\"noopener noreferrer\",\"children\":[[\"$\",\"span\",null,{\"children\":\"METUllica\"}],[\"$\",\"svg\",null,{\"ref\":\"$undefined\",\"xmlns\":\"http://www.w3.org/2000/svg\",\"width\":16,\"height\":16,\"viewBox\":\"0 0 24 24\",\"fill\":\"none\",\"stroke\":\"currentColor\",\"strokeWidth\":2,\"strokeLinecap\":\"round\",\"strokeLinejoin\":\"round\",\"className\":\"lucide lucide-music \",\"children\":[[\"$\",\"path\",\"1jmyc2\",{\"d\":\"M9 18V5l12-2v13\"}],[\"$\",\"circle\",\"fqmcym\",{\"cx\":\"6\",\"cy\":\"18\",\"r\":\"3\"}],[\"$\",\"circle\",\"1hluhg\",{\"cx\":\"18\",\"cy\":\"16\",\"r\":\"3\"}],\"$undefined\"]}],\"$undefined\"]}]\n25:T597a,"])</script>
3<script>self.__next_f.push([1,"\n\nYou've probably heard about [eBPF](/articles/an-applied-introduction-to-ebpf-with-go-2024-06-06) before, it's getting more popular everyday with the extended observability and low-level control coverages it gets in Linux kernel.\n\nBut did you know that eBPF can also **look inside** the Go runtime?\n\nKeep reading and I'll show you how we can use eBPF uprobes to trace goroutine lifecycle events and memory allocations as they happen, giving us a real-time view of what Go's scheduler is doing under the hood.\n\nHere's my latest side project, also a winner of the \u003cchip text=\"eBPF Summit '25 Hackathon\" href=\"https://devpost.com/software/xgotop-go-runtime-observer\" icon=\"globe\"\u003e\u003c/chip\u003e: `xgotop`. xgotop is a Go runtime tracing tool to observe goroutine state changes and memory allocations in near realtime.\n\n![xgotop: Realtime Go Runtime Visualizer](/assets/articles/xgotop/ui.gif)\n\nThis will be a two part series. In this article, we'll go through my thought process during the design and development of xgotop, also I'll explain some aspects of Go runtime internals, as well as using bpftrace to write PoCs for [eBPF programs](/articles/an-applied-introduction-to-ebpf-with-go-2024-06-06). The second one will c
3over turning the bpftrace PoC into a standalone project utilizing eBPF ringbuffers, hashmaps, LRU caches, and configurable sampling using C, Go and `cilium/ebpf-go`.\n\n\u003e!char![husky-1-1] If you just want to trace Go programs, the built-in [execution tracer](https://pkg.go.dev/runtime/trace) (`runtime/trace`) is the right tool for the job. It's lower overhead and gives you a complete picture of goroutine scheduling, blocking, and more. The eBPF approach we'll explore here is more expensive and is meant as an exploration of what's possible when combining eBPF with Go runtime internals.\n\n\u003e!char![sazak-explain] All Go source code snippets you'll see here are a part of Go 1.26\n\n## The Life of a Goroutine\n\nAs we all human beings do (and AI agents, if you are one), goroutines too start living, gather belongings, and eventually die after giving all those belongings back to where they got them from. During their lifetime they get to switch between different states for thousands of times. These changes happen when a goroutine is scheduled, parks in the runtime, enters or exits a syscall, gets preempted, or exits. Memory allocation is a separate runtime event that can happen while the goroutine is running user code.\n\n![Lifecycle of a Go goroutine](/assets/articles/xgotop/go-lifecycle.png)\n\nUnlike us, goroutines live much shorter and so observing their lives is a bit hard by just logging stuff to the terminal. You can easily miss ordering of events within a millisecond for example. To peek in with more detail, we need more than logs. What if there was an interface to tell us whenever a goroutine switch between states, and do memort operations?\n\nFortunately we have that. Goroutines, as being a part of the Go runtime, call specific functions inside the runtime library to **start** doing those operations. That happens in userspace. And we also have eBPF, which lets us call arbitrary code before a specific function **start**s and **end**s executing.\n\nBy putting specific Go runtime functions and eBPF userspace probes together, we can perform some simple tracing of goroutines.\n\n### Inspecting Go Runtime\n\nLet's start by understanding the goroutine lifecycle better. Goroutine is an abstraction over Go functions. It's run as a lightweight thread in Go runtime and is initiated with a specific function and a parent goroutine. All goroutines have a parent which is another goroutine, except the initial goroutine, which is attached to the `main` function when you run a Go binary.\n\nEach goroutine can have more than one children, so it can be said that the relationship between parent and children look like a Linux process tree.\n\nGoroutines are defined by the struct named `g` in Go runtime:\n\n```go filename=\"src/runtime/runtime2.go\"\ntype g struct {\n\tgoid       uint64\n\tparentGoid uint64          // goid of goroutine that created this goroutine\n\tstartpc    uintptr         // pc of goroutine function\n    atomicstatus atomic.Uint32 // atomic status code\n    ...\n}\n```\n\nAs you can see, `g` stores its own and its parent's id, current state, the function it was started for, as well as some other runtime related information which are out of the scope of this article.\n\nBelow are the possible states a goroutine can be in, which are stored in `g.atomicstatus` (skipping unused and scan ones, find the whole list [here](https://github.com/golang/go/blob/917949cc1d16c652cb09ba369718f45e5d814d8f/src/runtime/runtime2.go#L18)):\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eState\u003c/th\u003e\n      \u003cth\u003eExecutes\u003cbr /\u003eUser Code\u003c/th\u003e\n      \u003cth\u003eOn Run\u003cbr /\u003eQueue\u003c/th\u003e\n      \u003cth\u003eNotes\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gidle\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNewly allocated, not initialized\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Grunnable\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eYes\u003c/td\u003e\n      \u003ctd\u003eReady to run\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Grunning\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eYes\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eActively executing\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gsyscall\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eExecuting a syscall, assigned an M, must not touch g.m.p\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gwaiting\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eBlocked in the runtime, usually recorded somewhere so it can be readied\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gdead\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eExited, on free list, or being initialized\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gcopystack\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eStack 
3is being moved\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gpreempted\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eSuspended for suspendG preemption, not yet owned by a readying party\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gleaked\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eLeaked goroutine caught by GC\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gdeadextra\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gdead\u003c/code\u003e goroutine attached to an extra M for cgo callbacks\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nThese variables give us enough opportunity to continuously trace one's lifecycle. But before starting to do that, we need to know which functions are responsble of creating goroutines and changing their states. In practice, we can trace goroutine lifecycle changes by hooking runtime state-transition points.\n\nInstead of finding and hooking every state changing function in the Go runtime, we can do **a little hack**: `runtime.casgstatus` is one of the key low-level helpers because many scheduler transitions go through it. By hooking into `casgstatus`, we can observe a large portion of the important goroutine state changes, even though some hot paths use direct atomic CAS[^2] operations or specialized helpers instead.\n\n```go filename=\"src/runtime/proc.go\"\nfunc casgstatus(gp *g, oldval, newval uint32)\n```\n\n\u003ccollapsible-item title=\"Which functions actually change goroutine states?\" kind=\"mini-note\" readingtime=\"2\" parsetextfrom=\"mini-notes/goroutine-state-change.md\" collapsed=\"true\"\u003e\u003c/collapsible-item\u003e\n\nFor memory operations, we have these runtime functions used by goroutines:\n\n- `runtime.makemap_small`: Initializes a new runtime map object for `make(map[k]v)` and `make(map[k]v, hint)` expressions where `hint \u003c= abi.MapGroupSlots`.\n- `runtime.makemap`: Initializes a new runtime map object for `make(map[k]v, hint)`.\n\n\u003e!char![sazak-explain] Before Go 1.24, map making runtime functions also allocate memory for [the hash buckets](/articles/visual-guide-to-go-maps-hash-tables-2025-10-26), the internal data structure for Go maps. However Go 1.24 and further versions have a Swiss-table based map implementation so the internal allocation is different.\n\n- `runtime.makeslice`: Creates a new runtime slice data structure and allocates memory for [the underlying array](/articles/visual-guide-to-slices-in-go-2024-03-25).\n- `runtime.newobject`: Creates a new arbitrary Go object with the given type.\n\nYou might've noticed that I didn't include the function(s) for memory deallocation. Tracking if a specific object (custom type, etc.) is dellocated is not a trivial operation. We might take a look at how that happens and how it could be observed in a following article later.\n\nWith the common scheduling states in mind, we can draw a simplified goroutine state machine focused on `_Grunnable`, `_Grunning`, `_Gwaiting`, `_Gsyscall`, `_Gpreempted`, and `_Gdead`. I'm leaving `_Gidle` out of the main diagram because then the goroutine is just allocated and not yet initialized, and I'm omitting specialized states like `_Gcopystack`, `_Gleaked`, and `_Gdeadextra`.\n\n![](/assets/articles/xgotop/go_goroutine_state_machine.svg)\n\nAnd now we're ready to write some eBPF hooks to take a closer look at those functions' arguments in realtime!\n\n## Using bpftrace to Validate Our Idea\n\nWhenever I have a new eBPF related idea, I actually prefer writing a simple PoC in `bpftrace` before jumping into a full eBPF program design and implementation. That helps me to see if that idea is viable or not faster.\n\nFor those who are not familiar with, `bpftrace` is a program/parser/transpiler which can translate a special script format to a whole eBPF program with multiple hooks. It has some cool simplifications, for example you can define `C`-style `struct`s and use them to decode complex in-kernel and in-runtime data structures using pointer dereference, and bpftrace automatically does safe memory handling:\n\n```C\nstruct g {\n    uint64_t goid; // offset=152 size=8\n};\n\nuprobe:./testserver:runtime.newobject\n{\n    $goroutine = reg(\"r28\");\n    $g = (struct g *)($goroutine);\n    $goroutine_id = $g-\u003egoid;\n    ...\n}
3\n```\n\nThat `((struct g *)reg(\"r28\"))-\u003egoid` would require 2 extra variables and BPF CO-RE memory copy calls in eBPF C code for example.\n\nAnother cool feature is that we can directly get current register values via the `reg()` function. And as Go uses registers for function arguments in its call convention[^3], we can directly access them using `reg` and custom type definitions. Such as the example above, which uses `reg(\"r28\")` to get the current goroutine object in arm64 architecture, and use a custom defined `struct g` type to access the `goid` field of it.\n\n\u003cnewslettercard\u003e\u003c/newslettercard\u003e\n\n### A Little More of Go Runtime Magic\n\nLet's see which Go runtime function arguments we can peek into. As a refresher, these are the functions we'll hook:\n\n```go filename=\"src/runtime/...\"\nfunc casgstatus(gp *g, oldval, newval uint32)\nfunc newobject(typ *_type) unsafe.Pointer\nfunc makeslice(et *_type, len, cap int) unsafe.Pointer\nfunc makemap(t *abi.MapType, hint int, m *maps.Map) *maps.Map\n```\n\nWe've took a look into `runtime.g` struct before, the new runtime types here are: `abi.MapType`, and `runtime._type` which is actually defined to be a reference to `abi.Type`:\n\n```go filename=\"src/runtime/type.go\"\ntype _type = abi.Type\n```\n\n#### `abi.Type`\n\nThe runtime representation of a Go type in Go's ABI. Defines the type's total size, kind, alignment, string form, etc.\n\n```go filename=\"src/internal/abi/type.go\"\ntype Type struct {\n\tSize_       uintptr\n\tPtrBytes    uintptr // number of (prefix) bytes in the type that can contain pointers\n\tHash        uint32  // hash of type; avoids computation in hash tables\n\tTFlag       TFlag   // extra type information flags\n\tAlign_      uint8   // alignment of variable with this type\n\tFieldAlign_ uint8   // alignment of struct field with this type\n\tKind_       Kind    // what kind of type this is (string, int, ...)\n\t// function for comparing objects of this type\n\t// (ptr to object A, ptr to object B) -\u003e ==?\n\tEqual func(unsafe.Pointer, unsafe.Pointer) bool\n\tGCData    *byte\n\tStr       NameOff // string form\n\tPtrToThis TypeOff // type for pointer to this type, may be zero\n}\n```\n\nThe `Kind_` field here defines what kind of type this one is, which is defined in Go source code as:\n\n```go filename=\"src/internal/abi/type.go\"\n// A Kind represents the specific kind of type that a Type represents.\n// The zero Kind is not a valid kind.\ntype Kind uint8\n\nconst (\n\tInvalid Kind = iota\n\tBool\n\tInt\n\tInt8\n\tInt16\n\tInt32\n\tInt64\n\tUint\n\tUint8\n\tUint16\n\tUint32\n\tUint64\n\tUintptr\n\tFloat32\n\tFloat64\n\tComplex64\n\tComplex128\n\tArray\n\tChan\n\tFunc\n\tInterface\n\tMap\n\tPointer\n\tSlice\n\tString\n\tStruct\n\tUnsafePointer\n)\n```\n\n#### `abi.MapType`\n\nThe actual metadata definition of a Go map, including the native/custom types of keys, values, the hash function `func(unsafe.Pointer, uintptr) uintptr`, etc.\n\n```go filename=\"src/internal/abi/map.go\"\ntype MapType struct {\n    Type\n    Key        *Type\n    Elem       *Type\n    Group      *Type\n    Hasher     func(unsafe.Pointer, uintptr) uintptr\n    GroupSize  uintptr\n    KeysOff    uintptr\n    KeyStride  uintptr\n    ElemsOff   uintptr\n    ElemStride uintptr\n    ElemOff    uintptr\n    Flags      uint32\n}\n```\n\nThe `*Type` here is a pointer to `abi.Type`, which is explained above.\n\nReturning back to the functions we'll hook, here are what we can learn about the goroutines by decoding the function arguments in bpftrace/eBPF:\n\n- `casgstatus` -\u003e Goroutine ID, parent goroutine ID, old state, new state\n- `newobject` -\u003e Memory size and the kind of the new object \n- `makeslice` -\u003e Length and capacity of the new slice, and the total memory size and the kind of it\n- `makemap` -\u003e Hint (initial capacity), key/value types (their total sizes and kinds) of the new map, and the total memory size and the kind of it\n\n### xgotop.bt bpftrace Script\n\nSo let's try writing a simple bpftrace program/script to hook into these Go runtime functions. We first need a Go program to test our bpftrace code on. We will use an extremely simple HTTP server:\n\n```go filename=\"cmd/testserver/main.go\"\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/gorilla/mux\"\n)\n\nfunc main() {\n\tr := mux.NewRouter()\n\tr.HandleFunc(\"/books/{t
3itle}/page/{page}\", GetBook)\n\thttp.ListenAndServe(\":80\", r)\n}\n\nfunc GetBook(w http.ResponseWriter, r *http.Request) {\n    vars := mux.Vars(r)\n    title := vars[\"title\"]\n    page := vars[\"page\"]\n    fmt.Fprintf(w, \"You've requested the book: %s on page %s\\n\", title, page)\n}\n```\n\nWhen you build and run this `testserver` program and send an HTTP request via `curl` or `httpie` or your favorite HTTP client, you'll see that it's working:\n\n```bash\n$ go build -o testserver ./cmd/testserver\n\n$ ./testserver \u0026\n\n$ curl localhost/books/test123/page/45\nYou've requested the book: test123 on page 45\n```\n\nBut that's not the point, obviously. Now we can write the actual code, which is the bpftrace code. We'll hook into the functions `casgstatus`, `newobject`, `makeslice`, and `makemap`, then use the registers to decode actual function call arguments to observe goroutine lifecycle events in specific points in time.\n\nBelow is the full bpftrace proof-of-concept implementation for our goroutine tracer:\n\n```C filename=\"xgotop.bt\"\nstruct g {\n    uint8_t _pad1[152];\n    uint64_t goid; // offset=152 size=8\n    uint8_t _pad2[112];\n    uint64_t parentGoid; // offset=272 size=8\n    uint8_t _pad3[16];\n    uint64_t startpc; // offset=296 size=8\n};\n\nstruct _type {\n    uint64_t size; // offset=0 size=8\n    uint8_t _pad1[15];\n    uint8_t kind; // offset=23 size=1\n}\n\nstruct mapType {\n    uint8_t _pad1[48];\n    struct _type *key; // offset=48 size=8\n    struct _type *elem; // offset=56 size=8\n};\n\n// func casgstatus(gp *g, oldval, newval uint32)\nuprobe:./testserver:runtime.casgstatus\n{\n    $gp = (struct g *)reg(\"r0\");\n    $goid = $gp-\u003egoid;\n    $parentGoid = $gp-\u003eparentGoid;\n    $startpc = $gp-\u003estartpc;\n\n    $goroutine =  (struct g *)reg(\"r28\");\n    $goroutine_id = $goroutine-\u003egoid;\n\n    $status = reg(\"r2\");\n\n    printf(\"[%llu] pid=%d goid=%llu parentGoid=%llu startpc=%llx status=%llu [goroutine_id=%lld]\\n\", nsecs, pid, $goid, $parentGoid, $startpc, $status, $goroutine_id);\n}\n\n// func newobject(typ *_type) unsafe.Pointer\nuprobe:./testserver:runtime.newobject\n{\n    $g = (struct g *)reg(\"r28\");\n    $goroutine_id = $g-\u003egoid;\n\n    $typ = (struct _type *)(reg(\"r0\"));\n    $size = $typ-\u003esize;\n    $kind = $typ-\u003ekind;\n\n    printf(\"[%llu] g:%lld:runtime.newobject(size=%llu, kind=%llu)\\n\", nsecs, $goroutine_id, $size, $kind);\n}\n\n// func makeslice(et *_type, len, cap int) unsafe.Pointer \nuprobe:./testserver:runtime.makeslice\n{\n    $g = (struct g *)reg(\"r28\");\n    $goroutine_id = $g-\u003egoid;\n\n    $typ = (struct _type *)(reg(\"r0\"));\n    $size = $typ-\u003esize;\n    $kind = $typ-\u003ekind;\n\n    $len = reg(\"r1\");\n    $cap = reg(\"r2\");\n\n    printf(\"[%llu] g:%lld:runtime.makeslice(size=%llu, kind=%llu, len=%llu, cap=%llu)\\n\", nsecs, $goroutine_id, $size, $kind, $len, $cap);\n}\n\n// func makemap(t *abi.MapType, hint int, m *maps.Map) *maps.Map\nuprobe:./testserver:runtime.makemap\n{\n    $g = (struct g *)reg(\"r28\");\n    $goroutine_id = $g-\u003egoid;\n\n    $maptyp = (struct mapType *)(reg(\"r0\"));\n\n    $keysize = $maptyp-\u003ekey-\u003esize;\n    $keykind = $maptyp-\u003ekey-\u003ekind;\n    $valsize = $maptyp-\u003eelem-\u003esize;\n    $valkind = $maptyp-\u003eelem-\u003ekind;\n\n    $hint = reg(\"r1\");\n\n    printf(\"[%llu] g:%lld:runtime.makemap(keysize=%llu, keykind=%llu, valsize=%llu, valkind=%llu, hint=%llu)\\n\", nsecs, $goroutine_id, $keysize, $keykind, $valsize, $valkind, $hint);\n}\n```\n\nHere's how every hook is written:\n\n- I've defined `struct`s `g`, `_type`, `mapType` to be able to use internal Go types `runtime.g`, `abi.Type` and `abi.MapType`. Notice how I've used arbitrary `uint8_t` arrays in those structs as field paddings. The reason behind doing this is that we don't need most of those internal objects' fields - for example in `runtime.g` we only need ID and parent ID. We can easily skip past the remaining ones using single-byte (`uint8_t`) arrays with a desired length.\n- Used `uprobe` (userspace probe) to hook the runtime functions. These functions are a bit costly in the means of latency, however better for faster prototyping. Every hook in bpftrace can simply be written in 3 parts:\n\n```\n\u003ckind\u003e:\u003cprogram\u003e:\u003cfunction\u003e\n\nuprobe:./testserver:runtime.makemap\n```\n\n- Used `r28` to get the current goroutine's `g` struct[^4]\n- Casted the related registers (`r28`, `r0`, ...) into the related in-script structs to inspect the function call arguments in better detail\n\n\u003cnewslettercard\u003e\u003c/newslettercard\u003e\n\n
3If you run `xgotop.bt` with bpftrace while the `testserver` is running in the background and send some random HTTP requests to it, you'll see some interesting logs coming from bpftrace:\n\n```bash\n$ sudo bpftrace ./xgotop.bt\nAttaching 4 probes...\n[10348086967086] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=1 [goroutine_id=0]\n[10348087023933] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=2 [goroutine_id=0]\n[10348087033386] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=3 [goroutine_id=1]\n[10348087051502] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=2 [goroutine_id=1]\n[10348087054417] g:1:runtime.newobject(size=56, kind=25)\n[10348087059165] g:1:runtime.newobject(size=128, kind=25)\n[10348087066328] g:1:runtime.newobject(size=56, kind=25)\n[10348087069160] g:1:runtime.newobject(size=48, kind=25)\n[10348087071076] g:1:runtime.newobject(size=48, kind=25)\n[10348087076573] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=3 [goroutine_id=1]\n[10348087079363] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=2 [goroutine_id=1]\n[10348087081279] g:1:runtime.newobject(size=8, kind=57)\n[10348087083403] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=3 [goroutine_id=1]\n[10348087085818] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=2 [goroutine_id=1]\n[10348087087234] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=3 [goroutine_id=1]\n[10348087097812] g:1:runtime.newobject(size=144, kind=25)\n[10348087099978] g:1:runtime.newobject(size=48, kind=25)\n[10348087103726] g:1:runtime.newobject(size=32, kind=25)\n[10348087106266] g:0:runtime.newobject(size=440, kind=25)\n[10348087108599] pid=19641 goid=0 parentGoid=0 startpc=0 status=6 [goroutine_id=0]\n[10348088014562] pid=19641 goid=21 parentGoid=1 startpc=1e3710 status=1 [goroutine_id=0]\n[10348088057207] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=3 [goroutine_id=1]\n[10348088069535] pid=19641 goid=1 parentGoid=0 startpc=51cf0 status=2 [goroutine_id=1]\n[10348090552043] pid=19641 goid=21 parentGoid=1 startpc=1e3710 status=2 [goroutine_id=0]\n[10348090586900] g:21:runtime.newobject(size=48, kind=25)\n[10348090607307] g:21:runtime.newobject(size=80, kind=25)\n[10348090610139] g:21:runtime.newobject(size=16, kind=25)\n[10348090611555] g:21:runtime.newobject(size=64, kind=25)\n[10348090615678] g:21:runtime.makeslice(size=128, kind=25, len=4, cap=4)\n[10348090618218] g:21:runtime.newobject(size=88, kind=25)\n[10348090620009] g:21:runtime.makeslice(size=1, kind=8, len=4096, cap=4096)\n[10348090627630] g:21:runtime.makeslice(size=128, kind=25, len=4, cap=4)\n[10348090628921] g:21:runtime.makeslice(size=1, kind=8, len=4096, cap=4096)\n```\n\nYou can see that after an HTTP request is sent:\n\n1. A new goroutine with ID `21` is spawned to handle it (`startpc` of `0x1e3710` is probably the `GetBook` function of `testserver`)\n2. There are two slices allocated with type `Uint8` and length `4096` (`g:21:runtime.makeslice(size=1, kind=8, len=4096, cap=4096)`), which are probably the request and response body buffers\n3. There are arbitrary structs allocated for various reasons (`g:21:runtime.newobject(size=..., kind=25)`)\n\nAs you can see, we can now trace arbitrary goroutines running in a specific Go executable!\n\nWe can stop right here, feel free to play around with `xgotop.bt` by changing hooks, adding new ones, inspecting another Go program, etc.\n\nIn the next part, we will turn this PoC into a standalone project utilizing eBPF ringbuffers, hashmaps, and event sampling using C, Go and `
3cilium/ebpf-go`. Until then, stay tuned.\n\n## References\n\n- \u003cchip text=\"ozansz/xgotop\" href=\"https://github.com/ozansz/xgotop\" icon=\"github\"\u003e\u003c/chip\u003e\n- [Go runtime: `runtime/proc.go`](https://github.com/golang/go/blob/master/src/runtime/proc.go)\n- [Go runtime: `runtime/map.go` (map internals)](https://github.com/golang/go/blob/master/src/runtime/map.go)\n- \u003cchip text=\"bpftrace\" href=\"https://github.com/bpftrace/bpftrace\" icon=\"github\"\u003e\u003c/chip\u003e\n- \u003cchip text=\"cilium/ebpf-go\" href=\"https://github.com/cilium/ebpf\" icon=\"github\"\u003e\u003c/chip\u003e\n\n[^2]: [Compare-and-swap](https://en.wikipedia.org/wiki/Compare-and-swap)\n\n[^3]: Go uses different registers for different architectures: https://go.dev/src/cmd/compile/abi-internal#amd64-architecture https://go.dev/src/cmd/compile/abi-internal#arm64-architecture\n\n[^4]: In `arm64` Go ABI, r28 is the register that stores the current goroutine object's memory location"])</script>
3<script>self.__next_f.push([1,"26:T1f542,"])</script>
3<script>self.__next_f.push([1,"\u003cp\u003eYou\u0026#39;ve probably heard about \u003ca href=\"/articles/an-applied-introduction-to-ebpf-with-go-2024-06-06\" target=\"_blank\"\u003eeBPF\u003c/a\u003e before, it\u0026#39;s getting more popular everyday with the extended observability and low-level control coverages it gets in Linux kernel.\u003c/p\u003e\n\u003cp\u003eBut did you know that eBPF can also \u003cstrong\u003elook inside\u003c/strong\u003e the Go runtime?\u003c/p\u003e\n\u003cp\u003eKeep reading and I\u0026#39;ll show you how we can use eBPF uprobes to trace goroutine lifecycle events and memory allocations as they happen, giving us a real-time view of what Go\u0026#39;s scheduler is doing under the hood.\u003c/p\u003e\n\u003cp\u003eHere\u0026#39;s my latest side project, also a winner of the \u003cchip text=\"eBPF Summit \u0026#39;25 Hackathon\" href=\"https://devpost.com/software/xgotop-go-runtime-observer\" icon=\"globe\"\u003e\u003c/chip\u003e: \u003ccode\u003exgotop\u003c/code\u003e. xgotop is a Go runtime tracing tool to observe goroutine state changes and memory allocations in near realtime.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/xgotop/ui.gif\" alt=\"xgotop: Realtime Go Runtime Visualizer\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eThis will be a two part series. In this article, we\u0026#39;ll go through my thought process during the design and development of xgotop, also I\u0026#39;ll explain some aspects of Go runtime internals, as well as using bpftrace to write PoCs for \u003ca href=\"/articles/an-applied-introduction-to-ebpf-with-go-2024-06-06\" target=\"_blank\"\u003eeBPF programs\u003c/a\u003e. The second one will c
3over turning the bpftrace PoC into a standalone project utilizing eBPF ringbuffers, hashmaps, LRU caches, and configurable sampling using C, Go and \u003ccode\u003ecilium/ebpf-go\u003c/code\u003e.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"husky-1-1\" class=\"quote-character\"\u003e\u003cp\u003e If you just want to trace Go programs, the built-in \u003ca href=\"https://pkg.go.dev/runtime/trace\" target=\"_blank\"\u003eexecution tracer\u003c/a\u003e (\u003ccode\u003eruntime/trace\u003c/code\u003e) is the right tool for the job. It\u0026#39;s lower overhead and gives you a complete picture of goroutine scheduling, blocking, and more. The eBPF approach we\u0026#39;ll explore here is more expensive and is meant as an exploration of what\u0026#39;s possible when combining eBPF with Go runtime internals.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e All Go source code snippets you\u0026#39;ll see here are a part of Go 1.26\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch2 id=\"the-life-of-a-goroutine\"\u003eThe Life of a Goroutine\u003c/h2\u003e\n\u003cp\u003eAs we all human beings do (and AI agents, if you are one), goroutines too start living, gather belongings, and eventually die after giving all those belongings back to where they got them from. During their lifetime they get to switch between different states for thousands of times. These changes happen when a goroutine is scheduled, parks in the runtime, enters or exits a syscall, gets preempted, or exits. Memory allocation is a separate runtime event that can happen while the goroutine is running user code.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/xgotop/go-lifecycle.png\" alt=\"Lifecycle of a Go goroutine\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eUnlike us, goroutines live much shorter and so observing their lives is a bit hard by just logging stuff to the terminal. You can easily miss ordering of events within a millisecond for example. To peek in with more detail, we need more than logs. What if there was an interface to tell us whenever a goroutine switch between states, and do memort operations?\u003c/p\u003e\n\u003cp\u003eFortunately we have that. Goroutines, as being a part of the Go runtime, call specific functions inside the runtime library to \u003cstrong\u003estart\u003c/strong\u003e doing those operations. That happens in userspace. And we also have eBPF, which lets us call arbitrary code before a specific function \u003cstrong\u003estart\u003c/strong\u003es and \u003cstrong\u003eend\u003c/strong\u003es executing.\u003c/p\u003e\n\u003cp\u003eBy putting specific Go runtime functions and eBPF userspace probes together, we can perform some simple tracing of goroutines.\u003c/p\u003e\n\u003ch3 id=\"inspecting-go-runtime\"\u003eInspecting Go Runtime\u003c/h3\u003e\n\u003cp\u003eLet\u0026#39;s start by understanding the goroutine lifecycle better. Goroutine is an abstraction over Go functions. It\u0026#39;s run as a lightweight thread in Go runtime and is initiated with a specific function and a parent goroutine. All goroutines have a parent which is another goroutine, except the initial goroutine, which is attached to the \u003ccode\u003emain\u003c/code\u003e function when you run a Go binary.\u003c/p\u003e\n\u003cp\u003eEach goroutine can have more than one children, so it can be said that the relationship between parent and children look like a Linux process tree.\u003c/p\u003e\n\u003cp\u003eGoroutines are defined by the struct named \u003ccode\u003eg\u003c/code\u003e in Go runtime:\u003c/p\u003e\n\u003cpre data-filename=\"src/runtime/runtime2.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint64\u003c/span\u003e\u003cspan style=\"\"\u003e          \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// goid of goroutine that created this goroutine\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003estartpc\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e         \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// pc of goroutine function\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eatomicstatus\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eatomic\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eUint32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// atomic status code\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eAs you can see, \u
3003ccode\u003eg\u003c/code\u003e stores its own and its parent\u0026#39;s id, current state, the function it was started for, as well as some other runtime related information which are out of the scope of this article.\u003c/p\u003e\n\u003cp\u003eBelow are the possible states a goroutine can be in, which are stored in \u003ccode\u003eg.atomicstatus\u003c/code\u003e (skipping unused and scan ones, find the whole list \u003ca href=\"https://github.com/golang/go/blob/917949cc1d16c652cb09ba369718f45e5d814d8f/src/runtime/runtime2.go#L18\" target=\"_blank\"\u003ehere\u003c/a\u003e):\u003c/p\u003e\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eState\u003c/th\u003e\n      \u003cth\u003eExecutes\u003cbr/\u003eUser Code\u003c/th\u003e\n      \u003cth\u003eOn Run\u003cbr/\u003eQueue\u003c/th\u003e\n      \u003cth\u003eNotes\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gidle\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNewly allocated, not initialized\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Grunnable\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eYes\u003c/td\u003e\n      \u003ctd\u003eReady to run\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Grunning\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eYes\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eActively executing\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gsyscall\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eExecuting a syscall, assigned an M, must not touch g.m.p\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gwaiting\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eBlocked in the runtime, usually recorded somewhere so it can be readied\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gdead\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eExited, on free list, or being initialized\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gcopystack\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eStack is being moved\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gpreempted\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eSuspended for suspendG preemption, not yet owned by a readying party\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gleaked\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eLeaked goroutine caught by GC\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gdeadextra\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003eNo\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003e_Gdead\u003c/code\u003e goroutine attached to an extra M for cgo callbacks\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\u003cp\u003eThese variables give us enough opportunity to continuously trace one\u0026#39;s lifecycle. But before starting to do that, we need to know which functions are responsble of creating goroutines and changing their states. In practice, we can trace goroutine lifecycle changes by hooking runtime state-transition points.\u003c/p\u003e\n\u003cp\u003eInstead of finding and hooking every state changing function in the Go runtime, we can do \u003cstrong\u003ea little hack\u003c/strong\u003e: \u003ccode\u003eruntime.casgstatus\u003c/code\u003e is one of the key low-level helpers because many scheduler transitions go through it. By hooking into \u003ccode\u003ecasgstatus\u003c/code\u003e, we can observe a large portion of the important goroutine state changes, even though some hot paths use direct atomic CAS\u003csup id=\"fnref:1\"\u003e\u003ca href=\"#fn:1\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e1\u003c/a\u003e\u003c/sup\u003e operations or specialized helpers instead.\u003c/p\u003e\n\u003cpre data-filename=\"src/runtime/proc.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ecasgstatus\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003egp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eoldval\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enewval\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint32\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003e\u003ccollapsible-item title=\"Which functions actually change goroutine states?\" kind=\"mini-note\" readingtime=\"2\" parsetextfrom=\"mini-notes/goroutine-state-change.md\" collapsed=\"true\" parsedcontent=\"\u0026lt;p\u0026gt;The \u0026lt;code\u0026gt;casgstatus\u0026lt;/code\u0026gt; function is the main generic helper for many goroutine status transitions in Go runtime. However some hot paths use direct atomic CAS operations or specialized helpers instead, such as the syscall entry/exit functions.\u0026lt;/p\u0026gt;\n\u0026lt;p\u0026gt;The higher-level lifecycle functions are still worth listing because they explain why a state changes, not just how the atomic status field gets updated.\u
30026lt;/p\u0026gt;\n\u0026lt;blockquote\u0026gt;\n\u0026lt;p\u0026gt;Note: Functions listed here and their behaviors are specific to Go 1.26, the specific behaviors might be subject to change in later versions\u0026lt;/p\u0026gt;\n\u0026lt;/blockquote\u0026gt;\n\u0026lt;ul\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.newproc\u0026lt;/code\u0026gt;, \u0026lt;code\u0026gt;runtime.newproc1\u0026lt;/code\u0026gt;: Creates and initializes a new \u0026lt;code\u0026gt;g\u0026lt;/code\u0026gt;. On the normal \u0026lt;code\u0026gt;go\u0026lt;/code\u0026gt; statement path the new goroutine is created as \u0026lt;code\u0026gt;_Grunnable\u0026lt;/code\u0026gt;, and \u0026lt;code\u0026gt;runtime.newproc\u0026lt;/code\u0026gt; is the caller that enqueues it.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.execute\u0026lt;/code\u0026gt;: Scheduler transition from \u0026lt;code\u0026gt;_Grunnable\u0026lt;/code\u0026gt; to \u0026lt;code\u0026gt;_Grunning\u0026lt;/code\u0026gt;.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.gopark\u0026lt;/code\u0026gt;, \u0026lt;code\u0026gt;runtime.park_m\u0026lt;/code\u0026gt;: Transition from \u0026lt;code\u0026gt;_Grunning\u0026lt;/code\u0026gt; to \u0026lt;code\u0026gt;_Gwaiting\u0026lt;/code\u0026gt;.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.goready\u0026lt;/code\u0026gt;, \u0026lt;code\u0026gt;rutime.ready\u0026lt;/code\u0026gt;: Transition from \u0026lt;code\u0026gt;_Gwaiting\u0026lt;/code\u0026gt; to \u0026lt;code\u0026gt;_Grunnable\u0026lt;/code\u0026gt;.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.entersyscall\u0026lt;/code\u0026gt;, \u0026lt;code\u0026gt;runtime.entersyscallblock\u0026lt;/code\u0026gt;: Transition from \u0026lt;code\u0026gt;_Grunning\u0026lt;/code\u0026gt; to \u0026lt;code\u0026gt;_Gsyscall\u0026lt;/code\u0026gt;.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.exitsyscall\u0026lt;/code\u0026gt;: Fast path from \u0026lt;code\u0026gt;_Gsyscall\u0026lt;/code\u0026gt; back to \u0026lt;code\u0026gt;_Grunning\u0026lt;/code\u0026gt;. If it cannot keep or reacquire a \u0026lt;code\u0026gt;p\u0026lt;/code\u0026gt;, the slow path later moves the goroutine to \u0026lt;code\u0026gt;_Grunnable\u0026lt;/code\u0026gt; via \u0026lt;code\u0026gt;exitsyscallNoP\u0026lt;/code\u0026gt;.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.gosched\u0026lt;/code\u0026gt;, \u0026lt;code\u0026gt;runtime.goyield\u0026lt;/code\u0026gt;: Transition from \u0026lt;code\u0026gt;_Grunning\u0026lt;/code\u0026gt; to \u0026lt;code\u0026gt;_Grunnable\u0026lt;/code\u0026gt;.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.preemptPark\u0026lt;/code\u0026gt; + \u0026lt;code\u0026gt;runtime.casGFromPreempted\u0026lt;/code\u0026gt;: Transition from \u0026lt;code\u0026gt;_Grunning\u0026lt;/code\u0026gt; to \u0026lt;code\u0026gt;_Gpreempted\u0026lt;/code\u0026gt;, then to \u0026lt;code\u0026gt;_Gwaiting\u0026lt;/code\u0026gt;.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;code\u0026gt;runtime.goexit1\u0026lt;/code\u0026gt; -\u0026amp;gt; \u0026lt;code\u0026gt;runtime.goexit0\u0026lt;/code\u0026gt;, \u0026lt;code\u0026gt;runtime.gdestroy\u0026lt;/code\u0026gt;: Teardown of the current goroutine, ending in \u0026lt;code\u0026gt;_Gdead\u0026lt;/code\u0026gt;.\u0026lt;/li\u0026gt;\n\u0026lt;/ul\u0026gt;\n\" readingtime=\"60\"\u003e\u003c/collapsible-item\u003e\u003c/p\u003e\n\u003cp\u003eFor memory operations, we have these runtime functions used by goroutines:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003eruntime.makemap_small\u003c/code\u003e: Initializes a new runtime map object for \u003ccode\u003emake(map[k]v)\u003c/code\u003e and \u003ccode\u003emake(map[k]v, hint)\u003c/code\u003e expressions where \u003ccode\u003ehint \u0026lt;= abi.MapGroupSlots\u003c/code\u003e.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eruntime.makemap\u003c/code\u003e: Initializes a new runtime map object for \u003ccode\u003emake(map[k]v, hint)\u003c/code\u003e.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e Before Go 1.24, map making runtime functions also allocate memory for \u003ca href=\"/articles/visual-guide-to-go-maps-hash-tables-2025-10-26\" target=\"_blank\"\u003ethe hash buckets\u003c/a\u003e, the internal data structure for Go maps. However Go 1.24 and further versions have a Swiss-table based map implementation so the internal allocation is different.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003eruntime.makeslice\u003c/code\u003e: Creates a new runtime slice data structure and allocates memory for \u003ca href=\"/articles/visual-guide-to-slices-in-go-2024-03-25\" target=\"_blank\"\u003ethe underlying array\u003c/a\u003e.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eruntime.newobject\u003c/code\u003e: Creates a new arbitrary Go object with the given type.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eYou might\u0026#39;ve noticed that I didn\u0026#39;t include the function(s) for memory deallocation. Tracking if a specific object (custom type, etc.) is dellocated is not a trivial operation. We might take a look at how that happens and how it could be observed in a following article later.\u003c/p\u003e\n\u003cp\u003eWith the common scheduling states in mind, we can draw a simplified goroutine state machine focused on \u003ccode\u003e_Grunnable\u003c/code\u003e, \u003ccode\u003e_Grunning\u003c/code\u003e, \u003ccode\u003e_Gwaiting\u003c/code\u003e, \u003ccode\u003e_Gsyscall\u003c/code\u003e, \u003ccode\u003e_Gpreempted\u003c/code\u003e, and \u003ccode\u003e_Gdead\u003c/code\u003e. I\u0026#39;m leaving \u003ccode\u003e_Gidle\u003c/code\u003e out of the main diagram because then the goroutine is just allocated and not yet initialized, and I\u0026#39;m omitting specialized states like \u003ccode\u003e_Gcopystack\u003c/code\u003e, \u003ccode\u003e_Gleaked\u003c/code\u003e, and \u003ccode\u003e_Gdeadextra\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/xgotop/go_goroutine_state_machine.svg\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eAnd now we\u0026#39;re ready to write some eBPF hooks to take a closer look at those functions\u0026#39; arguments in realtime!\u003c/p\u003e\n\u003ch2 id=\"using-bpftrace-to-validate-our-idea\"\u003eUsing bpftrace to Validate Our Idea\u003c/h2\u003e\n\u003cp\u003eWhenever I have a new eBPF related idea, I actually prefer writing a simple PoC in \u003ccode\u003ebpftrace\u003c/code\u003e before jumping into a full eBPF program design and implementation. That helps me to see if that idea is viable or not faster.\u003c/p\u003e\n\u003cp\u003eFor those who are not familiar with, \u003ccode\u003ebpftrace\u003c/code\u003e is a program/parser/transpiler which can translate a special script format to a whole eBPF program with multiple hooks. It has some cool simplifications, for example you can define \u
3003ccode\u003eC\u003c/code\u003e-style \u003ccode\u003estruct\u003c/code\u003es and use them to decode complex in-kernel and in-runtime data structures using pointer dereference, and bpftrace automatically does safe memory handling:\u003c/p\u003e\n\u003cpre data-language=\"C\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint64_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// offset=152 size=8\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e};\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euprobe\u003c/span\u003e\u003cspan style=\"\"\u003e:.\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e/\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etestserver\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003eruntime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003enewobject\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r28\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThat \u003ccode\u003e((struct g *)reg(\u0026#34;r28\u0026#34;))-\u0026gt;goid\u003c/code\u003e would require 2 extra variables and BPF CO-RE memory copy calls in eBPF C code for example.\u003c/p\u003e\n\u003cp\u003eAnother cool feature is that we can directly get current register values via the \u
3003ccode\u003ereg()\u003c/code\u003e function. And as Go uses registers for function arguments in its call convention\u003csup id=\"fnref:2\"\u003e\u003ca href=\"#fn:2\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e2\u003c/a\u003e\u003c/sup\u003e, we can directly access them using \u003ccode\u003ereg\u003c/code\u003e and custom type definitions. Such as the example above, which uses \u003ccode\u003ereg(\u0026#34;r28\u0026#34;)\u003c/code\u003e to get the current goroutine object in arm64 architecture, and use a custom defined \u003ccode\u003estruct g\u003c/code\u003e type to access the \u003ccode\u003egoid\u003c/code\u003e field of it.\u003c/p\u003e\n\u003cp\u003e\u003cnewslettercard\u003e\u003c/newslettercard\u003e\u003c/p\u003e\n\u003ch3 id=\"a-little-more-of-go-runtime-magic\"\u003eA Little More of Go Runtime Magic\u003c/h3\u003e\n\u003cp\u003eLet\u0026#39;s see which Go runtime function arguments we can peek into. As a refresher, these are the functions we\u0026#39;ll hook:\u003c/p\u003e\n\u003cpre data-filename=\"src/runtime/...\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ecasgstatus\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003egp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eoldval\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enewval\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint32\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003enewobject\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003etyp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e_type\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eunsafe\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003emakeslice\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eet\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e_type\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eunsafe\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003emakemap\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eabi\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMapType\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ehint\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003emaps\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMap\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003emaps\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMap\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWe\u0026#39;ve took a look into \u003ccode\u003eruntime.g\u003c/code\u003e struct before, the new runtime types here are: \u003ccode\u003eabi.MapType\u003c/code\u003e, and \u003ccode\u003eruntime._type\u003c/code\u003e which is actually defined to be a reference to \u003ccode\u003eabi.Type\u003c/code\u003e:\u003c/p\u003e\n\u003cpre data-filename=\"src/runtime/type.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_type\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eabi\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eType\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003ch4 id=\"abitype\"\u003e\u003ccode\u003eabi.Type\u003c/code\u003e\u003c/h4\u003e\n\u003cp\u003eThe runtime representation of a Go type in Go\u0026#39;s ABI. Defines the type\u0026#39;s total size, kind, alignment, string form, etc.\u003c/p\u003e\n\u003cpre data-filename=\"src/internal/abi/type.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eType\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eSize_\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ePtrBytes\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// number of (prefix) bytes in the type that can contain pointers\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eHash\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint32\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// hash of type; avoids computation in hash tables\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eTFlag\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"\"\u003eTFlag\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// extra type information flags\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eAlign_\u003c/span\u003e\u003cspan style=\"\"\u003e      \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// alignment of variable with this type\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eFieldAlign_\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// alignment of struct field with this type\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eKind_\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"\"\u003eKind\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// what kind of type this is (string, int, ...)\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// function for comparing objects of this type\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// (ptr to object A, ptr to object B) -\u0026gt; ==?\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eEqual\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eunsafe\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eunsafe\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebool\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eGCData\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebyte\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eStr\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"\"\u003eNameOff\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// string form\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4
3em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ePtrToThis\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eTypeOff\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// type for pointer to this type, may be zero\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe \u003ccode\u003eKind_\u003c/code\u003e field here defines what kind of type this one is, which is defined in Go source code as:\u003c/p\u003e\n\u003cpre data-filename=\"src/internal/abi/type.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// A Kind represents the specific kind of type that a Type represents.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// The zero Kind is not a valid kind.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eKind\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003econst\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eInvalid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eKind\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eiota\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eBool\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eInt\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eInt8\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eInt16\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eInt32\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eInt64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eUint\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eUint8\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eUint16\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eUint32\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eUint64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eUintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eFloat32\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eFloat64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eComplex64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eComplex128\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eArray\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eChan\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eFunc\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eInterface\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eMap\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;
3color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eSlice\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eStruct\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eUnsafePointer\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003ch4 id=\"abimaptype\"\u003e\u003ccode\u003eabi.MapType\u003c/code\u003e\u003c/h4\u003e\n\u003cp\u003eThe actual metadata definition of a Go map, including the native/custom types of keys, values, the hash function \u003ccode\u003efunc(unsafe.Pointer, uintptr) uintptr\u003c/code\u003e, etc.\u003c/p\u003e\n\u003cpre data-filename=\"src/internal/abi/map.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eMapType\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eType\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eKey\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eType\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eElem\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eType\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eGroup\u003c/span\u003e\u003cspan style=\"\"\u003e      \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eType\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eHasher\u003c/span\u003e\u003cspan style=\"\"\u003e     \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eunsafe\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eGroupSize\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eKe
3ysOff\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eKeyStride\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eElemsOff\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eElemStride\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eElemOff\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eFlags\u003c/span\u003e\u003cspan style=\"\"\u003e      \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint32\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe \u003ccode\u003e*Type\u003c/code\u003e here is a pointer to \u003ccode\u003eabi.Type\u003c/code\u003e, which is explained above.\u003c/p\u003e\n\u003cp\u003eReturning back to the functions we\u0026#39;ll hook, here are what we can learn about the goroutines by decoding the function arguments in bpftrace/eBPF:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003ecasgstatus\u003c/code\u003e -\u0026gt; Goroutine ID, parent goroutine ID, old state, new state\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003enewobject\u003c/code\u003e -\u0026gt; Memory size and the kind of the new object\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003emakeslice\u003c/code\u003e -\u0026gt; Length and capacity of the new slice, and the total memory size and the kind of it\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003emakemap\u003c/code\u003e -\u0026gt; Hint (initial capacity), key/value types (their total sizes and kinds) of the new map, and the total memory size and the kind of it\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"xgotopbt-bpftrace-script\"\u003exgotop.bt bpftrace Script\u003c/h3\u003e\n\u003cp\u003eSo let\u0026#39;s try writing a simple bpftrace program/script to hook into these Go runtime functions. We first need a Go program to test our bpftrace code on. We will use an extremely simple HTTP server:\u003c/p\u003e\n\u003cpre data-filename=\"cmd/testserver/main.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003epackage\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emain\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eimport\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;fmt\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;net/http\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;github.com/gorilla/mux\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003emain\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003er\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emux\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eNewRouter\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003er\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eHandleFunc\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;/books/{title}/page/{page}\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eGetBook\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ehttp\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eListenAndServe\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;:80\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003er\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eGetBook\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ew\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ehttp\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eResponseWriter\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003er\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003ehttp\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eRequest\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003evars\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emux\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eVars\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003er\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003etitle\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003evars\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;title\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003epage\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003evars\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;page\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ew\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;You\u0026#39;ve requested the book: %s on page %s\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003etitle\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epage\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWhen you build and run this \u003ccode\u003etestserver\u003c/code\u003e program and send an HTTP request via \u003ccode\u003ecurl\u003c/code\u003e or \u003ccode\u003ehttpie\u003c/code\u003e or your favorite HTTP client, you\u0026#39;ll see that it\u0026#39;s working:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ go build -o testserver ./cmd/testserver\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ ./testserver \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ curl localhost/books/test123/page/45\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eYou\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026#39;\u003c/span\u003e\u003cspan style=\"\"\u003eve requested the book: test123 on page \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e45\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eBut that\u0026#39;s not the point, obviously. Now we can write the actual code, which is the bpftrace code. We\u0026#39;ll hook into the functions \u003ccode\u003ecasgstatus\u003c/code\u003e, \u003ccode\u003enewobject\u003c/code\u003e, \u003ccode\u003emakeslice\u003c/code\u003e, and \u003ccode\u003emakemap\u003c/code\u003e, then use the registers to decode actual function call arguments to observe goroutine lifecycle events in specific points in time.\u003c/p\u003e\n\u003cp\u003eBelow is the full bpftrace proof-of-concept implementation for our goroutine tracer:\u003c/p\u003e\n\u003cpre data-filename=\"xgotop.bt\" data-language=\"C\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_pad1\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e152\u
3003c/span\u003e\u003cspan style=\"\"\u003e];\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint64_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// offset=152 size=8\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_pad2\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e112\u003c/span\u003e\u003cspan style=\"\"\u003e];\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint64_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// offset=272 size=8\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_pad3\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e];\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint64_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003estartpc\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// offset=296 size=8\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e};\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_type\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint64_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// offset=0 size=8\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_pad1\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e];\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// offset=23 size=1\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emapType\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_pad1\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e];\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_type\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// offset=48 size=8\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_type\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eelem\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// offset=56 size=8\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e};\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// func casgstatus(gp *g, oldval, newval uint32)\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euprobe\u003c/span\u003e\u003cspan style=\"\"\u003e:.\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e/\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etestserver\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003eruntime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ecasgstatus\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r0\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;
3color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003estartpc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003estartpc\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r28\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003estatus\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r2\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e34\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e35\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;[%llu] pid=%d goid=%llu parentGoid=%llu startpc=%llx status=%llu [goroutine_id=%lld]\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\\n\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ensecs\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epid\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003estartpc\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003estatus\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e36\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e37\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e38\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// func newobject(typ *_type) unsafe.Pointer\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e39\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euprobe\u003c/span\u003e\u003cspan style=\"\"\u003e:.\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e/\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etestserver\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003eruntime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003enewobject\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e40\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e41\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r28\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e42\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e43\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e44\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003etyp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_type\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r0\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e));\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e45\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003etyp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e46\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003etyp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e47\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;[%llu] g:%lld:runtime.newobject(size=%llu, kind=%llu)\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\\n\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ensecs\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e49\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e50\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e51\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// func makeslice(et *_type, len, cap int) unsafe.Pointer \n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e52\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euprobe\u003c/span\u003e\u003cspan style=\"\"\u003e:.\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e/\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etestserver\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003eruntime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003emakeslice\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e53\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e54\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r28\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e55\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e56\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e57\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003etyp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_type\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r0\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e));\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e58\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003etyp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e59\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003etyp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e60\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e61\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r1\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e62\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r2\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e63\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e64\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;[%llu] g:%lld:runtime.makeslice(size=%llu, kind=%llu, len=%llu, cap=%llu)\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\\n\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ensecs\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e65\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e66\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e67\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// func makemap(t *abi.MapType, hint int, m *maps.Map) *maps.Map\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e68\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euprobe\u003c/span\u003e\u003cspan style=\"\"\u003e:.\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e/\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etestserver\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003eruntime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003emakemap\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e69\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e70\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r28\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e71\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003eg\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003egoid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e72\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e73\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003emaptyp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emapType\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r0\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e));\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e74\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e75\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ekeysize\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003emaptyp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e76\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ekeykind\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003emaptyp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e77\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003evalsize\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003emaptyp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003eelem\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003esize\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e78\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003evalkind\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003emaptyp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003eelem\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003ekind\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e79\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e80\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ehint\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ereg\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;r1\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e81\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e82\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;[%llu] g:%lld:runtime.makemap(keysize=%llu, keykind=%llu, valsize=%llu, valkind=%llu, hint=%llu)\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\\n\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ensecs\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ekeysize\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ekeykind\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003evalsize\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003evalkind\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e$\u003c/span\u003e\u003cspan style=\"\"\u003ehint\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e83\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eHere\u0026#39;s how every hook is written:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eI\u0026#39;ve defined \u003ccode\u003estruct\u003c/code\u003es \u003ccode\u003eg\u003c/code\u003e, \u003ccode\u003e_type\u003c/code\u003e, \u003ccode\u003emapType\u003c/code\u003e to be able to use internal Go types \u003ccode\u003eruntime.g\u003c/code\u003e, \u003ccode\u003eabi.Type\u003c/code\u003e and \u003ccode\u003eabi.MapType\u003c/code\u003e. Notice how I\u0026#39;ve used arbitrary \u003ccode\u003euint8_t\u003c/code\u003e arrays in those structs as field paddings. The reason behind doing this is that we don\u0026#39;t need most of those internal objects\u0026#39; fields - for example in \u003ccode\u003eruntime.g\u003c/code\u003e we only need ID and parent ID. We can easily skip past the remaining ones using single-byte (\u003ccode\u003euint8_t\u003c/code\u003e) arrays with a desired length.\u003c/li\u003e\n\u003cli\u003eUsed \u003ccode\u003euprobe\u003c/code\u003e (userspace probe) to hook the runtime functions. These functions are a bit costly in the means of latency, however better for faster prototyping. Every hook in bpftrace can simply be written in 3 parts:\u003c/li\u003e\n\u003c/ul\u003e\n\u003cpre\u003e\u003ccode\u003e\u0026lt;kind\u0026gt;:\u0026lt;program\u0026gt;:\u0026lt;function\u0026gt;\n\nuprobe:./testserver:runtime.makemap\n\u003c/code\u003e\u003c/pre\u003e\n\u003cul\u003e\n\u003cli\u003eUsed \u003ccode\u003er28\u003c/code\u003e to get the current goroutine\u0026#39;s \u003ccode\u003eg\u003c/code\u003e struct\u003csup id=\"fnref:3\"\u003e\u003ca href=\"#fn:3\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e3\u003c/a\u003e\u003c/sup\u003e\u003c/li\u003e\n\u003cli\u003eCasted the related registers (\u003ccode\u003er28\u003c/code\u003e, \u003ccode\u003er0\u003c/code\u003e, ...) into the related in-script structs to inspect the function call arguments in better detail\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003e\u003cnewslettercard\u003e\u003c/newslettercard\u003e\u003c/p\u003e\n\u003cp\u003eIf you run \u003ccode\u003exgotop.bt\u003c/code\u003e with bpftrace while the \u003ccode\u003etestserver\u003c/code\u003e is running in the background and send some random HTTP requests to it, you\u0026#39;ll see some interesting logs coming from bpftrace:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ sudo bpftrace ./xgotop.bt\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eAttaching \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e probes...\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348086967086\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e0\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087023933\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e0\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087033386\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087051502\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087054417\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e56, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087059165\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e128, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c
3/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087066328\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e56, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087069160\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e48, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087071076\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e48, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087076573\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087079363\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087081279\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e8, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e57\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087083403\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087085818\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087087234\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087097812\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e144, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087099978\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e48, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan st
3yle=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087103726\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:1:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e32, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087106266\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:0:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e440, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348087108599\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e0\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348088014562\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1e3710 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e0\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348088057207\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348088069535\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e51cf0 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090552043\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003epid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e19641\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eparentGoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estartpc\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1e3710 \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estatus\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003egoroutine_id\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e0\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090586900\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e48, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;
3color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090607307\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e80, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090610139\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e16, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090611555\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e64, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090615678\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.makeslice\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e128, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e4, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e4\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090618218\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.newobject\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e88, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090620009\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.makeslice\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e8, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e4096, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e4096\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e34\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090627630\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.makeslice\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e128, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e25, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e4, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e4\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e35\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10348090628921\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e g:21:runtime.makeslice\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003esize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e1, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ekind\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e8, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e4096, \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e4096\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eYou can see that after an HTTP request is sent:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eA new goroutine with ID \u003ccode\u003e21\u003c/code\u003e is spawned to handle it (\u003ccode\u003estartpc\u003c/code\u003e of \u003ccode\u003e0x1e3710\u003c/code\u003e is probably the \u
3003ccode\u003eGetBook\u003c/code\u003e function of \u003ccode\u003etestserver\u003c/code\u003e)\u003c/li\u003e\n\u003cli\u003eThere are two slices allocated with type \u003ccode\u003eUint8\u003c/code\u003e and length \u003ccode\u003e4096\u003c/code\u003e (\u003ccode\u003eg:21:runtime.makeslice(size=1, kind=8, len=4096, cap=4096)\u003c/code\u003e), which are probably the request and response body buffers\u003c/li\u003e\n\u003cli\u003eThere are arbitrary structs allocated for various reasons (\u003ccode\u003eg:21:runtime.newobject(size=..., kind=25)\u003c/code\u003e)\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eAs you can see, we can now trace arbitrary goroutines running in a specific Go executable!\u003c/p\u003e\n\u003cp\u003eWe can stop right here, feel free to play around with \u003ccode\u003exgotop.bt\u003c/code\u003e by changing hooks, adding new ones, inspecting another Go program, etc.\u003c/p\u003e\n\u003cp\u003eIn the next part, we will turn this PoC into a standalone project utilizing eBPF ringbuffers, hashmaps, and event sampling using C, Go and \u003ccode\u003ecilium/ebpf-go\u003c/code\u003e. Until then, stay tuned.\u003c/p\u003e\n\u003ch2 id=\"references\"\u003eReferences\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cchip text=\"ozansz/xgotop\" href=\"https://github.com/ozansz/xgotop\" icon=\"github\"\u003e\u003c/chip\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/golang/go/blob/master/src/runtime/proc.go\" target=\"_blank\"\u003eGo runtime: \u003ccode\u003eruntime/proc.go\u003c/code\u003e\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/golang/go/blob/master/src/runtime/map.go\" target=\"_blank\"\u003eGo runtime: \u003ccode\u003eruntime/map.go\u003c/code\u003e (map internals)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003cchip text=\"bpftrace\" href=\"https://github.com/bpftrace/bpftrace\" icon=\"github\"\u003e\u003c/chip\u003e\u003c/li\u003e\n\u003cli\u003e\u003cchip text=\"cilium/ebpf-go\" href=\"https://github.com/cilium/ebpf\" icon=\"github\"\u003e\u003c/chip\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cdiv class=\"footnotes\" role=\"doc-endnotes\"\u003e\n\u003chr/\u003e\n\u003col\u003e\n\u003cli id=\"fn:1\" data-index=\"1\"\u003e\n\u003cp\u003e\u003ca href=\"https://en.wikipedia.org/wiki/Compare-and-swap\" target=\"_blank\"\u003eCompare-and-swap\u003c/a\u003e \u003ca href=\"#fnref:1\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:2\" data-index=\"2\"\u003e\n\u003cp\u003eGo uses different registers for different architectures: \u003ca href=\"https://go.dev/src/cmd/compile/abi-internal#amd64-architecture\"\u003ehttps://go.dev/src/cmd/compile/abi-internal#amd64-architecture\u003c/a\u003e \u003ca href=\"https://go.dev/src/cmd/compile/abi-internal#arm64-architecture\"\u003ehttps://go.dev/src/cmd/compile/abi-internal#arm64-architecture\u003c/a\u003e \u003ca href=\"#fnref:2\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:3\" data-index=\"3\"\u003e\n\u003cp\u003eIn \u003ccode\u003earm64\u003c/code\u003e Go ABI, r28 is the register that stores the current goroutine object\u0026#39;s memory location \u003ca href=\"#fnref:3\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n"])</script>
3<script>self.__next_f.push([1,"27:T8831,"])</script>
3<script>self.__next_f.push([1,"\n\nIn the [previous article](/articles/visual-guide-to-slices-in-go-2024-03-25), we explored how slices work under the hood. Today, we'll dive into another fundamental Go data structure: **maps**. We'll see how Go implements maps as hash tables, how they handle collisions, and how they grow dynamically.\n\n\u003e!char![sazak-explain] This will be a two part series. This first part will cover the old `map` implementation which was in use until Go 1.24. The second part will cover the new `map` implementation using swiss tables. \u003c!--Although the current implementation is different than the legacy one, it's still worth learning. At the end of this article, you'll find [exercises](#exercises) to test your understanding.--\u003e\n\nThe mini note below covers the basics of hash tables and how they are implemented in simple terms. Feel free to skip it if you already know the basics.\n\n\u003ccollapsible-item title=\"What is a hash table?\" kind=\"mini-note\" readingtime=\"3\" parsetextfrom=\"mini-notes/primer-on-hash-tables.md\"\u003e\u003c/collapsible-item\u003e\n\nComing back to the main topic, let's see how maps are implemented in Go.\n\nIn Go, before version 1.24, **a map is a hash table implementation** that stores key-value pairs. Unlike slices which use integer indices, maps allow you to use any comparable[^3] type as a key to access values efficiently. A type is comparable if values of that type can be compared with `==` and `!=` operators.\n\nHere's how a map is defined in the [Go runtime](https://github.com/golang/go/blob/dd8b7ad9268c2fbde675132a41b4e4da02eef94d/src/runtime/map.go#L109):\n\n```go filename=\"go/src/runtime/map.go\"\ntype hmap struct {\n    count      int\n    flags      uint8\n    B          uint8\n    noverflow  uint16\n    hash0      uint32\n    buckets    unsafe.Pointer\n    oldbuckets unsafe.Pointer\n    nevacuate  uintptr\n    extra      *mapextra\n}\n```\n\nWhen you create a map like `m := make(map[string]int)`, Go allocates this `hmap` structure under the hood. The map you're working with is actually a pointer to this structure, which is why maps behave like reference types in Go[^5].\n\nThe important fields in this data structure are:\n- `count`: Number of key-value pairs currently stored in the map\n- `B`: Number of bucket bits (not the bucket count itself). The actual number of buckets is `2^B` (or `1 \u003c\u003c B` in Go). So if `B` is 3, you have 8 buckets.\n- `buckets`: Pointer to an array of buckets where key-value pairs are stored\n- `hash0`: A random seed used by the hash function. This seed is generated 
3when the map is created and it makes the hash function non-deterministic.\n\n\u003e!char![sazak-explain] The `oldbuckets` and `nevacuate` fields are used during map growth, which we'll explore in detail later.\n\nLet's start with a simple map creation:\n\n```go\nuserAges := map[string]int{\n    \"alice\": 25,\n    \"bob\":   30,\n    \"carol\": 28,\n}\n```\n\nThis creates a map with string keys and integer values. But how does Go organize this data internally?\n\n## Buckets\n\nWhen you work with a map, the Go runtime doesn't just store your key-value pairs in a simple array. Instead, it uses a **hash table with buckets**. Think of buckets as containers that hold multiple key-value pairs, and the hash table is an array of these buckets.\n\nThe key idea is, when you insert a key-value pair, Go hashes the key to determine which bucket it belongs to. All keys that hash to the same bucket are stored together. This organization allows for fast lookups. Go can hash your key once and immediately know which bucket to search in, rather than scanning through all the data.\n\nAnd here's how our `userAges` map looks like internally, at a high level:\n\n\u003cMapView \n    name=\"userAges map[string]int\" \n    buckets=\"8\" \n    items=\"alice:25,bob:30,carol:28\"\n    theme=\"blue\"\n/\u003e\n\nYou can see the map has **8 buckets** (numbered 0-7), which means `B = 3` since 2^3 = 8. \n\nEach colored cell represents a bucket that contains at least one key-value pair. The three keys we inserted, `\"alice\"`, `\"bob\"`, and `\"carol\"` were hashed and distributed across different buckets in the array. Notice they didn't all go to the same bucket; the hash function distributed them to help balance the load.\n\nThe gray buckets are empty, ready to receive new entries as we add more key-value pairs to the map.\n\nGo maps use **overflow pointers** to handle collisions. When a bucket becomes full, instead of reorganizing everything, Go simply allocates a new overflow bucket and links it to the full one, creating a short chain.\n\n### Bucket Structure\n\nNow let's look at what's inside each bucket. Each bucket in Go can hold up to **8 key-value pairs**. You can see that this value is hardcoded in [Go source code](https://github.com/golang/go/blob/dd8b7ad9268c2fbde675132a41b4e4da02eef94d/src/internal/abi/map.go):\n\n```go filename=\"go/src/internal/abi/map.go\"\npackage abi\n\nconst (\n\t// Maximum number of key/elem pairs a bucket can hold.\n\tMapBucketCountBits = 3 // log2 of number of elements in a bucket.\n\tMapBucketCount     = 1 \u003c\u003c MapBucketCountBits\n)\n```\n\nHere's the actual bucket structure:\n\n```go filename=\"go/src/runtime/map.go\"\ntype bmap struct {\n    tophash [abi.MapBucketCount]uint8\n}\n```\n\nThe `tophash` array is an interesting optimization. It stores the top 8 bits of each key's hash value. When Go searches for a key in a bucket, it first scans the `tophash` array. Only when it finds a matching tophash, the key comparison is done. This mean that Go can quickly skip over slots that definitely don't contain the key, without having to compare complex key types.\n\n\u003e!char![husky-1-1] The actual keys and values are stored after the `tophash` array, but they're not visible in the struct definition because their types are determined at runtime. Go knows the types of your keys and values at compile time, so it can calculate the correct memory layout dynamically.\n\nIf you search through the runtime code in Go source code (as I did), you can find the actual creation process of a bucket:\n\n```go filename=\"go/src/cmd/compile/internal/reflectdata/reflect.go\"\nfunc MapBucketType(t *types.Type) *types.Type {\n\t// Builds a type representing a Bucket structure for\n\t// the given map type. This type is not visible to users -\n\t// we include only enough information to generate a correct GC\n\t// program for it.\n\t// Make sure this stays in sync with runtime/map.go.\n\t//\n\t//\tA \"bucket\" is a \"struct\" {\n\t//\t      tophash [abi.MapBucketCount]uint8\n\t//\t      keys [abi.MapBucketCount]keyType\n\t//\t      elems [abi.MapBucketCount]elemType\n\t//\t      overflow *bucket\n\t//\t    }\n```\n\nLet's see how our example map looks with bucket details:\n\n\u003cMapBucket \n    bucket=\"0\" \n    tophash=\"ab,cd,ef,00,00,00,00,00\"\n    keys=\"alice,bob,carol,,,,,,\"\n    values=\"25,30,28,,,,,,\"\n    theme=\"blue\"\n/\u003e\n\nHere, you're looking at bucket 0 of our `userAges` map. Let's break down what each part means:\n\n**The tophash array:** `[ab, cd, ef, 00, 00, 00, 00, 00]`\n\nThe first three slots contain tophash values (`0xAB`, `0xCD`, `0xEF`). These are the top 8 bits from hashing \"alice\", \"bob\", and \"carol\" respectively. The remaining five slots show `0x00`, indicating they're empty and available for new entries.\n\n**The keys array:** `[alice, bob, carol, _, _, _, _, _]`\n\nThe first three positions hold our actual keys. The empty positions (shown with commas or underscores) are unused slots waiting for new key-value pairs.\n\n**The values array:** `[25, 30, 28, _, _, _, _, _]`\n\nThe values are stored in the same order as their corresponding keys. Alice's age (25) is at index 0, Bob's (30) at index 1, and Carol's (28) at index 2.\n\n## Hash Function and Key Distribution\n\nWhen you insert a key-value pair into a map, Go needs to decide which bucket to place it in. This is where the hash function comes in to play.\n\nLet's say we're inserting `\"gokce\": 25` into our map. Here's what Go does step by step.\n\nFirst, Go applies a hash function[^1] to the key along with the map's random seed (`hash0`):\n\n```go\nhash := hashFunction(\"gokce\", map.hash0)\n// Let's say this produces: 0xAB7F3C2E4D1A6B8F (64-bit hash)\n```\n\nGo then uses the **lower B bits** of the hash to select which bucket to use. If our map has `B = 3` (meaning 8 buckets), Go takes the lowest 3 bits:\n\n```go\nbucketIndex := hash \u0026 ((1 \u003c\u003c B) - 1)  // Bitwise AND with mask\n// If hash ends in ...110 (binary), bucketIndex = 6\n```\n\nThis logic is defined in the `bucketMask` function in Go source code:\n\n```go filename=\"go/sr
3c/runtime/map.go\"\n// bucketShift returns 1\u003c\u003cb, optimized for code generation.\nfunc bucketShift(b uint8) uintptr {\n\t// Masking the shift amount allows overflow checks to be elided.\n\treturn uintptr(1) \u003c\u003c (b \u0026 (goarch.PtrSize*8 - 1))\n}\n\n// bucketMask returns 1\u003c\u003cb - 1, optimized for code generation.\nfunc bucketMask(b uint8) uintptr {\n\treturn bucketShift(b) - 1\n}\n```\n\nThis is much faster than using the modulo operator (`%`). Since the bucket count is always a power of 2, we can use a bitwise AND instead.\n\nAfter that, Go takes the **top 8 bits** of the hash and stores them in the bucket's `tophash` array and finds an empty slot in the selected bucket and stores the tophash, key, and value there.\n\nLet's see how different keys get distributed across buckets:\n\n\u003cMapView \n    name=\"Distribution Example\" \n    buckets=\"8\" \n    items=\"alice:25,bob:30,carol:28,dave:35,eve:22\"\n    theme=\"green\"\n    showHashDist=\"1\"\n/\u003e\n\n## Handling Collisions\n\nSo what happens when multiple keys hash to the same bucket? This is called a **collision**, and it's inevitable in hash tables. The hash function tries to distribute keys evenly, but with a limited number of buckets some will inevitably end up with more entries than others.\n\nLet's say we have bucket 0 with three entries: `\"alice\"`, `\"bob\"`, and `\"carol\"`. Now we keep adding more keys that also hash to bucket 0 (oops!)\n\n```go\nuserAges[\"dave\"] = 35    // Hashes to bucket 0, slot 3\nuserAges[\"eve\"] = 22     // Hashes to bucket 0, slot 4\nuserAges[\"frank\"] = 32   // Hashes to bucket 0, slot 5\nuserAges[\"grace\"] = 29   // Hashes to bucket 0, slot 6\nuserAges[\"henry\"] = 31   // Hashes to bucket 0, slot 7\n```\n\nAt this point, bucket 0 has all 8 slots filled. What happens when we try to add one more key that hashes to the same bucket?\n\n```go\nuserAges[\"ivan\"] = 26    // Also hashes to bucket 0... but it's full!\n```\n\nGo doesn't reorganize the entire map at this point. Instead, it allocates an **overflow bucket** and links it to the original bucket. The overflow bucket is just another `bmap` structure -with the actual key and value arrays defined dynamically in runtime- and the original bucket's `overflow` pointer now points to it.\n\nHere's how overflow buckets work:\n\n\u003cMapBucket \n    bucket=\"0\" \n    tophash=\"ab,cd,ef,12,34,56,78,9a\"\n    keys=\"alice,bob,carol,dave,eve,frank,grace,henry\"\n    values=\"25,30,28,35,22,32,29,31\"\n    overflow=\"true\"\n    theme=\"yellow\"\n/\u003e\n\nThe overflow bucket is linked to the main bucket, creating a short chain. When Go looks up a key in bucket `0`, it first checks the main bucket, and if the key isn't found there, it follows the overflow pointer to check the overflow bucket.\n\nThis chaining approach is simple and efficient for small numbers of overflows. However, if you have many overflow buckets, lookups become slower (you have to scan multiple buckets). That's why Go monitors overflow bucket usage and triggers map growth when there are too many of them.\n\n\u003cnewslettercard\u003e\u003c/newslettercard\u003e\n\n## Looking Up Values\n\nWhen you access a value with `value := userAges[\"alice\"]`, it might look like a simple operation, but there's quite a bit happening under the hood. Let's take a look at what happens when a map value is accessed by a key.\n\n\u003cMapBucket \n    bucket=\"0\" \n    tophash=\"ab,cd,ef,00,00,00,00,00\"\n    keys=\"alice,bob,carol,,,,,,\"\n    values=\"25,30,28,,,,,,\"\n    highlight=\"alice\"\n    theme=\"blue\"\n/\u003e\n\n1. Go computes the hash of `\"alice\"` using the map's hash function and seed:\n\n```go\nhash := hashFunction(\"alice\", hash0)  // e.g., 0xAB7F3C2E4D1A6B8F\n```\n\n2. Using the lower `B` bits of the hash, Go calculates which bucket to search the key inside:\n\n```go\nbucketIndex := hash \u0026 ((1 \u003c\u003c B) - 1)  // e.g., bucket 6\ntophash := hash \u003e\u003e (64 - 8)           // e.g., 0xAB\n```\n\n3. Now Go walks through the bucket's `tophash` array looking for a match. Let's say bucket 6 looks like this:\n\n```\ntophash: [0xAB, 0xCD, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00]\nkeys:    [\"alice\", \"bob\", \"carol\", ...]\n```\n\nGo scans the tophash array, sees that the value at index 0 matches the tophash value of the key, and now it knows exactly where to look at. After retrieving the value at the same index in the values section of the bucket and returns it.\n\nIf Go scans all tophash entries (including any overflow bu
3ckets) without finding a match, it returns the **zero value** of the map's value type.\n\n```go\nvalue, ok := userAges[\"alice\"]\n\nif ok {\n    fmt.Printf(\"Alice is %d years old\\n\", value)\n} else {\n    // value is 0 (zero value for int)\n    fmt.Printf(\"Alice not found, got zero value: %d\\n\", value)\n}\n```\n\nWhen accessing a non-existent key, Go returns the **zero value** of the map's value type (`0` for numbers, `\"\"` for strings, `nil` for pointers, etc.). The two-value form (`value, ok`) lets you distinguish between a key that exists with a zero value and a key that doesn't exist at all.\n\n\u003e!char![sazak-explain] A return of `(\"\", true)` and `(\"\", false)` are not the same. The first one means that there was actually an entry in the map with the specified key, which value is an empty string. The second one means that there were no value associated with that key.\n\nThis is why checking `if m[\"key\"] != 0` can be ambiguous, the key might not exist, or it might exist with a zero value. Always use the two-value form when you need to distinguish these cases.\n\n## Map Growth\n\nAs you add more key-value pairs to a map, performance would degrade if Go kept using the same number of buckets. With more entries squeezed into the same buckets, lookups would require scanning longer bucket chains, making operations slower.\n\nThat's why maps grow dynamically. Go monitors the map's health and triggers growth when performance would suffer.\n\n\u003e!char![husky-1] Go runtime decides on whether to grow the map or not is based on **load factor**, which is the average number of key-value pairs per bucket.\n\nA map grows when either of these conditions is met:\n\n### Condition 1: High load factor\n\nThe average number of key-value pairs per bucket exceeds **6.5** (load factor threshold). This is calculated as:\n\n```go\nloadFactor := count / (1 \u003c\u003c B)  // count / numberOfBuckets\nif loadFactor \u003e 6.5 {\n    // Trigger growth\n}\n```\n\nWhy 6.5? That number comes from 80% threshold, as it's defined in Go runtime source code. It's a balance between memory usage and performance, a sweet spot where you don't waste too much memory but also don't have too many overflow buckets yet.\n\nLet's see an example. Say we have a map with 4 buckets that has accumulated 28 entries:\n\n**Before Growth (load factor = 7.0):**\n\u003cMapView \n    name=\"High Load Factor Map\" \n    buckets=\"4\" \n    items=\"gokce:25,ozan:26,carol:28,dave:35,alp:26,frank:32,grace:29,henry:31,baris:18,jack:33,akin:26,leo:26,mary:31,nick:29,olivia:23,paul:36,sulo:31,rachel:30,sam:28,tina:32,james:18,victor:27,wendy:31,bob:30,alice:25,zack:33,yigit:25,ben:30\"\n    theme=\"yellow\"\n    loadFactor=\"7\"\n/\u003e\n\nThe load factor is 28 / 4 = 7.0, which exceeds the 6.5 threshold. Many buckets are overflowing, creating long chains that slow down lookups.\n\nIn this case, the runtime performs a **regular growth** by doubling the bucket count. Here's what happens:\n\n1. Go increments `B` by 1[^2], which doubles the bucket count. If you had 4 buckets (`B == 2`), you now have 8 buckets (`B == 3`). The new bucket array is allocated, but the old buckets remain in place.\n\n2. The `hmap.buckets` pointer is updated to point to the new bucket array, and `hmap.oldbuckets` is set to point to the old buckets. The map is now in a **growing** state.\n\n3. Runtime starts an **incremental evacuation** process, where it doesn't move all key-value pairs immediately. Instead, it evacuates entries gradually during normal map operations. We'll discuss this in detail in the next section.\n\n**After Growth (load factor = 3.5):**\n\u003cMapView \n    name=\"After Regular Growth\" \n    buckets=\"8\" \n    items=\"gokce:25,ozan:26,carol:28,dave:35,alp:26,frank:32,grace:29,henry:31,baris:18,jack:33,akin:26,leo:26,mary:31,nick:29,olivia:23,paul:36,sulo:31,rachel:30,sam:28,tina:32,james:18,victor:27,wendy:31,bob:30,alice:25,zack:33,yigit:25,ben:30\"\n    theme=\"green\"\n    loadFactor=\"3.5\"\n/\u003e\n\nNow with 8 buckets, the load factor drops to 28 / 8 = 3.5, which is well below the threshold. The entries are redistributed more evenly, and overflow chains are reduced or eliminated.\n\n### Condition 2: Too many overflow bu
3ckets\n\nEven with a low load factor, if there are too many overflow buckets relative to the base bucket count, Go triggers a different type of growth. This happens when keys cluster unevenly, some buckets overflow while others stay mostly empty.\n\nIn this case, Go performs a **same-size growth** which reorganizes the data without adding more buckets. Runtime allocates a new bucket array with the same size as the current one (`B` stays the same). As entries are evacuated from old buckets to new ones, overflow chains are broken up. Keys that previously shared a bucket with many others might now be distributed more evenly, reducing overflow buckets. This process eliminates overflow buckets that accumulated over time due to deletions or poor initial distribution, making the map more cache-friendly.\n\n\u003e!char![beaver-question] Why would a map grow without increasing bucket count?\n\nWhen keys cluster in specific buckets due to hash patterns, you might have many overflow buckets even with a low overall load factor. For example, you might have a map with 100 entries across 16 bu
3ckets (load factor = 6.25, below the threshold), but if 80 entries landed in just 2 buckets, you'd have many overflow buckets. Same size growth reorganizes the data to improve performance without allocating more buckets.\n\nHere's how this logic is implemented in [Go source code](https://github.com/golang/go/blob/dd8b7ad9268c2fbde675132a41b4e4da02eef94d/src/runtime/map.go#L220):\n\n```go filename=\"go/src/runtime/map.go\"\n// incrnoverflow increments h.noverflow.\n// noverflow counts the number of overflow buckets.\n// This is used to trigger same-size map growth.\n// See also tooManyOverflowBuckets.\n// To keep hmap small, noverflow is a uint16.\n// When there are few buckets, noverflow is an exact count.\n// When there are many buckets, noverflow is an approximate count.\nfunc (h *hmap) incrnoverflow() {\n    ...\n}\n```\n\n### Incremental Evacuation\n\nHere's one of the cool aspects of Go's map implementation: **incremental evacuation**. Instead of moving all entries at once when the map grows (which could freeze your program for milliseconds on a large map), Go runtime spreads the work across many operations.\n\nHere's how it works:\n\n1. During growth, both old and new buckets exist and their references are held in `hmap` in the `oldbuckets` and `buckets` fields. When you perform any operation on the map, Go checks if the map is growing:\n\n```go filename=\"go/src/runtime/map.go\"\nif h.growing() {\n    growWork(t, h, bucket)  // Evacuate some pairs\n}\n```\n\n2. Whenever a value is inserted to, deleted from, or looked up in the map, Go evacuates at least one bucket (and possibly more) from the old array to the new array. The `nevacuate` field in the `hmap` structure tracks which old buckets have been evacuated.\n\n3. During the growth period, when you look up a key, Go might need to check the old buckets if that bucket hasn't been evacuated yet. The evacuation state markers in the `tophash` array (we'll see these shortly) tell Go whether to look in the old or new buckets.\n\nAn example code snippet from the Go source code, shows how the runtime handles an edge case of iterating through key/value pairs in the map during a grow:\n\n```go filename=\"go/src/runtime/map.go\"\n    if checkBucket != noCheck \u0026\u0026 !h.sameSizeGrow() {\n        // Special case: iterator was started during a grow to a larger size\n        // and the grow is not done yet. We're working on a bucket whose\n        // oldbucket has not been evacuated yet. Or at least, it wasn't\n        // evacuated when we started the bucket. So we're iterating\n        // through the oldbucket, skipping any keys that will go\n        // to the other new bucket (each oldbucket expands to two\n        // buckets during a grow).\n\n        ...\n    }\n```\n\n4. When doubling the bucket count (regular growth), each old bucket's entries are split between two new buckets:\n- Keys that hash to the old bucket index still hash there\n- Keys that need the newly available high bit go to `oldBucketIndex + oldBucketCount`\n\nThis incremental approach prevents \"stop-the-world\" pauses. Even with millions of entries, each individual operation only pays a small, bounded cost for evacuation. The map remains responsive throughout the growth process.\n\n\u003c!-- ## Special Cases and Optimizations\n\n### A note on special tophash values\n\nThe `tophash` array is doing double duty. Not only does it store the top 8 bits of hash values for quick comparisons, but it also uses special marker values to track the state of each slot in the bucket. These markers are crucial for map operations, especially during growth.\n\nThe special values (0-4) are:\n\n- **`emptyRest` (0)**: This cell is empty, and there are no more non-empty cells at higher indexes or overflows. This is an optimization, when Go sees this marker, it knows it can stop scanning the bucket immediately.\n- **`emptyOne` (1)**: This cell is empty, but there might be more entries after it. Go has to keep scanning.\n- **`evacuatedX` (2)**: During growth, this key/value has been evacuated to the first half of the larger table (same bucket index).\
3n- **`evacuatedY` (3)**: During growth, this key/value has been evacuated to the second half of the larger table (old bucket index + old bucket count).\n- **`evacuatedEmpty` (4)**: This cell was empty when the bucket was evacuated.\n- **`minTopHash` (5)**: Minimum value for a normal filled cell.\n\nNormal tophash values always start at 5 or higher. But what if the top 8 bits of your key's hash are actually 0, 1, 2, 3, or 4?\n\n\u003e!char![husky-1-1] If the top 8 bits of a hash compute to less than 5, Go adds `minTopHash` (5) to ensure it doesn't conflict with special markers. For example, if the top 8 bits are `0x03`, Go stores `0x08` instead. During lookup, Go knows to check both the exact tophash and the adjusted value. This clever design allows the tophash array to serve dual purposes: tracking cell states and storing hash bits for quick comparison.\n\nThese markers are why Go can efficiently handle map growth, deletions, and lookups even when the map is in a transitional state. --\u003e\n\n## A Note on interface Maps\n\nMaps with `interface{}` (or `any`) values are interesting because Go doesn't know the size of the values at compile time. An `interface{}` can hold anything: an `int` (which might be 8 bytes), a `string` (which is 16 bytes: pointer + length), or a complex struct.\n\nLet's see an example:\n\n```go\ndata := make(map[string]interface{})\ndata[\"number\"] = 42\ndata[\"text\"] = \"hello\"\ndata[\"slice\"] = []int{1, 2, 3}\n```\n\nHow does Go handle this? The values stored in the bucket aren't the actual data, they're **interface values**, which are represented with two pointers in runtime: one for the type, and one for the value. This means Go can still calculate a fixed bucket layout even though the concrete types can change.\n\n\u003cMapView \n    name=\"data map[string]interface{}\" \n    buckets=\"4\" \n    items=\"number:42,text:hello,slice:[1 2 3]\"\n    theme=\"purple\"\n    valueType=\"interface{}\"\n/\u003e\n\nThe actual data (`42`, `\"hello\"`, and the `[]int{1, 2, 3}` slice) is stored elsewhere in memory, and the interface values in the bucket point to them. This adds a level of abstraction, which is why interface maps can be slightly slower than maps with concrete types.\n\n\u003c!-- ### A note on deletion\n\nWhen you delete a key from a map using the `delete` built-in function, Go doesn't physically remove the entry or shift other entries around. Instead, it marks the slot as empty by setting the `tophash` to `emptyOne` (or `emptyRest` if there are no more entries after it).\n\n```go\ndelete(userAges, \"bob\")\n```\n\nLet's trace through what happens:\n\n**Step 1: Find the key**\n\nGo hashes \"bob\" and searches through the appropriate bucket (and any overflow buckets) to find the entry.\n\n**Step 2: Clear the slot**\n\nWhen found, Go clears the tophash entry, marking it as empty. The key and value might still be there in memory, but with the tophash cleared, Go will skip over this slot during lookups.\n\n**Step 3: Update count**\n\nThe map's `count` field is decremented.\n\nThe bucket might look like this after deletion:\n\n\u003cMapBucket \n    bucket=\"0\" \n    tophash=\"ab,00,ef,00,00,00,00,00\"\n    keys=\"alice,,carol,,,,,,\"\n    values=\"25,,28,,,,,,\"\n    deleted=\"bob\"\n    theme=\"red\"\n/\u003e\n\nNotice slot 1 is now empty (tophash = 0x00), but \"alice\" and \"carol\" remain in their original positions.\n\n\u003e!char![beaver-question] Why doesn't Go immediately reclaim the space when deleting keys?\n\nMarking slots as empty is much faster than reorganizing the bucket. Imagine if Go had to shift all subsequent entries down by one position after every deletion, that would be expensive! The space can be reused when new key-value pairs are added later, and the bucket structure remains stable without costly compaction.\n\nIf you delete many keys and the map ends up with lots of empty slots and overflow buckets but few actual entries, Go might trigger a same-size growth to compact the data and reclaim wasted space. --\u003e\n\n## Map Safety and Concurrency\n\nHere's something crucial to understand if you're writing concurrent Go code: **maps are not safe for concurrent access**.\n\nThere are two specific panics in Go runtime:\n\n- When one goroutine tries to read from a map while another goroutine writes, Go will panic with `\"concurrent map read and map write\"`\n- When two or more goroutines try to write to the same map simultaneously, Go will panic with `\"concurrent map writes\"`\n\n```go\n// UNSAFE - Will cause fatal error\nm := make(map[string]int)\n\ngo func() {\n    for i := 0; i \u003c 1000;
3 i++ {\n        m[\"key\"] = i // Write\n    }\n}()\n\ngo func() {\n    for i := 0; i \u003c 1000; i++ {\n        _ = m[\"key\"] // Read\n    }\n}()\n\ngo func() {\n    for i := 1000; i \u003c 2000; i++ {\n        m[\"key\"] = i // Write again\n    }\n}()\n```\n\nThis code will likely crash within the first few iterations.\n\nNotice that concurrent reading only in a map is not a panic-invoking action. However most of the time you will need to use maps for both read and write in different goroutines concurrently.\n\n**Solution**: Use `sync.Map`, mutex protection, or channels to coordinate access!\n\n### How to Make Maps Safe for Concurrent Use\n\nThe most common solution is to protect the map with a `sync.Mutex`:\n\n```go\n// SAFE - Using sync.Mutex\nvar mu sync.Mutex\nm := make(map[string]int)\n\n// Writer goroutine\ngo func() {\n    for i := 0; i \u003c 1000; i++ {\n        mu.Lock()\n        m[\"key\"] = i\n        mu.Unlock()\n    }\n}()\n\n// Reader goroutine\ngo func() {\n    for i := 0; i \u003c 1000; i++ {\n        mu.Lock()\n        _ = m[\"key\"]\n        mu.Unlock()\n    }\n}()\n```\n\nBy holding the lock using `mu.Lock()` before entering the critical sections, we ensure only one goroutine accesses the map at a time.\n\nWe can also use `defer` to automatically release the lock at the return of the goroutine. This is also a well-known pattern in Go:\n\n```go\n// SAFE - Using sync.Mutex with defer\nfunc writer(m map[string]int, mu *sync.Mutex, start, stop int) {\n    mu.Lock()\n    defer mu.Unlock() // This function will be called right before the return\n\n    for i := start; i \u003c stop; i++ {\n        key := fmt.Sprintf(\"key-%d\", i)\n        m[key] = i\n    }\n}\n\nvar mu sync.Mutex\nm := make(map[string]int)\n\n// Writer goroutines\ngo writer(m, \u0026mu, 0, 100)\ngo writer(m, \u0026mu, 100, 200)\ngo writer(m, \u0026mu, 200, 300)\n```\n\nFor read-heavy workloads, you can use `sync.RWMutex` to allow multiple concurrent readers (but still only one writer at a time). For specialized use cases, `sync.Map` provides a concurrent map implementation optimized for specific access patterns.\n\u003c!-- \n\u003e!char![beaver-question] Why didn't Go make maps thread-safe by default?\n\nMaking maps thread-safe would add locking overhead to every single map operation, even in single-threaded code (the vast majority of map usage). This goes against Go's philosophy of \"you don't pay for what you don't use.\" If you need concurrency, you add explicit synchronization, making the cost visible and giving you control over the synchronization strategy (mutex, RWMutex, channels, sync.Map, etc.). --\u003e\n\n\u003c!-- ## Map Iteration Behavior\n\nHere's something that surprises many new Go developers: when you iterate over a map, the order is **intentionally randomized**. Run the same program twice, and you'll get different iteration orders:\n\n```go\nm := map[string]int{\"alice\": 25, \"bob\": 30, \"carol\": 28}\n\n// Iteration order is random and changes between runs!\nfor name, age := range m {\n    fmt.Printf(\"%s is %d years old\\n\", name, age)\n}\n// Output order might be: bob, alice, carol\n// Next run might be: carol, bob, alice  \n// Next run might be: alice, carol, bob\n```\n\nThis isn't a quirk or a bug. Go **deliberately** randomizes the iteration order on every run. Why would Go do this?\n\n\u003e!char![sazak-explain] The Go runtime deliberately randomizes map iteration order by starting from a random bucket and wrapping around. This design choice catches bugs early where code incorrectly assumes a specific iteration order.\n\n### Why Randomize?\n\nThe randomization serves several important purposes:\n\n**1. Prevents brittle code**\n\nIf iteration order were consistent (even if unspecified), developers would inevitably write code that depends on it. Tests would pass, code would ship, and then a future Go version might change the internal implementation, breaking \"working\" code.\n\n**2. Makes bugs surface immediately**\n\nOrder-dependent bugs show up during development, not in production. If your co
3de works one run and fails the next, you know you have a problem with assuming order.\n\n**3. Future-proofs the language**\n\nBy making order explicitly random, Go can change map implementations (like the upcoming swiss tables) without worrying about breaking code that accidentally relied on iteration order.\n\nThe randomization happens by picking a random starting bucket on each iteration, then iterating through buckets in sequence (wrapping around at the end). This means all buckets get visited, just in an unpredictable order.\n\n### Getting Ordered Iteration\n\nIf you need ordered output, sort the keys first:\n\n```go\nkeys := make([]string, 0, len(m))\nfor k := range m {\n    keys = append(keys, k)\n}\nsort.Strings(keys)\n\nfor _, k := range keys {\n    fmt.Printf(\"%s: %d\\n\", k, m[k])\n}\n``` --\u003e\n\n## Comparing Maps and Slices\n\nNow that we've explored both slices and maps in detail, let's compare these two fundamental Go data structures. While they both store collections of data, they're designed for very different use cases.\n\n| Feature | Slices | Maps |\n|---------|--------|------|\n| **Index Type** | Integer only | Any comparable type |\n| **Ordering** | Ordered by index | No guaranteed order |\n| **Growth** | Append to end | Hash-based placement |\n| **Memory Layout** | Contiguous array | Hash table with buckets |\n| **Lookup Time** | O(1) by index | O(1) average by key |\n| **Concurrent Access** | Safe for read-only | Safe for read-only |\n\n### When to use slices\n- You need ordered data with integer indices\n- You're building a list or queue\n- You need to iterate in a specific order\n- Memory locality matters (more cache-friendly)\n\n### When to use maps\n- You need to look up values by non-integer keys\n- Order doesn't matter\n- You need fast membership checks\n- You're building a cache or index\n\n\u003e!char![sazak-explain] Both slices and maps grow dynamically, but maps are more complex internally due to hash collision handling and bucket management. Slices give you predictable iteration order, while maps give you flexible key types.\n\n\u003c!-- ## Exercises\n\nLet's test your understanding with some hands-on exercises:\n\n\u003cgocodequestion difficulty=\"easy\" playlink=\"\" parsetextfrom=\"questions/visual-go-maps/01.md\"\u003e\n    The map starts with 10 key-value pairs. Expression m[\"key5\"] returns 10 (5 * 2). After deletion, the key no longer exists, so the zero value (0) is returned along with fal
3se for the existence check.\n\u003c/gocodequestion\u003e\n\n\u003cgocodequestion difficulty=\"medium\" playlink=\"\" parsetextfrom=\"questions/visual-go-maps/02.md\"\u003e\nMap growth happens internally based on load factor, not at predictable intervals like slice capacity doubling. The hash table likely grows when the average number of items per bucket exceeds 6.5. Unlike slices, maps don't expose their internal bucket count, so we can only observe the number of key-value pairs (len(m)).\u003cbr\u003e\u003cbr\u003eThe output will show increasing length values:\n\u003cul\u003e\n\u003cli\u003eAfter 1 insertions, len=1\u003c/li\u003e\n\u003cli\u003eAfter 6 insertions, len=6\u003c/li\u003e\n\u003cli\u003eAfter 11 insertions, len=11\u003c/li\u003e\n\u003cli\u003eAfter 16 insertions, len=16\u003c/li\u003e\n\u003cli\u003eFinal length: 20\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/gocodequestion\u003e --\u003e\n\n\u003c!-- \u003e!char![sazak-explain] In the next article in the Go Internals series, we'll see how atomics work in the background, including a look at the machine instruction level. Stay tuned! --\u003e\n\n## References\n\n- [Go runtime: `runtime/map.go` (map internals)](https://github.com/golang/go/blob/master/src/runtime/map.go)\n- [Rob Pike - \"Go Maps in Action\" (talk)](https://www.youtube.com/watch?v=Tl7mi9QmLns)\n- [The Go Blog - Maps](https://go.dev/blog/maps)\n- [The Go Blog - Go maps in action](https://go.dev/blog/maps)\n- [Data Race Detector](https://go.dev/doc/articles/race_detector)\n- [sync.Map documentation](https://pkg.go.dev/sync#Map)\n- [The Go Memory Model](https://go.dev/ref/mem)\n- [Issue #63438: Map load factor clarification](https://github.com/golang/go/issues/63438)\n\n[^1]: The actual hash function used by Go is runtime/aeshash for most types, which uses AES instructions when available for security and performance. Different types may use optimized hash functions (e.g., strings have their own specialized hash).\n\n[^2]: The bucket count is always a power of 2, which allows Go to use bitwise operations for bucket selection instead of expensive modulo operations. This is why B represents the power (2^B buckets) rather than the count directly.\n\n[^3]: See [The Go Blog](https://go.dev/blog/comparable) for more information.\n\n[^4]: See [Go runtime source code](https://github.com/golang/go/blob/dd8b7ad9268c2fbde675132a41b4e4da02eef94d/src/runtime/map.go#L189) for more information on how tophash is calculated.\n\n[^5]: https://go.dev/doc/faq#references"])</script>
3<script>self.__next_f.push([1,"28:T1cc1e,"])</script>
3<script>self.__next_f.push([1,"\u003cp\u003eIn the \u003ca href=\"/articles/visual-guide-to-slices-in-go-2024-03-25\" target=\"_blank\"\u003eprevious article\u003c/a\u003e, we explored how slices work under the hood. Today, we\u0026#39;ll dive into another fundamental Go data structure: \u003cstrong\u003emaps\u003c/strong\u003e. We\u0026#39;ll see how Go implements maps as hash tables, how they handle collisions, and how they grow dynamically.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e This will be a two part series. This first part will cover the old \u003ccode\u003emap\u003c/code\u003e implementation which was in use until Go 1.24. The second part will cover the new \u003ccode\u003emap\u003c/code\u003e implementation using swiss tables. \u003c!--Although the current implementation is different than the legacy one, it's still worth learning. At the end of this article, you'll find [exercises](#exercises) to test your understanding.--\u003e\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eThe mini note below covers the basics of hash tables and how they are implemented in simple terms. Feel free to skip it if you already know the basics.\u003c/p\u003e\n\u003cp\u003e\u003ccollapsible-item title=\"What is a hash table?\" kind=\"mini-note\" readingtime=\"3\" parsetextfrom=\"mini-notes/primer-on-hash-tables.md\" parsedcontent=\"\u0026lt;p\u0026gt;Hash tables are one of the most fundamental data structures in Computer Science.\u0026lt;/p\u0026gt;\n\u0026lt;h2 id=\u0026#34;what-problem-do-hash-tables-solve\u0026#34;\u0026gt;What problem do hash tables solve?\u0026lt;/h2\u0026gt;\n\u0026lt;p\u0026gt;Let\u0026#39;s say you\u0026#39;re building a phone book application. You want to look up someone\u0026#39;s phone number by their name. Without a hash table, you might store the data in an array and search through it linearly:\u0026lt;/p\u0026gt;\n\u0026lt;pre data-language=\u0026#34;go\u0026#34; tabindex=\u0026#34;0\u0026#34; style=\u0026#34;color:#f8f8f2;background-color:#282a36;\u0026#34;\u0026gt;\u0026lt;code\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;color:#6272a4\u0026#34;\u0026gt;// O(n) lookup time\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;color:#6272a4\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;for\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;_\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;entry\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;range\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;phoneBook\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;{\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;
3\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;    \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;if\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;entry\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;.\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;Name\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;==\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;Alice\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;{\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;4\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;        \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;return\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;entry\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;.\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;Number\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;5\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;    \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;}\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;6\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;}\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/code\u0026gt;\u0026lt;/pre\u0026gt;\u0026lt;p\u0026gt;This works, but it\u0026#39;s slow. If you have a million entries, you might need to check all million in the worst case.\u0026lt;/p\u0026gt;\n\u0026lt;p\u0026gt;Hash tables solve this by converting keys (like names) into array indices using a \u0026lt;strong\u0026gt;hash function\u0026lt;/strong\u0026gt;, allowing nearly instant lookups.\u0026lt;/p\u0026gt;\n\u0026lt;h2 id=\u0026#34;how-hashing-works\u0026#34;\u0026gt;How hashing works\u0026lt;/h2\u0026gt;\n\u0026lt;p\u0026gt;At its core, a hash table is an array of \u0026lt;strong\u0026gt;buckets\u0026lt;/strong\u0026gt;. Each bucket can hold one or more key-value pairs. When you insert or look up a key, the hash function converts it to an integer:\u0026lt;/p\u0026gt;\n\u0026lt;pre data-language=\u0026#34;go\u0026#34; tabindex=\u0026#34;0\u0026#34; style=\u0026#34;color:#f8f8f2;background-color:#282a36;\u0026#34;
3\u0026gt;\u0026lt;code\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;color:#50fa7b\u0026#34;\u0026gt;hash\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;Alice\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;-\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026amp;gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;14523\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#50fa7b\u0026#34;\u0026gt;hash\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;Ozan\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;  \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;-\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026amp;gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;9217\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#50fa7b\u0026#34;\u0026gt;hash\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;Gokce\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;-\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026amp;gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;100225\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/code\u0026gt;\u0026lt;/pre\u0026gt;\u0026lt;p\u0026gt;The hash value is then mapped to a bucket index using modulo operation:\u0026lt;/p\u0026gt;\n\u0026lt;pre data-language=\u0026#34;go\u0026#34; tabindex=\u0026#34;0\u0026#34; style=\u0026#34;color:#f8f8f2;background-color:#282a36;\u0026#34;\u0026gt;\u0026lt;code\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;
3\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;bucketIndex\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;hash\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;%\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;numberOfBuckets\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/code\u0026gt;\u0026lt;/pre\u0026gt;\u0026lt;blockquote\u0026gt;\n\u0026lt;p\u0026gt;The \u0026lt;code\u0026gt;hash\u0026lt;/code\u0026gt; function here may accept different kinds of types as parameter, such as strings (as shown here), numbers, or even more complex objects. Some programming languages gives the user the ability to implement custom object specific hash functions which would then be used in the \u0026lt;code\u0026gt;hash\u0026lt;/code\u0026gt; function.\u0026lt;/p\u0026gt;\n\u0026lt;/blockquote\u0026gt;\n\u0026lt;p\u0026gt;Hash functions can implement different logics inside. Here is a fairly simple one, calculating the hash of a \u0026lt;code\u0026gt;string\u0026lt;/code\u0026gt; (as an array of \u0026lt;code\u0026gt;byte\u0026lt;/code\u0026gt;s) by summing up the ASCII-equivalent values of each character in it:\u0026lt;/p\u0026gt;\n\u0026lt;pre data-language=\u0026#34;go\u0026#34; tabindex=\u0026#34;0\u0026#34; style=\u0026#34;color:#f8f8f2;background-color:#282a36;\u0026#34;\u0026gt;\u0026lt;code\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;func\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#50fa7b\u0026#34;\u0026gt;hash\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;key\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd\u0026#34;\u0026gt;byte\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;buckets\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd\u0026#34;\u0026gt;int\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd\u0026#34;\u0026gt;int\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;{\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;    \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;
3\u0026#34;\u0026gt;h\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;0\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;4\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;    \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;for\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;i\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;range\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;key\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;{\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;5\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;        \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;h\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;+=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;int\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;key\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;i\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;])\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;6\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;    \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;}\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;
3\u0026gt;7\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;8\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;    \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;return\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;h\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;%\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;buckets\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;9\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;}\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/code\u0026gt;\u0026lt;/pre\u0026gt;\u0026lt;p\u0026gt;For example, the key \u0026amp;quot;Alice\u0026amp;quot; will map to the 222nd bucket:\u0026lt;/p\u0026gt;\n\u0026lt;ul\u0026gt;\n\u0026lt;li\u0026gt;\u0026#39;A\u0026#39; = 65, \u0026#39;l\u0026#39; = 108, \u0026#39;i\u0026#39; = 105, \u0026#39;c\u0026#39; = 99, and \u0026#39;e\u0026#39; = 101 in ASCII table\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;Sum mod 256 (if we had 256 buckets) = 222\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;So, the bucket index is 222\u0026lt;/li\u0026gt;\n\u0026lt;/ul\u0026gt;\n\u0026lt;p\u0026gt;\u0026lt;img src=\u0026#34;/assets/articles/visual-guide-go-map/hash-table-2.png\u0026#34; alt=\u0026#34;\u0026#34; loading=\u0026#34;lazy\u0026#34;\u0026gt;\u0026lt;/p\u0026gt;\n\u0026lt;blockquote\u0026gt;\n\u0026lt;p\u0026gt;Real-world hash functions are much more sophisticated. They need to distribute keys evenly, be fast to compute, and minimize collisions (different keys producing the same hash). Production hash algorithms include MurmurHash, xxHash, etc.\u0026lt;/p\u0026gt;\n\u0026lt;/blockquote\u0026gt;\n\u0026lt;h2 id=\u0026#34;inserting-data\u0026#34;\u0026gt;Inserting data\u0026lt;/h2\u0026gt;\n\u0026lt;p\u0026gt;Let\u0026#39;s say we have a hash table for storing people to their companies. The table already contains Alice, Bob, and Eve\u0026#39;s workplace information.\u0026lt;/p\u0026gt;\n\u0026lt;p\u0026gt;Let\u0026#39;s walk through inserting \u0026amp;quot;John\u0026amp;quot; -\u0026amp;gt; \u0026amp;quot;Amazon\u0026amp;quot; into the table.\u0026lt;/p\u0026gt;\n\u0026lt;ol\u0026gt;\n\u0026lt;li\u0026gt;Apply the hash function to \u0026amp;quot;John\u0026amp;quot; to get the bucket index. Let\u0026#39;s say it\u0026#39;s bucket 2.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;Go to bucket 2 in our bucket array.\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;Place the key-value pair (\u0026amp;quot;John\u0026amp;quot;, \u0026amp;quot;Amazon\u0026amp;quot;) in bucket 2. If the bucket already has entries (a \u0026lt;strong\u0026gt;collision\u0026lt;/strong\u0026gt;), add it to the bucket\u0026#39;s list.\u0026lt;/li\u0026gt;\n\u0026lt;/ol\u0026gt;\n\u0026lt;p\u0026gt;\u0026lt;img src=\u0026#34;/assets/articles/visual-guide-go-map/hash-table-1.png\u0026#34; alt=\u0026#34;\u0026#34; loading=\u0026#34;lazy\u0026#34;
3\u0026gt;\u0026lt;/p\u0026gt;\n\u0026lt;p\u0026gt;With this structure, searching for John\u0026#39;s workplace is pretty fast: hash \u0026amp;quot;John\u0026amp;quot;, go to bucket 2, and retrieve the value.\u0026lt;/p\u0026gt;\n\u0026lt;h3 id=\u0026#34;what-happens-when-multiple-keys-hash-to-the-same-bucket\u0026#34;\u0026gt;What happens when multiple keys hash to the same bucket?\u0026lt;/h3\u0026gt;\n\u0026lt;p\u0026gt;This is called \u0026lt;strong\u0026gt;collision\u0026lt;/strong\u0026gt;. There are different strategies to handle collisions, such as open addressing (find the next available bucket), or Go\u0026#39;s approach of using overflow buckets (in Go versions before 1.24). The implementation details vary, but the concept remains: distribute keys across buckets and handle collisions gracefully.\u0026lt;/p\u0026gt;\n\u0026lt;h2 id=\u0026#34;performance\u0026#34;\u0026gt;Performance\u0026lt;/h2\u0026gt;\n\u0026lt;p\u0026gt;Hash tables give us \u0026lt;strong\u0026gt;O(1) average case\u0026lt;/strong\u0026gt; time complexity for insertions, lookups, and deletions. Compare this to other data structures:\u0026lt;/p\u0026gt;\n\u0026lt;ul\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;strong\u0026gt;Array (unsorted)\u0026lt;/strong\u0026gt;: O(n) for search\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;strong\u0026gt;Binary search tree\u0026lt;/strong\u0026gt;: O(log n) for search\u0026lt;/li\u0026gt;\n\u0026lt;li\u0026gt;\u0026lt;strong\u0026gt;Hash table\u0026lt;/strong\u0026gt;: O(1) average for search\u0026lt;/li\u0026gt;\n\u0026lt;/ul\u0026gt;\n\u0026lt;table\u0026gt;\n\u0026lt;thead\u0026gt;\n\u0026lt;tr\u0026gt;\n\u0026lt;th\u0026gt;Operation\u0026lt;/th\u0026gt;\n\u0026lt;th\u0026gt;Average\u0026lt;/th\u0026gt;\n\u0026lt;th\u0026gt;Worst Case\u0026lt;/th\u0026gt;\n\u0026lt;/tr\u0026gt;\n\u0026lt;/thead\u0026gt;\n\u0026lt;tbody\u0026gt;\n\u0026lt;tr\u0026gt;\n\u0026lt;td\u0026gt;Insert(k, v)\u0026lt;/td\u0026gt;\n\u0026lt;td\u0026gt;O(1)\u0026lt;/td\u0026gt;\n\u0026lt;td\u0026gt;O(n)\u0026lt;/td\u0026gt;\n\u0026lt;/tr\u0026gt;\n\u0026lt;tr\u0026gt;\n\u0026lt;td\u0026gt;Search(k)\u0026lt;/td\u0026gt;\n\u0026lt;td\u0026gt;O(1)\u0026lt;/td\u0026gt;\n\u0026lt;td\u0026gt;O(n)\u0026lt;/td\u0026gt;\n\u0026lt;/tr\u0026gt;\n\u0026lt;tr\u0026gt;\n\u0026lt;td\u0026gt;Delete(k)\u0026lt;/td\u0026gt;\n\u0026lt;td\u0026gt;O(1)\u0026lt;/td\u0026gt;\n\u0026lt;td\u0026gt;O(n)\u0026lt;/td\u0026gt;\n\u0026lt;/tr\u0026gt;\n\u0026lt;/tbody\u0026gt;\n\u0026lt;/table\u0026gt;\n\u0026lt;p\u0026gt;Using hash tables lower the time complexity of key lookup to \u0026lt;code\u0026gt;O(1)\u0026lt;/code\u0026gt; theoretically.\u0026lt;/p\u0026gt;\n\" readingtime=\"180\"\u003e\u003c/collapsible-item\u003e\u003c/p\u003e\n\u003cp\u003eComing back to the main topic, let\u0026#39;s see how maps are implemented in Go.\u003c/p\u003e\n\u003cp\u003eIn Go, before version 1.24, \u003cstrong\u003ea map is a hash table implementation\u003c/strong\u003e that stores key-value pairs. Unlike slices which use integer indices, maps allow you to use any comparable\u003csup id=\"fnref:1\"\u003e\u003ca href=\"#fn:1\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e1\u003c/a\u003e\u003c/sup\u003e type as a key to access values efficiently. A type is comparable if values of that type can be compared with \u003ccode\u003e==\u003c/code\u003e and \u003ccode\u003e!=\u003c/code\u003e operators.\u003c/p\u003e\n\u003cp\u003eHere\u0026#39;s how a map is defined in the \u003ca href=\"https://github.com/golang/go/blob/dd8b7ad9268c2fbde675132a41b4e4da02eef94d/src/runtime/map.go#L109\" target=\"_blank\"\u003eGo runtime\u003c/a\u003e:\u003c/p\u003e\n\u003cpre data-filename=\"go/src/runtime/map.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ehmap\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ecount\u003c/span\u003e\u003cspan style=\"\"\u003e      \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eflags\u003c/span\u003e\u003cspan style=\"\"\u003e      \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eB\u003c/span\u003e\u003cspan style=\"\"\u003e          \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003enoverflow\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint16\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ehash0\u003c/span\u003e\u003cspan style=\"\"\u003e      \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint32\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ebuckets\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eunsafe\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eoldbuckets\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eunsafe\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003enevacuate\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eextra\u003c/span\u003e\u003cspan style=\"\"\u003e      \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003emapextra\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWhen you create a map like \u003ccode\u003em := make(map[string]int)\u003c/code\u003e, Go allocates this \u003ccode\u003ehmap\u003c/code\u003e structure under the hood. The map you\u0026#39;re working with is actually a pointer to this structure, which is why maps behave like reference types in Go\u003csup id=\"fnref:2\"\u003e\u003ca href=\"#fn:2\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e2\u003c/a\u003e\u003c/sup\u003e.\u003c/p\u003e\n\u003cp\u003eThe important fields in this data structure are:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003ecount\u003c/code\u003e: Number of key-value pairs currently stored in the map\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eB\u003c/code\u003e: Number of bucket bits (not the bucket count itself). The actual number of buckets is \u003ccode\u003e2^B\u003c/code\u003e (or \u003ccode\u003e1 \u0026lt;\u0026lt; B\u003c/code\u003e in Go). So if \u003ccode\u003eB\u003c/code\u003e is 3, you have 8 buckets.\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003ebuckets\u003c/code\u003e: Pointer to an array of buckets where key-value pairs are stored\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003ehash0\u003c/code\u003e: A random seed used by the hash function. This seed is generated 
3when the map is created and it makes the hash function non-deterministic.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e The \u003ccode\u003eoldbuckets\u003c/code\u003e and \u003ccode\u003enevacuate\u003c/code\u003e fields are used during map growth, which we\u0026#39;ll explore in detail later.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eLet\u0026#39;s start with a simple map creation:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003euserAges\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;alice\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;bob\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;carol\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e28\u
3003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis creates a map with string keys and integer values. But how does Go organize this data internally?\u003c/p\u003e\n\u003ch2 id=\"buckets\"\u003eBuckets\u003c/h2\u003e\n\u003cp\u003eWhen you work with a map, the Go runtime doesn\u0026#39;t just store your key-value pairs in a simple array. Instead, it uses a \u003cstrong\u003ehash table with buckets\u003c/strong\u003e. Think of buckets as containers that hold multiple key-value pairs, and the hash table is an array of these buckets.\u003c/p\u003e\n\u003cp\u003eThe key idea is, when you insert a key-value pair, Go hashes the key to determine which bucket it belongs to. All keys that hash to the same bucket are stored together. This organization allows for fast lookups. Go can hash your key once and immediately know which bucket to search in, rather than scanning through all the data.\u003c/p\u003e\n\u003cp\u003eAnd here\u0026#39;s how our \u003ccode\u003euserAges\u003c/code\u003e map looks like internally, at a high level:\u003c/p\u003e\n\u003cp\u003e\u003cmapview name=\"userAges map[string]int\" buckets=\"8\" items=\"alice:25,bob:30,carol:28\" theme=\"blue\"\u003e\u003c/mapview\u003e\u003c/p\u003e\n\u003cp\u003eYou can see the map has \u003cstrong\u003e8 buckets\u003c/strong\u003e (numbered 0-7), which means \u003ccode\u003eB = 3\u003c/code\u003e since 2^3 = 8.\u003c/p\u003e\n\u003cp\u003eEach colored cell represents a bucket that contains at least one key-value pair. The three keys we inserted, \u003ccode\u003e\u0026#34;alice\u0026#34;\u003c/code\u003e, \u003ccode\u003e\u0026#34;bob\u0026#34;\u003c/code\u003e, and \u003ccode\u003e\u0026#34;carol\u0026#34;\u003c/code\u003e were hashed and distributed across different buckets in the array. Notice they didn\u0026#39;t all go to the same bucket; the hash function distributed them to help balance the load.\u003c/p\u003e\n\u003cp\u003eThe gray buckets are empty, ready to receive new entries as we add more key-value pairs to the map.\u003c/p\u003e\n\u003cp\u003eGo maps use \u003cstrong\u003eoverflow pointers\u003c/strong\u003e to handle collisions. When a bucket becomes full, instead of reorganizing everything, Go simply allocates a new overflow bucket and links it to the full one, creating a short chain.\u003c/p\u003e\n\u003ch3 id=\"bucket-structure\"\u003eBucket Structure\u003c/h3\u003e\n\u003cp\u003eNow let\u0026#39;s look at what\u0026#39;s inside each bucket. Each bucket in Go can hold up to \u003cstrong\u003e8 key-value pairs\u003c/strong\u003e. You can see that this value is hardcoded in \u003ca href=\"https://github.com/golang/go/blob/dd8b7ad9268c2fbde675132a41b4e4da02eef94d/src/internal/abi/map.go\" target=\"_blank\"\u003eGo source code\u003c/a\u003e:\u003c/p\u003e\n\u003cpre data-filename=\"go/src/internal/abi/map.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003epackage\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eabi\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003econst\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Maximum number of key/elem pairs a bucket can hold.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eMapBucketCountBits\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// log2 of number of elements in a bucket.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eMapBucketCount\u003c/span\u003e\u003cspan style=\"\"\u003e     \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eMapBucketCountBits\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eHere\u0026#39;s the actual bucket structure:\u003c/p\u003e\n\u003cpre data-filename=\"go/sr
3c/runtime/map.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebmap\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003etophash\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003eabi\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMapBucketCount\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe \u003ccode\u003etophash\u003c/code\u003e array is an interesting optimization. It stores the top 8 bits of each key\u0026#39;s hash value. When Go searches for a key in a bucket, it first scans the \u003ccode\u003etophash\u003c/code\u003e array. Only when it finds a matching tophash, the key comparison is done. This mean that Go can quickly skip over slots that definitely don\u0026#39;t contain the key, without having to compare complex key types.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"husky-1-1\" class=\"quote-character\"\u003e\u003cp\u003e The actual keys and values are stored after the \u003ccode\u003etophash\u003c/code\u003e array, but they\u0026#39;re not visible in the struct definition because their types are determined at runtime. Go knows the types of your keys and values at compile time, so it can calculate the correct memory layout dynamically.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eIf you search through the runtime code in Go source code (as I did), you can find the actual creation process of a bucket:\u003c/p\u003e\n\u003cpre data-filename=\"go/src/cmd/compile/internal/reflectdata/reflect.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eMapBucketType\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003etypes\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eType\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003etypes\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eType\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Builds a type representing a Bucket structure for\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// the given map type. This type is not visible to users -\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// we include only enough information to generate a correct GC\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// program for it.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Make sure this stays in sync with runtime/map.go.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e//\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e//\tA \u0026#34;bucket\u0026#34; is a \u0026#34;struct\u0026#34; {\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e//\t      tophash [abi.MapBucketCount]uint8\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e//\t      keys [abi.MapBucketCount]keyType\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e//\t      elems [abi.MapBucketCount]elemType\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e//\t      overflow *bucket\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e//\t    }\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eLet\u0026#39;s see how our example map looks with bucket details:\u003c/p\u003e\n\u003cp\u003e\u003cmapbucket bucket=\"0\" tophash=\"ab,cd,ef,00,00,00,00,00\" keys=\"alice,bob,carol,,,,,,\" values=\"25,30,28,,,,,,\" theme=\"blue\"\u003e\u003c/mapbucket\u003e\u003c/p\u003e\n\u003cp\u003eHere, you\u0026#39;re looking at bucket 0 of our \u003ccode\u003euserAges\u003c/code\u003e map. Let\u0026#39;s break down what each part means:\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eThe tophash array:\u003c/strong\u003e \u003ccode\u003e[ab, cd, ef, 00, 00, 00, 00, 00]\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eThe first three slots contain tophash values (\u003ccode\u003e0xAB\u003c/code\u003e, \u003ccode\u003e0xCD\u003c/code\u003e, \u003ccode\u003e0xEF\u003c/code\u003e). These are the top 8 bits from hashing \u0026#34;alice\u0026#34;, \u0026#34;bob\u0026#34;, and \u0026#34;carol\u0026#34; respectively. The remaining five slots show \u003ccode\u003e0x00\u003c/code\u003e, indicating they\u0026#39;re empty and available for new entries.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eThe keys array:\u003c/strong\u003e \u003ccode\u003e[alice, bob, carol, _, _, _, _, _]\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eThe first three positions hold our actual keys. The empty positions (shown with commas or underscores) are unused slots waiting for new key-value pairs.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eThe values array:\u003c/strong\u003e \u003ccode\u003e[25, 30, 28, _, _, _, _, _]\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eThe values are stored in the same order as their corresponding keys. Alice\u0026#39;s age (25) is at index 0, Bob\u0026#39;s (30) at index 1, and Carol\u0026#39;s (28) at index 2.\u003c/p\u003e\n\u003ch2 id=\"hash-function-and-key-distribution\"\u003eHash Function and Key Distribution\u003c/h2\u003e\n\u003cp\u003eWhen you insert a key-value pair into a map, Go needs to decide which bucket to place it in. This is where the hash function comes in to play.\u003c/p\u003e\n\u003cp\u003eLet\u0026#39;s say we\u0026#39;re inserting \u003ccode\u003e\u0026#34;gokce\u0026#34;: 25\u003c/code\u003e into our map. Here\u0026#39;s what Go does step by step.\u003c/p\u003e\n\u003cp\u003eFirst, Go applies a hash function\u003csup id=\"fnref:3\"\u003e\u003ca href=\"#fn:3\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e3\u003c/a\u003e\u003c/sup\u003e to the key along with the map\u0026#39;s random seed (\u003ccode\u003ehash0\u003c/code\u003e):\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehash\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ehashFunction\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;gokce\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ehash0\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Let\u0026#39;s say this produces: 0xAB7F3C2E4D1A6B8F (64-bit hash)\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eGo then uses the \u003cstrong\u003elower B bits\u003c/strong\u003e of the hash to select which bucket to use. If our map has \u003ccode\u003eB = 3\u003c/code\u003e (meaning 8 buckets), Go takes the lowest 3 bits:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ebucketIndex\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ehash\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e((\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eB\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Bitwise AND with mask\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// If hash ends in ...110 (binary), bucketIndex = 6\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis logic is defined in the \u003ccode\u003ebucketMask\u003c/code\u003e function in Go source code:\u003c/p\u003e\n\u003cpre data-filename=\"go/src/runtime/map.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// bucketShift returns 1\u0026lt;\u0026lt;b, optimized for code generation.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ebucketShift\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eb\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Masking the shift amount allows overflow checks to be elided.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eb\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003egoarch\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePtrSize\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// bucketMask returns 1\u0026lt;\u0026lt;b - 1, optimized for code generation.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ebucketMask\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eb\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint8\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euintptr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ebucketShift\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eb\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis is much faster than using the modulo operator (\u003ccode\u003e%\u003c/code\u003e). Since the bucket count is always a power of 2, we can use a bitwise AND instead.\u003c/p\u003e\n\u003cp\u003eAfter that, Go takes the \u
3003cstrong\u003etop 8 bits\u003c/strong\u003e of the hash and stores them in the bucket\u0026#39;s \u003ccode\u003etophash\u003c/code\u003e array and finds an empty slot in the selected bucket and stores the tophash, key, and value there.\u003c/p\u003e\n\u003cp\u003eLet\u0026#39;s see how different keys get distributed across buckets:\u003c/p\u003e\n\u003cp\u003e\u003cmapview name=\"Distribution Example\" buckets=\"8\" items=\"alice:25,bob:30,carol:28,dave:35,eve:22\" theme=\"green\" showhashdist=\"1\"\u003e\u003c/mapview\u003e\u003c/p\u003e\n\u003ch2 id=\"handling-collisions\"\u003eHandling Collisions\u003c/h2\u003e\n\u003cp\u003eSo what happens when multiple keys hash to the same bucket? This is called a \u003cstrong\u003ecollision\u003c/strong\u003e, and it\u0026#39;s inevitable in hash tables. The hash function tries to distribute keys evenly, but with a limited number of buckets some will inevitably end up with more entries than others.\u003c/p\u003e\n\u003cp\u003eLet\u0026#39;s say we have bucket 0 with three entries: \u003ccode\u003e\u0026#34;alice\u0026#34;\u003c/code\u003e, \u003ccode\u003e\u0026#34;bob\u0026#34;\u003c/code\u003e, and \u003ccode\u003e\u0026#34;carol\u0026#34;\u003c/code\u003e. Now we keep adding more keys that also hash to bucket 0 (oops!)\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003euserAges\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;dave\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e35\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Hashes to bucket 0, slot 3\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003euserAges\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;eve\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e     \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Hashes to bucket 0, slot 4\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003euserAges\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;frank\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Hashes to bucket 0, slot 5\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003euserAges\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;grace\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Hashes to bucket 0, slot 6\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003euserAges\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;henry\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Hashes to bucket 0, slot 7\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eAt this point, bucket 0 has all 8 slots filled. What happens when we try to add one more key that hashes to the same bucket?\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003euserAges\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;ivan\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Also hashes to bucket 0... but it\u0026#39;s full!\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eGo doesn\u0026#39;t reorganize the entire map at this point. Instead, it allocates an \u003cstrong\u003eoverflow bucket\u003c/strong\u003e and links it to the original bucket. The overflow bucket is just another \u003ccode\u003ebmap\u003c/code\u003e structure -with the actual key and value arrays defined dynamically in runtime- and the original bucket\u0026#39;s \u003ccode\u003eoverflow\u003c/code\u003e pointer now points to it.\u003c/p\u003e\n\u003cp\u003eHere\u0026#39;s how overflow buckets work:\u003c/p\u003e\n\u003cp\u003e\u003cmapbucket bucket=\"0\" tophash=\"ab,cd,ef,12,34,56,78,9a\" keys=\"alice,bob,carol,dave,eve,frank,grace,henry\" values=\"25,30,28,35,22,32,29,31\" overflow=\"true\" theme=\"yellow\"\u003e\u003c/mapbucket\u003e\u003c/p\u003e\n\u003cp\u003eThe overflow bucket is linked to the main bucket, creating a short chain. When Go looks up a key in bucket \u003ccode\u003e0\u003c/code\u003e, it first checks the main bucket, and if the key isn\u0026#39;t found there, it follows the overflow pointer to check the overflow bucket.\u003c/p\u003e\n\u003cp\u003eThis chaining approach is simple and efficient for small numbers of overflows. However, if you have many overflow buckets, lookups become slower (you have to scan multiple buckets). That\u0026#39;s why Go monitors overflow bucket usage and triggers map growth when there are too many of them.\u003c/p\u003e\n\u003cp\u003e\u003cnewslettercard\u003e\u003c/newslettercard\u003e\u003c/p\u003e\n\u003ch2 id=\"looking-up-values\"\u003eLooking Up Values\u003c/h2\u003e\n\u003cp\u003eWhen you access a value with \u003ccode\u003evalue := userAges[\u0026#34;alice\u0026#34;]\u003c/code\u003e, it might look like a simple operation, but there\u0026#39;s quite a bit happening under the hood. Let\u0026#39;s take a look at what happens when a map value is accessed by a key.\u003c/p\u003e\n\u003cp\u003e\u003cmapbucket bucket=\"0\" tophash=\"ab,cd,ef,00,00,00,00,00\" keys=\"alice,bob,carol,,,,,,\" values=\"25,30,28,,,,,,\" highlight=\"alice\" theme=\"blue\"\u003e\u003c/mapbucket\u003e\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eGo computes the hash of \u003ccode\u003e\u0026#34;alice\u0026#34;
3\u003c/code\u003e using the map\u0026#39;s hash function and seed:\u003c/li\u003e\n\u003c/ol\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehash\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ehashFunction\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;alice\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ehash0\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// e.g., 0xAB7F3C2E4D1A6B8F\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003col start=\"2\"\u003e\n\u003cli\u003eUsing the lower \u003ccode\u003eB\u003c/code\u003e bits of the hash, Go calculates which bucket to search the key inside:\u003c/li\u003e\n\u003c/ol\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ebucketIndex\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ehash\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e((\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eB\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// e.g., bucket 6\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003etophash\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ehash\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026gt;\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e64\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e           \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// e.g., 0xAB\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003col start=\"3\"\u003e\n\u003cli\u003eNow Go walks through the bucket\u0026#39;s \u003ccode\u003etophash\u003c/code\u003e array looking for a match. Let\u0026#39;s say bucket 6 looks like this:\u003c/li\u003e\n\u003c/ol\u003e\n\u003cpre\u003e\u003ccode\u003etophash: [0xAB, 0xCD, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00]\nkeys:    [\u0026#34;alice\u0026#34;, \u0026#34;bob\u0026#34;, \u0026#34;carol\u0026#34;, ...]\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eGo scans the tophash array, sees that the value at index 0 matches the tophash value of the key, and now it knows exactly where to look at. After retrieving the value at the same index in the values section of the bucket and returns it.\u003c/p\u003e\n\u003cp\u003eIf Go scans all tophash entries (including any overflow bu
3ckets) without finding a match, it returns the \u003cstrong\u003ezero value\u003c/strong\u003e of the map\u0026#39;s value type.\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003evalue\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eok\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003euserAges\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;alice\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eok\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;Alice is %d years old\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003evalue\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eelse\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// value is 0 (zero value for int)\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;Alice not found, got zero value: %d\\n\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003evalue\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWhen accessing a non-existent key, Go returns the \u003cstrong\u003ezero value\u003c/strong\u003e of the map\u0026#39;s value type (\u003ccode\u003e0\u003c/code\u003e for numbers, \u003ccode\u003e\u0026#34;\u0026#34;\u003c/code\u003e for strings, \u003ccode\u003enil\u003c/code\u003e for pointers, etc.). The two-value form (\u003ccode\u003evalue, ok\u003c/code\u003e) lets you distinguish between a key that exists with a zero value and a key that doesn\u0026#39;t exist at all.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e A return of \u003ccode\u003e(\u0026#34;\u0026#34;, true)\u003c/code\u003e and \u003ccode\u003e(\u0026#34;\u0026#34;, false)\u003c/code\u003e are not the same. The first one means that there was actually an entry in the map with the specified key, which value is an empty string. The second one means that there were no value associated with that key.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eThis is why checking \u003ccode\u003eif m[\u0026#34;key\u0026#34;] != 0\u003c/code\u003e can be ambiguous, the key might not exist, or it might exist with a zero value. Always use the two-value form when you need to distinguish these cases.\u003c/p\u003e\n\u003ch2 id=\"map-growth\"\u003eMap Growth\u003c/h2\u003e\n\u003cp\u003eAs you add more key-value pairs to a map, performance would degrade if Go kept using the same number of buckets. With more entries squeezed into the same buckets, lookups would require scanning longer bucket chains, making operations slower.\u003c/p\u003e\n\u003cp\u003eThat\u0026#39;s why maps grow dynamically. Go monitors the map\u0026#39;s health and triggers growth when performance would suffer.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"husky-1\" class=\"quote-character\"\u003e\u003cp\u003e Go runtime decides on whether to grow the map or not is based on \u003cstrong\u003eload factor\u003c/strong\u003e, which is the average number of key-value pairs per bucket.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eA map grows when either of these conditions is met:\u003c/p\u003e\n\u003ch3 id=\"condition-1-high-load-factor\"\u003eCondition 1: High load factor\u003c/h3\u003e\n\u003cp\u003eThe average number of key-value pairs per bucket exceeds \u003cstrong\u003e6.5\u003c/strong\u003e (load factor threshold). This is calculated as:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eloadFactor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ecount\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e/\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eB\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// count / numberOfBuckets\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eloadFactor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e6.5\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Trigger growth\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWhy 6.5? That number comes from 80% threshold, as it\u0026#39;s defined in Go runtime source code. It\u0026#39;s a balance between memory usage and performance, a sweet spot where you don\u0026#39;t waste too much memory but also don\u0026#39;
3t have too many overflow buckets yet.\u003c/p\u003e\n\u003cp\u003eLet\u0026#39;s see an example. Say we have a map with 4 buckets that has accumulated 28 entries:\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eBefore Growth (load factor = 7.0):\u003c/strong\u003e\u003cbr/\u003e\n\u003cmapview name=\"High Load Factor Map\" buckets=\"4\" items=\"gokce:25,ozan:26,carol:28,dave:35,alp:26,frank:32,grace:29,henry:31,baris:18,jack:33,akin:26,leo:26,mary:31,nick:29,olivia:23,paul:36,sulo:31,rachel:30,sam:28,tina:32,james:18,victor:27,wendy:31,bob:30,alice:25,zack:33,yigit:25,ben:30\" theme=\"yellow\" loadfactor=\"7\"\u003e\u003c/mapview\u003e\u003c/p\u003e\n\u003cp\u003eThe load factor is 28 / 4 = 7.0, which exceeds the 6.5 threshold. Many buckets are overflowing, creating long chains that slow down lookups.\u003c/p\u003e\n\u003cp\u003eIn this case, the runtime performs a \u003cstrong\u003eregular growth\u003c/strong\u003e by doubling the bucket count. Here\u0026#39;s what happens:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cp\u003eGo increments \u003ccode\u003eB\u003c/code\u003e by 1\u003csup id=\"fnref:4\"\u003e\u003ca href=\"#fn:4\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e4\u003c/a\u003e\u003c/sup\u003e, which doubles the bucket count. If you had 4 buckets (\u003ccode\u003eB == 2\u003c/code\u003e), you now have 8 buckets (\u003ccode\u003eB == 3\u003c/code\u003e). The new bucket array is allocated, but the old buckets remain in place.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eThe \u003ccode\u003ehmap.buckets\u003c/code\u003e pointer is updated to point to the new bucket array, and \u003ccode\u003ehmap.oldbuckets\u003c/code\u003e is set to point to the old buckets. The map is now in a \u003cstrong\u003egrowing\u003c/strong\u003e state.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eRuntime starts an \u003cstrong\u003eincremental evacuation\u003c/strong\u003e process, where it doesn\u0026#39;t move all key-value pairs immediately. Instead, it evacuates entries gradually during normal map operations. We\u0026#39;ll discuss this in detail in the next section.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003e\u003cstrong\u003eAfter Growth (load factor = 3.5):\u003c/strong\u003e\u003cbr/\u003e\n\u003cmapview name=\"After Regular Growth\" buckets=\"8\" items=\"gokce:25,ozan:26,carol:28,dave:35,alp:26,frank:32,grace:29,henry:31,baris:18,jack:33,akin:26,leo:26,mary:31,nick:29,olivia:23,paul:36,sulo:31,rachel:30,sam:28,tina:32,james:18,victor:27,wendy:31,bob:30,alice:25,zack:33,yigit:25,ben:30\" theme=\"green\" loadfactor=\"3.5\"\u003e\u003c/mapview\u003e\u003c/p\u003e\n\u003cp\u003eNow with 8 buckets, the load factor drops to 28 / 8 = 3.5, which is well below the threshold. The entries are redistributed more evenly, and overflow chains are reduced or eliminated.\u003c/p\u003e\n\u003ch3 id=\"condition-2-too-many-overflow-buckets\"\u003eCondition 2: Too many overflow buckets\u003c/h3\u003e\n\u003cp\u003eEven with a low load factor, if there are too many overflow buckets relative to the base bucket count, Go triggers a different type of growth. This happens when keys cluster unevenly, some buckets overflow while others stay mostly empty.\u003c/p\u003e\n\u003cp\u003eIn this case, Go performs a \u003cstrong\u003esame-size growth\u003c/strong\u003e which reorganizes the data without adding more buckets. Runtime allocates a new bucket array with the same size as the current one (\u003ccode\u003eB\u003c/code\u003e stays the same). As entries are evacuated from old buckets to new ones, overflow chains are broken up. Keys that previously shared a bucket with many others might now be distributed more evenly, reducing overflow buckets. This process eliminates overflow buckets that accumulated over time due to deletions or poor initial distribution, making the map more cache-friendly.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"beaver-question\" class=\"quote-character\"\u003e\u003cp\u003e Why would a map grow without increasing bucket count?\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eWhen keys cluster in specific buckets due to hash patterns, you might have many overflow bu
3ckets even with a low overall load factor. For example, you might have a map with 100 entries across 16 buckets (load factor = 6.25, below the threshold), but if 80 entries landed in just 2 buckets, you\u0026#39;d have many overflow buckets. Same size growth reorganizes the data to improve performance without allocating more buckets.\u003c/p\u003e\n\u003cp\u003eHere\u0026#39;s how this logic is implemented in \u003ca href=\"https://github.com/golang/go/blob/dd8b7ad9268c2fbde675132a41b4e4da02eef94d/src/runtime/map.go#L220\" target=\"_blank\"\u003eGo source code\u003c/a\u003e:\u003c/p\u003e\n\u003cpre data-filename=\"go/src/runtime/map.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// incrnoverflow increments h.noverflow.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// noverflow counts the number of overflow buckets.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// This is used to trigger same-size map growth.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// See also tooManyOverflowBuckets.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// To keep hmap small, noverflow is a uint16.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// When there are few buckets, noverflow is an exact count.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// When there are many buckets, noverflow is an approximate count.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eh\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003ehmap\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eincrnoverflow\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003ch3 id=\"incremental-evacuation\"\u003eIncremental Evacuation\u003c/h3\u003e\n\u003cp\u003eHere\u0026#39;s one of the cool aspects of Go\u0026#39;s map implementation: \u003cstrong\u003eincremental evacuation\u003c/strong\u003e. Instead of moving all entries at once when the map grows (which could freeze your program for milliseconds on a large map), Go runtime spreads the work across many operations.\u003c/p\u003e\n\u003cp\u003eHere\u0026#39;s how it works:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eDuring growth, both old and new buckets exist and their references are held in \u003ccode\u003ehmap\u003c/code\u003e in the \u003ccode\u003eoldbuckets\u003c/code\u003e and \u003ccode\u003ebuckets\u003c/code\u003e fields. When you perform any operation on the map, Go checks if the map is growing:\u003c/li\u003e\n\u003c/ol\u003e\n\u003cpre data-filename=\"go/sr
3c/runtime/map.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eh\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003egrowing\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003egrowWork\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eh\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebucket\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Evacuate some pairs\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003col start=\"2\"\u003e\n\u003cli\u003e\n\u003cp\u003eWhenever a value is inserted to, deleted from, or looked up in the map, Go evacuates at least one bucket (and possibly more) from the old array to the new array. The \u003ccode\u003enevacuate\u003c/code\u003e field in the \u003ccode\u003ehmap\u003c/code\u003e structure tracks which old buckets have been evacuated.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eDuring the growth period, when you look up a key, Go might need to check the old buckets if that bucket hasn\u0026#39;t been evacuated yet. The evacuation state markers in the \u003ccode\u003etophash\u003c/code\u003e array (we\u0026#39;ll see these shortly) tell Go whether to look in the old or new buckets.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eAn example code snippet from the Go source code, shows how the runtime handles an edge case of iterating through key/value pairs in the map during a grow:\u003c/p\u003e\n\u003cpre data-filename=\"go/src/runtime/map.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003echeckBucket\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enoCheck\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e!\u003c/span\u003e\u003cspan style=\"\"\u003eh\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003esameSizeGrow\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Special case: iterator was started during a grow to a larger size\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// and the grow is not done yet. We\u0026#39;re working on a bucket whose\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// oldbucket has not been evacuated yet. Or at least, it wasn\u0026#39;t\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// evacuated when we started the bucket. So we\u0026#39;re iterating\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// through the oldbucket, skipping any keys that will go\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// to the other new bucket (each oldbucket exp
3ands to two\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// buckets during a grow).\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003col start=\"4\"\u003e\n\u003cli\u003eWhen doubling the bucket count (regular growth), each old bucket\u0026#39;s entries are split between two new buckets:\u003c/li\u003e\n\u003c/ol\u003e\n\u003cul\u003e\n\u003cli\u003eKeys that hash to the old bucket index still hash there\u003c/li\u003e\n\u003cli\u003eKeys that need the newly available high bit go to \u003ccode\u003eoldBucketIndex + oldBucketCount\u003c/code\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eThis incremental approach prevents \u0026#34;stop-the-world\u0026#34; pauses. Even with millions of entries, each individual operation only pays a small, bounded cost for evacuation. The map remains responsive throughout the growth process.\u003c/p\u003e\n\u003c!-- ## Special Cases and Optimizations\n\n### A note on special tophash values\n\nThe `tophash` array is doing double duty. Not only does it store the top 8 bits of hash values for quick comparisons, but it also uses special marker values to track the state of each slot in the bucket. These markers are crucial for map operations, especially during growth.\n\nThe special values (0-4) are:\n\n- **`emptyRest` (0)**: This cell is empty, and there are no more non-empty cells at higher indexes or overflows. This is an optimization, when Go sees this marker, it knows it can stop scanning the bucket immediately.\n- **`emptyOne` (1)**: This cell is empty, but there might be more entries after it. Go has to keep scanning.\n- **`evacuatedX` (2)**: During growth, this key/value has been evacuated to the first half of the larger table (same bucket index).\n- **`evacuatedY` (3)**: During growth, this key/value has been evacuated to the second half of the larger table (old bucket index + old bucket count).\n- **`evacuatedEmpty` (4)**: This cell was empty when the bucket was evacuated.\n- **`minTopHash` (5)**: Minimum value for a normal filled cell.\n\nNormal tophash values always start at 5 or higher. But what if the top 8 bits of your key's hash are actually 0, 1, 2, 3, or 4?\n\n\u003e If the top 8 bits of a hash compute to less than 5, Go adds `minTopHash` (5) to ensure it doesn't conflict with special markers. For example, if the top 8 bits are `0x03`, Go stores `0x08` instead. During lookup, Go knows to check both the exact tophash and the adjusted value. This clever design allows the tophash array to serve dual purposes: tracking cell states and storing hash bits for quick comparison.\n\nThese markers are why Go can efficie
3ntly handle map growth, deletions, and lookups even when the map is in a transitional state. --\u003e\n\u003ch2 id=\"a-note-on-interface-maps\"\u003eA Note on interface Maps\u003c/h2\u003e\n\u003cp\u003eMaps with \u003ccode\u003einterface{}\u003c/code\u003e (or \u003ccode\u003eany\u003c/code\u003e) values are interesting because Go doesn\u0026#39;t know the size of the values at compile time. An \u003ccode\u003einterface{}\u003c/code\u003e can hold anything: an \u003ccode\u003eint\u003c/code\u003e (which might be 8 bytes), a \u003ccode\u003estring\u003c/code\u003e (which is 16 bytes: pointer + length), or a complex struct.\u003c/p\u003e\n\u003cp\u003eLet\u0026#39;s see an example:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003einterface\u003c/span\u003e\u003cspan style=\"\"\u003e{})\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;number\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e42\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;text\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;hello\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;slice\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eHow does Go handle this? The values stored in the bucket aren\u0026#39;t the actual data, they\u0026#39;re \u003cstrong\u003einterface values\u003c/strong\u003e, which are represented with two pointers in runtime: one for the type, and one for the value. This means Go can still calculate a fixed bucket layout even though the concrete types can change.\u003c/p\u003e\n\u003cp\u003e\u003cmapview name=\"data map[string]interface{}\" buckets=\"4\" items=\"number:42,text:hello,slice:[1 2 3]\" theme=\"purple\" valuetype=\"interface{}\"\u003e\u003c/mapview\u003e\u003c/p\u003e\n\u003cp\u003eThe actual data (\u003ccode\u003e42\u003c/code\u003e, \u003ccode\u003e\u0026#34;hello\u0026#34;
3\u003c/code\u003e, and the \u003ccode\u003e[]int{1, 2, 3}\u003c/code\u003e slice) is stored elsewhere in memory, and the interface values in the bucket point to them. This adds a level of abstraction, which is why interface maps can be slightly slower than maps with concrete types.\u003c/p\u003e\n\u003c!-- ### A note on deletion\n\nWhen you delete a key from a map using the `delete` built-in function, Go doesn't physically remove the entry or shift other entries around. Instead, it marks the slot as empty by setting the `tophash` to `emptyOne` (or `emptyRest` if there are no more entries after it).\n\n```go\ndelete(userAges, \"bob\")\n```\n\nLet's trace through what happens:\n\n**Step 1: Find the key**\n\nGo hashes \"bob\" and searches through the appropriate bucket (and any overflow buckets) to find the entry.\n\n**Step 2: Clear the slot**\n\nWhen found, Go clears the tophash entry, marking it as empty. The key and value might still be there in memory, but with the tophash cleared, Go will skip over this slot during lookups.\n\n**Step 3: Update count**\n\nThe map's `count` field is decremented.\n\nThe bucket might look like this after deletion:\n\n\u003cMapBucket \n    bucket=\"0\" \n    tophash=\"ab,00,ef,00,00,00,00,00\"\n    keys=\"alice,,carol,,,,,,\"\n    values=\"25,,28,,,,,,\"\n    deleted=\"bob\"\n    theme=\"red\"\n/\u003e\n\nNotice slot 1 is now empty (tophash = 0x00), but \"alice\" and \"carol\" remain in their original positions.\n\n\u003e Why doesn't Go immediately reclaim the space when deleting keys?\n\nMarking slots as empty is much faster than reorganizing the bucket. Imagine if Go had to shift all subsequent entries down by one position after every deletion, that would be expensive! The space can be reused when new key-value pairs are added later, and the bucket structure remains stable without costly compaction.\n\nIf you delete many keys and the map ends up with lots of empty slots and overflow buckets but few actual entries, Go might trigger a same-size growth to compact the data and reclaim wasted space. --\u003e\n\u003ch2 id=\"map-safety-and-concurrency\"\u003eMap Safety and Concurrency\u003c/h2\u003e\n\u003cp\u003eHere\u0026#39;s something crucial to understand if you\u0026#39;re writing concurrent Go code: \u003cstrong\u003emaps are not safe for concurrent access\u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003eThere are two specific panics in Go runtime:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eWhen one goroutine tries to read from a map while another goroutine writes, Go will panic with \u003ccode\u003e\u0026#34;concurrent map read and map write\u0026#34;\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eWhen two or more goroutines try to write to the same map simultaneously, Go will panic with \u003ccode\u003e\u0026#34;concurrent map writes\u0026#34;\u003c/code\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// UNSAFE - Will cause fatal error\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1000\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e++\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;key\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Write\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1000\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e++\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e_\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;key\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Read\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1000\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2000\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e++\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;key\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Write again\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis code will likely crash within the first few iterations.\u003c/p\u003e\n\u003cp\u003eNotice that concurrent reading only in a map is not a panic-invoking action. However most of the time you will need to use maps for both read and write in different goroutines concurrently.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eSolution\u003c/strong\u003e: Use \u003ccode\u003esync.Map\u003c/code\u003e, mutex protection, or channels to coordinate access!\u003c/p\u003e\n\u003ch3 id=\"how-to-make-maps-safe-for-concurrent-use\"\u003eHow to Make Maps Safe for Concurrent Use\u003c/h3\u003e\n\u003cp\u003eThe most common solution is to protect the map with a \u003ccode\u003esync.Mutex\u003c/code\u003e:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// SAFE - Using sync.Mutex\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esync\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMutex\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Writer goroutine\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1000\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e++\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eLock\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;key\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eUnlock\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Reader goroutine\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1000\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e++\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eLock\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e_\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;key\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eUnlock\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eBy holding the lock using \u003ccode\u003emu.Lock()\u003c/code\u003e before entering the critical sections, we ensure only one goroutine accesses the map at a time.\u003c/p\u003e\n\u003cp\u003eWe can also use \u003ccode\u003edefer\u003c/code\u003e to automatically release the lock at the return of the goroutine. This is also a well-known pattern in Go:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// SAFE - Using sync.Mutex with defer\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ewriter\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003esync\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMutex\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003estart\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003estop\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eLock\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eUnlock\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// This function will be called right before the return\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003estart\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003estop\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e++\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;key-%d\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esync\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMutex\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Writer goroutines\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ewriter\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ewriter\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e200\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ewriter\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003emu\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e200\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e300\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eFor read-heavy workloads, you can use \u003ccode\u003esync.RWMutex\u003c/code\u003e to allow multiple concurrent readers (but still only one writer at a time). For specialized use cases, \u003ccode\u003esync.Map\u003c/code\u003e provides a concurrent map implementation optimized for specific access patterns.\u003c/p\u003e\n\u003c!-- \n\u003e Why didn't Go make maps thread-safe by default?\n\nMaking maps thread-safe would add locking overhead to every single map operation, even in single-threaded code (the vast majority of map usage). This goes against Go's philosophy of \"you don't pay for what you don't use.\" If you need concurrency, you add explicit synchronization, making the cost visible and giving you control over the synchronization strategy (mutex, RWMutex, channels, sync.Map, etc.). --\u003e\n\u003c!-- ## Map Iteration Behavior\
3n\nHere's something that surprises many new Go developers: when you iterate over a map, the order is **intentionally randomized**. Run the same program twice, and you'll get different iteration orders:\n\n```go\nm := map[string]int{\"alice\": 25, \"bob\": 30, \"carol\": 28}\n\n// Iteration order is random and changes between runs!\nfor name, age := range m {\n    fmt.Printf(\"%s is %d years old\\n\", name, age)\n}\n// Output order might be: bob, alice, carol\n// Next run might be: carol, bob, alice  \n// Next run might be: alice, carol, bob\n```\n\nThis isn't a quirk or a bug. Go **deliberately** randomizes the iteration order on every run. Why would Go do this?\n\n\u003e The Go runtime deliberately randomizes map iteration order by starting from a random bucket and wrapping around. This design choice catches bugs early where code incorrectly assumes a specific iteration order.\n\n### Why Randomize?\n\nThe randomization serves several important purposes:\n\n**1. Prevents brittle code**\n\nIf iteration order were consistent (even if unspecified), developers would inevitably write code that depends on it. Tests would pass, code would ship, and then a future Go version might change the internal implementation, breaking \"working\" code.\n\n**2. Makes bugs surface immediately**\n\nOrder-dependent bugs show up during development, not in production. If your co
3de works one run and fails the next, you know you have a problem with assuming order.\n\n**3. Future-proofs the language**\n\nBy making order explicitly random, Go can change map implementations (like the upcoming swiss tables) without worrying about breaking code that accidentally relied on iteration order.\n\nThe randomization happens by picking a random starting bucket on each iteration, then iterating through buckets in sequence (wrapping around at the end). This means all buckets get visited, just in an unpredictable order.\n\n### Getting Ordered Iteration\n\nIf you need ordered output, sort the keys first:\n\n```go\nkeys := make([]string, 0, len(m))\nfor k := range m {\n    keys = append(keys, k)\n}\nsort.Strings(keys)\n\nfor _, k := range keys {\n    fmt.Printf(\"%s: %d\\n\", k, m[k])\n}\n``` --\u003e\n\u003ch2 id=\"comparing-maps-and-slices\"\u003eComparing Maps and Slices\u003c/h2\u003e\n\u003cp\u003eNow that we\u0026#39;ve explored both slices and maps in detail, let\u0026#39;s compare these two fundamental Go data structures. While they both store collections of data, they\u0026#39;re designed for very different use cases.\u003c/p\u003e\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eFeature\u003c/th\u003e\n\u003cth\u003eSlices\u003c/th\u003e\n\u003cth\u003eMaps\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cstrong\u003eIndex Type\u003c/strong\u003e\u003c/td\u003e\n\u003ctd\u003eInteger only\u003c/td\u003e\n\u003ctd\u003eAny comparable type\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cstrong\u003eOrdering\u003c/strong\u003e\u003c/td\u003e\n\u003ctd\u003eOrdered by index\u003c/td\u003e\n\u003ctd\u003eNo guaranteed order\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cstrong\u003eGrowth\u003c/strong\u003e\u003c/td\u003e\n\u003ctd\u003eAppend to end\u003c/td\u003e\n\u003ctd\u003eHash-based placement\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cstrong\u003eMemory Layout\u003c/strong\u003e\u003c/td\u003e\n\u003ctd\u003eContiguous array\u003c/td\u003e\n\u003ctd\u003eHash table with buckets\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cstrong\u003eLookup Time\u003c/strong\u003e\u003c/td\u003e\n\u003ctd\u003eO(1) by index\u003c/td\u003e\n\u003ctd\u003eO(1) average by key\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cstrong\u003eConcurrent Access\u003c/strong\u003e\u003c/td\u003e\n\u003ctd\u003eSafe for read-only\u003c/td\u003e\n\u003ctd\u003eSafe for read-only\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003ch3 id=\"when-to-use-slices\"\u003eWhen to use slices\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003eYou need ordered data with integer indices\u003c/li\u003e\n\u003cli\u003eYou\u0026#39;re building a list or queue\u003c/li\u003e\n\u003cli\u003eYou need to iterate in a specific order\u003c/li\u003e\n\u003cli\u003eMemory locality matters (more cache-friendly)\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3 id=\"when-to-use-maps\"\u003eWhen to use maps\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003eYou need to look up values by non-integer keys\u003c/li\u003e\n\u003cli\u003eOrder doesn\u0026#39;t matter\u003c/li\u003e\n\u003cli\u003eYou need fast membership checks\u003c/li\u003e\n\u003cli\u003eYou\u0026#39;re building a cache or index\u003c/li\u003e\n\u003c/ul\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e Both slices and maps grow dynamically, but maps are more complex internally due to hash collision handling and bucket management. Slices give you predictable iteration order, while maps give you flexible key types.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003c!-- ## Exercises\n\nLet's test your understanding with some hands-on exercises:\n\n\u003cgocodequestion difficulty=\"easy\" playlink=\"\" parsetextfrom=\"questions/visual-go-maps/01.md\"\u003e\n    The map starts with 10 key-value pairs. Expression m[\"key5\"] returns 10 (5 * 2). After deletion, the key no longer exists, so the zero value (0) is returned along with fal
3se for the existence check.\n\u003c/gocodequestion\u003e\n\n\u003cgocodequestion difficulty=\"medium\" playlink=\"\" parsetextfrom=\"questions/visual-go-maps/02.md\"\u003e\nMap growth happens internally based on load factor, not at predictable intervals like slice capacity doubling. The hash table likely grows when the average number of items per bucket exceeds 6.5. Unlike slices, maps don't expose their internal bucket count, so we can only observe the number of key-value pairs (len(m)).\u003cbr\u003e\u003cbr\u003eThe output will show increasing length values:\n\u003cul\u003e\n\u003cli\u003eAfter 1 insertions, len=1\u003c/li\u003e\n\u003cli\u003eAfter 6 insertions, len=6\u003c/li\u003e\n\u003cli\u003eAfter 11 insertions, len=11\u003c/li\u003e\n\u003cli\u003eAfter 16 insertions, len=16\u003c/li\u003e\n\u003cli\u003eFinal length: 20\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/gocodequestion\u003e --\u003e\n\u003c!-- \u003e In the next article in the Go Internals series, we'll see how atomics work in the background, including a look at the machine instruction level. Stay tuned! --\u003e\n\u003ch2 id=\"references\"\u003eReferences\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/golang/go/blob/master/src/runtime/map.go\" target=\"_blank\"\u003eGo runtime: \u003ccode\u003eruntime/map.go\u003c/code\u003e (map internals)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://www.youtube.com/watch?v=Tl7mi9QmLns\" target=\"_blank\"\u003eRob Pike - \u0026#34;Go Maps in Action\u0026#34; (talk)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://go.dev/blog/maps\" target=\"_blank\"\u003eThe Go Blog - Maps\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://go.dev/blog/maps\" target=\"_blank\"\u003eThe Go Blog - Go maps in action\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://go.dev/doc/articles/race_detector\" target=\"_blank\"\u003eData Race Detector\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://pkg.go.dev/sync#Map\" target=\"_blank\"\u003esync.Map documentation\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://go.dev/ref/mem\" target=\"_blank\"\u003eThe Go Memory Model\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/golang/go/issues/63438\" target=\"_blank\"\u003eIssue #63438: Map load factor clarification\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cdiv class=\"footnotes\" role=\"doc-endnotes\"\u003e\n\u003chr/\u003e\n\u003col\u003e\n\u003cli id=\"fn:1\" data-index=\"1\"\u003e\n\u003cp\u003eSee \u003ca href=\"https://go.dev/blog/comparable\" target=\"_blank\"\u003eThe Go Blog\u003c/a\u003e for more information. \u003ca href=\"#fnref:1\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:2\" data-index=\"2\"\u003e\n\u003cp\u003e\u003ca href=\"https://go.dev/doc/faq#references\"\u003ehttps://go.dev/doc/faq#references\u003c/a\u003e \u003ca href=\"#fnref:2\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:3\" data-index=\"3\"\u003e\n\u003cp\u003eThe actual hash function used by Go is runtime/aeshash for most types, which uses AES instructions when available for security and performance. Different types may use optimized hash functions (e.g., strings have their own specialized hash). \u003ca href=\"#fnref:3\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:4\" data-index=\"4\"\u003e\n\u003cp\u003eThe bucket count is always a power of 2, which allows Go to use bitwise operations for bucket selection instead of expensive modulo operations. This is why B represents the power (2^B buckets) rather than the count directly. \u003ca href=\"#fnref:4\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n"])</script>
3<script>self.__next_f.push([1,"29:T6f22,"])</script>
3<script>self.__next_f.push([1,"\n\n\u003e This article is from the talk I gave at the [Go Konf Istanbul '24](/talks/an-applied-introduction-to-ebpf-with-go-2024-02-17) conference.\n\nMost of the time we are developing software or even using software, we are playing within the safe boundaries of the operating system. We don't even know how that IP packet was welcomed from the network interface, or those inodes were handled by the filesystem when we save a file.\n\nThat boundary is called the `user space`, and it's where we write our applications, libraries, and tools. But there's another world, which is the `kernel space`. It's where the operating system's kernel resides, and it's responsible for managing the system's resources, such as memory, CPU, and I/O devices.\n\n![Operating System Architecture](/assets/articles/ebpf-go/arch.png)\n\nWe usually don't need to go below the sockets or file descriptors, but sometimes we need to. Let's say you want to profile an application to see how much resource it consumes.\n\nIf you profile the application from the user space, you will not only miss too many useful details, but also you will consume a significant amount of resources for profiling itself, **because each layer on top of the CPU or memory introduces some overhead**.\n\n## The Need to Go Deeper\n\nLet's say you want to go down the stack and somehow insert your custom code into the kernel to profile the application, or to trace the system calls, or to monitor the network packets. How would you do that?\n\nTraditionally you have two options.\n\n### Option 1: Edit the Kernel Source Code\n\nIf you want to change the Linux kernel source code and then ship the same kernel to you customer's machine, you will need to convince the Linux kernel community that the change is required. Then, you will need to wait for several years for the new kernel version to be adopted by the Linux distributions.\n\nThis is not a practical approach for most of the cases, and it's also a little \nmuch for just profiling an application, or monitoring the network packets.\n\n### Option 2: Write a Kernel Module\n\nYou can write a kernel module, which is a piece of code that can be loaded into the kernel and executed. This is a more practical approach, but it has its own risks and downsides.\n\nFirst, you need to write a kernel module, which is not an easy task. Then, you need to maintain it regularly, because the kernel is a living thing, and it changes over time. If you don't maintain your kernel module, it will be outdated and won't work with the new kernel versions.\n\nSecond, you are risking corrupting your Linux kernel, because kernel modules don't have security boundaries. If you write a kernel module that has a bug, it can crash the whole system.\n\n## Enter eBPF\n\neBPF (Extended Berkeley Packet Filter) is a revolutionary technology that allows you to **reprogram the Linux kernel within minutes, even without rebooting the system**.\n\neBPF allows you to trace system calls, user space functions, library functions, network packets, and much more. It's a powerful tool for systems performance, monitoring, securtiy, and much more.\n\n### But how?\n\neBPF is a system consisting of several components:\n\n- eBPF programs\n- eBPF hooks\n- BPF maps\n- eBPF verifier\n- The eBPF virtual machine\n\n\u003e Note that I have used the term \"BPF\" and \"eBPF\" interchangeably. eBPF stands for \"Extended Berkeley Packet Filter\". BPF was originally introduced to Linux to filter network packets, but eBPF extends the original BPF to allow it to be used for other purposes. Today it's not related to Berkeley, and it's not only for filtering packets.\n\nBelow is an illustration of how eBPF works in both user space and under the hood. eBPF programs are written in a high-level language, such as C, and then compiled to `eBPF bytecode`. Then, the eBPF bytecode is loaded into the kernel and executed by the `eBPF virtual machine`.\n\nAn eBPF program is attaced to a specific code path in the kernel, such as a system call. These 
3code paths are called `\"hooks\"`. When the hook is triggered, the eBPF program is executed and now it performs the custom logic you have written. This way we can run our custom code in the kernel space.\n\n![Operating System Architecture](/assets/articles/ebpf-go/ebpf.png)\n\n## Hello World with eBPF\n\nBefore moving on to the details, let's write a simple eBPF program to trace the `execve` system call. We will write the program in C, the user space program in Go, and then run the user space program which will load the eBPF program into the kernel, and poll the custom events we will emit from the eBPF program, right before the actual `execve` system call is executed.\n\n### Writing the eBPF Program\n\nLet's start writing the eBPF program first. I will write part by part to explain the details better, but you can find the whole program in my GitHub repo: \u003cchip text=\"ozansz/intro-ebpf-with-go\" href=\"https://github.com/ozansz/intro-ebpf-with-go/tree/main/0x01-helloworld\" icon=\"github\"\u003e\u003c/chip\u003e.\n\n```c filename=\"hello_ebpf.c\"\n#include \"vmlinux.h\"\n#include \u003cbpf/bpf_helpers.h\u003e\n\nstruct event {\n    u32 pid;\n    u8  comm[100];\n};\n\nstruct {\n\t__uint(type, BPF_MAP_TYPE_RINGBUF);\n\t__uint(max_entries, 1000);\n} events SEC(\".maps\");\n```\n\nHere we import the `vmlinux.h` header file, which contains the kernel's data structures and function prototypes. Then we include the `bpf_helpers.h` header file, which contains helper functions for eBPF programs.\n\nThen we define a `struct` to hold the event data, and then we define a [BPF map](https://docs.kernel.org/bpf/maps.html) to store the events. We will use this map to communicate the events between the eBPF program, which will run in kernel space, and the user space program.\n\n\u003e We will go into the details of BPF maps later, so don't worry if you don't understand why we used `BPF_MAP_TYPE_RINGBUF`, or what is `SEC(\".maps\")` for.\n\nWe are now ready to write our first program and define the hook that it will be attached to:\n\n```c filename=\"hello_ebpf.c\"\nSEC(\"kprobe/sys_execve\")\nint hello_execve(struct pt_regs *ctx) {\n    u64 id = bpf_get_current_pid_tgid();\n    pid_t pid = id \u003e\u003e 32;\n    pid_t tid = (u32)id;\n\n    if (pid != tid)\n        return 0;\n\n    struct event *e;\n\n\te = bpf_ringbuf_reserve(\u0026events, sizeof(struct event), 0);\n\tif (!e) {\n\t\treturn 0;\n\t}\n\n\te-\u003epid = pid;\n\tbpf_get_current_comm(\u0026e-\u003ecomm, 100);\n\n\tbpf_ringbuf_submit(e, 0);\n\n\treturn 0;\n}\n```\n\nHere we define a function, `hello_execve`, and attach it to the `sys_execve` system call using the `kprobe` hook. `kprobe` is one of many hooks that eBPF provides, and it's used to trace kernel functions. This hook will trigger our `hello_execve` function right before the `sys_execve` system call is executed.\n\nInside the `hello_execve` function, we first get the process ID and the thread ID, and then we check if they are the same. If they are not the same, that means we are in a thread, and we don't want to trace threads, so we exit the eBPF program by returning zero.\n\nWe then reserve space in the `events` map to store the event data, and then we fill the event data with the process ID and the command name of the process. Then we submit the event to the `events` map.\n\nIt's pretty simple until now, right?\n\n### Writing the User Space Program\n\nBefore starting to write the user space program, let me briefly explain what the program needs to do in user space. We need a user space program to load the eBPF program into the kernel, create the BPF map, attach to the BPF map, and then read the events from the BPF map.\n\nTo perform these operations, we need to use a specific system call. This system call is called `bpf()`, and it's used to perform several eBPF-related operations, such as reading the contents of a BPF map.\n\nWe can call this system call ourselves from the user space as well, but it means too many low-level operations. Thankfully there are libraries that provide a high-level interface to the `bpf()` system call. One of them is \u003cchip text=\"Cilium\" href=\"https://cilium.io/\" icon=\"package\"\u003e\u003c/chip\u003e's \u003cchip text=\"ebpf-go\" href=\"https://github.com/cilium/ebpf\" icon=\"github\"\u003e\u003c/chip\u003e package, which we will use in this example.\n\nLet's dive into some Go code.\n\n```go filename=\"main.go\"\n//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -type event ebpf hello_ebpf.c\n\nfunc main() {\n\tstopper := make(chan os.Signal, 1)\n\tsignal.Notify(stopper, os.Interrupt, syscall.SIGTERM)\n\n\t// Allow the current process to lock memory for eBPF resources.\n\tif err := rlimit.RemoveMemlock(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tobjs := ebpfObjects{}\n\tif err := loadEbpfObjects(\u0026objs, nil); err != nil {\n\t\tlog.Fatalf(\"loading objects: %v\", err)\n\t}\n\tdefer objs.Close()\n\n\tkp, err := link.Kprobe(kprobeFunc, objs.HelloExecve, nil)\n\tif err != nil {\n\t\tlog.Fatalf(\"opening kprobe: %s\", err)\n\t}\n\tdefer kp.Close()\n\n\trd, err := ringbuf.NewReader(objs.Events)\n\tif err != nil {\n\t\tlog.Fatalf(\"opening ringbuf reader: %s\", err)\n\t}\n\tdefer rd.Close()\n\n    ...\n```\n\nThe first line is a Go compiler directive, `go:generate`. Here we say to the Go compiler to run the `bpf2go` tool from the `github.com/cilium/ebpf/cmd/bpf2go` package, and generate a Go file from the `hello_ebpf.c` file.\n\nThe generated Go files will include the Go representation of the eBPF program, the types and structs we have defined in the eBPF program, etc. We then will use these representations inside our Go code to load the eBPF program into the kernel, and to interact with the BPF map.\n\nWe then use the generated types to load the eBPF program (`loadEbpfObjects`), attach to the kprobe hook (`link.Kprobe`), and read the events from the BPF map (`ringbuf.NewReader`). All of these functions use the generated types.\n\nIt's time to interact with the kernel side:\n\n\n```go filename=\"main.go\"\n    ...\n\n\tgo func() {\n\t\t\u003c-stopper\n\n\t\tif err := rd.Close(); err != nil {\n\t\t\tlog.Fatalf(\"closing ringbuf reader: %s\", err)\n\t\t}\n\t}()\n\n\tlog.Println(\"Waiting for events..\")\n\n\tvar event ebpfEvent\n\tfor {\n\t\trecord, err := rd.Read()\n\t\tif err != nil {\n\t\t\tif errors.Is(err, ringbuf.ErrClosed) {\n\t\t\t\tlog.Println(\"Received signal, exiting..\")\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlog.Printf(\"reading from reader: %s\", err)\n\t\t\tcontinue\n\t\t}\n\n\t\tif err := binary.Read(bytes.NewBuffer(record.RawSample), binary.LittleEndian, \u0026event); err != nil {\n\t\t\tlog.Printf(\"parsing ringbuf event: %s\", err)\n\t\t\tcontinue\n\t\t}\n\n\t\tprocName := unix.ByteSliceToString(event.Comm[:])\n\t\tlog.Printf(\"pid: %d\\tcomm: %s\\n\", event.Pid, procName)\n\t}\n}\n```\n\nWe start a goroutine to listen to the `stopper` channel, which we defined in the previous Go snippet. This channel will be used to stop the program gracefully when we receive an interrupt signal.\n\nWe then start a loop to read the events from the BPF map. We use the `ringbuf.Reader` type to read the events, and then we parse the event data using the `binary.Read` function, into the `ebpfEvent` type, which is generated from the eBPF program.\n\nWe then print the process ID and the command name of the process to the standard output.\n\n### Running the Program\n\nNow 
3we are ready to run the program. First, we need to compile the eBPF program, and then run the user space program.\n\n```bash\n$ go generate\nCompiled /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfel.o\nStripped /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfel.o\nWrote /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfel.go\nCompiled /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfeb.o\nStripped /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfeb.o\nWrote /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfeb.go\n\n$ go build -o hello_ebpf\n```\n\nWe first run the `go generate` command to compile the eBPF program, and then we run the `go build` command to compile the user space program.\n\nThen we run the user space program:\n\n```bash\nsudo ./hello_ebpf\nhello_ebpf: 01:20:54 Waiting for events..\n```\n\nI'm running this program inside a VM in \u003cchip text=\"Lima\" href=\"https://github.com/lima-vm/lima\" icon=\"github\"\u003e\u003c/chip\u003e, why not open another shell and see what will happen?\n\n```bash\nlimactl shell intro-ebpf\n\n$\n```\n\nMeanwhile in the first shell:\n\n```bash\nhello_ebpf: 01:22:22 pid: 3360\tcomm: sshd\nhello_ebpf: 01:22:22 pid: 3360\tcomm: bash\nhello_ebpf: 01:22:22 pid: 3361\tcomm: bash\nhello_ebpf: 01:22:22 pid: 3362\tcomm: bash\nhello_ebpf: 01:22:22 pid: 3363\tcomm: bash\nhello_ebpf: 01:22:22 pid: 3366\tcomm: bash\nhello_ebpf: 01:22:22 pid: 3367\tcomm: lesspipe\nhello_ebpf: 01:22:22 pid: 3369\tcomm: lesspipe\nhello_ebpf: 01:22:22 pid: 3370\tcomm: bash\n```\n\nAs expected, we are seeing that the `sshd` process is starting, and then the `bash` process is starting, and then the `lesspipe` process is starting, and so on.\n\nThis is a simple example of how we can use eBPF to trace the `execve` system call, and then read the events from the BPF map in the user space. We wrote a fairly simple yet powerful program, and we intercepted the `execve` system call without modifying the kernel source code or restarting the system.\n\n## eBPF Hooks and Maps\n\nSo, what actually happened in the previous example? We attached the eBPF program to the `sys_execve` system call using the `kprobe` hook, to run the `hello_execve` function wheneve the `sys_execve` system call is called, right before the original system call is code is executed.\n\n![](/assets/articles/ebpf-go/hello-world.png)\n\neBPF is event driven, meaning that it expects us to attach the eBPF program to a specific code path in the kernel. These 
3code paths are called \"hooks\", and there are several types of hooks that eBPF provides. The most common ones are:\n\n- `kprobe`, `kretprobe`: Trace kernel functions\n- `uprobe`, `uretprobe`: Trace user space functions\n- `tracepoint`: Trace predefined tracepoints in the kernel\n- `xdp`: eXpress Data Path, used to filter and redirect network packets\n- `usdt`: User Statically Defined Tracing, used to trace user space functions in a more efficient way\n\nThe hooks `kprobe` and `uprobe` are used to invoke the attached eBPF programs **before** the function/syscall execution, and `kretprobe` and `uretprobe` are used to invoke the attached eBPF programs **after** the function/syscall execution.\n\nWe also used a BPF map to store the events. BPF maps are data structures to store and communicate different kinds of data. We also use them for state management. There are too many types of BPF maps supported, and we use different types of maps for different purposes. Some of the most common BPF map types are:\n\n- `BPF_MAP_TYPE_HASH`: A hash map\n- `BPF_MAP_TYPE_ARRAY`: An array\n- `BPF_MAP_TYPE_RINGBUF`: A ring buffer\n- `BPF_MAP_TYPE_STACK`: A stack\n- `BPF_MAP_TYPE_QUEUE`: A queue\n- `BPF_MAP_TYPE_LRU_HASH`: A least recently used hash map\n\nSome of these map types also have per-CPU variants, such as `BPF_MAP_TYPE_PERCPU_HASH`, which is a hash map with a separate hash table for each CPU core.\n\n## One Step Further: Tracing Incoming IP Packets\n\nLet's take a step further and write a more complex eBPF program. This time we will use the `XDP` hook to invoke the eBPF program right after the network interface sends a network packet to the kernel, **even before the kernel processes the packet**.\n\n![](/assets/articles/ebpf-go/xdp.png)\n\n### Writing the eBPF Program\n\nWe will write an eBPF program to count the number of incoming IP packets by the source IP address and port number, and then we will read the counts from the BPF map in the user space. We will parse the ethernet, IP and TCP/UDP headers of each packet, and store the counts of the valid TCP/UDP packets in the BPF map.\n\nFirst, the eBPF program:\n\n```c filename=\"hello_ebpf.c\"\n#include \"vmlinux.h\"\n#include \u003cbpf/bpf_helpers.h\u003e\n#include \u003cbpf/bpf_endian.h\u003e\n\n#define MAX_MAP_ENTRIES 100\n\n/* Define an LRU hash map for storing packet count by source IP and port */\nstruct {\n\t__uint(type, BPF_MAP_TYPE_LRU_HASH);\n\t__uint(max_entries, MAX_MAP_ENTRIES);\n\t__type(key, u64); // source IPv4 addresses and port tuple\n\t__type(value, u32); // packet count\n} xdp_stats_map SEC(\".maps\");\n```\n\nLike the first example, we will include the `vmlinux.h` and BPF helper headers. We also define a map, `xdp_stats_map`, to store the `IP:ports` and packet count information. We wil then populate this map inside the hook function and read the contents in the user space program.\n\nWhat I mean by `IP:ports` is basically a `u64` value, packed with the source IP, source port and the destination port. The IP address (**IPv4**, specifically) is 32-bits long, and each port number is 16-bits long, so we need exactly 64 bits to store all three - that's why we are using `u64` here. We are only processing the ingress (incoming packets) here so we won't need to store the destination IP address.\n\nDifferent from the last example we now used `BPF_MAP_TYPE_LRU_HASH` as the map type. This type of map lets us store a `(key, value)` pair as a hashmap with LRU variant.\n\nSee how we defined the map here, we explicitly set the number of maximum entries, and the types of the map key and values. For key we are using a 64-bit unsigned integer and for value a 32-bit unsigned integer.\n\n\u003e The maximum value of `u32` is `2^32 - 1`, which is more than enough packets for the sake of this example.\n\nTo learn the IP address and port number, we first need to parse the packet and read the **ethernet, IP and then TCP/UDP headers**.\n\nAs XDP is placed right after the network interface card, we will be given the **raw packet data in bytes**, so we will need to manually walk on the byte array and unmarshal the ethernet, IP and TCP/UDP headers.\n\nHopefully, we have all the header definitions (`struct ethhdr`, `struct iphdr`, `struct tcphdr`, and `struct udphdr`),  inside `vmlinux.h` header file. We will use these structs to extract the IP address and port number information in a separate function, `parse_ip_packet`:\n\n```c filename=\"hello_ebpf.c\"\n#define ETH_P_IP\t\t0x0800\t/* Internet Protocol packet\t*/\n\n#define PARSE_SKIP \t\t\t0\n#define PARSED_TCP_PACKET\t1\n#define PARSED_UDP_PACKET\t2\n\nstatic __always_inline int parse_ip_packet(struct xdp_md *ctx, u64 *ip_metadata) {\
3n\tvoid *data_end = (void *)(long)ctx-\u003edata_end;\n\tvoid *data     = (void *)(long)ctx-\u003edata;\n\n\t// First, parse the ethernet header.\n\tstruct ethhdr *eth = data;\n\tif ((void *)(eth + 1) \u003e data_end) {\n\t\treturn PARSE_SKIP;\n\t}\n\n\tif (eth-\u003eh_proto != bpf_htons(ETH_P_IP)) {\n\t\t// The protocol is not IPv4, so we can't parse an IPv4 source address.\n\t\treturn PARSE_SKIP;\n\t}\n\n\t// Then parse the IP header.\n\tstruct iphdr *ip = (void *)(eth + 1);\n\tif ((void *)(ip + 1) \u003e data_end) {\n\t\treturn PARSE_SKIP;\n\t}\n\n\tu16 src_port, dest_port;\n\tint retval;\n\n\tif (ip-\u003eprotocol == IPPROTO_TCP) {\n\t\tstruct tcphdr *tcp = (void*)ip + sizeof(*ip);\n\t\tif ((void*)(tcp+1) \u003e data_end) {\n\t\t\treturn PARSE_SKIP;\n\t\t}\n\t\tsrc_port = bpf_ntohs(tcp-\u003esource);\n\t\tdest_port = bpf_ntohs(tcp-\u003edest);\n\t\tretval = PARSED_TCP_PACKET;\n\t} else if (ip-\u003eprotocol == IPPROTO_UDP) {\n\t\tstruct udphdr *udp = (void*)ip + sizeof(*ip);\n\t\tif ((void*)(udp+1) \u003e data_end) {\n\t\t\treturn PARSE_SKIP;\n\t\t}\n\t\tsrc_port = bpf_ntohs(udp-\u003esource);\n\t\tdest_port = bpf_ntohs(udp-\u003edest);\n\t\tretval = PARSED_UDP_PACKET;\n\t} else {\n\t\t// The protocol is not TCP or UDP, so we can't parse a source port.\n\t\treturn PARSE_SKIP;\n\t}\n\n\t// Return the (source IP, destination IP) tuple in network byte order.\n\t// |\u003c-- Source IP: 32 bits --\u003e|\u003c-- Source Port: 16 bits --\u003e\u003c-- Dest Port: 16 bits --\u003e|\n\t*ip_metadata = ((u64)(ip-\u003esaddr) \u003c\u003c 32) | ((u64)src_port \u003c\u003c 16) | (u64)dest_port;\n\treturn retval;\n}\n```\n\nThe function:\n\n- Checks if the packet has a valid ethernet header, IP header, and TCP or UDP header. These checks are done by using the `h_proto` of `struct ethhdr` and `protocol` of `struct iphdr`. Each header stores the protocol of the inner packet it wraps.\n- Extracts the IP address from the IP header and port number from the TCP/UDP headers and forms an `IP:ports` tuple inside a 64-bit unsigned integer (`u64`)\n- Returns a code to tell the caller whether the packet is a TCP packet, a UDP packet, or else (`PARSE_SKIP`)\n\nNotice the `__always_inline` at the beginning of the function signature. This tells the compiler to always inline this funcion as static code, which saves us from performing a function call.\n\nNow it's time to write the hook function and use `parse_ip_packet`:\n\n```c filename=\"hello_ebpf.c\"\nSEC(\"xdp\")\nint xdp_prog_func(struct xdp_md *ctx) {\n\tu64 ip_meta;\n\tint retval = parse_ip_packet(ctx, \u0026ip_meta);
3\n\t\n\tif (retval != PARSED_TCP_PACKET) {\n\t\treturn XDP_PASS;\n\t}\n\n\tu32 *pkt_count = bpf_map_lookup_elem(\u0026xdp_stats_map, \u0026ip_meta);\n\tif (!pkt_count) {\n\t\t// No entry in the map for this IP tuple yet, so set the initial value to 1.\n\t\tu32 init_pkt_count = 1;\n\t\tbpf_map_update_elem(\u0026xdp_stats_map, \u0026ip_meta, \u0026init_pkt_count, BPF_ANY);\n\t} else {\n\t\t// Entry already exists for this IP tuple,\n\t\t// so increment it atomically.\n\t\t__sync_fetch_and_add(pkt_count, 1);\n\t}\n\n\treturn XDP_PASS;\n}\n```\n\nThe `xdp_prog_func` is fairly simple as we already coded most of the program logic inside `parse_ip_packet`. What we do here is:\n\n- Parse the packet using `parse_ip_packet`\n- Skip counting if it's not a TCP or UDP packet by returning `XDP_PASS`\n- Lookup the `IP:ports` tuple in BPF map keys using the `bpf_map_lookup_elem` helper function\n- Set the value to one if the `IP:ports` tuple is seen the first time, else increment it by one. The `__sync_fetch_and_add` is an LLVM built-in here\n\nFinally we attach this function to the `XDP` subsystem by using the `SEC(\"xdp\")` macro.\n\n### Writing the User Space Program\n\nIt's time to dive into Go code again.\n\n```go filename=\"main.go\"\n//go:generate go run github.com/cilium/ebpf/cmd/bpf2go ebpf xdp.c\n\nvar (\n    ifaceName = flag.String(\"iface\", \"\", \"network interface to attach XDP program to\")\n)\n\nfunc main() {\n\tlog.SetPrefix(\"packet_count: \")\n\tlog.SetFlags(log.Ltime | log.Lshortfile)\n    flag.Parse()\n\n\t// Subscribe to signals for terminating the program.\n\tstop := make(chan os.Signal, 1)\n\tsignal.Notify(stop, os.Interrupt, syscall.SIGTERM)\n\n\tiface, err := net.InterfaceByName(*ifaceName)\n\tif err != nil {\n\t\tlog.Fatalf(\"network iface lookup for %q: %s\", *ifaceName, err)\n\t}\n\n\t// Load pre-compiled programs and maps into the kernel.\n\tobjs := ebpfObjects{}\n\tif err := loadEbpfObjects(\u0026objs, nil); err != nil {\n\t\tlog.Fatalf(\"loading objects: %v\", err)\n\t}\n\tdefer objs.Close()\n\n\t// Attach the program.\n\tl, err := link.AttachXDP(link.XDPOptions{\n\t\tProgram:   objs.XdpProgFunc,\n\t\tInterface: iface.Index,\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"could not attach XDP program: %s\", err)\n\t}\n\tdefer l.Close()\n\n\tlog.Printf(\"Attached XDP program to iface %q (index %d)\", iface.Name, iface.Index)\n\n    ...\n```\n\nHere we first load the generated eBPF program and map using the `loadEbpfObjects` function. Then we attach the program to the specified network interface using the `link.AttachXDP` function. Similar to the previous example we used a channel to listen to the interrupt signal and close the program gracefully.\n\nNext, we will read the map contents in every second and print the packet counts to the standard output:\n\n```go filename=\"main.go\"\n    ...\n\n    ticker := time.NewTicker(time.Second)\n\tdefer ticker.Stop()\n\tfor {\n\t\tselect {\n\t\tcase \u003c-stop:\n\t\t\tif err := objs.XdpStatsMap.Close(); err != nil {\n\t\t\t\tlog.Fatalf(\"closing map reader: %s\", err)\n\t\t\t}\n\t\t\treturn\n\t\tcase \u003c-ticker.C:\n\t\t\tm, err := parsePacketCounts(objs.XdpStatsMap, excludeIPs)\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"Error reading map: %s\", err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tlog.Printf(\"Map contents:\\n%s\", m)\n\t\t\tsrv.Submit(m)\n\t\t}\n\t}\n}\n```\n\nWe will use a utility function, `parsePacketCounts`, to read the map contents and parse the packet counts. This function will read the map contents in a loop.\n\nAs we will be given raw bytes from the map, we will need to parse the bytes and convert them into a human-readable format. We will define a new type `PacketCounts` to store the parsed map contents.\n\n```go filename=\"main.go\"\ntype IPMetadata struct {\n\tSrcIP   netip.Addr\n\tSrcPort uint16\n\tDstPort uint16\n}\n\nfunc (t *IPMetadata) UnmarshalBinary(data []byte) (err error) {\n\tif len(data) != 8 {\n\t\treturn fmt.Errorf(\"invalid data length: %d\", len(data))\n\t}\n\tif err = t.SrcIP.UnmarshalBinary(data[4:8]); err != nil {\n\t\treturn\n\t}\n\tt.SrcPort = uint16(data[3])\u003c\u003c8 | uint16(data[2])\n\tt.DstPort = uint16(data[1])\u003c\u003c8 | uint16(data[0])\n\treturn nil\n}\n\nfunc (t IPMetadata) String() string {\n\treturn fmt.Sprintf(\"%s:%d =\u003e :%d\", t.SrcIP, t.SrcPort, t.DstPort)\n}\n\ntype PacketCounts map[string]int\n\nfunc (i PacketCounts) String() string {\n\tvar keys []string\n\tfor k := range i {\n\t\tkeys = append(keys, k)\n\t}\n\tsort.Strings(keys)\n\n\tvar sb strings.Builder\n\tfor _, k := range keys {\n\t\tsb.WriteString(fmt.Sprintf(\"%s\\t| %d\\
3n\", k, i[k]))\n\t}\n\n\treturn sb.String()\n}\n```\n\nWe defined a new type, `IPMetadata`, to store the `IP:ports` tuple. We also defined a `UnmarshalBinary` method to parse the raw bytes and convert them into a human-readable format. We also defined a `String` method to print the `IP:ports` tuple in a human-readable format.\n\nWe then defined a new type, `PacketCounts`, to store the parsed map contents. We also defined a `String` method to print the map contents in a human-readable format.\n\nFinally, we will use the `PacketCounts` type to parse the map contents and print the packet counts:\n\n```go filename=\"main.go\"\nfunc parsePacketCounts(m *ebpf.Map, excludeIPs map[string]bool) (PacketCounts, error) {\n\tvar (\n\t\tkey    IPMetadata\n\t\tval    uint32\n\t\tcounts = make(PacketCounts)\n\t)\n\titer := m.Iterate()\n\tfor iter.Next(\u0026key, \u0026val) {\n\t\tif _, ok := excludeIPs[key.SrcIP.String()]; ok {\n\t\t\tcontinue\n\t\t}\n\t\tcounts[key.String()] = int(val)\n\t}\n\treturn counts, iter.Err()\n}\n```\n\n### Running the Program\n\nWe first need to compile the eBPF program and then run the user space program.\n\n```bash\n$ go generate\nCompiled /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfel.o\nStripped /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfel.o\nWrote /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfel.go\nCompiled /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfeb.o\nStripped /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfeb.o\nWrote /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfeb.go\n\n$ go build -o packet_count\n```\n\nNow we can run it:\n\n```bash\n$ sudo ./packet_count --iface eth0\npacket_count: 22:11:10 main.go:107: Attached XDP program to iface \"eth0\" (index 2)\npacket_count: 22:11:10 main.go:132: Map contents:\n192.168.5.2:58597 =\u003e :22\t| 51\npacket_count: 22:11:11 main.go:132: Map contents:\n192.168.5.2:58597 =\u003e :22\t| 52\npacket_count: 22:11:11 main.go:132: Map contents:\n192.168.5.2:58597 =\u003e :22\t| 53\n```\n\nThe packets coming to the port `22` from the IP address `192.168.5.2` are the SSH packets, as I am running this program inside a VM and I am SSHing into.\n\nLet's run `curl` inside the VM in another terminal, and see what will happen:\n\n```bash\n$ curl https://www.google.com/\n```\n\nMeanwhile in the first terminal:\n\n```bash\npacket_count: 22:14:07 main.go:132: Map contents:\n172.217.22.36:443 =\u003e :38324\t| 12\n192.168.5.2:58597 =\u003e :22\t| 551\npacket_count: 22:14:08 main.go:132: Map contents:\n172.217.22.36:443 =\u003e :38324\t| 12\n192.168.5.2:58597 =\u003e :22\t| 552\npacket_count: 22:14:08 main.go:132: Map contents:\n172.217.22.36:443 =\u003e :38324\t| 30\n192.168.5.2:58597 =\u003e :22\t| 570\npacket_count: 22:14:09 main.go:132: Map contents:\n172.217.22.36:443 =\u003e :38324\t| 30\n192.168.5.2:58597 =\u003e :22\t| 571\n```\n\nWe are seeing the packets coming to the port `38324` from the IP address `172.217.22.36` are the packets coming from the `curl` command.\n\n## Conclusion\n\neBPF is powerful in many ways and I think it's a good technology to invest time in, especially you are in systems programming, observability or security. In this article we have seen what eBPF is, how it works, and how we can start using it with Go.\n\nI hope you enjoyed this article and learned something new. If you have any questions, feel free to [ping](https://twitter.com/oznszk) me.\n\n## Resources\n\n- Systems Performance, Brendan Gregg\n- Learning eBPF, Liz Rice\n- docs.kernel.org\n- ebpf.io\n- cilium.io\n- iovisor.org\n- brendangregg.com"])</script>
3<script>self.__next_f.push([1,"2a:T26abd,"])</script>
3<script>self.__next_f.push([1,"\u003cblockquote\u003e\n\u003cp\u003eThis article is from the talk I gave at the \u003ca href=\"/talks/an-applied-introduction-to-ebpf-with-go-2024-02-17\" target=\"_blank\"\u003eGo Konf Istanbul \u0026#39;24\u003c/a\u003e conference.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eMost of the time we are developing software or even using software, we are playing within the safe boundaries of the operating system. We don\u0026#39;t even know how that IP packet was welcomed from the network interface, or those inodes were handled by the filesystem when we save a file.\u003c/p\u003e\n\u003cp\u003eThat boundary is called the \u003ccode\u003euser space\u003c/code\u003e, and it\u0026#39;s where we write our applications, libraries, and tools. But there\u0026#39;s another world, which is the \u003ccode\u003ekernel space\u003c/code\u003e. It\u0026#39;s where the operating system\u0026#39;s kernel resides, and it\u0026#39;s responsible for managing the system\u0026#39;s resources, such as memory, CPU, and I/O devices.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/ebpf-go/arch.png\" alt=\"Operating System Architecture\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eWe usually don\u0026#39;t need to go below the sockets or file descriptors, but sometimes we need to. Let\u0026#39;s say you want to profile an application to see how much resource it consumes.\u003c/p\u003e\n\u003cp\u003eIf you profile the application from the user space, you will not only miss too many useful details, but also you will consume a significant amount of resources for profiling itself, \u003cstrong\u003ebecause each layer on top of the CPU or memory introduces some overhead\u003c/strong\u003e.\u003c/p\u003e\n\u003ch2 id=\"the-need-to-go-deeper\"\u003eThe Need to Go Deeper\u003c/h2\u003e\n\u003cp\u003eLet\u0026#39;s say you want to go down the stack and somehow insert your custom code into the kernel to profile the application, or to trace the system calls, or to monitor the network packets. How would you do that?\u003c/p\u003e\n\u003cp\u003eTraditionally you have two options.\u003c/p\u003e\n\u003ch3 id=\"option-1-edit-the-kernel-source-code\"\u003eOption 1: Edit the Kernel Source Code\u003c/h3\u003e\n\u003cp\u003eIf you want to change the Linux kernel source code and then ship the same kernel to you customer\u0026#39;s machine, you will need to convince the Linux kernel community that the change is required. Then, you will need to wait for several years for the new kernel version to be adopted by the Linux distributions.\u003c/p\u003e\n\u003cp\u003eThis is not a practical approach for most of the cases, and it\u0026#39;s also a little\u003cbr/\u003e\nmuch for just profiling an application, or monitoring the network packets.\u003c/p\u003e\n\u003ch3 id=\"option-2-write-a-kernel-module\"\u003eOption 2: Write a Kernel Module\u003c/h3\u003e\n\u003cp\u003eYou can write a kernel module, which is a piece of code that can be loaded into the kernel and executed. This is a more practical approach, but it has its own risks and downsides.\u003c/p\u003e\n\u003cp\u003eFirst, you need to write a kernel module, which is not an easy task. Then, you need to maintain it regularly, because the kernel is a living thing, and it changes over time. If you don\u0026#39;t maintain your kernel module, it will be outdated and won\u0026#39;t work with the new kernel versions.\u003c/p\u003e\n\u003cp\u003eSecond, you are risking corrupting your Linux kernel, because kernel modules don\u0026#39;t have security boundaries. If you write a kernel module that has a bug, it can crash the whole system.\u003c/p\u003e\n\u003ch2 id=\"enter-ebpf\"\u003eEnter eBPF\u003c/h2\u003e\n\u003cp\u003eeBPF (Extended Berkeley Packet Filter) is a revolutionary technology that allows you to \u003cstrong\u003ereprogram the Linux kernel within minutes, even without rebooting the system\u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003eeBPF allows you to trace system calls, user space functions, library functions, network packets, and much more. It\u0026#39;s a powerful tool for systems performance, monitoring, securtiy, and much more.\u003c/p\u003e\n\u003ch3 id=\"but-how\"\u003eBut how?\u003c/h3\u003e\n\u003cp\u003eeBPF is a system consisting of several components:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eeBPF programs\u003c/li\u003e\n\u003cli\u003eeBPF hooks\u003c/li\u003e\n\u003cli\u003eBPF maps\u003c/li\u003e\n\u003cli\u003eeBPF verifier\u003c/li\u003e\n\u003cli\u003eThe eBPF virtual machine\u003c/li\u003e\n\u003c/ul\u003e\n\u003cblockquote\u003e\n\u003cp\u003eNote that I have used the term \u0026#34;BPF\u0026#34; and \u0026#34;eBPF\u0026#34; interchangeably. eBPF stands for \u0026#34;Extended Berkeley Packet Filter\u0026#34;. BPF was originally introduced to Linux to filter network packets, but eBPF extends the original BPF to allow it to be used for other purposes. Today it\u0026#39;s not related to Berkeley, and it\u0026#39;s not only for filtering packets.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eBelow is an illustration of how eBPF works in both user space and under the hood. eBPF programs are written in a high-level language, such as C, and then compiled to \u003ccode\u003eeBPF bytecode\u003c/code\u003e. Then, the eBPF bytecode is loaded into the kernel and executed by the \u
3003ccode\u003eeBPF virtual machine\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eAn eBPF program is attaced to a specific code path in the kernel, such as a system call. These code paths are called \u003ccode\u003e\u0026#34;hooks\u0026#34;\u003c/code\u003e. When the hook is triggered, the eBPF program is executed and now it performs the custom logic you have written. This way we can run our custom code in the kernel space.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/ebpf-go/ebpf.png\" alt=\"Operating System Architecture\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch2 id=\"hello-world-with-ebpf\"\u003eHello World with eBPF\u003c/h2\u003e\n\u003cp\u003eBefore moving on to the details, let\u0026#39;s write a simple eBPF program to trace the \u003ccode\u003eexecve\u003c/code\u003e system call. We will write the program in C, the user space program in Go, and then run the user space program which will load the eBPF program into the kernel, and poll the custom events we will emit from the eBPF program, right before the actual \u003ccode\u003eexecve\u003c/code\u003e system call is executed.\u003c/p\u003e\n\u003ch3 id=\"writing-the-ebpf-program\"\u003eWriting the eBPF Program\u003c/h3\u003e\n\u003cp\u003eLet\u0026#39;s start writing the eBPF program first. I will write part by part to explain the details better, but you can find the whole program in my GitHub repo: \u003cchip text=\"ozansz/intro-ebpf-with-go\" href=\"https://github.com/ozansz/intro-ebpf-with-go/tree/main/0x01-helloworld\" icon=\"github\"\u003e\u003c/chip\u003e.\u003c/p\u003e\n\u003cpre data-filename=\"hello_ebpf.c\" data-language=\"c\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#include\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026#34;vmlinux.h\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#include\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;bpf/bpf_helpers.h\u0026gt;\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eevent\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eu32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eu8\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"\"\u003ecomm\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e];\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e};\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e__uint\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eBPF_MAP_TYPE_RINGBUF\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e__uint\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003emax_entries\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1000\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eevents\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eSEC\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;.maps\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eHere we import the \u003ccode\u003evmlinux.h\u003c/code\u003e header file, which contains the kernel\u0026#39;s data structures and function prototypes. Then we include the \u003ccode\u003ebpf_helpers.h\u003c/code\u003e header file, which contains helper functions for eBPF programs.\u003c/p\u003e\n\u003cp\u003eThen we define a \u003ccode\u003estruct\u003c/code\u003e to hold the event data, and then we define a \u003ca href=\"https://docs.kernel.org/bpf/maps.html\" target=\"_blank\"\u003eBPF map\u003c/a\u003e to store the events. We will use this map to communicate the events between the eBPF program, which will run in kernel space, and the user space program.\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003eWe will go into the details of BPF maps later, so don\u0026#39;t worry if you don\u0026#39;t understand why we used \u003ccode\u003eBPF_MAP_TYPE_RINGBUF\u003c/code\u003e, or what is \u003ccode\u003eSEC(\u0026#34;.maps\u0026#34;)\u003c/code\u003e for.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eWe are now ready to write our first program and define the hook that it will be attached to:\u003c/p\u003e\n\u003cpre data-filename=\"hello_ebpf.c\" data-language=\"c\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eSEC\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;kprobe/sys_execve\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ehello_execve\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ept_regs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003ectx\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eu64\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebpf_get_current_pid_tgid\u003c/span\u003e\u003cspan style=\"\"\u003e();\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003epid_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026gt;\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003epid_t\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003etid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eu32\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003eid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003etid\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eevent\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003ee\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ee\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebpf_ringbuf_reserve\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eevents\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003esizeof\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eevent\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!\u003c/span\u003e\u003cspan style=\"\"\u003ee\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ee\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003epid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epid\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ebpf_get_current_comm\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003ee\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003ecomm\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ebpf_ringbuf_submit\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ee\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eHere we define a function, \u003ccode\u003ehello_execve\u003c/code\u003e, and attach it to the \u003ccode\u003esys_execve\u003c/code\u003e system call using the \u003ccode\u003ekprobe\u003c/code\u003e hook. \u003ccode\u003ekprobe\u003c/code\u003e is one of many hooks that eBPF provides, and it\u0026#39;s used to trace kernel functions. This hook will trigger our \u003ccode\u003ehello_execve\u003c/code\u003e function right before the \u003ccode\u003esys_execve\u003c/code\u003e system call is executed.\u003c/p\u003e\n\u003cp\u003eInside the \u003ccode\u003ehello_execve\u003c/code\u003e function, we first get the process ID and the thread ID, and then we check if they are the same. If they are not the same, that means we are in a thread, and we don\u0026#39;t want to trace threads, so we exit the eBPF program by returning zero.\u003c/p\u003e\n\u003cp\u003eWe then reserve space in the \u003ccode\u003eevents\u003c/code\u003e map to store the event data, and then we fill the event data with the process ID and the command name of the process. Then we submit the event to the \u003
3ccode\u003eevents\u003c/code\u003e map.\u003c/p\u003e\n\u003cp\u003eIt\u0026#39;s pretty simple until now, right?\u003c/p\u003e\n\u003ch3 id=\"writing-the-user-space-program\"\u003eWriting the User Space Program\u003c/h3\u003e\n\u003cp\u003eBefore starting to write the user space program, let me briefly explain what the program needs to do in user space. We need a user space program to load the eBPF program into the kernel, create the BPF map, attach to the BPF map, and then read the events from the BPF map.\u003c/p\u003e\n\u003cp\u003eTo perform these operations, we need to use a specific system call. This system call is called \u003ccode\u003ebpf()\u003c/code\u003e, and it\u0026#39;s used to perform several eBPF-related operations, such as reading the contents of a BPF map.\u003c/p\u003e\n\u003cp\u003eWe can call this system call ourselves from the user space as well, but it means too many low-level operations. Thankfully there are libraries that provide a high-level interface to the \u003ccode\u003ebpf()\u003c/code\u003e system call. One of them is \u003cchip text=\"Cilium\" href=\"https://cilium.io/\" icon=\"package\"\u003e\u003c/chip\u003e\u0026#39;s \u003cchip text=\"ebpf-go\" href=\"https://github.com/cilium/ebpf\" icon=\"github\"\u003e\u003c/chip\u003e package, which we will use in this example.\u003c/p\u003e\n\u003cp\u003eLet\u0026#39;s dive into some Go code.\u003c/p\u003e\n\u003cpre data-filename=\"main.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -type event ebpf hello_ebpf.c\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003emain\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003estopper\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSignal\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003esignal\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eNotify\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003estopper\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eInterrupt\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esyscall\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSIGTERM\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Allow the current process to lock memory for eBPF resources.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003erlimit\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eRemoveMemlock\u003c/span\u003e\u003cspan style=\"\"\u003e();\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatal\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eebpfObjects\u003c/span\u003e\u003cspan style=\"\"\u003e{}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eloadEbpfObjects\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatalf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;loading objects: %v\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eClose\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ekp\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003elink\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eKprobe\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ekprobeFunc\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eHelloExecve\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatalf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;opening kprobe: %s\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ekp\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eClose\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003erd\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eringbuf\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eNewReader\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eEvents\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatalf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;opening ringbuf reader: %s\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;
3color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003erd\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eClose\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe first line is a Go compiler directive, \u003ccode\u003ego:generate\u003c/code\u003e. Here we say to the Go compiler to run the \u003ccode\u003ebpf2go\u003c/code\u003e tool from the \u003ccode\u003egithub.com/cilium/ebpf/cmd/bpf2go\u003c/code\u003e package, and generate a Go file from the \u003ccode\u003ehello_ebpf.c\u003c/code\u003e file.\u003c/p\u003e\n\u003cp\u003eThe generated Go files will include the Go representation of the eBPF program, the types and structs we have defined in the eBPF program, etc. We then will use these representations inside our Go code to load the eBPF program into the kernel, and to interact with the BPF map.\u003c/p\u003e\n\u003cp\u003eWe then use the generated types to load the eBPF program (\u003ccode\u003eloadEbpfObjects\u003c/code\u003e), attach to the kprobe hook (\u003ccode\u003elink.Kprobe\u003c/code\u003e), and read the events from the BPF map (\u003ccode\u003eringbuf.NewReader\u003c/code\u003e). All of these functions use the generated types.\u003c/p\u003e\n\u003cp\u003eIt\u0026#39;s time to interact with the kernel side:\u003c/p\u003e\n\u003cpre data-filename=\"main.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"\"\u003estopper\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003erd\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eClose\u003c/span\u003e\u003cspan style=\"\"\u003e();\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatalf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;closing ringbuf reader: %s\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintln\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;Waiting for events..\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eevent\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eebpfEvent\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003erecord\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003erd\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eRead\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerrors\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eIs\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eringbuf\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eErrClosed\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintln\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;Received signal, exiting..\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;reading from reader: %s\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003econtinue\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebinary\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eRead\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ebytes\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eNewBuffer\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003erecord\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eRawSample\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebinary\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eLittleEndian\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eevent\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;parsing ringbuf event: %s\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003econtinue\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003eprocName\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eunix\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eByteSliceToString\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eevent\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eComm\u003c/span\u003e\u003cspan style=\"\"\u003e[:])\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;pid: %d\\tcomm: %s\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eevent\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePid\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eprocName\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWe start a goroutine to listen to the \u003ccode\u003estopper\u003c/code\u003e channel, which we defined in the previous Go snippet. This channel will be used to stop the program gracefully when we receive an interrupt signal.\u003c/p\u003e\n\u003cp\u003eWe then start a loop to read the events from the BPF map. We use the \u003ccode\u003eringbuf.Reader\u003c/code\u003e type to read the events, and then we parse the event data using the \u003ccode\u003ebinary.Read\u003c/code\u003e function, into the \u003ccode\u003eebpfEvent\u003c/code\u003e type, which is generated from the eBPF program.\u003c/p\u003e\n\u003cp\u003eWe then print the process ID and the command name of the process to the standard output.\u003c/p\u003e\n\u003ch3 id=\"running-the-program\"\u003eRunning the Program\u003c/h3\u003e\n\u003cp\u003eNow we are ready to run the program. First, we need to compile the eBPF program, and then run the user space program.\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ go generate\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCompiled /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfel.o\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eStripped /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfel.o\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eWrote /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfel.go\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCompiled /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfeb.o\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eStripped /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfeb.o\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eWrote /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x01-helloworld/ebpf_bpfeb.go\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ go build -o hello_ebpf\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWe first run the \u
3003ccode\u003ego generate\u003c/code\u003e command to compile the eBPF program, and then we run the \u003ccode\u003ego build\u003c/code\u003e command to compile the user space program.\u003c/p\u003e\n\u003cp\u003eThen we run the user space program:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003esudo ./hello_ebpf\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:20:54 Waiting \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e events..\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eI\u0026#39;m running this program inside a VM in \u003cchip text=\"Lima\" href=\"https://github.com/lima-vm/lima\" icon=\"github\"\u003e\u003c/chip\u003e, why not open another shell and see what will happen?\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003elimactl shell intro-ebpf\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eMeanwhile in the first shell:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3360\tcomm: sshd\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3360\tcomm: bash\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3361\tcomm: bash\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3362\tcomm: bash\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3363\tcomm: bash\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3366\tcomm: bash\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3367\tcomm: lesspipe\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3369\tcomm: lesspipe\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehello_ebpf: 01:22:22 pid: 3370\tcomm: bash\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eAs expected, we are seeing that the \u003ccode\u003esshd\u003c/code\u003e process is starting, and then the \u
3003ccode\u003ebash\u003c/code\u003e process is starting, and then the \u003ccode\u003elesspipe\u003c/code\u003e process is starting, and so on.\u003c/p\u003e\n\u003cp\u003eThis is a simple example of how we can use eBPF to trace the \u003ccode\u003eexecve\u003c/code\u003e system call, and then read the events from the BPF map in the user space. We wrote a fairly simple yet powerful program, and we intercepted the \u003ccode\u003eexecve\u003c/code\u003e system call without modifying the kernel source code or restarting the system.\u003c/p\u003e\n\u003ch2 id=\"ebpf-hooks-and-maps\"\u003eeBPF Hooks and Maps\u003c/h2\u003e\n\u003cp\u003eSo, what actually happened in the previous example? We attached the eBPF program to the \u003ccode\u003esys_execve\u003c/code\u003e system call using the \u003ccode\u003ekprobe\u003c/code\u003e hook, to run the \u003ccode\u003ehello_execve\u003c/code\u003e function wheneve the \u003ccode\u003esys_execve\u003c/code\u003e system call is called, right before the original system call is code is executed.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/ebpf-go/hello-world.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eeBPF is event driven, meaning that it expects us to attach the eBPF program to a specific code path in the kernel. These 
3code paths are called \u0026#34;hooks\u0026#34;, and there are several types of hooks that eBPF provides. The most common ones are:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003ekprobe\u003c/code\u003e, \u003ccode\u003ekretprobe\u003c/code\u003e: Trace kernel functions\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003euprobe\u003c/code\u003e, \u003ccode\u003euretprobe\u003c/code\u003e: Trace user space functions\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003etracepoint\u003c/code\u003e: Trace predefined tracepoints in the kernel\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003exdp\u003c/code\u003e: eXpress Data Path, used to filter and redirect network packets\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eusdt\u003c/code\u003e: User Statically Defined Tracing, used to trace user space functions in a more efficient way\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eThe hooks \u003ccode\u003ekprobe\u003c/code\u003e and \u003ccode\u003euprobe\u003c/code\u003e are used to invoke the attached eBPF programs \u003cstrong\u003ebefore\u003c/strong\u003e the function/syscall execution, and \u003ccode\u003ekretprobe\u003c/code\u003e and \u003ccode\u003euretprobe\u003c/code\u003e are used to invoke the attached eBPF programs \u003cstrong\u003eafter\u003c/strong\u003e the function/syscall execution.\u003c/p\u003e\n\u003cp\u003eWe also used a BPF map to store the events. BPF maps are data structures to store and communicate different kinds of data. We also use them for state management. There are too many types of BPF maps supported, and we use different types of maps for different purposes. Some of the most common BPF map types are:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ccode\u003eBPF_MAP_TYPE_HASH\u003c/code\u003e: A hash map\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eBPF_MAP_TYPE_ARRAY\u003c/code\u003e: An array\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eBPF_MAP_TYPE_RINGBUF\u003c/code\u003e: A ring buffer\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eBPF_MAP_TYPE_STACK\u003c/code\u003e: A stack\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eBPF_MAP_TYPE_QUEUE\u003c/code\u003e: A queue\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eBPF_MAP_TYPE_LRU_HASH\u003c/code\u003e: A least recently used hash map\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eSome of these map types also have per-CPU variants, such as \u003ccode\u003eBPF_MAP_TYPE_PERCPU_HASH\u003c/code\u003e, which is a hash map with a separate hash table for each CPU core.\u003c/p\u003e\n\u003ch2 id=\"one-step-further-tracing-incoming-ip-packets\"\u003eOne Step Further: Tracing Incoming IP Packets\u003c/h2\u003e\n\u003cp\u003eLet\u0026#39;s take a step further and write a more complex eBPF program. This time we will use the \u003ccode\u003eXDP\u003c/code\u003e hook to invoke the eBPF program right after the network interface sends a network packet to the kernel, \u003cstrong\u003eeven before the kernel processes the packet\u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/ebpf-go/xdp.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch3 id=\"writing-the-ebpf-program-1\"\u003eWriting the eBPF Program\u003c/h3\u003e\n\u003cp\u003eWe will write an eBPF program to count the number of incoming IP packets by the source IP address and port number, and then we will read the counts from the BPF map in the user space. We will parse the ethernet, IP and TCP/UDP headers of each packet, and store the counts of the valid TCP/UDP packets in the BPF map.\u003c/p\u003e\n\u003cp\u003eFirst, the eBPF program:\u003c/p\u003e\n\u003cpre data-filename=\"hello_ebpf.c\" data-language=\"c\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#include\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026#34;vmlinux.h\u0026#34;
3\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#include\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;bpf/bpf_helpers.h\u0026gt;\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#include\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;bpf/bpf_endian.h\u0026gt;\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e#define MAX_MAP_ENTRIES 100\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e/* Define an LRU hash map for storing packet count by source IP and port */\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e__uint\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eBPF_MAP_TYPE_LRU_HASH\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e__uint\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003emax_entries\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eMAX_MAP_ENTRIES\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e__type\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eu64\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// source IPv4 addresses and port tuple\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e__type\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003evalue\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eu32\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// packet count\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003exdp_stats_map\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eSEC\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;.maps\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eLike the first example, we will include the \u003ccode\u003evmlinux.h\u003c/code\u003e and BPF helper headers. We also define a map, \u003ccode\u003exdp_stats_map\u003c/code\u003e, to store the \u003ccode\u003eIP:ports\u003c/code\u003e and packet count information. We wil then populate this map inside the hook function and read the contents in the user space program.\u003c/p\u003e\n\u003cp\u003eWhat I mean by \u003ccode\u003eIP:ports\u003c/code\u003e is basically a \u003ccode\u003eu64\u003c/code\u003e value, packed with the source IP, source port and the destination port. The IP address (\u003cstrong\u003eIPv4\u003c/strong\u003e, specifically) is 32-bits long, and each port number is 16-bits long, so we need exactly 64 bits to store all three - that\u0026#39;s why we are using \u003ccode\u003eu64\u003c/code\u003e here. We are only processing the ingress (incoming packets) here so we won\u0026#39;t need to store the destination IP address.\u003c/p\u003e\n\u003cp\u003eDifferent from the last example we now used \u003ccode\u003eBPF_MAP_TYPE_LRU_HASH\u003c/code\u003e as the map type. This type of map lets us store a \u003ccode\u003e(key, value)\u003c/code\u003e pair as a hashmap with LRU variant.\u003c/p\u003e\n\u003cp\u003eSee how we defined the map here, we explicitly set the number of maximum entries, and the types of the map key and values. For key we are using a 64-bit unsigned integer and for value a 32-bit unsigned integer.\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003eThe maximum value of \u003ccode\u003eu32\u003c/code\u003e is \u003ccode\u003e2^32 - 1\u003c/code\u003e, which is more than enough packets for the sake of this example.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eTo learn the IP address and port number, we first need to parse the packet and read the \u003cstrong\u003eethernet, IP and then TCP/UDP headers\u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003eAs XDP is placed right after the network interface card, we will be given the \u003cstrong\u003eraw packet data in bytes\u003c/strong\u003e, so we will need to manually walk on the byte array and unmarshal the ethernet, IP and TCP/UDP headers.\u003c/p\u003e\n\u003cp\u003eHopefully, we have all the header definitions (\u003ccode\u003estruct ethhdr\u003c/code\u003e, \u003ccode\u003estruct iphdr\u003c/code\u003e, \u003ccode\u003estruct tcphdr\u003c/code\u003e, and \u003ccode\u003estruct udphdr\u003c/code\u003e),  inside \u003ccode\u003evmlinux.h\u003c/code\u003e header file. We will use these structs to extract the IP address and port number information in a separate function, \u003ccode\u003eparse_ip_packet\u003c/code\u003e:\u003c/p\u003e\n\u003cpre data-filename=\"hello_ebpf.c\" data-language=\"c\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#define ETH_P_IP\t\t0x0800\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e/* Internet Protocol packet\t*/\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e#define PARSE_SKIP \t\t\t0\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#define PARSED_TCP_PACKET\t1\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#define PARSED_UDP_PACKET\t2\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estatic\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e__always_inline\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eparse_ip_packet\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003exdp_md\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003ectx\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eu64\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eip_metadata\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003edata_end\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003elong\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003ectx\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003edata_end\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e     \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003elong\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003ectx\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// First, parse the ethernet header.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eethhdr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eeth\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e((\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003eeth\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata_end\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSE_SKIP\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eeth\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003eh_proto\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebpf_htons\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eETH_P_IP\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// The protocol is not IPv4, so we can\u0026#39;t parse an IPv4 source address.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSE_SKIP\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Then parse the IP header.\n\u003c/span\u003e\u003c/s
3pan\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eiphdr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003eeth\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e((\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata_end\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSE_SKIP\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;
3color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eu16\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esrc_port\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edest_port\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eretval\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003eprotocol\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e==\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eIPPROTO_TCP\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003etcphdr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003etcp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003esizeof\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e((\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003etcp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata_end\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e34\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSE_SKIP\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e35\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e36\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003esrc_port\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebpf_ntohs\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003etcp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e37\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003edest_port\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebpf_ntohs\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003etcp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003edest\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e38\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003eretval\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSED_TCP_PACKET\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e39\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eelse\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003eprotocol\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e==\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eIPPROTO_UDP\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e40\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eudphdr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eudp\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003esizeof\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e41\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e((\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003evoid\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003eudp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata_end\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e42\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSE_SKIP\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e43\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e44\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003esrc_port\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebpf_ntohs\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eudp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e45\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003edest_port\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebpf_ntohs\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eudp\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003edest\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e46\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003eretval\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSED_UDP_PACKET\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e47\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eelse\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// The protocol is not TCP or UDP, so we can\u0026#39;t parse a source port.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e49\u003c/span\u
3003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSE_SKIP\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e50\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e51\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e52\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Return the (source IP, destination IP) tuple in network byte order.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e53\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// |\u0026lt;-- Source IP: 32 bits --\u0026gt;|\u0026lt;-- Source Port: 16 bits --\u0026gt;\u0026lt;-- Dest Port: 16 bits --\u0026gt;|\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e54\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eip_metadata\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e((\u003c/span\u003e\u003cspan style=\"\"\u003eu64\u003c/span\u003e\u003cspan style=\"\"\u003e)(\u003c/span\u003e\u003cspan style=\"\"\u003eip\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u0026gt;\u003c/span\u003e\u003cspan style=\"\"\u003esaddr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e((\u003c/span\u003e\u003cspan style=\"\"\u003eu64\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003esrc_port\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eu64\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003edest_port\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e55\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eretval\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e56\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe function:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eChecks if the packet has a valid ethernet header, IP header, and TCP or UDP header. These 
3checks are done by using the \u003ccode\u003eh_proto\u003c/code\u003e of \u003ccode\u003estruct ethhdr\u003c/code\u003e and \u003ccode\u003eprotocol\u003c/code\u003e of \u003ccode\u003estruct iphdr\u003c/code\u003e. Each header stores the protocol of the inner packet it wraps.\u003c/li\u003e\n\u003cli\u003eExtracts the IP address from the IP header and port number from the TCP/UDP headers and forms an \u003ccode\u003eIP:ports\u003c/code\u003e tuple inside a 64-bit unsigned integer (\u003ccode\u003eu64\u003c/code\u003e)\u003c/li\u003e\n\u003cli\u003eReturns a code to tell the caller whether the packet is a TCP packet, a UDP packet, or else (\u003ccode\u003ePARSE_SKIP\u003c/code\u003e)\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eNotice the \u003ccode\u003e__always_inline\u003c/code\u003e at the beginning of the function signature. This tells the compiler to always inline this funcion as static code, which saves us from performing a function call.\u003c/p\u003e\n\u003cp\u003eNow it\u0026#39;s time to write the hook function and use \u003ccode\u003eparse_ip_packet\u003c/code\u003e:\u003c/p\u003e\n\u003cpre data-filename=\"hello_ebpf.c\" data-language=\"c\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eSEC\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;xdp\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003exdp_prog_func\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003exdp_md\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003ectx\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eu64\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eip_meta\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eretval\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eparse_ip_packet\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ectx\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eip_meta\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eretval\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePARSED_TCP_PACKET\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eXDP_PASS\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eu32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003epkt_count\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ebpf_map_lookup_elem\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003exdp_stats_map\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eip_meta\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!\u003c/span\u003e\u003cspan style=\"\"\u003epkt_count\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// No entry in the map for this IP tuple yet, so set the initial value to 1.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003eu32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003einit_pkt_count\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003ebpf_map_update_elem\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003exdp_stats_map\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eip_meta\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003einit_pkt_count\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eBPF_ANY\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eelse\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Entry already exists for this IP tuple,\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// so increment it atomically.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e__sync_fetch_and_add\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epkt_count\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eXDP_PASS\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe \u003ccode\u003exdp_prog_func\u003c/code\u003e is fairly simple as we already coded most of the program logic inside \u003ccode\u003eparse_ip_packet\u003c/code\u003e. What we do here is:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eParse the packet using \u003ccode\u003eparse_ip_packet\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eSkip counting if it\u0026#39;s not a TCP or UDP packet by returning \u003ccode\u003eXDP_PASS\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003eLookup the \u003ccode\u003eIP:ports\u003c/code\u003e tuple in BPF map keys using the \u003ccode\u003ebpf_map_lookup_elem\u003c/code\u003e helper function\u003c/li\u003e\n\u003cli\u003eSet the value to one if the \u003ccode\u003eIP:ports\u003c/code\u003e tuple is seen the first time, else increment it by one. The \u003ccode\u003e__sync_fetch_and_add\u003c/code\u003e is an LLVM built-in here\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eFinally we attach this function to the \u003ccode\u003eXDP\u003c/code\u003e subsystem b
3y using the \u003ccode\u003eSEC(\u0026#34;xdp\u0026#34;)\u003c/code\u003e macro.\u003c/p\u003e\n\u003ch3 id=\"writing-the-user-space-program-1\"\u003eWriting the User Space Program\u003c/h3\u003e\n\u003cp\u003eIt\u0026#39;s time to dive into Go code again.\u003c/p\u003e\n\u003cpre data-filename=\"main.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e//go:generate go run github.com/cilium/ebpf/cmd/bpf2go ebpf xdp.c\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eifaceName\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eflag\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;iface\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;network interface to attach XDP program to\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003emain\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSetPrefix\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;packet_count: \u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSetFlags\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eLtime\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eLshortfile\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eflag\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eParse\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Subscribe to signals for terminating the program.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003estop\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSignal\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003esignal\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eNotify\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003estop\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eInterrupt\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esyscall\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSIGTERM\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eiface\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enet\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eInterfaceByName\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eifaceName\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatalf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;network iface lookup for %q: %s\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eifaceName\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Load pre-compiled programs and maps into the kernel.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eebpfObjects\u003c/span\u003e\u003cspan style=\"\"\u003e{}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eloadEbpfObjects\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatalf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;loading objects: %v\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eClose\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;
3color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Attach the program.\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003el\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003elink\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eAttachXDP\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003elink\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eXDPOptions\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003eProgram\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eXdpProgFunc\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003eInterface\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eiface\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eIndex\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e})\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e34\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatalf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;could not attach XDP program: %s\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e35\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e36\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003el\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eClose\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e37\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e38\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;Attached XDP program to iface %q (index %d)\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eiface\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eiface\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eIndex\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e39\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e40\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eHere we first load the generated eBPF program and map using the \u003ccode\u003eloadEbpfObjects\u003c/code\u003e function. Then we attach the program to the specified network interface using the \u003ccode\u003elink.AttachXDP\u003c/code\u003e function. Similar to the previous example we used a channel to listen to the interrupt signal and close the program gracefully.\u003c/p\u003e\n\u003cp\u003eNext, we will read the map contents in every second and print the packet counts to the standard output:\u003c/p\u003e\n\u003cpre data-filename=\"main.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eticker\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003etime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eNewTicker\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003etime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSecond\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eticker\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eStop\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eselect\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ecase\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"\"\u003estop\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eXdpStatsMap\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eClose\u003c/span\u003e\u003cspan style=\"\"\u003e();\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eFatalf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;closing map reader: %s\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ecase\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"\"\u003eticker\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eC\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eparsePacketCounts\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eobjs\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eXdpStatsMap\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eexcludeIPs\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;Error reading map: %s\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003econtinue\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;Map contents:\\n%s\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"\"\u003esrv\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSubmit\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWe will use a utility function, \u003ccode\u003eparsePacketCounts\u003c/code\u003e, to read the map contents and parse the packet counts. This function will read the map contents in a loop.\u003c/p\u003e\n\u003cp\u003eAs we will be given raw bytes from the map, we will need to parse the bytes and convert them into a human-readable format. We will define a new type \u003ccode\u003ePacketCounts\u003c/code\u003e to store the parsed map contents.\u003c/p\u003e\n\u003cpre data-filename=\"main.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eIPMetadata\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eSrcIP\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"\"\u003enetip\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eAddr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eSrcPort\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint16\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eDstPort\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint16\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eIPMetadata\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eUnmarshalBinary\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebyte\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eerror\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eErrorf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;invalid data length: %d\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSrcIP\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eUnmarshalBinary\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e]);\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSrcPort\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euint16\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e])\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euint16\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e])\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eDstPort\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euint16\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e])\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;\u0026lt;\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euint16\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e])\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eIPMetadata\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;%s:%d =\u0026gt; :%d\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSrcIP\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSrcPort\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003et\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eDstPort\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePacketCounts\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ePacketCounts\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ekeys\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ek\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;
3color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003ekeys\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ekeys\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ek\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003esort\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eStrings\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ekeys\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esb\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003estrings\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eBuilder\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ek\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ekeys\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e34\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003esb\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWriteString\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;
3%s\\t| %d\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ek\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003ek\u003c/span\u003e\u003cspan style=\"\"\u003e]))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e35\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e36\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e37\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esb\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e38\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWe defined a new type, \u003ccode\u003eIPMetadata\u003c/code\u003e, to store the \u003ccode\u003eIP:ports\u003c/code\u003e tuple. We also defined a \u003ccode\u003eUnmarshalBinary\u003c/code\u003e method to parse the raw bytes and convert them into a human-readable format. We also defined a \u003ccode\u003eString\u003c/code\u003e method to print the \u003ccode\u003eIP:ports\u003c/code\u003e tuple in a human-readable format.\u003c/p\u003e\n\u003cp\u003eWe then defined a new type, \u003ccode\u003ePacketCounts\u003c/code\u003e, to store the parsed map contents. We also defined a \u003ccode\u003eString\u003c/code\u003e method to print the map contents in a human-readable format.\u003c/p\u003e\n\u003cp\u003eFinally, we will use the \u003ccode\u003ePacketCounts\u003c/code\u003e type to parse the map contents and print the packet counts:\u003c/p\u003e\n\u003cpre data-filename=\"main.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eparsePacketCounts\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eebpf\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMap\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eexcludeIPs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebool\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ePacketCounts\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eerror\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eIPMetadata\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003eval\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint32\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003ecounts\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ePacketCounts\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eiter\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003em\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eIterate\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eiter\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eNext\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eval\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eok\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eexcludeIPs\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSrcIP\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e()];\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eok\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003econtinue\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\t\u003c/span\u003e\u003cspan style=\"\"\u003ecounts\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003ekey\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e()]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eval\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ecounts\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eiter\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eErr\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003ch3 id=\"running-the-program-1\"\u003eRunning the Program\u003c/h3\u003e\n\u003cp\u003eWe first need to compile the eBPF program and then run the user space program.\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ go generate\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCompiled /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfel.o\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eStripped /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfel.o\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eWrote /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfel.go\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eCompiled /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfeb.o\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan sty
3le=\"\"\u003e\u003cspan style=\"\"\u003eStripped /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfeb.o\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eWrote /Users/sazak/workspace/gocode/src/github.com/ozansz/intro-ebpf-with-go/0x03-packet-count/ebpf_bpfeb.go\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ go build -o packet_count\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eNow we can run it:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ sudo ./packet_count --iface eth0\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epacket_count: 22:11:10 main.go:107: Attached XDP program to iface \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;eth0\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eindex 2\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epacket_count: 22:11:10 main.go:132: Map contents:\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e192.168.5.2:58597 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :22\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e51\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epacket_count: 22:11:11 main.go:132: Map contents:\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e192.168.5.2:58597 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :22\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e52\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epacket_count: 22:11:11 main.go:132: Map contents:\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e192.168.5.2:58597 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :22\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e53\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe packets coming to the port \u003ccode\u003e22\u003c/code\u003e from the IP address \u003ccode\u003e192.168.5.2\u003c/code\u003e are the SSH packets, as I am running this program inside a VM and I am SSHing into.\u
3003c/p\u003e\n\u003cp\u003eLet\u0026#39;s run \u003ccode\u003ecurl\u003c/code\u003e inside the VM in another terminal, and see what will happen:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ curl https://www.google.com/\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eMeanwhile in the first terminal:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epacket_count: 22:14:07 main.go:132: Map contents:\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e172.217.22.36:443 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :38324\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e192.168.5.2:58597 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :22\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e551\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epacket_count: 22:14:08 main.go:132: Map contents:\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e172.217.22.36:443 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :38324\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e192.168.5.2:58597 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :22\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e552\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epacket_count: 22:14:08 main.go:132: Map contents:\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e172.217.22.36:443 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :38324\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e192.168.5.2:58597 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :22\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e570\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epacket_count: 22:14:09 main.go:132: Map contents:\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e172.217.22.36:443 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :38324\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e192.168.5.2:58597 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e\u0026gt; :22\t\u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e571\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWe are seeing the packets coming to the port \u003ccode\u003e38324\u003c/code\u003e from the IP address \u003ccode\u003e172.217.22.36\u003c/code\u003e are the packets coming from the \u003ccode\u003ecurl\u003c/code\u003e command.\u003c/p\u003e\n\u003ch2 id=\"conclusion\"\u003eConclusion\u003c/h2\u003e\n\u003cp\u003eeBPF is powerful in many ways and I think it\u0026#39;s a good technology to invest time in, especially you are in systems programming, observability or security. In this article we have seen what eBPF is, how it works, and how we 
3can start using it with Go.\u003c/p\u003e\n\u003cp\u003eI hope you enjoyed this article and learned something new. If you have any questions, feel free to \u003ca href=\"https://twitter.com/oznszk\" target=\"_blank\"\u003eping\u003c/a\u003e me.\u003c/p\u003e\n\u003ch2 id=\"resources\"\u003eResources\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003eSystems Performance, Brendan Gregg\u003c/li\u003e\n\u003cli\u003eLearning eBPF, Liz Rice\u003c/li\u003e\n\u003cli\u003edocs.kernel.org\u003c/li\u003e\n\u003cli\u003eebpf.io\u003c/li\u003e\n\u003cli\u003ecilium.io\u003c/li\u003e\n\u003cli\u003eiovisor.org\u003c/li\u003e\n\u003cli\u003ebrendangregg.com\u003c/li\u003e\n\u003c/ul\u003e\n"])</script>
3<script>self.__next_f.push([1,"2b:T5256,"])</script>
3<script>self.__next_f.push([1,"\n\nWe use slices everywhere in Go. With maps, they are fundamental data types we use to store data. Today we will dive into the internals and see **how slices work under the hood**.\n\n\u003e!char![sazak-explain] At the end of the article, you will find [exercises](#exercises) to test your knowledge. Enjoy!\n\n## What is a slice?\n\nIn Go, **slice is an abstraction over arrays**. It consists of a pointer to the backing array, the length of the slice, and its capacity. The length is the **number of elements in the slice**, while the capacity is the **number of elements in the underlying array**.\n\nHere's how a slice is defined in [Go runtime](https://github.com/golang/go/blob/cff7267e0d77f02d582c613c272b6f8ebf1c0412/src/runtime/slice.go#L15):\n\n```go filename=\"go/src/runtime/slice.go\"\ntype slice struct {\n\tarray unsafe.Pointer\n\tlen   int\n\tcap   int\n}\n```\n\nThe `array` field is a pointer to the (first element of the) backing array. The `len` field is the length of the slice, denoting the number of items in the slice, and the `cap` field is the capacity of the slice. Capacity stores the number of elements in the backing array, and it is the maximum number of elements the slice can hold without reallocating the backing array.\n\nThere are multiple ways to create a slice, and some of them differ in how they set the length and capacity of the slice. Let's say we have the following slice definition:\n\n```go\ns1 := []int32{1, 2, 3, 4, 5}\n```\n\nThis creates an `int32` slice `s1` with some initial values. The length of the slice is 5, as you can see from the number of elements in the slice definition. The capacity is also set to 5 by default (we did not specify a different capacity), and the backing array is filled with the given values.\n\nBelow is how the backing array looks like in memory. Numbers inside the cells represent values of items in the array, and the gray cells represent the memory that does not belong to the slice. See how both length and capacity is `5`, and slice points (ptr = `0x0100`) at the address of the first element of the array (`0x0100`).\n\n\u003cgoslice name=\"s1 []int32\" cap=\"5\" items=\"1,2,3,4,5\" ptr=\"0x0100\" startaddress=\"0x0100\" bytesperblock=\"4\"\u003e\u003c/goslice\u003e\n\n## `make`-ing of a slice\n\nWe can specify different lengths and capacities for a slice by using the `make` built-in function. The `make` function accepts two to three arguments for slice allocation: the type of the slice, the length, and the capacity. If the capacity is not given, **it defaults to the length**.\n\n```go\ns2 := make([]int, 5, 10)\n```\n\nThe code above allocates a 10-capacity array and creates a slice `s2`, which points to this array with a length of 5. The capacity of the slice is also set to 10.\n\n`make` also fills the array with the **zero values**[^1] of the item type. In this case, the zero value of `int` is `0`.\n\n\u003cgoslice name=\"s2 []int\" cap=\"10\" ptr=\"0x1234\" items=\"0,0,0,0,0\" show-unused-as-zero=\"1\"\u003e\u003c/goslice\u003e\n\n\u003e!char![sazak-explain] Notice that all items of the backing array are filled with zero values, not only the `len` items of the slice. From now on I won't show the zeroes in the unused parts of the backing array to keep the visuals more readable.\n\nIf we want to populate this slice with some values, we can set specific indexes:\n\n```go\nfor i := range s2 {\n    s2[i] = i * 2\n}\n```\n\nThis will set the values of the slice to **0, 2, 4, 6, 8**, by using `range`[^2] to iterate over the indexes of the slice.\n\n\u003cgoslice name=\"s2 []int\" cap=\"10\" ptr=\"0x1234\" items=\"0,2,4,6,8\" hidelegend=\"1\"\u003e\u003c/goslice\u003e\n\nNotice how the slice is still pointing to the same underlying array, but the initial values are changed. Also the length and capacity of the slice are still the same.\n\n\u003e!char![beaver-question] Why didn't `range` iterate over all indexes within the capacity (10) of the array?\n\nGood question. Let's see what happens if we try to set a value to an index that is out of the slice's length?\n\n```go\ns2[8] = 16\n```\n\nIf we run the assignment above, Go runtime will panic with the message below:\n\n```bash\npanic: runtime error: index out of range [8] with length 5\n```\n\nThe capacity is not the space Go gives us to use, it's the maximum number of the elements slice can hold **without reallocating the backing array**. If we try to access or set a value to an index that is out of the slice's length, Go will panic.\n\nOkay, so what if we add more elements by simply `append`ing them to the slice?\n\n```go\ns2 = append(s2, []int{10, 12, 14, 16, 18}...)\n```\n\nThe built-in function `append` works by pushing these items to the end of the slice, starting by the `len`-th item. Both the length and the capacity of the slice are **10** now.\n\n\u003cgoslice name=\"s2 []int\" cap=\"10\" items=\"0,2,4,6,8,10,12,14,16,18\" hidelegend=\"1\"\u003e\u003c/goslice\u003e\n\n## Growing the slice\n\nWhat do you think will happen if we add one more item to the end of the slice now, as it's capacity is already full?\n\nIf we have a full slice (`len` == `cap`), then Go runtime will **reallocate** the backing array, copy the existing elements to the new array, and append the new element.\n\n\u003e This was what I meant b
3y \"slices are abstraction over arrays\". Go abstracts the memory management from the developer so you don't need to think if the backing array is full, or how much of an extra capacity should I allocate every time. In C for example, you would need to use `calloc` or `realloc`[^5] to handle the reallocation of the memory, manually.\n\nThe new capacity will be **double the previous capacity** until the slice reaches a certain capacity threshold. After that, the capacity will **increase monotonically with different growth factors**.\n\nYou can see in other (older) resources that the capacity increases by 25% after 1024 items, but [in 2021 the growth formula was changed](https://github.com/golang/go/commit/2dda92ff6f9f07eeb110ecbf0fc2d7a0ddd27f9d) to be smoother.\n\nBelow is the _theoretical_[^4] growth factors by certain capacity thresholds:\n\n| Starting Capacity | Growth Factor |\n|-------------------|---------------|\n| 256               | 2.0           |\n| 512               | 1.63          |\n| 1024              | 1.44          |\n| 2048              | 1.35          |\n| 4096              | 1.30          |\n\nSo if we add one more item at the end of the slice `s2` we had, the `append` function will allocate a new array with a capacity of 20, copy the existing elements to the new array, and append the new element.\n\n```go\ns2 = append(s2, 20)\n```\n\n\u003cgoslice name=\"old array\" cap=\"10\" ptr=\"0x1234\" items=\"0,2,4,6,8,10,12,14,16,18\" hidelegend=\"1\" slim=\"1\" theme=\"red\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\n\n\u003cgoslice name=\"s2 []int\" cap=\"20\" ptr=\"0x2020\" items=\"0,2,4,6,8,10,12,14,16,18,20\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\n\nNotice how `s2` now points to a **different backing array** with a capacity of 20. The old array at memory address `0x1234` will be **garbage collected by the Go runtime**[^3] if no other slice points to it (references it).\n\n\u003e!char![sazak-explain] Keep in mind that the memory addresses I use in examples are just for demonstration purposes. In reality, the memory addresses are longer 32-bit or 64-bit integers and can change between runs.\n\n\u003cnewslettercard\u003e\u003c/newslettercard\u003e\n\n### A note on append function\n\nIn many places you will see the `append` function used with the same slice as the first argument, like `sl = append(sl, \"hello\")`.\n\nThis is because when the slice given exceeds the capacity with the given new elements and `append` needs to internally reallocate a new backing array, the new slice structure pointing to the new array will be returned from the function. The slice given in the first argument, however, will not be updated in-place.\n\nThat's why if you want the update to be reflected to the slice, you need to assign the result of the `append` function to the slice, as how `append` is used for most of the time.\n\nIt's good to know how using different variables for the result of the `append` function can affect the slices. Consider the following example:\n\n```go\ndogs := []string{\"bulldog\", \"poodle\", \"beagle\"}\nmoreDogs := append(dogs, \"husky\")\nmoreAndMoreDogs := append(moreDogs, \"shiba inu\")\n```\n\nBefore the append, `dogs` has both length and capacity of 3, and points to the backing array with the elements `\"bulldog\"`, `\"poodle\"`, and `\"beagle\"`. As `dogs` is at full capacity, the first append call will return a new slice, pointing to a new backing array filled with the initial elements and the new element `\"husky\"`, with a capacity of 6.\n\nNow `moreDogs` points to the new backing array, and `dogs` still points to the old backing array. In the second append call, we would not expect another reallocation happening, as the `moreDogs` slice has enough capacity to hold the new element `\"shiba inu\"`. So the `moreAndMoreDogs` slice will point to the same backing array as `moreDogs`.\n\n## Slicing\n\nWe can create a new slice from an existing slice by using the slicing expression. It's syntactically similar to what Python does with lists.\n\nWhen we slice another slice, the new slice will point to the same backing array, but the length and capacity will be different, **depending on the range we specify**. The range is inclusive for the start index and exclusive for the end index.\n\n```go \ns1 := []byte{16, 32, 48, 64, 80}\ns2 := s1[1:3]\n\nfmt.Printf(\"s1: %v, len: %d, cap: %d\\n\", s1, len(s1), cap(s1))\nfmt.Printf(\"s2: %v, len: %d, cap: %d\\n\", s2, len(s2), cap(s2))\n```\n\nThe code above will output:\n\n```bash\ns1: [16 32 48 64 80], len: 5, cap: 5\ns2: [32 48], len: 2, cap: 4\n```\n\nLength of `s2` is `2`, as the range `[1:3]` includes the elements at indexes `1` and `2`. The capacity will be the capacity of `s1` minus the start index, which is `4`.\n\nIf we look at the pointers of the slices, we will see that they **don't** point to the same memory address:\n\n```go \nfmt.Printf(\"s1: %p\\n\", s1)\nfmt.Printf(\"s2: %p\\n\", s2)\n```\n\n```bash\ns1: 0x0010\ns2: 0x0011\n```\n\nNotice how the pointer of `s2` is one byte ahead of the pointer of `s1`. This is because the slice `s2` starts from the second element of the slice `s1`, and as each element in slice `s1` is one byte long (`byte`), the second item is one byte ahead of the first item.\n\n\u003cgoslice name=\"s1 []byte\" cap=\"5\" items=\"16,32,48,64,80\" ptr=\"0x0010\" startaddress=\"0x0010\" theme=\"blue\" hidelegend=\"1\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\n\u003cgoslice name=\"s2 []byte\" cap=\"4\" items=\"32,48\" ptr=\"0x0011\" startaddress=\"0x0011\" theme=\"purple\" hidelegend=\"1\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\n\nLet's play a little bit on our new slice `s2`. Can you guess the outcome of the following code?\n\n```go\ns2 = append(s2, 100, 101)\n```\n\nRemember that `s2` points to the same backing array as `s1`, and has enough capacity (4) to hold two more elements. So the new slice `s2` will be:\n\n\u003cgoslice name=\"s2 []byte\" cap=\"4\" items=\"32,48,100,101\" ptr=\"0x0011\" theme=\"purple\" hidelegend=\"1\"\u003e\u003c/goslice\u003e\n\nAnd, as the slice `s1` still points to the same backing array, it will look like the following in memory:\n\n\u003cgoslice name=\"s1 []byte\" cap=\"5\" items=\"16,32,48,100,101\" ptr=\"0x0010\" theme=\"blue\" hidelegend=\"1\"\u003e\u003c/goslice\u003e\n\nNotice how the slice `s1` is also updated, as it points to the same backing array as `s2`.\n\nNow that `s2` is at full capacity, you know that if we append one more element to `s2`, the backing array will be reallocated, and the slice will point to a new array.\n\n```go\ns2 = append(s2, 102)\n```\n\n\u003cgoslice name=\"s2 []byte\" cap=\"8\" items=\"32,48,100,101,102\" ptr=\"0x0050\" startaddress=\"0x0050\" theme=\"purple\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\n\n`s2` now points to a new backing array in a different memory address (`0x0050`), with a capacity of `8`. \n\n\u003e!char![beaver-question-3] What will happen to `s1` in this case?\n\nNormally the old array would be garbage collected, but in this case, `s1` still points to it, so it will not be garbage collected.\n\n\u003cgoslice name=\"s1 []byte\" cap=\"5\" items=\"16,32,48,100,101\" ptr=\"0x0010\" startaddress=\"0x0010\" theme=\"blue\"\u003e\u003c/goslice\u003e\n\nSee how appending to a slice which shares the same backing array with another slice **can affect both slices, until one exceeds its capacity** and it has a new reallocated backing array.\n\n### Specifying the capacity\n\nDifferent slices using the same backing array may cause implicit problems sometimes. The new slice used in a function or in another part of the code appending new elements to the slice may cause the original slice to change its contents, which may not be the desired behavior.\n\n\u003e!char![beaver-question] How can I prevent this behavior then?\n\nGo allows us to specify the capacity of the new slice by using a **third argument** in the slicing expression. This is useful when we want to limit the capacity of the new slice, to prevent the slice to change the contents **out of the specified boun
3ds** of the backing array.\n\nIf we would like to create a new slice from `s1` starting from the second element and ending at the third element, with a capacity of 2, we can do it like this:\n\n```go\ns3 := s1[1:3:3]\n```\n\nThis will create a new slice `s3` with a length of 2 (indexes `1` and `2`), a capacity of 2 as specified, and it will point to the second item (index `1`) of the same backing array as `s1`. Notice that the third argument is **not** the capacity of the new slice, but in which index the capacity should end.\n\nNow if we append a to `s3`, as `s3` is at capacity (`len(s3)` == `cap(s3)` == `2`) it will cause a reallocation of the used parts of the backing array, but it will not affect the contents of `s1`.\n\n```go\ns1 = []byte{16, 32, 48, 64, 80}\ns3 := s1[1:3:3]\ns3 = append(s3, 200, 201)\n```\n\n\u003cgoslice name=\"s3 []byte\" cap=\"8\" items=\"32,48,200,201\" ptr=\"0x0060\" startaddress=\"0x0060\" theme=\"yellow\" hidelegend=\"1\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\n\u003cgoslice name=\"s1 []byte\" cap=\"5\" items=\"16,32,48,64,80\" ptr=\"0x0010\" startaddress=\"0x0010\" theme=\"blue\"\u003e\u003c/goslice\u003e\n\nNotice how the ptr of `s3` is different as it now points to a new backing array with length of 4 (2 old elements copied and two newly appended), and capacity of 4 (twice as the old capacity). The contents of `s1` after the index `2` are not affected by the append operation on `s3`.\n\nThe whole code snippet is below:\n\n```go filename=\"go.dev/play/p/DrKX2QE24QP\"\ns1 := []byte{16, 32, 48, 64, 80}\ns2 := s1[1:3]\n\ns2 = append(s2, 100, 101)\ns2 = append(s2, 102)\n\nfmt.Printf(\"s1: %v, len: %d, cap: %d\\n\", s1, len(s1), cap(s1))\nfmt.Printf(\"s2: %v, len: %d, cap: %d\\n\\n\", s2, len(s2), cap(s2))\n\ns1 = []byte{16, 32, 48, 64, 80}\ns3 := s1[1:3:3]\n\nfmt.Printf(\"s3 initially: %v, len: %d, cap: %d\\n\\n\", s3, len(s2), cap(s3))\n\ns3 = append(s3, 200, 201)\n\nfmt.Printf(\"s1: %v, len: %d, cap: %d\\n\", s1, len(s1), cap(s1))\nfmt.Printf(\"s3: %v, len: %d, cap: %d\\n\", s3, len(s2), cap(s3))\n```\n\n```bash\ns1: [16 32 48 100 101], len: 5, cap: 5\ns2: [32 48 100 101 102], len: 5, cap: 8\n\ns3 initially: [32 48], len: 5, cap: 2\n\ns1: [16 32 48 64 80], len: 5, cap: 5\ns3: [32 48 200 201], len: 5, cap: 8\n```\n\n\u003e Specifying the slice capacity is an option we can use to limit the new slice's capacity and actions on the items of backing array, to prevent unexpected changes in the original slice.\n\n## Conclusion\n\nSlices are a powerful abstraction in Go, allowing us to work with arrays in a more flexible way. Understanding how slices work internally helps us write more efficient and less error-prone code. I hope this article helped you gain insight on how slices work under the hood, and when to pay attention to implementation details to prevent unexpected behavior.\n\nThere will be more of these visual guides to Go internals in the future, and there _may_ be a part two to this article.\n\nIf you have any questions or feedback, feel free to reach out to me on [Twitter](https://twitter.com/oznszk). Until next time, stay tuned.\n\n## Exercises\n\n\u003cgocodequestion difficulty=\"easy\" playlink=\"https://go.dev/play/p/5mF1pW6SqDo\" parsetextfrom=\"questions/visual-go-slices/01.md\"\u003e\n    Length will be 10 as there will be 10 items in the slice at the end. The capacity will be doubled after we add the 8th element, so it will be 16.\n    \u003cgoslice name=\"s1 []int\" cap=\"16\" items=\"1,3,5,7,9,11,100,23,5,-23\" hidelegend=\"1\" slim=\"1\" theme=\"purple\"\u003e\u003c/goslice\u003e\n\u003c/gocodequestion\u003e\n\n\u003cgocodequestion difficulty=\"easy\" playlink=\"https://go.dev/play/p/O76cT6PnNPx\" parsetextfrom=\"questions/visual-go-slices/03.md\"\u003e\n    The make built-in function allocates the backing array with a length of 10, which is also the capacity of the slice. The length of the slice is 5, and the backing array is filled with the zero values of the element type.\u003cbr\u003e\u003cbr\u003eAs the zero value of the function type is nil, no matter the function signature, the slice will be filled with 5 nil values.\
3n    \u003cgoslice name=\"funcSl\" cap=\"10\" items=\"nil,nil,nil,nil,nil\" hidelegend=\"1\" slim=\"1\" theme=\"red\"\u003e\u003c/goslice\u003e\n\u003c/gocodequestion\u003e\n\n\u003cgocodequestion difficulty=\"medium\" playlink=\"https://go.dev/play/p/MrPYo1CRJ2w\" parsetextfrom=\"questions/visual-go-slices/02.md\"\u003e\n    After the first two index assignments, s1 will have \"A\" and \"B\" as first two items.\u003cbr\u003e\u003cbr\u003eWhen we append \"C\" to s1, the append function will not reallocate the backing array as s1 is not at capacity, and append will return a slice pointing to the same backing array with a length of 3 and capacity of 5, which is assigned to s2.\u003cbr\u003e\u003cbr\u003eThe last append to s2 will not reallocate as well, as the capacity is enough to hold the new element, and return a slice with a length of 4 and capacity of 5. All slices will point to the same backing array and have the same capacities, but with different lengths.\n    \u003cgoslice name=\"s1 []string\" cap=\"5\" ptr=\"0x0015\" startaddress=\"0x0015\" items=\"A,B\" hidelegend=\"1\" slim=\"1\" theme=\"red\"\u003e\u003c/goslice\u003e\n    \u003cgoslice name=\"s2 []string\" cap=\"5\" ptr=\"0x0015\" startaddress=\"0x0015\" items=\"A,B,C\" hidelegend=\"1\" slim=\"1\" theme=\"yellow\"\u003e\u003c/goslice\u003e\n    \u003cgoslice name=\"s3 []string\" cap=\"5\" ptr=\"0x0015\" startaddress=\"0x0015\" items=\"A,B,C,D\" hidelegend=\"1\" slim=\"1\" theme=\"purple\"\u003e\u003c/goslice\u003e\n\u003c/gocodequestion\u003e\n\n\u003cgocodequestion difficulty=\"hard\" playlink=\"https://go.dev/play/p/mvOgJqDwBrf\" parsetextfrom=\"questions/visual-go-slices/04.md\"\u003e\n    At first s1 is a byte slice with a length and capacity of 12, and with items 'H', 'e', 'l', 'l', 'o', etc. After the first slicing operation, s2 will be a byte slice pointing to the same memory location as s1, with length 6 and capacity 12.\u003cbr\u003e\u003cbr\u003eAppending the items of []byte(\"gophers\") means appending 7 bytes to s2, which is out of the capacity of s2. So the first append will allocate a new backing array, copy the items of s2 to the new array, and append the new items. The new slice s2 will point to the new backing array with a length of 13 and a capacity of 24\u003cbr\u003e\u003cbr\u003eAfter the second slicing, s3 will point to the 7th item of s1, with a length of 5 and a capacity of 6. The last append will not reallocate the backing array, as s3 has enough capacity to hold the new item, and the new slice will have a length of 6 and a capacity of 6.\u003cbr\u003e\u003cbr\u003eWhen we call append the second time on s3 and append one byte to it, s3 will be at full capacity and have length and capacity of 6. As this call did not reallocate and both s1 and s3 point to the same backing array, the last item of s1 will be updated as well.\n    \u003cgoslice name=\"s []byte\" cap=\"12\" ptr=\"0x1000\" startaddress=\"0x1000\" items=\"H,e,l,l,o, ,w,o,r,l,d,?\" theme=\"green\"\u003e\u003c/goslice\u003e\n    \u003cgoslice name=\"s2 []byte\" cap=\"24\" ptr=\"0x1230\" startaddress=\"0x1230\" items=\"H,e,l,l,o, ,g,o,p,h,e,r,s\"theme=\"blue\"\u003e\u003c/goslice\u003e\n    \u003cgoslice name=\"s3 []byte\" cap=\"6\" ptr=\"0x1006\" startaddress=\"0x1006\" items=\"w,o,r,l,d,?\" theme=\"purple\"\u003e\u003c/goslice\u003e\n\u003c/gocodequestion\u003e\n\n## References\n\n- [Go compiler source code](https://github.com/golang/go)\n- [Effective Go](https://go.dev/doc/effective_go)\n- \u003cchip text=\"100 Go Mistakes and How to Avoid Them\" href=\"https://100go.co\" icon=\"book\"\u003e\u003c/chip\u003e\n- [Go Slices: usage and internals](https://go.dev/blog/slices-intro)\n\n[^1]: Zero value is the default value of an uninitialized type in Go. For example, the zero value of a `bool` is `false`, integer types are `0`, and slices, functions, maps, etc. are `nil`.\n\n[^2]: The `range` keyword is used to iterate over the indexes and (optionally) the values of an array or slice. It returns the index and the value of each element. If the result is decomposed into one variable such as `i := range slice`, it will only return the index. If it is decomposed into two variables such as `i, v := range slice`, it will return both the index and the value. Similarly, if you only need the value, you can use `_` to discard the index, such as `_, v := range slice`. The `range` iteration behaves differently on `map`s and `channel`s.\
3n\n[^3]: For more info about the garbage collector, see [tip.golang.org/doc/gc-guide](https://tip.golang.org/doc/gc-guide)\n\n[^4]: The growth factors are not **constant**, in practice. To see the actual calculation of the \"smooth\" growth factors, you can check the `nextslicecap` function in [Go runtime source code](https://github.com/golang/go/blob/c2c4a32f9e57ac9f7102deeba8273bcd2b205d3c/src/runtime/slice.go#L282).\n\n[^5]: [linux.die.net/man/3/realloc](https://linux.die.net/man/3/realloc)"])</script>
3<script>self.__next_f.push([1,"2c:T11c20,"])</script>
3<script>self.__next_f.push([1,"\u003cp\u003eWe use slices everywhere in Go. With maps, they are fundamental data types we use to store data. Today we will dive into the internals and see \u003cstrong\u003ehow slices work under the hood\u003c/strong\u003e.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e At the end of the article, you will find \u003ca href=\"#exercises\"\u003eexercises\u003c/a\u003e to test your knowledge. Enjoy!\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch2 id=\"what-is-a-slice\"\u003eWhat is a slice?\u003c/h2\u003e\n\u003cp\u003eIn Go, \u003cstrong\u003eslice is an abstraction over arrays\u003c/strong\u003e. It consists of a pointer to the backing array, the length of the slice, and its capacity. The length is the \u003cstrong\u003enumber of elements in the slice\u003c/strong\u003e, while the capacity is the \u003cstrong\u003enumber of elements in the underlying array\u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003eHere\u0026#39;s how a slice is defined in \u003ca href=\"https://github.com/golang/go/blob/cff7267e0d77f02d582c613c272b6f8ebf1c0412/src/runtime/slice.go#L15\" target=\"_blank\"\u003eGo runtime\u003c/a\u003e:\u003c/p\u003e\n\u003cpre data-filename=\"go/src/runtime/slice.go\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eslice\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003earray\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eunsafe\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003ePointer\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e   \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe \u003ccode\u003earray\u003c/code\u003e field is a pointer to the (first element of the) backing array. The \u003ccode\u003elen\u003c/code\u003e field is the length of the slice, denoting the number of items in the slice, and the \u
3003ccode\u003ecap\u003c/code\u003e field is the capacity of the slice. Capacity stores the number of elements in the backing array, and it is the maximum number of elements the slice can hold without reallocating the backing array.\u003c/p\u003e\n\u003cp\u003eThere are multiple ways to create a slice, and some of them differ in how they set the length and capacity of the slice. Let\u0026#39;s say we have the following slice definition:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint32\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis creates an \u003ccode\u003eint32\u003c/code\u003e slice \u003ccode\u003es1\u003c/code\u003e with some initial values. The length of the slice is 5, as you can see from the number of elements in the slice definition. The capacity is also set to 5 by default (we did not specify a different capacity), and the backing array is filled with the given values.\u003c/p\u003e\n\u003cp\u003eBelow is how the backing array looks like in memory. Numbers inside the cells represent values of items in the array, and the gray cells represent the memory that does not belong to the slice. See how both length and capacity is \u003ccode\u003e5\u003c/code\u003e, and slice points (ptr = \u003ccode\u003e0x0100\u003c/code\u003e) at the address of the first element of the array (\u003ccode\u003e0x0100\u003c/code\u003e).\u003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s1 []int32\" cap=\"5\" items=\"1,2,3,4,5\" ptr=\"0x0100\" startaddress=\"0x0100\" bytesperblock=\"4\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003ch2 id=\"make-ing-of-a-slice\"\u003e\u003ccode\u003emake\u003c/code\u003e-ing of a slice\u003c/h2\u003e\n\u003cp\u003eWe can specify different lengths and capacities for a slice by using the \u003ccode\u003emake\u003c/code\u003e built-in function. The \u003ccode\u003emake\u003c/code\u003e function accepts two to three arguments for slice allocation: the type of the slice, the length, and the capacity. If the capacity is not given, \u003cstrong\u003eit defaults to the length\u003c/strong\u003e.\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e([]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe code above allocates a 10-capacity array and creates a slice \u003ccode\u003es2\u003c/code\u003e, which points to this array with a length of 5. The capacity of the slice is also set to 10.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003emake\u003c/code\u003e also fills the array with the \u003cstrong\u003ezero values\u003c/strong\u003e\u003csup id=\"fnref:1\"\u003e\u003ca href=\"#fn:1\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e1\u003c/a\u003e\u003c/sup\u003e of the item type. In this case, the zero value of \u003ccode\u003eint\u003c/code\u003e is \u003ccode\u003e0\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s2 []int\" cap=\"10\" ptr=\"0x1234\" items=\"0,0,0,0,0\" show-unused-as-zero=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e Notice that all items of the backing array are filled with zero values, not only the \u
3003ccode\u003elen\u003c/code\u003e items of the slice. From now on I won\u0026#39;t show the zeroes in the unused parts of the backing array to keep the visuals more readable.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eIf we want to populate this slice with some values, we can set specific indexes:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis will set the values of the slice to \u003cstrong\u003e0, 2, 4, 6, 8\u003c/strong\u003e, by using \u003ccode\u003erange\u003c/code\u003e\u003csup id=\"fnref:2\"\u003e\u003ca href=\"#fn:2\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e2\u003c/a\u003e\u003c/sup\u003e to iterate over the indexes of the slice.\u003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s2 []int\" cap=\"10\" ptr=\"0x1234\" items=\"0,2,4,6,8\" hidelegend=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003eNotice how the slice is still pointing to the same underlying array, but the initial values are changed. Also the length and capacity of the slice are still the same.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"beaver-question\" class=\"quote-character\"\u003e\u003cp\u003e Why didn\u0026#39;t \u003ccode\u003erange\u003c/code\u003e iterate over all indexes within the capacity (10) of the array?\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eGood question. Let\u0026#39;s see what happens if we try to set a value to an index that is out of the slice\u0026#39;s length?\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eIf we run the assignment above, Go runtime will panic with the message below:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003epanic: runtime error: index out of range \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e8\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e with length \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe capacity is not the space Go gives us to use, it\u0026#39;s the maximum number of the elements slice can hold \u003cstrong\u003ewithout reallocating the backing array\u003c/strong\u003e. If we try to access or set a value to an index that is out of the slice\u0026#39;s length, Go will panic.\u003c/p\u003e\n\u003cp\u003eOkay, so what if we add more elements by simply \u003ccode\u003eappend\u003c/code\u003eing them to the slice?\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e...\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe built-in function \u003ccode\u003eappend\u003c/code\u003e works by pushing these items to the end of the slice, starting by the \u
3003ccode\u003elen\u003c/code\u003e-th item. Both the length and the capacity of the slice are \u003cstrong\u003e10\u003c/strong\u003e now.\u003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s2 []int\" cap=\"10\" items=\"0,2,4,6,8,10,12,14,16,18\" hidelegend=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003ch2 id=\"growing-the-slice\"\u003eGrowing the slice\u003c/h2\u003e\n\u003cp\u003eWhat do you think will happen if we add one more item to the end of the slice now, as it\u0026#39;s capacity is already full?\u003c/p\u003e\n\u003cp\u003eIf we have a full slice (\u003ccode\u003elen\u003c/code\u003e == \u003ccode\u003ecap\u003c/code\u003e), then Go runtime will \u003cstrong\u003ereallocate\u003c/strong\u003e the backing array, copy the existing elements to the new array, and append the new element.\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003eThis was what I meant by \u0026#34;slices are abstraction over arrays\u0026#34;. Go abstracts the memory management from the developer so you don\u0026#39;t need to think if the backing array is full, or how much of an extra capacity should I allocate every time. In C for example, you would need to use \u003ccode\u003ecalloc\u003c/code\u003e or \u003ccode\u003erealloc\u003c/code\u003e\u003csup id=\"fnref:3\"\u003e\u003ca href=\"#fn:3\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e3\u003c/a\u003e\u003c/sup\u003e to handle the reallocation of the memory, manually.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eThe new capacity will be \u003cstrong\u003edouble the previous capacity\u003c/strong\u003e until the slice reaches a certain capacity threshold. After that, the capacity will \u003cstrong\u003eincrease monotonically with different growth factors\u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003eYou can see in other (older) resources that the capacity increases by 25% after 1024 items, but \u003ca href=\"https://github.com/golang/go/commit/2dda92ff6f9f07eeb110ecbf0fc2d7a0ddd27f9d\" target=\"_blank\"\u003ein 2021 the growth formula was changed\u003c/a\u003e to be smoother.\u003c/p\u003e\n\u003cp\u003eBelow is the \u003cem\u003etheoretical\u003c/em\u003e\u003csup id=\"fnref:4\"\u003e\u003ca href=\"#fn:4\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e4\u003c/a\u003e\u003c/sup\u003e growth factors by certain capacity thresholds:\u003c/p\u003e\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eStarting Capacity\u003c/th\u003e\n\u003cth\u003eGrowth Factor\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e256\u003c/td\u003e\n\u003ctd\u003e2.0\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e512\u003c/td\u003e\n\u003ctd\u003e1.63\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e1024\u003c/td\u003e\n\u003ctd\u003e1.44\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e2048\u003c/td\u003e\n\u003ctd\u003e1.35\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e4096\u003c/td\u003e\n\u003ctd\u003e1.30\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003cp\u003eSo if we add one more item at the end of the slice \u003ccode\u003es2\u003c/code\u003e we had, the \u003ccode\u003eappend\u003c/code\u003e function will allocate a new array with a capacity of 20, copy the existing elements to the new array, and append the new element.\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003e\u003cgoslice name=\"old array\" 
3cap=\"10\" ptr=\"0x1234\" items=\"0,2,4,6,8,10,12,14,16,18\" hidelegend=\"1\" slim=\"1\" theme=\"red\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s2 []int\" cap=\"20\" ptr=\"0x2020\" items=\"0,2,4,6,8,10,12,14,16,18,20\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003eNotice how \u003ccode\u003es2\u003c/code\u003e now points to a \u003cstrong\u003edifferent backing array\u003c/strong\u003e with a capacity of 20. The old array at memory address \u003ccode\u003e0x1234\u003c/code\u003e will be \u003cstrong\u003egarbage collected by the Go runtime\u003c/strong\u003e\u003csup id=\"fnref:5\"\u003e\u003ca href=\"#fn:5\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e5\u003c/a\u003e\u003c/sup\u003e if no other slice points to it (references it).\u003c/p\u003e\n\u003cblockquote data-quote-character=\"sazak-explain\" class=\"quote-character\"\u003e\u003cp\u003e Keep in mind that the memory addresses I use in examples are just for demonstration purposes. In reality, the memory addresses are longer 32-bit or 64-bit integers and can change between runs.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e\u003cnewslettercard\u003e\u003c/newslettercard\u003e\u003c/p\u003e\n\u003ch3 id=\"a-note-on-append-function\"\u003eA note on append function\u003c/h3\u003e\n\u003cp\u003eIn many places you will see the \u003ccode\u003eappend\u003c/code\u003e function used with the same slice as the first argument, like \u003ccode\u003esl = append(sl, \u0026#34;hello\u0026#34;)\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThis is because when the slice given exceeds the capacity with the given new elements and \u003ccode\u003eappend\u003c/code\u003e needs to internally reallocate a new backing array, the new slice structure pointing to the new array will be returned from the function. The slice given in the first argument, however, will not be updated in-place.\u003c/p\u003e\n\u003cp\u003eThat\u0026#39;s why if you want the update to be reflected to the slice, you need to assign the result of the \u003ccode\u003eappend\u003c/code\u003e function to the slice, as how \u003ccode\u003eappend\u003c/code\u003e is used for most of the time.\u003c/p\u003e\n\u003cp\u003eIt\u0026#39;s good to know how using different variables for the result of the \u003ccode\u003eappend\u003c/code\u003e function can affect the slices. Consider the following example:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003edogs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;bulldog\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;poodle\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;beagle\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003emoreDogs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edogs\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;husky\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003emoreAndMoreDogs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003emoreDogs\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;shiba inu\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eBefore the append, \u003ccode\u003edogs\u003c/code\u003e has both length and capacity of 3, and points to the backing array with the elements \u003ccode\u003e\u0026#34;bulldog\u0026#34;\u003c/code\u003e, \u003ccode\u003e\u0026#34;poodle\u0026#34;\u003c/code\u003e, and \u003ccode\u003e\u0026#34;beagle\u0026#34;\u003c/code\u003e. As \u003ccode\u003edogs\u003c/code\u003e is at full capacity, the first append call will return a new slice, pointing to a new backing array filled with the initial elements and the new element \u003ccode\u003e\u0026#34;husky\u0026#34;\u003c/code\u003e, with a capacity of 6.\u003c/p\u003e\n\u003cp\u003eNow \u003ccode\u003emoreDogs\u003c/code\u003e points to the new backing array, and \u003ccode\u003edogs\u003c/code\u003e still points to the old backing array. In the second append call, we would not expect another reallocation happening, as the \u003ccode\u003emoreDogs\u003c/code\u003e slice has enough capacity to hold the new element \u003ccode\u003e\u0026#34;shiba inu\u0026#34;\u003c/code\u003e. So the \u003ccode\u003emoreAndMoreDogs\u003c/code\u003e slice will point to the same backing array as \u003ccode\u003emoreDogs\u003c/code\u003e.\u003c/p\u003e\n\u003ch2 id=\"slicing\"\u003eSlicing\u003c/h2\u003e\n\u003cp\u003eWe can create a new slice from an existing slice by using the slicing expression. It\u0026#39;s syntactically similar to what Python does with lists.\u003c/p\u003e\n\u003cp\u003eWhen we slice another slice, the new slice will point to the same backing array, but the length and capacity will be different, \u003cstrong\u003edepending on the range we specify\u003c/strong\u003e. The range is inclusive for the start index and exclusive for the end index.\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebyte\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e64\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e80\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;s1: %v, len: %d, cap: %d\\n\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;s2: %v, len: %d, cap: %d\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe code above will output:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es1: \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e64\u003c/span\u003e\u003cspan style=\"\"\u003e 80\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e, len: 5, cap: \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2: \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e 48\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e, len: 2, cap: \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eLength of \u003ccode\u003es2\u003c/code\u003e is \u003ccode\u003e2\u003c/code\u003e, as the range \u003ccode\u003e[1:3]\u003c/code\u003e includes the elements at indexes \u003ccode\u003e1\u003c/code\u003e and \u003ccode\u003e2\u003c/code\u003e. The capacity will be the capacity of \u003ccode\u003es1\u003c/code\u003e minus the start index, which is \u003ccode\u003e4\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eIf we look at the pointers of the slices, we will see that they \u003cstrong\u003edon\u0026#39;t\u003c/strong\u003e point to the same memory address:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;s1: %p\\n\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;s2: %p\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es1: 0x0010\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2: 0x0011\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eNotice how the pointer of \u003ccode\u003es2\u003c/code\u003e is one byte ahead of the pointer of \u003ccode\u003es1\u003c/code\u003e. This is because the slice \u003ccode\u003es2\u003c/code\u003e starts from the second element of the slice \u003ccode\u003es1\u003c/code\u003e, and as each element in slice \u003ccode\u003es1\u003c/code\u003e is one byte long (\u003ccode\u003ebyte\u003c/code\u003e), the second item is one byte ahead of the first item.\u003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s1 []byte\" cap=\"5\" items=\"16,32,48,64,80\" ptr=\"0x0010\" startaddress=\"0x0010\" theme=\"blue\" hidelegend=\"1\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\u003cbr/\u003e\n\u003cgoslice name=\"s2 []byte\" cap=\"4\" items=\"32,48\" ptr=\"0x0011\" startaddress=\"0x0011\" theme=\"purple\" hidelegend=\"1\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003eLet\u0026#39;s play a little bit on our new slice \u003ccode\u003es2\u003c/code\u003e. Can you guess the outcome of the following code?\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e101\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eRemember that \u003ccode\u003es2\u003c/code\u003e points to the same backing array as \u003ccode\u003es1\u003c/code\u003e, and has enough capacity (4) to hold two more elements. So the new slice \u003ccode\u003es2\u003c/code\u003e will be:\u003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s2 []byte\" cap=\"4\" items=\"32,48,100,101\" ptr=\"0x0011\" theme=\"purple\" hidelegend=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003eAnd, as the slice \u003ccode\u003es1\u003c/code\u003e still points to the same backing array, it will look like the following in memory:\u003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s1 []byte\" cap=\"5\" items=\"16,32,48,100,101\" ptr=\"0x0010\" theme=\"blue\" hidelegend=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003eNotice how the slice \u003ccode\u003es1\u003c/code\u003e is also updated, as it points to the same backing array as \u003ccode\u003es2\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eNow that \u003ccode\u003es2\u003c/code\u003e is at full capacity, you know that if we append one more element to \u003ccode\u003es2\u003c/code\u003e, the backing array will be reallocated, and the slice will point to a new array.\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e102\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003e\u003cgoslice name=\"s2 []byte\" cap=\"8\" items=\"32,48,100,101,102\" ptr=\"0x0050\" startaddress=\"0x0050\" theme=\"purple\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003es2\u003c/code\u003e now points to a new backing array in a different memory address (\u003ccode\u003e0x0050\u003c/code\u003e), with a capacity of \u003ccode\u003e8\u003c/code\u003e.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"beaver-question-3\" class=\"quote-character\"\u003e\u003cp\u003e What will happen to \u003ccode\u003es1\u003c/code\u003e in this case?\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eNormally the old array would be garbage collected, but in this case, \u003ccode\u003es1\u003c/code\u003e still points to it, so it will not be garbage collected.\u
3003c/p\u003e\n\u003cp\u003e\u003cgoslice name=\"s1 []byte\" cap=\"5\" items=\"16,32,48,100,101\" ptr=\"0x0010\" startaddress=\"0x0010\" theme=\"blue\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003eSee how appending to a slice which shares the same backing array with another slice \u003cstrong\u003ecan affect both slices, until one exceeds its capacity\u003c/strong\u003e and it has a new reallocated backing array.\u003c/p\u003e\n\u003ch3 id=\"specifying-the-capacity\"\u003eSpecifying the capacity\u003c/h3\u003e\n\u003cp\u003eDifferent slices using the same backing array may cause implicit problems sometimes. The new slice used in a function or in another part of the code appending new elements to the slice may cause the original slice to change its contents, which may not be the desired behavior.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"beaver-question\" class=\"quote-character\"\u003e\u003cp\u003e How can I prevent this behavior then?\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eGo allows us to specify the capacity of the new slice by using a \u003cstrong\u003ethird argument\u003c/strong\u003e in the slicing expression. This is useful when we want to limit the capacity of the new slice, to prevent the slice to change the contents \u003cstrong\u003eout of the specified bounds\u003c/strong\u003e of the backing array.\u003c/p\u003e\n\u003cp\u003eIf we would like to create a new slice from \u003ccode\u003es1\u003c/code\u003e starting from the second element and ending at the third element, with a capacity of 2, we can do it like this:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis will create a new slice \u003ccode\u003es3\u003c/code\u003e with a length of 2 (indexes \u003ccode\u003e1\u003c/code\u003e and \u003ccode\u003e2\u003c/code\u003e), a capacity of 2 as specified, and it will point to the second item (index \u003ccode\u003e1\u003c/code\u003e) of the same backing array as \u003ccode\u003es1\u003c/code\u003e. Notice that the third argument is \u003cstrong\u003enot\u003c/strong\u003e the capacity of the new slice, but in which index the capacity should end.\u003c/p\u003e\n\u003cp\u003eNow if we append a to \u003ccode\u003es3\u003c/code\u003e, as \u003ccode\u003es3\u003c/code\u003e is at capacity (\u003ccode\u003elen(s3)\u003c/code\u003e == \u003ccode\u003ecap(s3)\u003c/code\u003e == \u003ccode\u003e2\u003c/code\u003e) it will cause a reallocation of the used parts of the backing array, but it will not affect the contents of \u003ccode\u003es1\u003c/code\u003e.\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebyte\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e64\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e80\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e200\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e201\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003e\u003cgoslice name=\"s3 []byte\" cap=\"8\" items=\"32,48,200,201\" ptr=\"0x0060\" startaddress=\"0x0060\" theme=\"yellow\" hidelegend=\"1\" highlight-ptr=\"1\"\u003e\u003c/goslice\u003e\u003cbr/\u003e\n\u003cgoslice name=\"s1 []byte\" cap=\"5\" items=\"16,32,48,64,80\" ptr=\"0x0010\" startaddress=\"0x0010\" theme=\"blue\"\u003e\u003c/goslice\u003e\u003c/p\u003e\n\u003cp\u003eNotice how the ptr of \u003ccode\u003es3\u003c/code\u003e is different as it now points to a new backing array with length of 4 (2 old elements copied and two newly appended), and capacity of 4 (twice as the old capacity). The contents of \u003ccode\u003es1\u003c/code\u003e after the index \u003ccode\u003e2\u003c/code\u003e are not affected by the append operation on \u003ccode\u003es3\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThe whole code snippet is below:\u003c/p\u003e\n\u003cpre data-filename=\"go.dev/play/p/DrKX2QE24QP\" data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebyte\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e64\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e80\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e101\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e102\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;s1: %v, len: %d, cap: %d\\n\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;s2: %v, len: %d, cap: %d\\n\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebyte\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e64\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e80\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;
3s3 initially: %v, len: %d, cap: %d\\n\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e200\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e201\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;s1: %v, len: %d, cap: %d\\n\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es1\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;s3: %v, len: %d, cap: %d\\n\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es2\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003ecap\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003es3\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es1: \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e 101\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e, len: 5, cap: \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es2: \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e101\u003c/span\u003e\u003cspan style=\"\"\u003e 102\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e, len: 5, cap: \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es3 initially: \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e 48\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e, len: 5, cap: \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es1: \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e64\u003c/span\u003e\u003cspan style=\"\"\u003e 80\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e, len: 5, cap: \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003es3: \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e48\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e200\u003c/span\u003e\u003cspan style=\"\"\u003e 201\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e, len: 5, cap: \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e8\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cblockquote\u003e\n\u003cp\u003eSpecifying the slice capacity is an option we can use to limit the new slice\u0026#39;s capacity and actions on the items of backing array, to prevent unexpected changes in the original slice.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003ch2 id=\"conclusion\"\u003eConclusion\u003c/h2\u003e\n\u003cp\u003eSlices are a powerful abstraction in Go, allowing us to work with arrays in a more flexible way. Understanding how slices work internally helps us write more efficient and less error-prone code. I hope this article helped you gain insight on how slices work under the hood, and when to pay attention to implementation details to prevent unexpected behavior.\u003c/p\u003e\n\u003cp\u003eThere will be more of these visual guides to Go internals in the future, and there \u003cem\u003emay\u003c/em\u003e be a part two to this article.\u003c/p\u003e\n\u003cp\u003eIf you have any questions or feedback, feel free to reach out to me on \u003ca href=\"https://twitter.com/oznszk\" target=\"_blank\"\u003eTwitter\u003c/a\u003e. Until next time, stay tuned.\u003c/p\u003e\n\u003ch2 id=\"exercises\"\u003eExercises\u003c/h2\u003e\n\u003cgocodequestion difficulty=\"easy\" playlink=\"https://go.dev/play/p/5mF1pW6SqDo\" parsetextfrom=\"questions/visual-go-slices/01.md\" parsedcontent=\"\u0026lt;p\u0026gt;What is the length and capacity of slice \u0026lt;code\u0026gt;s1\u0026lt;/code\u0026gt; after the operations below?\u0026lt;/p\u0026gt;\n\u0026lt;pre data-language=\u0026#34;go\u0026#34; tabindex=\u0026#34;0\u0026#34; style=\u0026#34;color:#f8f8f2;background-color:#282a36;\u0026#34;
3\u0026gt;\u0026lt;code\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;make\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;([]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd\u0026#34;\u0026gt;int\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;6\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;8\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;for\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;i\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;range\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;{\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;4\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;    \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;i\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;
3\u0026gt;2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;*\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;i\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;+\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;5\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;}\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;6\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;7\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;append\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd\u0026#34;\u0026gt;int\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;{\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;100\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;23\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;0x5\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;-\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;23\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;}\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;...\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;
3\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/code\u0026gt;\u0026lt;/pre\u0026gt;\"\u003e\n    Length will be 10 as there will be 10 items in the slice at the end. The capacity will be doubled after we add the 8th element, so it will be 16.\n    \u003cgoslice name=\"s1 []int\" cap=\"16\" items=\"1,3,5,7,9,11,100,23,5,-23\" hidelegend=\"1\" slim=\"1\" theme=\"purple\"\u003e\u003c/goslice\u003e\n\u003c/gocodequestion\u003e\n\u003cgocodequestion difficulty=\"easy\" playlink=\"https://go.dev/play/p/O76cT6PnNPx\" parsetextfrom=\"questions/visual-go-slices/03.md\" parsedcontent=\"\u0026lt;p\u0026gt;What are the contents of the slice \u0026lt;code\u0026gt;funcSl\u0026lt;/code\u0026gt; below?\u0026lt;/p\u0026gt;\n\u0026lt;pre data-language=\u0026#34;go\u0026#34; tabindex=\u0026#34;0\u0026#34; style=\u0026#34;color:#f8f8f2;background-color:#282a36;\u0026#34;\u0026gt;\u0026lt;code\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;funcSl\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;make\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;([]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;func\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;context\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;.\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;Context\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd\u0026#34;\u0026gt;error\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;5\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;10\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/code\u0026gt;\u0026lt;/pre\u0026gt;\"\u003e\n    The make built-in function allocates the backing array with a length of 10, which is also the capacity of the slice. The length of the slice is 5, and the backing array is filled with the zero values of the element type.\u003cbr/\u003e\u003cbr/\u003eAs the zero value of the function type is nil, no matter the function signature, the slice will be filled with 5 nil values.\n    \u003cgoslice name=\"funcSl\" cap=\"10\" items=\"nil,nil,nil,nil,nil\" hidelegend=\"1\" slim=\"1\" theme=\"red\"\u003e\u003c/goslice\u003e\n\u003c/gocodequestion\u003e\n\u003cgocodequestion difficulty=\"medium\" playlink=\"https://go.dev/play/p/MrPYo1CRJ2w\" parsetextfrom=\"questions/visual-go-slices/02.md\" parsedcontent=\"\u0026lt;p\u0026gt;What are the lengths and capacities of slices \u0026lt;code\u0026gt;s1\u0026lt;/code\u0026gt;, \u0026lt;code\u0026gt;s2\u0026lt;/code\u0026gt;, and \u0026lt;code\u0026gt;s3\u0026lt;/code\u0026gt; after the operations below?\u0026lt;/p\u0026gt;\n\u0026lt;pre data-language=\u0026#34;go\u0026#34; tabindex=\u0026#34;0\u0026#34; style=\u0026#34;color:#f8f8f2;background-color:#282a36;\u0026#34;
3\u0026gt;\u0026lt;code\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;make\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;([]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd\u0026#34;\u0026gt;string\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;5\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;0\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;A\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;4\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;B\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;
3\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;5\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;6\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;append\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;C\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;7\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;append\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;D\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/code\u0026gt;\u0026lt;/pre\u0026gt;\"\u003e\n    After the first two index assignments, s1 will have \u0026#34;A\u0026#34; and \u0026#34;B\u0026#34; as first two items.\u003cbr/\u003e\u003cbr/\u003eWhen we append \u0026#34;C\u0026#34; to s1, the append function will not reallocate the backing array as s1 is not at capacity, and append will return a slice pointing to the same backing array with a length of 3 and capacity of 5, which is assigned to s2.\u003cbr/\u003e\u003cbr/\u003eThe last append to s2 will not reallocate as well, as the capacity is enough to hold the new element, and return a slice with a length of 4 and capacity of 5. All slices will point to the same backing array and have the same capacities, but with different lengths.\n    \u003cgoslice name=\"s1 []string\" cap=\"5\" ptr=\"0x0015\" startaddress=\"0x0015\" items=\"A,B\" hidelegend=\"1\" slim=\"1\" theme=\"red\"\u003e\u003c/goslice\u003e\n    \u003cgoslice name=\"s2 []string\" cap=\"5\" ptr=\"0x0015\" startaddress=\"0x0015\" items=\"A,B,C\" hidelegend=\"1\" slim=\"1\" theme=\"yellow\"\u003e\u003c/goslice\u003e\n    \u003cgoslice name=\"s3 []string\" cap=\"5\" ptr=\"0x0015\" startaddress=\"0x0015\" items=\"A,B,C,D\" hidelegend=\"1\" slim=\"1\" theme=\"purple\"\u003e\u003c/goslice\u003e\n\u003c/gocodequestion\u003e\n\u003cgocodequestion difficulty=\"hard\" playlink=\"https://go.dev/play/p/mvOgJqDwBrf\" parsetextfrom=\"questions/visual-go-slices/04.md\" parsedcontent=\"\u0026lt;p\u0026gt;What are the contents, length and capacities of slices \u0026lt;code\u0026gt;s1\u0026lt;/code\u0026gt;, \u0026lt;code\u0026gt;s2\u0026lt;/code\u0026gt;, and \u0026lt;code\u0026gt;s3\u0026lt;/code\u0026gt; after the operations below?\u0026lt;/p\u0026gt;\n\u0026lt;pre data-language=\u0026#34;go\u0026#34; tabindex=\u0026#34;0\u0026#34; style=\u0026#34;color:#f8f8f2;background-color:#282a36;\u0026#34;
3\u0026gt;\u0026lt;code\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;byte\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;Hello world!\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[:\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;6\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;4\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;append\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s2\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;byte\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#34;gophers\u0026amp;#34;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;
3\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;...\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;)\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;5\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;6\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#ff79c6\u0026#34;\u0026gt;:=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s1\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;[\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;6\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;:\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#bd93f9\u0026#34;\u0026gt;11\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;]\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;display:flex;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\u0026#34;\u0026gt;7\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;=\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;append\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;s3\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;,\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt; \u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#8be9fd;font-style:italic\u0026#34;\u0026gt;byte\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;(\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;color:#f1fa8c\u0026#34;\u0026gt;\u0026amp;#39;?\u0026amp;#39;\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;))\u0026lt;/span\u0026gt;\u0026lt;span style=\u0026#34;\u0026#34;\u0026gt;\n\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/span\u0026gt;\u0026lt;/code\u0026gt;\u0026lt;/pre\u0026gt;\"\u003e\n    At first s1 is a byte slice with a length and capacity of 12, and with items \u0026#39;H\u0026#39;, \u0026#39;e\u0026#39;, \u0026#39;l\u0026#39;, \u0026#39;l\u0026#39;, \u0026#39;o\u0026#39;, etc. After the first slicing operation, s2 will be a byte slice pointing to the same memory location as s1, with length 6 and capacity 12.\u003cbr/\u003e\u003cbr/\u003eAppending the items of []byte(\u0026#34;gophers\u0026#34;) means appending 7 bytes to s2, which is out of the capacity of s2. So the first append will allocate a new backing array, copy the items of s2 to the new array, and append the new items. The new slice s2 will point to the new backing array with a length of 13 and a capacity of 24\u003cbr/\u003e\u003cbr/\u003eAfter the second slicing, s3 will point to the 7th item of s1, with a length of 5 and a capacity of 6. The last append will not reallocate the backing array, as s3 has enough capacity to hold the new item, and the new slice will have a length of 6 and a capacity of 6.\u003cbr/\u003e\u003cbr/\u003eWhen we call append the second time on s3 and append one byte to it, s3 will be at full capacity and have length and capacity of 6. As this call did not reallocate and both s1 and s3 point to the same backing array, the last item of s1 will be updated as well.\n    \u003cgoslice name=\"s []byte\" cap=\"12\" ptr=\"0x1000\" startaddress=\"0x1000\" items=\"H,e,l,l,o, ,w,o,r,l,d,?\" theme=\"green\"\u003e\u003c/goslice\u003e\n    \u003cgoslice name=\"s2 []byte\" cap=\"24\" ptr=\"0x1230\" startaddress=\"0x1230\" items=\"H,e,l,l,o, ,g,o,p,h,e,r,s\" theme=\"blue\"\u003e\u003c/goslice\u003e\n    \u003cgoslice name=\"s3 []byte\" cap=\"6\" ptr=\"0x1006\" startaddress=\"0x1006\" items=\"w,o,r,l,d,?\" theme=\"purple\"\u003e\u003c/goslice\u003e\n\u003c/gocodequestion\u003e\n\u003ch2 id=\"references\"\u003eReferences\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/golang/go\" target=\"_blank\"\u003eGo compiler source code\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://go.dev/doc/effective_go\" target=\"_blank\"\u003eEffective Go\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003cchip text=\"100 Go Mistakes and How to Avoid Them\" href=\"https://100go.co\" icon=\"book\"\u003e\u003c/chip\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://go.dev/blog/slices-intro\" target=\"_blank\"\u003eGo Slices: usage and internals\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cdiv class=\"footnotes\" role=\"doc-endnotes\"\u003e\n\u003chr/\u003e\n\u003col\u003e\n\u003cli id=\"fn:1\" data-index=\"1\"\u003e\n\u003cp\u003eZero value is the default value of an uninitialized type in Go. For example, the zero value of a \u003ccode\u003ebool\u003c/code\u003e is \u003ccode\u003efalse\u003c/code\u003e, integer types are \u003ccode\u003e0\u003c/code\u003e, and slices, functions, maps, etc. are \u003ccode\u003enil\u003c/code\u003e. \u003ca href=\"#fnref:1\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:2\" data-index=\"2\"\u003e\n\u003cp\u003eThe \u003ccode\u003erange\u003c/code\u003e keyword is used to iterate over the indexes and (optionally) the values of an array or slice. It returns the index and the value of each element. If the result is decomposed into one variable such as \u003ccode\u003ei := range slice\u003c/code\u003e, it will only return the index. If it is decomposed into two variables such as \u003ccode\u003ei, v := range slice\u003c/code\u003e, it will return both the index and the value. Similarly, if you only need the value, you can use \u003ccode\u003e_\u003c/code\u003e to discard the index, such as \u003ccode\u003e_, v := range slice\u003c/code\u003e. The \u003ccode\u003erange\u003c/code\u003e iteration behaves differently on \u003ccode\u003emap\u003c/code\u003es and \u003ccode\u003echannel\u003c/code\u003es. \u003ca href=\"#fnref:2\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:3\" data-index=\"3\"\u003e\n\u003cp\u003e\u003ca href=\"https://linux.die.net/man/3/realloc\" target=\"_blank\"\u003elinux.die.net/man/3/realloc\u003c/a\u003e \u003ca href=\"#fnref:3\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:4\" data-index=\"4\"\u003e\n\u003cp\u003eThe growth factors are not \u003cstrong\u003econstant\u003c/strong\u003e, in practice. To see the actual calculation of the \u0026#34;smooth\u0026#34; growth factors, you can check the \u003ccode\u003enextslicecap\u003c/code\u003e function in \u003ca href=\"https://github.com/golang/go/blob/c2c4a32f9e57ac9f7102deeba8273bcd2b205d3c/src/runtime/slice.go#L282\" target=\"_blank\"\u003eGo runtime source code\u003c/a\u003e. \u003ca href=\"#fnref:4\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:5\" data-index=\"5\"\u003e\n\u003cp\u003eFor more info about the garbage collector, see \u003ca href=\"https://tip.golang.org/doc/gc-guide\" target=\"_blank\"\u003etip.golang.org/doc/gc-guide\u003c/a\u003e \u003ca href=\"#fnref:5\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n"])</script>
3<script>self.__next_f.push([1,"2d:T1a4c,"])</script>
3<script>self.__next_f.push([1,"\n\nOne of the things I like about Go is that when you want to use someone else's code in your project, you can just import it by its GitHub repo URL.\n\nLiterally, you can just import the package by writing:\n\n```go\nimport \"github.com/google/go-cmp/cmp\"\n```\n\nAnd that's it. Although these URLs don't have to be GitHub URLs. Sometimes you see import paths like `go.uber.org/atomic`, or `golang.org/x/crypto/ssh`.\n\nThese are also valid import paths and they are called **\"vanity import paths\"**. They are called \"vanity\" because they are custom domain names, which redirect to the actual repository.\n\n## How does it work?\n\nThe work behind the scenes is pretty simple: When you run `go get`, or `go install`, Go tooling sends an HTTP request to this URL to get the package info, then downloads the source code under the `vendor` directory. The package info is provided in **meta tags** in the HTML response, which are:\n\n**go-import**: Where to find the repository. It has three parts: the import path, the VCS type (git, hg, etc.), and the repository URL.\n\n![](/assets/articles/go-sazak-io/go-import.png)\n\n**go-source**: Optional information for \u003cchip text=\"pkg.go.dev\" href=\"https://pkg.go.dev\" icon=\"globe\"\u003e\u003c/chip\u003e to link to the source code.\n\n![](/assets/articles/go-sazak-io/go-source.png)\n\nThe idea is, by simply returning these meta tags in the HTML response, you can make your own Go package index.\n\n## But why?\n\nWhy not? I like building stuff and putting them in public repos. I also use my own packages/tools later in other projects. So, I thought it would be cool to step it up a bit and have my own domain for my Go packages.\n\nIt's better to use this:\n\n```go\nimport \"go.sazak.io/my-package\"\n```\n\nInstead of this:\n\n```go\nimport \"github.com/ozansz/my-package\"\n```\n\nThat's how \u003cchip text=\"go.sazak.io\" href=\"https://go.sazak.io\" icon=\"globe\"\u003e\u003c/chip\u003e was born. It's a simple Go package index for my own public Go packages. It's basically a static site built by using a JSON file that contains the package info, which is also generated by a simple Go tool.\n\n## Designing the system\n\nWhen you think of designing an index which lists a number of packages, which link to their respective GitHub repositories, you might think of using a database, a backend server, and a frontend client.\n\nWe tend to overcomplicate things as developers, but in my opinion it's the best solution to keep things as simple as possible while preserving the functionality and developer experience.\n\n\u003e!char![gopher-info] \"Simple is better than complex.\" - Zen of Python\n\nThe whole systems consists of two parts: a Go tool called `sync-github-repos` that collects and compiles the data, and the static site that uses the JSON file as the data source to build a static site.\n\n![](/assets/articles/go-sazak-io/overall.png)\n\n### The Backend\n\nThe tool uses GitHub API to list my public repositories, then filters the ones that have a `go.mod` file which content starts with `module go.sazak.io/`. The data is then stored inside a `Repo` Go struct to later be marshaled into a JSON file:\n\n```go\ntype Repo struct {\n\tOwner        string            `json:\"owner\"`\n\tName         string            `json:\"name\"`\n\tStars        uint              `json:\"stars\"`\n\tDescription  string            `json:\"desc\"`\n\tGoPackage    string            `json:\"go_package\"`\n\tLatestTag    string            `json:\"latest_tag\"`\n\tAlphaRelease bool              `json:\"alpha_release\"`\n\tHasCLIApp    bool              `json:\"has_cli_app\"`\n\tPackages     map[string]string `json:\"packages\"`\n\tMasterBranch string            `json:\"master_branch\"`\n}\n```\n\nThen it checks if there are any public packages (containers) of the repository, are there any releases/tags, and if the latest tag is a pre-release. It also checks the name of the default branch, which is usually `main` or `master`.\n\nThe `HasCLIApp` field is a boolean that tells if the repository includes a CLI app in the `cmd` directory. This field is set if the repo has a `cli` tag.\n\nAlso the `AlphaRelease` field is a boolean that tells if the latest tag is a pre-release or if the tag is below version `v1.0.0`.\n\nThe JSON file is then used as the data source for the static site. The site is built with \u003cchip text=\"Next.js\" href=\"https://nextjs.org/\" icon=\"package\"\u003e\u003c/chip\u003e, \u003cchip text=\"
3Shadcn UI\" href=\"https://ui.shadcn.com/\" icon=\"package\"\u003e\u003c/chip\u003e and deployed to Vercel.\n\n### The UI\n\nAs I explained before, the website only needs to serve two meta tags in the HTML response. For a basic requirement like this I could just use plain HTML, but I thought it would be better to have a clean and informative UI for the human visitors.\n\nThat's why I decided to use Shadcn UI and design a one-page package listing site. I used the `Card` component to display the package info for all packages. The basic information is same for all packages, for example the package name, latest tag badge, instructions to clone the repository, etc.\n\n![](/assets/articles/go-sazak-io/card-1.png)\n\nCards also contain different sections, based on what package provides. If it's a CLI app, it shows the instructions to install the app. If it has packages (containers), it also shows the instructions to pull the containers using `docker pull`.\n\n![](/assets/articles/go-sazak-io/card-2.png)\n\nAfter putting it all together, the site looks like this:\n\n![](/assets/articles/go-sazak-io/website.png)\n\nWhich, I think, is pretty cool for a simple Go package index, and also for a backend/platform engineer like me to build.\n\n### The Pipeline\n\nTo make it easier to deploy the website with the synced data, I created a ~~GitHub Actions workflow~~ pre-commit hook that runs the `sync-github-repos` tool to generate the JSON file and put it inside the UI project:\n\n```bash\n#!/bin/sh\n\nset -eo pipefail\n\ngo run cmd/sync-github-repos/main.go --username ozansz --hostname go.sazak.io --out ui/src/repos.json --force-authenticated\nif [ $? -ne 0 ]; then\n    echo \"Pre-commit hook failed (content generation script)\"\n    exit 1\nfi\n\ngit update-index --add ui/src/repos.json\n```\n\nAfter I push the changes, the Vercel deployment pipeline is triggered and the site is updated with the new data.\n\n![](/assets/articles/go-sazak-io/deploy.png)\n\n## Conclusion\n\nIt's pretty simple -and cool- to have your own Go package index. It's a good way to keep track of your own packages publicly.\n\nIf you liked the idea, you can also build your own package index. My implementation for \u003cchip text=\"go.sazak.io\" href=\"https://go.sazak.io\" icon=\"globe\"\u003e\u003c/chip\u003e is open source and available on \u003cchip text=\"GitHub\" href=\"https://github.com/ozansz/go.sazak.io\" icon=\"github\"\u003e\u003c/chip\u003e. I tried to make it as simple as possible to use and extend.\n\nFeel free to fork it and build your own package index!"])</script>
3<script>self.__next_f.push([1,"2e:T3ff3,"])</script>
3<script>self.__next_f.push([1,"\u003cp\u003eOne of the things I like about Go is that when you want to use someone else\u0026#39;s code in your project, you can just import it by its GitHub repo URL.\u003c/p\u003e\n\u003cp\u003eLiterally, you can just import the package by writing:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003eimport\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;github.com/google/go-cmp/cmp\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eAnd that\u0026#39;s it. Although these URLs don\u0026#39;t have to be GitHub URLs. Sometimes you see import paths like \u003ccode\u003ego.uber.org/atomic\u003c/code\u003e, or \u003ccode\u003egolang.org/x/crypto/ssh\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThese are also valid import paths and they are called \u003cstrong\u003e\u0026#34;vanity import paths\u0026#34;\u003c/strong\u003e. They are called \u0026#34;vanity\u0026#34; because they are custom domain names, which redirect to the actual repository.\u003c/p\u003e\n\u003ch2 id=\"how-does-it-work\"\u003eHow does it work?\u003c/h2\u003e\n\u003cp\u003eThe work behind the scenes is pretty simple: When you run \u003ccode\u003ego get\u003c/code\u003e, or \u003ccode\u003ego install\u003c/code\u003e, Go tooling sends an HTTP request to this URL to get the package info, then downloads the source code under the \u003ccode\u003evendor\u003c/code\u003e directory. The package info is provided in \u003cstrong\u003emeta tags\u003c/strong\u003e in the HTML response, which are:\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003ego-import\u003c/strong\u003e: Where to find the repository. It has three parts: the import path, the VCS type (git, hg, etc.), and the repository URL.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/go-sazak-io/go-import.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003ego-source\u003c/strong\u003e: Optional information for \u003cchip text=\"pkg.go.dev\" href=\"https://pkg.go.dev\" icon=\"globe\"\u003e\u003c/chip\u003e to link to the source code.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/go-sazak-io/go-source.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eThe idea is, by simply returning these meta tags in the HTML response, you can make your own Go package index.\u003c/p\u003e\n\u003ch2 id=\"but-why\"\u003eBut why?\u003c/h2\u003e\n\u003cp\u003eWhy not? I like building stuff and putting them in public repos. I also use my own packages/tools later in other projects. So, I thought it would be cool to step it up a bit and have my own domain for my Go packages.\u003c/p\u003e\n\u003cp\u003eIt\u0026#39;s better to use this:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003eimport\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;go.sazak.io/my-package\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eInstead of this:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003eimport\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;github.com/ozansz/my-package\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThat\u0026#39;s how \u003cchip text=\"go.sazak.io\" href=\"https://go.sazak.io\" icon=\"globe\"\u003e\u003c/chip\u003e was born. It\u0026#39;s a simple Go package index for my own public Go packages. It\u0026#39;s basically a static site built by using a JSON file that contains the package info, which is also generated by a simple Go tool.\u003c/p\u003e\n\u003ch2 id=\"designing-the-system\"\u003eDesigning the system\u003c/h2\u003e\n\u003cp\u003eWhen you think of designing an index which lists a number of packages, which link to their respective GitHub repositories, you might think of using a database, a backend server, and a frontend client.\u003c/p\u003e\n\u003cp\u003eWe tend to overcomplicate things as developers, but in my opinion it\u0026#39;s the best solution to keep things as simple as possible while preserving the functionality and developer experience.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"gopher-info\" class=\"quote-character\"\u003e\u003cp\u003e \u0026#34;Simple is better than complex.\u0026#34; - Zen of Python\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eThe whole systems consists of two parts: a Go tool called \u003ccode\u003esync-github-repos\u003c/code\u003e that collects and compiles the data, and the static site that uses the JSON file as the data source to build a static site.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/go-sazak-io/overall.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch3 id=\"the-backend\"\u003eThe Backend\u003c/h3\u003e\n\u003cp\u003eThe tool uses GitHub API to list my public repositories, then filters the ones that have a \u003ccode\u003ego.mod\u003c/code\u003e file which content starts with \u003ccode\u003emodule go.sazak.io/\u003c/code\u003e. The data is then stored inside a \u003ccode\u003eRepo\u003c/code\u003e Go struct to later be marshaled into a JSON file:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eRepo\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eOwner\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;owner\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e         \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;name\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eStars\u003c/span\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint\u003c/span\u003e\u003cspan style=\"\"\u003e              \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;stars\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eDescription\u003c/span\u003e\u003cspan style=\"\"\u003e  \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;desc\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eGoPackage\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;go_package\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eLatestTag\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;latest_tag\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eAlphaRelease\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebool\u003c/span\u003e\u003cspan style=\"\"\u003e              \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;alpha_release\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eHasCLIApp\u003c/span\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebool\u003c/span\u003e\u003cspan style=\"\"\u003e              \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;has_cli_app\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003ePackages\u003c/span\u003e\u003cspan style=\"\"\u003e     \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emap\u003c/span\u003e\u003cspan style=\"\"\u003e[\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;packages\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\t\u003c/span\u003e\u003cspan style=\"\"\u003eMasterBranch\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e`json:\u0026#34;master_branch\u0026#34;`\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThen it checks if there are any public packages (containers
3) of the repository, are there any releases/tags, and if the latest tag is a pre-release. It also checks the name of the default branch, which is usually \u003ccode\u003emain\u003c/code\u003e or \u003ccode\u003emaster\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode\u003eHasCLIApp\u003c/code\u003e field is a boolean that tells if the repository includes a CLI app in the \u003ccode\u003ecmd\u003c/code\u003e directory. This field is set if the repo has a \u003ccode\u003ecli\u003c/code\u003e tag.\u003c/p\u003e\n\u003cp\u003eAlso the \u003ccode\u003eAlphaRelease\u003c/code\u003e field is a boolean that tells if the latest tag is a pre-release or if the tag is below version \u003ccode\u003ev1.0.0\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThe JSON file is then used as the data source for the static site. The site is built with \u003cchip text=\"Next.js\" href=\"https://nextjs.org/\" icon=\"package\"\u003e\u003c/chip\u003e, \u003cchip text=\"Shadcn UI\" href=\"https://ui.shadcn.com/\" icon=\"package\"\u003e\u003c/chip\u003e and deployed to Vercel.\u003c/p\u003e\n\u003ch3 id=\"the-ui\"\u003eThe UI\u003c/h3\u003e\n\u003cp\u003eAs I explained before, the website only needs to serve two meta tags in the HTML response. For a basic requirement like this I could just use plain HTML, but I thought it would be better to have a clean and informative UI for the human visitors.\u003c/p\u003e\n\u003cp\u003eThat\u0026#39;s why I decided to use Shadcn UI and design a one-page package listing site. I used the \u003ccode\u003eCard\u003c/code\u003e component to display the package info for all packages. The basic information is same for all packages, for example the package name, latest tag badge, instructions to clone the repository, etc.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/go-sazak-io/card-1.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eCards also contain different sections, based on what package provides. If it\u0026#39;s a CLI app, it shows the instructions to install the app. If it has packages (containers), it also shows the instructions to pull the containers using \u003ccode\u003edocker pull\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/go-sazak-io/card-2.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eAfter putting it all together, the site looks like this:\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/go-sazak-io/website.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eWhich, I think, is pretty cool for a simple Go package index, and also for a backend/platform engineer like me to build.\u003c/p\u003e\n\u003ch3 id=\"the-pipeline\"\u003eThe Pipeline\u003c/h3\u003e\n\u003cp\u003eTo make it easier to deploy the website with the synced data, I created a \u003cdel\u003eGitHub Actions workflow\u003c/del\u003e pre-commit hook that runs the \u003ccode\u003esync-github-repos\u003c/code\u003e tool to generate the JSON file and put it inside the UI project:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e#!/bin/sh\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eset\u003c/span\u003e\u003cspan style=\"\"\u003e -eo pipefail\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ego run cmd/sync-github-repos/main.go --username ozansz --hostname go.sazak.io --out ui/src/repos.json --for
3ce-authenticated\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003e$?\u003c/span\u003e\u003cspan style=\"\"\u003e -ne \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ethen\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eecho\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;Pre-commit hook failed (content generation script)\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eexit\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efi\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003egit update-index --add ui/src/repos.json\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eAfter I push the changes, the Vercel deployment pipeline is triggered and the site is updated with the new data.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/go-sazak-io/deploy.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch2 id=\"conclusion\"\u003eConclusion\u003c/h2\u003e\n\u003cp\u003eIt\u0026#39;s pretty simple -and cool- to have your own Go package index. It\u0026#39;s a good way to keep track of your own packages publicly.\u003c/p\u003e\n\u003cp\u003eIf you liked the idea, you can also build your own package index. My implementation for \u003cchip text=\"go.sazak.io\" href=\"https://go.sazak.io\" icon=\"globe\"\u003e\u003c/chip\u003e is open source and available on \u003cchip text=\"GitHub\" href=\"https://github.com/ozansz/go.sazak.io\" icon=\"github\"\u003e\u003c/chip\u003e. I tried to make it as simple as possible to use and extend.\u003c/p\u003e\n\u003cp\u003eFeel free to fork it and build your own package index!\u003c/p\u003e\n"])</script>
3<script>self.__next_f.push([1,"2f:T2278,"])</script>
3<script>self.__next_f.push([1,"\n\nSo you are a newbie developer looking for a project idea to apply what you've learned in that Udemy course, or maybe an experienced engineer searching for the next side project to work on for fun. Either way, you need a creative idea to bring to life.\n\nIt's a fun way to apply what you have learned in the courses/books and an excellent skill to craft the tool you just need to automate that boring stuff you need to do every day.\n\nHere, I will list a few sources/techniques I used to find cool project ideas while learning programming and now to craft useful tools for my needs. **This blog post is a little bit opinionated.** Everyone has a unique learning curve, so if you find my suggestions harder or easier than expected, it's okay to modify them to fit your level.\n\n![](/assets/articles/project-complexity-by-time-graph.png)\n\n## you have just started learning programming...\n\n...and looking for project ideas. You probably know Python or JavaScript a little bit, or maybe C/Go, and want to dive into 
3interesting real-life stuff.\n\nIn this stage, you should **not** dive right into big and complex projects. I know it's exciting, but hear my reasons:\n1. **You probably don't have the technical background required to build a complex system.** Whether it's creating a browser, a search engine, a social media app, …. These projects seem simple from the outside. _\"I mean, you just enter a search text, and it lists some websites\"_, yes, but in the background, there are too many moving parts and some pretty complex algorithms for a beginner. For a browser, you need to write a JavaScript parser; for a search engine, you at least need to understand graphs, and so on.\n2. **You may not have the ability to read other people's code.** Building complex stuff requires the skill (yes, it's kind of a skill) to read long lines of production code to see how other engineers solved similar problems. Also, you can't always find blog posts/videos/docs explaining _\"how to do X\"_ after a certain level of problem complexity.\n\n**However**, the most beneficial thing you can do is code simple yet not tedious stuff using the programming topics you learned to jump to advanced levels where you can work on complex projects as fast as possible.\n\nI suggest **coding simple versions** of those complex programs, such as **creating little terminal-based games**. You don't need to learn GUI, a self-made hangman game is still fun after all. Also, while building one, you will need to use most of the topics you've learned/are learning: fundamental data types, variables, control flow (conditionals, loops), terminal input/output, etc…\n\nAnother one may be **a simple chatbot in the terminal**. It gives you a list of prompt options, you select one, and it prints a defined answer for the fixed prompt. It's like a super simple version of ChatGPT - you don't need to design and code all the frontend, backend, and ML stuff.\n\n## you had some time with a programming language and can write basic programs\n\nPerfect! Now you are ready to step up your game a little bit and start learning and applying CS fundamentals in your programs to reach a higher level of complexity:\n- **Basic data structures**. Array, linked list, tree, hash map, and stack/queue data structures are in this category.\n- **Basic algorithms**. \n- **File operations**. You won't only interact with the user via the terminal input all the time. Sometimes, you need other communication mediums, and one of the most fundamental ones is **through using a simple file**.\n\nIn this stage, you can add more functionality to the programs you have created until now, adding **dynamism** by implementing:\n- Updating the program data during runtime\n- Not-strictly-defined user interactions\n\n\u003e!char![gopher-info] The idea is forcing yourself to use a new data structure/algorithm in every project you create.\n\nLet's say you have a program that gives you the information of students when you enter the name of one. You can enhance this program to run in a loop that takes the student name, gives the info, **then asks the user if they want to update** the information. To do this, you will need to use a data structure ([linked list](https://en.wikipedia.org/wiki/Linked_list), for example) instead of hardcoded data. Then, you will need to use a [search algorithm](https://en.wikipedia.org/wiki/Search_algorithm) to find specific students given the name. \n\nAdding more functionality pushes you to utilize new stuff in your code, which is an excellent way to learn and practice new concepts in programming.\n\u003c!-- \n```d2\ndirection: right\n\nCode -\u003e Add more functionality -\u003e Learn new stuff -\u003e Code: {\n style.animated: true\n}\n``` --\u003e\n\n## you are fluent in a programming language and know basic CS theory\n\nThis is the time you need to start learning more advanced stuff. Such as:\n- **Storing and retrieving application data.** How/when to use JSON/CSV files, SQL databases, caches, message queues, data serialization algorithms, etc.\n- **Interprocess communication.** This is where the distributed systems practically begin. As the complexity increases, you will need your programs to talk to each other.\n- **Beyond basic data structures and algorithms.** You can put graphs, tries, B+ trees, and bloom filters in this category. These data structures are used inside browsers, databases, search engines, and many more complex systems.\
3n\nIn this stage, you can try to design and implement **your own version of existing stuff** you use, such as creating your own programming language and writing a compiler for it, trying to write your own database engine with indexes, basic queries, and maybe aggregations.\n\n**You don't have to go with a fully functional clone**; for example, creating a programming language with just integer types as the native type is a good exercise, and it's still challenging!\n\nHere are some practical resources and project ideas:\n- **Try to read the Python source code**. The official implementation[^1] is done in C, and it's a good exercise to go over and try to understand how the native data types (`int`, `list`, `dict`, etc.) are implemented, how did they handle memory management, and so on.\n- If you are fluent in Python and can code at least a little bit of C, try to write a **Python extension**[^2]\n- **Try to design and implement your own programming language**. This is a fun project because until now, you were on the consumer side of the languages (if you did not contribute to a programming language), _and now you will be on the creator side!_ Interpreters and compilers are complex computer science topics, but you don't need to know them in detail to implement a simple language processor.\n- **Create a blog engine**. You can develop your own static site generator[^3] and start blogging using your own blog engine. Checking some of the popular static site generators, such as \u003cchip text=\"Hugo\" href=\"https://github.com/gohugoio/hugo\" icon=\"github\"\u003e\u003c/chip\u003e and \u003cchip text=\"Zola\" href=\"https://www.getzola.org/\" icon=\"package\"\u003e\u003c/chip\u003e, can help determine which features to implement in your engine.\n\nSome good resources worth reading/checking for **compiler/interpreter design**:\n- \u003cchip text=\"Writing An Interpreter In Go\" href=\"https://interpreterbook.com/\" icon=\"book\"\u003e\u003c/chip\u003e - Book by Thorsten Ball, going through the steps of writing an interpreter from scratch for a toy programming language \n- \u003cchip text=\"Writing A Compiler In Go\" href=\"https://compilerbook.com/\" icon=\"book\"\u003e\u003c/chip\u003e - Book by Thorsten Ball, sequel to Writing An Interpreter In Go\n- \u003cchip text=\"Crafting Interpreters\" href=\"https://craftinginterpreters.com/\" icon=\"book\"\u003e\u003c/chip\u003e - Book by Robert Nystrom, a good read on interpreter internals\n- **Compilers: Principles, Techniques, and Tools** - The Dragon Book. Maybe the most popular compiler book among the CS students :)\n- \u003cchip text=\"A Compiler Writing Journey\" href=\"https://github.com/DoctorWkt/acwj\" icon=\"github\"\u003e\u003c/chip\u003e - GitHub repo of a self-compiling compiler project. There are implementation notes for all parts, it's worth checking out.\n\n## ~~you are capable of designing and implementing complex stuff~~\n\nThis blog post became longer than I expected, and it's been a while since I started writing, so I will write another one just for this subtopic 🤷‍♂️\n\n## that's all!\n\nI hope you found this content useful. I will add sequels to this post, writing about my side projects or other resources to find fun side project ideas in the future.\n\n\n[^1]: [https://github.com/python/cpython](https://github.com/python/cpython)\n\n[^2]: [https://realpython.com/build-python-c-extension-module/](https://realpython.com/build-python-c-extension-module/)\n\n[^3]: [https://www.cloudflare.com/learning/performance/static-site-generator/](https://www.cloudflare.com/learning/performance/static-site-generator/)"])</script>
3<script>self.__next_f.push([1,"30:T2a47,"])</script>
3<script>self.__next_f.push([1,"\u003cp\u003eSo you are a newbie developer looking for a project idea to apply what you\u0026#39;ve learned in that Udemy course, or maybe an experienced engineer searching for the next side project to work on for fun. Either way, you need a creative idea to bring to life.\u003c/p\u003e\n\u003cp\u003eIt\u0026#39;s a fun way to apply what you have learned in the courses/books and an excellent skill to craft the tool you just need to automate that boring stuff you need to do every day.\u003c/p\u003e\n\u003cp\u003eHere, I will list a few sources/techniques I used to find cool project ideas while learning programming and now to craft useful tools for my needs. \u003cstrong\u003eThis blog post is a little bit opinionated.\u003c/strong\u003e Everyone has a unique learning curve, so if you find my suggestions harder or easier than expected, it\u0026#39;s okay to modify them to fit your level.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/project-complexity-by-time-graph.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch2 id=\"you-have-just-started-learning-programming\"\u003eyou have just started learning programming...\u003c/h2\u003e\n\u003cp\u003e...and looking for project ideas. You probably know Python or JavaScript a little bit, or maybe C/Go, and want to dive into 
3interesting real-life stuff.\u003c/p\u003e\n\u003cp\u003eIn this stage, you should \u003cstrong\u003enot\u003c/strong\u003e dive right into big and complex projects. I know it\u0026#39;s exciting, but hear my reasons:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\u003cstrong\u003eYou probably don\u0026#39;t have the technical background required to build a complex system.\u003c/strong\u003e Whether it\u0026#39;s creating a browser, a search engine, a social media app, …. These projects seem simple from the outside. \u003cem\u003e\u0026#34;I mean, you just enter a search text, and it lists some websites\u0026#34;\u003c/em\u003e, yes, but in the background, there are too many moving parts and some pretty complex algorithms for a beginner. For a browser, you need to write a JavaScript parser; for a search engine, you at least need to understand graphs, and so on.\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eYou may not have the ability to read other people\u0026#39;s code.\u003c/strong\u003e Building complex stuff requires the skill (yes, it\u0026#39;s kind of a skill) to read long lines of production code to see how other engineers solved similar problems. Also, you can\u0026#39;t always find blog posts/videos/docs explaining \u003cem\u003e\u0026#34;how to do X\u0026#34;\u003c/em\u003e after a certain level of problem complexity.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003e\u003cstrong\u003eHowever\u003c/strong\u003e, the most beneficial thing you can do is code simple yet not tedious stuff using the programming topics you learned to jump to advanced levels where you can work on complex projects as fast as possible.\u003c/p\u003e\n\u003cp\u003eI suggest \u003cstrong\u003ecoding simple versions\u003c/strong\u003e of those complex programs, such as \u003cstrong\u003ecreating little terminal-based games\u003c/strong\u003e. You don\u0026#39;t need to learn GUI, a self-made hangman game is still fun after all. Also, while building one, you will need to use most of the topics you\u0026#39;ve learned/are learning: fundamental data types, variables, control flow (conditionals, loops), terminal input/output, etc…\u003c/p\u003e\n\u003cp\u003eAnother one may be \u003cstrong\u003ea simple chatbot in the terminal\u003c/strong\u003e. It gives you a list of prompt options, you select one, and it prints a defined answer for the fixed prompt. It\u0026#39;s like a super simple version of ChatGPT - you don\u0026#39;t need to design and code all the frontend, backend, and ML stuff.\u003c/p\u003e\n\u003ch2 id=\"you-had-some-time-with-a-programming-language-and-can-write-basic-programs\"\u003eyou had some time with a programming language and can write basic programs\u003c/h2\u003e\n\u003cp\u003ePerfect! Now you are ready to step up your game a little bit and start learning and applying CS fundamentals in your programs to reach a higher level of complexity:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cstrong\u003eBasic data structures\u003c/strong\u003e. Array, linked list, tree, hash map, and stack/queue data structures are in this category.\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eBasic algorithms\u003c/strong\u003e.\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eFile operations\u003c/strong\u003e. You won\u0026#39;t only interact with the user via the terminal input all the time. Sometimes, you need other communication mediums, and one of the most fundamental ones is \u003cstrong\u003ethrough using a simple file\u003c/strong\u003e.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eIn this stage, you can add more functionality to the programs you have created until now, adding \u003cstrong\u003edynamism\u003c/strong\u003e by implementing:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eUpdating the program data during runtime\u003c/li\u003e\n\u003cli\u003eNot-strictly-defined user interactions\u003c/li\u003e\n\u003c/ul\u003e\n\u003cblockquote data-quote-character=\"gopher-info\" class=\"quote-character\"\u003e\u003cp\u003e The idea is forcing yourself to use a new data structure/algorithm in every project you create.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eLet\u0026#39;s say you have a program that gives you the information of students when you enter the name of one. You can enhance this program to run in a loop that takes the student name, gives the info, \u003cstrong\u003ethen asks the user if they want to update\u003c/strong\u003e the information. To do this, you will need to use a data structure (\u003ca href=\"https://en.wikipedia.org/wiki/Linked_list\" target=\"_blank\"\u003elinked list\u003c/a\u003e, for example) instead of hardcoded data. Then, you will need to use a \u003ca href=\"https://en.wikipedia.org/wiki/Search_algorithm\" target=\"_blank\"\u003esearch algorithm\u003c/a\u003e to find specific students given the name.\u003c/p\u003e\n\u003cp\u003eAdding more functionality pushes you to utilize new stuff in your code, which is an excellent way to learn and practice new concepts in programming.\u003c/p\u003e\n\u003c!-- \n```d2\ndirection: right\n\nCode -\u0026gt; Add more functionality -\u0026gt; Learn new stuff -\u0026gt;
3 Code: {\n style.animated: true\n}\n``` --\u003e\n\u003ch2 id=\"you-are-fluent-in-a-programming-language-and-know-basic-cs-theory\"\u003eyou are fluent in a programming language and know basic CS theory\u003c/h2\u003e\n\u003cp\u003eThis is the time you need to start learning more advanced stuff. Such as:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cstrong\u003eStoring and retrieving application data.\u003c/strong\u003e How/when to use JSON/CSV files, SQL databases, caches, message queues, data serialization algorithms, etc.\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eInterprocess communication.\u003c/strong\u003e This is where the distributed systems practically begin. As the complexity increases, you will need your programs to talk to each other.\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eBeyond basic data structures and algorithms.\u003c/strong\u003e You can put graphs, tries, B+ trees, and bloom filters in this category. These data structures are used inside browsers, databases, search engines, and many more complex systems.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eIn this stage, you can try to design and implement \u003cstrong\u003eyour own version of existing stuff\u003c/strong\u003e you use, such as creating your own programming language and writing a compiler for it, trying to write your own database engine with indexes, basic queries, and maybe aggregations.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eYou don\u0026#39;t have to go with a fully functional clone\u003c/strong\u003e; for example, creating a programming language with just integer types as the native type is a good exercise, and it\u0026#39;s still challenging!\u003c/p\u003e\n\u003cp\u003eHere are some practical resources and project ideas:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cstrong\u003eTry to read the Python source code\u003c/strong\u003e. The official implementation\u003csup id=\"fnref:1\"\u003e\u003ca href=\"#fn:1\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e1\u003c/a\u003e\u003c/sup\u003e is done in C, and it\u0026#39;s a good exercise to go over and try to understand how the native data types (\u003ccode\u003eint\u003c/code\u003e, \u003ccode\u003elist\u003c/code\u003e, \u003ccode\u003edict\u003c/code\u003e, etc.) are implemented, how did they handle memory management, and so on.\u003c/li\u003e\n\u003cli\u003eIf you are fluent in Python and can code at least a little bit of C, try to write a \u003cstrong\u003ePython extension\u003c/strong\u003e\u003csup id=\"fnref:2\"\u003e\u003ca href=\"#fn:2\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e2\u003c/a\u003e\u003c/sup\u003e\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eTry to design and implement your own programming language\u003c/strong\u003e. This is a fun project because until now, you were on the consumer side of the languages (if you did not contribute to a programming language), \u003cem\u003eand now you will be on the creator side!\u003c/em\u003e Interpreters and compilers are complex computer science topics, but you don\u0026#39;t need to know them in detail to implement a simple language processor.\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eCreate a blog engine\u003c/strong\u003e. You can develop your own static site generator\u003csup id=\"fnref:3\"\u003e\u003ca href=\"#fn:3\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e3\u003c/a\u003e\u003c/sup\u003e and start blogging using your own blog engine. Checking some of the popular static site generators, such as \u003cchip text=\"Hugo\" href=\"https://github.com/gohugoio/hugo\" icon=\"github\"\u003e\u003c/chip\u003e and \u003cchip text=\"Zola\" href=\"https://www.getzola.org/\" icon=\"package\"\u003e\u003c/chip\u003e, can help determine which features to implement in your engine.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eSome good resources worth reading/checking for \u003cstrong\u003ecompiler/interpreter design\u003c/strong\u003e:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cchip text=\"Writing An Interpreter In Go\" href=\"https://interpreterbook.com/\" icon=\"book\"\u003e\u003c/chip\u003e - Book by Thorsten Ball, going through the steps of writing an interpreter from scratch for a toy programming language\u003c/li\u003e\n\u003cli\u003e\u003cchip text=\"Writing A Compiler In Go\" href=\"https://compilerbook.com/\" icon=\"book\"\u003e\u003c/chip\u003e - Book by Thorsten Ball, sequel to Writing An Interpreter In Go\u003c/li\u003e\n\u003cli\u003e\u003cchip text=\"Crafting Interpreters\" href=\"https://craftinginterpreters.com/\" icon=\"book\"\u003e\u003c/chip\u003e - Book by Robert Nystrom, a good read on interpreter internals\u003c/li\u003e\n\u003cli\u003e\u003cstrong\u003eCompilers: Principles, Techniques, and Tools\u003c/strong\u003e - The Dragon Book. Maybe the most popular compiler book among the CS students :)\u003c/li\u003e\n\u003cli\u003e\u003cchip text=\"A Compiler Writing Journey\" href=\"https://github.com/DoctorWkt/acwj\" icon=\"github\"\u003e\u003c/chip\u003e - GitHub repo of a self-compiling compiler project. There are implementation notes for all parts, it\u0026#39;s worth checking out.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"you-are-capable-of-designing-and-implementing-complex-stuff\"\u003e\u003cdel\u003eyou are capable of designing and implementing complex stuff\u003c/del\u003e\u003c/h2\u003e\n\u003cp\u003eThis blog post became longer than I expected, and it\u0026#39;s been a while since I started writing, so I will write another one just for this subtopic 🤷‍♂️\u003c/p\u003e\n\u003ch2 id=\"thats-all\"\u003ethat\u0026#39;s all!\u003c/h2\u003e\n\u003cp\u003eI hope you found this content useful. I will add sequels to this post, writing about my side projects or other resources to find fun side project ideas in the future.\u003c/p\u003e\n\u003cdiv class=\"footnotes\" role=\"doc-endnotes\"\u003e\n\u003chr/\u003e\n\u003col\u003e\n\u003cli id=\"fn:1\" data-index=\"1\"\u003e\n\u003cp\u003e\u003ca href=\"https://github.com/python/cpython\" target=\"_blank\"\u003ehttps://github.com/python/cpython\u003c/a\u003e \u003ca href=\"#fnref:1\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:2\" data-index=\"2\"\u003e\n\u003cp\u003e\u003ca href=\"https://realpython.com/build-python-c-extension-module/\" target=\"_blank\"\u003ehttps://realpython.com/build-python-c-extension-module/\u003c/a\u003e \u003ca href=\"#fnref:2\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:3\" data-index=\"3\"\u003e\n\u003cp\u003e\u003ca href=\"https://www.cloudflare.com/learning/performance/static-site-generator/\" target=\"_blank\"\u003ehttps://www.cloudflare.com/learning/performance/static-site-generator/\u003c/a\u003e \u003ca href=\"#fnref:3\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n"])</script>
3<script>self.__next_f.push([1,"31:T1d6f,"])</script>
3<script>self.__next_f.push([1,"\nI've started reading technical books after my graduation from CS to broaden my knowledge on many topics, such as system design, low-level CS, cloud native, etc. Nowadays, I'm reading \u003cchip text=\"Cloud Native Go\" href=\"https://www.oreilly.com/library/view/cloud-native-go/9781492076322/\" icon=\"book\"\u003e\u003c/chip\u003e by Matthew Titmus, which gives a smooth introduction to the cloud native world using the benefits of Go. The book starts with Go basics and cloud native patterns, and that's where I thought \"I should write about these patterns!\".\n\nIn this series of blog posts, I will write about the cloud native patterns I've learnt – also with illustrations using \u003cchip text=\"Manim\" href=\"https://www.manim.community\" icon=\"package\"\u003e\u003c/chip\u003e.\n## The Problem\nLet's say we have a constant data source (such as a Go [channel](https://go.dev/tour/concurrency/2)), and we need to process the data and put the processed data into a destination channel with a latency as low as possible.\n\nIn the general case, we have a processor function which is in the middle of source and destinations, which processes the data packets (packet here is an abstraction for simplicity) one by one.\n\n![](/assets/articles/fan-in-fan-out-1.png)\n\nHowever, every processing function have latency. This may be because of network or CPU usage, blocking syscalls, etc. If we send enough packets per second to the processor function, voilà! We now have a bottleneck!\n\n![](/assets/articles/fan-in-fan-out-2.png)\n## Solution\nThere's a fairly simple solution to this problem: using multiple processors inside the data pipeline. This way, we can process the data stream concurrently, which drops the overall latency and decreases the pipeline congestion.\n\n![](/assets/articles/fan-in-fan-out-3.png)\n## That's where Fan-in and Fan-out comes in…\nWe can implement this solution by utilizing shared memory, such as message queues.\nWith this approach, we will split the incoming data packets into different input queues. Then, each queue's own processor will take the packets one by one, process the data, and put the processed data into its related output queue. Finally, the destination (another processor, queue, or some other system) will take the processed data packets from each of the output queues, and aggregate them into a single data source.\n\nThe first approach, splitting the data source (input) to multiple data sources (input queues) is called the `Fan-out` pattern. The second one, aggregating multiple data sources (output queues) into a single data source (destination) is called the `Fan-in` pattern.\n\n\u003e For simplicity, we've specified one input queue and one output queue for each processor in our pipeline. We could use multiple input/output queues per processor, or a shared queue between a few processors, depending on the overall system requirements.\n\n\n![](/assets/articles/fan-in-fan-out-4.png)\n\n\n## Go Implementation\nLet's get our hands dirty with some concurrent Go! First, let's define our data sources:\n\n```go\nfunc stringGenerator(prefix string, count uint) \u003c-chan string {\n    ch := make(chan string)\n\n    go func() {\n        defer close(ch)\n        for i := uint(0); i \u003c count; i++ {\n            ch \u003c- fmt.Sprintf(\"%s-%d\", prefix, i)\n        }\n    }()\n\n    return ch\n}\n```\n\nThe function `stringGenerator` creates a receive-only string channel, creates a [goroutine](https://go.dev/tour/concurrency/1) that puts prefixed strings into the channel, and returns the channel. We read from this channel later in the Fan-out code. \n\nOur processor function will be fairly simple too:\n```go\nfunc stringProcessor(id int, source \u003c-chan string) \u003c-chan string {\n    ch := make(chan string)\n\n    go func() {\n        defer close(ch)\n        for data := range source {\n            ch \u003c- fmt.Sprintf(\"P-%d processed message: %s\", id, data)\n            millisecs := rand.Intn(901) + 100\n            time.Sleep(time.Duration(millisecs * int(time.Millisecond)))\n        }\n    }()\n\n    return ch\n}\n```\nInside the processor function, we will wait for a random while to simulate the processor latency.\n### Fan-out Implementation\nIn the Fan-out implementation, we will take a receive-only channel, and return a slice of receive-only channels:\n```go\n// Splitter implements the Fan-out pattern\nfunc Splitter(source \u003c-chan string, numDests uint) []\u003c-chan string {\n    destinations := make([]\u003c-chan string, 0, numDests)\n\n    for i := uint(0); i \u003c numDests; i++ {\n        dest := make(chan string)\n\n        go func() {\n            defer close(dest)\n            for data := range source {\n                dest \u003c- data\n            }\n        }()\n\n        destinations = append(destinations, dest)\n    }\n\n    return destinations\n}\n```\nGoroutines created inside the `Splitter` function will handle the data routing logic. Notice that inside the goroutines, we used a single `range` statement to receive from the `source` channel:\n```go\nfor data := range source {\n    dest \u003c- data\n}\n```\nThis means each goroutine will try to read from the channel in the loop, and the first one to do the read will receive the next item. In other words, **each goroutine will fight over the next data instance**.\n\nWe could use a centralized solution for Fan-out instead of competing goroutines. In that case, we would define a `master process` to distribute each incoming data instance (`string` in our 
3case) among all the output channels.\n### Fan-in Implementation\nIn Fan-in, we will basically do the reverse of Fan-out, with a few differences:\n```go\n// Aggregator implements the Fan-in pattern\nfunc Aggregator(sources []\u003c-chan string) \u003c-chan string {\n    destination := make(chan string)\n\n    var wg sync.WaitGroup\n    wg.Add(len(sources))\n\n    for _, source := range sources {\n        go func(src \u003c-chan string) {\n            defer wg.Done()\n            for data := range src {\n                destination \u003c- data\n            }\n        }(source)\n    }\n    go func() {\n        wg.Wait()\n        close(destination)\n    }()\n\n    return destination\n}\n```\nThe `Aggregator` function takes a slice of receive-only input sources and returns a single receive-only output channel. Inside, we created a goroutine for each input source, which reads from the source continuously and populates the output channel (`destination`) with the data it received.\n\nNotice that we've used a `sync.WaitGroup` to wait for the aggregator goroutines to finish. After an input source (`channel`) is closed, the for loop inside the respective goroutine will end, and it will finish its job.\n\nAfter all input sources are closed, we're done with aggregating, and we now can close the destination channel. **This is a crucial step**, and if we don't close the channel we have created, the Go runtime will complain with a fatal error:\n```bash\nfatal error: all goroutines are asleep - deadlock!\n```\n### main()\nPutting all of our functions together, we're ready to run our code:\n```go\nconst (\n    processorCount = 10\n)\n\nfunc main() {\n    splitSources := Splitter(stringGenerator(\"test\", 100), processorCount)\n    procSources := make([]\u003c-chan string, 0, processorCount)\n\n    for i, src := range splitSources {\n        procSources = append(procSources, stringProcessor(i, src))\n    }\n\n    for out := range Aggregator(procSources) {\n        fmt.Println(out)\n    }\n}\n```\n\n## tl;dr\n- Data pipelines with a single processor will eventually bump into a bottleneck\n- Splitting the input source into several queues and processing concurrently is helpful\n- This split-process-aggregate pattern is called Fan-in/Fan-out\n\nThank you for reading!"])</script>
3<script>self.__next_f.push([1,"32:Ta4c3,"])</script>
3<script>self.__next_f.push([1,"\u003cp\u003eI\u0026#39;ve started reading technical books after my graduation from CS to broaden my knowledge on many topics, such as system design, low-level CS, cloud native, etc. Nowadays, I\u0026#39;m reading \u003cchip text=\"Cloud Native Go\" href=\"https://www.oreilly.com/library/view/cloud-native-go/9781492076322/\" icon=\"book\"\u003e\u003c/chip\u003e by Matthew Titmus, which gives a smooth introduction to the cloud native world using the benefits of Go. The book starts with Go basics and cloud native patterns, and that\u0026#39;s where I thought \u0026#34;I should write about these patterns!\u0026#34;.\u003c/p\u003e\n\u003cp\u003eIn this series of blog posts, I will write about the cloud native patterns I\u0026#39;ve learnt – also with illustrations using \u003cchip text=\"Manim\" href=\"https://www.manim.community\" icon=\"package\"\u003e\u003c/chip\u003e.\u003c/p\u003e\n\u003ch2 id=\"the-problem\"\u003eThe Problem\u003c/h2\u003e\n\u003cp\u003eLet\u0026#39;s say we have a constant data source (such as a Go \u003ca href=\"https://go.dev/tour/concurrency/2\" target=\"_blank\"\u003echannel\u003c/a\u003e), and we need to process the data and put the processed data into a destination channel with a latency as low as possible.\u003c/p\u003e\n\u003cp\u003eIn the general case, we have a processor function which is in the middle of source and destinations, which processes the data packets (packet here is an abstraction for simplicity) one by one.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/fan-in-fan-out-1.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003eHowever, every processing function have latency. This may be because of network or CPU usage, blocking syscalls, etc. If we send enough packets per second to the processor function, voilà! We now have a bottleneck!\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/fan-in-fan-out-2.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch2 id=\"solution\"\u003eSolution\u003c/h2\u003e\n\u003cp\u003eThere\u0026#39;s a fairly simple solution to this problem: using multiple processors inside the data pipeline. This way, we can process the data stream concurrently, which drops the overall latency and decreases the pipeline congestion.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/fan-in-fan-out-3.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch2 id=\"thats-where-fan-in-and-fan-out-comes-in\"\u003eThat\u0026#39;s where Fan-in and Fan-out comes in…\u003c/h2\u003e\n\u003cp\u003eWe can implement this solution by utilizing shared memory, such as message queues.\u003cbr/\u003e\nWith this approach, we will split the incoming data packets into different input queues. Then, each queue\u0026#39;s own processor will take the packets one by one, process the data, and put the processed data into its related output queue. Finally, the destination (another processor, queue, or some other system) will take the processed data packets from each of the output queues, and aggregate them into a single data source.\u003c/p\u003e\n\u003cp\u003eThe first approach, splitting the data source (input) to multiple data sources (input queues) is called the \u003ccode\u003eFan-out\u003c/code\u003e pattern. The second one, aggregating multiple data sources (output queues) into a single data source (destination) is called the \u003ccode\u003eFan-in\u003c/code\u003e pattern.\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003eFor simplicity, we\u0026#39;ve specified one input queue and one output queue for each processor in our pipeline. We could use multiple input/output queues per processor, or a shared queue between a few processors, depending on the overall system requirements.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/fan-in-fan-out-4.png\" alt=\"\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch2 id=\"go-implementation\"\u003eGo Implementation\u003c/h2\u003e\n\u003cp\u003eLet\u0026#39;s get our hands dirty with some concurrent Go! First, let\u0026#39;s define our data sources:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003estringGenerator\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eprefix\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ecount\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ech\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eclose\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ech\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euint\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ecount\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e++\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003ech\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;%s-%d\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eprefix\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ech\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe function \u003ccode\u003estringGenerator\u003c/code\u003e creates a receive-only string channel, creates a \u003ca href=\"https://go.dev/tour/concurrency/1\" target=\"_blank\"\u003egoroutine\u003c/a\u003e that puts prefixed strings into the channel, and returns the channel. We read from this channel later in the Fan-out code.\u003c/p\u003e\n\u003cp\u003eOur processor function will be fairly simple too:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003estringProcessor\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eid\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ech\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eclose\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ech\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003ech\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSprintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;P-%d processed message: %s\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eid\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003emillisecs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003erand\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eIntn\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e901\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003etime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSleep\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003etime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eDuration\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003emillisecs\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003etime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMillisecond\u003c/span\u003e\u003cspan style=\"\"\u003e)))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ech\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eInside the processor function, we will wait for a random while to simulate the processor latency.\u003c/p\u003e\n\u003ch3 id=\"fan-out-implementation\"\u003eFan-out Implementation\u003c/h3\u003e\n\u003cp\u003eIn the Fan-out implementation, we will take a receive-only channel, and return a slice of receive-only channels:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// Splitter implements the Fan-out pattern\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSplitter\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enumDests\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003euint\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003edestinations\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e([]\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enumDests\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003euint\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e);\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e\u0026lt;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enumDests\u003c/span\u003e\u003cspan style=\"\"\u003e;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e++\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003edest\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eclose\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edest\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e                \u003c/span\u003e\u003cspan style=\"\"\u003edest\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003edestinations\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edestinations\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edest\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e
3\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edestinations\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eGoroutines created inside the \u003ccode\u003eSplitter\u003c/code\u003e function will handle the data routing logic. Notice that inside the goroutines, we used a single \u003ccode\u003erange\u003c/code\u003e statement to receive from the \u003ccode\u003esource\u003c/code\u003e channel:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003edest\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis means each goroutine will try to read from the channel in the loop, and the first one to do the read will receive the next item. In other words, \u003cstrong\u003eeach goroutine will fight over the next data instance\u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003eWe could use a centralized solution for Fan-out instead of competing goroutines. In that case, we would define a \u003ccode\u003emaster process\u003c/code\u003e to distribute each incoming data instance (\u003ccode\u003estring\u003c/code\u003e in our case) among all the output channels.\u003c/p\u003e\n\u003ch3 id=\"fan-in-implementation\"\u003eFan-in Implementation\u003c/h3\u003e\n\u003cp\u003eIn Fan-in, we will basically do the reverse of Fan-out, with a few differences:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e// Aggregator implements the Fan-in pattern\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eAggregator\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003esources\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003edestination\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ewg\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esync\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eWaitGroup\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ewg\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eAdd\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003elen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003esources\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esources\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003esrc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003edefer\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ewg\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eDone\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esrc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e                \u003c/span\u003e\u003cspan style=\"\"\u003edestination\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edata\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e}(\u003c/span\u003e\u003cspan style=\"\"\u003esource\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ego\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003ewg\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWait\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eclose\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edestination\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}()\u003c/span\u003e\u003cspan st
3yle=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003edestination\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThe \u003ccode\u003eAggregator\u003c/code\u003e function takes a slice of receive-only input sources and returns a single receive-only output channel. Inside, we created a goroutine for each input source, which reads from the source continuously and populates the output channel (\u003ccode\u003edestination\u003c/code\u003e) with the data it received.\u003c/p\u003e\n\u003cp\u003eNotice that we\u0026#39;ve used a \u003ccode\u003esync.WaitGroup\u003c/code\u003e to wait for the aggregator goroutines to finish. After an input source (\u003ccode\u003echannel\u003c/code\u003e) is closed, the for loop inside the respective goroutine will end, and it will finish its job.\u003c/p\u003e\n\u003cp\u003eAfter all input sources are closed, we\u0026#39;re done with aggregating, and we now can close the destination channel. \u003cstrong\u003eThis is a crucial step\u003c/strong\u003e, and if we don\u0026#39;t close the channel we have created, the Go runtime will complain with a fatal error:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003efatal error: all goroutines are asleep - deadlock!\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003ch3 id=\"main\"\u003emain()\u003c/h3\u003e\n\u003cp\u003ePutting all of our functions together, we\u0026#39;re ready to run our code:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003econst\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eprocessorCount\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003emain\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003esplitSources\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSplitter\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003estringGenerator\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;test\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eprocessorCount\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eprocSources\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003emake\u003c/span\u003e\u003cspan style=\"\"\u003e([]\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026lt;-\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003echan\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eprocessorCount\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esrc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esplitSources\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eprocSources\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eprocSources\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003estringProcessor\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003ei\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003esrc\u003c/span\u003e\u003cspan style=\"\"\u003e))\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eout\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eAggregator\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eprocSources\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintln\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eout\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003ch2 id=\"tldr\"\u003etl;dr\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003eData pipelines with a single processor will eventually bump into a bottleneck\u003c/li\u003e\n\u003cli\u003eSplitting the input source into several queues and processing concurrently is helpful\u003c/li\u003e\n\u003cli\u003eThis split-process-aggregate pattern is called Fan-in/Fan-out\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eThank y
3ou for reading!\u003c/p\u003e\n"])</script>
3<script>self.__next_f.push([1,"33:T2bd2,"])</script>
3<script>self.__next_f.push([1,"\n\nThis week my last term in college is finished and my brain started to come up with creative ides, so I started working on one of the fancy ones: developing a file manager with GUI that I can use in terminal, with Go.\n\nBefore diving into my design and development process, here’s a little backstory: I use a 2019 model MacBook Pro storage as my development machine. Since it only has 256 GB storage, I frequently run out of space and try to find which files take up most of the space and which of them to delete.  Here I have a few options and the one I do is basically using `du` command to find out the biggest files on terminal:\n\n```bash\n$ du -shc ~/* | sort -rh\n```\n\nThis basically works out, but I find myself consistently bragging about `du` not having an interactive interface that also lists the filesystem in tree format with file/folder sizes.\n\nAnd that’s where I said out loud: I should do this!\n\n## The initial design\nAfter deciding to develop a program for this idea, I thought of the main features this program should provide for my daily use:\n* List files and folders under a specified path in tree view\n* Show total size of the file/folder in KB, MB, GB, etc.\n* Show file type (MIME and file extension) as the `file` command does\n* Show file/folder permissions\n* Optionally show last modification or creation time of files\n* Search files by name with regular expressions\n* Create (`touch`-like), move, copy, remove files\n* Open files with the default or specified program\n\nMany other features could be added, but these are the trivial ones :) I also decided to name my program `gls`, a mimicking `“graphical ls”`.\n\n![Initial UI design of gls that I've drawn on iPad](/assets/articles/Screen%20Shot%202022-07-10%20at%2010.40.33.png)\n\n## Walking down the filesystem\nBefore diving deep into coding the UI, we first need to build a virtual filesystem representation of the original folder structure with the path we’re currently interested in. This representation will make us able to show the real folder structure in the UI in tree view. It will also help us perform specific file- and folder-related operations, such as copying and removing, by using the virtual representation to get info of specific files and folders instead of using system calls to get the same information each time.\n\nSpeaking of which, most of the operating systems hold the whole filesystem structure as a one-rooted tree data structure, where all folders and files are child nodes of the root node or another node with a higher-level parent node. This type of data structure is also called “directed acyclic graph”.\n\n![An example file tree in UNIX-like filesystem format](/assets/articles/Screen%20Shot%202022-07-10%20at%2010.39.22.png)\n\n\u003e!char![gopher-info-2] Extra information: in Linux and UNIX-like systems, every node in the filesystem tree is a file[^1]. Even directories, drivers (files under `/dev`), terminals (eg. `/dev/tty`), etc. are files with special properties.\n\nComing back to our virtual filesystem representation, it will be sufficient to construct a basic tree data structure that you’ve probably coded from scratch in a DS course:\n\n```go\ntype Node struct {\n    Name             string\n    Mode             os.FileMode\n    Size             int64\n    SizeOnDisk       int64\n    IsDir            bool\n    LastModification time.Time\n    Children         []*Node\n    Parent           *Node\n}\n```\n\n\u003e!char![gopher-info] You may be asking “Why `Size` is a signed integer while it’s used for the size of an entity which can’t be negative?”. Well, the answer is `os.FileInfo`’s size property is also `int64` and that’s also probably because of why `len()` returns a signed integer, to prevent integer underflows in arithmetic calculations[^2]. Also, storing the size in `int64` makes us able to properly store the size of files/folders *up to 16777216 TB*, so it’s actually not a downside to use signed integers here.\n\nThe reason that we have both `Size` and `SizeOnDisk` is that, `Size` shows the actual number of bytes a specific file consists of. But as the operating systems allocates a number of blocks on the storage device for each file, the real size on the disk is a multiple of `block_size`[^3] (Even if the file content is a single byte, the size of the storage area allocated for the file will be `block_size` bytes[^4]). So we calculate `SizeOnDisk` by `block_size * number_of_blocks`.\n\nNow it’s time to walk on the file tree. To do this, we need to use a tree traversal algorithm[^5], which are pretty straightforward. I will explain the traversal basics in the next subtitle, so you can pass it if it’s too basic for you.\n\n### Primer on tree traversals\nThe most trivial tree traversal algorithm is depth-first search, where we walk down the tree from a node as deep as possible before hopping to its siblings. DFS can be used as pre-order, post-order and in-order. The only difference is when do we process the root (or current) node, other than that, what DFS does is iteratively applying the same traversal to the child subtrees of the specific node. \n\nIn pre-order traversal, we visit the root node and then the children one by one (root-Left-Right for example if we have a binary tree). In post-order, we visit the children one by one and then the root node eventually (e.g L-R-root). Likewise in in-order traversal we visit the root node in between visiting the child nodes (e.g L-root-R).\n\n![Node visiting order visualization in the same binary tree using post-order (left) and pre-order (right) algorithms](/assets/articles/IMG_B1947371A873-1.jpeg)\n\n### Coding the traversal function\nFor the sake of implementation simplicity, I decided to use pre-order traversal to walk in the file tree and construct the `*Node` tree on our side.\n\n```go\nfunc Walk(path string) (*Node, error) {\n    f, err := os.Lstat(path)\n    if err != nil {\n        log.Warningf(\"%s: %v\", path, err)\n        return nil, nil\n    }\n    st, ok := f.Sys().(*syscall.Stat_t)\n    if !ok {\n        return nil, fmt.Errorf(\"could not cast 
3%T to syscall.Stat_t\", f.Sys())\n    }\n    root := \u0026Node{\n        Name:             f.Name(),\n        Mode:             f.Mode(),\n        Size:             st.Size,\n        SizeOnDisk:       st.Blocks * 512,\n        IsDir:            f.IsDir(),\n        LastModification: f.ModTime(),\n    }\n    if root.IsDir {\n        names, err := readDirNames(path)\n        if err != nil {\n            log.Warningf(\"%s: %v\", path, err)\n            return root, nil\n        }\n        for _, name := range names {\n            child, err := Walk(path + \"/\" + name)\n            if err != nil {\n                return nil, err\n            }\n            child.Parent = root\n            root.Size += child.Size\n            root.SizeOnDisk += child.SizeOnDisk\n            root.Children = append(root.Children, child)\n        }\n    }\n    return root, nil\n}\n```\n\nWe call `os.Lstat` for each node in the file tree to get the file/directory information. The `os.Lstat` function uses the `lstat`[^6] system call internally, which returns `struct stat` structure. Then,  `os.Lstat` uses  `struct stat` to return `os.FileInfo`, which is an easily usable variant of `struct stat`.\n\nAfter getting the file information, we construct the root node of type `*Node`, and then call `Walk` for each of its children if root is a directory, and lastly update the child nodes’ root, the root’s size and so on. 
3Children of the root are found by the `readDirNames` function, which basically reads the directories under the specified path and sorts them by their name[^7]. The `SizeOnDisk` calculation is done by using `Stat_t.Blocks`. The `Stat_t` structure is the Go equivalent of Linux kernel’s `struct stat`, and `Stat_t.Blocks` is the number of 512-byte blocks that the file uses.\n\n\u003e!char![beaver-question] Please note that this code we’ve written will only work in Linux and UNIX-like systems!\n\nWe can now call `Walk` and test it on a real directory:\n\n```go\nimport (\n    \"flag\"\n    \"fmt\"\n    \"os\"\n    \"sort\"\n    \"strings\"\n    \"syscall\" \n    \"time\"\n\n    \"github.com/ozansz/gls/log\"\n)\n\ntype Node struct {\n    Name             string\n    Mode             os.FileMode\n    Size             int64\n    SizeOnDisk       int64\n    IsDir            bool\n    LastModification time.Time\n    Children         []*Node\n    Parent           *Node\n}\n\nfunc (n *Node) Print() {\n    n.printWithLevel(0)\n}\n\nfunc (n *Node) printWithLevel(level int) {\n    fmt.Printf(\"%s%s [%s] [%d]\\n\", strings.Repeat(\"  \", level),\n        n.Name, n.Mode.String(), n.SizeOnDisk)\n    for _, child := range n.Children {\n        child.printWithLevel(level + 1)\n    }\n}\n\nvar (\n    path = flag.String(\"path\", \"\", \"path to walk\")\n)\n\nfunc main() {\n    flag.Parse()\n    if *path == \"\" {\n        flag.Usage()\n        return\n    }\n\n}\n\nfunc Walk(path string) (*Node, error) {\n    f, err := os.Lstat(path)\n    if err != nil {\n        log.Warningf(\"%s: %v\", path, err)\n        return nil, nil\n    }\n    st, ok := f.Sys().(*syscall.Stat_t)\n    if !ok {\n        return nil, fmt.Errorf(\"could not cast %T to syscall.Stat_t\", f.Sys())\n    }\n    root := \u0026Node{\n        Name:             f.Name(),\n        Mode:             f.Mode(),\n        Size:             st.Size,\n        SizeOnDisk:       st.Blocks * 512,\n        IsDir:            f.IsDir(),\n        LastModification: f.ModTime(),\n    }\n    if root.IsDir {\n        names, err := readDirNames(path)\n        if err != nil {\n            log.Warningf(\"%s: %v\", path, err)\n            return root, nil\n        }\n        for _, name := range names {\n            child, err := Walk(path + \"/\" + name)\n            if err != nil {\n                return nil, err\n            }\n            child.Parent = root\n            root.Size += child.Size\n            root.SizeOnDisk += child.SizeOnDisk\n            root.Children = append(root.Children, child)\n        }\n    }\n    return root, nil\n}\n\n// Taken directly from the Go stdlib\nfunc readDirNames(dirname string) ([]string, error) {\n    f, err := os.Open(dirname)\n    if err != nil {\n        return nil, err\n    }\n    names, err := f.Readdirnames(-1)\n    f.Close()\n    if err != nil {\n        return nil, err\n    }\n    sort.Strings(names)\n    return names, nil\n}\n```\n\nWhen we save this code as `main.go` and run it by specifying a path,\n\n```bash\n$ go run main.go --path ~/root-folder\n```\n\n…and assume that the file tree is something like that:\n\n![Example file tree for the Walk function test](/assets/articles/Screen%20Shot%202022-07-10%20at%2010.38.48.png)\n\n…we will see an output like that:\n\n```bash\nroot-folder [drwxr-xr-x] [10010624]\n  subfolder [drwxr-xr-x] [10002432]\n    file_3.mp4 [-rw-r--r--] [9998336]\n  file_1.c [-rw-rw-r] [8192]\n  file_2.sh [-rw-r---] [4096]\n```\n\n[^1]: https://en.wikipedia.org/wiki/Unix_filesystem\n\n[^2]: https://stackoverflow.com/questions/39088945/why-does-len-returned-a-signed-value\n\n[^3]: https://wiki.linuxquestions.org/wiki/Block_devices_and_block_sizes\n\n[^4]: https://tldp.org/LDP/sag/html/filesystems.html\n\n[^5]: https://en.wikipedia.org/wiki/Tree_traversal\n\n[^6]: https://man7.org/linux/man-pages/man2/lstat.2.html\n\n[^7]: https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/path/filepath/path.go;l=543"])</script>
3<script>self.__next_f.push([1,"34:T11928,"])</script>
3<script>self.__next_f.push([1,"\u003cp\u003eThis week my last term in college is finished and my brain started to come up with creative ides, so I started working on one of the fancy ones: developing a file manager with GUI that I can use in terminal, with Go.\u003c/p\u003e\n\u003cp\u003eBefore diving into my design and development process, here’s a little backstory: I use a 2019 model MacBook Pro storage as my development machine. Since it only has 256 GB storage, I frequently run out of space and try to find which files take up most of the space and which of them to delete.  Here I have a few options and the one I do is basically using \u003ccode\u003edu\u003c/code\u003e command to find out the biggest files on terminal:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ du -shc ~/* \u003c/span\u003e\u003cspan style=\"\"\u003e|\u003c/span\u003e\u003cspan style=\"\"\u003e sort -rh\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThis basically works out, but I find myself consistently bragging about \u003ccode\u003edu\u003c/code\u003e not having an interactive interface that also lists the filesystem in tree format with file/folder sizes.\u003c/p\u003e\n\u003cp\u003eAnd that’s where I said out loud: I should do this!\u003c/p\u003e\n\u003ch2 id=\"the-initial-design\"\u003eThe initial design\u003c/h2\u003e\n\u003cp\u003eAfter deciding to develop a program for this idea, I thought of the main features this program should provide for my daily use:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eList files and folders under a specified path in tree view\u003c/li\u003e\n\u003cli\u003eShow total size of the file/folder in KB, MB, GB, etc.\u003c/li\u003e\n\u003cli\u003eShow file type (MIME and file extension) as the \u003ccode\u003efile\u003c/code\u003e command does\u003c/li\u003e\n\u003cli\u003eShow file/folder permissions\u003c/li\u003e\n\u003cli\u003eOptionally show last modification or creation time of files\u003c/li\u003e\n\u003cli\u003eSearch files by name with regular expressions\u003c/li\u003e\n\u003cli\u003eCreate (\u003ccode\u003etouch\u003c/code\u003e-like), move, copy, remove files\u003c/li\u003e\n\u003cli\u003eOpen files with the default or specified program\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eMany other features could be added, but these are the trivial ones :) I also decided to name my program \u003ccode\u003egls\u003c/code\u003e, a mimicking \u003ccode\u003e“graphical ls”\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/Screen%20Shot%202022-07-10%20at%2010.40.33.png\" alt=\"Initial UI design of gls that I\u0026#39;ve drawn on iPad\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch2 id=\"walking-down-the-filesystem\"\u003eWalking down the filesystem\u003c/h2\u003e\n\u003cp\u003eBefore diving deep into coding the UI, we first need to build a virtual filesystem representation of the original folder structure with the path we’re currently interested in. This representation will make us able to show the real folder structure in the UI in tree view. It will also help us perform specific file- and folder-related operations, such as copying and removing, by using the virtual representation to get info of specific files and folders instead of using system calls to get the same information each time.\u003c/p\u003e\n\u003cp\u003eSpeaking of which, most of the operating systems hold the whole filesystem structure as a one-rooted tree data structure, where all folders and files are child nodes of the root node or another node with a higher-level parent node. This type of data structure is also called “directed acyclic graph”.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/Screen%20Shot%202022-07-10%20at%2010.39.22.png\" alt=\"An example file tree in UNIX-like filesystem format\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cblockquote data-quote-character=\"go
3pher-info-2\" class=\"quote-character\"\u003e\u003cp\u003e Extra information: in Linux and UNIX-like systems, every node in the filesystem tree is a file\u003csup id=\"fnref:1\"\u003e\u003ca href=\"#fn:1\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e1\u003c/a\u003e\u003c/sup\u003e. Even directories, drivers (files under \u003ccode\u003e/dev\u003c/code\u003e), terminals (eg. \u003ccode\u003e/dev/tty\u003c/code\u003e), etc. are files with special properties.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eComing back to our virtual filesystem representation, it will be sufficient to construct a basic tree data structure that you’ve probably coded from scratch in a DS course:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eMode\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eFileMode\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eIsDir\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebool\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eLastModification\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003etime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eTime\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eChildren\u003c/span\u003e\u003cspan style=\"\"\u003e         \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eParent\u003c/span\u003e\u003cspan style=\"\"\u003e           \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cblockquote data-quote-character=\"go
3pher-info\" class=\"quote-character\"\u003e\u003cp\u003e You may be asking “Why \u003ccode\u003eSize\u003c/code\u003e is a signed integer while it’s used for the size of an entity which can’t be negative?”. Well, the answer is \u003ccode\u003eos.FileInfo\u003c/code\u003e’s size property is also \u003ccode\u003eint64\u003c/code\u003e and that’s also probably because of why \u003ccode\u003elen()\u003c/code\u003e returns a signed integer, to prevent integer underflows in arithmetic calculations\u003csup id=\"fnref:2\"\u003e\u003ca href=\"#fn:2\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e2\u003c/a\u003e\u003c/sup\u003e. Also, storing the size in \u003ccode\u003eint64\u003c/code\u003e makes us able to properly store the size of files/folders \u003cem\u003eup to 16777216 TB\u003c/em\u003e, so it’s actually not a downside to use signed integers here.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eThe reason that we have both \u003ccode\u003eSize\u003c/code\u003e and \u003ccode\u003eSizeOnDisk\u003c/code\u003e is that, \u003ccode\u003eSize\u003c/code\u003e shows the actual number of bytes a specific file consists of. But as the operating systems allocates a number of blocks on the storage device for each file, the real size on the disk is a multiple of \u003ccode\u003eblock_size\u003c/code\u003e\u003csup id=\"fnref:3\"\u003e\u003ca href=\"#fn:3\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e3\u003c/a\u003e\u003c/sup\u003e (Even if the file content is a single byte, the size of the storage area allocated for the file will be \u003ccode\u003eblock_size\u003c/code\u003e bytes\u003csup id=\"fnref:4\"\u003e\u003ca href=\"#fn:4\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e4\u003c/a\u003e\u003c/sup\u003e). So we calculate \u003ccode\u003eSizeOnDisk\u003c/code\u003e by \u003ccode\u003eblock_size * number_of_blocks\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eNow it’s time to walk on the file tree. To do this, we need to use a tree traversal algorithm\u003csup id=\"fnref:5\"\u003e\u003ca href=\"#fn:5\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e5\u003c/a\u003e\u003c/sup\u003e, which are pretty straightforward. I will explain the traversal basics in the next subtitle, so you can pass it if it’s too basic for you.\u003c/p\u003e\n\u003ch3 id=\"primer-on-tree-traversals\"\u003ePrimer on tree traversals\u003c/h3\u003e\n\u003cp\u003eThe most trivial tree traversal algorithm is depth-first search, where we walk down the tree from a node as deep as possible before hopping to its siblings. DFS can be used as pre-order, post-order and in-order. The only difference is when do we process the root (or current) node, other than that, what DFS does is iteratively applying the same traversal to the child subtrees of the specific node.\u003c/p\u003e\n\u003cp\u003eIn pre-order traversal, we visit the root node and then the children one by one (root-Left-Right for example if we have a binary tree). In post-order, we visit the children one by one and then the root node eventually (e.g L-R-root). Likewise in in-order traversal we visit the root node in between visiting the child nodes (e.g L-root-R).\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/IMG_B1947371A873-1.jpeg\" alt=\"Node visiting order visualization in the same binary tree using post-order (left) and pre-order (right) algorithms\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003ch3 id=\"coding-the-traversal-function\"\u003eCoding the traversal function\u003c/h3\u003e\n\u003cp\u003eFor the sake of implementation simplicity, I decided to use pre-order traversal to walk in the file tree and construct the \u003ccode\u003e*Node\u003c/code\u003e tree on our side.\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWalk\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eerror\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eLstat\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWarningf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;%s: %v\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003est\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eok\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSys\u003c/span\u003e\u003cspan style=\"\"\u003e().(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003esyscall\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eStat_t\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e!\u003c/span\u003e\u003cspan style=\"\"\u003eok\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eErrorf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;could not cast %T to syscall.Stat_t\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSys\u003c/span\u003e\u003cspan style=\"\"\u003e())\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eMode\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eMode\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"\"\u003est\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"\"\u003est\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eBlocks\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e512\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eIsDir\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eIsDir\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eLastModification\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eModTime\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eIsDir\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003enames\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ereadDirNames\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWarningf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;%s: %v\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ename\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enames\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWalk\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;/\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ename\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;
3color:#7f7f7f\"\u003e28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e                \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eParent\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eChildren\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eChildren\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e34\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e35\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e36\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e37\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWe call \u003ccode\u003eos.Lstat\u003c/code\u003e for each node in the file tree to get the file/directory information. The \u003ccode\u003eos.Lstat\u003c/code\u003e function uses the \u
3003ccode\u003elstat\u003c/code\u003e\u003csup id=\"fnref:6\"\u003e\u003ca href=\"#fn:6\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e6\u003c/a\u003e\u003c/sup\u003e system call internally, which returns \u003ccode\u003estruct stat\u003c/code\u003e structure. Then,  \u003ccode\u003eos.Lstat\u003c/code\u003e uses  \u003ccode\u003estruct stat\u003c/code\u003e to return \u003ccode\u003eos.FileInfo\u003c/code\u003e, which is an easily usable variant of \u003ccode\u003estruct stat\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eAfter getting the file information, we construct the root node of type \u003ccode\u003e*Node\u003c/code\u003e, and then call \u003ccode\u003eWalk\u003c/code\u003e for each of its children if root is a directory, and lastly update the child nodes’ root, the root’s size and so on. Children of the root are found by the \u003ccode\u003ereadDirNames\u003c/code\u003e function, which basically reads the directories under the specified path and sorts them by their name\u003csup id=\"fnref:7\"\u003e\u003ca href=\"#fn:7\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e7\u003c/a\u003e\u003c/sup\u003e. The \u003ccode\u003eSizeOnDisk\u003c/code\u003e calculation is done by using \u003ccode\u003eStat_t.Blocks\u003c/code\u003e. The \u003ccode\u003eStat_t\u003c/code\u003e structure is the Go equivalent of Linux kernel’s \u003ccode\u003estruct stat\u003c/code\u003e, and \u003ccode\u003eStat_t.Blocks\u003c/code\u003e is the number of 512-byte blocks that the file uses.\u003c/p\u003e\n\u003cblockquote data-quote-character=\"beaver-question\" class=\"quote-character\"\u003e\u003cp\u003e Please note that this code we’ve written will only work in Linux and UNIX-like systems!\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eWe can now call \u003ccode\u003eWalk\u003c/code\u003e and test it on a real directory:\u003c/p\u003e\n\u003cpre data-language=\"go\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#ff79c6\"\u003eimport\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;flag\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;fmt\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;os\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;sort\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  6\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;strings\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  7\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;syscall\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e \n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  8\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;time\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e  9\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 10\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;github.com/ozansz/gls/log\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 11\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 12\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 13\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003etype\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003estruct\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 14\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 15\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eMode\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eFileMode\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 16\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 17\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint64\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 18\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eIsDir\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003ebool\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 19\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eLastModification\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003etime\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eTime\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 20\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eChildren\u003c/span\u003e\u003cspan style=\"\"\u003e         \u003c/span\u003e\u003cspan style=\"\"\u003e[]\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 21\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eParent\u003c/span\u003e\u003cspan style=\"\"\u003e           \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 22\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 23\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 24\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrint\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 25\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eprintWithLevel\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e0\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 26\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 27\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 28\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eprintWithLevel\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003elevel\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eint\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 29\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ePrintf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;%s%s [%s] [%d]\\n\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003estrings\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eRepeat\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;  \u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003elevel\u003c/span\u003e\u003cspan style=\"\"\u003e),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 30\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eMode\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 31\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003en\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eChildren\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 32\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eprintWithLevel\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003elevel\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 33\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 34\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 35\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 36\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003evar\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 37\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eflag\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eString\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;path\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;path to walk\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 38\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 39\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 40\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003emain\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 41\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eflag\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eParse\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 42\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e==\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 43\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eflag\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eUsage\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 44\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 45\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 46\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 47\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 48\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 49\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWalk\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eerror\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 50\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eLstat\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 51\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 52\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWarningf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;%s: %v\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 53\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 54\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 55\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003est\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eok\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSys\u003c/span\u003e\u003cspan style=\"\"\u003e().(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003esyscall\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eStat_t\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 56\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e!\u003c/span\u003e\u003cspan style=\"\"\u003eok\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 57\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003efmt\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eErrorf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;could not cast %T to syscall.Stat_t\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eSys\u003c/span\u003e\u003cspan style=\"\"\u003e())\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 58\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 59\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e\u0026amp;\u003c/span\u003e\u003cspan style=\"\"\u003eNode\u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 60\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eName\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 61\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eMode\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eMode\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 62\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e             \u003c/span\u003e\u003cspan style=\"\"\u003est\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 63\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003cspan style=\"\"\u003est\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eBlocks\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e*\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e512\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 64\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eIsDir\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eIsDir\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 65\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003eLastModification\u003c/span\u003e\u003cspan style=\"\"\u003e:\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eModTime\u003c/span\u003e\u003cspan style=\"\"\u003e(),\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 66\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 67\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eIsDir\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 68\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003enames\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ereadDirNames\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 69\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 70\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003elog\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWarningf\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;%s: %v\u0026#34;
3\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 71\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 72\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 73\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003efor\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e_\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ename\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003erange\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enames\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 74\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eWalk\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003epath\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#f1fa8c\"\u003e\u0026#34;/\u0026#34;\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ename\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 75\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 76\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e                \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 77\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 78\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eParent\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 79\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSize\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 80\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e+=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eSizeOnDisk\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 81\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e            \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eChildren\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003eappend\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"\"\u003eChildren\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003echild\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 82\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 83\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 84\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eroot\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 85\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 86\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 87\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"color:#6272a4\"\u003e// Taken directly from the Go stdlib\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 88\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"color:#6272a4\"\u003e\u003c/span\u003e\u003cspan style=\"color:#8be9fd;font-style:italic\"\u003efunc\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003ereadDirNames\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edirname\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e([]\u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003estring\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#8be9fd\"\u003eerror\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 89\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eos\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eOpen\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003edirname\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 90\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 91\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 92\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 93\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003enames\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e:=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eReaddirnames\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e-\u003c/span\u003e\u003cspan style=\"color:#bd93f9\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-sel
3ect:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 94\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003ef\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eClose\u003c/span\u003e\u003cspan style=\"\"\u003e()\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 95\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003eif\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e!=\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003e{\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 96\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e        \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003eerr\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 97\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 98\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"\"\u003esort\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#50fa7b\"\u003eStrings\u003c/span\u003e\u003cspan style=\"\"\u003e(\u003c/span\u003e\u003cspan style=\"\"\u003enames\u003c/span\u003e\u003cspan style=\"\"\u003e)\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e 99\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003ereturn\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"\"\u003enames\u003c/span\u003e\u003cspan style=\"\"\u003e,\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003enil\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e100\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003cspan style=\"\"\u003e}\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eWhen we save this code as \u003ccode\u003emain.go\u003c/code\u003e and run it by specifying a path,\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e$ go run main.go --path ~/root-folder\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cp\u003e…and assume that the file tree is something like that:\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/assets/articles/Screen%20Shot%202022-07-10%20at%2010.38.48.png\" alt=\"Example file tree for the Walk function test\" loading=\"lazy\"/\u003e\u003c/p\u003e\n\u003cp\u003e…we will see an output like that:\u003c/p\u003e\n\u003cpre data-language=\"bash\" tabindex=\"0\" style=\"color:#f8f8f2;background-color:#282a36;\"\u003e\u003ccode\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e1\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eroot-folder \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003edrwxr-xr-x\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10010624\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e2\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e  subfolder \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003edrwxr-xr-x\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e10002432\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e3\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e    file_3.mp4 \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e-rw-r--r--\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e9998336\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e4\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e  file_1.c \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e-rw-rw-r\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e8192\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan style=\"white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\"\u003e5\u003c/span\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003e  file_2.sh \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e-rw-r---\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e4096\u003c/span\u003e\u003cspan style=\"color:#ff79c6\"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003cdiv class=\"footnotes\" role=\"doc-endnotes\"\u003e\n\u003chr/\u003e\n\u003col\u003e\n\u003cli id=\"fn:1\" data-index=\"1\"\u003e\n\u003cp\u003e\u003ca href=\"https://en.wikipedia.org/wiki/Unix_filesystem\"\u003ehttps://en.wikipedia.org/wiki/Unix_filesystem\u003c/a\u003e \u003ca href=\"#fnref:1\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:2\" data-index=\"2\"\u003e\n\u003cp\u003e\u003ca href=\"https://stackoverflow.com/questions/39088945/why-does-len-returned-a-signed-value\"\u003ehttps://stackoverflow.com/questions/39088945/why-does-len-returned-a-signed-value\u003c/a\u003e \u003ca href=\"#fnref:2\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:3\" data-index=\"3\"\u003e\n\u003cp\u003e\u003ca href=\"https://wiki.linuxquestions.org/wiki/Block_devices_and_block_sizes\"\u003ehttps://wiki.linuxquestions.org/wiki/Block_devices_and_block_sizes\u003c/a\u003e \u003ca href=\"#fnref:3\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:4\" data-index=\"4\"\u003e\n\u003cp\u003e\u003ca href=\"https://tldp.org/LDP/sag/html/filesystems.html\"\u003ehttps://tldp.org/LDP/sag/html/filesystems.html\u003c/a\u003e \u003ca href=\"#fnref:4\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:5\" data-index=\"5\"\u003e\n\u003cp\u003e\u003ca href=\"https://en.wikipedia.org/wiki/Tree_traversal\"\u003ehttps://en.wikipedia.org/wiki/Tree_traversal\u003c/a\u003e \u003ca href=\"#fnref:5\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:6\" data-index=\"6\"\u003e\n\u003cp\u003e\u003ca href=\"https://man7.org/linux/man-pages/man2/lstat.2.html\"\u003ehttps://man7.org/linux/man-pages/man2/lstat.2.html\u003c/a\u003e \u003ca href=\"#fnref:6\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli id=\"fn:7\" data-index=\"7\"\u003e\n\u003cp\u003e\u003ca href=\"https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src
3/path/filepath/path.go;l=543\"\u003ehttps://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/path/filepath/path.go;l=543\u003c/a\u003e \u003ca href=\"#fnref:7\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e↩︎\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n"])</script>
3<script>self.__next_f.push([1,"1f:[\"$\",\"div\",null,{\"className\":\"content\",\"children\":[[\"$\",\"$Ld\",null,{\"href\":\"/articles\",\"children\":[\"$\",\"h2\",null,{\"className\":\"mb-4 mt-8\",\"children\":\"Articles\"}],\"className\":\"items-center justify-center rounded-md text-sm font-medium transition-colors duration-300 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950 disabled:pointer-events-none disabled:opacity-50 dark:focus-visible:ring-gray-300 text-gray-900 underline-offset-4 hover:underline dark:text-gray-50 h-9 py-2 inline px-0\",\"ref\":null}],[\"$\",\"$5\",null,{\"fallback\":[\"$\",\"div\",null,{\"className\":\"grid place-content-center h-screen w-full\",\"children\":[\"$\",\"div\",null,{\"className\":\"inline-block h-4 w-4 animate-spin rounded-full border-[2px] border-current border-t-transparent text-black\",\"role\":\"status\",\"aria-label\":\"loading\",\"children\":[\"$\",\"span\",null,{\"className\":\"sr-only\",\"children\":\"Loading...\"}]}]}],\"children\":[\"$\",\"$L24\",null,{\"items\":[{\"header\":{\"tldr\":\"Built a Go runtime tracer called xgotop to trace and visualize goroutine lifecycles and memory allocations in realtime, and won eBPF Summit '25 Hackathon with it!\",\"date\":\"2026-03-31\",\"class\":\"tutorial\",\"tags\":[\"ebpf\",\"bpftrace\",\"go\",\"linux\"],\"keywords\":\"\",\"series\":\"Practical eBPF\",\"series_index\":2,\"keypoints\":null,\"last_update\":\"2026-03-31\"},\"markdown\":\"$25\",\"html\":\"$26\",\"slug\":\"tracing-goroutines-in-realtime-with-ebpf-2026-03-31\",\"title\":\"Tracing Goroutines in Realtime with eBPF\",\"reading_time_seconds\":780,\"metadata\":{\"readingtime-which-functions-actually-change-goroutine-states\":60}},{\"header\":{\"tldr\":\"This visual guide explores how maps work in Go runtime, covering hash tables, bucket structure, collision handling, and map growth with Go source code.\",\"date\":\"2025-10-26\",\"class\":\"tutorial\",\"tags\":[\"go\",\"maps\",\"data structures\"],\"keywords\":\"go maps, hash table, buckets, collision handling, map internals, go programming, data structures, hash function, key-value pairs\",\"series\":\"Go Internals\",\"series_index\":2,\"keypoints\":[{\"point\":\"Maps are hash tables where keys are hashed to determine bucket placement, with the lower bits selecting the bucket and top 8 bits stored for quick lookups\",\"ref\":\"#hash-function-and-key-distribution\"},{\"point\":\"Each bucket holds up to 8 key-value pairs with keys and values stored separately for better memory alignment and cache performance\",\"ref\":\"#bucket-structure\"},{\"point\":\"Maps grow when load factor exceeds 6.5 or when too many overflow buckets exist, using incremental evacuation to avoid blocking\",\"ref\":\"#map-growth\"},{\"point\":\"Maps are not thread-safe by design, concurrent reads and writes require explicit synchronization with mutexes or sync.Map\",\"ref\":\"#map-safety-and-concurrency\"}],\"last_update\":\"2025-10-26\"},\"markdown\":\"$27\",\"html\":\"$28\",\"slug\":\"visual-guide-to-go-maps-hash-tables-2025-10-26\",\"title\":\"Visual Guide to Go Maps: Hash Tables\",\"reading_time_seconds\":1680,\"metadata\":{\"readingtime-what-is-a-hash-table\":180}},{\"header\":{\"tldr\":\"eBPF is a revolutionary technology that allows you to reprogram the Linux kernel within minutes, even without rebooting the system. It allows you to trace system calls, user space functions, library functions, network packets, and much more.\",\"date\":\"2024-06-06\",\"class\":\"tutorial\",\"tags\":[\"go\",\"ebpf\"],\"keywords\":\"\",\"series\":\"Practical eBPF\",\"series_index\":1,\"keypoints\":[{\"point\":\"You can reprogram Linux to perform custom tasks inside the kernel using eBPF\",\"ref\":\"#enter-ebpf\"},{\"point\":\"eBPF is used for packet inspection, low level network security, performance monitoring, and more\",\"ref\":\"#but-how\"},{\"point\":\"eBPF is event-driven, you attach eBPF programs to specific code paths in the kernel using hooks\",\"ref\":\"#ebpf-hooks-and-maps\"}],\"last_update\":\"2024-06-06\"},\"markdown\":\"$29\",\"html\":\"$2a\",\"slug\":\"an-applied-introduction-to-ebpf-with-go-2024-06-06\",\"title\":\"An Applied Introduction to eBPF with Go\",\"reading_time_seconds\":1380,\"metadata\":{}},{\"header\":{\"tldr\":\"This visual guide shows how slices work under the hood in Go, covers slice creation, manipulation using make and append, how capacity grows, and slicing syntax for creating new slices from existing ones.\",\"date\":\"2024-03-25\",\"class\":\"tutorial\",\"tags\":[\"go\"],\"keywords\":\"\",\"series\":\"Go Internals\",\"series_index\":1,\"keypoints\":null,\"last_update\":\"2024-03-25\"},\"markdown\":\"$2b\",\"html\":\"$2c\",\"slug\":\"visual-guide-to-slices-in-go-2024-03-25\",\"t
3itle\":\"Visual Guide to Slices in Go\",\"reading_time_seconds\":1080,\"metadata\":{}},{\"header\":{\"tldr\":\"I built my own Go package index with a static site using Go, Next.js and Shadcn UI. Here's how I did it.\",\"date\":\"2024-03-10\",\"class\":\"i did this\",\"tags\":[\"go\",\"nextjs\",\"shadcn\",\"tooling\"],\"keywords\":\"Go programming, custom package index, dependency management, open-source development, Go project setup, vanity URLs, Go packages, import paths, developer tools, software best practices, module management, static site generation, package discovery, version control, resource management, programming language efficiency, code simplification, developer productivity, package versioning, source code management\",\"keypoints\":null,\"last_update\":\"2024-03-10\"},\"markdown\":\"$2d\",\"html\":\"$2e\",\"slug\":\"how-i-built-my-own-go-package-index---gosazakio-2024-03-10\",\"title\":\"How I built my own Go package index - go.sazak.io\",\"reading_time_seconds\":300,\"metadata\":{}},{\"header\":{\"tldr\":\"Here are the advices you need to check if you're searching for a cool side project idea.\",\"date\":\"2023-09-03\",\"class\":\"advice\",\"tags\":[\"programming\"],\"keywords\":\"programming, software engineering, side project, side projects, idea, ideas, advice, programming advice, softwaree ngineering advice, software engineering advices, programming advice
3s, side project advice, side project ideas, side project idea, side projects ideas\",\"keypoints\":null,\"last_update\":\"2023-09-03\"},\"markdown\":\"$2f\",\"html\":\"$30\",\"slug\":\"fantastic-side-projects-and-where-to-find-them-2023-09-03\",\"title\":\"Fantastic Side Projects and Where to Find Them\",\"reading_time_seconds\":420,\"metadata\":{}},{\"header\":{\"tldr\":\"Fan-in and fan-out patterns explained with fancy animations.\",\"date\":\"2022-10-30\",\"class\":\"tutorial\",\"tags\":[\"go\",\"concurrency\"],\"keywords\":\"fan-in, fan-out, go, concurrency, parallelism, patterns, animation, visualisation, illustration, explanation, tutorial, guide, example, code, source code\",\"keypoints\":null,\"last_update\":\"2022-10-30\"},\"markdown\":\"$31\",\"html\":\"$32\",\"slug\":\"cloud-native-patterns-illustrated-fan-in-and-fan-out-2022-10-30\",\"title\":\"Cloud Native Patterns Illustrated: Fan-in and Fan-out\",\"reading_time_seconds\":300,\"metadata\":{}},{\"header\":{\"tldr\":\"I coded a graphical ls command with folder sizes in Go.\",\"date\":\"2022-07-19\",\"class\":\"i did this\",\"tags\":[\"go\",\"cli\"],\"keywords\":\"gls, go, cli, tooling, folder size, file size, linux, terminal, command line, windows, macos, unix\",\"keypoints\":null,\"last_update\":\"2022-07-19\"},\"markdown\":\"$33\",\"html\":\"$34\",\"slug\":\"gls-file-manager-on-terminal-with-go-2022-07-19\",\"title\":\"gls: File Manager on Terminal with Go\",\"reading_time_seconds\":480,\"metadata\":{}}],\"header\":\"Articles\"}]}]]}]\n"])</script>
3<script>self.__next_f.push([1,"8:[[\"$\",\"meta\",\"0\",{\"charSet\":\"utf-8\"}],[\"$\",\"meta\",\"1\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1, maximum-scale=1\"}],[\"$\",\"meta\",\"2\",{\"name\":\"theme-color\",\"content\":\"white\"}],[\"$\",\"meta\",\"3\",{\"name\":\"color-scheme\",\"content\":\"only light\"}]]\n"])</script>
3<script>self.__next_f.push([1,"35:I[97608,[\"/_next/static/chunks/0~6uqz2cc7cgk.js\",\"/_next/static/chunks/060eq880magqv.js\"],\"IconMark\"]\n6:null\n"])</script>
3<script>self.__next_f.push([1,"a:[[\"$\",\"title\",\"0\",{\"children\":\"Ozan Sazak\"}],[\"$\",\"meta\",\"1\",{\"name\":\"description\",\"content\":\"I'm a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog.\"}],[\"$\",\"link\",\"2\",{\"rel\":\"manifest\",\"href\":\"/manifest.webmanifest\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"meta\",\"3\",{\"name\":\"robots\",\"content\":\"index, follow\"}],[\"$\",\"meta\",\"4\",{\"name\":\"pinterest\",\"content\":\"nopin\"}],[\"$\",\"link\",\"5\",{\"rel\":\"canonical\",\"href\":\"https://sazak.io\"}],[\"$\",\"meta\",\"6\",{\"property\":\"og:title\",\"content\":\"Ozan Sazak\"}],[\"$\",\"meta\",\"7\",{\"property\":\"og:description\",\"content\":\"I'm a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog.\"}],[\"$\",\"meta\",\"8\",{\"property\":\"og:url\",\"content\":\"https://sazak.io\"}],[\"$\",\"meta\",\"9\",{\"property\":\"og:site_name\",\"content\":\"Ozan Sazak\"}],[\"$\",\"meta\",\"10\",{\"property\":\"og:locale\",\"content\":\"en_IE\"}],[\"$\",\"meta\",\"11\",{\"property\":\"og:image\",\"content\":\"https://sazak.io/opengraph-image?3c9e8dae5c8d2000\"}],[\"$\",\"meta\",\"12\",{\"property\":\"og:image:type\",\"content\":\"image/png\"}],[\"$\",\"meta\",\"13\",{\"property\":\"og:image:width\",\"content\":\"1200\"}],[\"$\",\"meta\",\"14\",{\"property\":\"og:image:height\",\"content\":\"630\"}],[\"$\",\"meta\",\"15\",{\"property\":\"og:image:alt\",\"content\":\"I'm a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog.\"}],[\"$\",\"meta\",\"16\",{\"property\":\"og:type\",\"content\":\"website\"}],[\"$\",\"meta\",\"17\",{\"name\":\"twitter:card\",\"content\":\"summary_large_image\"}],[\"$\",\"meta\",\"18\",{\"name\":\"twitter:site\",\"content\":\"@oznszk\"}],[\"$\",\"meta\",\"19\",{\"name\":\"twitter:creator\",\"content\":\"@oznszk\"}],[\"$\",\"meta\",\"20\",{\"name\":\"twitter:title\",\"content\":\"Ozan Sazak\"}],[\"$\",\"meta\",\"21\",{\"name\":\"twitter:description\",\"content\":\"I'm a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog.\"}],[\"$\",\"meta\",\"22\",{\"name\":\"twitter:image\",\"content\":\"https://sazak.io/opengraph-image?3c9e8dae5c8d2000\"}],[\"$\",\"meta\",\"23\",{\"name\":\"twitter:image:alt\",\"content\":\"I'm a software engineer at Datadog, living in Madrid. I build stuff and write about them in this blog.\"}],[\"$\",\"meta\",\"24\",{\"name\":\"twitter:image:type\",\"content\":\"image/png\"}],[\"$\",\"meta\",\"25\",{\"name\":\"twitter:image:width\",\"content\":\"1200\"}],[\"$\",\"meta\",\"26\",{\"name\":\"twitter:image:height\",\"content\":\"630\"}],[\"$\",\"link\",\"27\",{\"rel\":\"icon\",\"href\":\"/favicon.ico?favicon.0598-h8n1_7xt.ico\",\"sizes\":\"64x64\",\"type\":\"image/x-icon\"}],[\"$\",\"$L35\",\"28\",{}]]\n"])</script>
3</body></html>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.