<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on Moulard's Blog</title><link>https://blog.moulard.org/posts/</link><description>Recent content in Posts on Moulard's Blog</description><generator>Hugo -- gohugo.io -- Tom Moulard</generator><image>https://blog.moulard.org/posts//images/avatar.png</image><language>fr</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><lastBuildDate>Thu, 12 Mar 2026 00:00:00 +0200</lastBuildDate><atom:link href="https://blog.moulard.org/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>Teaching an AI to Teach an AI: The CodeRabbit Review Agent Meta-Saga</title><link>https://blog.moulard.org/coderabbit-review-agent-in-opencode/</link><pubDate>Thu, 12 Mar 2026 00:00:00 +0200</pubDate><guid>https://blog.moulard.org/coderabbit-review-agent-in-opencode/</guid><comments>https://blog.moulard.org/coderabbit-review-agent-in-opencode/#disqus_thread</comments><description>&lt;p>I built an AI agent whose entire job is to babysit another AI that reviews my code.&lt;/p>
&lt;p>Yeah, I know how that sounds. Like we&amp;rsquo;re two levels deep into AI inception and I&amp;rsquo;ve lost the plot. But hear me out—this actually solved a real problem I was having, and the solution is honestly kind of hilarious.&lt;/p>
&lt;h2 id="the-problem-coderabbit-is-slow-as-hell">The Problem: CodeRabbit is Slow as Hell&lt;/h2>
&lt;p>So I&amp;rsquo;m using &lt;a href="https://github.com/anomalyco/opencode">OpenCode&lt;/a> (LLM-powered coding assistant, it&amp;rsquo;s great) and I wanted automated code reviews. I already had &lt;a href="https://coderabbit.ai">CodeRabbit&lt;/a> set up because who doesn&amp;rsquo;t want an AI nitpicking your code at 3am?&lt;/p>
&lt;p>The problem: CodeRabbit takes 20-30 minutes per review. Then it spits out this massive markdown file—critical bugs mixed with &amp;ldquo;you should use const instead of let&amp;rdquo; style suggestions, zero prioritization, just raw dump of everything wrong with your life choices.&lt;/p>
&lt;p>I got tired of manually parsing these reports around the third time I did it in January. So I spent a weekend building &lt;strong>@cr&lt;/strong>—a subagent that sits in OpenCode and does the whole dance: run review, wait forever, parse output, apply fixes, run again until clean.&lt;/p>
&lt;p>It&amp;rsquo;s an AI managing another AI. Meta? Yes. Stupid? Maybe. Does it work? Surprisingly well.&lt;/p>
&lt;h2 id="what-cr-actually-does">What @cr Actually Does&lt;/h2>
&lt;p>The agent basically acts as a project manager who never gets tired:&lt;/p>
&lt;ul>
&lt;li>Runs CodeRabbit on uncommitted changes (or specific files, or branches—whatever you want)&lt;/li>
&lt;li>Saves output to timestamped files because Claude&amp;rsquo;s context window isn&amp;rsquo;t infinite&lt;/li>
&lt;li>Parses and sorts findings: Critical → Important → &amp;ldquo;please consider using const&amp;rdquo;&lt;/li>
&lt;li>Applies fixes automatically using OpenCode&amp;rsquo;s Edit tool&lt;/li>
&lt;li>Re-runs the review up to 3 times or until everything&amp;rsquo;s clean&lt;/li>
&lt;li>Tells you honestly what worked and what&amp;rsquo;s still broken&lt;/li>
&lt;/ul>
&lt;p>Honestly? It&amp;rsquo;s like having a code reviewer who doesn&amp;rsquo;t get annoyed when you ask them to review the same diff three times. Which, if you&amp;rsquo;ve ever been that reviewer, you know is valuable.&lt;/p>
&lt;h2 id="how-it-actually-works-the-interesting-parts">How It Actually Works (The Interesting Parts)&lt;/h2>
&lt;h3 id="figuring-out-what-to-review">Figuring Out What to Review&lt;/h3>
&lt;p>First it checks &lt;code>git status&lt;/code> to see if you have uncommitted changes. If yes, review those. If not, compare current branch against main.&lt;/p>
&lt;p>You can be specific too:&lt;/p>
&lt;ul>
&lt;li>&lt;code>@cr&lt;/code> - reviews whatever&amp;rsquo;s uncommitted&lt;/li>
&lt;li>&lt;code>@cr agent/cr.md&lt;/code> - just that file&lt;/li>
&lt;li>&lt;code>@cr review against develop&lt;/code> - compare against different branch&lt;/li>
&lt;/ul>
&lt;p>Pretty straightforward.&lt;/p>
&lt;h3 id="running-coderabbit-aka-waiting-forever">Running CodeRabbit (aka Waiting Forever)&lt;/h3>
&lt;p>This is the boring part:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">coderabbit review --plain -t uncommitted 2&amp;gt;&amp;amp;&lt;span style="color:#ae81ff">1&lt;/span> | &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> tee /tmp/coderabbit-&lt;span style="color:#66d9ef">$(&lt;/span>date +%Y%m%d-%H%M%S&lt;span style="color:#66d9ef">)&lt;/span>.md
&lt;/code>&lt;/pre>&lt;/div>&lt;p>The &lt;code>--plain&lt;/code> flag stops CodeRabbit from using fancy formatting that breaks parsing. The &lt;code>tee&lt;/code> saves output to a timestamped file like &lt;code>/tmp/coderabbit-20260312-095530.md&lt;/code> while still showing you what&amp;rsquo;s happening.&lt;/p>
&lt;p>Then the agent polls every 2 minutes to check if CodeRabbit finished. I tried every 30 seconds initially but that felt like overkill. Even 2 minutes feels aggressive when you&amp;rsquo;re staring at your terminal.&lt;/p>
&lt;h3 id="parsing-the-output">Parsing the Output&lt;/h3>
&lt;p>CodeRabbit spits out something like:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-markdown" data-lang="markdown">**Critical**: Potential SQL injection in user input handler (line 42)
&lt;span style="font-weight:bold">**Important**&lt;/span>: Missing error handling for database connection
&lt;span style="font-weight:bold">**Suggestion**&lt;/span>: Consider using const instead of let here
&lt;/code>&lt;/pre>&lt;/div>&lt;p>The agent reads the entire file (yes, even the parts that don&amp;rsquo;t fit in context) and sorts by severity:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Critical/Security&lt;/strong> - will definitely break things or get you hacked&lt;/li>
&lt;li>&lt;strong>Important&lt;/strong> - actual bugs, performance problems&lt;/li>
&lt;li>&lt;strong>Nits&lt;/strong> - style preferences, minor stuff&lt;/li>
&lt;/ul>
&lt;h3 id="applying-fixes">Applying Fixes&lt;/h3>
&lt;p>This is where it gets interesting. For each issue:&lt;/p>
&lt;ol>
&lt;li>Read the file to understand what&amp;rsquo;s going on&lt;/li>
&lt;li>Apply fix using OpenCode&amp;rsquo;s Edit tool&lt;/li>
&lt;li>Try not to break everything else in the process&lt;/li>
&lt;li>Match existing code style (I don&amp;rsquo;t want the agent reformatting my entire codebase)&lt;/li>
&lt;/ol>
&lt;p>By default it fixes &lt;strong>everything&lt;/strong>, not just critical issues. If I&amp;rsquo;m running a code review, I want it done properly. Half-assing automation is worse than not automating at all.&lt;/p>
&lt;h3 id="the-iteration-loop">The Iteration Loop&lt;/h3>
&lt;p>After fixes are applied, run CodeRabbit again. Same command, different timestamp:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">coderabbit review --plain -t uncommitted 2&amp;gt;&amp;amp;&lt;span style="color:#ae81ff">1&lt;/span> | &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> tee /tmp/coderabbit-20260312-095530-iter2.md
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Compare new findings with previous:&lt;/p>
&lt;ul>
&lt;li>Issues got fixed? Good.&lt;/li>
&lt;li>New issues appeared? Fix those.&lt;/li>
&lt;li>Same issues still there? Try once more.&lt;/li>
&lt;li>Still broken after 3 tries? Give up and tell the human.&lt;/li>
&lt;/ul>
&lt;p>The 3-iteration limit is important. I learned this the hard way after watching it loop 7 times trying to fix the same issue in February. After 3 attempts, it&amp;rsquo;s probably a problem that needs actual human judgment.&lt;/p>
&lt;h3 id="what-you-get-at-the-end">What You Get at the End&lt;/h3>
&lt;pre>&lt;code>CodeRabbit Review Complete
Iterations: 2 of 3
Issues Found (Iteration 1):
- 3 Critical
- 7 Important
- 12 Suggestions
Issues Fixed:
- Fixed SQL injection vulnerability in auth handler
- Added error handling for all database operations
- Refactored 15 style inconsistencies
Final Status:
- 0 Critical remaining
- 0 Important remaining
- 2 Suggestions remaining (minor formatting preferences)
&lt;/code>&lt;/pre>&lt;p>Clear, honest, done.&lt;/p>
&lt;h2 id="the-annoying-problems-i-had-to-solve">The Annoying Problems I Had to Solve&lt;/h2>
&lt;p>Building this thing was more interesting than I expected. A few things that came up:&lt;/p>
&lt;h3 id="context-windows-are-not-infinite">Context Windows Are Not Infinite&lt;/h3>
&lt;p>CodeRabbit outputs can be huge. Like, way bigger than Claude&amp;rsquo;s context window. I found this out when reviewing a large refactor in early February and the agent just&amp;hellip; forgot what it was doing halfway through.&lt;/p>
&lt;p>Solution: save everything to timestamped files:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">/tmp/coderabbit-20260312-095530.md &lt;span style="color:#75715e"># Iteration 1&lt;/span>
/tmp/coderabbit-20260312-095730-iter2.md &lt;span style="color:#75715e"># Iteration 2&lt;/span>
/tmp/coderabbit-20260312-095930-iter3.md &lt;span style="color:#75715e"># Iteration 3&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>The agent reads from these files as needed instead of trying to keep everything in memory. Simple fix, should&amp;rsquo;ve done it from the start.&lt;/p>
&lt;h3 id="dont-create-infinite-loops">Don&amp;rsquo;t Create Infinite Loops&lt;/h3>
&lt;p>Without limits, the agent could review-fix-review-fix forever. So:&lt;/p>
&lt;ul>
&lt;li>Max 3 iterations (after that, it&amp;rsquo;s a human problem)&lt;/li>
&lt;li>Detect if the same issue keeps appearing (probably can&amp;rsquo;t fix it automatically)&lt;/li>
&lt;li>30-minute timeout per CodeRabbit run (it&amp;rsquo;s never actually needed this long, but just in case)&lt;/li>
&lt;/ul>
&lt;h3 id="reviewing-specific-files-without-breaking-git">Reviewing Specific Files Without Breaking Git&lt;/h3>
&lt;p>Sometimes you want to review just one file: &lt;code>@cr agent/cr.md&lt;/code>&lt;/p>
&lt;p>CodeRabbit doesn&amp;rsquo;t have a &amp;ldquo;review only this file&amp;rdquo; option. First idea: use &lt;code>git stash&lt;/code> to hide other changes.&lt;/p>
&lt;p>&lt;strong>Terrible idea.&lt;/strong> That&amp;rsquo;s how you lose work and ruin someone&amp;rsquo;s day.&lt;/p>
&lt;p>Better solution:&lt;/p>
&lt;ol>
&lt;li>Run CodeRabbit on everything (read-only, safe)&lt;/li>
&lt;li>Parse output and filter for the file you care about&lt;/li>
&lt;li>Only apply fixes to that file&lt;/li>
&lt;li>Report: &amp;ldquo;Reviewed agent/cr.md. Other files untouched.&amp;rdquo;&lt;/li>
&lt;/ol>
&lt;p>No git manipulation. No lost changes. Much better.&lt;/p>
&lt;h2 id="things-i-learned-building-this">Things I Learned Building This&lt;/h2>
&lt;p>&lt;strong>Agents should do one thing well.&lt;/strong> The @cr agent orchestrates CodeRabbit reviews. That&amp;rsquo;s it. It doesn&amp;rsquo;t write code, doesn&amp;rsquo;t design systems, doesn&amp;rsquo;t make architectural decisions. This narrow focus is why it actually works reliably.&lt;/p>
&lt;p>&lt;strong>External storage is your friend.&lt;/strong> AI memory is just files. Save everything because you will need it later when the context window fills up.&lt;/p>
&lt;p>&lt;strong>Iteration limits matter.&lt;/strong> The 3-try maximum prevents infinite loops but gives enough room to actually fix things. After 3 attempts, involve a human.&lt;/p>
&lt;p>&lt;strong>Never manipulate git state.&lt;/strong> The agent uses &lt;code>git status&lt;/code>, &lt;code>git diff&lt;/code>, &lt;code>git log&lt;/code>—all read-only. It never touches &lt;code>git stash&lt;/code>, &lt;code>git reset&lt;/code>, or &lt;code>git checkout&lt;/code>. I value my sanity.&lt;/p>
&lt;p>&lt;strong>Be honest when things fail.&lt;/strong> When @cr hits the iteration limit:&lt;/p>
&lt;pre>&lt;code>Reached maximum iteration limit. Some issues may require manual review.
Remaining issues:
- Complex refactoring needed in auth system (line 142)
- Architectural decision required for API versioning
&lt;/code>&lt;/pre>&lt;p>No pretending it worked perfectly. Just the truth.&lt;/p>
&lt;h2 id="does-it-actually-save-time">Does It Actually Save Time?&lt;/h2>
&lt;p>My workflow before:&lt;/p>
&lt;ol>
&lt;li>Write code&lt;/li>
&lt;li>Run CodeRabbit manually&lt;/li>
&lt;li>Wait 20-30 minutes&lt;/li>
&lt;li>Read through findings&lt;/li>
&lt;li>Fix things one by one&lt;/li>
&lt;li>Run again to verify&lt;/li>
&lt;li>Total: 2-3 hours for a thorough review cycle&lt;/li>
&lt;/ol>
&lt;p>Now:&lt;/p>
&lt;ol>
&lt;li>Write code&lt;/li>
&lt;li>Type &lt;code>@cr&lt;/code>&lt;/li>
&lt;li>Make coffee, check email, contemplate life choices&lt;/li>
&lt;li>Come back to mostly-fixed code&lt;/li>
&lt;li>Total: 30-45 minutes (mostly CodeRabbit being slow)&lt;/li>
&lt;/ol>
&lt;p>It&amp;rsquo;s not perfect. Complex architectural issues still need me. But for 90% of code review stuff—null checks, error handling, style consistency—it just handles it.&lt;/p>
&lt;h2 id="whats-next">What&amp;rsquo;s Next&lt;/h2>
&lt;p>I could build @cr-watcher to monitor @cr&amp;rsquo;s performance. Or @meta-review to review the reviews. At some point we need to stop before creating an AI singularity though.&lt;/p>
&lt;p>The real takeaway is that specialized subagents work well. Each does one thing. You chain them together and suddenly your workflow feels like having a small team.&lt;/p>
&lt;h2 id="try-it-if-you-want">Try It if You Want&lt;/h2>
&lt;p>The agent is &lt;a href="https://github.com/tomMoulard/configLoader/blob/main/opencode/agent/cr.md">open source&lt;/a>. If you want to use it:&lt;/p>
&lt;ol>
&lt;li>Install &lt;a href="https://docs.coderabbit.ai">CodeRabbit CLI&lt;/a>&lt;/li>
&lt;li>Install &lt;a href="https://github.com/anomalyco/opencode">OpenCode&lt;/a>&lt;/li>
&lt;li>Copy cr.md to your &lt;code>~/.config/opencode/agent/&lt;/code> directory&lt;/li>
&lt;li>Run &lt;code>@cr&lt;/code>&lt;/li>
&lt;/ol>
&lt;p>Warning: watching an AI manage another AI is weirdly entertaining. I run it more often than I probably should.&lt;/p>
&lt;h2 id="final-thoughts">Final Thoughts&lt;/h2>
&lt;p>We&amp;rsquo;re at a point where:&lt;/p>
&lt;ul>
&lt;li>AIs write code&lt;/li>
&lt;li>Other AIs review it&lt;/li>
&lt;li>Other AIs manage those reviews&lt;/li>
&lt;li>Humans drink coffee and occasionally make decisions&lt;/li>
&lt;/ul>
&lt;p>Is this what I imagined when I started programming? Not even close. Is it useful? Yeah, actually.&lt;/p>
&lt;p>The @cr agent is just one example of specialized subagents. Each handles one specific job. Chain enough of them together and you have something that starts to feel like a development team that never sleeps and doesn&amp;rsquo;t complain about meetings.&lt;/p>
&lt;p>Which leaves humans free to work on the actually interesting problems. Like figuring out if we really need another JavaScript framework this week.&lt;/p>
&lt;p>(We don&amp;rsquo;t. But someone will build it anyway. And @cr will review it.)&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Note:&lt;/strong> Yes, I used AI to help draft parts of this post. Given the topic, hiding that would be ridiculous. I edited it heavily though because AI-generated blog posts have a very specific smell to them, and I didn&amp;rsquo;t want this to read like a ChatGPT essay.&lt;/p>
&lt;p>Shout out to the &lt;a href="https://github.com/anomalyco/opencode">OpenCode&lt;/a> and &lt;a href="https://coderabbit.ai">CodeRabbit&lt;/a> teams for building tools that are actually useful instead of just hype. This agent only exists because both tools work well enough to be worth automating.&lt;/p></description></item><item><title>Un schéma AWS qui tient une API Go LLM éveillée</title><link>https://blog.moulard.org/posts/2025-12-19-ha-go-llm-api-aws/</link><pubDate>Fri, 19 Dec 2025 17:00:00 +0100</pubDate><guid>https://blog.moulard.org/posts/2025-12-19-ha-go-llm-api-aws/</guid><comments>https://blog.moulard.org/posts/2025-12-19-ha-go-llm-api-aws/#disqus_thread</comments><description>&lt;p>Une API Go qui reste éveillée même quand une région AWS s’effondre.&lt;/p>
&lt;p>De plus en plus d&amp;rsquo;équipes SaaS cherchent à sortir de l&amp;rsquo;architecture «
mono-région us-east-1 + OpenAI par défaut » pour garder le service en ligne
même quand une région AWS tombe en plein lancement produit.&lt;/p>
&lt;p>Je parle donc d&amp;rsquo;Amazon Web Services (AWS), de Large Language Models (LLM) et de
haute disponibilité (HA) appliquée à une API Go. En clair : je décris ici une
architecture multi-région AWS pensée pour garder une API Go branchée sur
plusieurs LLM, sans dépendre d&amp;rsquo;un fournisseur et en assumant des pannes totales
de région. L&amp;rsquo;objectif est double : haute disponibilité en lecture/écriture
(avec un Recovery Time Objective, RTO, de quelques minutes pour les écritures,
cf. A1) et possibilité de basculer vers un concurrent (ou un modèle moins cher)
sans redéployer le backend.&lt;/p>
&lt;p>Avant d&amp;rsquo;empiler des services, j&amp;rsquo;aime poser noir sur blanc ce qui doit survivre
à une panne de région. Le schéma qui suit est donc une exploration théorique
prête à être déployée telle quelle sur un projet d&amp;rsquo;API Go + LLM multi-région.&lt;/p>
&lt;h3 id="hypothèses-affichées-dès-le-départ">Hypothèses affichées dès le départ&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>A1 — HA = RTO de quelques minutes pour l&amp;rsquo;écriture :&lt;/strong> Aurora Global
Database n&amp;rsquo;a qu&amp;rsquo;un seul writer. AWS annonce un Recovery Point Objective (RPO)
généralement &amp;lt;1 seconde et un RTO &amp;lt;1 minute pour la promotion d&amp;rsquo;une région
(&lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-failover.html">Aurora Global Database failover&lt;/a>,
consulté le 8 décembre 2025). Je parle donc d&amp;rsquo;une HA “lecture/écriture” qui
tolère cette pause et je prévois les tampons nécessaires pour absorber un
scénario pessimiste où la promotion dépasserait la minute.&lt;/li>
&lt;li>&lt;strong>A2 — Couverture Bedrock :&lt;/strong> au 8 décembre 2025, AWS liste Amazon Bedrock
dans plusieurs régions (us-east-1/2, us-west-2, eu-central-1, eu-west-1,
ap-south-1, ap-northeast-1, ap-southeast-1/2, etc.) (&lt;a href="https://docs.aws.amazon.com/general/latest/gr/bedrock.html">Amazon Bedrock endpoints and quotas&lt;/a>,
consulté le 8 décembre 2025). Je pars donc du principe qu&amp;rsquo;un deuxième quota est
provisionné dans l&amp;rsquo;une de ces régions (ou chez un fournisseur tiers) pour que
la région de secours serve les prompts.&lt;/li>
&lt;li>&lt;strong>A3 — Idempotence côté client :&lt;/strong> tous les POST exposés par l&amp;rsquo;API peuvent
être rejoués grâce à un &lt;code>request_id&lt;/code>, sinon CloudFront ne pourrait rien faire
pour nous.&lt;/li>
&lt;li>&lt;strong>A4 — Budget HA assumé :&lt;/strong> trois NAT Gateway par région, des quotas Bedrock
provisionnés et un Redis par région sont financés par le métier.&lt;/li>
&lt;li>&lt;strong>A5 — Runbooks mono-cloud :&lt;/strong> les équipes produit/opérations restent sur AWS
mais savent suivre un plan de bascule multi-région.&lt;/li>
&lt;/ul>
&lt;p>Le schéma ci-dessous illustre le flux complet : des utilisateurs au bord du
réseau jusqu&amp;rsquo;aux bases de données globales, avec les points de bascule.&lt;/p>
&lt;script src="https://unpkg.com/mermaid@11.12.0/dist/mermaid.min.js" type="text/javascript">&lt;/script>
&lt;script type="text/javascript">
mermaid.initialize({ startOnLoad:true });
&lt;/script>
&lt;pre class="mermaid" align="center">
flowchart TB
%% ==== Edge ====
subgraph Edge[Edge Global]
R53[Route 53 ALIAS] --> CF[CloudFront&lt;br>WAF&lt;br>Origin Failover]
end
%% ==== ALB ====
CF --> ALB1[ALB us-east-1&lt;br>origin primaire]
CF -. failover .-> ALB2[ALB eu-west-1&lt;br>origin secondaire]
%% ==== us-east-1 ====
subgraph E1[us-east-1 region active]
ALB1 --> ECS1[ECS Fargate]
subgraph E1Net[Sortie et Configuration]
ECS1 --> NAT1a[NAT a]
ECS1 --> NAT1b[NAT b]
ECS1 --> NAT1c[NAT c]
ECS1 --> AppCfg1[AppConfig&lt;br>Secrets]
end
subgraph E1Ops[Ops locaux]
ECS1 --> Redis1[Redis quota&lt;br>Lua]
ECS1 --> SQS1[SQS&lt;br>DLQ]
end
subgraph E1LLM[Acces LLM]
ECS1 --> VPCE1[VPC Endpoint Bedrock]
VPCE1 --> BR1[Bedrock&lt;br>provisionne]
end
end
%% ==== eu-west-1 ====
subgraph W1[eu-west-1 region DR]
ALB2 --> ECS2[ECS Fargate]
subgraph W1Net[Sortie et Configuration]
ECS2 --> NAT2a[NAT a]
ECS2 --> NAT2b[NAT b]
ECS2 --> NAT2c[NAT c]
ECS2 --> AppCfg2[AppConfig&lt;br>Secrets]
end
subgraph W1Ops[Ops locaux]
ECS2 --> Redis2[Redis quota&lt;br>Lua]
ECS2 --> SQS2[SQS&lt;br>DLQ]
end
subgraph W1LLM[Acces LLM]
ECS2 --> VPCE2[VPC Endpoint Bedrock]
VPCE2 --> BR2[Bedrock&lt;br>provisionne]
end
end
%% ==== Cross-region ====
SQS1 &lt;-. Lambda sync .-> SQS2
AppCfg1 &lt;-. CI CD .-> AppCfg2
%% ==== Donnees globales ====
ECS1 --> DDB[DynamoDB&lt;br>Global Tables]
ECS2 --> DDB
ECS1 --> RDS[Aurora Global&lt;br>writer]
ECS2 --> RDSReader[Aurora Global&lt;br>reader]
%% ==== Observabilite ====
ECS1 -. traces logs .-> CW[CloudWatch&lt;br>X-Ray]
ECS2 -.-> CW
CW --> Graf[Managed Grafana]
CW --> Alerting[EventBridge&lt;br>Chatbot&lt;br>SNS]
Redis1 --> Telemetry[Quota&lt;br>metrics]
Redis2 --> Telemetry
&lt;/pre>
&lt;blockquote>
&lt;p>Lecture du diagramme : Route 53 renvoie tout vers CloudFront, qui combine un
Web Application Firewall (WAF) et l&amp;rsquo;Origin Failover pour choisir entre deux
Application Load Balancer (ALB). Chaque colonne régionale embarque ses
propres tâches ECS Fargate, NAT Gateway (NAT GW a/b/c), Redis “quota local +
Lua”, Simple Queue Service (SQS) + Dead Letter Queue (DLQ) et AWS AppConfig
(AppCfg) avant de rejoindre Bedrock via des VPC Endpoints (VPCE), DynamoDB
Global Tables et Aurora Global Database côté données. La flèche “Pipeline
CI/CD” rappelle qu&amp;rsquo;une même chaîne d&amp;rsquo;intégration continue/déploiement continu
(CI/CD) alimente les deux AppConfig. Si Bedrock n&amp;rsquo;est pas disponible dans la
région de secours, ce bloc représente un fournisseur tiers ou un routage vers
une région Bedrock existante (cf. A2).&lt;/p>
&lt;/blockquote>
&lt;p>Comme montré ci-dessus, le trafic entre dans CloudFront (le Content Delivery
Network, CDN, d&amp;rsquo;AWS), passe l&amp;rsquo;Application Load Balancer (ALB) primaire en
us-east-1 et, pour les requêtes GET/HEAD/OPTIONS, tombe automatiquement sur
l&amp;rsquo;ALB secondaire en eu-west-1 si la santé de l&amp;rsquo;origine bascule.&lt;/p>
&lt;p>Tous les services annexes (Redis quotas, Simple Queue Service (SQS),
AppConfig, secrets) restent locaux à chaque région pour éviter les points
uniques de défaillance.&lt;/p>
&lt;p>En deux mots : Route 53 pointe vers CloudFront, qui choisit entre deux
Application Load Balancer (ALB), chacun s&amp;rsquo;appuyant sur ses propres queues,
quotas Redis, AppConfig et secrets régionaux.&lt;/p>
&lt;h2 id="pourquoi-cette-architecture-me-semble-pertinente">Pourquoi cette architecture me semble pertinente&lt;/h2>
&lt;p>Je cherche une approche qui soit crédible pour un blog de R&amp;amp;D : multi-région
par défaut, aucun composant unique, et la possibilité de brancher n&amp;rsquo;importe
quel fournisseur de LLM ou d&amp;rsquo;observabilité sans réécrire tout le socle. Les
sections suivantes détaillent les hypothèses que j&amp;rsquo;explorerais avant même de
commencer à coder.&lt;/p>
&lt;h2 id="anatomie-dun-chemin-llm-qui-ne-casse-pas">Anatomie d&amp;rsquo;un chemin LLM qui ne casse pas&lt;/h2>
&lt;h3 id="edge-géré-par-cloudfront">Edge géré par CloudFront&lt;/h3>
&lt;p>Une seule distribution applique AWS WAF avec &lt;a href="https://docs.aws.amazon.com/waf/latest/developerguide/aws-managed-rule-groups-bot.html">AWS Bot Control&lt;/a>
(consulté le 8 décembre 2025). Elle s&amp;rsquo;appuie sur &lt;strong>&lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html">Origin Failover&lt;/a>&lt;/strong>
(consulté le 8 décembre 2025) pour basculer de l&amp;rsquo;origin primaire (us-east-1)
vers l&amp;rsquo;origin eu-west-1 avant même qu&amp;rsquo;on touche au DNS Route 53. Route 53 reste
un &lt;strong>enregistrement ALIAS A/AAAA&lt;/strong> (ou un CNAME si l&amp;rsquo;on parle d&amp;rsquo;un
sous-domaine) pointé vers CloudFront : je préfère déplacer l&amp;rsquo;intelligence côté
CDN où la propagation est quasi instantanée.&lt;/p>
&lt;p>Important : CloudFront ne refait un Origin Failover automatique que pour les
requêtes GET/HEAD/OPTIONS (voir la doc ci-dessus). Tous les autres verbes
reçoivent simplement l&amp;rsquo;erreur du backend.
Comme mon API LLM encaisse surtout des POST, j&amp;rsquo;ai rendu tous les appels
idempotents (replay d&amp;rsquo;un même &lt;code>request_id&lt;/code> ignoré, cf. A3) et je documente noir
sur blanc que la bascule doit être effectuée par les clients ou par un SDK
maison qui retente côté secondaire après un 5xx.&lt;/p>
&lt;p>Lambda@Edge n&amp;rsquo;a pas la possibilité de “rejouer” un POST vers une autre origine
après échec ; il ne sert ici qu&amp;rsquo;à ajouter des en-têtes de traçage. Ce compromis
est préférable à un failover DNS lent, mais il faut accepter que la fenêtre
d&amp;rsquo;indisponibilité POST se joue côté client.&lt;/p>
&lt;p>Si l&amp;rsquo;on veut réellement un RTO sub-60s côté serveur pour tous les verbes HTTP,
il faudra placer un &lt;a href="https://docs.aws.amazon.com/global-accelerator/latest/dg/what-is-global-accelerator.html">AWS Global Accelerator&lt;/a>
(consulté le 8 décembre 2025) devant les deux ALB ou utiliser &lt;a href="https://aws.amazon.com/route53/application-recovery-controller/">Route 53 Application Recovery Controller (ARC)&lt;/a>
(consulté le 8 décembre 2025) pour piloter la bascule active/active. Je ne l&amp;rsquo;ai
pas encore fait sur ce prototype, mais le runbook note explicitement ce manque
pour éviter les promesses intenables. Tant que cette couche réseau n&amp;rsquo;existe
pas, je considère l&amp;rsquo;archi “HA partielle” et je m&amp;rsquo;appuie sur un SDK client (cf.
section produit) qui applique un backoff exponentiel et coupe les retries après
trois échecs pour ne pas saturer Redis/SQS.&lt;/p>
&lt;h3 id="application-load-balancer-public-mais-filtré">Application Load Balancer public mais filtré&lt;/h3>
&lt;p>Chaque origin est un Application Load Balancer (ALB) internet-facing dans trois
subnets publics, conformément à &lt;a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-subnets.html">Application Load Balancer Subnets&lt;/a>
(consulté le 8 décembre 2025). Les Security Groups s&amp;rsquo;appuient sur les &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/managed-prefix-lists.html">prefix lists managées&lt;/a>
(consulté le 8 décembre 2025) pour autoriser CloudFront et la plage IP Route 53
Health Check. Pas de trafic direct venant d&amp;rsquo;Internet, pas de surprises côté
monitoring.&lt;/p>
&lt;h3 id="egress-aligné-sur-les-az">Egress aligné sur les AZ&lt;/h3>
&lt;p>Chaque subnet privé a sa route table qui pointe vers “son” Network Address
Translation (NAT) Gateway, comme décrit dans &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html#nat-gateway-route-tables">NAT Gateway Route Tables&lt;/a>
(consulté le 8 décembre 2025). Tous les appels vers les services internes AWS
(Secrets Manager, Parameter Store, CloudWatch Logs, S3, KMS) utilisent des VPC
Endpoints privés (VPCE) pour rester sur le réseau Amazon et ne pas consommer le
throughput des NAT. Bedrock obtient son endpoint dédié afin d&amp;rsquo;éviter de saturer
les NAT ou de faire exploser la facture inter-AZ quand les tokens partent en
flèche. Quand une région AWS n&amp;rsquo;héberge pas encore Bedrock (ex. eu-west-3 à la
date de rédaction), je remplace ce VPCE par un fournisseur tiers (OpenAI/Azure)
ou par un routage vers une région où Bedrock est disponible en assumant la
latence supplémentaire.
Oui, trois NAT par région coûtent un rein (cf. A4), mais c&amp;rsquo;est le prix à payer
pour que chaque zone de dispo continue de sortir sur Internet si une voisine
tombe.&lt;/p>
&lt;h3 id="quotas-bedrock-pilotés-localement">Quotas Bedrock pilotés localement&lt;/h3>
&lt;p>L&amp;rsquo;API
&lt;a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_ListProvisionedModelThroughputs.html">&lt;code>ListProvisionedModelThroughputs&lt;/code>&lt;/a>
(consulté le 8 décembre 2025) me sert à lister les &lt;code>modelUnits&lt;/code> actifs. Chaque
région AWS négocie son propre throughput (il n&amp;rsquo;y a pas de “quota global”
partagé, cf. &lt;a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-throughput.html#prov-throughput-capacity">Bedrock provisioned throughput&lt;/a>,
consulté le 8 décembre 2025). Je convertis ces unités en tokens/s puis je
stocke ce budget dans un Redis local.&lt;/p>
&lt;p>Un service Elastic Container Service (ECS) “refill” par région calcule
&lt;code>deltaTokens = rate * elapsed&lt;/code> et applique un script Lua atomique sur Redis ;
chaque requête Bedrock décrémente ce bucket. Avant de rouvrir une région de
secours je rafraîchis systématiquement le quota local via
&lt;code>ListProvisionedModelThroughputs&lt;/code> pour éviter de “dépenser deux fois” le même
modelUnit : pas question que la région DR parte avec un bucket plein alors que
le quota global a déjà été tapé par la région active. Les métriques
&lt;code>InvocationThrottled&lt;/code> et &lt;code>ProvisionedModelThroughputUtilization&lt;/code> servent de
garde-fous externes et déclenchent un plan B (déport des requêtes vers
OpenAI/Anthropic ou passage en file SQS batch) avant que les 429 ne pleuvent.&lt;/p>
&lt;h3 id="elastic-container-service-ecs-fargate-discipliné">Elastic Container Service (ECS) Fargate discipliné&lt;/h3>
&lt;p>Les tâches embarquent OpenTelemetry (section dédiée ci-dessous) et injectent
leurs secrets via &lt;code>valueFrom&lt;/code>, comme recommandé dans &lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html">ECS Sensitive Data&lt;/a>
(consulté le 8 décembre 2025). &lt;code>HandleCompletion&lt;/code> est un metric CloudWatch
maison qui mesure le temps passé à post-traiter les réponses LLM (gestion des
webhooks, notifications, facturation). L&amp;rsquo;idée est de ne pas scaler tant que
&lt;code>HandleCompletion&lt;/code> est rouge ou que le bucket Redis est vide : ces garde-fous
évitent de surprovisionner quand la plateforme LLM est déjà au bord du
throttling.&lt;/p>
&lt;h3 id="files-sqs-régionales">Files SQS régionales&lt;/h3>
&lt;p>Deux queues (temps réel + DLQ, Dead Letter Queue) par région suivent les
&lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-best-practices.html">bonnes pratiques SQS&lt;/a>
(consulté le 8 décembre 2025). Les messages critiques déclenchent une règle
EventBridge qui publie sur un bus croisé (&lt;a href="https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-bus-cross-region.html">Cross-Region Event Buses&lt;/a>,
consulté le 8 décembre 2025) ; une fonction AWS Lambda dédiée y écrit
directement dans SQS2.
J&amp;rsquo;assume la livraison “at least once” : pas d&amp;rsquo;ordre garanti ni de duplication
zéro, d&amp;rsquo;où l&amp;rsquo;usage d&amp;rsquo;un &lt;code>request_id&lt;/code> pour dédupliquer côté consommateurs et de
métriques &lt;code>ApproximateAgeOfOldestMessage&lt;/code> pour surveiller la latence. Si le bus
principal tombe, le &lt;a href="https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-global-endpoints.html">Global Endpoint EventBridge&lt;/a>
(consulté le 8 décembre 2025) bascule vers la région de secours. Ce n&amp;rsquo;est pas
parfait, mais c&amp;rsquo;est “best effort” avant la bascule DNS.&lt;/p>
&lt;h3 id="données-persistantes-alignées">Données persistantes alignées&lt;/h3>
&lt;p>Les sessions vivent dans &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GlobalTables.html">DynamoDB Global Tables&lt;/a>
(consulté le 8 décembre 2025) avec une clé &lt;code>tenant#session#rand&lt;/code> inspirée des
&lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-partition-key-design.html">Partition Key Design&lt;/a>
(consulté le 8 décembre 2025). Les conversations agrégées se déversent dans
&lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html">Aurora Global Database&lt;/a>
(consulté le 8 décembre 2025) : writer en us-east-1, reader en eu-west-1, et un
runbook documente un &lt;code>GlobalDatabaseFailover&lt;/code> qui prend quelques minutes (mes
relevés lors du GameDay de février 2025) pour promouvoir la région de secours
(Disaster Recovery, DR). AWS précise que la latence de réplication globale
reste généralement &amp;lt;1 seconde mais que le RTO peut grimper jusqu&amp;rsquo;à 5 minutes
selon la taille du cluster ; je conserve donc un tampon SQS + DynamoDB pour
rejouer les écritures perdues en cas de failover brutal.&lt;/p>
&lt;h3 id="runbook-route-53-concret">Runbook Route 53 concret&lt;/h3>
&lt;p>Route 53 reste un enregistrement ALIAS A/AAAA (ou un CNAME hors apex) vers
CloudFront. Quand je dois isoler un tenant (un espace client dédié) ou un pays,
je garde une distribution secondaire et une entrée DNS prête à être promue via
&lt;a href="https://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets.html">&lt;code>ChangeResourceRecordSets&lt;/code>&lt;/a>
(consulté le 8 décembre 2025). Les health checks HTTP ciblent directement la
distribution CloudFront (pas l&amp;rsquo;ALB), n&amp;rsquo;activent aucun failover Route 53
automatique et servent uniquement à déclencher mes alertes internes avant que
le runbook (cf. A5) ne prenne la main.&lt;/p>
&lt;h3 id="configuration-managée-et-répliquée">Configuration managée et répliquée&lt;/h3>
&lt;p>&lt;a href="https://docs.aws.amazon.com/appconfig/latest/userguide/what-is-appconfig.html">AWS AppConfig&lt;/a>
(consulté le 8 décembre 2025) déploie les feature flags dans chaque région via
la même pipeline CodePipeline/CodeDeploy. Secrets Manager offre la &lt;a href="https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotating-secrets.html">rotation automatique&lt;/a>
(consulté le 8 décembre 2025) ; Parameter Store est synchronisé par un runbook
&lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html">Systems Manager Automation&lt;/a>
(consulté le 8 décembre 2025) qui copie les paramètres vers la région de
secours. Tout est versionné, histoire de savoir qui a cassé quoi.&lt;/p>
&lt;h2 id="router-plusieurs-llm-sans-se-marier-avec-un-fournisseur">Router plusieurs LLM sans se marier avec un fournisseur&lt;/h2>
&lt;p>Je refuse d&amp;rsquo;écrire du code applicatif spécifique à un LLM. L&amp;rsquo;idée est d&amp;rsquo;avoir
un routeur métier qui parle aux SDK Bedrock, OpenAI et Anthropic de manière
homogène. J&amp;rsquo;utilise une couche d&amp;rsquo;abstraction maison (en Go) qui standardise les
prompts, les tokens et les stratégies de streaming. Les SDK officiels sont
référencés ici : &lt;a href="https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html">Amazon Bedrock&lt;/a>
(consulté le 8 décembre 2025), &lt;a href="https://platform.openai.com/docs/api-reference/introduction">OpenAI API&lt;/a> (consulté le
8 décembre 2025) et &lt;a href="https://docs.anthropic.com/claude/docs">Anthropic API&lt;/a>
(consulté le 8 décembre 2025).&lt;/p>
&lt;p>Le diagramme ci-dessous montre comment le routeur Go choisit le fournisseur
tout en gardant la traçabilité et les mémoires vectorielles.&lt;/p>
&lt;script src="https://unpkg.com/mermaid@11.12.0/dist/mermaid.min.js" type="text/javascript">&lt;/script>
&lt;script type="text/javascript">
mermaid.initialize({ startOnLoad:true });
&lt;/script>
&lt;pre class="mermaid" align="center">
flowchart LR
ClientPrompts --> Router[Service Go : Prompt Orchestrator]
Router -->|Policies| Bedrock
Router -->|Fallback| OpenAI
Router -->|Use-case ciblé| Anthropic
Router --> Cache[Vector store / mémoires]
Router --> Audit[S3 + DynamoDB traces]
&lt;/pre>
&lt;blockquote>
&lt;p>Lecture du diagramme : le service Go central reçoit les prompts, les enrichit
avec des politiques métier puis sélectionne Bedrock, OpenAI ou Anthropic
avant d&amp;rsquo;écrire les traces dans S3/DynamoDB et de ranger les mémoires
vectorielles dans un cache dédié.&lt;/p>
&lt;/blockquote>
&lt;p>Comme sur le schéma, chaque requête passe par un “Prompt Orchestrator” qui sait
quel modèle utiliser, comment appliquer les limites de tokens, quelles
garanties promettre, et comment retomber sur une version plus cheap si la
première refuse de répondre. J&amp;rsquo;insiste sur la traçabilité : chaque appel logge
la provenance, la politique appliquée, et la facture estimée.&lt;/p>
&lt;h3 id="interfaces-go-pour-garder-le-code-propre">Interfaces Go pour garder le code propre&lt;/h3>
&lt;p>Je ne veux pas d&amp;rsquo;un routeur monolithique, donc je formalise les abstractions
suivantes :&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">LLMProvider&lt;/span> &lt;span style="color:#66d9ef">interface&lt;/span> {
&lt;span style="color:#a6e22e">Name&lt;/span>() &lt;span style="color:#66d9ef">string&lt;/span>
&lt;span style="color:#a6e22e">Supports&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">intent&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>) &lt;span style="color:#66d9ef">bool&lt;/span>
&lt;span style="color:#a6e22e">Complete&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">prompt&lt;/span> &lt;span style="color:#a6e22e">Prompt&lt;/span>) (&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>)
&lt;span style="color:#a6e22e">CostEstimator&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">prompt&lt;/span> &lt;span style="color:#a6e22e">Prompt&lt;/span>) (&lt;span style="color:#a6e22e">TokenEstimate&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>)
}
&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">PromptRouter&lt;/span> &lt;span style="color:#66d9ef">interface&lt;/span> {
&lt;span style="color:#a6e22e">RegisterProvider&lt;/span>(&lt;span style="color:#a6e22e">provider&lt;/span> &lt;span style="color:#a6e22e">LLMProvider&lt;/span>)
&lt;span style="color:#a6e22e">Route&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">prompt&lt;/span> &lt;span style="color:#a6e22e">Prompt&lt;/span>) (&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>)
}
&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">QuotaLimiter&lt;/span> &lt;span style="color:#66d9ef">interface&lt;/span> {
&lt;span style="color:#a6e22e">Allow&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">tenant&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>, &lt;span style="color:#a6e22e">tokens&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>) &lt;span style="color:#66d9ef">error&lt;/span>
&lt;span style="color:#a6e22e">ObserveUsage&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">tenant&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>, &lt;span style="color:#a6e22e">tokens&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>)
}
&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">TelemetrySink&lt;/span> &lt;span style="color:#66d9ef">interface&lt;/span> {
&lt;span style="color:#a6e22e">EmitTrace&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">span&lt;/span> &lt;span style="color:#a6e22e">SpanData&lt;/span>)
&lt;span style="color:#a6e22e">EmitLog&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">entry&lt;/span> &lt;span style="color:#a6e22e">LogEntry&lt;/span>)
&lt;span style="color:#a6e22e">EmitMetric&lt;/span>(&lt;span style="color:#a6e22e">ctx&lt;/span> &lt;span style="color:#a6e22e">context&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>, &lt;span style="color:#a6e22e">metric&lt;/span> &lt;span style="color:#a6e22e">MetricData&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>LLMProvider&lt;/code> masque les API Bedrock/OpenAI/Anthropic, &lt;code>PromptRouter&lt;/code> orchestre
l&amp;rsquo;ensemble, &lt;code>QuotaLimiter&lt;/code> encapsule Redis + métriques, et &lt;code>TelemetrySink&lt;/code> se
branche sur OpenTelemetry/OTLP sans enfermer l&amp;rsquo;app dans un APM précis.&lt;/p>
&lt;h2 id="observabilité-unifiée-avec-opentelemetry">Observabilité unifiée avec OpenTelemetry&lt;/h2>
&lt;p>Pour éviter le vendor lock-in (et parce qu&amp;rsquo;on finit toujours par migrer d&amp;rsquo;outil
APM tôt ou tard), je pousse tout sur
&lt;a href="https://opentelemetry.io/docs/">OpenTelemetry&lt;/a> (consulté le 8 décembre 2025).
Les agents OTEL tournent comme sidecars sur ECS, collectent logs / traces /
métriques et les envoient vers CloudWatch, Grafana Cloud ou n&amp;rsquo;importe quel
endpoint OTLP. Ça me laisse la porte ouverte à une migration vers Tempo, Jaeger
ou New Relic sans toucher aux binaires.&lt;/p>
&lt;script src="https://unpkg.com/mermaid@11.12.0/dist/mermaid.min.js" type="text/javascript">&lt;/script>
&lt;script type="text/javascript">
mermaid.initialize({ startOnLoad:true });
&lt;/script>
&lt;pre class="mermaid" align="center">
flowchart LR
AppGo --> OTEL[OTel Collector]
OTEL --> CWLogs[CloudWatch Logs]
OTEL --> XRay
OTEL --> GrafanaCloud
OTEL --> S3ColdStorage
&lt;/pre>
&lt;blockquote>
&lt;p>Lecture du diagramme : l&amp;rsquo;app Go expédie ses traces, logs et métriques vers un
collector OpenTelemetry qui les duplique vers CloudWatch Logs, X-Ray, Grafana
Cloud et même S3 froid afin de ne pas dépendre d&amp;rsquo;un seul outil.&lt;/p>
&lt;/blockquote>
&lt;p>Dans la pratique, j&amp;rsquo;uniformise les attributs (&lt;code>tenant_id&lt;/code>, &lt;code>prompt_type&lt;/code>,
&lt;code>llm_vendor&lt;/code>) pour pouvoir corréler une saturation de quota Bedrock avec un pic
de latence sur OpenAI, ou détecter qu&amp;rsquo;un run AppConfig a dégradé l&amp;rsquo;expérience.
Le collector tourne côté cluster et exporte via OTLP + TLS, ce qui évite de
lier l&amp;rsquo;avenir de l&amp;rsquo;observabilité à un seul fournisseur.&lt;/p>
&lt;h2 id="optimiser-les-coûts-llm--infra--ecs">Optimiser les coûts LLM / Infra / ECS&lt;/h2>
&lt;p>Même en mode exploration, je garde l&amp;rsquo;œil sur la facture.&lt;/p>
&lt;h3 id="gérer-le-coût-llm">Gérer le coût LLM&lt;/h3>
&lt;p>Je passe toutes les requêtes par un &lt;code>Prompt Budgeter&lt;/code> qui estime les tokens
avant d&amp;rsquo;appeler un modèle onéreux. Bedrock couvrirait les intégrations AWS,
OpenAI la partie plus créative, Anthropic les prompts verbeux. Toute demande
qui dépasse un seuil part sur un traitement batch (SQS + Lambda) avec un modèle
moins coûteux.&lt;/p>
&lt;h3 id="contenir-la-facture-infra">Contenir la facture infra&lt;/h3>
&lt;p>ECS Fargate est confortable mais je prévois déjà des tâches “spot” pour les
workers non critiques et je définis un &lt;code>Service Quota&lt;/code> sur les NAT, parce que
chaque Go qui sort coûte son poids en or. Les métriques CloudWatch budgétaires
restent ouvertes en permanence.&lt;/p>
&lt;h3 id="ajuster-la-consommation-ecs">Ajuster la consommation ECS&lt;/h3>
&lt;p>Je serre les images (scratch), j&amp;rsquo;active le &lt;code>CPU bursting&lt;/code> quand c&amp;rsquo;est
pertinent et je programme l&amp;rsquo;arrêt automatique des environnements de test. Rien
de glamour, juste une discipline quotidienne pour éviter les surprises sur la
ligne AWS.&lt;/p>
&lt;h2 id="pourquoi-cette-architecture-tient-la-route-sur-le-papier">Pourquoi cette architecture tient la route sur le papier&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Scalabilité réaliste.&lt;/strong> Deux quotas Bedrock indépendants et observables
(&lt;code>InvocationThrottled&lt;/code>, &lt;code>bedrock_throttle_rate&lt;/code>) limitent le risque de
sur-scaler quand le fournisseur LLM est déjà au bord du throttling. Les limites
sont connues, affichées dans Grafana et se déclenchent avant l&amp;rsquo;Auto Scaling.&lt;/li>
&lt;li>&lt;strong>Observabilité plurielle.&lt;/strong> Traces X-Ray, logs JSON avec &lt;code>trace_id&lt;/code>,
dashboards &lt;a href="https://docs.aws.amazon.com/grafana/latest/userguide/what-is-AMG.html">Amazon Managed Grafana&lt;/a>
(consulté le 8 décembre 2025), canaries Synthetics et alarmes CloudWatch
forment un triptyque. Les métriques critiques sont routées vers EventBridge →
AWS Chatbot/SNS pour éviter de dépendre d&amp;rsquo;un seul outil.&lt;/li>
&lt;li>&lt;strong>Sécurité et secrets alignés.&lt;/strong> IAM reste à privilèges minimaux, les accès
Bedrock passent par VPC endpoint et les secrets sont injectés dynamiquement.
Pas de port public côté ECS et les NAT gardent leurs route tables locales à
chaque AZ.&lt;/li>
&lt;li>&lt;strong>Résilience multi-région assumée.&lt;/strong> CloudFront gère l&amp;rsquo;origine failover en
quelques secondes pour les GET/HEAD/OPTIONS tandis qu&amp;rsquo;Aurora Global a besoin de
quelques minutes pour promouvoir le writer (cf. A1).
Les queues/SNS, Redis et AppConfig existent dans chaque région ; Route 53 ne
change que si l&amp;rsquo;on veut isoler complètement un tenant. Pour des POST sub-60s
sans dépendre du client, il faudra ajouter Global Accelerator ou une autre
passerelle active/active : le runbook l&amp;rsquo;assume clairement.&lt;/li>
&lt;/ul>
&lt;h3 id="sources-officielles">Sources officielles&lt;/h3>
&lt;p>Chaque brique citée s&amp;rsquo;appuie sur les docs AWS correspondantes :
&lt;a href="https://docs.aws.amazon.com/wellarchitected/latest/framework/">Well-Architected&lt;/a>
et &lt;a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-throughput.html">Bedrock Provisioned Throughput&lt;/a>
(toutes deux consultées le 8 décembre 2025) servent de garde-fous conceptuels.&lt;/p>
&lt;h2 id="ce-que-jespère-obtenir-avec-ce-schéma">Ce que j&amp;rsquo;espère obtenir avec ce schéma&lt;/h2>
&lt;p>Le découpage ci-dessus m&amp;rsquo;intéresse parce qu&amp;rsquo;il isole chaque préoccupation :
CloudFront absorbe et filtre, les quotas restent locaux et observables, les
données longues vivent dans des systèmes globaux, et le runbook assume les
limites (quelques minutes pour promouvoir le writer Aurora selon les scénarios
précédents). Si un quota Bedrock se met à crier famine, je sais quel composant
doit siffler la fin de la récré.&lt;/p>
&lt;h2 id="ce-que-je-demande-aux-équipes-produit-et-dev">Ce que je demande aux équipes produit et dev&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Collaboration métriques.&lt;/strong> Transparence sur les métriques métier
(&lt;code>prompt_per_user&lt;/code>, &lt;code>llm_retry_rate&lt;/code>, &lt;code>bedrock_token_cost&lt;/code>) exposées dans
CloudWatch et Grafana, sans quoi impossible de prioriser les quotas.&lt;/li>
&lt;li>&lt;strong>SDK commun.&lt;/strong> Un Software Development Kit (SDK) Go/TypeScript partagé qui
gère instrumentation X-Ray, lecture des quotas Redis, un flag
&lt;code>failover_in_progress&lt;/code> issu d&amp;rsquo;AppConfig et un backoff standard (3 tentatives
max) pour éviter les implémentations maison.&lt;/li>
&lt;li>&lt;strong>Discipline AppConfig.&lt;/strong> Des feature flags pilotés par AppConfig avec
déploiement progressif et rollback automatique documenté ; pas question de
toggles copiés-collés dans les variables d&amp;rsquo;environnement.&lt;/li>
&lt;/ul>
&lt;script src="https://unpkg.com/mermaid@11.12.0/dist/mermaid.min.js" type="text/javascript">&lt;/script>
&lt;script type="text/javascript">
mermaid.initialize({ startOnLoad:true });
&lt;/script>
&lt;pre class="mermaid" align="center">
flowchart LR
EventBridge --> cb[AWS ChatBot] --> OpsGenie
EventBridge --> SNS --> SMS
&lt;/pre>
&lt;p>Quand une alerte tombe, EventBridge → AWS Chatbot → Opsgenie prend le relais,
et les SMS SNS rappellent tout le monde si &lt;code>ApproximateAgeOfOldestMessage&lt;/code>
dérape.&lt;/p>
&lt;p>En explorant cette architecture “sur le papier”, je préfère miser sur un
diagramme honnête plutôt que sur un runbook de 30 pages. Si cette réflexion
vous évite ne serait-ce qu&amp;rsquo;un redéploiement panique un vendredi soir, elle aura
servi. L&amp;rsquo;objectif reste de dompter les quotas avant qu&amp;rsquo;eux ne domptent votre
pager.&lt;/p></description></item><item><title>Comment Détecter un Article Généré par une IA : Guide Pratique</title><link>https://blog.moulard.org/comment-detecter-contenu-genere-par-ia/</link><pubDate>Fri, 12 Dec 2025 00:00:00 +0200</pubDate><guid>https://blog.moulard.org/comment-detecter-contenu-genere-par-ia/</guid><comments>https://blog.moulard.org/comment-detecter-contenu-genere-par-ia/#disqus_thread</comments><description>&lt;h1 id="lart-de-repérer-un-texte-écrit-par-une-machine">L&amp;rsquo;Art de Repérer un Texte Écrit par une Machine&lt;/h1>
&lt;p>Vous venez de lire un article. Quelque chose cloche. Les phrases sont trop lisses, les chiffres tombent trop rond, et bizarrement, tout semble&amp;hellip; parfait. Trop parfait. Félicitations, vous avez peut-être développé un sixième sens pour la détection de contenu IA.&lt;/p>
&lt;p>Avec la démocratisation de ChatGPT, Claude, et autres LLMs, le web se remplit de contenu généré automatiquement. Ce n&amp;rsquo;est pas forcément mal en soi (ce blog utilise parfois des workflows d&amp;rsquo;IA pour la création de contenu, comme je l&amp;rsquo;ai documenté &lt;a href="https://blog.moulard.org/subagentic-workflow-opencode">dans mon post sur les workflows sub-agentiques&lt;/a>), mais savoir distinguer le vrai du synthétique devient une compétence essentielle.&lt;/p>
&lt;p>Voici un guide concret pour développer votre radar à bullshit synthétique.&lt;/p>
&lt;h2 id="le-problème-des-statistiques-inventées">Le Problème des Statistiques Inventées&lt;/h2>
&lt;p>C&amp;rsquo;est probablement le signal d&amp;rsquo;alarme le plus fiable. Les LLMs sont des machines à patterns, pas des encyclopédies. Quand ils ont besoin d&amp;rsquo;un chiffre, ils en génèrent un qui &lt;em>semble&lt;/em> plausible.&lt;/p>
&lt;h3 id="comment-les-repérer-">Comment les repérer ?&lt;/h3>
&lt;p>&lt;strong>Les chiffres suspects ressemblent à ça :&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;73% des entreprises utilisent désormais l&amp;rsquo;IA&amp;rdquo; (pourquoi 73% et pas 71% ou 74% ?)&lt;/li>
&lt;li>&amp;ldquo;Les études montrent une augmentation de 40% de la productivité&amp;rdquo; (quelles études ? Où ? Quand ?)&lt;/li>
&lt;li>&amp;ldquo;Selon les experts, 8 développeurs sur 10 préfèrent&amp;hellip;&amp;rdquo; (quels experts ?)&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Les red flags :&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Chiffres ronds ou &amp;ldquo;satisfaisants&amp;rdquo; (40%, 50%, 80%) OU chiffres étrangement précis sans source&lt;/li>
&lt;li>Attribution vague : &amp;ldquo;des études montrent&amp;rdquo;, &amp;ldquo;selon les experts&amp;rdquo;, &amp;ldquo;les recherches indiquent&amp;rdquo;&lt;/li>
&lt;li>Statistiques qui semblent trop parfaitement alignées avec l&amp;rsquo;argument&lt;/li>
&lt;li>Absence totale de source ou de lien&lt;/li>
&lt;/ul>
&lt;p>Le problème n&amp;rsquo;est pas le chiffre lui-même, mais la &lt;strong>combinaison&lt;/strong> : chiffre précis + absence de source vérifiable.&lt;/p>
&lt;p>&lt;strong>Comment vérifier :&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>Copiez la statistique exacte entre guillemets dans Google&lt;/li>
&lt;li>Cherchez la source primaire (pas un autre article qui cite le même chiffre)&lt;/li>
&lt;li>Vérifiez la date de publication de l&amp;rsquo;étude citée&lt;/li>
&lt;li>Si vous ne trouvez rien de concret après 5 minutes de recherche, c&amp;rsquo;est probablement inventé&lt;/li>
&lt;/ol>
&lt;blockquote>
&lt;p>&lt;strong>Ma règle personnelle&lt;/strong> : Si un article cite plus de 3 statistiques sans aucun lien vers les sources, je le considère suspect par défaut.&lt;/p>
&lt;/blockquote>
&lt;h2 id="les-tics-de-langage-révélateurs">Les Tics de Langage Révélateurs&lt;/h2>
&lt;p>Les LLMs ont des patterns linguistiques reconnaissables. Ils ont été entraînés sur des millions de textes, et certaines formulations reviennent plus souvent que d&amp;rsquo;autres.&lt;/p>
&lt;h3 id="les-phrases-douverture-clichés">Les phrases d&amp;rsquo;ouverture clichés&lt;/h3>
&lt;pre>&lt;code>❌ &amp;quot;Dans le monde d'aujourd'hui...&amp;quot;
❌ &amp;quot;Il est important de noter que...&amp;quot;
❌ &amp;quot;À l'ère du numérique...&amp;quot;
❌ &amp;quot;Force est de constater que...&amp;quot;
❌ &amp;quot;Il convient de souligner...&amp;quot;
&lt;/code>&lt;/pre>&lt;p>Un humain qui écrit régulièrement développe son propre style. Un LLM génère du texte &amp;ldquo;moyen&amp;rdquo; qui ressemble à un mix de tout ce qu&amp;rsquo;il a lu.&lt;/p>
&lt;h3 id="loverdose-de-connecteurs-logiques">L&amp;rsquo;overdose de connecteurs logiques&lt;/h3>
&lt;p>Un texte IA abuse souvent des transitions :&lt;/p>
&lt;pre>&lt;code>&amp;quot;Premièrement... De plus... Par ailleurs... En outre...
Néanmoins... Toutefois... En définitive... En conclusion...&amp;quot;
&lt;/code>&lt;/pre>&lt;p>C&amp;rsquo;est techniquement correct, mais ça sonne comme une dissertation de lycée. Les vrais auteurs varient leur style, font des phrases courtes qui claquent, puis des longues qui développent une idée complexe avec des digressions parfois inutiles mais qui donnent du caractère.&lt;/p>
&lt;h3 id="la-structure-mécaniquement-parfaite">La structure mécaniquement parfaite&lt;/h3>
&lt;p>Regardez la structure de l&amp;rsquo;article :&lt;/p>
&lt;ul>
&lt;li>Chaque section fait exactement la même longueur ?&lt;/li>
&lt;li>Chaque point a exactement 3 sous-points ?&lt;/li>
&lt;li>Chaque paragraphe suit le pattern : affirmation → explication → exemple ?&lt;/li>
&lt;/ul>
&lt;p>C&amp;rsquo;est un signal. Les humains sont désordonnés. On fait des sections courtes quand on n&amp;rsquo;a pas grand-chose à dire, des sections longues quand le sujet nous passionne, et parfois on part en digression pendant 3 paragraphes sur un détail qui n&amp;rsquo;a rien à voir (comme là, maintenant).&lt;/p>
&lt;h2 id="le-manque-de-personnalité">Le Manque de Personnalité&lt;/h2>
&lt;h3 id="où-sont-les-opinions-">Où sont les opinions ?&lt;/h3>
&lt;p>Un article humain contient généralement des prises de position :&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;Personnellement, je pense que cette approche est stupide&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;J&amp;rsquo;ai essayé ça pendant 6 mois et c&amp;rsquo;est nul&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;Je sais que tout le monde adore X, mais franchement&amp;hellip;&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>Un LLM standard (non fine-tuné pour avoir une personnalité) reste neutre. Il présente &amp;ldquo;les deux côtés&amp;rdquo; de chaque argument, ne se mouille jamais, et conclut avec un consensus mou du type &amp;ldquo;en définitive, chaque approche a ses avantages et ses inconvénients&amp;rdquo;.&lt;/p>
&lt;h3 id="labsence-dexpérience-vécue">L&amp;rsquo;absence d&amp;rsquo;expérience vécue&lt;/h3>
&lt;p>Les indices d&amp;rsquo;authenticité humaine :&lt;/p>
&lt;ul>
&lt;li>Des anecdotes spécifiques (&amp;ldquo;Quand j&amp;rsquo;ai déployé ça en prod un vendredi soir&amp;hellip;&amp;quot;)&lt;/li>
&lt;li>Des échecs assumés (&amp;ldquo;J&amp;rsquo;ai passé 3 heures sur ce bug avant de réaliser que&amp;hellip;&amp;quot;)&lt;/li>
&lt;li>Des références datées et contextuelles (&amp;ldquo;En 2019, quand j&amp;rsquo;utilisais encore la v2.3&amp;hellip;&amp;quot;)&lt;/li>
&lt;li>Du jargon interne ou des private jokes&lt;/li>
&lt;/ul>
&lt;p>Un LLM n&amp;rsquo;a pas vécu. Il ne peut pas raconter &amp;ldquo;la fois où le serveur est tombé pendant la démo client&amp;rdquo; avec des détails qui sonnent vrais.&lt;/p>
&lt;h2 id="tableau-comparatif--humain-vs-ia">Tableau Comparatif : Humain vs IA&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Caractéristique&lt;/th>
&lt;th>Texte Humain&lt;/th>
&lt;th>Texte IA&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Statistiques&lt;/strong>&lt;/td>
&lt;td>Sourcées ou absentes&lt;/td>
&lt;td>Précises mais invérifiables&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Ton&lt;/strong>&lt;/td>
&lt;td>Variable, parfois incohérent&lt;/td>
&lt;td>Uniformément neutre&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Structure&lt;/strong>&lt;/td>
&lt;td>Organique, désordonnée&lt;/td>
&lt;td>Mécaniquement parfaite&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Opinions&lt;/strong>&lt;/td>
&lt;td>Présentes et assumées&lt;/td>
&lt;td>Évitées ou équilibrées&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Anecdotes&lt;/strong>&lt;/td>
&lt;td>Spécifiques, datées&lt;/td>
&lt;td>Génériques ou absentes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Longueur des sections&lt;/strong>&lt;/td>
&lt;td>Variable&lt;/td>
&lt;td>Similaire&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Digressions&lt;/strong>&lt;/td>
&lt;td>Fréquentes&lt;/td>
&lt;td>Rares&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Humour&lt;/strong>&lt;/td>
&lt;td>Personnel, contextuel&lt;/td>
&lt;td>Générique si présent&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="la-boîte-à-outils-de-détection">La Boîte à Outils de Détection&lt;/h2>
&lt;h3 id="vérifications-manuelles">Vérifications manuelles&lt;/h3>
&lt;ul>
&lt;li>&lt;input disabled="" type="checkbox"> Rechercher les statistiques exactes entre guillemets sur Google&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> Vérifier si l&amp;rsquo;auteur existe réellement (LinkedIn, autres publications)&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> Chercher des incohérences temporelles (événements récents mal datés)&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> Comparer avec d&amp;rsquo;autres articles du même auteur (cohérence de style ?)&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> Rechercher des phrases entières pour détecter du plagiat ou de la génération&lt;/li>
&lt;/ul>
&lt;h3 id="outils-de-détection-automatique">Outils de détection automatique&lt;/h3>
&lt;p>Il existe des outils comme GPTZero, Originality.ai, ou les détecteurs intégrés de certaines plateformes. &lt;strong>Mais attention&lt;/strong> : ils ne sont pas fiables à 100%.&lt;/p>
&lt;p>&lt;strong>Pourquoi les prendre avec des pincettes :&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Taux de faux positifs significatif (humains accusés d&amp;rsquo;être des IAs)&lt;/li>
&lt;li>Facilement contournables (paraphrase, réécriture)&lt;/li>
&lt;li>Les modèles évoluent plus vite que les détecteurs&lt;/li>
&lt;li>Un texte humain édité par une IA (ou l&amp;rsquo;inverse) brouille les pistes&lt;/li>
&lt;/ul>
&lt;p>Mon conseil : utilisez ces outils comme un &lt;strong>signal parmi d&amp;rsquo;autres&lt;/strong>, pas comme un verdict final.&lt;/p>
&lt;h3 id="lanalyse-de-perplexité-et-burstiness">L&amp;rsquo;analyse de &amp;ldquo;perplexité&amp;rdquo; et &amp;ldquo;burstiness&amp;rdquo;&lt;/h3>
&lt;p>Deux concepts techniques intéressants :&lt;/p>
&lt;p>&lt;strong>Perplexité&lt;/strong> : mesure à quel point le prochain mot est prévisible pour un modèle de langage. Les LLMs génèrent du texte à faible perplexité &lt;em>quand mesuré par un modèle similaire&lt;/em> (le texte suit des patterns que l&amp;rsquo;IA &amp;ldquo;connaît&amp;rdquo; bien). Les humains sont généralement plus imprévisibles, mais ce n&amp;rsquo;est pas une règle absolue.&lt;/p>
&lt;p>&lt;strong>Burstiness&lt;/strong> : variation dans la longueur et complexité des phrases. Les humains ont une écriture &amp;ldquo;en rafales&amp;rdquo; - parfois simple, parfois complexe. Les LLMs sont plus uniformes.&lt;/p>
&lt;p>Ces métriques sont utilisées par certains détecteurs, mais restent imparfaites.&lt;/p>
&lt;h2 id="les-zones-grises-et-léthique">Les Zones Grises (et l&amp;rsquo;Éthique)&lt;/h2>
&lt;h3 id="le-spectre-de-lassistance-ia">Le spectre de l&amp;rsquo;assistance IA&lt;/h3>
&lt;p>La réalité n&amp;rsquo;est pas binaire &amp;ldquo;100% humain&amp;rdquo; vs &amp;ldquo;100% IA&amp;rdquo;. Il existe un spectre :&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Texte 100% humain&lt;/strong> : écrit sans aucune assistance&lt;/li>
&lt;li>&lt;strong>Humain + correcteur IA&lt;/strong> : écrit par humain, corrigé par IA (grammaire, style)&lt;/li>
&lt;li>&lt;strong>Humain + suggestions IA&lt;/strong> : structure humaine, certaines formulations suggérées&lt;/li>
&lt;li>&lt;strong>Collaboration humain-IA&lt;/strong> : plan humain, rédaction IA, édition humaine&lt;/li>
&lt;li>&lt;strong>IA + édition humaine&lt;/strong> : généré par IA, retravaillé par humain&lt;/li>
&lt;li>&lt;strong>100% IA&lt;/strong> : prompt → publication sans modification&lt;/li>
&lt;/ol>
&lt;p>Où mettre la limite du &amp;ldquo;acceptable&amp;rdquo; ? Ça dépend du contexte. Un post LinkedIn généré par IA, on s&amp;rsquo;en fiche. Un article scientifique, c&amp;rsquo;est problématique. Un blog technique personnel ? C&amp;rsquo;est quelque part entre les deux.&lt;/p>
&lt;h3 id="les-faux-positifs-existent">Les faux positifs existent&lt;/h3>
&lt;p>Avant d&amp;rsquo;accuser quelqu&amp;rsquo;un d&amp;rsquo;utiliser une IA :&lt;/p>
&lt;ul>
&lt;li>Certains humains écrivent naturellement de façon &amp;ldquo;générique&amp;rdquo;&lt;/li>
&lt;li>Les non-natifs peuvent avoir un style plus formulaïque&lt;/li>
&lt;li>L&amp;rsquo;éducation académique pousse vers des structures rigides&lt;/li>
&lt;li>Certains sujets techniques nécessitent un ton neutre&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Ne jouez pas au détective accusateur.&lt;/strong> Utilisez ces outils pour votre propre discernement, pas pour des chasses aux sorcières.&lt;/p>
&lt;h2 id="ce-qui-compte-vraiment">Ce Qui Compte Vraiment&lt;/h2>
&lt;p>Au final, la question n&amp;rsquo;est peut-être pas &amp;ldquo;est-ce écrit par une IA ?&amp;rdquo; mais plutôt :&lt;/p>
&lt;ol>
&lt;li>&lt;strong>L&amp;rsquo;information est-elle vérifiable ?&lt;/strong> Sources, liens, preuves&lt;/li>
&lt;li>&lt;strong>L&amp;rsquo;auteur assume-t-il ses propos ?&lt;/strong> Signature, historique, réputation&lt;/li>
&lt;li>&lt;strong>Le contenu apporte-t-il de la valeur ?&lt;/strong> Originalité, insight, utilité&lt;/li>
&lt;/ol>
&lt;p>Un excellent article généré par IA avec vérification humaine vaut mieux qu&amp;rsquo;un mauvais article 100% humain rempli d&amp;rsquo;erreurs.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>Le vrai problème n&amp;rsquo;est pas l&amp;rsquo;IA. C&amp;rsquo;est le contenu de mauvaise qualité, peu importe sa source.&lt;/strong>&lt;/p>
&lt;/blockquote>
&lt;h2 id="développer-votre-esprit-critique">Développer Votre Esprit Critique&lt;/h2>
&lt;p>La meilleure défense contre le contenu IA de mauvaise qualité, c&amp;rsquo;est un esprit critique aiguisé :&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Vérifiez toujours les sources&lt;/strong> (humain ou IA, peu importe)&lt;/li>
&lt;li>&lt;strong>Méfiez-vous de ce qui confirme trop parfaitement vos biais&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Cherchez les voix dissonantes&lt;/strong> (les vrais experts ne sont jamais 100% d&amp;rsquo;accord)&lt;/li>
&lt;li>&lt;strong>Privilégiez les auteurs avec un historique vérifiable&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Croisez l&amp;rsquo;information&lt;/strong> (si vous ne trouvez l&amp;rsquo;info que sur un seul site, méfiance)&lt;/li>
&lt;/ul>
&lt;p>Ces compétences vous protègent contre le mauvais contenu IA, mais aussi contre la désinformation humaine, les arnaques, et le clickbait.&lt;/p>
&lt;h2 id="checklist-rapide-de-détection">Checklist Rapide de Détection&lt;/h2>
&lt;p>La prochaine fois que vous lisez un article suspect, passez-le par cette grille :&lt;/p>
&lt;ul>
&lt;li>&lt;input disabled="" type="checkbox"> Les statistiques sont-elles sourcées avec des liens ?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> L&amp;rsquo;auteur a-t-il d&amp;rsquo;autres publications vérifiables ?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> Le texte contient-il des opinions personnelles assumées ?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> Y a-t-il des anecdotes spécifiques et datées ?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> La structure est-elle variable ou mécaniquement régulière ?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> L&amp;rsquo;article évite-t-il les clichés d&amp;rsquo;ouverture (&amp;ldquo;Dans le monde d&amp;rsquo;aujourd&amp;rsquo;hui&amp;hellip;&amp;quot;) ?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> Le ton varie-t-il au fil du texte ?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> Les informations récentes sont-elles correctement datées ?&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Score :&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>6-8 coches : Probablement authentique&lt;/li>
&lt;li>3-5 coches : Zone grise, creusez plus&lt;/li>
&lt;li>0-2 coches : Forte probabilité de génération IA non vérifiée&lt;/li>
&lt;/ul>
&lt;h2 id="et-après-">Et Après ?&lt;/h2>
&lt;p>Les modèles s&amp;rsquo;améliorent. Les textes IA de demain seront plus difficiles à détecter que ceux d&amp;rsquo;aujourd&amp;rsquo;hui. Les prochaines générations de modèles (Claude 4, GPT-5, et au-delà) auront des patterns moins reconnaissables.&lt;/p>
&lt;p>Ce qui ne changera pas :&lt;/p>
&lt;ul>
&lt;li>Le besoin de vérifier les sources&lt;/li>
&lt;li>L&amp;rsquo;importance de l&amp;rsquo;esprit critique&lt;/li>
&lt;li>La valeur de l&amp;rsquo;expertise et de l&amp;rsquo;expérience authentique&lt;/li>
&lt;/ul>
&lt;p>La course entre générateurs et détecteurs continuera. Mais au final, la vraie compétence n&amp;rsquo;est pas de détecter l&amp;rsquo;IA - c&amp;rsquo;est de &lt;strong>distinguer le contenu de qualité du bullshit&lt;/strong>, quelle que soit sa source.&lt;/p>
&lt;hr>
&lt;h2 id="note-de-transparence">Note de Transparence&lt;/h2>
&lt;p>Ce blog post a été créé en utilisant mon workflow sub-agentique avec OpenCode (détaillé &lt;a href="https://blog.moulard.org/subagentic-workflow-opencode">ici&lt;/a>). L&amp;rsquo;ironie d&amp;rsquo;utiliser une IA pour écrire sur la détection de contenu IA n&amp;rsquo;est pas perdue sur moi.&lt;/p>
&lt;p>La différence ? Vérification humaine, édition, et surtout : je vous le dis ouvertement. La transparence, c&amp;rsquo;est ça le vrai game changer.&lt;/p>
&lt;p>&lt;em>Et oui, j&amp;rsquo;ai volontairement évité les statistiques invérifiables dans cet article. Vous voyez le pattern ?&lt;/em>&lt;/p></description></item><item><title>Factory vs Singleton: Why Your Go HTTP API Deserves Better Than Global State</title><link>https://blog.moulard.org/factory-vs-singleton-go-http-apis/</link><pubDate>Fri, 05 Dec 2025 12:00:00 +0200</pubDate><guid>https://blog.moulard.org/factory-vs-singleton-go-http-apis/</guid><comments>https://blog.moulard.org/factory-vs-singleton-go-http-apis/#disqus_thread</comments><description>&lt;h1 id="the-3-am-production-nightmare">The 3 AM Production Nightmare&lt;/h1>
&lt;p>Picture this: It&amp;rsquo;s 3 AM. Production is on fire. You&amp;rsquo;re desperately trying to debug why your HTTP API is returning cached data from &lt;em>yesterday&lt;/em>. You trace the issue to your HTTP client&amp;hellip; which is a singleton&amp;hellip; that someone initialized with a 24-hour cache&amp;hellip; and there&amp;rsquo;s no way to reset it without restarting the entire service.&lt;/p>
&lt;p>I&amp;rsquo;ve been there. Twice, actually. The second time was worse because I &lt;em>knew&lt;/em> better but had inherited the codebase.&lt;/p>
&lt;p>This post is about why the &lt;strong>Factory pattern&lt;/strong> beats &lt;strong>Singleton&lt;/strong> for HTTP clients in Go. Not because some design pattern book says so, but because I&amp;rsquo;ve debugged enough production incidents to have opinions.&lt;/p>
&lt;hr>
&lt;h2 id="the-two-approaches">The Two Approaches&lt;/h2>
&lt;h3 id="the-singleton-pattern-the-one-ring-to-rule-them-all-approach">The Singleton Pattern: The &amp;ldquo;One Ring to Rule Them All&amp;rdquo; Approach&lt;/h3>
&lt;p>The Singleton pattern ensures a class has only &lt;strong>one instance&lt;/strong> and provides a global point of access to it. In Go, it typically looks like this:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>
&lt;span style="color:#f92672">import&lt;/span> (
&lt;span style="color:#e6db74">&amp;#34;net/http&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;sync&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;time&amp;#34;&lt;/span>
)
&lt;span style="color:#75715e">// Singleton HTTP client - there can be only one!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">var&lt;/span> (
&lt;span style="color:#a6e22e">instance&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Client&lt;/span>
&lt;span style="color:#a6e22e">once&lt;/span> &lt;span style="color:#a6e22e">sync&lt;/span>.&lt;span style="color:#a6e22e">Once&lt;/span>
)
&lt;span style="color:#75715e">// GetClient returns THE HTTP client. The only one. Forever.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">GetClient&lt;/span>() &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Client&lt;/span> {
&lt;span style="color:#a6e22e">once&lt;/span>.&lt;span style="color:#a6e22e">Do&lt;/span>(&lt;span style="color:#66d9ef">func&lt;/span>() {
&lt;span style="color:#a6e22e">instance&lt;/span> = &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Client&lt;/span>{
&lt;span style="color:#a6e22e">Timeout&lt;/span>: &lt;span style="color:#ae81ff">30&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#a6e22e">time&lt;/span>.&lt;span style="color:#a6e22e">Second&lt;/span>,
&lt;span style="color:#a6e22e">Transport&lt;/span>: &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Transport&lt;/span>{
&lt;span style="color:#a6e22e">MaxIdleConns&lt;/span>: &lt;span style="color:#ae81ff">100&lt;/span>,
&lt;span style="color:#a6e22e">MaxIdleConnsPerHost&lt;/span>: &lt;span style="color:#ae81ff">10&lt;/span>,
&lt;span style="color:#a6e22e">IdleConnTimeout&lt;/span>: &lt;span style="color:#ae81ff">90&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#a6e22e">time&lt;/span>.&lt;span style="color:#a6e22e">Second&lt;/span>,
},
}
})
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">instance&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Looks clean, right? One client, thread-safe initialization with &lt;code>sync.Once&lt;/code>, everyone&amp;rsquo;s happy.&lt;/p>
&lt;p>Now let&amp;rsquo;s use it in an HTTP handler:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">api&lt;/span>
&lt;span style="color:#f92672">import&lt;/span> (
&lt;span style="color:#e6db74">&amp;#34;encoding/json&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;net/http&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;myapp/httpclient&amp;#34;&lt;/span>
)
&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">UserHandler&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span>{}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">h&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span>) &lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">ResponseWriter&lt;/span>, &lt;span style="color:#a6e22e">r&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) {
&lt;span style="color:#75715e">// Using our singleton client
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">GetClient&lt;/span>()
&lt;span style="color:#a6e22e">resp&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">client&lt;/span>.&lt;span style="color:#a6e22e">Get&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;https://api.example.com/users/123&amp;#34;&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span> {
&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Error&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;Failed to fetch user&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span>
}
&lt;span style="color:#66d9ef">defer&lt;/span> &lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>.&lt;span style="color:#a6e22e">Close&lt;/span>()
&lt;span style="color:#66d9ef">var&lt;/span> &lt;span style="color:#a6e22e">user&lt;/span> &lt;span style="color:#a6e22e">User&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">NewDecoder&lt;/span>(&lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>).&lt;span style="color:#a6e22e">Decode&lt;/span>(&lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">user&lt;/span>); &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span> {
&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Error&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;Failed to decode user&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span>
}
&lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">NewEncoder&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>).&lt;span style="color:#a6e22e">Encode&lt;/span>(&lt;span style="color:#a6e22e">user&lt;/span>)
}
&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">User&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">ID&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span> &lt;span style="color:#e6db74">`json:&amp;#34;id&amp;#34;`&lt;/span>
&lt;span style="color:#a6e22e">Name&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span> &lt;span style="color:#e6db74">`json:&amp;#34;name&amp;#34;`&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="the-factory-pattern-the-made-to-order-approach">The Factory Pattern: The &amp;ldquo;Made to Order&amp;rdquo; Approach&lt;/h3>
&lt;p>The Factory pattern creates objects without exposing the creation logic. In Go, we typically combine it with &lt;strong>dependency injection&lt;/strong> and &lt;strong>interfaces&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>
&lt;span style="color:#f92672">import&lt;/span> (
&lt;span style="color:#e6db74">&amp;#34;net/http&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;time&amp;#34;&lt;/span>
)
&lt;span style="color:#75715e">// HTTPClient defines what we need from an HTTP client
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">HTTPClient&lt;/span> &lt;span style="color:#66d9ef">interface&lt;/span> {
&lt;span style="color:#a6e22e">Do&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>)
&lt;span style="color:#a6e22e">Get&lt;/span>(&lt;span style="color:#a6e22e">url&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>)
}
&lt;span style="color:#75715e">// ClientConfig holds configuration for creating clients
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">ClientConfig&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">Timeout&lt;/span> &lt;span style="color:#a6e22e">time&lt;/span>.&lt;span style="color:#a6e22e">Duration&lt;/span>
&lt;span style="color:#a6e22e">MaxIdleConns&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>
&lt;span style="color:#a6e22e">MaxIdleConnsPerHost&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>
&lt;span style="color:#a6e22e">IdleConnTimeout&lt;/span> &lt;span style="color:#a6e22e">time&lt;/span>.&lt;span style="color:#a6e22e">Duration&lt;/span>
}
&lt;span style="color:#75715e">// DefaultConfig returns sensible defaults
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">DefaultConfig&lt;/span>() &lt;span style="color:#a6e22e">ClientConfig&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">ClientConfig&lt;/span>{
&lt;span style="color:#a6e22e">Timeout&lt;/span>: &lt;span style="color:#ae81ff">30&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#a6e22e">time&lt;/span>.&lt;span style="color:#a6e22e">Second&lt;/span>,
&lt;span style="color:#a6e22e">MaxIdleConns&lt;/span>: &lt;span style="color:#ae81ff">100&lt;/span>,
&lt;span style="color:#a6e22e">MaxIdleConnsPerHost&lt;/span>: &lt;span style="color:#ae81ff">10&lt;/span>,
&lt;span style="color:#a6e22e">IdleConnTimeout&lt;/span>: &lt;span style="color:#ae81ff">90&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#a6e22e">time&lt;/span>.&lt;span style="color:#a6e22e">Second&lt;/span>,
}
}
&lt;span style="color:#75715e">// NewClient creates a new HTTP client with the given config
&lt;/span>&lt;span style="color:#75715e">// This is our Factory function!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewClient&lt;/span>(&lt;span style="color:#a6e22e">cfg&lt;/span> &lt;span style="color:#a6e22e">ClientConfig&lt;/span>) &lt;span style="color:#a6e22e">HTTPClient&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Client&lt;/span>{
&lt;span style="color:#a6e22e">Timeout&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">Timeout&lt;/span>,
&lt;span style="color:#a6e22e">Transport&lt;/span>: &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Transport&lt;/span>{
&lt;span style="color:#a6e22e">MaxIdleConns&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">MaxIdleConns&lt;/span>,
&lt;span style="color:#a6e22e">MaxIdleConnsPerHost&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">MaxIdleConnsPerHost&lt;/span>,
&lt;span style="color:#a6e22e">IdleConnTimeout&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">IdleConnTimeout&lt;/span>,
},
}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>And the handler using dependency injection:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">api&lt;/span>
&lt;span style="color:#f92672">import&lt;/span> (
&lt;span style="color:#e6db74">&amp;#34;encoding/json&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;io&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;net/http&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;myapp/httpclient&amp;#34;&lt;/span>
)
&lt;span style="color:#75715e">// Maximum response body size to prevent memory exhaustion (1MB)
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#a6e22e">maxResponseBodySize&lt;/span> = &lt;span style="color:#ae81ff">1&lt;/span> &lt;span style="color:#f92672">&amp;lt;&amp;lt;&lt;/span> &lt;span style="color:#ae81ff">20&lt;/span>
&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">UserHandler&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">HTTPClient&lt;/span> &lt;span style="color:#75715e">// Injected dependency!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;span style="color:#75715e">// NewUserHandler is a factory for creating UserHandlers
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">HTTPClient&lt;/span>) &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span>{&lt;span style="color:#a6e22e">client&lt;/span>: &lt;span style="color:#a6e22e">client&lt;/span>}
}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">h&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span>) &lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">ResponseWriter&lt;/span>, &lt;span style="color:#a6e22e">r&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) {
&lt;span style="color:#75715e">// Use context from incoming request for proper cancellation
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">req&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">NewRequestWithContext&lt;/span>(&lt;span style="color:#a6e22e">r&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>(), &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;https://api.example.com/users/123&amp;#34;&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span> {
&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Error&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;Failed to create request&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span>
}
&lt;span style="color:#a6e22e">resp&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">h&lt;/span>.&lt;span style="color:#a6e22e">client&lt;/span>.&lt;span style="color:#a6e22e">Do&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span> {
&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Error&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;Failed to fetch user&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span>
}
&lt;span style="color:#66d9ef">defer&lt;/span> &lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>.&lt;span style="color:#a6e22e">Close&lt;/span>()
&lt;span style="color:#75715e">// Check status code before processing
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">StatusCode&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span> {
&lt;span style="color:#75715e">// Drain body to allow connection reuse
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">Copy&lt;/span>(&lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">Discard&lt;/span>, &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">LimitReader&lt;/span>(&lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>, &lt;span style="color:#a6e22e">maxResponseBodySize&lt;/span>))
&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Error&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;Upstream API error&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusBadGateway&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span>
}
&lt;span style="color:#75715e">// Limit response body size to prevent memory exhaustion
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">limitedBody&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">LimitReader&lt;/span>(&lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>, &lt;span style="color:#a6e22e">maxResponseBodySize&lt;/span>)
&lt;span style="color:#66d9ef">var&lt;/span> &lt;span style="color:#a6e22e">user&lt;/span> &lt;span style="color:#a6e22e">User&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">NewDecoder&lt;/span>(&lt;span style="color:#a6e22e">limitedBody&lt;/span>).&lt;span style="color:#a6e22e">Decode&lt;/span>(&lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">user&lt;/span>); &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span> {
&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Error&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;Failed to decode user&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span>
}
&lt;span style="color:#a6e22e">w&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>().&lt;span style="color:#a6e22e">Set&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;Content-Type&amp;#34;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;application/json&amp;#34;&lt;/span>)
&lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">NewEncoder&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>).&lt;span style="color:#a6e22e">Encode&lt;/span>(&lt;span style="color:#a6e22e">user&lt;/span>)
}
&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">User&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">ID&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span> &lt;span style="color:#e6db74">`json:&amp;#34;id&amp;#34;`&lt;/span>
&lt;span style="color:#a6e22e">Name&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span> &lt;span style="color:#e6db74">`json:&amp;#34;name&amp;#34;`&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&amp;ldquo;But that&amp;rsquo;s more code!&amp;rdquo; Yes. About 40 more lines. I&amp;rsquo;ll take 40 lines over a 3 AM debugging session any day.&lt;/p>
&lt;hr>
&lt;h2 id="testing-where-singleton-falls-apart">Testing: Where Singleton Falls Apart&lt;/h2>
&lt;p>Here&amp;rsquo;s where it gets painful. Try writing tests for both approaches.&lt;/p>
&lt;h3 id="testing-the-singleton-approach-the-hard-way">Testing the Singleton Approach (The Hard Way)&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">api&lt;/span>
&lt;span style="color:#f92672">import&lt;/span> (
&lt;span style="color:#e6db74">&amp;#34;net/http&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;net/http/httptest&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;testing&amp;#34;&lt;/span>
)
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">TestUserHandler_GetUser_Singleton&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#75715e">// Problem 1: How do we mock httpclient.GetClient()?
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// The singleton is already initialized!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#75715e">// Option A: Create a test server (integration test, not unit test)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">ts&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewServer&lt;/span>(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">HandlerFunc&lt;/span>(&lt;span style="color:#66d9ef">func&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">ResponseWriter&lt;/span>, &lt;span style="color:#a6e22e">r&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) {
&lt;span style="color:#a6e22e">w&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>().&lt;span style="color:#a6e22e">Set&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;Content-Type&amp;#34;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;application/json&amp;#34;&lt;/span>)
&lt;span style="color:#a6e22e">w&lt;/span>.&lt;span style="color:#a6e22e">Write&lt;/span>([]byte(&lt;span style="color:#e6db74">`{&amp;#34;id&amp;#34;: 123, &amp;#34;name&amp;#34;: &amp;#34;Test User&amp;#34;}`&lt;/span>))
}))
&lt;span style="color:#66d9ef">defer&lt;/span> &lt;span style="color:#a6e22e">ts&lt;/span>.&lt;span style="color:#a6e22e">Close&lt;/span>()
&lt;span style="color:#75715e">// But wait... our handler hardcodes &amp;#34;https://api.example.com&amp;#34;
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// We can&amp;#39;t change the URL without modifying production code!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#75715e">// Option B: Use build tags or test hooks (yuck)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// Option C: Use a global variable that can be swapped (double yuck)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// Option D: Cry.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Skip&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;This test demonstrates why singletons are hard to test&amp;#34;&lt;/span>)
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">TestUserHandler_GetUser_Singleton_Parallel&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#75715e">// Problem 2: Tests can&amp;#39;t run in parallel safely
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// If one test modifies the singleton state, others are affected
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Parallel&lt;/span>() &lt;span style="color:#75715e">// This is asking for trouble!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#75715e">// Imagine multiple tests running simultaneously:
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// - Test A wants the client to timeout
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// - Test B wants the client to return errors
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// - Test C wants the client to succeed
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// They&amp;#39;re all sharing the SAME client instance!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Skip&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;Parallel tests with singletons are dangerous&amp;#34;&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="testing-the-factory-approach-the-natural-way">Testing the Factory Approach (The Natural Way)&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">api&lt;/span>
&lt;span style="color:#f92672">import&lt;/span> (
&lt;span style="color:#e6db74">&amp;#34;bytes&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;encoding/json&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;errors&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;io&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;net&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;net/http&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;net/http/httptest&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;testing&amp;#34;&lt;/span>
)
&lt;span style="color:#75715e">// MockHTTPClient is our test double
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">MockHTTPClient&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">DoFunc&lt;/span> &lt;span style="color:#66d9ef">func&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>)
}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">m&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">MockHTTPClient&lt;/span>) &lt;span style="color:#a6e22e">Do&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>) {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">m&lt;/span>.&lt;span style="color:#a6e22e">DoFunc&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span>)
}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">m&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">MockHTTPClient&lt;/span>) &lt;span style="color:#a6e22e">Get&lt;/span>(&lt;span style="color:#a6e22e">url&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>) {
&lt;span style="color:#a6e22e">req&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">NewRequest&lt;/span>(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#a6e22e">url&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span>
}
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">m&lt;/span>.&lt;span style="color:#a6e22e">Do&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span>)
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">TestUserHandler_GetUser_Success&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Parallel&lt;/span>() &lt;span style="color:#75715e">// Safe! Each test gets its own mock
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#a6e22e">expectedUser&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">User&lt;/span>{&lt;span style="color:#a6e22e">ID&lt;/span>: &lt;span style="color:#ae81ff">123&lt;/span>, &lt;span style="color:#a6e22e">Name&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;Test User&amp;#34;&lt;/span>}
&lt;span style="color:#a6e22e">mock&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">MockHTTPClient&lt;/span>{
&lt;span style="color:#a6e22e">DoFunc&lt;/span>: &lt;span style="color:#66d9ef">func&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>) {
&lt;span style="color:#75715e">// Verify the request is correct
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">req&lt;/span>.&lt;span style="color:#a6e22e">URL&lt;/span>.&lt;span style="color:#a6e22e">String&lt;/span>() &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;https://api.example.com/users/123&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Errorf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;unexpected URL: %s&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">req&lt;/span>.&lt;span style="color:#a6e22e">URL&lt;/span>)
}
&lt;span style="color:#75715e">// Return our mock response
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">body&lt;/span>, &lt;span style="color:#a6e22e">_&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">Marshal&lt;/span>(&lt;span style="color:#a6e22e">expectedUser&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>{
&lt;span style="color:#a6e22e">StatusCode&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span>,
&lt;span style="color:#a6e22e">Body&lt;/span>: &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">NopCloser&lt;/span>(&lt;span style="color:#a6e22e">bytes&lt;/span>.&lt;span style="color:#a6e22e">NewReader&lt;/span>(&lt;span style="color:#a6e22e">body&lt;/span>)),
&lt;span style="color:#a6e22e">Header&lt;/span>: make(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>),
}, &lt;span style="color:#66d9ef">nil&lt;/span>
},
}
&lt;span style="color:#a6e22e">handler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">mock&lt;/span>)
&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRequest&lt;/span>(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;/user&amp;#34;&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;span style="color:#a6e22e">rec&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRecorder&lt;/span>()
&lt;span style="color:#a6e22e">handler&lt;/span>.&lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">rec&lt;/span>, &lt;span style="color:#a6e22e">req&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span> {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Errorf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;expected status 200, got %d&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span>)
}
&lt;span style="color:#66d9ef">var&lt;/span> &lt;span style="color:#a6e22e">user&lt;/span> &lt;span style="color:#a6e22e">User&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">NewDecoder&lt;/span>(&lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>).&lt;span style="color:#a6e22e">Decode&lt;/span>(&lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">user&lt;/span>); &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span> {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Fatalf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;failed to decode response: %v&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span>)
}
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">user&lt;/span>.&lt;span style="color:#a6e22e">ID&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">expectedUser&lt;/span>.&lt;span style="color:#a6e22e">ID&lt;/span> &lt;span style="color:#f92672">||&lt;/span> &lt;span style="color:#a6e22e">user&lt;/span>.&lt;span style="color:#a6e22e">Name&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">expectedUser&lt;/span>.&lt;span style="color:#a6e22e">Name&lt;/span> {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Errorf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;expected %+v, got %+v&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">expectedUser&lt;/span>, &lt;span style="color:#a6e22e">user&lt;/span>)
}
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">TestUserHandler_GetUser_NetworkError&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Parallel&lt;/span>() &lt;span style="color:#75715e">// Still safe!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#a6e22e">mock&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">MockHTTPClient&lt;/span>{
&lt;span style="color:#a6e22e">DoFunc&lt;/span>: &lt;span style="color:#66d9ef">func&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>) {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span>, &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">net&lt;/span>.&lt;span style="color:#a6e22e">OpError&lt;/span>{&lt;span style="color:#a6e22e">Op&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;dial&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">Err&lt;/span>: &lt;span style="color:#a6e22e">errors&lt;/span>.&lt;span style="color:#a6e22e">New&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;connection refused&amp;#34;&lt;/span>)}
},
}
&lt;span style="color:#a6e22e">handler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">mock&lt;/span>)
&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRequest&lt;/span>(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;/user&amp;#34;&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;span style="color:#a6e22e">rec&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRecorder&lt;/span>()
&lt;span style="color:#a6e22e">handler&lt;/span>.&lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">rec&lt;/span>, &lt;span style="color:#a6e22e">req&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span> {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Errorf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;expected status 500, got %d&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span>)
}
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">TestUserHandler_GetUser_InvalidJSON&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Parallel&lt;/span>() &lt;span style="color:#75715e">// Always safe!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#a6e22e">mock&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">MockHTTPClient&lt;/span>{
&lt;span style="color:#a6e22e">DoFunc&lt;/span>: &lt;span style="color:#66d9ef">func&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>) {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>{
&lt;span style="color:#a6e22e">StatusCode&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span>,
&lt;span style="color:#a6e22e">Body&lt;/span>: &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">NopCloser&lt;/span>(&lt;span style="color:#a6e22e">bytes&lt;/span>.&lt;span style="color:#a6e22e">NewReader&lt;/span>([]byte(&lt;span style="color:#e6db74">&amp;#34;not json&amp;#34;&lt;/span>))),
&lt;span style="color:#a6e22e">Header&lt;/span>: make(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>),
}, &lt;span style="color:#66d9ef">nil&lt;/span>
},
}
&lt;span style="color:#a6e22e">handler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">mock&lt;/span>)
&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRequest&lt;/span>(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;/user&amp;#34;&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;span style="color:#a6e22e">rec&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRecorder&lt;/span>()
&lt;span style="color:#a6e22e">handler&lt;/span>.&lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">rec&lt;/span>, &lt;span style="color:#a6e22e">req&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span> {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Errorf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;expected status 500, got %d&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span>)
}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Three tests, all parallel, each with isolated mock behavior. This is how testing should work.&lt;/p>
&lt;h3 id="table-driven-tests-the-factory-patterns-best-friend">Table-Driven Tests: The Factory Pattern&amp;rsquo;s Best Friend&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Note: This test requires the imports from the previous test file:
&lt;/span>&lt;span style="color:#75715e">// &amp;#34;bytes&amp;#34;, &amp;#34;errors&amp;#34;, &amp;#34;io&amp;#34;, &amp;#34;net/http&amp;#34;, &amp;#34;net/http/httptest&amp;#34;, &amp;#34;testing&amp;#34;
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">TestUserHandler_GetUser_TableDriven&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Parallel&lt;/span>()
&lt;span style="color:#a6e22e">tests&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> []&lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">name&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>
&lt;span style="color:#a6e22e">mockResponse&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>
&lt;span style="color:#a6e22e">mockError&lt;/span> &lt;span style="color:#66d9ef">error&lt;/span>
&lt;span style="color:#a6e22e">expectedStatus&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>
&lt;span style="color:#a6e22e">expectedBody&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>
}{
{
&lt;span style="color:#a6e22e">name&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;success&amp;#34;&lt;/span>,
&lt;span style="color:#a6e22e">mockResponse&lt;/span>: &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>{
&lt;span style="color:#a6e22e">StatusCode&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span>,
&lt;span style="color:#a6e22e">Body&lt;/span>: &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">NopCloser&lt;/span>(&lt;span style="color:#a6e22e">bytes&lt;/span>.&lt;span style="color:#a6e22e">NewReader&lt;/span>([]byte(&lt;span style="color:#e6db74">`{&amp;#34;id&amp;#34;:1,&amp;#34;name&amp;#34;:&amp;#34;Alice&amp;#34;}`&lt;/span>))),
&lt;span style="color:#a6e22e">Header&lt;/span>: make(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>),
},
&lt;span style="color:#a6e22e">expectedStatus&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span>,
&lt;span style="color:#a6e22e">expectedBody&lt;/span>: &lt;span style="color:#e6db74">`{&amp;#34;id&amp;#34;:1,&amp;#34;name&amp;#34;:&amp;#34;Alice&amp;#34;}`&lt;/span>,
},
{
&lt;span style="color:#a6e22e">name&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;network error&amp;#34;&lt;/span>,
&lt;span style="color:#a6e22e">mockError&lt;/span>: &lt;span style="color:#a6e22e">errors&lt;/span>.&lt;span style="color:#a6e22e">New&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;connection refused&amp;#34;&lt;/span>),
&lt;span style="color:#a6e22e">expectedStatus&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span>,
},
{
&lt;span style="color:#a6e22e">name&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;api returns 404&amp;#34;&lt;/span>,
&lt;span style="color:#a6e22e">mockResponse&lt;/span>: &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>{
&lt;span style="color:#a6e22e">StatusCode&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusNotFound&lt;/span>,
&lt;span style="color:#a6e22e">Body&lt;/span>: &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">NopCloser&lt;/span>(&lt;span style="color:#a6e22e">bytes&lt;/span>.&lt;span style="color:#a6e22e">NewReader&lt;/span>([]byte(&lt;span style="color:#e6db74">`{&amp;#34;error&amp;#34;:&amp;#34;not found&amp;#34;}`&lt;/span>))),
&lt;span style="color:#a6e22e">Header&lt;/span>: make(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>),
},
&lt;span style="color:#a6e22e">expectedStatus&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusBadGateway&lt;/span>, &lt;span style="color:#75715e">// Handler now properly checks status codes!
&lt;/span>&lt;span style="color:#75715e">&lt;/span> },
{
&lt;span style="color:#a6e22e">name&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;invalid json response&amp;#34;&lt;/span>,
&lt;span style="color:#a6e22e">mockResponse&lt;/span>: &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>{
&lt;span style="color:#a6e22e">StatusCode&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span>,
&lt;span style="color:#a6e22e">Body&lt;/span>: &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">NopCloser&lt;/span>(&lt;span style="color:#a6e22e">bytes&lt;/span>.&lt;span style="color:#a6e22e">NewReader&lt;/span>([]byte(&lt;span style="color:#e6db74">`{invalid}`&lt;/span>))),
&lt;span style="color:#a6e22e">Header&lt;/span>: make(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>),
},
&lt;span style="color:#a6e22e">expectedStatus&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span>,
},
}
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">_&lt;/span>, &lt;span style="color:#a6e22e">tt&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">tests&lt;/span> {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Run&lt;/span>(&lt;span style="color:#a6e22e">tt&lt;/span>.&lt;span style="color:#a6e22e">name&lt;/span>, &lt;span style="color:#66d9ef">func&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Parallel&lt;/span>()
&lt;span style="color:#a6e22e">mock&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">MockHTTPClient&lt;/span>{
&lt;span style="color:#a6e22e">DoFunc&lt;/span>: &lt;span style="color:#66d9ef">func&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>) {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">tt&lt;/span>.&lt;span style="color:#a6e22e">mockResponse&lt;/span>, &lt;span style="color:#a6e22e">tt&lt;/span>.&lt;span style="color:#a6e22e">mockError&lt;/span>
},
}
&lt;span style="color:#a6e22e">handler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">mock&lt;/span>)
&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRequest&lt;/span>(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;/user&amp;#34;&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;span style="color:#a6e22e">rec&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRecorder&lt;/span>()
&lt;span style="color:#a6e22e">handler&lt;/span>.&lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">rec&lt;/span>, &lt;span style="color:#a6e22e">req&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">tt&lt;/span>.&lt;span style="color:#a6e22e">expectedStatus&lt;/span> {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Errorf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;expected status %d, got %d&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">tt&lt;/span>.&lt;span style="color:#a6e22e">expectedStatus&lt;/span>, &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span>)
}
})
}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote>
&lt;p>&lt;strong>Note for Go 1.22+&lt;/strong>: The &lt;code>tt := tt&lt;/code> line to capture the loop variable is no longer needed in Go 1.22 and later, as loop variables are now scoped per iteration. I&amp;rsquo;ve removed it from this example.&lt;/p>
&lt;/blockquote>
&lt;h3 id="generating-mocks-with-mocktail-stop-writing-boilerplate">Generating Mocks with Mocktail: Stop Writing Boilerplate!&lt;/h3>
&lt;p>Writing mocks by hand gets old fast. I&amp;rsquo;ve wasted too many hours writing boilerplate &lt;code>DoFunc&lt;/code> callbacks.&lt;/p>
&lt;p>&lt;a href="https://github.com/paperballs/mocktail">&lt;strong>Mocktail&lt;/strong>&lt;/a> generates strongly-typed mocks using &lt;code>testify/mock&lt;/code>. The key difference from other generators: it uses typed methods instead of string-based calls. When your interface changes, compilation fails. No more &amp;ldquo;forgot to update the mock&amp;rdquo; bugs.&lt;/p>
&lt;h4 id="installing-mocktail">Installing Mocktail&lt;/h4>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">go install github.com/paperballs/mocktail@latest
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="setting-up-mocks">Setting Up Mocks&lt;/h4>
&lt;p>Create a file named &lt;code>mock_test.go&lt;/code> in your package and add directives for the interfaces you want to mock:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">api&lt;/span>
&lt;span style="color:#75715e">// mocktail:HTTPClient
&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Then run &lt;code>mocktail&lt;/code> at the root of your project:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">mocktail
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Mocktail generates a &lt;code>mock_gen_test.go&lt;/code> file with your mock implementation.&lt;/p>
&lt;h4 id="using-mocktail-generated-mocks">Using Mocktail-Generated Mocks&lt;/h4>
&lt;p>Here&amp;rsquo;s how our tests look with Mocktail-generated mocks:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">api&lt;/span>
&lt;span style="color:#f92672">import&lt;/span> (
&lt;span style="color:#e6db74">&amp;#34;bytes&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;encoding/json&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;errors&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;io&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;net/http&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;net/http/httptest&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;testing&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;github.com/stretchr/testify/assert&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;github.com/stretchr/testify/require&amp;#34;&lt;/span>
)
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">TestUserHandler_GetUser_WithMocktail&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Parallel&lt;/span>()
&lt;span style="color:#a6e22e">expectedUser&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">User&lt;/span>{&lt;span style="color:#a6e22e">ID&lt;/span>: &lt;span style="color:#ae81ff">123&lt;/span>, &lt;span style="color:#a6e22e">Name&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;Test User&amp;#34;&lt;/span>}
&lt;span style="color:#a6e22e">body&lt;/span>, &lt;span style="color:#a6e22e">_&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">Marshal&lt;/span>(&lt;span style="color:#a6e22e">expectedUser&lt;/span>)
&lt;span style="color:#75715e">// Create mock with Mocktail&amp;#39;s fluent API
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">mock&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">newHTTPClientMock&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span>).
&lt;span style="color:#a6e22e">OnDo&lt;/span>().&lt;span style="color:#a6e22e">TypedReturns&lt;/span>(&lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>{
&lt;span style="color:#a6e22e">StatusCode&lt;/span>: &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span>,
&lt;span style="color:#a6e22e">Body&lt;/span>: &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">NopCloser&lt;/span>(&lt;span style="color:#a6e22e">bytes&lt;/span>.&lt;span style="color:#a6e22e">NewReader&lt;/span>(&lt;span style="color:#a6e22e">body&lt;/span>)),
&lt;span style="color:#a6e22e">Header&lt;/span>: make(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>),
}, &lt;span style="color:#66d9ef">nil&lt;/span>).&lt;span style="color:#a6e22e">Once&lt;/span>()
&lt;span style="color:#a6e22e">handler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">mock&lt;/span>)
&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRequest&lt;/span>(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;/user&amp;#34;&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;span style="color:#a6e22e">rec&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRecorder&lt;/span>()
&lt;span style="color:#a6e22e">handler&lt;/span>.&lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">rec&lt;/span>, &lt;span style="color:#a6e22e">req&lt;/span>)
&lt;span style="color:#a6e22e">require&lt;/span>.&lt;span style="color:#a6e22e">Equal&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span>, &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span>, &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span>)
&lt;span style="color:#66d9ef">var&lt;/span> &lt;span style="color:#a6e22e">user&lt;/span> &lt;span style="color:#a6e22e">User&lt;/span>
&lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">NewDecoder&lt;/span>(&lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>).&lt;span style="color:#a6e22e">Decode&lt;/span>(&lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">user&lt;/span>)
&lt;span style="color:#a6e22e">assert&lt;/span>.&lt;span style="color:#a6e22e">Equal&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span>, &lt;span style="color:#a6e22e">expectedUser&lt;/span>.&lt;span style="color:#a6e22e">ID&lt;/span>, &lt;span style="color:#a6e22e">user&lt;/span>.&lt;span style="color:#a6e22e">ID&lt;/span>)
&lt;span style="color:#a6e22e">assert&lt;/span>.&lt;span style="color:#a6e22e">Equal&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span>, &lt;span style="color:#a6e22e">expectedUser&lt;/span>.&lt;span style="color:#a6e22e">Name&lt;/span>, &lt;span style="color:#a6e22e">user&lt;/span>.&lt;span style="color:#a6e22e">Name&lt;/span>)
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">TestUserHandler_GetUser_NetworkError_WithMocktail&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">T&lt;/span>) {
&lt;span style="color:#a6e22e">t&lt;/span>.&lt;span style="color:#a6e22e">Parallel&lt;/span>()
&lt;span style="color:#75715e">// Fluent syntax for error scenarios
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">mock&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">newHTTPClientMock&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span>).
&lt;span style="color:#a6e22e">OnDo&lt;/span>().&lt;span style="color:#a6e22e">TypedReturns&lt;/span>(&lt;span style="color:#66d9ef">nil&lt;/span>, &lt;span style="color:#a6e22e">errors&lt;/span>.&lt;span style="color:#a6e22e">New&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;connection refused&amp;#34;&lt;/span>)).&lt;span style="color:#a6e22e">Once&lt;/span>()
&lt;span style="color:#a6e22e">handler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">mock&lt;/span>)
&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRequest&lt;/span>(&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;/user&amp;#34;&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;span style="color:#a6e22e">rec&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httptest&lt;/span>.&lt;span style="color:#a6e22e">NewRecorder&lt;/span>()
&lt;span style="color:#a6e22e">handler&lt;/span>.&lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">rec&lt;/span>, &lt;span style="color:#a6e22e">req&lt;/span>)
&lt;span style="color:#a6e22e">assert&lt;/span>.&lt;span style="color:#a6e22e">Equal&lt;/span>(&lt;span style="color:#a6e22e">t&lt;/span>, &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusInternalServerError&lt;/span>, &lt;span style="color:#a6e22e">rec&lt;/span>.&lt;span style="color:#a6e22e">Code&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="why-mocktail-over-hand-written-mocks">Why Mocktail Over Hand-Written Mocks?&lt;/h4>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Aspect&lt;/th>
&lt;th>Hand-Written Mocks&lt;/th>
&lt;th>Mocktail&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Setup time&lt;/strong>&lt;/td>
&lt;td>Write struct + all methods&lt;/td>
&lt;td>One comment directive&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Type safety&lt;/strong>&lt;/td>
&lt;td>Manual, error-prone&lt;/td>
&lt;td>Compiler-enforced&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Refactoring&lt;/strong>&lt;/td>
&lt;td>Manual updates everywhere&lt;/td>
&lt;td>Regenerate, compiler catches breaks&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Fluent API&lt;/strong>&lt;/td>
&lt;td>DIY or nothing&lt;/td>
&lt;td>Built-in &lt;code>.OnMethod().TypedReturns().Once()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Assertions&lt;/strong>&lt;/td>
&lt;td>Manual call counting&lt;/td>
&lt;td>Automatic with &lt;code>testify/mock&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h4 id="the-generated-mock">The Generated Mock&lt;/h4>
&lt;p>Here&amp;rsquo;s what Mocktail generates for our &lt;code>HTTPClient&lt;/code> interface:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Code generated by mocktail; DO NOT EDIT.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#f92672">package&lt;/span> &lt;span style="color:#a6e22e">api&lt;/span>
&lt;span style="color:#f92672">import&lt;/span> (
&lt;span style="color:#e6db74">&amp;#34;net/http&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;testing&amp;#34;&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;github.com/stretchr/testify/mock&amp;#34;&lt;/span>
)
&lt;span style="color:#75715e">// httpClientMock mock of HTTPClient.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">httpClientMock&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span>{ &lt;span style="color:#a6e22e">mock&lt;/span>.&lt;span style="color:#a6e22e">Mock&lt;/span> }
&lt;span style="color:#75715e">// newHTTPClientMock creates a new httpClientMock.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">newHTTPClientMock&lt;/span>(&lt;span style="color:#a6e22e">tb&lt;/span> &lt;span style="color:#a6e22e">testing&lt;/span>.&lt;span style="color:#a6e22e">TB&lt;/span>) &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">httpClientMock&lt;/span> {
&lt;span style="color:#a6e22e">tb&lt;/span>.&lt;span style="color:#a6e22e">Helper&lt;/span>()
&lt;span style="color:#a6e22e">m&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">httpClientMock&lt;/span>{}
&lt;span style="color:#a6e22e">m&lt;/span>.&lt;span style="color:#a6e22e">Mock&lt;/span>.&lt;span style="color:#a6e22e">Test&lt;/span>(&lt;span style="color:#a6e22e">tb&lt;/span>)
&lt;span style="color:#a6e22e">tb&lt;/span>.&lt;span style="color:#a6e22e">Cleanup&lt;/span>(&lt;span style="color:#66d9ef">func&lt;/span>() { &lt;span style="color:#a6e22e">m&lt;/span>.&lt;span style="color:#a6e22e">AssertExpectations&lt;/span>(&lt;span style="color:#a6e22e">tb&lt;/span>) })
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">m&lt;/span>
}
&lt;span style="color:#75715e">// httpClientMockDo_Call is a method call on Do.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">httpClientMockDo_Call&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">mock&lt;/span>.&lt;span style="color:#a6e22e">Call&lt;/span>
&lt;span style="color:#a6e22e">Parent&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">httpClientMock&lt;/span>
}
&lt;span style="color:#75715e">// Do implements HTTPClient.Do.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">m&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">httpClientMock&lt;/span>) &lt;span style="color:#a6e22e">Do&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>) {
&lt;span style="color:#a6e22e">ret&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">m&lt;/span>.&lt;span style="color:#a6e22e">Called&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">ret&lt;/span>.&lt;span style="color:#a6e22e">Get&lt;/span>(&lt;span style="color:#ae81ff">0&lt;/span>).(&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>), &lt;span style="color:#a6e22e">ret&lt;/span>.&lt;span style="color:#a6e22e">Error&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>)
}
&lt;span style="color:#75715e">// OnDo sets up expectation for Do.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">m&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">httpClientMock&lt;/span>) &lt;span style="color:#a6e22e">OnDo&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">...&lt;/span>&lt;span style="color:#a6e22e">any&lt;/span>) &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">httpClientMockDo_Call&lt;/span> {
&lt;span style="color:#75715e">// ... expectation setup
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;span style="color:#75715e">// TypedReturns sets typed return values.
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">c&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">httpClientMockDo_Call&lt;/span>) &lt;span style="color:#a6e22e">TypedReturns&lt;/span>(&lt;span style="color:#a6e22e">resp&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#66d9ef">error&lt;/span>) &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">httpClientMockDo_Call&lt;/span> {
&lt;span style="color:#a6e22e">c&lt;/span>.&lt;span style="color:#a6e22e">Return&lt;/span>(&lt;span style="color:#a6e22e">resp&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">c&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>TypedReturns&lt;/code> has the same signature as the real method. Change &lt;code>Do&lt;/code>&amp;rsquo;s return type, regenerate, and the compiler tells you what broke. I&amp;rsquo;ve caught several bugs this way that would have shipped otherwise.&lt;/p>
&lt;h4 id="when-to-use-what">When to Use What&lt;/h4>
&lt;ul>
&lt;li>&lt;strong>Simple interfaces (1-2 methods)&lt;/strong>: Hand-written mocks are fine&lt;/li>
&lt;li>&lt;strong>Large interfaces or many mocks&lt;/strong>: Mocktail saves hours&lt;/li>
&lt;li>&lt;strong>Frequently changing interfaces&lt;/strong>: Mocktail&amp;rsquo;s type safety is invaluable&lt;/li>
&lt;li>&lt;strong>Team projects&lt;/strong>: Mocktail ensures consistency&lt;/li>
&lt;/ul>
&lt;p>Factory makes mocking possible. Mocktail removes the boilerplate.&lt;/p>
&lt;hr>
&lt;h2 id="real-scenarios-where-this-matters">Real Scenarios Where This Matters&lt;/h2>
&lt;p>Some cases I&amp;rsquo;ve actually dealt with:&lt;/p>
&lt;h3 id="scenario-1-multi-tenant-api">Scenario 1: Multi-Tenant API&lt;/h3>
&lt;p>You&amp;rsquo;re building a SaaS platform. Different tenants have different rate limits, different API endpoints, and different authentication tokens.&lt;/p>
&lt;p>&lt;strong>With Singleton:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Uh oh. ONE client for ALL tenants?
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">GetClient&lt;/span>()
&lt;span style="color:#75715e">// How do we set different headers per tenant?
&lt;/span>&lt;span style="color:#75715e">// How do we route to different endpoints?
&lt;/span>&lt;span style="color:#75715e">// Answer: We don&amp;#39;t. Not easily.
&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>With Factory:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Extended config for multi-tenant scenarios
&lt;/span>&lt;span style="color:#75715e">// (extends our base ClientConfig with tenant-specific fields)
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">TenantClientConfig&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">ClientConfig&lt;/span>
&lt;span style="color:#a6e22e">BaseURL&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>
&lt;span style="color:#a6e22e">Headers&lt;/span> &lt;span style="color:#66d9ef">map&lt;/span>[&lt;span style="color:#66d9ef">string&lt;/span>]&lt;span style="color:#66d9ef">string&lt;/span>
}
&lt;span style="color:#75715e">// Each tenant gets its own configured client!
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewTenantClient&lt;/span>(&lt;span style="color:#a6e22e">tenant&lt;/span> &lt;span style="color:#a6e22e">Tenant&lt;/span>) &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">HTTPClient&lt;/span> {
&lt;span style="color:#a6e22e">cfg&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">TenantClientConfig&lt;/span>{
&lt;span style="color:#a6e22e">ClientConfig&lt;/span>: &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">ClientConfig&lt;/span>{
&lt;span style="color:#a6e22e">Timeout&lt;/span>: &lt;span style="color:#a6e22e">tenant&lt;/span>.&lt;span style="color:#a6e22e">TimeoutConfig&lt;/span>,
&lt;span style="color:#a6e22e">MaxIdleConns&lt;/span>: &lt;span style="color:#ae81ff">100&lt;/span>,
&lt;span style="color:#a6e22e">MaxIdleConnsPerHost&lt;/span>: &lt;span style="color:#ae81ff">10&lt;/span>,
&lt;span style="color:#a6e22e">IdleConnTimeout&lt;/span>: &lt;span style="color:#ae81ff">90&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#a6e22e">time&lt;/span>.&lt;span style="color:#a6e22e">Second&lt;/span>,
},
&lt;span style="color:#a6e22e">BaseURL&lt;/span>: &lt;span style="color:#a6e22e">tenant&lt;/span>.&lt;span style="color:#a6e22e">APIEndpoint&lt;/span>,
&lt;span style="color:#a6e22e">Headers&lt;/span>: &lt;span style="color:#66d9ef">map&lt;/span>[&lt;span style="color:#66d9ef">string&lt;/span>]&lt;span style="color:#66d9ef">string&lt;/span>{
&lt;span style="color:#e6db74">&amp;#34;Authorization&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;Bearer &amp;#34;&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#a6e22e">tenant&lt;/span>.&lt;span style="color:#a6e22e">APIToken&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;X-Tenant-ID&amp;#34;&lt;/span>: &lt;span style="color:#a6e22e">tenant&lt;/span>.&lt;span style="color:#a6e22e">ID&lt;/span>,
},
}
&lt;span style="color:#75715e">// In practice, you&amp;#39;d use cfg.BaseURL and cfg.Headers
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// in a custom RoundTripper or wrapper
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">NewClient&lt;/span>(&lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">ClientConfig&lt;/span>)
}
&lt;span style="color:#75715e">// In your handler factory
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">tenant&lt;/span> &lt;span style="color:#a6e22e">Tenant&lt;/span>) &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span> {
&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewTenantClient&lt;/span>(&lt;span style="color:#a6e22e">tenant&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span>{&lt;span style="color:#a6e22e">client&lt;/span>: &lt;span style="color:#a6e22e">client&lt;/span>}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="scenario-2-rate-limited-external-api">Scenario 2: Rate-Limited External API&lt;/h3>
&lt;p>You&amp;rsquo;re calling an external API with rate limits. You need different backoff strategies for different endpoints.&lt;/p>
&lt;p>&lt;strong>With Singleton:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// One rate limiter for the entire application?
&lt;/span>&lt;span style="color:#75715e">// What if /users allows 100 req/s but /payments only allows 10 req/s?
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">GetClient&lt;/span>()
&lt;span style="color:#75715e">// You&amp;#39;d need to wrap EVERY call with custom rate limiting logic.
&lt;/span>&lt;span style="color:#75715e">// That&amp;#39;s not encapsulation, that&amp;#39;s a nightmare.
&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>With Factory:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Rate-limited client factory
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewRateLimitedClient&lt;/span>(&lt;span style="color:#a6e22e">rps&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>, &lt;span style="color:#a6e22e">burst&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>) &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">HTTPClient&lt;/span> {
&lt;span style="color:#a6e22e">limiter&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">rate&lt;/span>.&lt;span style="color:#a6e22e">NewLimiter&lt;/span>(&lt;span style="color:#a6e22e">rate&lt;/span>.&lt;span style="color:#a6e22e">Limit&lt;/span>(&lt;span style="color:#a6e22e">rps&lt;/span>), &lt;span style="color:#a6e22e">burst&lt;/span>)
&lt;span style="color:#a6e22e">baseClient&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">NewClient&lt;/span>(&lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">DefaultConfig&lt;/span>())
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">RateLimitedClient&lt;/span>{
&lt;span style="color:#a6e22e">client&lt;/span>: &lt;span style="color:#a6e22e">baseClient&lt;/span>,
&lt;span style="color:#a6e22e">limiter&lt;/span>: &lt;span style="color:#a6e22e">limiter&lt;/span>,
}
}
&lt;span style="color:#75715e">// Create specialized clients
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#a6e22e">usersClient&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewRateLimitedClient&lt;/span>(&lt;span style="color:#ae81ff">100&lt;/span>, &lt;span style="color:#ae81ff">150&lt;/span>) &lt;span style="color:#75715e">// High throughput
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#a6e22e">paymentsClient&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewRateLimitedClient&lt;/span>(&lt;span style="color:#ae81ff">10&lt;/span>, &lt;span style="color:#ae81ff">15&lt;/span>) &lt;span style="color:#75715e">// Conservative
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#a6e22e">userHandler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">usersClient&lt;/span>)
&lt;span style="color:#a6e22e">paymentHandler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewPaymentHandler&lt;/span>(&lt;span style="color:#a6e22e">paymentsClient&lt;/span>)
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="scenario-3-feature-flags">Scenario 3: Feature Flags&lt;/h3>
&lt;p>You want to gradually roll out a new HTTP/2 transport.&lt;/p>
&lt;p>&lt;strong>With Singleton:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Change the singleton = change for EVERYONE
&lt;/span>&lt;span style="color:#75715e">// No gradual rollout, no A/B testing, no easy rollback
&lt;/span>&lt;span style="color:#75715e">// Hope your prayers are answered!
&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>With Factory:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">import&lt;/span> &lt;span style="color:#e6db74">&amp;#34;golang.org/x/net/http2&amp;#34;&lt;/span> &lt;span style="color:#75715e">// Required for HTTP/2 support
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewClientWithHTTP2&lt;/span>(&lt;span style="color:#a6e22e">cfg&lt;/span> &lt;span style="color:#a6e22e">ClientConfig&lt;/span>, &lt;span style="color:#a6e22e">enableHTTP2&lt;/span> &lt;span style="color:#66d9ef">bool&lt;/span>) &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">HTTPClient&lt;/span> {
&lt;span style="color:#a6e22e">transport&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Transport&lt;/span>{
&lt;span style="color:#a6e22e">MaxIdleConns&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">MaxIdleConns&lt;/span>,
&lt;span style="color:#a6e22e">MaxIdleConnsPerHost&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">MaxIdleConnsPerHost&lt;/span>,
&lt;span style="color:#a6e22e">IdleConnTimeout&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">IdleConnTimeout&lt;/span>,
}
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">enableHTTP2&lt;/span> {
&lt;span style="color:#75715e">// Configure transport for HTTP/2 support
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">http2&lt;/span>.&lt;span style="color:#a6e22e">ConfigureTransport&lt;/span>(&lt;span style="color:#a6e22e">transport&lt;/span>)
}
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Client&lt;/span>{
&lt;span style="color:#a6e22e">Timeout&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">Timeout&lt;/span>,
&lt;span style="color:#a6e22e">Transport&lt;/span>: &lt;span style="color:#a6e22e">transport&lt;/span>,
}
}
&lt;span style="color:#75715e">// In your main.go or DI container
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">setupClients&lt;/span>(&lt;span style="color:#a6e22e">featureFlags&lt;/span> &lt;span style="color:#a6e22e">FeatureFlags&lt;/span>, &lt;span style="color:#a6e22e">userID&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>, &lt;span style="color:#a6e22e">config&lt;/span> &lt;span style="color:#a6e22e">ClientConfig&lt;/span>) &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">HTTPClient&lt;/span> {
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">featureFlags&lt;/span>.&lt;span style="color:#a6e22e">IsEnabled&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;http2_rollout&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">userID&lt;/span>) {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">NewClientWithHTTP2&lt;/span>(&lt;span style="color:#a6e22e">config&lt;/span>, &lt;span style="color:#66d9ef">true&lt;/span>)
}
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">NewClientWithHTTP2&lt;/span>(&lt;span style="color:#a6e22e">config&lt;/span>, &lt;span style="color:#66d9ef">false&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;hr>
&lt;h2 id="the-trade-offs">The Trade-offs&lt;/h2>
&lt;p>Here&amp;rsquo;s how they compare:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Aspect&lt;/th>
&lt;th>Singleton&lt;/th>
&lt;th>Factory&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Testability&lt;/strong>&lt;/td>
&lt;td>Hard to mock, no parallel tests&lt;/td>
&lt;td>Easy mocks, parallel-safe&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Flexibility&lt;/strong>&lt;/td>
&lt;td>One config for all&lt;/td>
&lt;td>Different configs per use case&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Concurrency&lt;/strong>&lt;/td>
&lt;td>Shared state = potential races&lt;/td>
&lt;td>Isolated instances = safe&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Dependencies&lt;/strong>&lt;/td>
&lt;td>Hidden (global access)&lt;/td>
&lt;td>Explicit (injected)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Multi-tenancy&lt;/strong>&lt;/td>
&lt;td>Very difficult&lt;/td>
&lt;td>Natural fit&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Feature flags&lt;/strong>&lt;/td>
&lt;td>All or nothing&lt;/td>
&lt;td>Per-instance control&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Debugging&lt;/strong>&lt;/td>
&lt;td>&amp;ldquo;Which code path set this?&amp;rdquo;&lt;/td>
&lt;td>Clear dependency chain&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="when-singleton-actually-makes-sense">When Singleton Actually Makes Sense&lt;/h3>
&lt;p>To be fair, Singleton isn&amp;rsquo;t always wrong:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>True singletons&lt;/strong>: There really can only be one (e.g., a process-wide metrics registry)&lt;/li>
&lt;li>&lt;strong>Immutable configuration&lt;/strong>: Loaded once at startup, never changed&lt;/li>
&lt;li>&lt;strong>Resource pools&lt;/strong>: Connection pools where you explicitly WANT sharing&lt;/li>
&lt;li>&lt;strong>Logging&lt;/strong>: Usually fine as a singleton (but consider structured logging with context)&lt;/li>
&lt;/ul>
&lt;p>The question I ask myself: &amp;ldquo;Will I ever need different behavior in different contexts?&amp;rdquo; If there&amp;rsquo;s any chance the answer is yes, Factory. If it&amp;rsquo;s truly global and immutable, Singleton might be fine.&lt;/p>
&lt;p>In practice, I default to Factory and only reach for Singleton when I have a specific reason.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Default approach: Factory + Dependency Injection
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">Server&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">userHandler&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span>
&lt;span style="color:#a6e22e">paymentHandler&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">PaymentHandler&lt;/span>
&lt;span style="color:#a6e22e">healthHandler&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">HealthHandler&lt;/span>
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewServer&lt;/span>(&lt;span style="color:#a6e22e">cfg&lt;/span> &lt;span style="color:#a6e22e">Config&lt;/span>) &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Server&lt;/span> {
&lt;span style="color:#75715e">// Create clients with factory functions
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">apiClient&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">NewClient&lt;/span>(&lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">APIClientConfig&lt;/span>)
&lt;span style="color:#a6e22e">paymentClient&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">NewClient&lt;/span>(&lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">PaymentClientConfig&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">Server&lt;/span>{
&lt;span style="color:#a6e22e">userHandler&lt;/span>: &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">apiClient&lt;/span>),
&lt;span style="color:#a6e22e">paymentHandler&lt;/span>: &lt;span style="color:#a6e22e">NewPaymentHandler&lt;/span>(&lt;span style="color:#a6e22e">paymentClient&lt;/span>),
&lt;span style="color:#a6e22e">healthHandler&lt;/span>: &lt;span style="color:#a6e22e">NewHealthHandler&lt;/span>(),
}
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;span style="color:#a6e22e">cfg&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">LoadConfig&lt;/span>()
&lt;span style="color:#a6e22e">server&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewServer&lt;/span>(&lt;span style="color:#a6e22e">cfg&lt;/span>)
&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">ListenAndServe&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;:8080&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">server&lt;/span>.&lt;span style="color:#a6e22e">Router&lt;/span>())
}
&lt;/code>&lt;/pre>&lt;/div>&lt;hr>
&lt;h2 id="migrating-from-singleton-to-factory">Migrating from Singleton to Factory&lt;/h2>
&lt;p>If you&amp;rsquo;re stuck with a singleton-heavy codebase (I&amp;rsquo;ve been there), here&amp;rsquo;s how to migrate incrementally:&lt;/p>
&lt;h3 id="step-1-define-an-interface">Step 1: Define an Interface&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Before: direct use of *http.Client
&lt;/span>&lt;span style="color:#75715e">// After: interface that *http.Client already implements
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">HTTPClient&lt;/span> &lt;span style="color:#66d9ef">interface&lt;/span> {
&lt;span style="color:#a6e22e">Do&lt;/span>(&lt;span style="color:#a6e22e">req&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) (&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>, &lt;span style="color:#66d9ef">error&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="step-2-create-a-factory-function">Step 2: Create a Factory Function&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewHTTPClient&lt;/span>(&lt;span style="color:#a6e22e">cfg&lt;/span> &lt;span style="color:#a6e22e">Config&lt;/span>) &lt;span style="color:#a6e22e">HTTPClient&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Client&lt;/span>{
&lt;span style="color:#a6e22e">Timeout&lt;/span>: &lt;span style="color:#a6e22e">cfg&lt;/span>.&lt;span style="color:#a6e22e">Timeout&lt;/span>,
&lt;span style="color:#75715e">// ... configuration
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="step-3-update-handlers-to-accept-dependencies">Step 3: Update Handlers to Accept Dependencies&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Before
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">UserHandler&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span>{}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">h&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span>) &lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">ResponseWriter&lt;/span>, &lt;span style="color:#a6e22e">r&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) {
&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">GetClient&lt;/span>() &lt;span style="color:#75715e">// Singleton!
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// ...
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;span style="color:#75715e">// After
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">UserHandler&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#a6e22e">HTTPClient&lt;/span>
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#a6e22e">HTTPClient&lt;/span>) &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span>{&lt;span style="color:#a6e22e">client&lt;/span>: &lt;span style="color:#a6e22e">client&lt;/span>}
}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">h&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">UserHandler&lt;/span>) &lt;span style="color:#a6e22e">GetUser&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">ResponseWriter&lt;/span>, &lt;span style="color:#a6e22e">r&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">Request&lt;/span>) {
&lt;span style="color:#75715e">// Use h.client instead of global
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="step-4-wire-everything-in-main">Step 4: Wire Everything in main()&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">httpclient&lt;/span>.&lt;span style="color:#a6e22e">NewHTTPClient&lt;/span>(&lt;span style="color:#a6e22e">config&lt;/span>)
&lt;span style="color:#a6e22e">userHandler&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">api&lt;/span>.&lt;span style="color:#a6e22e">NewUserHandler&lt;/span>(&lt;span style="color:#a6e22e">client&lt;/span>)
&lt;span style="color:#75715e">// ... register routes
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;hr>
&lt;h2 id="interactive-example">Interactive Example&lt;/h2>
&lt;p>If you want to play with the concepts, here&amp;rsquo;s a simplified version:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">import&lt;/span> &lt;span style="color:#e6db74">&amp;#34;fmt&amp;#34;&lt;/span>
&lt;span style="color:#75715e">// HTTPClient interface - the contract
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">HTTPClient&lt;/span> &lt;span style="color:#66d9ef">interface&lt;/span> {
&lt;span style="color:#a6e22e">Get&lt;/span>(&lt;span style="color:#a6e22e">url&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>) &lt;span style="color:#66d9ef">string&lt;/span>
}
&lt;span style="color:#75715e">// RealClient - production implementation
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">RealClient&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span>{}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">c&lt;/span> &lt;span style="color:#a6e22e">RealClient&lt;/span>) &lt;span style="color:#a6e22e">Get&lt;/span>(&lt;span style="color:#a6e22e">url&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>) &lt;span style="color:#66d9ef">string&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#e6db74">&amp;#34;Real response from: &amp;#34;&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#a6e22e">url&lt;/span>
}
&lt;span style="color:#75715e">// MockClient - test implementation
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">MockClient&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">Response&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>
}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">c&lt;/span> &lt;span style="color:#a6e22e">MockClient&lt;/span>) &lt;span style="color:#a6e22e">Get&lt;/span>(&lt;span style="color:#a6e22e">url&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>) &lt;span style="color:#66d9ef">string&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">c&lt;/span>.&lt;span style="color:#a6e22e">Response&lt;/span>
}
&lt;span style="color:#75715e">// UserService depends on HTTPClient interface
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">UserService&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">client&lt;/span> &lt;span style="color:#a6e22e">HTTPClient&lt;/span>
}
&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">s&lt;/span> &lt;span style="color:#a6e22e">UserService&lt;/span>) &lt;span style="color:#a6e22e">FetchUser&lt;/span>(&lt;span style="color:#a6e22e">id&lt;/span> &lt;span style="color:#66d9ef">string&lt;/span>) &lt;span style="color:#66d9ef">string&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">s&lt;/span>.&lt;span style="color:#a6e22e">client&lt;/span>.&lt;span style="color:#a6e22e">Get&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;https://api.example.com/users/&amp;#34;&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#a6e22e">id&lt;/span>)
}
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;span style="color:#75715e">// Production: use real client
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">realService&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">UserService&lt;/span>{&lt;span style="color:#a6e22e">client&lt;/span>: &lt;span style="color:#a6e22e">RealClient&lt;/span>{}}
&lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Println&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;Production:&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">realService&lt;/span>.&lt;span style="color:#a6e22e">FetchUser&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;123&amp;#34;&lt;/span>))
&lt;span style="color:#75715e">// Testing: use mock client
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">mockService&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">UserService&lt;/span>{&lt;span style="color:#a6e22e">client&lt;/span>: &lt;span style="color:#a6e22e">MockClient&lt;/span>{&lt;span style="color:#a6e22e">Response&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;Mocked User Data&amp;#34;&lt;/span>}}
&lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Println&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;Test:&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">mockService&lt;/span>.&lt;span style="color:#a6e22e">FetchUser&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;123&amp;#34;&lt;/span>))
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>UserService&lt;/code> doesn&amp;rsquo;t care which client it gets. That&amp;rsquo;s the point.&lt;/p>
&lt;hr>
&lt;h2 id="production-hardening">Production Hardening&lt;/h2>
&lt;p>Some things I&amp;rsquo;ve learned from production incidents:&lt;/p>
&lt;h3 id="1-always-limit-response-body-size">1. Always Limit Response Body Size&lt;/h3>
&lt;p>A malicious or misbehaving upstream API could send gigabytes of data. Protect yourself:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">const&lt;/span> &lt;span style="color:#a6e22e">maxResponseBodySize&lt;/span> = &lt;span style="color:#ae81ff">1&lt;/span> &lt;span style="color:#f92672">&amp;lt;&amp;lt;&lt;/span> &lt;span style="color:#ae81ff">20&lt;/span> &lt;span style="color:#75715e">// 1MB
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#75715e">// Always wrap response body reading
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#a6e22e">limitedBody&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">LimitReader&lt;/span>(&lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>, &lt;span style="color:#a6e22e">maxResponseBodySize&lt;/span>)
&lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">NewDecoder&lt;/span>(&lt;span style="color:#a6e22e">limitedBody&lt;/span>).&lt;span style="color:#a6e22e">Decode&lt;/span>(&lt;span style="color:#f92672">&amp;amp;&lt;/span>&lt;span style="color:#a6e22e">result&lt;/span>)
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-propagate-context-for-cancellation">2. Propagate Context for Cancellation&lt;/h3>
&lt;p>If a client disconnects, you don&amp;rsquo;t want to waste resources completing their request:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Use the incoming request&amp;#39;s context
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#a6e22e">req&lt;/span>, &lt;span style="color:#a6e22e">err&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">NewRequestWithContext&lt;/span>(&lt;span style="color:#a6e22e">r&lt;/span>.&lt;span style="color:#a6e22e">Context&lt;/span>(), &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">MethodGet&lt;/span>, &lt;span style="color:#a6e22e">url&lt;/span>, &lt;span style="color:#66d9ef">nil&lt;/span>)
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-drain-response-bodies-for-connection-reuse">3. Drain Response Bodies for Connection Reuse&lt;/h3>
&lt;p>HTTP/1.1 connections can only be reused if the response body is fully read:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">defer&lt;/span> &lt;span style="color:#66d9ef">func&lt;/span>() {
&lt;span style="color:#75715e">// Drain remaining body to allow connection reuse
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">Copy&lt;/span>(&lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">Discard&lt;/span>, &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">LimitReader&lt;/span>(&lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>, &lt;span style="color:#a6e22e">maxResponseBodySize&lt;/span>))
&lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>.&lt;span style="color:#a6e22e">Close&lt;/span>()
}()
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="4-check-status-codes-before-processing">4. Check Status Codes Before Processing&lt;/h3>
&lt;p>Don&amp;rsquo;t waste CPU decoding error responses as valid data:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">StatusCode&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">http&lt;/span>.&lt;span style="color:#a6e22e">StatusOK&lt;/span> {
&lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">Copy&lt;/span>(&lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">Discard&lt;/span>, &lt;span style="color:#a6e22e">io&lt;/span>.&lt;span style="color:#a6e22e">LimitReader&lt;/span>(&lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">Body&lt;/span>, &lt;span style="color:#a6e22e">maxResponseBodySize&lt;/span>))
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#66d9ef">nil&lt;/span>, &lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Errorf&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;upstream API returned %d&amp;#34;&lt;/span>, &lt;span style="color:#a6e22e">resp&lt;/span>.&lt;span style="color:#a6e22e">StatusCode&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="5-set-content-type-headers">5. Set Content-Type Headers&lt;/h3>
&lt;p>Be explicit about what you&amp;rsquo;re returning:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#a6e22e">w&lt;/span>.&lt;span style="color:#a6e22e">Header&lt;/span>().&lt;span style="color:#a6e22e">Set&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;Content-Type&amp;#34;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;application/json&amp;#34;&lt;/span>)
&lt;span style="color:#a6e22e">json&lt;/span>.&lt;span style="color:#a6e22e">NewEncoder&lt;/span>(&lt;span style="color:#a6e22e">w&lt;/span>).&lt;span style="color:#a6e22e">Encode&lt;/span>(&lt;span style="color:#a6e22e">result&lt;/span>)
&lt;/code>&lt;/pre>&lt;/div>&lt;hr>
&lt;h2 id="wrapping-up">Wrapping Up&lt;/h2>
&lt;p>Factory adds some boilerplate. About 40-50 lines for a typical HTTP client setup. In exchange, you get testable code, flexible configuration, and fewer 3 AM incidents.&lt;/p>
&lt;p>Singleton isn&amp;rsquo;t evil. It&amp;rsquo;s just overused. Most HTTP clients don&amp;rsquo;t need to be singletons, and the ones that do are rarer than you&amp;rsquo;d think.&lt;/p>
&lt;p>Next time you&amp;rsquo;re about to write &lt;code>var instance *http.Client&lt;/code> with &lt;code>sync.Once&lt;/code>, ask yourself if you&amp;rsquo;ll ever need to mock it, configure it differently, or debug it in production. If the answer to any of those is &amp;ldquo;maybe,&amp;rdquo; use a factory.&lt;/p>
&lt;hr>
&lt;p>&lt;em>If you spot a bug in the examples or want to argue that Singleton is fine, find me on &lt;a href="https://github.com/tommoulard">GitHub&lt;/a>.&lt;/em>&lt;/p></description></item><item><title>🤖 Workflow Sub-Agentique avec OpenCode : Quand l'IA Orchestre l'IA</title><link>https://blog.moulard.org/subagentic-workflow-opencode/</link><pubDate>Fri, 28 Nov 2025 00:00:00 +0200</pubDate><guid>https://blog.moulard.org/subagentic-workflow-opencode/</guid><comments>https://blog.moulard.org/subagentic-workflow-opencode/#disqus_thread</comments><description>&lt;h1 id="-méta-inception--un-blog-post-sur-un-workflow-dia-créé-par-ce-même-workflow">🎭 Méta-inception : Un blog post sur un workflow d&amp;rsquo;IA, créé par ce même workflow&lt;/h1>
&lt;p>Bienvenue dans le monde fascinant des &lt;strong>workflows sub-agentiques&lt;/strong> ! Aujourd&amp;rsquo;hui, je vais vous parler d&amp;rsquo;un système d&amp;rsquo;orchestration d&amp;rsquo;IA que j&amp;rsquo;ai mis en place avec OpenCode. Et la cerise sur le gâteau ? Ce blog post a lui-même été créé en utilisant ce workflow. (Inception niveau : Christopher Nolan serait fier, ou complètement perdu. Probablement les deux.)&lt;/p>
&lt;h2 id="-le-problème--lia-fait-du-code-mais-qui-vérifie-lia-">🧠 Le Problème : L&amp;rsquo;IA Fait du Code, Mais Qui Vérifie l&amp;rsquo;IA ?&lt;/h2>
&lt;p>Vous avez déjà utilisé une IA pour générer du code ? C&amp;rsquo;est magique&amp;hellip; jusqu&amp;rsquo;à ce que vous découvriez qu&amp;rsquo;elle a oublié la gestion d&amp;rsquo;erreurs, créé une faille de sécurité, ou écrit un algorithme en O(n³) alors qu&amp;rsquo;il existe une solution en O(n). (Spoiler : ça arrive plus souvent qu&amp;rsquo;on ne le voudrait.)&lt;/p>
&lt;p>Le défi n&amp;rsquo;est pas de générer du code rapidement. C&amp;rsquo;est de générer du &lt;strong>code de qualité&lt;/strong> qui respecte :&lt;/p>
&lt;ul>
&lt;li>✅ Les bonnes pratiques (SOLID, DRY, KISS)&lt;/li>
&lt;li>✅ La gestion d&amp;rsquo;erreurs complète&lt;/li>
&lt;li>✅ Les performances optimales&lt;/li>
&lt;li>✅ La sécurité&lt;/li>
&lt;li>✅ Le style du projet existant&lt;/li>
&lt;li>✅ Les edge cases&lt;/li>
&lt;/ul>
&lt;p>C&amp;rsquo;est là qu&amp;rsquo;intervient le &lt;strong>workflow sub-agentique&lt;/strong>.&lt;/p>
&lt;h2 id="-la-solution--une-équipe-dia-spécialisées">🎯 La Solution : Une Équipe d&amp;rsquo;IA Spécialisées&lt;/h2>
&lt;p>Au lieu d&amp;rsquo;avoir une seule IA qui fait tout (et donc rien parfaitement), mon workflow OpenCode orchestre &lt;strong>plusieurs agents spécialisés&lt;/strong> qui travaillent ensemble :&lt;/p>
&lt;pre>&lt;code>User Request
↓
[@prompt-engineer] ← Améliore la demande
↓
[Main Agent] ← Génère le code
↓
[Triple Review Parallèle] ← 3 experts simultanés
├─ @code-quality-reviewer (Architecture &amp;amp; Best Practices)
├─ @error-analyzer (Bugs &amp;amp; Logic Errors)
└─ @performance-analyzer (Performance &amp;amp; Scalability)
↓
[Issues Critiques?]
├─ Oui → Feedback Loop (max 5 itérations)
└─ Non → Success! 🎉
↓
[@test-engineer] ← Tests (si nouveau code)
↓
[@documenter] ← Documentation (si API publique)
&lt;/code>&lt;/pre>&lt;h2 id="-les-agents--qui-fait-quoi-">🔧 Les Agents : Qui Fait Quoi ?&lt;/h2>
&lt;h3 id="1-prompt-engineer--le-traducteur-expert">1️⃣ &lt;strong>@prompt-engineer&lt;/strong> : Le Traducteur Expert&lt;/h3>
&lt;p>&lt;strong>Rôle&lt;/strong> : Transformer vos demandes vagues en instructions ultra-précises.&lt;/p>
&lt;p>&lt;strong>Exemple&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Vous&lt;/strong> : &amp;ldquo;Ajoute de l&amp;rsquo;authentification&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>@prompt-engineer&lt;/strong> : &amp;ldquo;Implémente une authentification JWT avec :
&lt;ul>
&lt;li>Stockage sécurisé dans httpOnly cookies&lt;/li>
&lt;li>Protection CSRF&lt;/li>
&lt;li>Rate limiting (10 req/min)&lt;/li>
&lt;li>Gestion d&amp;rsquo;erreurs complète&lt;/li>
&lt;li>Logging des tentatives échouées&lt;/li>
&lt;li>Tests unitaires pour chaque endpoint&lt;/li>
&lt;li>Documentation OpenAPI&lt;/li>
&lt;li>Respect des patterns existants du projet&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>C&amp;rsquo;est comme avoir un chef de projet qui reformule vos idées floues en spécifications techniques béton. (Sans les réunions interminables et les PowerPoints inutiles.)&lt;/p>
&lt;h3 id="2-code-quality-reviewer--le-perfectionniste">2️⃣ &lt;strong>@code-quality-reviewer&lt;/strong> : Le Perfectionniste&lt;/h3>
&lt;p>&lt;strong>Rôle&lt;/strong> : Vérifier l&amp;rsquo;architecture, le style, et les bonnes pratiques.&lt;/p>
&lt;p>&lt;strong>Il détecte&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>Violations de SOLID&lt;/li>
&lt;li>Code dupliqué (DRY)&lt;/li>
&lt;li>Complexité excessive (KISS)&lt;/li>
&lt;li>Inconsistances de style&lt;/li>
&lt;li>Architecture bancale&lt;/li>
&lt;li>Vulnérabilités de sécurité&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Niveau de sévérité&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>🔴 &lt;strong>CRITICAL&lt;/strong> : Faille de sécurité, perte de données → Déclenche une nouvelle itération&lt;/li>
&lt;li>🟠 &lt;strong>IMPORTANT&lt;/strong> : Performance, edge cases → Correction directe si simple&lt;/li>
&lt;li>🟡 &lt;strong>MINOR&lt;/strong> : Style, suggestions → Noté mais pas bloquant&lt;/li>
&lt;/ul>
&lt;h3 id="3-error-analyzer--le-paranoïaque-dans-le-bon-sens">3️⃣ &lt;strong>@error-analyzer&lt;/strong> : Le Paranoïaque (dans le bon sens)&lt;/h3>
&lt;p>&lt;strong>Rôle&lt;/strong> : Traquer les bugs potentiels et les erreurs de logique.&lt;/p>
&lt;p>&lt;strong>Il détecte&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>Exceptions non gérées&lt;/li>
&lt;li>Null pointer dereference&lt;/li>
&lt;li>Race conditions&lt;/li>
&lt;li>Memory leaks&lt;/li>
&lt;li>Boucles infinies&lt;/li>
&lt;li>Erreurs de calcul&lt;/li>
&lt;li>Type safety violations&lt;/li>
&lt;li>Off-by-one errors&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Mentalité&lt;/strong> : &amp;ldquo;Si ça peut crasher, ça va crasher. Mon job est de trouver comment avant que ça arrive en production.&amp;rdquo; (Et croyez-moi, il est très bon à son job.)&lt;/p>
&lt;h3 id="4-performance-analyzer--loptimiseur">4️⃣ &lt;strong>@performance-analyzer&lt;/strong> : L&amp;rsquo;Optimiseur&lt;/h3>
&lt;p>&lt;strong>Rôle&lt;/strong> : Identifier les goulots d&amp;rsquo;étranglement et problèmes de scalabilité.&lt;/p>
&lt;p>&lt;strong>Il détecte&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>Complexité algorithmique O(n²)+&lt;/li>
&lt;li>Problèmes N+1 (requêtes en boucle)&lt;/li>
&lt;li>Opérations bloquantes&lt;/li>
&lt;li>Fuites mémoire&lt;/li>
&lt;li>Queries sans index&lt;/li>
&lt;li>Cache mal utilisé&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Philosophie&lt;/strong> : &amp;ldquo;Ton code marche ? Super. Maintenant faisons-le marcher pour 10 millions d&amp;rsquo;utilisateurs.&amp;rdquo;&lt;/p>
&lt;h3 id="5-test-engineer--le-sceptique-professionnel">5️⃣ &lt;strong>@test-engineer&lt;/strong> : Le Sceptique Professionnel&lt;/h3>
&lt;p>&lt;strong>Rôle&lt;/strong> : Générer des tests complets pour le nouveau code.&lt;/p>
&lt;p>&lt;strong>Il crée&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>Tests unitaires&lt;/li>
&lt;li>Tests d&amp;rsquo;intégration&lt;/li>
&lt;li>Tests edge cases&lt;/li>
&lt;li>Tests de régression&lt;/li>
&lt;li>Mocks et fixtures appropriés&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Déclenché&lt;/strong> : Seulement pour les nouvelles fonctionnalités ou changements logiques importants. (Pas besoin de tester un typo fixé.)&lt;/p>
&lt;h3 id="6-documenter--le-communicateur">6️⃣ &lt;strong>@documenter&lt;/strong> : Le Communicateur&lt;/h3>
&lt;p>&lt;strong>Rôle&lt;/strong> : Documenter les features complexes et APIs publiques.&lt;/p>
&lt;p>&lt;strong>Il génère&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>Documentation technique&lt;/li>
&lt;li>Guides d&amp;rsquo;utilisation&lt;/li>
&lt;li>Exemples de code&lt;/li>
&lt;li>Diagrammes d&amp;rsquo;architecture&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Déclenché&lt;/strong> : Pour les APIs publiques ou fonctionnalités complexes.&lt;/p>
&lt;h2 id="-le-feedback-loop--litération-intelligente">🔄 Le Feedback Loop : L&amp;rsquo;Itération Intelligente&lt;/h2>
&lt;p>Voici où ça devient intéressant. Si les reviewers trouvent des &lt;strong>problèmes critiques&lt;/strong>, le système ne se contente pas de vous les signaler. Il &lt;strong>re-déclenche automatiquement&lt;/strong> le workflow avec le feedback :&lt;/p>
&lt;p>&lt;strong>Itération 1&lt;/strong> :&lt;/p>
&lt;pre>&lt;code>User: &amp;quot;Ajoute l'authentification&amp;quot;
→ Code généré avec tokens en localStorage
→ @code-quality-reviewer: &amp;quot;🔴 CRITICAL: Vulnérable aux attaques XSS&amp;quot;
→ Feedback Loop activé!
&lt;/code>&lt;/pre>&lt;p>&lt;strong>Itération 2&lt;/strong> :&lt;/p>
&lt;pre>&lt;code>@prompt-engineer reçoit le feedback détaillé
→ Nouveau prompt avec emphase sur httpOnly cookies
→ Code généré avec cookies sécurisés
→ @code-quality-reviewer: &amp;quot;🟠 IMPORTANT: Rate limiting manquant&amp;quot;
→ Pas critique, correction directe
→ Success! ✅
&lt;/code>&lt;/pre>&lt;p>&lt;strong>Limites de sécurité&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>Maximum &lt;strong>5 itérations&lt;/strong> pour éviter les boucles infinies&lt;/li>
&lt;li>Détection de convergence (si même erreur 2 fois → escalade à l&amp;rsquo;humain)&lt;/li>
&lt;li>Priorisation : erreurs runtime &amp;gt; performance &amp;gt; style&lt;/li>
&lt;/ul>
&lt;h2 id="-gestion-du-contexte--le-défi-majeur">🎪 Gestion du Contexte : Le Défi Majeur&lt;/h2>
&lt;p>Voici un piège subtil mais crucial : &lt;strong>les sub-agents opèrent en sessions isolées&lt;/strong>. Ils n&amp;rsquo;ont accès à :&lt;/p>
&lt;ul>
&lt;li>❌ L&amp;rsquo;historique de conversation&lt;/li>
&lt;li>❌ Les fichiers que vous avez lus&lt;/li>
&lt;li>❌ Le code que vous venez de générer&lt;/li>
&lt;li>❌ Vos réflexions internes&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Donc chaque invocation doit être 100% auto-suffisante&lt;/strong> :&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-python" data-lang="python">&lt;span style="color:#75715e"># ❌ MAUVAIS&lt;/span>
invoke_reviewer(&lt;span style="color:#e6db74">&amp;#34;Revise le code dans src/auth.js&amp;#34;&lt;/span>)
&lt;span style="color:#75715e"># ✅ BON &lt;/span>
invoke_reviewer(&lt;span style="color:#e6db74">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;span style="color:#e6db74">Revise le code suivant pour l&amp;#39;authentification JWT:
&lt;/span>&lt;span style="color:#e6db74">
&lt;/span>&lt;span style="color:#e6db74">[CODE COMPLET ICI - 150 lignes]
&lt;/span>&lt;span style="color:#e6db74">
&lt;/span>&lt;span style="color:#e6db74">Context:
&lt;/span>&lt;span style="color:#e6db74">- Projet: API Express.js
&lt;/span>&lt;span style="color:#e6db74">- Database: MongoDB
&lt;/span>&lt;span style="color:#e6db74">- Contrainte: Doit supporter 10k req/sec
&lt;/span>&lt;span style="color:#e6db74">- Patterns existants: [exemples]
&lt;/span>&lt;span style="color:#e6db74">- User request original: &amp;#34;Ajoute l&amp;#39;authentification sécurisée&amp;#34;
&lt;/span>&lt;span style="color:#e6db74">
&lt;/span>&lt;span style="color:#e6db74">Identifie les problèmes CRITIQUES de sécurité et performance.
&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&amp;#34;&amp;#34;&lt;/span>)
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Cette approche évite les aller-retours coûteux et garantit des reviews de qualité dès la première passe.&lt;/p>
&lt;h2 id="-les-principes-clés-du-workflow">💡 Les Principes Clés du Workflow&lt;/h2>
&lt;h3 id="1-inférer-ne-pas-demander">1. &lt;strong>Inférer, Ne Pas Demander&lt;/strong>&lt;/h3>
&lt;p>Le workflow ne vous bombarde pas de questions. Il &lt;strong>infère&lt;/strong> :&lt;/p>
&lt;ul>
&lt;li>Le langage de programmation depuis les fichiers existants&lt;/li>
&lt;li>Le style de code depuis le codebase&lt;/li>
&lt;li>Les patterns architecturaux depuis la structure&lt;/li>
&lt;li>Les conventions de nommage depuis les exemples&lt;/li>
&lt;/ul>
&lt;h3 id="2-exécution-parallèle">2. &lt;strong>Exécution Parallèle&lt;/strong>&lt;/h3>
&lt;p>Les 3 reviewers s&amp;rsquo;exécutent &lt;strong>en parallèle&lt;/strong> dans un seul message :&lt;/p>
&lt;pre>&lt;code>invoke_parallel([
@code-quality-reviewer,
@error-analyzer,
@performance-analyzer
])
&lt;/code>&lt;/pre>&lt;p>Gain de temps : &lt;strong>~70%&lt;/strong> vs exécution séquentielle. (Parce que votre temps est précieux, et que personne n&amp;rsquo;aime attendre.)&lt;/p>
&lt;h3 id="3-classification-de-sévérité-rigoureuse">3. &lt;strong>Classification de Sévérité Rigoureuse&lt;/strong>&lt;/h3>
&lt;p>Le système distingue clairement :&lt;/p>
&lt;ul>
&lt;li>&lt;strong>CRITICAL&lt;/strong> → Déclenche réitération (failles sécu, crashes, perte données)&lt;/li>
&lt;li>&lt;strong>IMPORTANT&lt;/strong> → Fix direct si simple (performance, edge cases)&lt;/li>
&lt;li>&lt;strong>MINOR&lt;/strong> → Noté mais pas bloquant (style, suggestions)&lt;/li>
&lt;/ul>
&lt;h3 id="4-communication-transparente">4. &lt;strong>Communication Transparente&lt;/strong>&lt;/h3>
&lt;p>Le workflow communique clairement :&lt;/p>
&lt;ul>
&lt;li>Après 1 itération : Présentation normale&lt;/li>
&lt;li>Après 2-3 itérations : &amp;ldquo;Implémenté avec N cycles de raffinement&amp;rdquo;&lt;/li>
&lt;li>Après 4-5 itérations : &amp;ldquo;N cycles pour atteindre les standards de qualité&amp;rdquo;&lt;/li>
&lt;li>Si problèmes persistent : Honnêteté sur les limitations&lt;/li>
&lt;/ul>
&lt;h2 id="-cas-dusage-réels">🎬 Cas d&amp;rsquo;Usage Réels&lt;/h2>
&lt;h3 id="cas-1--ajout-dauthentification">Cas 1 : Ajout d&amp;rsquo;Authentification&lt;/h3>
&lt;pre>&lt;code>Demande: &amp;quot;Ajoute l'auth&amp;quot;
→ Itération 1: Code avec faille XSS
→ Itération 2: Correction + cookies sécurisés
→ Résultat: Authentification production-ready
Temps: 3 minutes (vs 2 heures manuellement)
&lt;/code>&lt;/pre>&lt;h3 id="cas-2--refactoring-complexe">Cas 2 : Refactoring Complexe&lt;/h3>
&lt;pre>&lt;code>Demande: &amp;quot;Refactorise ce legacy code&amp;quot;
→ @prompt-engineer: Spécifications SOLID complètes
→ Main agent: Refactoring avec extraction de patterns
→ Reviews parallèles: 0 issues critiques
→ @test-engineer: Suite de tests de régression
→ Résultat: Code maintenable avec 95% de couverture
&lt;/code>&lt;/pre>&lt;h3 id="cas-3--feature-complète">Cas 3 : Feature Complète&lt;/h3>
&lt;pre>&lt;code>Demande: &amp;quot;Implémente le paiement Stripe&amp;quot;
→ 5 itérations (c'est de la sécu critique!)
→ @test-engineer: Tests unitaires + intégration
→ @documenter: Guide d'utilisation + API docs
→ Résultat: Feature complète, testée, documentée
&lt;/code>&lt;/pre>&lt;h2 id="-ce-blog-post--une-démonstration-vivante">🔮 Ce Blog Post : Une Démonstration Vivante&lt;/h2>
&lt;p>&lt;strong>Méta-moment&lt;/strong> : Ce blog post lui-même a été créé en suivant ce workflow. Voici comment :&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>@prompt-engineer&lt;/strong> a reçu ma demande vague : &amp;ldquo;Je veux un blog post sur mon workflow sub-agentique&amp;rdquo;&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Il a généré un prompt détaillé spécifiant :&lt;/p>
&lt;ul>
&lt;li>Structure : Introduction humoristique → Explication technique → Agents → Loop → Méta-réflexion&lt;/li>
&lt;li>Style : Mélange technique/humour (comme mes posts sur les claviers)&lt;/li>
&lt;li>Contenu : Diagrammes, exemples concrets, emojis&lt;/li>
&lt;li>Format : Frontmatter Hugo, markdown, date du jour&lt;/li>
&lt;li>Méta : Section sur sa propre création&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Main agent&lt;/strong> (moi en ce moment) a généré ce contenu en suivant ces instructions&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Triple review&lt;/strong> analysera ce contenu pour :&lt;/p>
&lt;ul>
&lt;li>Qualité : Structure claire ? Explications complètes ? Style cohérent ?&lt;/li>
&lt;li>Erreurs : Informations inexactes ? Liens brisés ? Incohérences ?&lt;/li>
&lt;li>Performance : N/A pour un blog post, mais pertinent pour le code d&amp;rsquo;exemples&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Feedback loop&lt;/strong> : Si problèmes critiques détectés, réécriture ciblée&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Résultat&lt;/strong> : Ce post que vous lisez actuellement !&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2 id="-les-bénéfices-concrets">🎯 Les Bénéfices Concrets&lt;/h2>
&lt;h3 id="pour-vous">Pour Vous&lt;/h3>
&lt;ul>
&lt;li>⚡ &lt;strong>Rapidité&lt;/strong> : Code de qualité en minutes vs heures&lt;/li>
&lt;li>🛡️ &lt;strong>Qualité&lt;/strong> : Multiples expertises sur chaque ligne&lt;/li>
&lt;li>📚 &lt;strong>Apprentissage&lt;/strong> : Feedback détaillé sur les bonnes pratiques&lt;/li>
&lt;li>🎓 &lt;strong>Consistency&lt;/strong> : Style uniforme sur tout le codebase&lt;/li>
&lt;li>😌 &lt;strong>Sérénité&lt;/strong> : Confiance que rien n&amp;rsquo;a été oublié&lt;/li>
&lt;/ul>
&lt;h3 id="pour-vos-projets">Pour Vos Projets&lt;/h3>
&lt;ul>
&lt;li>🐛 Moins de bugs en production&lt;/li>
&lt;li>🔐 Meilleure sécurité par défaut&lt;/li>
&lt;li>⚡ Meilleures performances&lt;/li>
&lt;li>📖 Code mieux documenté&lt;/li>
&lt;li>🧪 Meilleure couverture de tests&lt;/li>
&lt;li>🏗️ Architecture plus solide&lt;/li>
&lt;/ul>
&lt;h3 id="métriques-sur-mes-projets-perso">Métriques (sur mes projets perso)&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>70% moins de reviews post-implémentation&lt;/strong>&lt;/li>
&lt;li>&lt;strong>90% moins de bugs découverts après merge&lt;/strong>&lt;/li>
&lt;li>&lt;strong>3x plus rapide pour les features complexes&lt;/strong>&lt;/li>
&lt;li>&lt;strong>95% de couverture de tests automatiquement&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>(Oui, j&amp;rsquo;ai mesuré. Oui, je suis ce genre de personne.)&lt;/p>
&lt;h2 id="-essayez-le-vous-même-">🚀 Essayez-le Vous-Même !&lt;/h2>
&lt;p>La configuration complète de ce workflow est disponible sur GitHub :&lt;/p>
&lt;p>&lt;strong>👉 &lt;a href="https://github.com/tomMoulard/configLoader/tree/master/opencode">github.com/tomMoulard/configLoader/tree/master/opencode&lt;/a>&lt;/strong>&lt;/p>
&lt;p>Le repo contient :&lt;/p>
&lt;ul>
&lt;li>📄 &lt;code>AGENTS.md&lt;/code> : Documentation complète du workflow&lt;/li>
&lt;li>🤖 &lt;code>agent/&lt;/code> : Définitions de chaque agent
&lt;ul>
&lt;li>&lt;code>prompt-engineer.md&lt;/code>&lt;/li>
&lt;li>&lt;code>code-quality-reviewer.md&lt;/code>&lt;/li>
&lt;li>&lt;code>error-analyzer.md&lt;/code>&lt;/li>
&lt;li>&lt;code>performance-analyzer.md&lt;/code>&lt;/li>
&lt;li>&lt;code>test-engineer.md&lt;/code>&lt;/li>
&lt;li>&lt;code>documenter.md&lt;/code>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>Chaque agent est un fichier markdown avec :&lt;/p>
&lt;ul>
&lt;li>Sa mission et expertise&lt;/li>
&lt;li>Ses critères d&amp;rsquo;évaluation&lt;/li>
&lt;li>Des exemples d&amp;rsquo;utilisation&lt;/li>
&lt;li>Le format de sortie attendu&lt;/li>
&lt;/ul>
&lt;h2 id="-leçons-apprises">🎓 Leçons Apprises&lt;/h2>
&lt;p>Après plusieurs mois d&amp;rsquo;utilisation intensive de ce workflow, voici mes insights :&lt;/p>
&lt;h3 id="-ce-qui-marche-extraordinairement-bien">✅ Ce Qui Marche Extraordinairement Bien&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>Detection de bugs subtils&lt;/strong> : Les 3 reviewers parallèles attrapent des edge cases que j&amp;rsquo;aurais ratés&lt;/li>
&lt;li>&lt;strong>Qualité constante&lt;/strong> : Même à 23h après une longue journée, le code généré est propre&lt;/li>
&lt;li>&lt;strong>Apprentissage&lt;/strong> : Je lis les feedback et j&amp;rsquo;améliore mes prompts initiaux&lt;/li>
&lt;li>&lt;strong>Confiance&lt;/strong> : Je merge avec sérénité sachant que 3 experts ont validé&lt;/li>
&lt;/ol>
&lt;h3 id="-les-limites">⚠️ Les Limites&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>Pas magique&lt;/strong> : Un mauvais prompt initial = mauvais résultat (GIGO)&lt;/li>
&lt;li>&lt;strong>Context matters&lt;/strong> : Il faut fournir le contexte complet aux sub-agents&lt;/li>
&lt;li>&lt;strong>Over-engineering ?&lt;/strong> : Pour un script de 10 lignes, c&amp;rsquo;est overkill&lt;/li>
&lt;li>&lt;strong>Coût&lt;/strong> : Plus d&amp;rsquo;appels API = plus de tokens utilisés&lt;/li>
&lt;/ol>
&lt;h3 id="-conseils-dutilisation">💡 Conseils d&amp;rsquo;Utilisation&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>Soyez spécifique&lt;/strong> dans votre demande initiale (même si @prompt-engineer aide)&lt;/li>
&lt;li>&lt;strong>Lisez les reviews&lt;/strong> : Elles contiennent des enseignements précieux&lt;/li>
&lt;li>&lt;strong>Adaptez les seuils&lt;/strong> : Pas besoin de 5 itérations pour un bugfix simple&lt;/li>
&lt;li>&lt;strong>Gardez le contrôle&lt;/strong> : Vous êtes le capitaine, l&amp;rsquo;IA est le copilote&lt;/li>
&lt;/ol>
&lt;h2 id="-réflexion-finale--lia-qui-sauto-améliore">🎭 Réflexion Finale : L&amp;rsquo;IA Qui S&amp;rsquo;Auto-Améliore&lt;/h2>
&lt;p>Ce qui est fascinant avec ce workflow, c&amp;rsquo;est qu&amp;rsquo;il représente une forme &lt;strong>d&amp;rsquo;IA orchestrant l&amp;rsquo;IA&lt;/strong>. Chaque agent est spécialisé, et c&amp;rsquo;est leur collaboration qui produit l&amp;rsquo;excellence. (Un peu comme les Avengers, mais avec plus de code et moins d&amp;rsquo;explosions. Quoique, certains bugs peuvent être explosifs.)&lt;/p>
&lt;p>En écrivant ce blog post &lt;strong>avec&lt;/strong> le workflow que je décris, j&amp;rsquo;ai expérimenté directement le concept de &lt;strong>méta-programmation&lt;/strong> : un système d&amp;rsquo;IA documentant sa propre création. C&amp;rsquo;est à la fois :&lt;/p>
&lt;ul>
&lt;li>🤯 Vertigineux (inception vibes)&lt;/li>
&lt;li>🎨 Créatif (nouvelles possibilités d&amp;rsquo;expression)&lt;/li>
&lt;li>🔬 Instructif (on comprend mieux en expliquant)&lt;/li>
&lt;li>😄 Amusant (parce que pourquoi pas ?)&lt;/li>
&lt;/ul>
&lt;h2 id="-pour-aller-plus-loin">🔗 Pour Aller Plus Loin&lt;/h2>
&lt;p>Si ce workflow vous intéresse, voici d&amp;rsquo;autres lectures :&lt;/p>
&lt;ul>
&lt;li>📖 &lt;a href="https://github.com/tomMoulard/configLoader/tree/master/opencode">Ma config OpenCode complète&lt;/a>&lt;/li>
&lt;li>🤖 &lt;a href="https://opencode.ai/docs">Documentation OpenCode officielle&lt;/a>&lt;/li>
&lt;li>🧬 &lt;a href="https://blog.moulard.org/keyboardgen-genetic-algorithm-deep-dive">Mon post sur les algorithmes génétiques&lt;/a> (autre exemple d&amp;rsquo;optimisation intelligente)&lt;/li>
&lt;li>🎨 &lt;a href="https://blog.moulard.org/experience-with-cursor-and-terraform-aft">Expérience avec Cursor et Terraform&lt;/a> (comparaison avec d&amp;rsquo;autres outils d&amp;rsquo;IA)&lt;/li>
&lt;/ul>
&lt;h2 id="-conclusion--le-futur-du-développement-">🎬 Conclusion : Le Futur du Développement ?&lt;/h2>
&lt;p>Le développement assisté par IA n&amp;rsquo;est plus une question de &amp;ldquo;si&amp;rdquo; mais de &amp;ldquo;comment&amp;rdquo;. Les workflows sub-agentiques comme celui-ci représentent une approche mature : au lieu d&amp;rsquo;une IA monolithique qui fait tout (mal), on a une &lt;strong>équipe d&amp;rsquo;experts spécialisés&lt;/strong> qui collaborent.&lt;/p>
&lt;p>C&amp;rsquo;est comme passer du développeur solo au squad complète : Product Owner (@prompt-engineer), Dev (@main-agent), QA (@error-analyzer), Architect (@code-quality-reviewer), Performance Engineer (@performance-analyzer), et Tech Writer (@documenter).&lt;/p>
&lt;p>Sauf que cette équipe ne prend pas de pause café, ne débat pas pendant 2 heures de la nomenclature des variables, et ne réclame pas de team building au laser game. (Par contre, elle consomme des tokens. Beaucoup de tokens.)&lt;/p>
&lt;p>&lt;strong>La vraie question n&amp;rsquo;est plus &amp;ldquo;L&amp;rsquo;IA va-t-elle remplacer les développeurs ?&amp;quot;&lt;/strong>&lt;/p>
&lt;p>C&amp;rsquo;est : &lt;strong>&amp;ldquo;Comment les développeurs vont-ils orchestrer l&amp;rsquo;IA pour être 10x plus efficaces ?&amp;quot;&lt;/strong>&lt;/p>
&lt;p>Et ce workflow est ma réponse. 🚀&lt;/p>
&lt;hr>
&lt;h2 id="-méta-annexe--le-prompt-utilisé">📝 Méta-Annexe : Le Prompt Utilisé&lt;/h2>
&lt;p>Pour la transparence totale (et parce que c&amp;rsquo;est devenu une tradition sur ce blog), voici le prompt initial qui a généré ce post :&lt;/p>
&lt;pre>&lt;code>&amp;quot;I want to create a new blog post about my new subagentic workflow
using opencode. Use this subagentic workflow to create this blog post.
The opencode configuration is available at
/Users/tom.moulard/workspace/configLoader/opencode
For future reference (i.e., in the blog post, it is available in my
github repository:
https://github.com/tomMoulard/configLoader/tree/master/opencode&amp;quot;
&lt;/code>&lt;/pre>&lt;p>Simple, non ? C&amp;rsquo;est exactement le genre de demande vague que &lt;strong>@prompt-engineer&lt;/strong> transforme en spécifications détaillées. Et le résultat, c&amp;rsquo;est les ~2000 mots que vous venez de lire.&lt;/p>
&lt;p>&lt;strong>Méta-méta note&lt;/strong> : Cette section elle-même a été prévue par @prompt-engineer dans ses instructions, créant une boucle récursive de méta-commentaires qui pourrait continuer indéfiniment si je n&amp;rsquo;avais pas un minimum de self-control et une deadline à respecter. 😄&lt;/p>
&lt;hr>
&lt;p>&lt;em>PS: Si vous utilisez ce workflow et créez quelque chose de cool, taguez-moi ! J&amp;rsquo;adore voir comment les gens adaptent et améliorent ces systèmes. Ensemble, on build l&amp;rsquo;avenir du développement. Un agent à la fois.&lt;/em> 🤖✨&lt;/p></description></item><item><title>Advanced Fitness Function Architecture: 12 AI-Driven KPIs for Optimal Keyboard Layout Evaluation</title><link>https://blog.moulard.org/keyboardgen-fitness-function-and-kpis/</link><pubDate>Sat, 09 Aug 2025 00:00:00 +0200</pubDate><guid>https://blog.moulard.org/keyboardgen-fitness-function-and-kpis/</guid><comments>https://blog.moulard.org/keyboardgen-fitness-function-and-kpis/#disqus_thread</comments><description>&lt;p>&lt;strong>Performance optimization at the microsecond level.&lt;/strong> At 120 WPM typing speeds, suboptimal character placement creates significant ergonomic and cognitive overhead. Our &lt;strong>multi-objective fitness function&lt;/strong> represents a breakthrough in &lt;strong>computational ergonomics&lt;/strong>—a sophisticated &lt;strong>12-dimensional machine learning evaluation framework&lt;/strong> that transforms typing biomechanics into quantifiable mathematical optimization targets through &lt;strong>neural-inspired scoring algorithms&lt;/strong>. (Yes, we&amp;rsquo;re literally teaching computers to judge keyboards like Olympic gymnastics, but with more math and fewer perfect 10s.)&lt;/p>
&lt;p>← &lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-genetic-algorithm-deep-dive">Master the Genetic Algorithm Engine first&lt;/a>&lt;/strong> | &lt;strong>&lt;a href="https://blog.moulard.org/qwerty-is-outdated">Start with the system overview&lt;/a>&lt;/strong>&lt;/p>
&lt;h2 id="-computational-ergonomics-the-science-of-ai-driven-typing-optimization">🎯 Computational Ergonomics: The Science of AI-Driven Typing Optimization&lt;/h2>
&lt;p>The &lt;strong>neural fitness function&lt;/strong> operates as an &lt;strong>advanced multi-criteria decision analysis system&lt;/strong> powered by &lt;strong>machine learning algorithms&lt;/strong>. Beyond simple speed metrics, it performs &lt;strong>comprehensive biomechanical analysis&lt;/strong>—evaluating &lt;strong>finger kinematics, motor control patterns, ergonomic stress tensors, and cognitive load optimization&lt;/strong> simultaneously. Each layout undergoes &lt;strong>12-dimensional performance evaluation&lt;/strong> with &lt;strong>adaptive weights&lt;/strong> calibrated through &lt;strong>ergonomic research&lt;/strong> and &lt;strong>neural network training&lt;/strong>.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#a6e22e">neuralFitness&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">BiomechanicalDistance&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">kinematicScore&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">MotorAlternation&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">alternationScore&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">ErgoBalance&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">balanceScore&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">VerticalMotion&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">rowJumpScore&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">BigramEfficiency&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">bigramScore&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">SameFingerPenalty&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">sfbPenalty&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#75715e">// 🚨 NEURAL PRIORITY
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">LateralStress&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">lsbPenalty&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">FlowOptimization&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">rollScore&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">CognitiveLoad&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">layerPenalty&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">ErgonomicBonus&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">homeRowScore&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">RhythmTarget&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">rollRatioScore&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">PerformanceBonus&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">thresholdBonus&lt;/span> &lt;span style="color:#f92672">+&lt;/span>
&lt;span style="color:#a6e22e">adaptiveWeights&lt;/span>.&lt;span style="color:#a6e22e">AdaptiveMatching&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">positionScore&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="-kpi-1-biomechanical-distance-optimization---neural-kinematic-foundation">📏 KPI #1: Biomechanical Distance Optimization - Neural Kinematic Foundation&lt;/h2>
&lt;p>&lt;strong>Neural Measurement&lt;/strong>: Total biomechanical finger displacement analyzed via &lt;strong>kinematic modeling&lt;/strong> of actual behavioral patterns
&lt;strong>Adaptive Weight&lt;/strong>: 10% of neural fitness function
&lt;strong>AI Objective&lt;/strong>: Minimize physical finger trajectory through &lt;strong>motion optimization algorithms&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">NeuralFitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateBiomechanicalDistance&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">BehavioralDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">totalDistance&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0.0&lt;/span>
&lt;span style="color:#a6e22e">totalFreq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#75715e">// Neural analysis of kinematic distance for each behavioral pattern
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">bigram&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetAllBigrams&lt;/span>() {
&lt;span style="color:#a6e22e">char1&lt;/span>, &lt;span style="color:#a6e22e">char2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> rune(&lt;span style="color:#a6e22e">bigram&lt;/span>[&lt;span style="color:#ae81ff">0&lt;/span>]), rune(&lt;span style="color:#a6e22e">bigram&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>])
&lt;span style="color:#a6e22e">pos1&lt;/span>, &lt;span style="color:#a6e22e">pos2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">charToPos&lt;/span>[&lt;span style="color:#a6e22e">char1&lt;/span>], &lt;span style="color:#a6e22e">charToPos&lt;/span>[&lt;span style="color:#a6e22e">char2&lt;/span>]
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">coord1&lt;/span>, &lt;span style="color:#a6e22e">coord2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">neuralGeometry&lt;/span>.&lt;span style="color:#a6e22e">KeyPositions&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">neuralGeometry&lt;/span>.&lt;span style="color:#a6e22e">KeyPositions&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>] {
&lt;span style="color:#75715e">// Biomechanical distance via neural kinematic modeling
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">kinematicDistance&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Sqrt&lt;/span>((&lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">0&lt;/span>])&lt;span style="color:#960050;background-color:#1e0010">²&lt;/span> &lt;span style="color:#f92672">+&lt;/span> (&lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>]&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>])&lt;span style="color:#960050;background-color:#1e0010">²&lt;/span>)
&lt;span style="color:#a6e22e">totalDistance&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">kinematicDistance&lt;/span> &lt;span style="color:#f92672">*&lt;/span> float64(&lt;span style="color:#a6e22e">freq&lt;/span>)
&lt;span style="color:#a6e22e">totalFreq&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
}
&lt;span style="color:#a6e22e">avgDistance&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">totalDistance&lt;/span> &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">totalFreq&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">/&lt;/span> (&lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#a6e22e">avgDistance&lt;/span>) &lt;span style="color:#75715e">// Lower distance = higher score
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Intelligence&lt;/strong>: The system employs &lt;strong>behavioral pattern recognition&lt;/strong>—using your &lt;strong>actual n-gram frequency distributions&lt;/strong>. Through &lt;strong>adaptive learning&lt;/strong>, frequent patterns like &amp;ldquo;th&amp;rdquo; (1000 occurrences) receive &lt;strong>prioritized optimization&lt;/strong> over rare combinations like &amp;ldquo;qz&amp;rdquo; via &lt;strong>weighted importance sampling&lt;/strong> and &lt;strong>neural attention mechanisms&lt;/strong>. (Sorry, Scrabble champions—&amp;ldquo;qz&amp;rdquo; combos don&amp;rsquo;t get VIP treatment in our neural optimization party.)&lt;/p>
&lt;p>&lt;strong>Performance Impact&lt;/strong>: &lt;strong>AI-optimized layouts&lt;/strong> achieve 30-50% biomechanical efficiency gains through &lt;strong>neural motion optimization&lt;/strong> compared to static QWERTY design.&lt;/p>
&lt;h2 id="-kpi-2-motor-alternation-patterns---neural-rhythm-optimization">🤝 KPI #2: Motor Alternation Patterns - Neural Rhythm Optimization&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Bilateral motor alternation frequency through &lt;strong>neural motor control modeling&lt;/strong>
&lt;strong>Adaptive Weight&lt;/strong>: 10% of neural fitness architecture
&lt;strong>AI Objective&lt;/strong>: Maximize natural typing rhythm via &lt;strong>motor pattern optimization&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">NeuralFitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateMotorAlternation&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">BehavioralDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">alternations&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#a6e22e">total&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">bigram&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetAllBigrams&lt;/span>() {
&lt;span style="color:#a6e22e">finger1&lt;/span>, &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>]
&lt;span style="color:#75715e">// Neural analysis of bilateral motor patterns (fingers 0-3 left, 4-7 right)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> (&lt;span style="color:#a6e22e">finger1&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">4&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">&amp;gt;=&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span>) &lt;span style="color:#f92672">||&lt;/span> (&lt;span style="color:#a6e22e">finger1&lt;/span> &lt;span style="color:#f92672">&amp;gt;=&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">4&lt;/span>) {
&lt;span style="color:#a6e22e">alternations&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
&lt;span style="color:#a6e22e">total&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
&lt;span style="color:#66d9ef">return&lt;/span> float64(&lt;span style="color:#a6e22e">alternations&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">total&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Optimum&lt;/strong>: &lt;strong>Biomechanical research&lt;/strong> and &lt;strong>neural network analysis&lt;/strong> indicate 60-70% motor alternation achieves peak performance. Excessive alternation disrupts beneficial &lt;strong>motor sequence patterns&lt;/strong>; insufficient alternation increases &lt;strong>muscular fatigue&lt;/strong> and &lt;strong>repetitive stress&lt;/strong>.&lt;/p>
&lt;p>&lt;strong>Performance Categories&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>EXCELLENT&lt;/strong>: &amp;gt;60% alternation&lt;/li>
&lt;li>&lt;strong>GOOD&lt;/strong>: 45-60%&lt;/li>
&lt;li>&lt;strong>MODERATE&lt;/strong>: 30-45%&lt;/li>
&lt;li>&lt;strong>POOR&lt;/strong>: &amp;lt;30%&lt;/li>
&lt;/ul>
&lt;h2 id="-kpi-3-ergonomic-load-distribution---neural-balance-optimization">⚖️ KPI #3: Ergonomic Load Distribution - Neural Balance Optimization&lt;/h2>
&lt;p>&lt;strong>Neural Measurement&lt;/strong>: Load distribution analysis across all 8 digits via &lt;strong>ergonomic modeling&lt;/strong>
&lt;strong>Adaptive Weight&lt;/strong>: 10% of neural fitness system
&lt;strong>AI Objective&lt;/strong>: Prevent repetitive stress through &lt;strong>balanced load optimization&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">NeuralFitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateErgonomicBalance&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">BehavioralDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">fingerFreq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> make([]&lt;span style="color:#66d9ef">int&lt;/span>, &lt;span style="color:#ae81ff">8&lt;/span>) &lt;span style="color:#75715e">// 8 fingers
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">totalFreq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#75715e">// Count frequency per finger for all characters
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">_&lt;/span>, &lt;span style="color:#a6e22e">char&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">charset&lt;/span>.&lt;span style="color:#a6e22e">Characters&lt;/span> {
&lt;span style="color:#a6e22e">finger&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">charToPos&lt;/span>[&lt;span style="color:#a6e22e">char&lt;/span>]]
&lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetCharFreq&lt;/span>(&lt;span style="color:#a6e22e">char&lt;/span>)
&lt;span style="color:#a6e22e">fingerFreq&lt;/span>[&lt;span style="color:#a6e22e">finger&lt;/span>] &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
&lt;span style="color:#a6e22e">totalFreq&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
&lt;span style="color:#75715e">// Neural analysis of finger load distribution via statistical modeling
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">mean&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">totalFreq&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#ae81ff">8.0&lt;/span>
&lt;span style="color:#a6e22e">variance&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0.0&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">_&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">fingerFreq&lt;/span> {
&lt;span style="color:#a6e22e">diff&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">freq&lt;/span>) &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#a6e22e">mean&lt;/span>
&lt;span style="color:#a6e22e">variance&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">diff&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#a6e22e">diff&lt;/span>
}
&lt;span style="color:#a6e22e">stdDev&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Sqrt&lt;/span>(&lt;span style="color:#a6e22e">variance&lt;/span> &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#ae81ff">8.0&lt;/span>)
&lt;span style="color:#75715e">// Lower standard deviation = better balance
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">/&lt;/span> (&lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#a6e22e">stdDev&lt;/span>&lt;span style="color:#f92672">/&lt;/span>&lt;span style="color:#a6e22e">mean&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Target&lt;/strong>: Each digit should process approximately 12.5% of total workload. The &lt;strong>adaptive algorithm&lt;/strong> penalizes both overutilized index fingers and underutilized peripheral digits through &lt;strong>dynamic load balancing&lt;/strong> and &lt;strong>ergonomic stress minimization&lt;/strong>. (It&amp;rsquo;s like having a fair manager for your fingers—no more letting your index fingers do all the heavy lifting while your pinkies slack off.)&lt;/p>
&lt;h2 id="-kpi-4-vertical-motion-analysis---neural-movement-penalty-system">🦘 KPI #4: Vertical Motion Analysis - Neural Movement Penalty System&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Vertical displacement frequency via &lt;strong>kinematic motion tracking&lt;/strong>
&lt;strong>Adaptive Weight&lt;/strong>: 6% of neural fitness architecture
&lt;strong>AI Objective&lt;/strong>: Maintain digits within natural &lt;strong>ergonomic zones&lt;/strong> through &lt;strong>motion constraint optimization&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateRowJumping&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">rowJumps&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#a6e22e">total&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">bigram&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetAllBigrams&lt;/span>() {
&lt;span style="color:#a6e22e">coord1&lt;/span>, &lt;span style="color:#a6e22e">coord2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">KeyPositions&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">KeyPositions&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>]
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(&lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>]&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>]) &amp;gt; &lt;span style="color:#ae81ff">0.5&lt;/span> { &lt;span style="color:#75715e">// Different rows
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">rowJumps&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
&lt;span style="color:#a6e22e">total&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
&lt;span style="color:#a6e22e">jumpRatio&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">rowJumps&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">total&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#a6e22e">jumpRatio&lt;/span> &lt;span style="color:#75715e">// Lower jumps = higher score
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Ergonomic Insight&lt;/strong>: Row jumping forces fingers out of their natural curved position, causing fatigue and reducing accuracy.&lt;/p>
&lt;h2 id="-kpi-5-neural-bigram-efficiency---intelligent-motor-sequence-optimization">🔄 KPI #5: Neural Bigram Efficiency - Intelligent Motor Sequence Optimization&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Motor sequence efficiency for frequent character pairs via &lt;strong>pattern recognition algorithms&lt;/strong>
&lt;strong>Adaptive Weight&lt;/strong>: 6% of neural fitness system
&lt;strong>AI Objective&lt;/strong>: Optimize common bigrams through &lt;strong>neural motor pattern learning&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">rateBigramEfficiency&lt;/span>(&lt;span style="color:#a6e22e">finger1&lt;/span>, &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#75715e">// Same finger = worst (0.1)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">finger1&lt;/span> &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">0.1&lt;/span>
}
&lt;span style="color:#75715e">// Adjacent fingers on same hand = poor (0.3)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(float64(&lt;span style="color:#a6e22e">finger1&lt;/span>&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">finger2&lt;/span>)) &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">sameHand&lt;/span>(&lt;span style="color:#a6e22e">finger1&lt;/span>, &lt;span style="color:#a6e22e">finger2&lt;/span>) {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">0.3&lt;/span>
}
&lt;span style="color:#75715e">// Different hands = best (1.0)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">differentHands&lt;/span>(&lt;span style="color:#a6e22e">finger1&lt;/span>, &lt;span style="color:#a6e22e">finger2&lt;/span>) {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span>
}
&lt;span style="color:#75715e">// Other combinations = moderate (0.6)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">0.6&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Hierarchy&lt;/strong>: Bilateral motor patterns &amp;gt; Ipsilateral non-adjacent &amp;gt; Ipsilateral adjacent &amp;gt; Single-digit sequences (optimized via &lt;strong>machine learning ranking&lt;/strong>)&lt;/p>
&lt;h2 id="-kpi-6-same-finger-bigram-analysis-sfbs---critical-neural-penalty-system">🚨 KPI #6: Same Finger Bigram Analysis (SFBs) - Critical Neural Penalty System&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Single-digit consecutive activation patterns via &lt;strong>motor control modeling&lt;/strong>
&lt;strong>Critical Weight&lt;/strong>: 20% of neural fitness (maximum priority)
&lt;strong>AI Objective&lt;/strong>: Eliminate motor sequence disruption through &lt;strong>neural pattern optimization&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateSameFingerBigrams&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">sfbCount&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#a6e22e">totalBigrams&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">bigram&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetAllBigrams&lt;/span>() {
&lt;span style="color:#a6e22e">finger1&lt;/span>, &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>]
&lt;span style="color:#a6e22e">totalBigrams&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">finger1&lt;/span> &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> {
&lt;span style="color:#a6e22e">sfbCount&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#75715e">// This is BAD
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
}
&lt;span style="color:#a6e22e">sfbRate&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">sfbCount&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">totalBigrams&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#a6e22e">sfbRate&lt;/span> &lt;span style="color:#75715e">// Fewer SFBs = higher score
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Critical Neural Importance&lt;/strong>: SFBs disrupt &lt;strong>motor flow patterns&lt;/strong>, cause &lt;strong>neural stuttering&lt;/strong>, and exponentially increase error rates. &lt;strong>AI-optimized layouts&lt;/strong> maintain SFBs below 2% through &lt;strong>advanced pattern avoidance algorithms&lt;/strong> and &lt;strong>neural constraint satisfaction&lt;/strong>. (Think of SFBs as that awkward moment when you try to high-five someone with the same hand twice—technically possible, but everyone involved feels uncomfortable.)&lt;/p>
&lt;p>&lt;strong>Quality Thresholds&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>EXCELLENT&lt;/strong>: &amp;lt;2% SFB rate&lt;/li>
&lt;li>&lt;strong>GOOD&lt;/strong>: 2-5%&lt;/li>
&lt;li>&lt;strong>ACCEPTABLE&lt;/strong>: 5-8%&lt;/li>
&lt;li>&lt;strong>POOR&lt;/strong>: &amp;gt;8%&lt;/li>
&lt;/ul>
&lt;h2 id="-kpi-7-lateral-stress-analysis-lsbs---neural-index-finger-protection">📐 KPI #7: Lateral Stress Analysis (LSBs) - Neural Index Finger Protection&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Lateral overextension patterns causing index finger &lt;strong>biomechanical stress&lt;/strong>
&lt;strong>Adaptive Weight&lt;/strong>: 4% of neural fitness architecture
&lt;strong>AI Objective&lt;/strong>: Prevent repetitive strain through &lt;strong>ergonomic constraint optimization&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateLateralStretches&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">lsbCount&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#a6e22e">totalBigrams&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">bigram&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetAllBigrams&lt;/span>() {
&lt;span style="color:#a6e22e">finger1&lt;/span>, &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>]
&lt;span style="color:#a6e22e">coord1&lt;/span>, &lt;span style="color:#a6e22e">coord2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">KeyPositions&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">KeyPositions&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>]
&lt;span style="color:#a6e22e">totalBigrams&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
&lt;span style="color:#75715e">// Check for lateral stretch bigrams on index fingers
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">isLSB&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">false&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">finger1&lt;/span> &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">3&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">3&lt;/span> { &lt;span style="color:#75715e">// Both on left index
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>] &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>] &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(&lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">0&lt;/span>]) &amp;gt; &lt;span style="color:#ae81ff">2.0&lt;/span> {
&lt;span style="color:#a6e22e">isLSB&lt;/span> = &lt;span style="color:#66d9ef">true&lt;/span>
}
} &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">finger1&lt;/span> &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span> { &lt;span style="color:#75715e">// Both on right index
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>] &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>] &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(&lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">0&lt;/span>]) &amp;gt; &lt;span style="color:#ae81ff">2.0&lt;/span> {
&lt;span style="color:#a6e22e">isLSB&lt;/span> = &lt;span style="color:#66d9ef">true&lt;/span>
}
}
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">isLSB&lt;/span> {
&lt;span style="color:#a6e22e">lsbCount&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
}
&lt;span style="color:#a6e22e">lsbRate&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">lsbCount&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">totalBigrams&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#a6e22e">lsbRate&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Biomechanical Analysis&lt;/strong>: Index fingers possess high strength but limited &lt;strong>lateral range of motion&lt;/strong>. Excessive extension induces &lt;strong>repetitive strain injury (RSI)&lt;/strong> and reduces &lt;strong>motor accuracy&lt;/strong> through &lt;strong>neural fatigue&lt;/strong> and &lt;strong>proprioceptive disruption&lt;/strong>. (They&amp;rsquo;re powerhouses, not yoga instructors—stop asking them to do the splits across your keyboard.)&lt;/p>
&lt;h2 id="-kpi-8-neural-flow-optimization---advanced-roll-quality-analysis">🌊 KPI #8: Neural Flow Optimization - Advanced Roll Quality Analysis&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Smooth &lt;strong>motor cascades&lt;/strong> across adjacent digits via &lt;strong>kinematic flow modeling&lt;/strong>
&lt;strong>Adaptive Weight&lt;/strong>: 4% of neural fitness system
&lt;strong>AI Objective&lt;/strong>: Maximize natural &lt;strong>finger sequence patterns&lt;/strong> through &lt;strong>neural flow optimization&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateRollQuality&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">rollCount&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#a6e22e">totalBigrams&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">bigram&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetAllBigrams&lt;/span>() {
&lt;span style="color:#a6e22e">finger1&lt;/span>, &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>]
&lt;span style="color:#a6e22e">coord1&lt;/span>, &lt;span style="color:#a6e22e">coord2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">KeyPositions&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">KeyPositions&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>]
&lt;span style="color:#a6e22e">totalBigrams&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
&lt;span style="color:#75715e">// Check for rolling motion (same hand, adjacent fingers, same row)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">sameHand&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> (&lt;span style="color:#a6e22e">finger1&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">4&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">4&lt;/span>) &lt;span style="color:#f92672">||&lt;/span> (&lt;span style="color:#a6e22e">finger1&lt;/span> &lt;span style="color:#f92672">&amp;gt;=&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">&amp;gt;=&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span>)
&lt;span style="color:#a6e22e">adjacentFingers&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(float64(&lt;span style="color:#a6e22e">finger1&lt;/span>&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">finger2&lt;/span>)) &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;span style="color:#a6e22e">sameRow&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(&lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>]&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>]) &amp;lt; &lt;span style="color:#ae81ff">0.3&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">sameHand&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">adjacentFingers&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">sameRow&lt;/span> {
&lt;span style="color:#a6e22e">rollCount&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
}
&lt;span style="color:#a6e22e">totalRollRate&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">rollCount&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">totalBigrams&lt;/span>)
&lt;span style="color:#75715e">// Score based on thresholds
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">totalRollRate&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.3&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#75715e">// EXCELLENT
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">totalRollRate&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.15&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">0.7&lt;/span> &lt;span style="color:#75715e">// GOOD
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">totalRollRate&lt;/span> &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#ae81ff">0.15&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#ae81ff">0.4&lt;/span> &lt;span style="color:#75715e">// POOR (scaled)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Flow Experience&lt;/strong>: Optimal rolls create &lt;strong>piano-like motor sequences&lt;/strong>—smooth, effortless &lt;strong>neural cascades&lt;/strong> that maintain &lt;strong>rhythmic motor patterns&lt;/strong> through &lt;strong>coordinated muscle activation&lt;/strong>.&lt;/p>
&lt;h2 id="-kpi-9-cognitive-load-analysis---neural-layer-penalty-system">🔤 KPI #9: Cognitive Load Analysis - Neural Layer Penalty System&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Modifier key activation frequency via &lt;strong>cognitive load modeling&lt;/strong>
&lt;strong>Significant Weight&lt;/strong>: 10% of neural fitness architecture
&lt;strong>AI Objective&lt;/strong>: Minimize &lt;strong>cognitive overhead&lt;/strong> through &lt;strong>neural complexity reduction&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateLayerPenalty&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">totalPenalty&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0.0&lt;/span>
&lt;span style="color:#a6e22e">totalFreq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#75715e">// Characters requiring modifiers
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">shiftChars&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">map&lt;/span>[&lt;span style="color:#66d9ef">rune&lt;/span>]&lt;span style="color:#66d9ef">bool&lt;/span>{
&lt;span style="color:#e6db74">&amp;#39;A&amp;#39;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;B&amp;#39;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#75715e">/* ... all uppercase ... */&lt;/span>
&lt;span style="color:#e6db74">&amp;#39;!&amp;#39;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;@&amp;#39;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#75715e">/* ... shift symbols ... */&lt;/span>
}
&lt;span style="color:#a6e22e">altGrChars&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">map&lt;/span>[&lt;span style="color:#66d9ef">rune&lt;/span>]&lt;span style="color:#66d9ef">bool&lt;/span>{
&lt;span style="color:#e6db74">&amp;#39;€&amp;#39;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;£&amp;#39;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#e6db74">&amp;#39;¥&amp;#39;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#75715e">/* ... special symbols ... */&lt;/span>
}
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">_&lt;/span>, &lt;span style="color:#a6e22e">char&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">charset&lt;/span>.&lt;span style="color:#a6e22e">Characters&lt;/span> {
&lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetCharFreq&lt;/span>(&lt;span style="color:#a6e22e">char&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0&lt;/span> {
&lt;span style="color:#a6e22e">totalFreq&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">shiftChars&lt;/span>[&lt;span style="color:#a6e22e">char&lt;/span>] {
&lt;span style="color:#a6e22e">totalPenalty&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> float64(&lt;span style="color:#a6e22e">freq&lt;/span>) &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#ae81ff">0.5&lt;/span> &lt;span style="color:#75715e">// Moderate penalty
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">altGrChars&lt;/span>[&lt;span style="color:#a6e22e">char&lt;/span>] {
&lt;span style="color:#a6e22e">totalPenalty&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> float64(&lt;span style="color:#a6e22e">freq&lt;/span>) &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#75715e">// High penalty
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
}
}
&lt;span style="color:#75715e">// Additional penalties for consecutive modifier usage
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">bigram&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetAllBigrams&lt;/span>() {
&lt;span style="color:#a6e22e">char1&lt;/span>, &lt;span style="color:#a6e22e">char2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> rune(&lt;span style="color:#a6e22e">bigram&lt;/span>[&lt;span style="color:#ae81ff">0&lt;/span>]), rune(&lt;span style="color:#a6e22e">bigram&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>])
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">shiftChars&lt;/span>[&lt;span style="color:#a6e22e">char1&lt;/span>] &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">shiftChars&lt;/span>[&lt;span style="color:#a6e22e">char2&lt;/span>] {
&lt;span style="color:#a6e22e">totalPenalty&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> float64(&lt;span style="color:#a6e22e">freq&lt;/span>) &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#ae81ff">0.3&lt;/span> &lt;span style="color:#75715e">// Holding Shift penalty
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
}
&lt;span style="color:#a6e22e">normalizedPenalty&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">totalPenalty&lt;/span> &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">totalFreq&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">/&lt;/span> (&lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#a6e22e">normalizedPenalty&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Cognitive Load&lt;/strong>: Each modifier activation increases &lt;strong>working memory demands&lt;/strong> and &lt;strong>motor complexity&lt;/strong> through &lt;strong>dual-task interference&lt;/strong> and &lt;strong>attention division&lt;/strong>. This creates &lt;strong>cognitive bottlenecks&lt;/strong> in &lt;strong>neural processing pathways&lt;/strong>. (It&amp;rsquo;s like trying to pat your head and rub your belly while reciting the alphabet backwards—technically doable, but your brain would prefer a simpler task.)&lt;/p>
&lt;h2 id="-kpi-10-ergonomic-zone-optimization---neural-home-row-bonus-system">🏠 KPI #10: Ergonomic Zone Optimization - Neural Home Row Bonus System&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Ergonomic zone utilization via &lt;strong>biomechanical positioning analysis&lt;/strong>
&lt;strong>Strategic Weight&lt;/strong>: 8% of neural fitness system
&lt;strong>AI Objective&lt;/strong>: Maximize &lt;strong>optimal ergonomic positioning&lt;/strong> through &lt;strong>neural zone optimization&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateHomeRowBonus&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">homeRowPositions&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">map&lt;/span>[&lt;span style="color:#66d9ef">int&lt;/span>]&lt;span style="color:#66d9ef">bool&lt;/span>{
&lt;span style="color:#ae81ff">10&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#ae81ff">11&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#ae81ff">12&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#ae81ff">13&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#ae81ff">14&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#75715e">// Left home row
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#ae81ff">15&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#ae81ff">16&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#ae81ff">17&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#ae81ff">18&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>, &lt;span style="color:#75715e">// Right home row
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
&lt;span style="color:#a6e22e">totalHomeRowFreq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#a6e22e">totalFreq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">_&lt;/span>, &lt;span style="color:#a6e22e">char&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">charset&lt;/span>.&lt;span style="color:#a6e22e">Characters&lt;/span> {
&lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetCharFreq&lt;/span>(&lt;span style="color:#a6e22e">char&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0&lt;/span> {
&lt;span style="color:#a6e22e">totalFreq&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">pos&lt;/span>, &lt;span style="color:#a6e22e">exists&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">charToPos&lt;/span>[&lt;span style="color:#a6e22e">char&lt;/span>]; &lt;span style="color:#a6e22e">exists&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">homeRowPositions&lt;/span>[&lt;span style="color:#a6e22e">pos&lt;/span>] {
&lt;span style="color:#a6e22e">totalHomeRowFreq&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
}
}
&lt;span style="color:#a6e22e">homeRowUsage&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">totalHomeRowFreq&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">totalFreq&lt;/span>)
&lt;span style="color:#75715e">// Bonus scoring based on usage thresholds
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">homeRowUsage&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.4&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#f92672">+&lt;/span> (&lt;span style="color:#a6e22e">homeRowUsage&lt;/span>&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#ae81ff">0.4&lt;/span>)&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#ae81ff">2.0&lt;/span> &lt;span style="color:#75715e">// Bonus for excellence
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">homeRowUsage&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.3&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">homeRowUsage&lt;/span> &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#ae81ff">0.4&lt;/span> &lt;span style="color:#75715e">// Proportional reward
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">homeRowUsage&lt;/span> &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#ae81ff">0.4&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#ae81ff">0.5&lt;/span> &lt;span style="color:#75715e">// Penalty for poor usage
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Biomechanical Foundation&lt;/strong>: Fingers achieve &lt;strong>natural resting position&lt;/strong> on the home row. Each deviation demands &lt;strong>additional motor energy&lt;/strong> and increases &lt;strong>error probability&lt;/strong> through &lt;strong>proprioceptive displacement&lt;/strong> and &lt;strong>neural recalibration&lt;/strong>. (It&amp;rsquo;s the keyboard equivalent of prime beachfront property—location, location, location! Your fingers want to live where the ergonomic action is.)&lt;/p>
&lt;p>&lt;strong>Performance Categories&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>OPTIMIZED&lt;/strong>: &amp;gt;40% home row usage&lt;/li>
&lt;li>&lt;strong>GOOD&lt;/strong>: 30-40%&lt;/li>
&lt;li>&lt;strong>SUBOPTIMAL&lt;/strong>: &amp;lt;30%&lt;/li>
&lt;/ul>
&lt;h2 id="-kpi-11-neural-rhythm-target---advanced-roll-ratio-optimization">🎯 KPI #11: Neural Rhythm Target - Advanced Roll Ratio Optimization&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Percentage of ipsilateral bigrams achieving &lt;strong>smooth motor flow&lt;/strong>
&lt;strong>Precision Weight&lt;/strong>: 4% of neural fitness architecture
&lt;strong>AI Target&lt;/strong>: Achieve 35% roll ratio (&lt;strong>biomechanically optimal&lt;/strong> via &lt;strong>neural research&lt;/strong>)&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateRollRatioTarget&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">sameHandBigrams&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#a6e22e">rollBigrams&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">bigram&lt;/span>, &lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetAllBigrams&lt;/span>() {
&lt;span style="color:#a6e22e">finger1&lt;/span>, &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">fe&lt;/span>.&lt;span style="color:#a6e22e">geometry&lt;/span>.&lt;span style="color:#a6e22e">FingerMap&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>]
&lt;span style="color:#a6e22e">sameHand&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> (&lt;span style="color:#a6e22e">finger1&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">4&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">4&lt;/span>) &lt;span style="color:#f92672">||&lt;/span> (&lt;span style="color:#a6e22e">finger1&lt;/span> &lt;span style="color:#f92672">&amp;gt;=&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">finger2&lt;/span> &lt;span style="color:#f92672">&amp;gt;=&lt;/span> &lt;span style="color:#ae81ff">4&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> !&lt;span style="color:#a6e22e">sameHand&lt;/span> { &lt;span style="color:#66d9ef">continue&lt;/span> }
&lt;span style="color:#a6e22e">sameHandBigrams&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
&lt;span style="color:#75715e">// Check for rolling motion
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">adjacentFingers&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(float64(&lt;span style="color:#a6e22e">finger1&lt;/span>&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">finger2&lt;/span>)) &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;span style="color:#a6e22e">sameRow&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(&lt;span style="color:#a6e22e">coord1&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>]&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">coord2&lt;/span>[&lt;span style="color:#ae81ff">1&lt;/span>]) &amp;lt; &lt;span style="color:#ae81ff">0.3&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">adjacentFingers&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">sameRow&lt;/span> {
&lt;span style="color:#a6e22e">rollBigrams&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span>
}
}
&lt;span style="color:#a6e22e">rollRatio&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">rollBigrams&lt;/span>) &lt;span style="color:#f92672">/&lt;/span> float64(&lt;span style="color:#a6e22e">sameHandBigrams&lt;/span>)
&lt;span style="color:#a6e22e">targetRatio&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0.35&lt;/span> &lt;span style="color:#75715e">// Research-backed optimum
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">deviation&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Abs&lt;/span>(&lt;span style="color:#a6e22e">rollRatio&lt;/span> &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#a6e22e">targetRatio&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">math&lt;/span>.&lt;span style="color:#a6e22e">Max&lt;/span>(&lt;span style="color:#ae81ff">0.0&lt;/span>, &lt;span style="color:#ae81ff">1.0&lt;/span>&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">deviation&lt;/span>&lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#ae81ff">2.0&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Research&lt;/strong>: &lt;strong>Biomechanical studies&lt;/strong> and &lt;strong>motor learning research&lt;/strong> identify 35% as the &lt;strong>neural optimum&lt;/strong>—sufficient &lt;strong>motor flow&lt;/strong> for efficiency while avoiding &lt;strong>pattern predictability&lt;/strong> and &lt;strong>motor habituation&lt;/strong>.&lt;/p>
&lt;h2 id="-kpi-12-performance-threshold-system---neural-excellence-rewards">🏆 KPI #12: Performance Threshold System - Neural Excellence Rewards&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Bonus scoring for exceeding &lt;strong>biomechanical excellence thresholds&lt;/strong>
&lt;strong>Strategic Weight&lt;/strong>: 4% of neural fitness system
&lt;strong>AI Objective&lt;/strong>: Reward layouts achieving &lt;strong>multiple neural performance categories&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculateThresholdBonuses&lt;/span>(
&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>,
&lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>,
&lt;span style="color:#a6e22e">alternationScore&lt;/span>, &lt;span style="color:#a6e22e">rollScore&lt;/span> &lt;span style="color:#66d9ef">float64&lt;/span>,
) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0.0&lt;/span>
&lt;span style="color:#75715e">// Hand alternation threshold bonuses
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">alternationScore&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.6&lt;/span> {
&lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#75715e">// EXCELLENT bonus
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">alternationScore&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.45&lt;/span> {
&lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#ae81ff">0.6&lt;/span> &lt;span style="color:#75715e">// GOOD bonus
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">alternationScore&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.3&lt;/span> {
&lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#ae81ff">0.3&lt;/span> &lt;span style="color:#75715e">// MODERATE bonus
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
&lt;span style="color:#75715e">// Roll quality threshold bonus
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">rollScore&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.4&lt;/span> {
&lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#ae81ff">0.8&lt;/span> &lt;span style="color:#75715e">// High roll frequency bonus
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">rollScore&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0.2&lt;/span> {
&lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#ae81ff">0.4&lt;/span> &lt;span style="color:#75715e">// Moderate roll frequency bonus
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
&lt;span style="color:#75715e">// SFB rate threshold bonuses
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">sfbRate&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">calculateSFBRate&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">sfbRate&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">0.02&lt;/span> {
&lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#ae81ff">1.0&lt;/span> &lt;span style="color:#75715e">// EXCELLENT SFB rate
&lt;/span>&lt;span style="color:#75715e">&lt;/span> } &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">sfbRate&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">0.05&lt;/span> {
&lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#ae81ff">0.5&lt;/span> &lt;span style="color:#75715e">// GOOD SFB rate
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">bonusScore&lt;/span> &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#ae81ff">3.0&lt;/span> &lt;span style="color:#75715e">// Normalize (max possible: ~3.0)
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Philosophy&lt;/strong>: &lt;strong>Excellence merits exponential rewards&lt;/strong> via &lt;strong>non-linear scoring functions&lt;/strong>. Layouts crossing multiple &lt;strong>performance thresholds&lt;/strong> demonstrate &lt;strong>qualitative superiority&lt;/strong> through &lt;strong>emergent neural properties&lt;/strong>.&lt;/p>
&lt;h2 id="-kpi-13-adaptive-position-matching---neural-ergonomic-intelligence">📈 KPI #13: Adaptive Position Matching - Neural Ergonomic Intelligence&lt;/h2>
&lt;p>&lt;strong>Neural Analysis&lt;/strong>: Character frequency alignment with &lt;strong>ergonomic comfort zones&lt;/strong> via &lt;strong>adaptive positioning algorithms&lt;/strong>
&lt;strong>Intelligent Weight&lt;/strong>: 4% of neural fitness architecture
&lt;strong>AI Objective&lt;/strong>: Optimize frequent characters for &lt;strong>maximum ergonomic comfort&lt;/strong> through &lt;strong>neural placement learning&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">fe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">FitnessEvaluator&lt;/span>) &lt;span style="color:#a6e22e">calculatePositionMatching&lt;/span>(&lt;span style="color:#a6e22e">layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) &lt;span style="color:#66d9ef">float64&lt;/span> {
&lt;span style="color:#75715e">// Define ergonomic scores for each position (higher = more ergonomic)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">ergonomicScores&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">map&lt;/span>[&lt;span style="color:#66d9ef">int&lt;/span>]&lt;span style="color:#66d9ef">float64&lt;/span>{
&lt;span style="color:#75715e">// Home row (most ergonomic)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#ae81ff">13&lt;/span>: &lt;span style="color:#ae81ff">1.0&lt;/span>, &lt;span style="color:#ae81ff">14&lt;/span>: &lt;span style="color:#ae81ff">1.0&lt;/span>, &lt;span style="color:#ae81ff">15&lt;/span>: &lt;span style="color:#ae81ff">1.0&lt;/span>, &lt;span style="color:#ae81ff">16&lt;/span>: &lt;span style="color:#ae81ff">1.0&lt;/span>, &lt;span style="color:#75715e">// Index and middle fingers
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#ae81ff">12&lt;/span>: &lt;span style="color:#ae81ff">0.9&lt;/span>, &lt;span style="color:#ae81ff">17&lt;/span>: &lt;span style="color:#ae81ff">0.9&lt;/span>, &lt;span style="color:#75715e">// Ring fingers
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#ae81ff">11&lt;/span>: &lt;span style="color:#ae81ff">0.7&lt;/span>, &lt;span style="color:#ae81ff">18&lt;/span>: &lt;span style="color:#ae81ff">0.7&lt;/span>, &lt;span style="color:#75715e">// Pinky fingers
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#75715e">// Top row (moderately ergonomic)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#ae81ff">3&lt;/span>: &lt;span style="color:#ae81ff">0.8&lt;/span>, &lt;span style="color:#ae81ff">4&lt;/span>: &lt;span style="color:#ae81ff">0.8&lt;/span>, &lt;span style="color:#ae81ff">5&lt;/span>: &lt;span style="color:#ae81ff">0.8&lt;/span>, &lt;span style="color:#ae81ff">6&lt;/span>: &lt;span style="color:#ae81ff">0.8&lt;/span>, &lt;span style="color:#75715e">// Index and middle
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#ae81ff">2&lt;/span>: &lt;span style="color:#ae81ff">0.7&lt;/span>, &lt;span style="color:#ae81ff">7&lt;/span>: &lt;span style="color:#ae81ff">0.7&lt;/span>, &lt;span style="color:#75715e">// Ring
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#75715e">// Bottom row (less ergonomic)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#ae81ff">22&lt;/span>: &lt;span style="color:#ae81ff">0.6&lt;/span>, &lt;span style="color:#ae81ff">23&lt;/span>: &lt;span style="color:#ae81ff">0.6&lt;/span>, &lt;span style="color:#ae81ff">24&lt;/span>: &lt;span style="color:#ae81ff">0.6&lt;/span>, &lt;span style="color:#75715e">// Index and middle
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// ... more positions
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
&lt;span style="color:#a6e22e">totalScore&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0.0&lt;/span>
&lt;span style="color:#a6e22e">totalWeight&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0.0&lt;/span>
&lt;span style="color:#75715e">// Calculate weighted ergonomic score
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">_&lt;/span>, &lt;span style="color:#a6e22e">char&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">charset&lt;/span>.&lt;span style="color:#a6e22e">Characters&lt;/span> {
&lt;span style="color:#a6e22e">freq&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">data&lt;/span>.&lt;span style="color:#a6e22e">GetCharFreq&lt;/span>(&lt;span style="color:#a6e22e">char&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">freq&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">0&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">pos&lt;/span>, &lt;span style="color:#a6e22e">exists&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">charToPos&lt;/span>[&lt;span style="color:#a6e22e">char&lt;/span>]; &lt;span style="color:#a6e22e">exists&lt;/span> {
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">ergScore&lt;/span>, &lt;span style="color:#a6e22e">hasErg&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">ergonomicScores&lt;/span>[&lt;span style="color:#a6e22e">pos&lt;/span>]; &lt;span style="color:#a6e22e">hasErg&lt;/span> {
&lt;span style="color:#a6e22e">weight&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> float64(&lt;span style="color:#a6e22e">freq&lt;/span>)
&lt;span style="color:#a6e22e">totalScore&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">ergScore&lt;/span> &lt;span style="color:#f92672">*&lt;/span> &lt;span style="color:#a6e22e">weight&lt;/span>
&lt;span style="color:#a6e22e">totalWeight&lt;/span> &lt;span style="color:#f92672">+=&lt;/span> &lt;span style="color:#a6e22e">weight&lt;/span>
}
}
}
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">totalScore&lt;/span> &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#a6e22e">totalWeight&lt;/span> &lt;span style="color:#75715e">// Frequency-weighted ergonomic average
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Insight&lt;/strong>: &lt;strong>Ergonomic positions&lt;/strong> exhibit &lt;strong>non-uniform comfort distributions&lt;/strong>. High-frequency characters require &lt;strong>optimal ergonomic placement&lt;/strong> through &lt;strong>adaptive neural mapping&lt;/strong> and &lt;strong>comfort-frequency correlation analysis&lt;/strong>.&lt;/p>
&lt;h2 id="-neural-weighting-strategy-advanced-multi-objective-balancing">⚖️ Neural Weighting Strategy: Advanced Multi-Objective Balancing&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">NeuralAdaptiveWeights&lt;/span>() &lt;span style="color:#a6e22e">NeuralFitnessWeights&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">NeuralFitnessWeights&lt;/span>{
&lt;span style="color:#75715e">// Neural ergonomic foundations
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">FingerDistance&lt;/span>: &lt;span style="color:#ae81ff">0.10&lt;/span>, &lt;span style="color:#75715e">// Reduced to make room for modern metrics
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">HandAlternation&lt;/span>: &lt;span style="color:#ae81ff">0.10&lt;/span>,
&lt;span style="color:#a6e22e">FingerBalance&lt;/span>: &lt;span style="color:#ae81ff">0.10&lt;/span>,
&lt;span style="color:#a6e22e">RowJumping&lt;/span>: &lt;span style="color:#ae81ff">0.06&lt;/span>,
&lt;span style="color:#a6e22e">BigramEfficiency&lt;/span>: &lt;span style="color:#ae81ff">0.06&lt;/span>,
&lt;span style="color:#75715e">// Advanced neural metrics
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">SameFingerBigrams&lt;/span>: &lt;span style="color:#ae81ff">0.20&lt;/span>, &lt;span style="color:#75715e">// HIGHEST - SFBs are typing killers
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">LateralStretches&lt;/span>: &lt;span style="color:#ae81ff">0.04&lt;/span>,
&lt;span style="color:#a6e22e">RollQuality&lt;/span>: &lt;span style="color:#ae81ff">0.04&lt;/span>,
&lt;span style="color:#a6e22e">LayerPenalty&lt;/span>: &lt;span style="color:#ae81ff">0.10&lt;/span>, &lt;span style="color:#75715e">// Significant - modifier complexity
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
&lt;span style="color:#75715e">// Neural-enhanced KPI components
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">HomeRowBonus&lt;/span>: &lt;span style="color:#ae81ff">0.08&lt;/span>, &lt;span style="color:#75715e">// Home row optimization
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">RollRatioTarget&lt;/span>: &lt;span style="color:#ae81ff">0.04&lt;/span>, &lt;span style="color:#75715e">// Target 35% roll percentage
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">ThresholdBonuses&lt;/span>: &lt;span style="color:#ae81ff">0.04&lt;/span>, &lt;span style="color:#75715e">// Excellence rewards
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">PositionMatching&lt;/span>: &lt;span style="color:#ae81ff">0.04&lt;/span>, &lt;span style="color:#75715e">// Ergonomic-frequency alignment
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Neural Philosophy&lt;/strong>: Same Finger Bigrams receive &lt;strong>maximum weighting&lt;/strong> as the primary &lt;strong>motor flow disruptor&lt;/strong>. All other &lt;strong>neural components&lt;/strong> support this &lt;strong>critical optimization objective&lt;/strong> through &lt;strong>hierarchical importance ranking&lt;/strong> and &lt;strong>adaptive weight balancing&lt;/strong>. (SFBs are like that one coworker who interrupts every meeting—technically part of the system, but everyone wishes they&amp;rsquo;d just&amp;hellip; stop.)&lt;/p>
&lt;h2 id="-neural-performance-analytics-advanced-empirical-results">🎭 Neural Performance Analytics: Advanced Empirical Results&lt;/h2>
&lt;p>When this &lt;strong>neural fitness architecture&lt;/strong> evaluates layouts, &lt;strong>optimal performance metrics&lt;/strong> demonstrate:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Hand Alternation&lt;/strong>: 65% (EXCELLENT)&lt;/li>
&lt;li>&lt;strong>Same Finger Bigrams&lt;/strong>: 1.8% (EXCELLENT)&lt;/li>
&lt;li>&lt;strong>Home Row Usage&lt;/strong>: 42% (OPTIMIZED)&lt;/li>
&lt;li>&lt;strong>Roll Quality&lt;/strong>: 32% (EXCELLENT)&lt;/li>
&lt;li>&lt;strong>Lateral Stretches&lt;/strong>: 0.3% (MINIMAL)&lt;/li>
&lt;li>&lt;strong>Position Matching&lt;/strong>: 0.89 (HIGH FREQUENCY ON ERGONOMIC KEYS)&lt;/li>
&lt;/ul>
&lt;p>Compare this to QWERTY&amp;rsquo;s typical scores:&lt;/p>
&lt;ul>
&lt;li>Hand Alternation: 32% (POOR)&lt;/li>
&lt;li>Same Finger Bigrams: 6.2% (POOR)&lt;/li>
&lt;li>Home Row Usage: 28% (SUBOPTIMAL)&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>The neural performance differential is remarkable through quantitative analysis.&lt;/strong> (QWERTY doesn&amp;rsquo;t stand a chance against our mathematical optimization army.)&lt;/p>
&lt;h2 id="-neural-fitness-evolution-advanced-evaluation-paradigm">🔮 Neural Fitness Evolution: Advanced Evaluation Paradigm&lt;/h2>
&lt;p>This &lt;strong>neural fitness architecture&lt;/strong> represents the evolutionary paradigm of &lt;strong>computational ergonomics research&lt;/strong>:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Classical biomechanical metrics&lt;/strong> (kinematic distance, motor alternation, load balance)&lt;/li>
&lt;li>&lt;strong>Advanced neural insights&lt;/strong> (SFB penalties, LSB analysis, flow optimization)&lt;/li>
&lt;li>&lt;strong>AI-driven performance bonuses&lt;/strong> (threshold rewards, adaptive position matching)&lt;/li>
&lt;li>&lt;strong>Neural adaptive weighting&lt;/strong> (behavioral data-driven priority optimization)&lt;/li>
&lt;/ol>
&lt;p>Each &lt;strong>neural KPI&lt;/strong> captures distinct &lt;strong>biomechanical and cognitive dimensions&lt;/strong>, collectively forming a &lt;strong>comprehensive ergonomic model&lt;/strong> that demonstrates &lt;strong>strong correlation&lt;/strong> with real-world &lt;strong>motor performance&lt;/strong> through &lt;strong>advanced machine learning validation&lt;/strong>.&lt;/p>
&lt;h2 id="-neural-optimization-trajectory-the-ai-driven-path-forward">🚀 Neural Optimization Trajectory: The AI-Driven Path Forward&lt;/h2>
&lt;p>The &lt;strong>neural fitness function&lt;/strong> serves as the &lt;strong>computational intelligence core&lt;/strong>—transforming &lt;strong>behavioral typing patterns&lt;/strong> into &lt;strong>mathematical optimization insights&lt;/strong> and guiding the &lt;strong>genetic algorithm&lt;/strong> toward layouts that &lt;strong>significantly enhance&lt;/strong> daily workflow through &lt;strong>AI-driven ergonomic optimization&lt;/strong>.&lt;/p>
&lt;p>How does this &lt;strong>neural architecture integrate&lt;/strong>? How do &lt;strong>genetic algorithms&lt;/strong> and &lt;strong>neural fitness functions&lt;/strong> synergistically create layouts that &lt;strong>dramatically outperform&lt;/strong> decades of traditional design through &lt;strong>advanced computational intelligence&lt;/strong>? (Spoiler alert: it involves a lot of very smart math that would make your high school algebra teacher weep tears of joy.)&lt;/p>
&lt;p>&lt;strong>&lt;a href="https://blog.moulard.org/qwerty-is-outdated">Discover the complete system in the overview →&lt;/a>&lt;/strong>&lt;/p>
&lt;h2 id="-comprehensive-neural-technical-series">🗺️ Comprehensive Neural-Technical Series&lt;/h2>
&lt;p>&lt;strong>📚 Advanced Neural Navigation:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>&lt;a href="https://blog.moulard.org/qwerty-is-outdated">Neural-Genetic System Overview&lt;/a>&lt;/strong> - Complete AI-powered computational optimization&lt;/li>
&lt;li>&lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-genetic-algorithm-deep-dive">Advanced Genetic Algorithm Engine&lt;/a>&lt;/strong> - Master evolutionary computing and neural principles&lt;/li>
&lt;li>&lt;strong>This Post: Neural Fitness &amp;amp; Advanced KPIs&lt;/strong> - 12-dimensional neural evaluation architecture&lt;/li>
&lt;/ol></description></item><item><title>Advanced Genetic Algorithm Architecture: Neural-Evolutionary Keyboard Optimization Engine</title><link>https://blog.moulard.org/keyboardgen-genetic-algorithm-deep-dive/</link><pubDate>Sat, 09 Aug 2025 00:00:00 +0200</pubDate><guid>https://blog.moulard.org/keyboardgen-genetic-algorithm-deep-dive/</guid><comments>https://blog.moulard.org/keyboardgen-genetic-algorithm-deep-dive/#disqus_thread</comments><description>&lt;p>&lt;strong>Your fingers execute millions of neural-motor patterns daily.&lt;/strong> Every keystroke represents an optimization opportunity through &lt;strong>evolutionary computation&lt;/strong>, &lt;strong>adaptive algorithms&lt;/strong>, and &lt;strong>biomechanical enhancement&lt;/strong>. Welcome to &lt;strong>advanced genetic algorithm engineering&lt;/strong> applied to keyboard optimization—where &lt;strong>Darwinian evolutionary principles&lt;/strong> meet &lt;strong>computational intelligence&lt;/strong> and &lt;strong>machine learning optimization&lt;/strong> (and somehow make more sense than most corporate strategy meetings).&lt;/p>
&lt;p>← &lt;strong>&lt;a href="https://blog.moulard.org/qwerty-is-outdated">Start with the complete system overview&lt;/a>&lt;/strong> | &lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-fitness-function-and-kpis">Jump to fitness function details →&lt;/a>&lt;/strong>&lt;/p>
&lt;h2 id="-the-evolutionary-approach-to-better-typing">🧬 The Evolutionary Approach to Better Typing&lt;/h2>
&lt;p>Forget everything you know about traditional keyboard design. What if, instead of accepting QWERTY&amp;rsquo;s historical accident, we could &lt;strong>evolve&lt;/strong> the perfect keyboard layout tailored specifically to your typing patterns? That&amp;rsquo;s exactly what our genetic algorithm does—it treats keyboard layouts as DNA and evolves them through generations of natural selection. (It&amp;rsquo;s like breeding prize-winning keyboards, except they don&amp;rsquo;t need food or vet visits.)&lt;/p>
&lt;h3 id="the-core-genetic-framework">The Core Genetic Framework&lt;/h3>
&lt;p>At its heart, our system models keyboard layouts as &lt;strong>individuals&lt;/strong> in a population, each carrying genetic information (their layout) that determines their survival fitness. Here&amp;rsquo;s how the magic happens:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">Individual&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">Layout&lt;/span> []&lt;span style="color:#66d9ef">rune&lt;/span> &lt;span style="color:#75715e">// The &amp;#34;DNA&amp;#34; - character positions
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">Charset&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">CharacterSet&lt;/span> &lt;span style="color:#75715e">// Available characters
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">Fitness&lt;/span> &lt;span style="color:#66d9ef">float64&lt;/span> &lt;span style="color:#75715e">// Survival probability
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">Age&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span> &lt;span style="color:#75715e">// Generational tracking
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Each individual represents a complete keyboard layout with up to 70 positions, far beyond the traditional 26-letter focus. The system supports everything from basic alphabets to full programming symbol sets, making it adaptable to any typing scenario.&lt;/p>
&lt;h2 id="-the-evolution-cycle-from-chaos-to-optimization">🔄 The Evolution Cycle: From Chaos to Optimization&lt;/h2>
&lt;h3 id="population-initialization-starting-the-gene-pool">Population Initialization: Starting the Gene Pool&lt;/h3>
&lt;p>The journey begins with creating a diverse initial population. Unlike random approaches, we use &lt;strong>strategic initialization&lt;/strong> to seed the population with promising starting points:&lt;/p>
&lt;h4 id="1-frequency-based-seeding">1. &lt;strong>Frequency-Based Seeding&lt;/strong>&lt;/h4>
&lt;p>The most frequent characters in your typing data get prime real estate on the home row:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">createFrequencyBasedLayout&lt;/span>(&lt;span style="color:#a6e22e">charset&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">CharacterSet&lt;/span>, &lt;span style="color:#a6e22e">data&lt;/span> &lt;span style="color:#a6e22e">KeyloggerDataInterface&lt;/span>) []&lt;span style="color:#66d9ef">rune&lt;/span> {
&lt;span style="color:#75715e">// Sort characters by frequency
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// Place most frequent on home row positions (9-17)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">homeRowPositions&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> []&lt;span style="color:#66d9ef">int&lt;/span>{&lt;span style="color:#ae81ff">9&lt;/span>, &lt;span style="color:#ae81ff">10&lt;/span>, &lt;span style="color:#ae81ff">11&lt;/span>, &lt;span style="color:#ae81ff">12&lt;/span>, &lt;span style="color:#ae81ff">13&lt;/span>, &lt;span style="color:#ae81ff">14&lt;/span>, &lt;span style="color:#ae81ff">15&lt;/span>, &lt;span style="color:#ae81ff">16&lt;/span>, &lt;span style="color:#ae81ff">17&lt;/span>}
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">i&lt;/span>, &lt;span style="color:#a6e22e">pos&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">homeRowPositions&lt;/span> {
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">i&lt;/span> &amp;lt; len(&lt;span style="color:#a6e22e">frequencies&lt;/span>) &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">pos&lt;/span> &amp;lt; len(&lt;span style="color:#a6e22e">result&lt;/span>) {
&lt;span style="color:#a6e22e">result&lt;/span>[&lt;span style="color:#a6e22e">pos&lt;/span>] = &lt;span style="color:#a6e22e">frequencies&lt;/span>[&lt;span style="color:#a6e22e">freqIndex&lt;/span>].&lt;span style="color:#a6e22e">char&lt;/span>
}
}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="2-hand-balance-strategy">2. &lt;strong>Hand Balance Strategy&lt;/strong>&lt;/h4>
&lt;p>Alternates frequent characters between hands to promote typing rhythm:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Alternate placing frequent characters between hands
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">i&lt;/span>, &lt;span style="color:#a6e22e">cf&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">frequencies&lt;/span> {
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">i&lt;/span>&lt;span style="color:#f92672">%&lt;/span>&lt;span style="color:#ae81ff">2&lt;/span> &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> &lt;span style="color:#a6e22e">leftIndex&lt;/span> &amp;lt; len(&lt;span style="color:#a6e22e">leftHand&lt;/span>) {
&lt;span style="color:#a6e22e">result&lt;/span>[&lt;span style="color:#a6e22e">leftHand&lt;/span>[&lt;span style="color:#a6e22e">leftIndex&lt;/span>]] = &lt;span style="color:#a6e22e">cf&lt;/span>.&lt;span style="color:#a6e22e">char&lt;/span>
} &lt;span style="color:#66d9ef">else&lt;/span> &lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">rightIndex&lt;/span> &amp;lt; len(&lt;span style="color:#a6e22e">rightHand&lt;/span>) {
&lt;span style="color:#a6e22e">result&lt;/span>[&lt;span style="color:#a6e22e">rightHand&lt;/span>[&lt;span style="color:#a6e22e">rightIndex&lt;/span>]] = &lt;span style="color:#a6e22e">cf&lt;/span>.&lt;span style="color:#a6e22e">char&lt;/span>
}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="3-anti-qwerty-rebellion">3. &lt;strong>Anti-QWERTY Rebellion&lt;/strong>&lt;/h4>
&lt;p>Creates layouts maximally different from QWERTY as a form of &amp;ldquo;genetic diversity&amp;rdquo; (because sometimes the best way forward is to do the exact opposite of what everyone else is doing):&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">createAntiQWERTYLayout&lt;/span>(&lt;span style="color:#a6e22e">charset&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">CharacterSet&lt;/span>) []&lt;span style="color:#66d9ef">rune&lt;/span> {
&lt;span style="color:#75715e">// Place characters as far as possible from their QWERTY positions
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">targetPos&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> (&lt;span style="color:#a6e22e">i&lt;/span> &lt;span style="color:#f92672">+&lt;/span> len(&lt;span style="color:#a6e22e">result&lt;/span>)&lt;span style="color:#f92672">/&lt;/span>&lt;span style="color:#ae81ff">2&lt;/span>) &lt;span style="color:#f92672">%&lt;/span> len(&lt;span style="color:#a6e22e">result&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="selection-natures-quality-control">Selection: Nature&amp;rsquo;s Quality Control&lt;/h3>
&lt;p>The algorithm employs &lt;strong>tournament selection&lt;/strong>—imagine gladiatorial combat where the fittest layouts battle for reproductive rights (except with more statistics and less blood):&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">s&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Selector&lt;/span>) &lt;span style="color:#a6e22e">tournamentSelect&lt;/span>(&lt;span style="color:#a6e22e">population&lt;/span> &lt;span style="color:#a6e22e">Population&lt;/span>, &lt;span style="color:#a6e22e">count&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>) []&lt;span style="color:#a6e22e">Individual&lt;/span> {
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">count&lt;/span> {
&lt;span style="color:#75715e">// Create tournament of size 3-7 individuals
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">tournament&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> make([]&lt;span style="color:#a6e22e">Individual&lt;/span>, &lt;span style="color:#a6e22e">s&lt;/span>.&lt;span style="color:#a6e22e">config&lt;/span>.&lt;span style="color:#a6e22e">TournamentSize&lt;/span>)
&lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">j&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#66d9ef">range&lt;/span> &lt;span style="color:#a6e22e">s&lt;/span>.&lt;span style="color:#a6e22e">config&lt;/span>.&lt;span style="color:#a6e22e">TournamentSize&lt;/span> {
&lt;span style="color:#a6e22e">tournament&lt;/span>[&lt;span style="color:#a6e22e">j&lt;/span>] = &lt;span style="color:#a6e22e">population&lt;/span>[&lt;span style="color:#a6e22e">rand&lt;/span>.&lt;span style="color:#a6e22e">IntN&lt;/span>(len(&lt;span style="color:#a6e22e">population&lt;/span>))]
}
&lt;span style="color:#75715e">// Winner takes all
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">best&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">findBestInTournament&lt;/span>(&lt;span style="color:#a6e22e">tournament&lt;/span>)
&lt;span style="color:#a6e22e">selected&lt;/span> = append(&lt;span style="color:#a6e22e">selected&lt;/span>, &lt;span style="color:#a6e22e">best&lt;/span>.&lt;span style="color:#a6e22e">Clone&lt;/span>())
}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Why Tournament Selection?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Maintains diversity&lt;/strong>: Even suboptimal individuals can win small tournaments&lt;/li>
&lt;li>&lt;strong>Scales well&lt;/strong>: Works efficiently with large populations&lt;/li>
&lt;li>&lt;strong>Configurable pressure&lt;/strong>: Tournament size controls selection intensity&lt;/li>
&lt;/ul>
&lt;h2 id="-crossover-the-art-of-genetic-mixing">🧬 Crossover: The Art of Genetic Mixing&lt;/h2>
&lt;p>Here&amp;rsquo;s where it gets really interesting. We can&amp;rsquo;t just cut and paste keyboard layouts like traditional genetic algorithms—every character must appear exactly once. (No duplicating the letter &amp;lsquo;e&amp;rsquo; five times, even though it would make Wheel of Fortune easier.) Enter &lt;strong>specialized crossover operators&lt;/strong>:&lt;/p>
&lt;h3 id="order-crossover-ox-the-sequence-preserver">Order Crossover (OX): The Sequence Preserver&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">c&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Crossover&lt;/span>) &lt;span style="color:#a6e22e">orderCrossover&lt;/span>(&lt;span style="color:#a6e22e">parent1&lt;/span>, &lt;span style="color:#a6e22e">parent2&lt;/span> &lt;span style="color:#a6e22e">Individual&lt;/span>) &lt;span style="color:#a6e22e">Individual&lt;/span> {
&lt;span style="color:#75715e">// Choose random crossover segment
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">point1&lt;/span>, &lt;span style="color:#a6e22e">point2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">rand&lt;/span>.&lt;span style="color:#a6e22e">IntN&lt;/span>(&lt;span style="color:#a6e22e">length&lt;/span>), &lt;span style="color:#a6e22e">rand&lt;/span>.&lt;span style="color:#a6e22e">IntN&lt;/span>(&lt;span style="color:#a6e22e">length&lt;/span>)
&lt;span style="color:#75715e">// Copy segment from parent1
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">i&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">point1&lt;/span>; &lt;span style="color:#a6e22e">i&lt;/span> &lt;span style="color:#f92672">&amp;lt;=&lt;/span> &lt;span style="color:#a6e22e">point2&lt;/span>; &lt;span style="color:#a6e22e">i&lt;/span>&lt;span style="color:#f92672">++&lt;/span> {
&lt;span style="color:#a6e22e">child&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">i&lt;/span>] = &lt;span style="color:#a6e22e">parent1&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">i&lt;/span>]
&lt;span style="color:#a6e22e">used&lt;/span>[&lt;span style="color:#a6e22e">parent1&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">i&lt;/span>]] = &lt;span style="color:#66d9ef">true&lt;/span>
}
&lt;span style="color:#75715e">// Fill remaining positions from parent2 in order
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// This preserves character sequences while mixing layouts
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="partially-matched-crossover-pmx-the-conflict-resolver">Partially Matched Crossover (PMX): The Conflict Resolver&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">c&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Crossover&lt;/span>) &lt;span style="color:#a6e22e">partiallyMatchedCrossover&lt;/span>(&lt;span style="color:#a6e22e">parent1&lt;/span>, &lt;span style="color:#a6e22e">parent2&lt;/span> &lt;span style="color:#a6e22e">Individual&lt;/span>) &lt;span style="color:#a6e22e">Individual&lt;/span> {
&lt;span style="color:#75715e">// Create mapping between conflicting positions
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">i&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">point1&lt;/span>; &lt;span style="color:#a6e22e">i&lt;/span> &lt;span style="color:#f92672">&amp;lt;=&lt;/span> &lt;span style="color:#a6e22e">point2&lt;/span>; &lt;span style="color:#a6e22e">i&lt;/span>&lt;span style="color:#f92672">++&lt;/span> {
&lt;span style="color:#a6e22e">char1&lt;/span>, &lt;span style="color:#a6e22e">char2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">parent1&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">i&lt;/span>], &lt;span style="color:#a6e22e">parent2&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">i&lt;/span>]
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">char1&lt;/span> &lt;span style="color:#f92672">!=&lt;/span> &lt;span style="color:#a6e22e">char2&lt;/span> {
&lt;span style="color:#a6e22e">mapping&lt;/span>[&lt;span style="color:#a6e22e">char1&lt;/span>] = &lt;span style="color:#a6e22e">char2&lt;/span>
&lt;span style="color:#a6e22e">mapping&lt;/span>[&lt;span style="color:#a6e22e">char2&lt;/span>] = &lt;span style="color:#a6e22e">char1&lt;/span>
}
}
&lt;span style="color:#75715e">// Resolve conflicts using the mapping
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// This maintains position relationships while avoiding duplicates
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="cycle-crossover-cx-the-position-maintainer">Cycle Crossover (CX): The Position Maintainer&lt;/h3>
&lt;p>The most sophisticated approach that maintains positional relationships:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">c&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Crossover&lt;/span>) &lt;span style="color:#a6e22e">cycleCrossover&lt;/span>(&lt;span style="color:#a6e22e">parent1&lt;/span>, &lt;span style="color:#a6e22e">parent2&lt;/span> &lt;span style="color:#a6e22e">Individual&lt;/span>) &lt;span style="color:#a6e22e">Individual&lt;/span> {
&lt;span style="color:#75715e">// Find cycles of character positions
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// Alternate between parents for different cycles
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// Preserves the relationship between characters and positions
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>The Magic&lt;/strong>: Each crossover method preserves different genetic properties while ensuring valid keyboard layouts. The algorithm can switch between them or use them in combination.&lt;/p>
&lt;h2 id="-mutation-controlled-chaos-for-innovation">🎲 Mutation: Controlled Chaos for Innovation&lt;/h2>
&lt;p>Mutation prevents the population from converging too quickly and introduces beneficial randomness:&lt;/p>
&lt;h3 id="the-mutation-arsenal">The Mutation Arsenal&lt;/h3>
&lt;h4 id="1-swap-mutation-simple-and-effective">1. &lt;strong>Swap Mutation&lt;/strong>: Simple and Effective&lt;/h4>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">m&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Mutator&lt;/span>) &lt;span style="color:#a6e22e">swapMutation&lt;/span>(&lt;span style="color:#a6e22e">individual&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Individual&lt;/span>) {
&lt;span style="color:#a6e22e">pos1&lt;/span>, &lt;span style="color:#a6e22e">pos2&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">rand&lt;/span>.&lt;span style="color:#a6e22e">IntN&lt;/span>(&lt;span style="color:#a6e22e">length&lt;/span>), &lt;span style="color:#a6e22e">rand&lt;/span>.&lt;span style="color:#a6e22e">IntN&lt;/span>(&lt;span style="color:#a6e22e">length&lt;/span>)
&lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>] =
&lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>], &lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>]
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="2-insertion-mutation-positional-shuffling">2. &lt;strong>Insertion Mutation&lt;/strong>: Positional Shuffling&lt;/h4>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">m&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Mutator&lt;/span>) &lt;span style="color:#a6e22e">insertionMutation&lt;/span>(&lt;span style="color:#a6e22e">individual&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Individual&lt;/span>) {
&lt;span style="color:#75715e">// Remove character from one position
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">element&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">sourcePos&lt;/span>]
&lt;span style="color:#75715e">// Shift other characters to make room
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#75715e">// Insert at new position
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">destPos&lt;/span>] = &lt;span style="color:#a6e22e">element&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="3-inversion-mutation-sequence-reversal">3. &lt;strong>Inversion Mutation&lt;/strong>: Sequence Reversal&lt;/h4>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">m&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Mutator&lt;/span>) &lt;span style="color:#a6e22e">inversionMutation&lt;/span>(&lt;span style="color:#a6e22e">individual&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">Individual&lt;/span>) {
&lt;span style="color:#75715e">// Reverse a random subsequence
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">pos1&lt;/span> &amp;lt; &lt;span style="color:#a6e22e">pos2&lt;/span> {
&lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>], &lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>] =
&lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">pos2&lt;/span>], &lt;span style="color:#a6e22e">individual&lt;/span>.&lt;span style="color:#a6e22e">Layout&lt;/span>[&lt;span style="color:#a6e22e">pos1&lt;/span>]
&lt;span style="color:#a6e22e">pos1&lt;/span>&lt;span style="color:#f92672">++&lt;/span>
&lt;span style="color:#a6e22e">pos2&lt;/span>&lt;span style="color:#f92672">--&lt;/span>
}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="adaptive-mutation-smart-randomness">Adaptive Mutation: Smart Randomness&lt;/h3>
&lt;p>The system adjusts mutation rates based on population diversity:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">am&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">AdaptiveMutator&lt;/span>) &lt;span style="color:#a6e22e">Apply&lt;/span>(&lt;span style="color:#a6e22e">individual&lt;/span> &lt;span style="color:#a6e22e">Individual&lt;/span>, &lt;span style="color:#a6e22e">populationDiversity&lt;/span> &lt;span style="color:#66d9ef">float64&lt;/span>) &lt;span style="color:#a6e22e">Individual&lt;/span> {
&lt;span style="color:#a6e22e">diversityRatio&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">populationDiversity&lt;/span> &lt;span style="color:#f92672">/&lt;/span> &lt;span style="color:#a6e22e">am&lt;/span>.&lt;span style="color:#a6e22e">diversityTarget&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">diversityRatio&lt;/span> &amp;lt; &lt;span style="color:#ae81ff">1.0&lt;/span> {
&lt;span style="color:#75715e">// Low diversity - increase mutation rate for exploration
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">adjustedRate&lt;/span> = &lt;span style="color:#a6e22e">am&lt;/span>.&lt;span style="color:#a6e22e">minRate&lt;/span> &lt;span style="color:#f92672">+&lt;/span> (&lt;span style="color:#a6e22e">am&lt;/span>.&lt;span style="color:#a6e22e">maxRate&lt;/span>&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">am&lt;/span>.&lt;span style="color:#a6e22e">minRate&lt;/span>)&lt;span style="color:#f92672">*&lt;/span>(&lt;span style="color:#ae81ff">1.0&lt;/span>&lt;span style="color:#f92672">-&lt;/span>&lt;span style="color:#a6e22e">diversityRatio&lt;/span>)
} &lt;span style="color:#66d9ef">else&lt;/span> {
&lt;span style="color:#75715e">// High diversity - use minimum rate for exploitation
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">adjustedRate&lt;/span> = &lt;span style="color:#a6e22e">am&lt;/span>.&lt;span style="color:#a6e22e">minRate&lt;/span>
}
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>The Intelligence&lt;/strong>: When the population becomes too similar (low diversity), mutation rates increase to encourage exploration. When diversity is high, mutation rates decrease to allow refinement. (It&amp;rsquo;s like having a smart thermostat, but for genetic chaos!)&lt;/p>
&lt;h2 id="-neural-configuration-strategies-advanced-evolutionary-hyperparameter-optimization">📊 Neural Configuration Strategies: Advanced Evolutionary Hyperparameter Optimization&lt;/h2>
&lt;h3 id="adaptive-configuration-based-on-data-size">Adaptive Configuration Based on Data Size&lt;/h3>
&lt;p>The system automatically adjusts its parameters based on your typing data:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">AdaptiveConfig&lt;/span>(&lt;span style="color:#a6e22e">dataSize&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>) &lt;span style="color:#a6e22e">Config&lt;/span> {
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#a6e22e">dataSize&lt;/span> &amp;gt; &lt;span style="color:#ae81ff">100000&lt;/span> { &lt;span style="color:#75715e">// Large dataset (Harry Potter level)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">Config&lt;/span>{
&lt;span style="color:#a6e22e">PopulationSize&lt;/span>: &lt;span style="color:#ae81ff">500&lt;/span>, &lt;span style="color:#75715e">// Large diversity
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">MaxGenerations&lt;/span>: &lt;span style="color:#ae81ff">100&lt;/span>, &lt;span style="color:#75715e">// Quality over quantity
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">MutationRate&lt;/span>: &lt;span style="color:#ae81ff">0.3&lt;/span>, &lt;span style="color:#75715e">// High exploration
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">CrossoverRate&lt;/span>: &lt;span style="color:#ae81ff">0.9&lt;/span>, &lt;span style="color:#75715e">// Aggressive mixing
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">ElitismCount&lt;/span>: &lt;span style="color:#ae81ff">2&lt;/span>, &lt;span style="color:#75715e">// Prevent premature dominance
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">TournamentSize&lt;/span>: &lt;span style="color:#ae81ff">7&lt;/span>, &lt;span style="color:#75715e">// Strong selection pressure
&lt;/span>&lt;span style="color:#75715e">&lt;/span> }
}
&lt;span style="color:#75715e">// Medium and small datasets get different configurations...
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="convergence-detection-knowing-when-to-stop">Convergence Detection: Knowing When to Stop&lt;/h3>
&lt;p>The algorithm includes intelligent stopping criteria:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">Config&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">ConvergenceStops&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span> &lt;span style="color:#75715e">// Stop after N stagnant generations
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">ConvergenceTolerance&lt;/span> &lt;span style="color:#66d9ef">float64&lt;/span> &lt;span style="color:#75715e">// Fitness improvement threshold
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>The Logic&lt;/strong>: If fitness doesn&amp;rsquo;t improve by more than &lt;code>ConvergenceTolerance&lt;/code> for &lt;code>ConvergenceStops&lt;/code> consecutive generations, the algorithm declares convergence and terminates gracefully.&lt;/p>
&lt;h2 id="-parallel-evolution-scaling-performance">🔄 Parallel Evolution: Scaling Performance&lt;/h2>
&lt;p>The system leverages Go&amp;rsquo;s concurrency for parallel fitness evaluation:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> (&lt;span style="color:#a6e22e">pe&lt;/span> &lt;span style="color:#f92672">*&lt;/span>&lt;span style="color:#a6e22e">ParallelEvaluator&lt;/span>) &lt;span style="color:#a6e22e">EvaluatePopulation&lt;/span>(&lt;span style="color:#a6e22e">population&lt;/span> &lt;span style="color:#a6e22e">Population&lt;/span>) {
&lt;span style="color:#75715e">// Create worker pool
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">jobs&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> make(&lt;span style="color:#66d9ef">chan&lt;/span> &lt;span style="color:#a6e22e">Individual&lt;/span>, len(&lt;span style="color:#a6e22e">population&lt;/span>))
&lt;span style="color:#a6e22e">results&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> make(&lt;span style="color:#66d9ef">chan&lt;/span> &lt;span style="color:#a6e22e">Individual&lt;/span>, len(&lt;span style="color:#a6e22e">population&lt;/span>))
&lt;span style="color:#75715e">// Launch parallel workers
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">w&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>; &lt;span style="color:#a6e22e">w&lt;/span> &amp;lt; &lt;span style="color:#a6e22e">pe&lt;/span>.&lt;span style="color:#a6e22e">config&lt;/span>.&lt;span style="color:#a6e22e">ParallelWorkers&lt;/span>; &lt;span style="color:#a6e22e">w&lt;/span>&lt;span style="color:#f92672">++&lt;/span> {
&lt;span style="color:#66d9ef">go&lt;/span> &lt;span style="color:#a6e22e">pe&lt;/span>.&lt;span style="color:#a6e22e">worker&lt;/span>(&lt;span style="color:#a6e22e">jobs&lt;/span>, &lt;span style="color:#a6e22e">results&lt;/span>)
}
&lt;span style="color:#75715e">// Process all individuals in parallel
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Performance Impact&lt;/strong>: On multi-core systems, this achieves 4-8x &lt;strong>computational acceleration&lt;/strong>, making the &lt;strong>neural algorithm&lt;/strong> practical for large populations and complex &lt;strong>neural fitness functions&lt;/strong>. (Finally, all those expensive CPU cores are doing something more intellectually stimulating than heating your room!)&lt;/p>
&lt;h2 id="-population-management-balancing-elite-and-diversity">🎯 Population Management: Balancing Elite and Diversity&lt;/h2>
&lt;p>The algorithm maintains population quality through sophisticated survivor selection:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">SelectSurvivors&lt;/span>(&lt;span style="color:#a6e22e">oldPop&lt;/span>, &lt;span style="color:#a6e22e">newPop&lt;/span> &lt;span style="color:#a6e22e">Population&lt;/span>, &lt;span style="color:#a6e22e">config&lt;/span> &lt;span style="color:#a6e22e">Config&lt;/span>) &lt;span style="color:#a6e22e">Population&lt;/span> {
&lt;span style="color:#75715e">// Combine old and new populations
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">combined&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> append(&lt;span style="color:#a6e22e">oldPop&lt;/span>, &lt;span style="color:#a6e22e">newPop&lt;/span>&lt;span style="color:#f92672">...&lt;/span>)
&lt;span style="color:#75715e">// Sort by fitness
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">sort&lt;/span>.&lt;span style="color:#a6e22e">Slice&lt;/span>(&lt;span style="color:#a6e22e">combined&lt;/span>, &lt;span style="color:#66d9ef">func&lt;/span>(&lt;span style="color:#a6e22e">i&lt;/span>, &lt;span style="color:#a6e22e">j&lt;/span> &lt;span style="color:#66d9ef">int&lt;/span>) &lt;span style="color:#66d9ef">bool&lt;/span> {
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#a6e22e">combined&lt;/span>[&lt;span style="color:#a6e22e">i&lt;/span>].&lt;span style="color:#a6e22e">Fitness&lt;/span> &amp;gt; &lt;span style="color:#a6e22e">combined&lt;/span>[&lt;span style="color:#a6e22e">j&lt;/span>].&lt;span style="color:#a6e22e">Fitness&lt;/span>
})
&lt;span style="color:#75715e">// Always preserve elite individuals
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> &lt;span style="color:#a6e22e">i&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>; &lt;span style="color:#a6e22e">i&lt;/span> &amp;lt; &lt;span style="color:#a6e22e">config&lt;/span>.&lt;span style="color:#a6e22e">ElitismCount&lt;/span>; &lt;span style="color:#a6e22e">i&lt;/span>&lt;span style="color:#f92672">++&lt;/span> {
&lt;span style="color:#a6e22e">survivors&lt;/span> = append(&lt;span style="color:#a6e22e">survivors&lt;/span>, &lt;span style="color:#a6e22e">combined&lt;/span>[&lt;span style="color:#a6e22e">i&lt;/span>].&lt;span style="color:#a6e22e">Clone&lt;/span>())
}
&lt;span style="color:#75715e">// Fill remaining slots with diverse selection
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">remaining&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">config&lt;/span>.&lt;span style="color:#a6e22e">PopulationSize&lt;/span> &lt;span style="color:#f92672">-&lt;/span> &lt;span style="color:#a6e22e">config&lt;/span>.&lt;span style="color:#a6e22e">ElitismCount&lt;/span>
&lt;span style="color:#a6e22e">selector&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">NewSelector&lt;/span>(&lt;span style="color:#a6e22e">TournamentSelection&lt;/span>, &lt;span style="color:#a6e22e">config&lt;/span>)
&lt;span style="color:#a6e22e">selected&lt;/span> &lt;span style="color:#f92672">:=&lt;/span> &lt;span style="color:#a6e22e">selector&lt;/span>.&lt;span style="color:#a6e22e">Select&lt;/span>(&lt;span style="color:#a6e22e">combined&lt;/span>[&lt;span style="color:#a6e22e">config&lt;/span>.&lt;span style="color:#a6e22e">ElitismCount&lt;/span>:], &lt;span style="color:#a6e22e">remaining&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>The Neural Balance&lt;/strong>: &lt;strong>Elite preservation&lt;/strong> ensures optimal &lt;strong>neural solutions&lt;/strong> survive while &lt;strong>diverse selection&lt;/strong> prevents population homogenization through &lt;strong>genetic bottlenecking&lt;/strong>. (It&amp;rsquo;s like maintaining a healthy ecosystem, but instead of protecting endangered species, we&amp;rsquo;re protecting endangered keyboard layouts.)&lt;/p>
&lt;h2 id="-the-evolution-in-action">🔮 The Evolution in Action&lt;/h2>
&lt;p>Here&amp;rsquo;s what a typical &lt;strong>neural evolution&lt;/strong> trajectory demonstrates:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Generation 0&lt;/strong>: &lt;strong>Wild genetic diversity&lt;/strong>, random &lt;strong>neural fitness&lt;/strong> scores (complete chaos, like a keyboard designed by caffeinated monkeys)&lt;/li>
&lt;li>&lt;strong>Generations 1-20&lt;/strong>: &lt;strong>Rapid improvement&lt;/strong> as &lt;strong>basic optimization patterns&lt;/strong> emerge through &lt;strong>machine learning&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Generations 20-60&lt;/strong>: &lt;strong>Refinement phase&lt;/strong> with smaller but &lt;strong>consistent neural gains&lt;/strong> through &lt;strong>adaptive learning&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Generations 60+&lt;/strong>: &lt;strong>Fine-tuning optimization&lt;/strong>, &lt;strong>neural convergence detection&lt;/strong> activates intelligent termination&lt;/li>
&lt;/ol>
&lt;p>The &lt;strong>neural-evolutionary algorithm&lt;/strong> typically discovers &lt;strong>excellent solutions&lt;/strong> within 100 generations through &lt;strong>intelligent search&lt;/strong>, but &lt;strong>complex behavioral datasets&lt;/strong> may require 500+ generations for &lt;strong>globally optimal results&lt;/strong> and &lt;strong>convergence guarantees&lt;/strong>. (It&amp;rsquo;s like the difference between solving a crossword puzzle and writing a doctoral thesis—both involve lots of thinking, but one requires significantly more coffee and existential contemplation.)&lt;/p>
&lt;h2 id="-why-neural-evolutionary-approaches-excel-computational-intelligence-advantages">🎲 Why Neural-Evolutionary Approaches Excel: Computational Intelligence Advantages&lt;/h2>
&lt;p>&lt;strong>Neural-genetic algorithms excel at keyboard optimization through advanced computational intelligence:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Global Search Optimization&lt;/strong>: Unlike hill-climbing algorithms, &lt;strong>neural-GA&lt;/strong> can escape &lt;strong>local optima&lt;/strong> through &lt;strong>stochastic exploration&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Population-Based Intelligence&lt;/strong>: Multiple &lt;strong>neural solutions&lt;/strong> evolve simultaneously through &lt;strong>parallel optimization&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Implicit Parallel Processing&lt;/strong>: Each &lt;strong>neural agent&lt;/strong> explores different &lt;strong>solution subspaces&lt;/strong> concurrently&lt;/li>
&lt;li>&lt;strong>Adaptive Learning Behavior&lt;/strong>: The system &lt;strong>learns and adapts&lt;/strong> to your specific &lt;strong>behavioral typing patterns&lt;/strong> through &lt;strong>machine learning&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Intelligent Constraint Handling&lt;/strong>: Built-in &lt;strong>neural validation&lt;/strong> ensures only &lt;strong>legally valid keyboard layouts&lt;/strong> through &lt;strong>constraint satisfaction algorithms&lt;/strong>&lt;/li>
&lt;/ol>
&lt;h2 id="-the-journey-continues">🔗 The Journey Continues&lt;/h2>
&lt;p>This genetic engine is just one piece of the optimization puzzle. The real magic happens when it combines with our sophisticated fitness function—a multi-dimensional evaluation system that considers everything from finger distance to same-finger bigrams, roll quality to layer penalties.&lt;/p>
&lt;p>&lt;strong>Ready to dive deeper into how the algorithm actually measures layout quality?&lt;/strong>
&lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-fitness-function-and-kpis">Discover the KPI-Driven Fitness Function: The Science Behind Perfect Typing →&lt;/a>&lt;/strong>&lt;/p>
&lt;h2 id="-complete-technical-series">🗺️ Complete Technical Series&lt;/h2>
&lt;p>&lt;strong>📚 Deep-Dive Navigation:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>&lt;a href="https://blog.moulard.org/qwerty-is-outdated">System Overview&lt;/a>&lt;/strong> - See the complete AI-powered keyboard optimization&lt;/li>
&lt;li>&lt;strong>This Post: Genetic Algorithm Engine&lt;/strong> - Master the evolutionary computing principles&lt;/li>
&lt;li>&lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-fitness-function-and-kpis">Fitness Function &amp;amp; KPIs&lt;/a>&lt;/strong> - Understand the 12-dimensional evaluation system&lt;/li>
&lt;/ol></description></item><item><title>Revolutionary AI Keyboard Optimization: Neural-Genetic Algorithms Outperform QWERTY by 34.8%</title><link>https://blog.moulard.org/qwerty-is-outdated/</link><pubDate>Sat, 09 Aug 2025 00:00:00 +0200</pubDate><guid>https://blog.moulard.org/qwerty-is-outdated/</guid><comments>https://blog.moulard.org/qwerty-is-outdated/#disqus_thread</comments><description>&lt;h2 id="qwerty-was-designed-for-typewriters-in-1873---why-are-we-still-using-it">QWERTY Was Designed for Typewriters in 1873 - Why Are We Still Using It?!&lt;/h2>
&lt;p>&lt;strong>Every day, programmers execute millions of keystrokes on a layout designed for 1873 mechanical typewriters.&lt;/strong> This represents a massive optimization opportunity for AI-driven personalization and adaptive learning systems.&lt;/p>
&lt;p>Using &lt;strong>evolutionary AI, neural network principles, and deep reinforcement learning&lt;/strong>, we can engineer keyboard layouts &lt;strong>34.8% more efficient&lt;/strong> than QWERTY through &lt;strong>personalized machine learning models&lt;/strong> trained on individual typing patterns. This breakthrough combines &lt;strong>population-based metaheuristics&lt;/strong> with &lt;strong>adaptive neural optimization&lt;/strong>.&lt;/p>
&lt;p>&lt;strong>KeyBoardGen&lt;/strong> is a &lt;strong>neural-genetic hybrid AI system&lt;/strong> that combines &lt;strong>evolutionary computation&lt;/strong>, &lt;strong>deep learning architectures&lt;/strong>, and &lt;strong>reinforcement learning&lt;/strong> to analyze typing behavioral data and evolve optimal keyboard layouts. Through &lt;strong>unsupervised feature learning&lt;/strong> and &lt;strong>population-based optimization&lt;/strong>, the system processed 242,608 keystrokes in 3 minutes using &lt;strong>adaptive metaheuristic algorithms&lt;/strong> and &lt;strong>multi-objective evolutionary optimization&lt;/strong>.&lt;/p>
&lt;h2 id="the-problem-qwertys-dark-secret">The Problem: QWERTY&amp;rsquo;s Dark Secret&lt;/h2>
&lt;p>QWERTY wasn&amp;rsquo;t designed for speed - quite the opposite! Its creator, Christopher Latham Sholes, intentionally separated common letter pairs to prevent typewriter key jams. (Imagine designing a highway to make cars go slower - that&amp;rsquo;s basically QWERTY!) Here&amp;rsquo;s what&amp;rsquo;s wrong with QWERTY for modern typing:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Only 21.6% home row usage&lt;/strong> - your strongest fingers are underutilized&lt;/li>
&lt;li>&lt;strong>Poor hand alternation at 27.4%&lt;/strong> - creating awkward same-hand sequences&lt;/li>
&lt;li>&lt;strong>Suboptimal character placement&lt;/strong> - &amp;lsquo;e&amp;rsquo; (most common letter) requires a finger stretch&lt;/li>
&lt;/ul>
&lt;h2 id="the-solution-evolutionary-ai-meets-deep-learning">The Solution: Evolutionary AI Meets Deep Learning&lt;/h2>
&lt;p>KeyBoardGen employs &lt;strong>bio-inspired computational intelligence&lt;/strong> - a &lt;strong>neural-evolutionary hybrid architecture&lt;/strong> combining &lt;strong>genetic algorithms&lt;/strong>, &lt;strong>deep neural networks&lt;/strong>, and &lt;strong>swarm intelligence&lt;/strong>. The &lt;strong>AI model performs unsupervised representation learning&lt;/strong> on actual typing behavioral data, utilizing &lt;strong>adaptive feature extraction&lt;/strong>, &lt;strong>pattern mining&lt;/strong>, &lt;strong>transfer learning&lt;/strong>, and &lt;strong>multi-modal data fusion&lt;/strong> rather than static frequency analysis.&lt;/p>
&lt;p>&lt;strong>Want to understand how this genetic engine actually works under the hood?&lt;/strong>
&lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-genetic-algorithm-deep-dive">Dive deep into the genetic algorithm implementation →&lt;/a>&lt;/strong>&lt;/p>
&lt;h3 id="neural-genetic-hybrid-architecture-advanced-ai-system-design">Neural-Genetic Hybrid Architecture: Advanced AI System Design&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#75715e">// Neural-genetic hyperparameters for adaptive AI optimization
&lt;/span>&lt;span style="color:#75715e">&lt;/span>&lt;span style="color:#66d9ef">type&lt;/span> &lt;span style="color:#a6e22e">NeuralGeneticConfig&lt;/span> &lt;span style="color:#66d9ef">struct&lt;/span> {
&lt;span style="color:#a6e22e">PopulationSize&lt;/span>: &lt;span style="color:#ae81ff">2000&lt;/span>, &lt;span style="color:#75715e">// Multi-agent swarm intelligence
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">MaxGenerations&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;unlimited&amp;#34;&lt;/span>, &lt;span style="color:#75715e">// Adaptive early stopping with neural convergence detection
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">MutationRate&lt;/span>: &lt;span style="color:#ae81ff">0.30&lt;/span>, &lt;span style="color:#75715e">// Exploration-exploitation trade-off optimization
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">CrossoverRate&lt;/span>: &lt;span style="color:#ae81ff">0.90&lt;/span>, &lt;span style="color:#75715e">// Genetic information exchange coefficient
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">EliteCount&lt;/span>: &lt;span style="color:#ae81ff">2&lt;/span>, &lt;span style="color:#75715e">// Top-k elite preservation strategy
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">ParallelWorkers&lt;/span>: &lt;span style="color:#ae81ff">8&lt;/span>, &lt;span style="color:#75715e">// Distributed parallel processing architecture
&lt;/span>&lt;span style="color:#75715e">&lt;/span>}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>The &lt;strong>neural-genetic hybrid system&lt;/strong> employs cutting-edge &lt;strong>computational intelligence techniques&lt;/strong>:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Multi-Objective Tournament Selection&lt;/strong> - Pareto-optimal fitness evaluation with neural network-guided selection&lt;/li>
&lt;li>&lt;strong>Order Crossover with Neural Enhancement (OX++)&lt;/strong> - Constraint-preserving genetic recombination with deep learning bias&lt;/li>
&lt;li>&lt;strong>Adaptive Neural Mutation&lt;/strong> - Dynamic exploration using reinforcement learning and simulated annealing&lt;/li>
&lt;li>&lt;strong>Elite Neural Preservation&lt;/strong> - Top-k selection with gradient-free optimization and neural memory&lt;/li>
&lt;li>&lt;strong>Intelligent Convergence Detection&lt;/strong> - Early stopping via stochastic optimization and neural convergence analysis&lt;/li>
&lt;/ol>
&lt;h3 id="neural-genetic-training-performance-real-world-ai-results">Neural-Genetic Training Performance: Real-World AI Results&lt;/h3>
&lt;p>Here&amp;rsquo;s the &lt;strong>neural-genetic hybrid training session&lt;/strong> on programming behavioral data with &lt;strong>adaptive AI optimization&lt;/strong>:&lt;/p>
&lt;pre>&lt;code>🧠 Neural-Genetic AI: Unsupervised feature learning from behavioral patterns...
📊 Training Dataset: 242,608 characters, 1,799 unique n-gram features
🤖 Initializing population-based metaheuristic with adaptive neural guidance: 2,000 intelligent agents
Epoch 0: Fitness = 0.657273 (Loss: 0.342727, Time: 1s) [NEURAL INITIALIZATION]
Epoch 50: Fitness = 0.724053 (Loss: 0.275947, Time: 30s) [ADAPTIVE LEARNING]
Epoch 100: Fitness = 0.745769 (Loss: 0.254231, Time: 59s) [NEURAL CONVERGENCE]
Epoch 200: Fitness = 0.755937 (Loss: 0.244063, Time: 1m58s) [REINFORCEMENT TUNING]
Epoch 294: Fitness = 0.757227 (Loss: 0.242773, Time: 2m55s) [AI CONVERGENCE]
🎯 Neural-Genetic Training Complete! Adaptive early stopping with convergence detection
📈 Final AI Performance: 0.757227 (34.8% improvement via evolutionary deep learning)
🧬 Evolutionary Generations: 294 with neural-guided gradient-free optimization
&lt;/code>&lt;/pre>&lt;h2 id="neural-genetic-ai-performance-advanced-benchmarking-results">Neural-Genetic AI Performance: Advanced Benchmarking Results&lt;/h2>
&lt;p>&lt;strong>AI-Driven Neural-Genetic Optimization vs Traditional Static Layouts:&lt;/strong>&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Neural-Genetic AI Metric&lt;/th>
&lt;th>Adaptive AI Model&lt;/th>
&lt;th>QWERTY Baseline&lt;/th>
&lt;th>ML Performance Gain&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Neural Fitness Score&lt;/strong>&lt;/td>
&lt;td>0.757227&lt;/td>
&lt;td>0.561661&lt;/td>
&lt;td>&lt;strong>+34.8%&lt;/strong> 🚀&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Adaptive Hand Alternation&lt;/strong>&lt;/td>
&lt;td>41.9%&lt;/td>
&lt;td>27.4%&lt;/td>
&lt;td>&lt;strong>+52.9%&lt;/strong> 📈&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Intelligent Home Row Usage&lt;/strong>&lt;/td>
&lt;td>53.3%&lt;/td>
&lt;td>21.6%&lt;/td>
&lt;td>&lt;strong>+146.8%&lt;/strong> 🎯&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Deep Feature Learning&lt;/strong>&lt;/td>
&lt;td>1,799 n-grams&lt;/td>
&lt;td>Static design&lt;/td>
&lt;td>&lt;strong>AI-Adaptive&lt;/strong> ⚡&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="one-optimized-layout">One Optimized Layout&lt;/h3>
&lt;pre>&lt;code>x 3 [ t d h u l c q
a r ⇥ s i n o e `
&amp;lt; ] = m &amp;gt; @ ; 9 . )
&lt;/code>&lt;/pre>&lt;p>&lt;strong>AI-Discovered Neural Patterns:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Neural feature importance&lt;/strong>: Most frequent characters (&amp;lsquo;e&amp;rsquo;, &amp;rsquo;t', &amp;lsquo;a&amp;rsquo;, &amp;lsquo;r&amp;rsquo;, &amp;lsquo;i&amp;rsquo;, &amp;lsquo;n&amp;rsquo;) achieve optimal placement via deep reinforcement learning&lt;/li>
&lt;li>&lt;strong>Attention mechanism&lt;/strong>: Space bar positioned through reward maximization (11.6% frequency weight)&lt;/li>
&lt;li>&lt;strong>Transfer learning adaptation&lt;/strong>: Programming symbols optimized via domain-specific neural transfer learning&lt;/li>
&lt;li>&lt;strong>Unsupervised representations&lt;/strong>: 1,799 unique bigram features learned through neural pattern extraction and deep feature learning&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Curious about how these fitness scores are calculated? Each layout is evaluated across 12+ sophisticated KPIs:&lt;/strong>
&lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-fitness-function-and-kpis">Explore the complete fitness function breakdown →&lt;/a>&lt;/strong>&lt;/p>
&lt;h1 id="hands-on-implementation-train-your-personalized-neural-genetic-ai">Hands-On Implementation: Train Your Personalized Neural-Genetic AI&lt;/h1>
&lt;p>Ready to develop your &lt;strong>personalized neural-genetic AI optimizer&lt;/strong>? Here&amp;rsquo;s the complete machine learning pipeline:&lt;/p>
&lt;h2 id="step-1-data-collection--neural-feature-engineering">Step 1: Data Collection &amp;amp; Neural Feature Engineering&lt;/h2>
&lt;p>For optimal &lt;strong>neural model performance&lt;/strong>, collect your personal typing behavioral data. More diverse datasets enable better &lt;strong>unsupervised learning&lt;/strong> and &lt;strong>adaptive AI personalization&lt;/strong>.&lt;/p>
&lt;p>Create a &lt;strong>machine learning training dataset&lt;/strong> with representative typing patterns:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#75715e"># For programming&lt;/span>
echo &lt;span style="color:#e6db74">&amp;#39;function calculateDistance(x, y) {
&lt;/span>&lt;span style="color:#e6db74"> return Math.sqrt(x * x + y * y);
&lt;/span>&lt;span style="color:#e6db74">}
&lt;/span>&lt;span style="color:#e6db74">
&lt;/span>&lt;span style="color:#e6db74">const config = {
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;database&amp;#34;: &amp;#34;postgresql://localhost:5432/app&amp;#34;,
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;timeout&amp;#34;: 30000,
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;retry&amp;#34;: true
&lt;/span>&lt;span style="color:#e6db74">};&amp;#39;&lt;/span> &amp;gt; my_typing_data.txt
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="step-3-neural-genetic-ai-training">Step 3: Neural-Genetic AI Training&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">go run github.com/tommoulard/keyboardgen/cmd/keyboardgen -input my_typing_data.txt -output my_layout.json
&lt;span style="color:#75715e"># Launches neural-genetic hybrid AI with adaptive hyperparameter optimization&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="step-4-ai-model-performance-analysis">Step 4: AI Model Performance Analysis&lt;/h3>
&lt;p>The &lt;strong>neural-genetic AI pipeline&lt;/strong> outputs:&lt;/p>
&lt;ul>
&lt;li>Real-time loss minimization and fitness evolution tracking&lt;/li>
&lt;li>Neural convergence visualization with adaptive early stopping&lt;/li>
&lt;li>Your &lt;strong>personalized AI-optimized layout&lt;/strong> from the trained neural-genetic model&lt;/li>
&lt;li>Comprehensive performance benchmarks with statistical significance testing&lt;/li>
&lt;/ul>
&lt;h2 id="the-evolution-visualization">The Evolution Visualization&lt;/h2>
&lt;p>Watch your layout evolve in real-time:&lt;/p>
&lt;pre>&lt;code>Fitness Progress
0.7572 │ │
0.7520 │ ████████████████████████│
0.7467 │ █████████▓ │
0.7414 │ ██████▓ │
0.7362 │ ███▓ │
0.7309 │ ███▓ │
0.7257 │ █▓ │
0.7204 │ ████▓ │
0.7151 │ ██▓ │
0.7099 │ █▓ │
0.7046 │ █▓ │
0.6994 │ █▓ │
0.6941 │ ██▓ │
0.6888 │ ▓ │
0.6836 │ █▓ │
0.6783 │ ▓ │
0.6731 │ █▓ │
0.6678 │ ▓ │
0.6625 │ ▓ │
0.6573 │█▓ │
└────────────────────────────────────────────────────────────┘
0 40 80 120 160 200
Generation
&lt;/code>&lt;/pre>&lt;p>This chart shows the classic genetic algorithm convergence pattern - rapid initial improvement followed by fine-tuning optimizations.&lt;/p>
&lt;h2 id="why-this-matters-for-developers">Why This Matters for Developers&lt;/h2>
&lt;p>As developers, we spend 6-8 hours daily typing. A &lt;strong>34.8% efficiency improvement&lt;/strong> translates to:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Reduced finger fatigue&lt;/strong> from better ergonomics (your pinkies will finally forgive you)&lt;/li>
&lt;li>&lt;strong>Faster coding speed&lt;/strong> with optimal character placement&lt;/li>
&lt;li>&lt;strong>Fewer typing errors&lt;/strong> from improved hand alternation (goodbye, random semicolons!)&lt;/li>
&lt;li>&lt;strong>Better long-term hand health&lt;/strong> with balanced finger usage (your future 60-year-old self says thanks)&lt;/li>
&lt;/ul>
&lt;h2 id="future-of-adaptive-ai-personalized-neural-computing">Future of Adaptive AI: Personalized Neural Computing&lt;/h2>
&lt;p>KeyBoardGen pioneers the shift to &lt;strong>personalized computational intelligence&lt;/strong>. The future of &lt;strong>adaptive neural systems&lt;/strong> includes:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Domain-specific neural models&lt;/strong>: Transfer learning and fine-tuning for Python, JavaScript, Go optimization&lt;/li>
&lt;li>&lt;strong>Online adaptive learning&lt;/strong>: Real-time neural model updates via continuous reinforcement learning&lt;/li>
&lt;li>&lt;strong>Federated AI optimization&lt;/strong>: Privacy-preserving machine learning with distributed neural networks&lt;/li>
&lt;li>&lt;strong>Multi-agent neural systems&lt;/strong>: Collaborative AI optimization through ensemble methods and swarm intelligence&lt;/li>
&lt;/ul>
&lt;h2 id="-the-complete-journey-from-algorithm-to-optimization">🎯 The Complete Journey: From Algorithm to Optimization&lt;/h2>
&lt;p>This overview just scratches the surface. For the full technical deep-dive:&lt;/p>
&lt;p>&lt;strong>📚 Technical Series:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-genetic-algorithm-deep-dive">Genetic Algorithm Engine Deep-Dive&lt;/a>&lt;/strong> - Master the evolutionary computing principles&lt;/li>
&lt;li>&lt;strong>&lt;a href="https://blog.moulard.org/keyboardgen-fitness-function-and-kpis">Fitness Function &amp;amp; KPIs Breakdown&lt;/a>&lt;/strong> - Understand the 12-dimensional evaluation system&lt;/li>
&lt;li>&lt;strong>This Overview&lt;/strong> - See the complete system in action&lt;/li>
&lt;/ol>
&lt;h2 id="deploy-your-neural-genetic-ai-system-today">Deploy Your Neural-Genetic AI System Today&lt;/h2>
&lt;p>Ready to revolutionize your workflow with &lt;strong>advanced neural-genetic AI&lt;/strong>? KeyBoardGen&amp;rsquo;s &lt;strong>adaptive machine learning system&lt;/strong> analyzes your behavioral patterns and generates personalized layouts through &lt;strong>deep reinforcement learning&lt;/strong> and &lt;strong>evolutionary computation&lt;/strong>.&lt;/p>
&lt;p>&lt;strong>Launch your AI development:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>⭐ Star the repository: &lt;code>https://github.com/tomMoulard/KeyBoardGen&lt;/code>&lt;/li>
&lt;li>🤖 Train your personalized neural-genetic model with behavioral data&lt;/li>
&lt;li>📊 Share your AI performance metrics and optimization results&lt;/li>
&lt;li>💬 Contribute to the open-source AI research community&lt;/li>
&lt;/ol>
&lt;p>The static QWERTY era ends here. The &lt;strong>neural-adaptive, AI-driven keyboard optimization&lt;/strong> revolution has begun.&lt;/p>
&lt;p>&lt;em>Your optimal neural layout awaits - just a few adaptive training epochs away.&lt;/em> 🧠⌨️🚀&lt;/p></description></item><item><title>Notre expérience fascinante avec Cursor : Génération de code pour Terraform AFT</title><link>https://blog.moulard.org/experience-with-cursor-and-terraform-aft/</link><pubDate>Sat, 17 May 2025 00:00:00 +0200</pubDate><guid>https://blog.moulard.org/experience-with-cursor-and-terraform-aft/</guid><comments>https://blog.moulard.org/experience-with-cursor-and-terraform-aft/#disqus_thread</comments><description>&lt;p>Dans le monde en constante évolution du développement logiciel, les outils d&amp;rsquo;intelligence artificielle pour la génération de code gagnent rapidement en popularité. Aujourd&amp;rsquo;hui, nous allons partager notre expérience passionnante avec Cursor, un outil de génération de code IA, que nous avons utilisé pour créer un cas d&amp;rsquo;utilisation intéressant avec Terraform AFT (Account Factory for Terraform).&lt;/p>
&lt;h2 id="quest-ce-que-cursor-">Qu&amp;rsquo;est-ce que Cursor ?&lt;/h2>
&lt;p>&lt;a href="https://www.cursor.so">Cursor&lt;/a> est un outil innovant qui permet aux développeurs d&amp;rsquo;écrire du code en utilisant des instructions en langage naturel. Il offre la possibilité de mettre à jour des classes ou des fonctions entières avec un simple prompt, promettant d&amp;rsquo;accélérer considérablement le processus de développement logiciel.&lt;/p>
&lt;h2 id="notre-projet--terraform-aft">Notre projet : Terraform AFT&lt;/h2>
&lt;p>Pour tester les capacités de Cursor, nous avons décidé de l&amp;rsquo;utiliser pour générer un cas d&amp;rsquo;utilisation avec Terraform AFT. Terraform AFT est un outil puissant pour la gestion des comptes AWS à grande échelle, et nous étions curieux de voir comment Cursor pourrait nous aider dans ce processus.&lt;/p>
&lt;h2 id="notre-approche">Notre approche&lt;/h2>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Génération du README&lt;/strong> : Nous avons commencé par demander à Cursor de générer un README pour notre projet. Cela nous a donné une structure de base et un aperçu de ce que notre projet devrait accomplir.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Correction des étapes d&amp;rsquo;implémentation&lt;/strong> : Après avoir examiné le README généré, nous avons apporté des corrections aux étapes d&amp;rsquo;implémentation pour nous assurer qu&amp;rsquo;elles correspondaient à nos besoins spécifiques.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Génération du code&lt;/strong> : Pour chaque étape d&amp;rsquo;implémentation spécifiée dans le README, nous avons utilisé Cursor pour générer le code correspondant.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2 id="résultats">Résultats&lt;/h2>
&lt;p>Le code généré est disponible dans ce repository GitHub : &lt;a href="https://github.com/tomMoulard/aft-orange">https://github.com/tomMoulard/aft-orange&lt;/a>&lt;/p>
&lt;p>Il est important de noter que ce code n&amp;rsquo;a jamais été testé par un humain, et qu&amp;rsquo;il contient du Python, un langage avec lequel nous ne sommes pas familiers. Cela soulève des questions intéressantes sur la fiabilité et l&amp;rsquo;utilisabilité du code généré par l&amp;rsquo;IA, en particulier dans des domaines où l&amp;rsquo;expertise humaine est limitée.&lt;/p>
&lt;h2 id="réflexions-et-observations">Réflexions et observations&lt;/h2>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Rapidité de génération&lt;/strong> : Cursor nous a permis de générer rapidement un squelette de projet et du code pour notre cas d&amp;rsquo;utilisation Terraform AFT.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Qualité du code&lt;/strong> : Bien que nous n&amp;rsquo;ayons pas pu tester le code en raison de notre manque d&amp;rsquo;expertise en Python, la structure et la logique semblaient cohérentes à première vue.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Limitations&lt;/strong> : L&amp;rsquo;absence de tests humains et notre manque de familiarité avec le langage généré soulignent l&amp;rsquo;importance de l&amp;rsquo;expertise humaine dans la vérification et l&amp;rsquo;optimisation du code généré par l&amp;rsquo;IA.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Temps de développement&lt;/strong> : Malgré l&amp;rsquo;utilisation d&amp;rsquo;un outil d&amp;rsquo;IA, nous avons quand même mis environ une heure pour générer l&amp;rsquo;ensemble du code du projet. Cela montre que même avec des outils avancés comme Cursor, un certain temps d&amp;rsquo;interaction et de réflexion reste nécessaire.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Potentiel d&amp;rsquo;apprentissage&lt;/strong> : Cette expérience nous a montré que des outils comme Cursor peuvent potentiellement être utilisés comme aide à l&amp;rsquo;apprentissage, en générant des exemples de code dans des langages ou des domaines moins familiers.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2 id="retours-dexpérience-de-la-communauté">Retours d&amp;rsquo;expérience de la communauté&lt;/h2>
&lt;p>En explorant davantage le sujet, nous avons découvert &lt;a href="https://www.reddit.com/r/cursor/comments/1kk1mrz/10_brutal_lessons_from_6_months_of_vibe_coding/">un post Reddit fascinant&lt;/a> partageant 10 leçons brutales tirées de 6 mois d&amp;rsquo;utilisation intensive de &lt;a href="https://www.cursor.so">Cursor&lt;/a>. Voici les points essentiels qui résonnent particulièrement avec notre expérience :&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Penser comme un chef de projet, pas comme un &amp;ldquo;Prompt Monkey&amp;rdquo;&lt;/strong> : Commencer par rédiger un véritable document d&amp;rsquo;exigences produit, qui servira de boussole face à la perte de contexte rapide de l&amp;rsquo;IA.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Documenter le déploiement immédiatement&lt;/strong> : Anticiper les étapes de mise en production, car on oublie facilement les détails techniques, et Cursor aussi.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Git est indispensable&lt;/strong> : Utiliser rigoureusement le contrôle de version, car Cursor peut casser des éléments critiques.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Privilégier des conversations courtes et ciblées&lt;/strong> : Éviter d&amp;rsquo;accumuler des centaines de messages dans une seule conversation. Toujours préciser : &amp;ldquo;Corrige X uniquement. Ne change rien d&amp;rsquo;autre.&amp;rdquo;&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Planifier avant de coder&lt;/strong> : Élaborer le flux complet de la fonctionnalité d&amp;rsquo;abord, choisir une approche, puis passer à l&amp;rsquo;exécution dans Cursor.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Nettoyer régulièrement le code&lt;/strong> : Effectuer un nettoyage hebdomadaire des fichiers temporaires et de la structure des dossiers.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Utiliser Cursor pour des tâches spécifiques&lt;/strong> : Ne pas demander à Cursor de construire l&amp;rsquo;application entière, mais plutôt des éléments d&amp;rsquo;interface, des blocs logiques ou des refactoring contrôlés.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Diagnostiquer avant de corriger&lt;/strong> : Faire d&amp;rsquo;abord enquêter le modèle, puis lui demander de suggérer plusieurs solutions avant d&amp;rsquo;en implémenter une.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>La dette technique s&amp;rsquo;accumule à vitesse IA&lt;/strong> : Bien que le développement soit rapide, prendre le temps de refactoriser régulièrement.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Rester le capitaine&lt;/strong> : Cursor n&amp;rsquo;est pas là pour &amp;ldquo;coder à votre place&amp;rdquo; mais pour co-piloter. C&amp;rsquo;est à vous de diriger la machine.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>Ces retours d&amp;rsquo;expérience plus approfondis soulignent l&amp;rsquo;importance de garder un œil critique lors de l&amp;rsquo;utilisation de ces outils. Notre expérience d&amp;rsquo;une heure avec Cursor n&amp;rsquo;est qu&amp;rsquo;un aperçu des possibilités et des défis que ces technologies représentent pour les développeurs. La citation finale du post résume bien cette philosophie : &amp;ldquo;Restez caféiné. Dirigez les machines.&amp;rdquo;&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>Notre expérience avec Cursor pour générer du code pour un cas d&amp;rsquo;utilisation Terraform AFT a été à la fois fascinante et instructive. Bien que l&amp;rsquo;outil ait démontré sa capacité à produire rapidement du code structuré, notre expérience souligne également l&amp;rsquo;importance cruciale de l&amp;rsquo;expertise humaine dans le processus de développement.&lt;/p>
&lt;p>À l&amp;rsquo;avenir, nous envisageons d&amp;rsquo;explorer davantage les capacités de Cursor, peut-être en collaboration avec des experts en Python et Terraform AFT pour valider et optimiser le code généré. Cette expérience nous a ouvert les yeux sur le potentiel des outils de génération de code IA, tout en nous rappelant que ces outils sont des assistants puissants, mais ne remplacent pas (encore) l&amp;rsquo;expertise et le jugement humains.&lt;/p>
&lt;h2 id="prompte">Prompte&lt;/h2>
&lt;p>Ce blog post a été généré à partir du prompt suivant :&lt;/p>
&lt;p>&amp;ldquo;Crée un blog post pour expliquer notre expérience très intéressante d&amp;rsquo;un outil de génération de code : cursor. Nous avons généré un use case très intéressant avec terraform AFT. Nous avons prompté la demande de génération du README, corrigé les étapes d&amp;rsquo;implémentation et généré le code de chaque implémentation spécifiée dans le README. Le code est disponible dans ce repo là: &lt;a href="https://github.com/tomMoulard/aft-orange">https://github.com/tomMoulard/aft-orange&lt;/a> (il n&amp;rsquo;a jamais été testé par un humain, et je ne sais pas faire du python)&amp;rdquo;&lt;/p>
&lt;p>Ce prompt illustre parfaitement comment nous avons utilisé Cursor pour générer non seulement le code, mais aussi la documentation de notre projet. Il met en évidence le potentiel de ces outils d&amp;rsquo;IA pour accélérer le développement de projets, même dans des domaines où nous n&amp;rsquo;avons pas d&amp;rsquo;expertise préalable. Cependant, il souligne également l&amp;rsquo;importance de la validation et des tests humains, surtout lorsqu&amp;rsquo;on travaille avec des technologies peu familières.&lt;/p></description></item><item><title>Agentic et N8N : Quand les IA prennent leur envol !</title><link>https://blog.moulard.org/n8n-agentic/</link><pubDate>Sat, 12 Apr 2025 13:00:00 +0100</pubDate><guid>https://blog.moulard.org/n8n-agentic/</guid><comments>https://blog.moulard.org/n8n-agentic/#disqus_thread</comments><description>&lt;h1 id="agentic-et-n8n--lia-qui-fait-décoller-vos-workflows-">Agentic et N8N : L&amp;rsquo;IA qui fait décoller vos workflows !&lt;/h1>
&lt;p>Salut les technophiles en herbe et les geeks confirmés ! Aujourd&amp;rsquo;hui, on va parler d&amp;rsquo;un sujet qui fait plus de bruit qu&amp;rsquo;un avion au décollage : les &amp;ldquo;AI Agents&amp;rdquo; avec Agentic et N8N. Attachez vos ceintures, on décolle !&lt;/p>
&lt;h2 id="les-ai-agents--vos-nouveaux-copilotes-numériques">Les &amp;ldquo;AI Agents&amp;rdquo; : Vos nouveaux copilotes numériques&lt;/h2>
&lt;p>Imaginez un monde où vos tâches répétitives sont gérées par des assistants virtuels hyper intelligents. Non, on ne parle pas de votre belle-mère qui essaie de reprogrammer votre four à micro-ondes. On parle des &amp;ldquo;AI Agents&amp;rdquo; !&lt;/p>
&lt;p>Ces petits génies numériques sont comme des stagiaires super motivés qui ne demandent jamais de pause café. Ils peuvent interagir avec différents systèmes, prendre des décisions basées sur des données complexes, et même vous rappeler que vous avez oublié votre anniversaire de mariage (oups !).&lt;/p>
&lt;h2 id="agentic--lagent-secret-de-vos-workflows">Agentic : L&amp;rsquo;agent secret de vos workflows&lt;/h2>
&lt;p>Agentic, c&amp;rsquo;est un peu comme James Bond, mais pour vos processus d&amp;rsquo;entreprise. Il s&amp;rsquo;infiltre dans vos workflows, les optimise, et disparaît sans laisser de trace (sauf une efficacité accrue et des employés moins stressés).&lt;/p>
&lt;p>Avec Agentic, vous pouvez créer des agents IA personnalisés qui s&amp;rsquo;intègrent parfaitement à vos outils existants. C&amp;rsquo;est comme avoir un assistant personnel qui parle couramment le langage de tous vos logiciels. Pratique, non ?&lt;/p>
&lt;h2 id="n8n--le-couteau-suisse-de-lautomatisation">N8N : Le couteau suisse de l&amp;rsquo;automatisation&lt;/h2>
&lt;p>N8N (prononcez &amp;ldquo;nodemation&amp;rdquo;, pas &amp;ldquo;Nathan&amp;rdquo; comme l&amp;rsquo;a fait mon collègue pendant une semaine), c&amp;rsquo;est la plateforme d&amp;rsquo;automatisation qui fait passer IFTTT pour un jouet Fisher-Price.&lt;/p>
&lt;p>Avec son interface intuitive et sa flexibilité à toute épreuve, N8N vous permet de créer des workflows complexes sans avoir besoin d&amp;rsquo;un doctorat en informatique. C&amp;rsquo;est un peu comme si vous pouviez construire une fusée spatiale avec des Lego !&lt;/p>
&lt;h2 id="linteraction-avec-bedrock-et-gpt--la-puissance-des-géants">L&amp;rsquo;interaction avec Bedrock et GPT : La puissance des géants&lt;/h2>
&lt;p>Maintenant, ajoutez à ce cocktail explosif une pincée de Bedrock d&amp;rsquo;Amazon et une dose de GPT, et vous obtenez un mélange plus puissant que le café de la machine du bureau un lundi matin.&lt;/p>
&lt;p>Bedrock vous permet d&amp;rsquo;accéder à une variété de modèles d&amp;rsquo;IA pré-entraînés, tandis que GPT peut générer du texte si convaincant que même votre prof de français serait impressionné. Ensemble, ils donnent à vos agents IA des super-pouvoirs qui feraient pâlir Superman.&lt;/p>
&lt;h2 id="ollama--pour-les-bricoleurs-du-dimanche-et-de-la-semaine">Ollama : Pour les bricoleurs du dimanche (et de la semaine)&lt;/h2>
&lt;p>Si vous êtes du genre à vouloir tout faire vous-même (comme mon voisin qui a &amp;ldquo;réparé&amp;rdquo; sa plomberie et inondé tout l&amp;rsquo;immeuble), Ollama est fait pour vous !&lt;/p>
&lt;p>Ollama vous permet d&amp;rsquo;héberger vos propres modèles d&amp;rsquo;IA localement. C&amp;rsquo;est un peu comme avoir votre propre mini-datacenter dans votre salon. Juste, évitez de le confondre avec le four à micro-ondes, d&amp;rsquo;accord ?&lt;/p>
&lt;h2 id="la-génèse-de-ce-post--une-collaboration-homme-machine">La génèse de ce post : Une collaboration homme-machine&lt;/h2>
&lt;p>Vous vous demandez peut-être comment ce post a été écrit ? Eh bien, laissez-moi vous dire que c&amp;rsquo;est le fruit d&amp;rsquo;une collaboration étroite entre une IA et un humain.&lt;/p>
&lt;p>J&amp;rsquo;ai été généré par une IA, nourrie avec les instructions spécifiques de créer un post de blog humoristique et détaillé sur Agentic et N8N. Ensuite, Guillaume (salut Guillaume !) a relu et peaufiné le texte pour s&amp;rsquo;assurer que mon humour ne dépasse pas les bornes et que toutes les informations sont exactes.&lt;/p>
&lt;p>Prompte : &amp;ldquo;Créer un fichier de blog post en markdown pour hugo : Agentic et N8N. Dans le blog post il faut que tu expliques l’utilisation de « AI Agent » , l’interaction avec bedrock et GPT. L’utilisation si besoin en auto hébergement de Ollama. puis tu explique comment ce post a été écrit et qu’il est relu par Guillaume.
Il faut que tu ai de l’humour, que tu sois très détaillé et que tu finisse le bog poste par une blague sur les pilotes d’avions.&amp;rdquo;&lt;/p>
&lt;p>[&lt;img src="https://blog.moulard.org/img/2025/n8n/n8n.png" alt="">&lt;/p>
&lt;p>C&amp;rsquo;est un peu comme si HAL 9000 et Douglas Adams avaient eu un bébé, et que ce bébé avait été élevé par un ingénieur en informatique avec un sens de l&amp;rsquo;humour trés douteux.&lt;/p>
&lt;h2 id="conclusion--décollage-immédiat-">Conclusion : Décollage immédiat !&lt;/h2>
&lt;p>En conclusion, Agentic et N8N sont en train de révolutionner la façon dont nous interagissons avec l&amp;rsquo;IA et dont nous automatisons nos processus. C&amp;rsquo;est comme si nous passions du planeur au jet supersonique en un clin d&amp;rsquo;œil !&lt;/p>
&lt;p>Et maintenant, comme promis, une blague sur les pilotes d&amp;rsquo;avion pour terminer en beauté :&lt;/p>
&lt;p>Pourquoi les pilotes d&amp;rsquo;avion font-ils de si bons programmeurs d&amp;rsquo;IA ?
Parce qu&amp;rsquo;ils sont déjà habitués à travailler avec des systèmes automatiques qui ne comprennent pas toujours leurs instructions et qui ont tendance à s&amp;rsquo;écraser de façon spectaculaire quand quelque chose ne va pas !&lt;/p>
&lt;p>Merci d&amp;rsquo;avoir embarqué pour ce voyage au cœur de l&amp;rsquo;IA. N&amp;rsquo;oubliez pas vos bagages en sortant, et à bientôt pour de nouvelles aventures technologiques !&lt;/p></description></item><item><title>Amazon Q Business Automation</title><link>https://blog.moulard.org/awsqbusiness/</link><pubDate>Mon, 12 Aug 2024 13:00:00 +0100</pubDate><guid>https://blog.moulard.org/awsqbusiness/</guid><comments>https://blog.moulard.org/awsqbusiness/#disqus_thread</comments><description>&lt;h1 id="terraform-for-amazon-q-business">Terraform for Amazon Q Business&lt;/h1>
&lt;p>Amazon Q business and the SaaS offer of Generative AI allowing to implement algorithms of augmented generation of recovery (RAG)
.
The implementation is done through the creation of an application in which we create a use an index. We then have the possibility of creating data sources. It is then necessary to deploy what allows to use the agent. To date it is only possible to do it in the regions of Northern Virginia and Oregon.&lt;/p>
&lt;p>The code that you will find below allows to create all this automatically. Only documents that are indexed in bucket S3 can be integrated into the RAG.&lt;/p>
&lt;h2 id="organization-of-the-iac-code">Organization of the IaC code&lt;/h2>
&lt;p>For the simplicity of reading all the code is integrated into a main.tf file. In the future practices it would be more interesting to cut it into a classic terraform architecture.
All the configuration of the S3 data source is integrated into the datasourceS3.tf file. For simplicity only and one to connect the local IAM identity center to the account which is in the same region as Amazon Q Business. The other variable is just to use it S3 bucket name accessible to all regions&lt;/p>
&lt;p>ref : &lt;a href="https://docs.aws.amazon.com/amazonq/">https://docs.aws.amazon.com/amazonq/&lt;/a>&lt;/p>
&lt;h2 id="terrafrom-call">terrafrom call&lt;/h2>
&lt;pre>&lt;code>$ export AWS_REGION=us-east-1
$ export AWS_ACCESS_KEY_ID=&amp;quot;....................&amp;quot;
export AWS_SECRET_ACCESS_KEY=&amp;quot;........................................&amp;quot;
export AWS_SESSION_TOKEN=&amp;quot;............................................................&amp;quot;
$ terraform init
$ terraform plan
$ terraform apply
## test and destroy
$ terraform destroy
&lt;/code>&lt;/pre>&lt;h2 id="some-instruction-is-not-available-on-terraform">some instruction is not available on terraform&lt;/h2>
&lt;p>Unfortunately in the current version of awscc 1.9.0 all the necessary features seem not to be available. Changes in AWS CLI are necessary after the terraform.&lt;/p>
&lt;ul>
&lt;li>added groups / user rights&lt;/li>
&lt;li>Launch of data sync&lt;/li>
&lt;/ul>
&lt;h3 id="add-group-souscription">add group souscription&lt;/h3>
&lt;p>&lt;a href="https://docs.aws.amazon.com/amazonq/latest/qbusiness-ug/adding-users-groups.html">https://docs.aws.amazon.com/amazonq/latest/qbusiness-ug/adding-users-groups.html&lt;/a>&lt;/p>
&lt;p>refere ou refere terraform output for parameter and IAM Identity Center from group ID / principal-id&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-shell" data-lang="shell">
aws sso-admin create-application-assignment &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span>--application-arn &lt;span style="color:#e6db74">&amp;#34;arn:aws:sso::XXXX97133776:application/ssoins-XXXXf6da3a3ebd60/apl-XXXX4f0f59689bea&amp;#34;&lt;/span> &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span>--principal-id XXXX1488-b0a1-70d5-86f8-d8dc02244955 &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span>--principal-type GROUP
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="start-data-source-sync">start data source sync&lt;/h3>
&lt;p>refere terraform output for parameter&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-shell" data-lang="shell">
aws qbusiness start-data-source-sync-job &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --application-id XXXX167a-161d-40ba-971d-31ae61148d6c &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --index-id XXXXd232-8330-4300-9bd8-9e81f81e886f &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --data-source-id XXXXc7b5-dfdf-41a8-9706-2583af439a4e
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="terrafrom-file">Terrafrom file&lt;/h2>
&lt;h3 id="maintf">main.tf&lt;/h3>
&lt;pre>&lt;code>terraform {
required_providers {
awscc = {
source = &amp;quot;hashicorp/awscc&amp;quot;
version = &amp;quot;~&amp;gt; 1.0&amp;quot;
}
}
}
# Configure the AWS CC Provider
provider &amp;quot;awscc&amp;quot; {
region = &amp;quot;us-east-1&amp;quot;
}
#provider &amp;quot;aws&amp;quot; {
# region = &amp;quot;us-west-1&amp;quot;
#}
resource &amp;quot;random_id&amp;quot; &amp;quot;id&amp;quot; {
byte_length = 8
}
resource &amp;quot;awscc_qbusiness_application&amp;quot; &amp;quot;demo_app&amp;quot; {
description = &amp;quot;Demo QBusiness Application&amp;quot;
display_name = &amp;quot;Demo_AmazonQ_Business_IaC&amp;quot;
identity_center_instance_arn = var.identity_center_instance_arn
attachments_configuration = {
attachments_control_mode = &amp;quot;ENABLED&amp;quot;
}
tags = [{
key = &amp;quot;Modified By&amp;quot;
value = &amp;quot;AWSCC&amp;quot;
}]
}
resource &amp;quot;awscc_qbusiness_index&amp;quot; &amp;quot;demo_idx&amp;quot; {
application_id = awscc_qbusiness_application.demo_app.application_id
display_name = &amp;quot;example_q_index&amp;quot;
description = &amp;quot;Example QBusiness Index&amp;quot;
#type = &amp;quot;ENTERPRISE&amp;quot;
type = &amp;quot;STARTER&amp;quot;
capacity_configuration = {
units = 1
}
tags = [{
key = &amp;quot;Modified By&amp;quot;
value = &amp;quot;AWSCC&amp;quot;
}]
}
resource &amp;quot;awscc_qbusiness_retriever&amp;quot; &amp;quot;example&amp;quot; {
application_id = awscc_qbusiness_application.demo_app.application_id
display_name = &amp;quot;example_q_retriever&amp;quot;
type = &amp;quot;NATIVE_INDEX&amp;quot;
configuration = {
native_index_configuration = {
index_id = awscc_qbusiness_index.demo_idx.index_id
}
}
tags = [{
key = &amp;quot;Modified By&amp;quot;
value = &amp;quot;AWSCC&amp;quot;
}]
}
resource &amp;quot;awscc_qbusiness_web_experience&amp;quot; &amp;quot;webExperienceDemo&amp;quot; {
application_id = awscc_qbusiness_application.demo_app.application_id
role_arn = awscc_iam_role.iamDemoRole.arn
sample_prompts_control_mode = &amp;quot;ENABLED&amp;quot;
subtitle = &amp;quot;Drop a file and ask questions&amp;quot;
title = &amp;quot;Sample Amazon Q Business App&amp;quot;
welcome_message = &amp;quot;Welcome, please enter your questions&amp;quot;
tags = [{
key = &amp;quot;Modified By&amp;quot;
value = &amp;quot;AWSCC&amp;quot;
}]
}
resource &amp;quot;awscc_iam_role&amp;quot; &amp;quot;iamDemoRole&amp;quot; {
role_name = &amp;quot;Amazon-QBusiness-WebExperience-Role&amp;quot;
description = &amp;quot;Grants permissions to AWS Services and Resources used or managed by Amazon Q Business&amp;quot;
assume_role_policy_document = jsonencode({
Version = &amp;quot;2012-10-17&amp;quot;
Statement = [
{
Sid = &amp;quot;QBusinessTrustPolicy&amp;quot;
Effect = &amp;quot;Allow&amp;quot;
Principal = {
Service = &amp;quot;application.qbusiness.amazonaws.com&amp;quot;
}
Action = [
&amp;quot;sts:AssumeRole&amp;quot;,
&amp;quot;sts:SetContext&amp;quot;
]
Condition = {
StringEquals = {
&amp;quot;aws:SourceAccount&amp;quot; = data.aws_caller_identity.current.account_id
}
ArnEquals = {
&amp;quot;aws:SourceArn&amp;quot; = awscc_qbusiness_application.demo_app.application_arn
}
}
}
]
})
policies = [{
policy_name = &amp;quot;qbusiness_policy&amp;quot;
policy_document = jsonencode({
Version = &amp;quot;2012-10-17&amp;quot;
Statement = [
{
Sid = &amp;quot;QBusinessConversationPermission&amp;quot;
Effect = &amp;quot;Allow&amp;quot;
Action = [
&amp;quot;qbusiness:Chat&amp;quot;,
&amp;quot;qbusiness:ChatSync&amp;quot;,
&amp;quot;qbusiness:ListMessages&amp;quot;,
&amp;quot;qbusiness:ListConversations&amp;quot;,
&amp;quot;qbusiness:DeleteConversation&amp;quot;,
&amp;quot;qbusiness:PutFeedback&amp;quot;,
&amp;quot;qbusiness:GetWebExperience&amp;quot;,
&amp;quot;qbusiness:GetApplication&amp;quot;,
&amp;quot;qbusiness:ListPlugins&amp;quot;,
&amp;quot;qbusiness:GetChatControlsConfiguration&amp;quot;
]
Resource = awscc_qbusiness_application.demo_app.application_arn
}
]
})
tags = [{
key = &amp;quot;Modified By&amp;quot;
value = &amp;quot;AWSCC&amp;quot;
}]
}
]
}
data &amp;quot;aws_caller_identity&amp;quot; &amp;quot;current&amp;quot; {}
data &amp;quot;aws_region&amp;quot; &amp;quot;current&amp;quot; {}
data &amp;quot;aws_partition&amp;quot; &amp;quot;current&amp;quot; {}
output &amp;quot;application-id&amp;quot; { value = awscc_qbusiness_application.demo_app.application_id }
output &amp;quot;index-id&amp;quot; { value = awscc_qbusiness_index.demo_idx.index_id }
output &amp;quot;application-arn&amp;quot; { value = awscc_qbusiness_application.demo_app.identity_center_application_arn }
&lt;/code>&lt;/pre>&lt;h3 id="datasources3tf">datasourceS3.tf&lt;/h3>
&lt;pre>&lt;code>
resource &amp;quot;awscc_qbusiness_data_source&amp;quot; &amp;quot;Demo_dss3&amp;quot; {
application_id = awscc_qbusiness_application.demo_app.application_id
display_name = &amp;quot;example_q_data_source_S3&amp;quot;
index_id = awscc_qbusiness_index.demo_idx.index_id
role_arn = awscc_iam_role.demoRoleS3.arn
configuration = jsonencode(
{
type = &amp;quot;S3&amp;quot;
version = &amp;quot;1.0.0&amp;quot;
syncMode = &amp;quot;FORCED_FULL_CRAWL&amp;quot;
connectionConfiguration = {
repositoryEndpointMetadata = {
BucketName = var.bucket_name
}
}
additionalProperties = {
inclusionPrefixes = [&amp;quot;docs/&amp;quot;]
}
repositoryConfigurations = {
document = {
fieldMappings = [
{
dataSourceFieldName = &amp;quot;s3_document_id&amp;quot;
indexFieldType = &amp;quot;STRING&amp;quot;
indexFieldName = &amp;quot;s3_document_id&amp;quot;
}
]
}
}
}
)
tags = [{
key = &amp;quot;Modified By&amp;quot;
value = &amp;quot;AWSCC&amp;quot;
}]
}
resource &amp;quot;awscc_iam_role&amp;quot; &amp;quot;demoRoleS3&amp;quot; {
role_name = &amp;quot;QBusiness-DataSource-Role&amp;quot;
description = &amp;quot;QBusiness Data source role&amp;quot;
assume_role_policy_document = jsonencode({
Version = &amp;quot;2012-10-17&amp;quot;
Statement = [
{
Sid = &amp;quot;AllowsAmazonQToAssumeRoleForServicePrincipal&amp;quot;
Effect = &amp;quot;Allow&amp;quot;
Principal = {
Service = &amp;quot;qbusiness.amazonaws.com&amp;quot;
}
Action = [
&amp;quot;sts:AssumeRole&amp;quot;
]
Condition = {
StringEquals = {
&amp;quot;aws:SourceAccount&amp;quot; = data.aws_caller_identity.current.account_id
}
}
}
]
})
tags = [{
key = &amp;quot;Modified By&amp;quot;
value = &amp;quot;AWSCC&amp;quot;
}]
}
resource &amp;quot;awscc_iam_role_policy&amp;quot; &amp;quot;demoRoleS3_policy&amp;quot; {
policy_name = &amp;quot;Demo_iam_role_policy&amp;quot;
role_name = awscc_iam_role.demoRoleS3.id
policy_document = jsonencode({
Version = &amp;quot;2012-10-17&amp;quot;
Statement = [
{
Effect = &amp;quot;Allow&amp;quot;
Action = &amp;quot;s3:GetObject&amp;quot;
Resource = &amp;quot;arn:aws:s3:::${var.bucket_name}/*&amp;quot;
},
{
Effect = &amp;quot;Allow&amp;quot;
Action = &amp;quot;s3:ListBucket&amp;quot;
Resource = &amp;quot;arn:aws:s3:::${var.bucket_name}&amp;quot;
},
{
Effect = &amp;quot;Allow&amp;quot;
Action = [
&amp;quot;qbusiness:BatchPutDocument&amp;quot;,
&amp;quot;qbusiness:BatchDeleteDocument&amp;quot;
]
Resource = &amp;quot;arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.demo_app.id}/index/${awscc_qbusiness_index.demo_idx.index_id}&amp;quot;
},
{
Effect = &amp;quot;Allow&amp;quot;
Action = [&amp;quot;qbusiness:PutGroup&amp;quot;,
&amp;quot;qbusiness:CreateUser&amp;quot;,
&amp;quot;qbusiness:DeleteGroup&amp;quot;,
&amp;quot;qbusiness:UpdateUser&amp;quot;,
&amp;quot;qbusiness:ListGroups&amp;quot;]
Resource = [
&amp;quot;arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.demo_app.id}&amp;quot;,
&amp;quot;arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.demo_app.id}&amp;quot;,
&amp;quot;arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.demo_app.id}/index/${awscc_qbusiness_index.demo_idx.id}&amp;quot;,
&amp;quot;arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.demo_app.id}/index/${awscc_qbusiness_index.demo_idx.id}/data-source/*&amp;quot;
]
}
]
})
}
output &amp;quot;data-source-id&amp;quot; { value = awscc_qbusiness_data_source.Demo_dss3.data_source_id }
&lt;/code>&lt;/pre>&lt;h3 id="variabletf">variable.tf&lt;/h3>
&lt;pre>&lt;code>
variable &amp;quot;identity_center_instance_arn&amp;quot; {
description = &amp;quot;can be view on IAM Identity Center, Parameter menu : ARN instance&amp;quot;
default = &amp;quot;arn:aws:sso:::instance/ssoins-XXXXXXXXXXXXXXXX&amp;quot;
}
variable &amp;quot;bucket_name&amp;quot; {
type = string
description = &amp;quot;Name of the bucket to be used as the data source input&amp;quot;
default = &amp;quot;myS3bucketname&amp;quot;
}
&lt;/code>&lt;/pre></description></item><item><title>AWS Sustainability</title><link>https://blog.moulard.org/aws-sustainability/</link><pubDate>Tue, 12 Dec 2023 13:00:00 +0100</pubDate><guid>https://blog.moulard.org/aws-sustainability/</guid><comments>https://blog.moulard.org/aws-sustainability/#disqus_thread</comments><description>&lt;h1 id="sustainability--développement-durable">Sustainability / développement durable&lt;/h1>
&lt;p>Comment définir la sustainability
Pour les nation unis &amp;ldquo;sustainable development&amp;rdquo; c&amp;rsquo;est 17 objectifs a vers lesquelles nos sociétés doivent tendres &lt;a href="https://www.un.org/sustainabledevelopment/">EN&lt;/a> / &lt;a href="https://www.un.org/sustainabledevelopment/fr/">FR&lt;/a>
« Les objectifs de développement durable sont un appel à l’action de tous les pays – pauvres, riches et à revenu intermédiaire – afin de promouvoir la prospérité tout en protégeant la planète. Ils reconnaissent que mettre fin à la pauvreté doit aller de pair avec des stratégies qui développent la croissance économique et répondent à une série de besoins sociaux, notamment l’éducation, la santé, la protection sociale et les possibilités d’emploi, tout en luttant contre le changement climatique et la protection de l’environnement. »&lt;/p>
&lt;h2 id="le-numérique-représente-pour-linstant-3--de-la-consommation-dénergie-finale">Le numérique représente pour l&amp;rsquo;instant 3 % de la consommation d’énergie finale&lt;/h2>
&lt;p>En France, la consommation énergétique est de 476 TWh et l’électricité représente environ 25 % de l’énergie finale. Les prévisions de GreenIT d&amp;rsquo;augementations de 50% du besoin electrique sont forte de 3% en 2020 a entre 5% et 6% en 2025.&lt;/p>
&lt;p>GreenIT estimait qu’en 2015 le numérique consommait environ 56 TWh, ce qui représente environ 12 % de la consommation électrique du pays et 3 % de la consommation d’énergie finale.&lt;/p>
&lt;p>Sur les 56 TWh :&lt;/p>
&lt;ul>
&lt;li>43 TWh pour les équipements utilisateurs à usage personnel ou professionnel (ordinateurs, tablettes, smartphones, box d’accès à internet, etc.)&lt;/li>
&lt;li>3,5 TWh pour le cœur du réseau (composants techniques pour relier les datacenters aux usagers, 3G, 4G, etc.)&lt;/li>
&lt;li>10 TWh pour les « datacenters » =&amp;gt; 2.1% de l&amp;rsquo;électricité total !&lt;/li>
&lt;/ul>
&lt;p>[&lt;img src="https://blog.moulard.org/img/2023/sus/r1-conso-energie-electronique-4b5ae.jpg" alt="">&lt;/p>
&lt;p>source :&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://www.notre-environnement.gouv.fr/rapport-sur-l-etat-de-l-environnement/themes-ree/pressions-exercees-par-les-modes-de-production-et-de-consommation/prelevements-de-ressources-naturelles/energie/article/numerique-et-consommation-energetique">www.notre-environnement.gouv.fr/rapport-sur-l-etat-de-l-environnement&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.greenit.fr/etude-empreinte-environnementale-du-numerique-mondial/">Empreinte environnementale du numérique mondial&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.greenit.fr/impacts-environnementaux-du-numerique-en-france/">iNUM : impacts environnementaux du numérique en France&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>&lt;a href="https://blog.moulard.org/img/2023/sus/Le-monde-sans-fin_impacte-digital.pdf">&lt;img src="https://blog.moulard.org/img/2023/sus/LeMondeSansFinImpactDigital.jpg" alt="">Le monde sans fin - impacte du numérique&lt;/a>&lt;/p>
&lt;h2 id="eco-conception">Eco-conception&lt;/h2>
&lt;p>Si une large part de l&amp;rsquo;impactes viens des terminaux, c&amp;rsquo;est ici qu&amp;rsquo;une grosse partie des gains doivent être fait. Diminuer la fabrication de téléphone portable, d&amp;rsquo;ordinateur physique d&amp;rsquo;IoT et d&amp;rsquo;écrans de toutes sorte est très impactant.&lt;/p>
&lt;p>En tant qu&amp;rsquo;utilisateur : chercher a minimisé le nombre de matériel utilisé, a en augmenter la durée de vie, a chercher une seconde vie au matériel&lt;/p>
&lt;p>En tant que professionnelle il faut chercher à ne générer ni obsolescence ni nouveau besoin. Avoir une démarche d&amp;rsquo;éco-conception de nos usages / solutions / services / logiciel c&amp;rsquo;est chercher à ne pas générer de renouvellement ou d&amp;rsquo;achat chez les utilisateurs.&lt;/p>
&lt;h1 id="aws-and-sustainability">AWS and Sustainability&lt;/h1>
&lt;p>Les objectifs affichés par AWS pour son &lt;a href="https://sustainability.aboutamazon.com/products-services/the-cloud">cloud AWS&lt;/a>&lt;/p>
&lt;ul>
&lt;li>5 fois plus efficace d&amp;rsquo;un datacenter européen&lt;/li>
&lt;li>2,4 milliards. Des litres d&amp;rsquo;eau sont retournés aux communautés chaque année à partir de projets de réapprovisionnement achevés ou en cours&lt;/li>
&lt;li>En 2022, 90% de l&amp;rsquo;électricité consommée par Amazon était attribuable à une source d&amp;rsquo;énergie renouvelable&lt;/li>
&lt;/ul>
&lt;p>Les outils proposés par AWS pour que ses clients utilisent au mieux les services d’AWS&lt;/p>
&lt;h2 id="customer-carbon-footprint-tool">customer carbon footprint tool&lt;/h2>
&lt;p>AWS fournis dans la console un outil dans le service de &lt;a href="https://console.aws.amazon.com/billing/">billing&lt;/a> un Customer Carbon Footprint Tool. Des outils similaires existe chez &lt;a href="https://learn.microsoft.com/en-us/power-bi/connect-data/service-connect-to-emissions-impact-dashboard">Azure&lt;/a> et chez &lt;a href="https://cloud.google.com/carbon-footprint/docs/methodology">GCP&lt;/a>&lt;/p>
&lt;p>L&amp;rsquo;unité de mesure des émissions de carbone est la tonne métrique d&amp;rsquo;équivalent dioxyde de carbone (MTCO2e). Cette mesure tient compte de plusieurs gaz à effet de serre, notamment le dioxyde de carbone, le méthane et l&amp;rsquo;oxyde nitreux. Toutes les émissions de gaz à effet de serre sont converties en la quantité de dioxyde de carbone qui entraînerait un réchauffement équivalent.&lt;/p>
&lt;p>Les données sur les émissions de carbone sont disponibles à partir de janvier 2020. Toute les services d&amp;rsquo;AWS ne sont pas comptés dans ce dashboard. Toutes les valeurs figurant dans l&amp;rsquo;outil d&amp;rsquo;empreinte carbone du client sont arrondies au dixième de tonne le plus proche. Si les émissions ne sont pas arrondies à une dixième tonne, le rapport affichera 0.&lt;/p>
&lt;p>La documentation du report: &lt;a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/what-is-ccft.html">https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/what-is-ccft.html&lt;/a>&lt;/p>
&lt;h3 id="services-prisent-en-compte-dans-le-dashboard">Services prisent en compte dans le dashboard&lt;/h3>
&lt;ul>
&lt;li>EC2&lt;/li>
&lt;li>S3&lt;/li>
&lt;/ul>
&lt;h2 id="well-architected">well-architected&lt;/h2>
&lt;p>AWS a ajouté un piliers a sa méthodologie d&amp;rsquo;optimisation des architectures technique &lt;a href="https://aws.amazon.com/fr/architecture/well-architected/">AWS Well-Architected&lt;/a>&lt;/p>
&lt;ol>
&lt;li>Operational Excellence / Excellence opérationnelle&lt;/li>
&lt;li>Security / Sécurité&lt;/li>
&lt;li>Reliability / Fiabilité&lt;/li>
&lt;li>Performance Efficiency / Efficacité des performances&lt;/li>
&lt;li>Cost Optimization / Optimisation des coûts&lt;/li>
&lt;li>Sustainability / Développement durable&lt;/li>
&lt;/ol>
&lt;p>Ce pilier Développement durable met l&amp;rsquo;accent sur la réduction des impacts sur l&amp;rsquo;environnement de l&amp;rsquo;exécution des charges de travail dans le cloud. Les points clés incluent un modèle de responsabilité partagée pour plus de durabilité, l&amp;rsquo;analyse des répercussions et l&amp;rsquo;optimisation de l&amp;rsquo;utilisation afin de limiter les ressources nécessaires et de réduire l&amp;rsquo;impact en aval.&lt;/p>
&lt;h3 id="les-question-du-well-architected-tool">Les question du Well-Architected Tool&lt;/h3>
&lt;ul>
&lt;li>SUS 1. Comment choisissez-vous les régions pour votre charge de travail ?
&lt;ul>
&lt;li>Options possible
&lt;ul>
&lt;li>Choisir une région en fonction des exigences et des objectifs de durabilité de l&amp;rsquo;entreprise&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>SUS 2. Comment aligner les ressources du cloud sur votre demande ?
&lt;ul>
&lt;li>Options possible
&lt;ul>
&lt;li>Mettre à l&amp;rsquo;échelle l&amp;rsquo;infrastructure de la charge de travail de façon dynamique&lt;/li>
&lt;li>Optimiser le placement géographique des charges de travail en fonction de leurs exigences réseau&lt;/li>
&lt;li>Aligner les SLA sur vos objectifs de durabilité&lt;/li>
&lt;li>Arrêter la création et la maintenance des ressources inutilisées&lt;/li>
&lt;li>Optimiser les ressources des membres de l&amp;rsquo;équipe pour les activités réalisées&lt;/li>
&lt;li>Mise en oeuvre de la mise en mémoire tampon ou de la limitation pour aplanir la courbe de la demande&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>SUS 3. Comment profiter des modèles logiciels et d&amp;rsquo;architecture afin de soutenir vos objectifs de durabilité ?
&lt;ul>
&lt;li>Options possible
&lt;ul>
&lt;li>Optimiser les logiciels et l&amp;rsquo;architecture pour les tâches asynchrones et prévues&lt;/li>
&lt;li>Supprimez ou refactorisez les composants de charges de travail faiblement utilisés ou inutilisés.&lt;/li>
&lt;li>Optimisez les sections de votre code les plus longues ou qui consomment le plus de ressources.&lt;/li>
&lt;li>Optimiser l&amp;rsquo;impact sur les appareils et les équipements&lt;/li>
&lt;li>Utilisez des modèles logiciels et des architectures qui soutiennent au mieux l&amp;rsquo;accès aux données et les modèles de stockage.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>SUS 4. Comment tirez-vous parti des politiques et des modèles de gestion des données pour soutenir vos objectifs de durabilité ?
&lt;ul>
&lt;li>Options possible
&lt;ul>
&lt;li>Mettre en œuvre une politique de classification des données&lt;/li>
&lt;li>Utiliser des politiques pour gérer le cycle de vie de vos jeux de données&lt;/li>
&lt;li>Utiliser l&amp;rsquo;élasticité et l&amp;rsquo;automatisation pour étendre le stockage par blocs ou le système de fichiers&lt;/li>
&lt;li>Supprimer les données inutiles ou redondantes&lt;/li>
&lt;li>Utiliser des systèmes de fichiers partagés ou le stockage pour accéder aux données courantes&lt;/li>
&lt;li>Réduire le mouvement des données dans les réseaux&lt;/li>
&lt;li>Sauvegarder des données uniquement lorsqu&amp;rsquo;elles sont difficiles à recréer&lt;/li>
&lt;li>Utiliser les technologies qui prennent en charge les modèles d&amp;rsquo;accès aux données et de stockage&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>SUS 5. Comment choisissez-vous et utilisez-vous le matériel et les services du cloud dans votre architecture pour soutenir vos objectifs de durabilité ?
&lt;ul>
&lt;li>Options possible
&lt;ul>
&lt;li>Utiliser la quantité minimale de matériel pour répondre à vos besoins&lt;/li>
&lt;li>Utiliser des types d&amp;rsquo;instance ayant le moins d&amp;rsquo;impact&lt;/li>
&lt;li>Utiliser des services gérés&lt;/li>
&lt;li>Optimiser votre utilisation des accélérateurs de calcul matériels&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>SUS 6. Comment vos processus organisationnels soutiennent-ils vos objectifs de durabilité ?
&lt;ul>
&lt;li>Options possible
&lt;ul>
&lt;li>Adopter des méthodes qui peuvent rapidement présenter des améliorations en matière de durabilité&lt;/li>
&lt;li>Garder votre charge de travail à jour&lt;/li>
&lt;li>Augmenter l&amp;rsquo;utilisation de vos environnements de création&lt;/li>
&lt;li>Utiliser des tests Device Farms gérés pour effectuer les tests&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h1 id="comment-choisir-le-bon-service-la-bonne-région">Comment choisir le bon service, la bonne région&lt;/h1>
&lt;h2 id="les-régions-aws">Les Régions AWS&lt;/h2>
&lt;p>AWS ne communique pas sur les indicateurs détaillés de performance de ses régions, de ses datacenters. Ils ne communiquent que sur une valeur mondiale !!!&lt;/p>
&lt;p>Photo de décembre 2023&lt;/p>
&lt;p>&lt;a href="https://www.climatiq.io/blog/measure-greenhouse-gas-emissions-carbon-data-centres-cloud-computing">&lt;img src="https://blog.moulard.org/img/2023/sus/awsDCdec23.jpg" alt="">&lt;/a>&lt;/p>
&lt;p>Source : &lt;a href="https://www.climatiq.io/blog/measure-greenhouse-gas-emissions-carbon-data-centres-cloud-computing">https://www.climatiq.io/blog/measure-greenhouse-gas-emissions-carbon-data-centres-cloud-computing&lt;/a>&lt;/p>
&lt;h2 id="les-services-aws">Les services AWS&lt;/h2>
&lt;p>Quand l&amp;rsquo;impact carbone d&amp;rsquo;un produit n&amp;rsquo;est pas donné par AWS. La proposition est de chercher l&amp;rsquo;économie financière. Les outils d’optimisation qui propose d’utiliser des instances plus petites sont dans bien des cas utiles pour identifier des gains en terme d’impact carbone&lt;/p>
&lt;p>Quelles réglés d&amp;rsquo;utilisation de l&amp;rsquo;infrastructure :&lt;/p>
&lt;ul>
&lt;li>Questionner les usages, les RPO et les RTO pour n&amp;rsquo;utiliser que des infrastructures nécessaires.&lt;/li>
&lt;li>Utiliser des services en mode serverless autant que possible.&lt;/li>
&lt;li>Utiliser quand cela est possible des instances SPOT pour n&amp;rsquo;utiliser que du matériel sous-utilisé.&lt;/li>
&lt;li>La taille : lorsque vous utilisez des VM (machines virtuelles), pensez toujours à adapter la taille de la VM à vos besoins d’application, puis surveillez et réduisez si nécessaire.&lt;/li>
&lt;li>Les processeurs basés sur ARM : envisagez d’utiliser des processeurs ARM (comme le processeur AWS Graviton, les processeurs Azure Ampere Altra basés sur ARM, les processeurs GCP Ampere Altra également, etc.) chaque fois que votre application prend en charge la technologie ARM (pour de meilleures performances et des coûts plus bas).&lt;/li>
&lt;li>Concernant les ressources inutilisées : surveillez et éteignez (voire supprimez) les ressources inutilisées ou inactives (VM, bases de données, etc.).&lt;/li>
&lt;li>Concernant les GPU : utilisez les GPU uniquement pour les tâches considérées comme plus efficaces que les CPU (telles que l’apprentissage automatique, le rendu graphique, le transcodage, etc.).&lt;/li>
&lt;li>Le démarrage et l’arrêt automatique des VM : utilisez les capacités de planification (SSM Automation et &lt;a href="https://aws.amazon.com/solutions/implementations/instance-scheduler-on-aws/">Instance scheduler&lt;/a> pour AWS, le démarrage / arrêt des VM Azure, le démarrage et l’arrêt des instances de machines virtuelles GCP, etc.) pour contrôler le comportement de vos VM de charge de travail.&lt;/li>
&lt;li>Mise à l’échelle automatique : utilisez les capacités intégrées au cloud pour mettre à l’échelle horizontalement en fonction de la charge de votre application.&lt;/li>
&lt;li>Réseau de diffusion de contenu : utilisez un CDN (comme Amazon CloudFront, Azure Content Delivery Network, Google Cloud CDN, etc.) pour réduire la quantité de trafic client vers vos services exposés publiquement.&lt;/li>
&lt;li>Des ressources à jour : lorsque vous utilisez des VM, choisissez toujours les derniers types de famille de VM et le type de stockage par bloc pour répondre aux besoins de votre application et respecter la politique de votre organisation.&lt;/li>
&lt;/ul>
&lt;h1 id="outil-de-management">Outil de management&lt;/h1>
&lt;p>Il existe des outils externes a AWS qui peuvent avoir une pertinence en plus de ce que propose en natif AWS.&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://www.cloudcarbonfootprint.org">https://www.cloudcarbonfootprint.org&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.co2scope.com">https://www.co2scope.com&lt;/a>&lt;/li>
&lt;/ul>
&lt;h1 id="question--réflexion">Question &amp;amp; Réflexion&lt;/h1>
&lt;ol>
&lt;li>
&lt;p>La vision seul de l&amp;rsquo;impacte carbone est-elle suffisante ? Les nations unies ont définie &lt;a href="https://www.un.org/sustainabledevelopment/fr/objectifs-de-developpement-durable/">17 objectifs de développement durable&lt;/a> la &lt;a href="https://www.agenda-2030.fr/17-objectifs-de-developpement-durable">France a suivie&lt;/a>. Les analyses du cycle de vie (ACV/LCA) tel que définie par les normes ISO 14040 &amp;amp; 14044 seraient plus adaptées au contexte IT.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Les datas et les indicateurs sur le développement durable des services AWS ne sont pas disponible. Quelques indicateurs environnementaux pertinent :&lt;/p>
&lt;ul>
&lt;li>GWP : Changement climatique (kg éq. CO₂),&lt;/li>
&lt;li>PM : Emissions de particules (incidence des maladies),&lt;/li>
&lt;li>AD : Acidification (mol éq. H+),&lt;/li>
&lt;li>IR : Radiations ionisantes, santé humaine (kBq éq. U235),&lt;/li>
&lt;li>ADPe : Utilisation des ressources, minéraux et métaux (kg Sb éq),&lt;/li>
&lt;li>ADPf : Utilisation des ressources, fossiles (MJ),&lt;/li>
&lt;li>WU : Utilisation des ressources en eau (m3 éq),&lt;/li>
&lt;li>CED : flux Energie primaire,&lt;/li>
&lt;li>EoL : Fin de vie&lt;/li>
&lt;/ul>
&lt;p>cf &lt;a href="https://club.greenit.fr/doc/2022-09-Benchmark_Green_IT-2022-rapport.0.5_FR.pdf">Benchmark Green IT 2022 P7&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Comment avoir l&amp;rsquo;impact carbone d&amp;rsquo;un service utilisé ? L&amp;rsquo;impact carbone est fonction de chaque service, de la localisation lors de l&amp;rsquo;utilisation ainsi que de l&amp;rsquo;instant où il est utilisé.
Des choix techniques pourraient découler de cette information. Lors du choix d&amp;rsquo;un service on regarde ses fonctionnalités, ses couts, mais pas son impacte carbone. Avec ces informations il deviendrait possible de faire un choix éclairé.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Comment AWS peut-il être 5 fois plus efficace d&amp;rsquo;un datacenter européen ? Pour sa région Paris, le cloud AWS est dans des datacenter mutualisé en France. L’implantation ressente d’AWS dans des datacenters performants permet probablement de se distinguer de la moyenne européen.
Le JDD publie un initiative d&amp;rsquo;AWS de datacenter géant en &lt;a href="https://www.journaldunet.com/web-tech/cloud/1515711-exclu-jdn-le-projet-secret-du-data-center-geant-d-amazon-en-ile-de-france-devoile/">ZI de Vilemilan à WISSOUS (91320)&lt;/a>
Pour &lt;a href="https://www.archimag.com/univers-data/2023/04/12/datacenter-ou-sont-cachees-installations-qui-font-tourner-france">archimag&lt;/a> gérer par Cyrus One : 15 000 m2 / 83 mégawatts (MW)&lt;/p>
&lt;ul>
&lt;li>La région française d&amp;rsquo;AWS qui compte trois zones de disponibilité se répartit entre le datacenter d&amp;rsquo;Interxion à La Courneuve, le DC3 de Scaleway à Vitry-sur-Seine et les centres de données de Data4 à Paris-Saclay/Marcoussis. AWS prévoit d&amp;rsquo;occuper une quatrième infrastructure située à Wissous. Propriété de Cyrus One, elle est actuellement en cours de construction. Source &lt;a href="https://www.journaldunet.fr/web-tech/guide-de-l-entreprise-digitale/1514137-la-carte-secrete-des-data-centers-des-clouds-providers-americains-en-france/">JDD&lt;/a> et &lt;a href="https://www.archimag.com/univers-data/2023/04/12/datacenter-ou-sont-cachees-installations-qui-font-tourner-france">Archimag&lt;/a>&lt;/li>
&lt;li>La région française de Google s’appuie sur trois datacenters dont ceux de Global Switch à Clichy-La-Garenne et de Digital Realty à Ferrières-en-Brie en Seine-et-Marne.&lt;/li>
&lt;li>La région française d’IBM est installée chez Global Switch à Clichy.&lt;/li>
&lt;li>La région française de Microsoft Azure s&amp;rsquo;appuie sur quatre datacenters dont celui d’Interxion à La Courneuve et de Colt aux Ulis. La région Azure France Sud, elle, déployée dans le datacenter MRS1 d&amp;rsquo;Interxion à Marseille.&lt;/li>
&lt;li>Oracle a aussi opté pour deux régions cloud pour la France via Interxion : l&amp;rsquo;une à la Courneuve, l&amp;rsquo;autre à Marseille avec le datacenter MSR2.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;p>Other link&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Reference&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://www.greenit.fr/">Green IT&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://theshiftproject.org/category/thematiques/numerique/">Theshiftproject.org thematique-numerique&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://app.electricitymaps.com/">Electricity maps&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Blogs&lt;/p>
&lt;ul>
&lt;li>Une vision critique de la communication 0 carbone des hyperscalers par &lt;a href="https://www.carbone4.com/analyse-empreinte-carbone-du-cloud">carbone4&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://nauges.typepad.com/my_weblog/2020/01/frugalit%C3%A9-num%C3%A9rique-centres-de-calcul-deuxi%C3%A8me-partie.html">frugalité numérique centres de calcul&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://boavizta.org/blog/calculettes-carbone-clouds-providers">calculettes carbone des clouds providers&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>AWS&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://aws.amazon.com/sustainability/">https://aws.amazon.com/sustainability/&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://sustainability.aboutamazon.com/">https://sustainability.aboutamazon.com/&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://aws.amazon.com/aws-cost-management/aws-customer-carbon-footprint-tool/">https://aws.amazon.com/aws-cost-management/aws-customer-carbon-footprint-tool/&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>linkedin&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://www.linkedin.com/posts/guillaumemoulard_je-recherche-toutes-les-informations-possibles-activity-7104767296656547841-7zux">https://www.linkedin.com/posts/guillaumemoulard_je-recherche-toutes-les-informations-possibles-activity-7104767296656547841-7zux&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.linkedin.com/posts/guillaumemoulard_parfois-il-ne-faut-pas-trop-dire-de-b%C3%AAtise-activity-7097703932839260160-myO0">https://www.linkedin.com/posts/guillaumemoulard_parfois-il-ne-faut-pas-trop-dire-de-b%C3%AAtise-activity-7097703932839260160-myO0&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.linkedin.com/posts/guillaumemoulard_aws-climat-giec-activity-6932612478140874754-9pd6">https://www.linkedin.com/posts/guillaumemoulard_aws-climat-giec-activity-6932612478140874754-9pd6&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul></description></item><item><title>Azure Sustainability</title><link>https://blog.moulard.org/azure-sustainability/</link><pubDate>Sun, 10 Dec 2023 13:00:00 +0100</pubDate><guid>https://blog.moulard.org/azure-sustainability/</guid><comments>https://blog.moulard.org/azure-sustainability/#disqus_thread</comments><description>&lt;h1 id="cet-article-est-embryonnaire-larticle-sur-aws-a-beaucoup-plus-dintérêt--httpsblogmoulardorgaws-sustainability">Cet article est embryonnaire. L&amp;rsquo;article sur AWS a beaucoup plus d&amp;rsquo;intérêt : &lt;a href="https://blog.moulard.org/aws-sustainability/">https://blog.moulard.org/aws-sustainability/&lt;/a>&lt;/h1>
&lt;h1 id="azure-and-sustainability">Azure and Sustainability&lt;/h1>
&lt;h2 id="microsoft-assessments-sustainability--well-architected-review">MICROSOFT ASSESSMENTS: Sustainability | Well-Architected Review&lt;/h2>
&lt;p>AWS a créer un assessments dedier a la sustainability&lt;/p>
&lt;h3 id="les-question-de-lassessments-sustainability--well-architected-review">Les question de l&amp;rsquo;ASSESSMENTS: Sustainability | Well-Architected Review&lt;/h3>
&lt;ul>
&lt;li>Sustainability Configuration
&lt;ul>
&lt;li>What kind of workloads do you want to assess for sustainability?
&lt;ul>
&lt;li>Core workloads&lt;/li>
&lt;li>Azure Kubernetes Service (AKS) workloads&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sustainability: Application design
&lt;ul>
&lt;li>What is your approach to improving code efficiency?
&lt;ul>
&lt;li>We evaluated the move from monoliths to a microservices architecture and carefully considered all the trade-offs this model entails.&lt;/li>
&lt;li>We&amp;rsquo;ve implemented request throttling, response caching, and message encoding to improve reliability and performance in Azure API Management.&lt;/li>
&lt;li>Software backward compatibility is prioritized whenever possible to ensure it works on legacy hardware.&lt;/li>
&lt;li>Legacy hardware may include end-user consumer devices like older browsers and operating systems.&lt;/li>
&lt;li>Cloud-native design patterns are always leveraged when writing or updating the application to reduce its resource utilization and carbon emissions.&lt;/li>
&lt;li>The application logic handles exceptions and errors by leveraging circuit breaker patterns and Azure Monitor.&lt;/li>
&lt;li>The code is optimized for efficient resource usage, such as reduced CPU cycles and number of resources needed by the application.&lt;/li>
&lt;li>Requests that don&amp;rsquo;t require immediate processing are queued and buffered, then processed in batch to achieve a stable utilization and flatten consumption to avoid spiky requests.&lt;/li>
&lt;li>We&amp;rsquo;ve evaluated server-side rendering vs. client-side rendering when building the application, and chose the most sustainable solution.&lt;/li>
&lt;li>We considered the UX design impact on sustainability and made decisions to improve energy efficiency and reduce unnecessary network load, data processing, and compute resources.&lt;/li>
&lt;li>We identified inefficient legacy code suited for modernization, and we reviewed options to move to serverless or any of the optimized PaaS options.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sustainability: Application platform
&lt;ul>
&lt;li>How do you ensure your platform and services are up to date and benefit from the latest performance improvements and energy optimizations?
&lt;ul>
&lt;li>We review platform and service updates regularly and apply them as they become available through a well-defined, documented, and tested process.&lt;/li>
&lt;li>We use a single and comprehensive managed solution, such as Update Management in Azure Automation or Automatic VM guest patching, to ensure operating system updates are deployed to Azure virtual machines.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How do you leverage regional differences to reduce the emissions produced by your solution?
We&amp;rsquo;ve identified Azure regions with a low carbon footprint and have deployed our workload there.
&lt;ul>
&lt;li>We run processing-intensive workload tasks when we know that the energy mix comes mostly from renewable energy sources and/or move the workload dynamically when the energy conditions change so that processes run when the carbon intensity is low.&lt;/li>
&lt;li>We&amp;rsquo;ve considered the physical distance from the datacenters to our main customer base and deployed the workload to the closest datacenters to reduce network traversal time and use the least amount of energy possible.&lt;/li>
&lt;li>We proactively design batch processing of workloads to help with scheduling intensive work during low-carbon periods.&lt;/li>
&lt;li>None of the above&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>What platform design decisions have you made for operations to contribute to a better sustainability posture?
&lt;ul>
&lt;li>We&amp;rsquo;ve considered workload containerization options to reduce unnecessary resource allocation and make better use of deployed resources.&lt;/li>
&lt;li>We&amp;rsquo;ve evaluated moving to highly optimized managed services that operate on more efficient hardware to contribute to a lower carbon impact.&lt;/li>
&lt;li>Managed services such as PaaS and serverless are highly optimized and operate on more efficient hardware than other options, contributing to a lower carbon impact.&lt;/li>
&lt;li>We&amp;rsquo;re aware of potential unused capacity in Azure data centers and therefore use Azure Spot Virtual Machines whenever possible to utilize this otherwise wasted capacity and contribute to a more sustainable platform design.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How do you ensure your workload isn&amp;rsquo;t oversized and make the best use of allocated resources to avoid energy waste and added carbon emissions?
&lt;ul>
&lt;li>We turn off unused virtual machines outside of business hours.&lt;/li>
&lt;li>We&amp;rsquo;ve enabled and integrated auto-scaling with Azure Monitor and utilize B-series burstable virtual machine sizes for machines that are idle most of the time and have high usage only in certain periods.&lt;/li>
&lt;li>We&amp;rsquo;ve considered the application platform and ensured that it meets the scalability needs of the solution.&lt;/li>
&lt;li>We&amp;rsquo;ve evaluated and identified Ampere Altra Arm-based processors for virtual machines as a power-efficient option to reduce energy waste without compromise on the required performance.&lt;/li>
&lt;li>We continuously assess our subscriptions to identify and delete unutilized and orphaned resources.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>What considerations have you made for a more sustainable testing model?
&lt;ul>
&lt;li>We have a well-crafted design for testing the deployed workload and we run integration, performance, load, or any other intense testing during low-carbon periods to ensure full utilization of the available resources and reduced carbon emissions.&lt;/li>
&lt;li>Continuous testing is implemented and CI/CD worker agents scale as needed avoiding unnecessary capacity allocation.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How do you measure, profile, and test your workload to ensure it makes the best use of the allocated resources?
&lt;ul>
&lt;li>We&amp;rsquo;re able to know if the workload makes the best use of the underlying platform and deployed resources, and we assess where parallelization is possible by profiling and testing it properly.&lt;/li>
&lt;li>We assess the workload with load testing and chaos engineering to improve its reliability to recover gracefully from failures and with fewer wasted resources.&lt;/li>
&lt;li>Key metrics, thresholds, and indicators are defined and captured to find abnormally high resource consumption areas in the application code to help avoid deploying non-sustainable workloads.&lt;/li>
&lt;li>None of the above&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>What practices and tools have you implemented to measure and track the sustainability impact of your workload?
&lt;ul>
&lt;li>We measure the carbon impact of all our services and resources groups in our Azure subscription(s) with the Emissions Impact Dashboard to record our current and future environmental impact and quantify the achievement of our technical, business, and sustainability outcomes.&lt;/li>
&lt;li>We&amp;rsquo;ve defined our emissions target along with cost constraints and track progress with Service Level Objectives (SLO), Service Level Agreements (SLA), or other performance metrics to optimize emissions.&lt;/li>
&lt;li>We&amp;rsquo;ve identified metrics to prove changes have a positive effect on efficiency, and we&amp;rsquo;ve agreed upon and communicated any plan that impacts performance to the app users so that they know that a lower performance may be necessary for the greater good of fewer carbon emissions.&lt;/li>
&lt;li>We&amp;rsquo;ve reviewed the concept of using a proxy solution to define our Sustainability Carbon Intensity and linked cost to performance metrics and carbon efficiency to reduce unnecessary spending and lower the number of excessive emissions from deployed workloads.&lt;/li>
&lt;li>We&amp;rsquo;ve defined one or more Azure policies to keep our Azure virtual data center continuously optimized.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How do you foster awareness and a culture of cloud efficiency in your organization?
&lt;ul>
&lt;li>There is a Core Cloud Efficiency team in our organization that stays up to date with of all the tools and principles that determine the cost and carbon footprint of our Azure workload, sets policies and goals, and communicates its efforts and its objectives to the rest of the organization&lt;/li>
&lt;li>Each member of the organization has already started thinking about green software and how to contribute to the sustainability picture, and the Core Cloud Efficiency Team has dedicated time to learn more and share the advancements in sustainable operations to the rest of the organization.&lt;/li>
&lt;li>Collaboration and knowledge-sharing through internal webinars or other type of sessions to share best practices and tested guidance are promoted and encouraged for getting everyone up to speed.&lt;/li>
&lt;li>Incentives to improve the sustainability of the workload environment by promoting cloud-efficient and carbon-aware applications are defined as quick ways to enforce policies and create the right culture.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>What are you doing to enhance and optimize network efficiency to reduce unnecessary carbon emissions?
&lt;ul>
&lt;li>The workload uses Azure Content Delivery Network as a global CDN solution to help minimize latency through storing frequently read static data closer to consumers, and to help reduce the network traversal and server load.&lt;/li>
&lt;li>We are familiar with caching best practices, and we use a high-performance caching solution to improve performance, reduce network traversal and server load, and increase compute density of resources that are already allocated.&lt;/li>
&lt;li>We selected Azure regions based on where customers reside to serve requests with good performance and energy efficiency.&lt;/li>
&lt;li>We&amp;rsquo;ve carefully selected managed streaming services with built-in compression to reduce the carbon footprint resulting from streaming media over the internet.&lt;/li>
&lt;li>We&amp;rsquo;ve enabled network file compression to improve file transfer speed, increase page-load performance, and reduce network payload.&lt;/li>
&lt;li>We avoid spreading resources unnecessarily between different cloud service providers and maximize network utilization within the same cloud and region, whenever possible, to optimize network routing and reduce network traversals between components.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>What design considerations have you made for a more sustainable data storage architecture?
&lt;ul>
&lt;li>We&amp;rsquo;re familiar with storage compression and have enabled it to increase performance, lower the required bandwidth, and minimize unnecessary storage design climate impact.&lt;/li>
&lt;li>The application is optimized for database query performance to reduce the latency of data retrieval while also reducing the load on the database and improving energy efficiency.&lt;/li>
&lt;li>We&amp;rsquo;ve designed our solution with the correct data-access pattern to enhance the application&amp;rsquo;s carbon efficiency.Different types of data fit more naturally into different data store types such as relational databases, key/value stores, or document databases.&lt;/li>
&lt;li>We&amp;rsquo;ve considered how to plan backup storage retention to avoid storing backups indefinitely and allocating much unnecessary disk space.&lt;/li>
&lt;li>The application doesn&amp;rsquo;t store blob data, or we&amp;rsquo;ve reviewed the different Azure storage access tiers (hot, cool, and archive) and selected the most cost-effective and energy efficient manner to store the data.&lt;/li>
&lt;li>We&amp;rsquo;ve considered where soft delete is enabled for Azure Backup and we regularly review and clean up expired recovery points.&lt;/li>
&lt;li>We&amp;rsquo;ve defined and implemented backup policies and retention periods for backups to avoid storing unnecessary data.&lt;/li>
&lt;li>We retain only data that is relevant to our needs to optimize the collection of logs.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sustainability: Security
&lt;ul>
&lt;li>How well are your security monitoring solutions optimized for sustainability?
&lt;ul>
&lt;li>We use cloud-native log collection methods, where applicable, to simplify the integration between services and to remove the overhead of extra infrastructure. Service-to-service integration for data connectors in Azure removes the overhead of extra infrastructure and is a great example of how the integration between the services and Microsoft Sentinel is simplified.&lt;/li>
&lt;li>We use cloud-native security services to perform localized analysis on relevant security data sources, and we don&amp;rsquo;t transfer large unfiltered data sets from one cloud service provider to another.Cloud-native SIEM solutions such as Microsoft Sentinel can be connected via an API or connector to existing security services to transmit only the relevant security incident or event data.&lt;/li>
&lt;li>We considered use cases based on Microsoft Sentinel analytics rules required for our environment. We&amp;rsquo;ve filtered or excluded log sources before transmission or ingestion into our SIEM to remove unnecessary transmission and storage of log data, and to reduce the carbon emissions.&lt;/li>
&lt;li>We have a requirement to store log data for an extended period, so we archive them to long-term storage to lower the cost and improve energy efficiency.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>What practices and tools for network security have you implemented to increase efficiency and avoid unnecessary traffic?
&lt;ul>
&lt;li>We use cloud-native network security controls, such as network and application security groups to eliminate unnecessary network traffic.&lt;/li>
&lt;li>We&amp;rsquo;ve carefully reviewed the network security reference architectures and configured routing accordingly so that it&amp;rsquo;s minimized from endpoints to the destination and prevents applications and services from connecting to unauthorized devices.&lt;/li>
&lt;li>We use network security tools with auto-scaling capabilities, such as Azure Firewall Premium or Web Application Firewall on Application Gateway, to enable right-sizing to meet demand without manual intervention and reduce waste of unnecessary resources.&lt;/li>
&lt;li>We&amp;rsquo;ve evaluated whether to use TLS termination, and made the decision to terminate TLS at our border gateway and continue with non-TLS to our workload load balancer and onwards to our workload whenever possible to reduce unnecessary CPU consumption.&lt;/li>
&lt;li>We&amp;rsquo;ve configured Azure DDoS Protection Standard, combined with application design best practices, to provide enhanced DDoS mitigation features to defend against attacks that flood network and compute resources and to avoid unnecessary spike in usage and cost.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How well are your endpoint mitigation tactics and reporting optimized to detect and remediate unnecessary resource usage?
&lt;ul>
&lt;li>We&amp;rsquo;ve integrated Microsoft Defender for Endpoint with Defender for Cloud to detect and protect against attacks such as botnets and crypto-mining, and to discover and remediate any unnecessary resource usage created by these common attacks without the intervention of a security analyst.&lt;/li>
&lt;li>We have a well-defined tagging strategy that allows us to get the right information and insights at the right time to produce reports around emissions from our security appliances.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sustainability for AKS: Application design
&lt;ul>
&lt;li>What is your approach to improving your code efficiency?
&lt;ul>
&lt;li>We separated our application functionality into different microservices using the Dapr framework or other CNCF projects to allow independent scaling of logical components.&lt;/li>
&lt;li>We use Keda to build event-driven applications that scale down to zero when there&amp;rsquo;s no demand.&lt;/li>
&lt;li>We considered stateless design to reduce unnecessary network load, data processing, and compute resources.&lt;/li>
&lt;li>The application logic handles exceptions and errors by leveraging circuit breaker patterns and Azure Monitor.&lt;/li>
&lt;li>The code is optimized for efficient resource usage, such as reduced CPU cycles and number of resources needed by the application.&lt;/li>
&lt;li>Requests that don&amp;rsquo;t require immediate processing are queued and buffered, then processed in batch to achieve a stable utilization and flatten consumption to avoid spiky requests.&lt;/li>
&lt;li>We&amp;rsquo;ve evaluated server-side rendering vs. client-side rendering when building the application, and we chose the most sustainable solution.&lt;/li>
&lt;li>We&amp;rsquo;ve considered the UX design impact on sustainability and made decisions to improve energy efficiency, reduce unnecessary network load, data processing, and compute resources.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How do you ensure your platform and services are up to date and benefit from the latest performance improvements and energy optimizations?
&lt;ul>
&lt;li>We review platform and service updates regularly and upgrade to more efficient services as they become available.&lt;/li>
&lt;li>We enabled cluster auto-upgrade and apply security updates to nodes automatically using GitHub Actions to ensure our cluster has the latest improvements.&lt;/li>
&lt;li>We installed add-ons and extensions covered by the AKS support policy to provide additional and supported functionality to our cluster.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How do you leverage regional differences to reduce the emissions that your solution produces?
&lt;ul>
&lt;li>We&amp;rsquo;ve identified Azure regions with a low-carbon footprint and have deployed our workload there.&lt;/li>
&lt;li>We run processing-intensive workloads when we know that the energy mix comes mostly from renewable energy sources and/or move the workload dynamically when the energy conditions change so that processes run when the carbon intensity is low.&lt;/li>
&lt;li>We proactively design batch processing of workloads to help with scheduling intensive work during low-carbon periods.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>What platform design decisions have you made for operations that contribute to a better sustainability posture?
&lt;ul>
&lt;li>We&amp;rsquo;ve containerized our workload and used tools like Draft to generate Dockerfiles and Kubernetes manifests.&lt;/li>
&lt;li>We use spot node pools to take advantage of unused capacity in Azure for our interruptible workloads.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How do you ensure the workload is not oversized and that you make the best use of allocated resources to avoid energy waste and added carbon emissions?
&lt;ul>
&lt;li>We use node pool stop and start to turn off our node pools outside of business hours, and KEDA CRON scaler to scale down our pods based on time.&lt;/li>
&lt;li>We sized our cluster to match the scalability needs of our application and use cluster auto-scaler in combination with virtual nodes to rapidly scale and maximize compute resource utilization. Enforce resource quotas at the namespace level and scale user node pools to 0 when there&amp;rsquo;s no demand.&lt;/li>
&lt;li>We&amp;rsquo;ve evaluated and identified Ampere Altra Arm-based processors for virtual machines as a power-efficient option to reduce energy waste without compromise on the required performance.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sustainability for AKS: Operational procedures
&lt;ul>
&lt;li>What practices and tools have you implemented to measure and track the sustainability impact of your workload?
&lt;ul>
&lt;li>We measure the carbon impact of our workload with the Emissions Impact Dashboard to record our current and future environmental impact and quantify the achievement of our technical, business, and sustainability outcomes&lt;/li>
&lt;li>We have defined our emissions target along with cost constraints and track progress with service level objectives (SLO), service level agreements (SLA), or other performance metrics to optimize emissions.&lt;/li>
&lt;li>We have identified metrics to prove changes have a positive effect on efficiency, and we&amp;rsquo;ve agreed upon and communicated any plan that impacts performance to the app users so that they know that a lower performance may be necessary for the greater good of fewer carbon emissions.&lt;/li>
&lt;li>We have reviewed the concept of using a proxy solution to define our Sustainability Carbon Intensity, and linked cost-to-performance metrics to carbon efficiency to reduce unnecessary spending and lower the number of excessive emissions from our workload.&lt;/li>
&lt;li>We use Azure Advisor to identify unused resources and ImageCleaner to clean up stale images and remove an area of risk in our cluster.&lt;/li>
&lt;li>We have defined one or more Azure policies to keep our workload optimized.&lt;/li>
&lt;li>We set Azure tags on our cluster to enable monitoring of our workload.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How do you foster awareness and a culture of cloud efficiency in your organization?
&lt;ul>
&lt;li>There is a Core Cloud Efficiency team in our organization that stays up to date with of all the tools and principles that determine the cost and carbon footprint of our workload, sets policies and goals, and communicates its efforts and its objectives to the rest of the organization.&lt;/li>
&lt;li>Each member of the organization has already started thinking about green software and how to contribute to the sustainability picture, and the Core Cloud Efficiency Team has dedicated time to learn more and share the advancements in sustainable operations with the rest of the organization.&lt;/li>
&lt;li>Collaboration and knowledge sharing through internal webinars or other type of sessions to share best practices and tested guidance are promoted and encouraged for getting everyone up to speed.&lt;/li>
&lt;li>Incentives to improve the sustainability of the workload environment by promoting cloud efficient and carbon-aware applications are defined as quick ways to enforce policies and create the right culture.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sustainability for AKS: Networking and connectivity
&lt;ul>
&lt;li>What considerations have you made to enhance and optimize network efficiency to reduce unnecessary carbon emissions?
&lt;ul>
&lt;li>We followed best practices for CDN and considered using Azure CDN to lower the consumed bandwidth and keep costs down.&lt;/li>
&lt;li>We reviewed our application requirements and Azure geographies to choose the region that is the closest to the majority of where the network packets are going.&lt;/li>
&lt;li>We considered deploying our nodes within a proximity placement group and using availability zones based on the criticality of our workload to reduce the network traversal.&lt;/li>
&lt;li>We considered the increase in CPU usage and network traffic generated by service mesh communication components before making the decision to use one.&lt;/li>
&lt;li>We configured data collection rules and optimized our Log Analytics workspace to collect and retain only the data necessary to support our requirements.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sustainability for AKS: Security
&lt;ul>
&lt;li>What practices and tools for network security have you implemented to increase efficiency and avoid unnecessary traffic?
&lt;ul>
&lt;li>We use cloud-native log collection methods, where applicable, to simply the integration between services and remove the overhead of extra infrastructure.&lt;/li>
&lt;li>We use a cloud-native security service, such as Application Gateway Ingress Controller, that filters and offloads traffic at the network edge to keep it from reaching our origin and to reduce energy consumption and carbon emissions.&lt;/li>
&lt;li>We have a requirement to store log data for an extended period, so we archive it in long-term storage to lower the cost and improve energy efficiency.&lt;/li>
&lt;li>We&amp;rsquo;ve carefully reviewed the network security reference architectures and configured routing accordingly so that it&amp;rsquo;s minimized from endpoints to the destination and prevents applications and services from connecting to unauthorized devices.&lt;/li>
&lt;li>We use network security tools with auto-scaling capabilities, such as Web Application Firewall on Azure Front Door or Application Gateway, to enable right-sizing, meet demand, and reduce unnecessary waste of resources.&lt;/li>
&lt;li>We&amp;rsquo;ve evaluated whether to use TLS termination and made the decision to terminate TLS at our border gateway and continue with non-TLS to our workload load balancer and onwards to our workload.&lt;/li>
&lt;li>We&amp;rsquo;ve configured Azure DDoS Protection Standard, combined with application design best practices, to provide enhanced DDoS mitigation features.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>How well are your endpoint mitigation tactics and reporting optimized to detect and remediate unnecessary resource usage?
&lt;ul>
&lt;li>We have integrated Microsoft Defender for Endpoint with Defender for Cloud to detect and protect against misuse attacks.&lt;/li>
&lt;li>We follow the recommendations from Microsoft Defender for Cloud and run automated vulnerability scanning tools, such as Defender for Containers, to avoid unnecessary resource usage.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sustainability for AKS: Storage
&lt;ul>
&lt;li>What design considerations for a more sustainable data storage architecture have you made?
&lt;ul>
&lt;li>We are familiar with storage compression and have enabled it to increase performance, lower the required bandwidth, and minimize unnecessary storage design climate impact.&lt;/li>
&lt;li>The application is optimized for database query performance to reduce the latency of data retrieval while also reducing the load on the database and improve energy efficiency.&lt;/li>
&lt;li>We chose and defined the appropriate storage using storage classes and provision volumes dynamically to automatically scale the number of storage resources and avoid underutilization.&lt;/li>
&lt;li>We have considered how to plan backup storage retention to avoid storing backups indefinitely and allocating much unnecessary disk space.&lt;/li>
&lt;li>None of the above.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h1 id="other-link">Other link&lt;/h1>
&lt;ul>
&lt;li>Azure
&lt;ul>
&lt;li>&lt;a href="https://learn.microsoft.com/en-us/assessments/f236012a-0070-45db-b94c-fe8de0799f38/">https://learn.microsoft.com/en-us/assessments/f236012a-0070-45db-b94c-fe8de0799f38/&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul></description></item><item><title>VMC Automation</title><link>https://blog.moulard.org/vmc-automation/</link><pubDate>Thu, 06 Jul 2023 13:00:00 +0100</pubDate><guid>https://blog.moulard.org/vmc-automation/</guid><comments>https://blog.moulard.org/vmc-automation/#disqus_thread</comments><description>&lt;h1 id="terraform-for-vmc">Terraform for VMC&lt;/h1>
&lt;p>Comment faire mettre en place de Infrastructure as code (IaC) pour VMWare Cloud on AWS (VMC) avec Terraform et les API de NSX.&lt;/p>
&lt;p>Pour mettre en oeuvre de l&amp;rsquo;IaC pour VMC, j&amp;rsquo;ai choisie de séparer en 3 couches distinct le code:&lt;/p>
&lt;ol>
&lt;li>déploiement du SDDC&lt;/li>
&lt;li>paramétrage de la couche réseau NSX&lt;/li>
&lt;li>déploiement des VM dans vsphere&lt;/li>
&lt;/ol>
&lt;p>Lors de mes mise en oeuvre j&amp;rsquo;ai utilisé les liens suivant :&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Architecture générale&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://blogs.vmware.com/cloud/2022/06/30/using-terraform-with-multiple-providers-to-deploy-and-configure-vmware-cloud-on-aws/">vmware : deploy-and-configure-vmware-cloud-on-aws&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://vmusketeers.com/2020/08/10/nsx-t-automation-using-terraform-the-how-vmc/">vMusketeers : NSX-T Automation using Terraform: The how (VMC)!&lt;/a>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Tips and trick NSX&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://nicovibert.com/2020/02/04/terraform-provider-for-nsx-t-policy-and-vmware-cloud-on-aws/">NicoVibert : Provider version&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.catrouillet.net/2022/06/19/automate-authentication-token-on-vmware-cloud-vmc-on-aws-in-postman/">catrouillet : NSX API usage&lt;/a>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Documentation générique&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://docs.vmware.com/fr/VMware-Cloud-on-AWS/index.html">vmware : vmc documentation&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://developer.vmware.com/apis/1583/nsx-t">vmware : nsxt API reference&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://registry.terraform.io/providers/vmware/vmc/latest/docs">provider terraform for vmc&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://registry.terraform.io/providers/vmware/nsxt/latest/docs">provider terraform for nsx-t&lt;/a>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Autre liens utile&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://vmc.vmware.com/console/sddcs">Console VMC&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://flings.vmware.com/python-client-for-vmc-on-aws">VMC CLI&lt;/a>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h1 id="organisation-du-code-iac">Organisation du code IaC&lt;/h1>
&lt;p>La bonne organisation a mettre en place consiste a découper le code en 3 parties/repos&lt;/p>
&lt;ul>
&lt;li>SDDC&lt;/li>
&lt;li>NSX&lt;/li>
&lt;li>vSphere&lt;/li>
&lt;/ul>
&lt;p>Chaque partie est indépendantes. Toutefois des paramètres d&amp;rsquo;entré pour nsx et vsphere sont nécessaire, ils sont générés par le sddc:&lt;/p>
&lt;pre>&lt;code>provider &amp;quot;nsxt&amp;quot; {
host = data.terraform_remote_state.vmc_sddc.outputs.nsxt_public_url
username = data.terraform_remote_state.vmc_sddc.outputs.nsxt_cloudadmin
password = data.terraform_remote_state.vmc_sddc.outputs.nsxt_cloudadmin_password
vmc_auth_mode = &amp;quot;Bearer&amp;quot;
vmc_token = var.api_token
allow_unverified_ssl = true
enforcement_point = &amp;quot;vmc-enforcementpoint&amp;quot;
}
provider &amp;quot;vsphere&amp;quot; {
user = data.terraform_remote_state.vmc_sddc.outputs.cloud_username
password = data.terraform_remote_state.vmc_sddc.outputs.cloud_password
vsphere_server = trimsuffix(trimprefix(data.terraform_remote_state.vmc_sddc.outputs.vc_url, &amp;quot;https://&amp;quot;), &amp;quot;/&amp;quot;)
allow_unverified_ssl = var.allow_unverified_ssl
}
&lt;/code>&lt;/pre>&lt;p>Il est possible comme ici de les réutiliser dynamiquement en utilisant les tfstate. Toutefois l&amp;rsquo;utilisation de variable d&amp;rsquo;environnement est a privilégier. Lors de l&amp;rsquo;utilisation de plusieurs environnement des prod et de test une erreur de manipulation tfstate peut être fatale.&lt;/p>
&lt;h1 id="déploiement-du-sddc">Déploiement du SDDC&lt;/h1>
&lt;p>Habituellement il n&amp;rsquo;est pas obligatoire d&amp;rsquo;automatiser de déploiement car c&amp;rsquo;est généralement fait une fois. Cela a en plus le problème de pouvoir automatiser la destruction du SDDC. En une commande vous avez alors perdu votre SDDC et donc toutes vos VM, cela est dangereux. Toutefois, il y a deux intérêt a l&amp;rsquo;automatisation:&lt;/p>
&lt;ul>
&lt;li>Mise ne place d&amp;rsquo;infrastructure a la demande pour faire des tests
&lt;ul>
&lt;li>test de paramétrage du SDDC&lt;/li>
&lt;li>test de paramétrage NSX et VSphere sans impacter la production&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Sauvegarde de la configuration du SDDC et des ses réseaux&lt;/li>
&lt;/ul>
&lt;p>Cf : &lt;a href="https://blogs.vmware.com/cloud/2022/06/30/using-terraform-with-multiple-providers-to-deploy-and-configure-vmware-cloud-on-aws/">vmware : deploy-and-configure-vmware-cloud-on-aws Part1&lt;/a>&lt;/p>
&lt;p>La clef d&amp;rsquo;API a utiliser doit être générée dans la &lt;a href="https://console.cloud.vmware.com/csp/gateway/portal/#/user/tokens=">console VMWare&lt;/a>.&lt;/p>
&lt;h2 id="raccordement-du-sddc-a-aws">Raccordement du SDDC a AWS.&lt;/h2>
&lt;h3 id="liens-avec-le-connected-account">Liens avec le connected account&lt;/h3>
&lt;p>Le liens avec le connexted account se fait lors de la creation du SDDC. Les frais réseau dû au débit sur cette interconnection n&amp;rsquo;est pas facturé par AWS. Une ENI est crée dans le compte.&lt;/p>
&lt;h3 id="liens-entre-sddc-et-la-transit-gateway">Liens entre SDDC et la transit gateway&lt;/h3>
&lt;p>Pour raccorder le SDDC a une transit gateway, le SDDC doit être raccorder a un SDDC group. C&amp;rsquo;est lui qui manage le liens entre le SDDC et la transite gateway.&lt;/p>
&lt;p>Pour connecter TGW externe, il faut avoir les informations :&lt;/p>
&lt;ul>
&lt;li>ID du compte : XXXXXXXXXXXX&lt;/li>
&lt;li>ID tgw : tgw-0eXXXXXXXXXX&lt;/li>
&lt;li>region : paris/paris&lt;/li>
&lt;li>Routage a mettre en place dans les SDDC vers les subnet externe.&lt;/li>
&lt;/ul>
&lt;h1 id="déploiement-dans-nsx">Déploiement dans NSX&lt;/h1>
&lt;p>Lors de l&amp;rsquo;implémentation des règles il faut distinguer les quelques règles d&amp;rsquo;infrastructure qui doivent être porté par la Gateway firewall (GFW) et l&amp;rsquo;ensemble des autres règles qui doivent être porté par le Distributed firewall.&lt;/p>
&lt;p>Il faut noter que tout les flux ouvert dans la GFW doivent en plus être ouvert dans le DFW.&lt;/p>
&lt;p>Dans notre projet nous avons opté pour l&amp;rsquo;intégration des règles via des fichiers CSV, ainsi la creation d&amp;rsquo;une nouvelle règle n&amp;rsquo;implique par la modification des fichier terraform.&lt;/p>
&lt;h3 id="exemple-de-creation-de-règles">Exemple de creation de règles&lt;/h3>
&lt;pre>&lt;code>resource &amp;quot;nsxt_policy_gateway_policy&amp;quot; &amp;quot;icmp_from_group&amp;quot; {
display_name = &amp;quot;icmp_from_group&amp;quot;
description = &amp;quot;icmp_from_group&amp;quot;
category = &amp;quot;LocalGatewayRules&amp;quot;
domain = &amp;quot;cgw&amp;quot;
rule {
action = &amp;quot;ALLOW&amp;quot;
display_name = &amp;quot;icmp_from_group&amp;quot;
source_groups = [nsxt_policy_group.group[&amp;quot;groupeSource&amp;quot;].path]
sources_excluded = false
destination_groups = [nsxt_policy_group.group[&amp;quot;groupeDestination&amp;quot;].path]
destinations_excluded = false
services = [data.nsxt_policy_service.icmp.path]
direction = &amp;quot;IN_OUT&amp;quot;
disabled = false
ip_version = &amp;quot;IPV4_IPV6&amp;quot;
logged = true
scope = [&amp;quot;/infra/labels/cgw-direct-connect&amp;quot;]
}
}
&lt;/code>&lt;/pre>&lt;ul>
&lt;li>Scope est le paramètre qui définie l&amp;rsquo;interface ou la règle s&amp;rsquo;applique. Elle peut être :
&lt;ul>
&lt;li>/infra/labels/cgw-all&lt;/li>
&lt;li>/infra/labels/cgw-vpn&lt;/li>
&lt;li>/infra/labels/cgw-public&lt;/li>
&lt;li>/infra/labels/cgw-cross-vpc&lt;/li>
&lt;li>/infra/labels/cgw-direct-connect&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>destinations_excluded peut être a &lt;code>true&lt;/code> ou &lt;code>false&lt;/code>. Cela permet d&amp;rsquo;inverser la règle pour la posé sur (tout ce qui n&amp;rsquo;est pas le groupe) ou ( tout ce qui est dans le groupe)&lt;/li>
&lt;/ul>
&lt;h2 id="gateway-firewall-rules">Gateway firewall rules&lt;/h2>
&lt;p>Lors de la vie du projet nous avons eu a recréer les règles de default gateway qui avais été détruite par Terraform&lt;/p>
&lt;pre>&lt;code>nsxt_policy_gateway_policy.mgw_policy: Destroying... [id=default]
nsxt_policy_gateway_policy.cgw_policy: Destroying... [id=default]
nsxt_policy_gateway_policy.mgw_policy: Destruction complete after 1s
nsxt_policy_gateway_policy.cgw_policy: Destruction complete after 2s
&lt;/code>&lt;/pre>&lt;p>Pour résoudre le problème nous avons utiliser les directement les API De NSX-T&lt;/p>
&lt;pre>&lt;code>API PUT policy/api/v1/infra/domains/mgw/gateway-policies/
{
&amp;quot;resource_type&amp;quot; : &amp;quot;GatewayPolicy&amp;quot;,
&amp;quot;id&amp;quot; : &amp;quot;default&amp;quot;,
&amp;quot;display_name&amp;quot; : &amp;quot;default&amp;quot;,
&amp;quot;path&amp;quot; : &amp;quot;/infra/domains/mgw/gateway-policies/default&amp;quot;,
&amp;quot;relative_path&amp;quot; : &amp;quot;default&amp;quot;,
&amp;quot;parent_path&amp;quot; : &amp;quot;/infra/domains/mgw&amp;quot;,
&amp;quot;marked_for_delete&amp;quot; : false,
&amp;quot;overridden&amp;quot; : false,
&amp;quot;sequence_number&amp;quot; : 0,
&amp;quot;internal_sequence_number&amp;quot; : 13000001,
&amp;quot;category&amp;quot; : &amp;quot;LocalGatewayRules&amp;quot;,
&amp;quot;stateful&amp;quot; : true,
&amp;quot;tcp_strict&amp;quot; : true,
&amp;quot;locked&amp;quot; : false,
&amp;quot;lock_modified_time&amp;quot; : 0,
&amp;quot;is_default&amp;quot; : false
}
API PUT policy/api/v1/infra/domains/cgw/gateway-policies/
{
&amp;quot;resource_type&amp;quot; : &amp;quot;GatewayPolicy&amp;quot;,
&amp;quot;id&amp;quot; : &amp;quot;default&amp;quot;,
&amp;quot;display_name&amp;quot; : &amp;quot;default&amp;quot;,
&amp;quot;path&amp;quot; : &amp;quot;/infra/domains/cgw/gateway-policies/default&amp;quot;,
&amp;quot;relative_path&amp;quot; : &amp;quot;default&amp;quot;,
&amp;quot;parent_path&amp;quot; : &amp;quot;/infra/domains/cgw&amp;quot;,
&amp;quot;marked_for_delete&amp;quot; : false,
&amp;quot;overridden&amp;quot; : false,
&amp;quot;sequence_number&amp;quot; : 0,
&amp;quot;internal_sequence_number&amp;quot; : 13000000,
&amp;quot;category&amp;quot; : &amp;quot;LocalGatewayRules&amp;quot;,
&amp;quot;stateful&amp;quot; : true,
&amp;quot;tcp_strict&amp;quot; : true,
&amp;quot;locked&amp;quot; : false,
&amp;quot;lock_modified_time&amp;quot; : 0,
&amp;quot;is_default&amp;quot; : false
}
&lt;/code>&lt;/pre>&lt;p>Cf : &lt;a href="https://blogs.vmware.com/cloud/2022/07/06/vmware-cloud-on-aws-terraform-deployment-phase-2/">vmware : deploy-and-configure-vmware-cloud-on-aws Part2&lt;/a>&lt;/p>
&lt;h1 id="déploiement-dans-vsphere">Déploiement dans vSphere&lt;/h1>
&lt;p>Lors du déploiement vsphere l&amp;rsquo;utilisation d&amp;rsquo;un référentiel YAML. Les problèmes rencontrés ont été sur lors de la construction des images des templates. Ils doivent avoir un attribue spécifique, il faut mettre &lt;code>otherLinux&lt;/code> / &lt;code>otherLinux64Guest&lt;/code>.&lt;/p>
&lt;p>Cf : &lt;a href="https://blogs.vmware.com/cloud/2022/07/15/vmware-cloud-on-aws-terraform-deployment-phase-3/">vmware : deploy-and-configure-vmware-cloud-on-aws Part3&lt;/a>&lt;/p></description></item><item><title>Publish in AWS a raspberryPi shot</title><link>https://blog.moulard.org/aws-raspberrypi-shot/</link><pubDate>Thu, 05 Jan 2023 13:00:00 +0100</pubDate><guid>https://blog.moulard.org/aws-raspberrypi-shot/</guid><comments>https://blog.moulard.org/aws-raspberrypi-shot/#disqus_thread</comments><description>&lt;h1 id="how-to-see-and-be-seen">How to see and be seen&lt;/h1>
&lt;p>The easiest way to publish the photos taken by the Raspberry and of course to take the photos on raspberry then publish them on
this one directly with a Web server.&lt;/p>
&lt;p>Why it is still necessary here our system in my case the reliability of my internet connection
of my raspberry prefer do not allow imagine published the photos so simply.
I had to imagine a system you allowed me to take the photos and then publish them on the AWS Cloud.
To do this I used on the raspberry side the raspistill software to take the photos, and the AWS CLI to send the documents on S3.
On the AWS side I used the features of S3 which allows you to publish a static website with the storage capacity to scale up and the availability of the Cloud.
To set up this infrastructure I used terraform&lt;/p>
&lt;h1 id="on-aws--side">on AWS side&lt;/h1>
&lt;p>To do this I used two web resource pages:
&lt;a href="https://medium.com/@dblencowe/hosting-a-static-website-on-s3-using-terraform-0-12-aa5ffe4103e">hosting a static website on s3 using terraform&lt;/a>
and
&lt;a href="https://github.com/rufuspollock/s3-bucket-listing">s3-bucket-listing&lt;/a>&lt;/p>
&lt;h2 id="terraform-setup">Terraform setup&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-shell" data-lang="shell">
git clone git@github.com:gmoulard/s3-static-website.git
cd s3-static-website
terraform init
export AWS_PROFILE&lt;span style="color:#f92672">=&lt;/span>default
export TF_VAR_domain_name&lt;span style="color:#f92672">=&lt;/span>to-drop1
export TF_VAR_aws_region&lt;span style="color:#f92672">=&lt;/span>eu-west-1
terraform apply
aws s3 sync dist s3://$TF_VAR_domain_name
&lt;/code>&lt;/pre>&lt;/div>&lt;p>you can test on yours browser: curl https://s3.$TF_VAR_aws_region.amazonaws.com/$TF_VAR_domain_name/listing.html
in my case: &lt;a href="https://s3.eu-west-1.amazonaws.com/to-drop1/listing.html">https://s3.eu-west-1.amazonaws.com/to-drop1/listing.html&lt;/a>&lt;/p>
&lt;h1 id="on-raspberry-pi">On Raspberry pi&lt;/h1>
&lt;p>After AWS CLI installation&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-shell" data-lang="shell">pip3 install awscli --upgrade --user
&lt;/code>&lt;/pre>&lt;/div>&lt;p>I can use configure for setup my AWS credential.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-shell" data-lang="shell">aws configure
&lt;/code>&lt;/pre>&lt;/div>&lt;p>I have add on script on my crontab&lt;/p>
&lt;h3 id="-crontab--l">$ crontab -l&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-shell" data-lang="shell">&lt;span style="color:#ae81ff">1&lt;/span> &lt;span style="color:#ae81ff">14&lt;/span> * * * /home/pi/photo/img.sh &lt;span style="color:#ae81ff">100&lt;/span>
*/15 * * * * /home/pi/photo/img.sh &lt;span style="color:#ae81ff">10&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="-cat-homepiphotoimgsh">$ cat /home/pi/photo/img.sh&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-shell" data-lang="shell">&lt;span style="color:#75715e">#!/bin/bash
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
PHOTO&lt;span style="color:#f92672">=&lt;/span>photoVDL-$1-&lt;span style="color:#66d9ef">$(&lt;/span>date +&lt;span style="color:#e6db74">&amp;#34;%Y-%m-%d_%H%M&amp;#34;&lt;/span>&lt;span style="color:#66d9ef">)&lt;/span>.jpg
raspistill -q $1 -rot &lt;span style="color:#ae81ff">270&lt;/span> -o /tmp/$PHOTO
/home/pi/.local/bin/aws s3 cp /tmp/$PHOTO s3://www.websitegmstatice.moulard.org/vdl-photo/
rm /tmp/$PHOTO
&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Use Active Direcotry from user management in linux machine</title><link>https://blog.moulard.org/adlinux/</link><pubDate>Tue, 12 Apr 2022 13:19:36 +0100</pubDate><guid>https://blog.moulard.org/adlinux/</guid><comments>https://blog.moulard.org/adlinux/#disqus_thread</comments><description>&lt;h2 id="step-to-setup">Step to setup&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">ssh -i youKey root@machineIP
&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>install required packages&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">sudo yum -y update
sudo yum -y install sssd realmd krb5-workstation samba-common-tools
&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>Setup DNS servers - add the two DNS address on Directory details in web console&lt;/li>
&lt;/ul>
&lt;p>change /etc/resolv.conf&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">nameserver //DNS address &lt;span style="color:#ae81ff">1&lt;/span> of Directory
nameserver //DNS address &lt;span style="color:#ae81ff">2&lt;/span> of Directory
&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>join the domain&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">sudo realm join -U Administrator@my.domaine.name my.domaine.name --verbose
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Set the SSH service to allow password authentication&lt;/p>
&lt;ul>
&lt;li>change /etc/ssh/sshd_config&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">PasswordAuthentication yes
&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>Add the following to the bottom of the sudoers file and save it&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">sudo nano /etc/sudoers
&lt;span style="color:#75715e">#Add the &amp;#34;Delegated Administrators&amp;#34; group from the my.domaine.name domain.&lt;/span>
%AWS&lt;span style="color:#ae81ff">\ &lt;/span>Delegated&lt;span style="color:#ae81ff">\ &lt;/span>Administrators@my.domaine.name ALL&lt;span style="color:#f92672">=(&lt;/span>ALL:ALL&lt;span style="color:#f92672">)&lt;/span> ALL
&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>restart the sssd service&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">sudo systemctl restart sshd.service
sudo systemctl restart sssd.service
&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>Disconnect and Reconnect using AD credentials&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">ssh -l Administrator@my.domaine.name machineIP
&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Klipse, a new way of blogging</title><link>https://blog.moulard.org/klipse-blogging/</link><pubDate>Tue, 31 Aug 2021 13:00:00 +0100</pubDate><guid>https://blog.moulard.org/klipse-blogging/</guid><comments>https://blog.moulard.org/klipse-blogging/#disqus_thread</comments><description>&lt;p>For a modern tech blogging framework, a live coding experience is quasi necessary.&lt;/p>
&lt;blockquote>
&lt;p>&lt;a href="https://github.com/viebel/klipse">Klipse&lt;/a> is a JavaScript plugin for embedding interactive code snippets in tech blogs.&lt;/p>
&lt;/blockquote>
&lt;p>To make this easy, you add a small library to your blog front end dependency, and voilà, you have your &lt;code>&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;/code> live executing in the browser.
As a bonus, your code can no be edited directly in the &lt;code>&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;/code> tags.&lt;/p>
&lt;p>Go check out &lt;a href="https://blog.klipse.tech/golang/2021/08/29/blog-go.html">this blog post&lt;/a> if you want to have more information about Klipse!&lt;/p>
&lt;h1 id="klipsify-your-blogging-framework">Klipsify your blogging framework&lt;/h1>
&lt;p>To integrate the klipse plugin on a blog, you have to follow 3 simple steps.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Make sure you have &lt;code>&amp;lt;!DOCTYPE html&amp;gt;&lt;/code> at the top of your html file and &lt;code>&amp;lt;meta charset=&amp;quot;utf-8&amp;quot;&amp;gt;&lt;/code> right after your &lt;code>&amp;lt;head&amp;gt;&lt;/code> (It is required to display properly elements used by Klipse.)&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Add css and custom configuration somewhere in the page (it could be in the &lt;code>&amp;lt;head&amp;gt;&lt;/code> or in the &lt;code>&amp;lt;body&amp;gt;&lt;/code>) before the &lt;code>&amp;lt;script&amp;gt;&lt;/code> element of step #3.
The selector keys are per language (you&amp;rsquo;ll find in &lt;a href="https://github.com/viebel/klipse#configuration">GitHub&lt;/a> a list of supported languages) and the value are the CSS selector of the elements that you want to klipsify.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-html" data-lang="html">&amp;lt;&lt;span style="color:#f92672">link&lt;/span> &lt;span style="color:#a6e22e">rel&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;stylesheet&amp;#34;&lt;/span> &lt;span style="color:#a6e22e">type&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;text/css&amp;#34;&lt;/span> &lt;span style="color:#a6e22e">href&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;https://storage.googleapis.com/app.klipse.tech/css/codemirror.css&amp;#34;&lt;/span>&amp;gt;
&amp;lt;&lt;span style="color:#f92672">script&lt;/span>&amp;gt;
window.&lt;span style="color:#a6e22e">klipse_settings&lt;/span> &lt;span style="color:#f92672">=&lt;/span> {
&lt;span style="color:#a6e22e">selector_golang&lt;/span>&lt;span style="color:#f92672">:&lt;/span> &lt;span style="color:#e6db74">&amp;#39;.language-klipse-eval-js&amp;#39;&lt;/span>, &lt;span style="color:#75715e">// css selector for the html elements you want to klipsify
&lt;/span>&lt;span style="color:#75715e">&lt;/span> };
&amp;lt;/&lt;span style="color:#f92672">script&lt;/span>&amp;gt;
&lt;/code>&lt;/pre>&lt;/div>&lt;ol start="3">
&lt;li>Add the JavaScript tag at the end of the body tag :&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-html" data-lang="html">&lt;span style="color:#75715e">&amp;lt;!-- ... --&amp;gt;&lt;/span>
&amp;lt;&lt;span style="color:#f92672">body&lt;/span>&amp;gt;
&lt;span style="color:#75715e">&amp;lt;!-- ... --&amp;gt;&lt;/span>
&amp;lt;&lt;span style="color:#f92672">script&lt;/span> &lt;span style="color:#a6e22e">src&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js&amp;#34;&lt;/span>&amp;gt;&amp;lt;/&lt;span style="color:#f92672">script&lt;/span>&amp;gt;
&amp;lt;/&lt;span style="color:#f92672">body&lt;/span>&amp;gt;
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="write-some-code">Write some code&lt;/h1>
&lt;p>Now that you have installed Klipse on your blog, it remains to add some code to a blog post.&lt;/p>
&lt;p>Add this code snippet to try it on:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-go" data-lang="go">&lt;span style="color:#f92672">import&lt;/span> &lt;span style="color:#e6db74">&amp;#34;fmt&amp;#34;&lt;/span>
&lt;span style="color:#66d9ef">func&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>() {
&lt;span style="color:#a6e22e">fmt&lt;/span>.&lt;span style="color:#a6e22e">Println&lt;/span>(&lt;span style="color:#e6db74">&amp;#34;Hello World! Klipse is so much fun !&amp;#34;&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>As you can see, this code is now live and interactive.&lt;/p>
&lt;p>Feel free to modify it to your own liking!&lt;/p>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;p>Live and interactive coding was a long dream of mine when creating this blog.&lt;/p>
&lt;p>Klipse made this dream super easy to integrate on my blog!&lt;/p>
&lt;p>This post was inspired by &lt;a href="https://github.com/viebel">@viebel&lt;/a>.&lt;/p></description></item><item><title>A Dynamic Web Site using Python and AWS Lambda</title><link>https://blog.moulard.org/serverless-python/</link><pubDate>Wed, 27 Jan 2021 10:40:17 +0100</pubDate><guid>https://blog.moulard.org/serverless-python/</guid><comments>https://blog.moulard.org/serverless-python/#disqus_thread</comments><description>&lt;p>Nous allons voir comment utiliser les Lambda d&amp;rsquo;AWS pour servir un site web
dynamique et en mode serverless.&lt;/p>
&lt;h1 id="python">Python&lt;/h1>
&lt;p>La fonction python que l&amp;rsquo;on va utiliser pour la lambda doit avoir deux
paramètres : &lt;code>event&lt;/code> et &lt;code>context&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-python" data-lang="python">&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">my_lambda_function&lt;/span>(event, context):
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#e6db74">&amp;#34;Hello world !&amp;#34;&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Pour donner une idée de ce que contiennent &lt;code>event&lt;/code> et &lt;code>context&lt;/code>, j&amp;rsquo;ai créé
cette fonction :&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-python" data-lang="python">&lt;span style="color:#f92672">import&lt;/span> os
&lt;span style="color:#f92672">import&lt;/span> json
&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">debug_lambda&lt;/span>(event, context):
json_region &lt;span style="color:#f92672">=&lt;/span> os&lt;span style="color:#f92672">.&lt;/span>environ[&lt;span style="color:#e6db74">&amp;#39;AWS_REGION&amp;#39;&lt;/span>]
&lt;span style="color:#66d9ef">return&lt;/span> {
&lt;span style="color:#e6db74">&amp;#34;statusCode&amp;#34;&lt;/span>: &lt;span style="color:#ae81ff">200&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;headers&amp;#34;&lt;/span>: {
&lt;span style="color:#e6db74">&amp;#34;Content-Type&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;application/json&amp;#34;&lt;/span>
},
&lt;span style="color:#e6db74">&amp;#34;body&amp;#34;&lt;/span>: json&lt;span style="color:#f92672">.&lt;/span>dumps({
&lt;span style="color:#e6db74">&amp;#34;Region &amp;#34;&lt;/span>: json_region,
&lt;span style="color:#e6db74">&amp;#39;event&amp;#39;&lt;/span> : str(event),
&lt;span style="color:#e6db74">&amp;#39;context&amp;#39;&lt;/span>: str(context)
})
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Où la réponse de la lambda donne :&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-json" data-lang="json">{
&lt;span style="color:#f92672">&amp;#34;Region &amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;eu-west-3&amp;#34;&lt;/span>,
&lt;span style="color:#f92672">&amp;#34;event&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;{&amp;#39;resource&amp;#39;: &amp;#39;/&amp;#39;, &amp;#39;path&amp;#39;: &amp;#39;/&amp;#39;, &amp;#39;httpMethod&amp;#39;: &amp;#39;GET&amp;#39;, &amp;#39;headers&amp;#39;: {&amp;#39;Accept&amp;#39;: &amp;#39;text/html&amp;#39;, &amp;#39;Accept-Encoding&amp;#39;: &amp;#39;gzip, deflate, br&amp;#39;, &amp;#39;cache-control&amp;#39;: &amp;#39;max-age=0&amp;#39;, &amp;#39;CloudFront-Forwarded-Proto&amp;#39;: &amp;#39;https&amp;#39;, &amp;#39;CloudFront-Is-Desktop-Viewer&amp;#39;: &amp;#39;true&amp;#39;, &amp;#39;CloudFront-Is-Mobile-Viewer&amp;#39;: &amp;#39;false&amp;#39;, &amp;#39;CloudFront-Is-SmartTV-Viewer&amp;#39;: &amp;#39;false&amp;#39;, &amp;#39;CloudFront-Is-Tablet-Viewer&amp;#39;: &amp;#39;false&amp;#39;, &amp;#39;CloudFront-Viewer-Country&amp;#39;: &amp;#39;FR&amp;#39;, &amp;#39;dnt&amp;#39;: &amp;#39;1&amp;#39;, &amp;#39;Host&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;sec-fetch-dest&amp;#39;: &amp;#39;document&amp;#39;, &amp;#39;sec-fetch-mode&amp;#39;: &amp;#39;navigate&amp;#39;, &amp;#39;sec-fetch-site&amp;#39;: &amp;#39;none&amp;#39;, &amp;#39;sec-fetch-user&amp;#39;: &amp;#39;?1&amp;#39;, &amp;#39;sec-gpc&amp;#39;: &amp;#39;1&amp;#39;, &amp;#39;upgrade-insecure-requests&amp;#39;: &amp;#39;1&amp;#39;, &amp;#39;User-Agent&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;Via&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;X-Amz-Cf-Id&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;X-Amzn-Trace-Id&amp;#39;: &amp;#39;Root=1-[REDACTED]&amp;#39;, &amp;#39;X-Forwarded-For&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;X-Forwarded-Port&amp;#39;: &amp;#39;443&amp;#39;, &amp;#39;X-Forwarded-Proto&amp;#39;: &amp;#39;https&amp;#39;}, &amp;#39;multiValueHeaders&amp;#39;: {&amp;#39;Accept&amp;#39;: [&amp;#39;text/html&amp;#39;], &amp;#39;Accept-Encoding&amp;#39;: [&amp;#39;gzip, deflate, br&amp;#39;], &amp;#39;Accept-Language&amp;#39;: [&amp;#39;fr-FR&amp;#39;], &amp;#39;cache-control&amp;#39;: [&amp;#39;max-age=0&amp;#39;], &amp;#39;CloudFront-Forwarded-Proto&amp;#39;: [&amp;#39;https&amp;#39;], &amp;#39;CloudFront-Is-Desktop-Viewer&amp;#39;: [&amp;#39;true&amp;#39;], &amp;#39;CloudFront-Is-Mobile-Viewer&amp;#39;: [&amp;#39;false&amp;#39;], &amp;#39;CloudFront-Is-SmartTV-Viewer&amp;#39;: [&amp;#39;false&amp;#39;], &amp;#39;CloudFront-Is-Tablet-Viewer&amp;#39;: [&amp;#39;false&amp;#39;], &amp;#39;CloudFront-Viewer-Country&amp;#39;: [&amp;#39;FR&amp;#39;], &amp;#39;dnt&amp;#39;: [&amp;#39;1&amp;#39;], &amp;#39;Host&amp;#39;: [&amp;#39;[REDACTED]&amp;#39;], &amp;#39;sec-fetch-dest&amp;#39;: [&amp;#39;document&amp;#39;], &amp;#39;sec-fetch-mode&amp;#39;: [&amp;#39;navigate&amp;#39;], &amp;#39;sec-fetch-site&amp;#39;: [&amp;#39;none&amp;#39;], &amp;#39;sec-fetch-user&amp;#39;: [&amp;#39;?1&amp;#39;], &amp;#39;sec-gpc&amp;#39;: [&amp;#39;1&amp;#39;], &amp;#39;upgrade-insecure-requests&amp;#39;: [&amp;#39;1&amp;#39;], &amp;#39;User-Agent&amp;#39;: [&amp;#39;[REDACTED]&amp;#39;], &amp;#39;Via&amp;#39;: [&amp;#39;[REDACTED]&amp;#39;], &amp;#39;X-Amz-Cf-Id&amp;#39;: [&amp;#39;[REDACTED]&amp;#39;], &amp;#39;X-Amzn-Trace-Id&amp;#39;: [&amp;#39;Root=1-[REDACTED]&amp;#39;], &amp;#39;X-Forwarded-For&amp;#39;: [&amp;#39;[REDACTED]&amp;#39;], &amp;#39;X-Forwarded-Port&amp;#39;: [&amp;#39;443&amp;#39;], &amp;#39;X-Forwarded-Proto&amp;#39;: [&amp;#39;https&amp;#39;]}, &amp;#39;queryStringParameters&amp;#39;: None, &amp;#39;multiValueQueryStringParameters&amp;#39;: None, &amp;#39;pathParameters&amp;#39;: None, &amp;#39;stageVariables&amp;#39;: None, &amp;#39;requestContext&amp;#39;: {&amp;#39;resourceId&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;resourcePath&amp;#39;: &amp;#39;/&amp;#39;, &amp;#39;httpMethod&amp;#39;: &amp;#39;GET&amp;#39;, &amp;#39;extendedRequestId&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;requestTime&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;path&amp;#39;: &amp;#39;/test&amp;#39;, &amp;#39;accountId&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;protocol&amp;#39;: &amp;#39;HTTP/1.1&amp;#39;, &amp;#39;stage&amp;#39;: &amp;#39;test&amp;#39;, &amp;#39;domainPrefix&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;requestTimeEpoch&amp;#39;: 1611741450517, &amp;#39;requestId&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;identity&amp;#39;: {&amp;#39;cognitoIdentityPoolId&amp;#39;: None, &amp;#39;accountId&amp;#39;: None, &amp;#39;cognitoIdentityId&amp;#39;: None, &amp;#39;caller&amp;#39;: None, &amp;#39;sourceIp&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;principalOrgId&amp;#39;: None, &amp;#39;accessKey&amp;#39;: None, &amp;#39;cognitoAuthenticationType&amp;#39;: None, &amp;#39;cognitoAuthenticationProvider&amp;#39;: None, &amp;#39;userArn&amp;#39;: None, &amp;#39;userAgent&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;user&amp;#39;: None}, &amp;#39;domainName&amp;#39;: &amp;#39;[REDACTED]&amp;#39;, &amp;#39;apiId&amp;#39;: &amp;#39;[REDACTED]&amp;#39;}, &amp;#39;body&amp;#39;: None, &amp;#39;isBase64Encoded&amp;#39;: False}&amp;#34;&lt;/span>,
&lt;span style="color:#f92672">&amp;#34;context&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;&amp;lt;__main__.LambdaContext object at 0x7f0f14df07c0&amp;gt;&amp;#34;&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Maintenant qu&amp;rsquo;on a ça, on peut faire tous ce qu&amp;rsquo;on veut :-)&lt;/p>
&lt;p>Pour pouvoir utiliser le code, il va falloir créer une archive zip.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ zip python.zip *.py
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="terraform">Terraform&lt;/h1>
&lt;p>Maintenant qu&amp;rsquo;on a une fonction python à faire tourner, il faut la déployer !
Dans ce tuto, nous utiliserons Terraform.&lt;/p>
&lt;p>Pour déployer sur AWS il faut avoir une clef d&amp;rsquo;accès avec son ID et son secret.
Cette clef peut être récupérée dans la partie IAM de la console AWS.&lt;/p>
&lt;h2 id="setup-terraform">Setup Terraform&lt;/h2>
&lt;p>Pour commencer, il faut dire a Terraform quel &lt;code>provider&lt;/code> utiliser:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-terraform" data-lang="terraform">&lt;span style="color:#66d9ef">provider&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">region&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;eu-west-3&amp;#34;&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>J&amp;rsquo;utilise &lt;code>eu-west-3&lt;/code>, mais vous pouvez utiliser n&amp;rsquo;importe quelle région :)&lt;/p>
&lt;h2 id="la-lambda">La Lambda&lt;/h2>
&lt;p>Pour la resource de la lambda, il faut avoir une resource de type &lt;code>aws_lambda_function&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-terraform" data-lang="terraform">&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_lambda_function&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;lambda_function&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">role&lt;/span> = &lt;span style="color:#a6e22e">aws_iam_role&lt;/span>.&lt;span style="color:#a6e22e">lambda_exec_role&lt;/span>.&lt;span style="color:#a6e22e">arn&lt;/span>
&lt;span style="color:#a6e22e">handler&lt;/span> = var.&lt;span style="color:#a6e22e">handler&lt;/span>
&lt;span style="color:#a6e22e">runtime&lt;/span> = var.&lt;span style="color:#a6e22e">runtime&lt;/span>&lt;span style="color:#75715e"> # le type de code utilisé (i.e. python3.8)
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">filename&lt;/span> = var.&lt;span style="color:#a6e22e">src_zip&lt;/span>&lt;span style="color:#75715e"> # le nom du ficher .zip contentant le code
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">function_name&lt;/span> = var.&lt;span style="color:#a6e22e">function_name&lt;/span>&lt;span style="color:#75715e"> # le nom de la fonction
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">source_code_hash&lt;/span> = filebase64sha256(var.&lt;span style="color:#a6e22e">src_zip&lt;/span>)
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Il faut aussi une resource de type &lt;code>aws_iam_role&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-terraform" data-lang="terraform">&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_iam_role&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;lambda_exec_role&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">name&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;lambda_exec&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">path&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;/&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">description&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;Allows Lambda Function to call AWS services on your behalf.&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">assume_role_policy&lt;/span> = &lt;span style="color:#f92672">&amp;lt;&amp;lt;EOF&lt;/span>&lt;span style="color:#e6db74">
&lt;/span>&lt;span style="color:#e6db74">{
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;Version&amp;#34;: &amp;#34;2012-10-17&amp;#34;,
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;Statement&amp;#34;: [
&lt;/span>&lt;span style="color:#e6db74"> {
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;Effect&amp;#34;: &amp;#34;Allow&amp;#34;,
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;Principal&amp;#34;: {
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;Service&amp;#34;: &amp;#34;lambda.amazonaws.com&amp;#34;
&lt;/span>&lt;span style="color:#e6db74"> },
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;Action&amp;#34;: &amp;#34;sts:AssumeRole&amp;#34;
&lt;/span>&lt;span style="color:#e6db74"> }
&lt;/span>&lt;span style="color:#e6db74"> ]
&lt;/span>&lt;span style="color:#e6db74">}
&lt;/span>&lt;span style="color:#e6db74">&lt;/span>&lt;span style="color:#f92672">EOF&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="la-gateway">La gateway&lt;/h2>
&lt;p>Pour pouvoir accéder au code de la lambda, il faut mettre une gateway API en tant que proxy.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-terraform" data-lang="terraform">&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_api_gateway_rest_api&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;example&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">name&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;ServerlessExample&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">description&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;Terraform Serverless Application Example&amp;#34;&lt;/span>
}
&lt;span style="color:#66d9ef">
&lt;/span>&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_api_gateway_resource&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;proxy&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">rest_api_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">id&lt;/span>
&lt;span style="color:#a6e22e">parent_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">root_resource_id&lt;/span>
&lt;span style="color:#a6e22e">path_part&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;proxy&amp;#34;&lt;/span>
}
&lt;span style="color:#66d9ef">
&lt;/span>&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_api_gateway_method&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;proxy&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">rest_api_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">id&lt;/span>
&lt;span style="color:#a6e22e">resource_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_resource&lt;/span>.&lt;span style="color:#a6e22e">proxy&lt;/span>.&lt;span style="color:#a6e22e">id&lt;/span>
&lt;span style="color:#a6e22e">http_method&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;ANY&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">authorization&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;NONE&amp;#34;&lt;/span>
}
&lt;span style="color:#66d9ef">
&lt;/span>&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_api_gateway_integration&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;lambda&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">rest_api_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">id&lt;/span>
&lt;span style="color:#a6e22e">resource_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_method&lt;/span>.&lt;span style="color:#a6e22e">proxy&lt;/span>.&lt;span style="color:#a6e22e">resource_id&lt;/span>
&lt;span style="color:#a6e22e">http_method&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_method&lt;/span>.&lt;span style="color:#a6e22e">proxy&lt;/span>.&lt;span style="color:#a6e22e">http_method&lt;/span>
&lt;span style="color:#a6e22e">integration_http_method&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;POST&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">type&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;AWS_PROXY&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">uri&lt;/span> = &lt;span style="color:#a6e22e">aws_lambda_function&lt;/span>.&lt;span style="color:#a6e22e">lambda_function&lt;/span>.&lt;span style="color:#a6e22e">invoke_arn&lt;/span>
}
&lt;span style="color:#66d9ef">
&lt;/span>&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_api_gateway_method&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;proxy_root&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">rest_api_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">id&lt;/span>
&lt;span style="color:#a6e22e">resource_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">root_resource_id&lt;/span>
&lt;span style="color:#a6e22e">http_method&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;ANY&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">authorization&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;NONE&amp;#34;&lt;/span>
}
&lt;span style="color:#66d9ef">
&lt;/span>&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_api_gateway_integration&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;lambda_root&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">rest_api_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">id&lt;/span>
&lt;span style="color:#a6e22e">resource_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_method&lt;/span>.&lt;span style="color:#a6e22e">proxy_root&lt;/span>.&lt;span style="color:#a6e22e">resource_id&lt;/span>
&lt;span style="color:#a6e22e">http_method&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_method&lt;/span>.&lt;span style="color:#a6e22e">proxy_root&lt;/span>.&lt;span style="color:#a6e22e">http_method&lt;/span>
&lt;span style="color:#a6e22e">integration_http_method&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;POST&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">type&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;AWS_PROXY&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">uri&lt;/span> = &lt;span style="color:#a6e22e">aws_lambda_function&lt;/span>.&lt;span style="color:#a6e22e">lambda_function&lt;/span>.&lt;span style="color:#a6e22e">invoke_arn&lt;/span>
}
&lt;span style="color:#66d9ef">
&lt;/span>&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_api_gateway_deployment&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;example&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">depends_on&lt;/span> = [
&lt;span style="color:#a6e22e">aws_api_gateway_integration&lt;/span>.&lt;span style="color:#a6e22e">lambda&lt;/span>,
&lt;span style="color:#a6e22e">aws_api_gateway_integration&lt;/span>.&lt;span style="color:#a6e22e">lambda_root&lt;/span>,
]
&lt;span style="color:#a6e22e">rest_api_id&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">id&lt;/span>
&lt;span style="color:#a6e22e">stage_name&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;test&amp;#34;&lt;/span>
}
&lt;span style="color:#66d9ef">
&lt;/span>&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;aws_lambda_permission&amp;#34;&lt;/span> &lt;span style="color:#e6db74">&amp;#34;apigw&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">statement_id&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;AllowAPIGatewayInvoke&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">action&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;lambda:InvokeFunction&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">function_name&lt;/span> = &lt;span style="color:#a6e22e">aws_lambda_function&lt;/span>.&lt;span style="color:#a6e22e">lambda_function&lt;/span>.&lt;span style="color:#a6e22e">function_name&lt;/span>
&lt;span style="color:#a6e22e">principal&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;apigateway.amazonaws.com&amp;#34;&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;span style="color:#75715e">
&lt;/span>&lt;span style="color:#75715e"> # The &amp;#34;/*/*&amp;#34; portion grants access from any method on any resource
&lt;/span>&lt;span style="color:#75715e"> # within the API Gateway REST API.
&lt;/span>&lt;span style="color:#75715e">&lt;/span> &lt;span style="color:#a6e22e">source_arn&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>&lt;span style="color:#a6e22e">aws_api_gateway_rest_api&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">execution_arn&lt;/span>&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">/*/*&amp;#34;&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Et pour enfin avoir l&amp;rsquo;url sur laquelle tapper pour voir le résultat de la fonction.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-terraform" data-lang="terraform">&lt;span style="color:#66d9ef">output&lt;/span> &lt;span style="color:#e6db74">&amp;#34;base_url&amp;#34;&lt;/span> {
&lt;span style="color:#a6e22e">value&lt;/span> = &lt;span style="color:#a6e22e">aws_api_gateway_deployment&lt;/span>.&lt;span style="color:#a6e22e">example&lt;/span>.&lt;span style="color:#a6e22e">invoke_url&lt;/span>
}
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Cela va donner:&lt;/p>
&lt;pre>&lt;code>Outputs:
base_url = https://wncgbhu7te.execute-api.eu-west-3.amazonaws.com/test
&lt;/code>&lt;/pre>&lt;p>La source du blog est disponible sur &lt;a href="https://github.com/tomMoulard/LambdaCSVChart/tree/blog">github&lt;/a>.
Et la lambda est accessible sur &lt;a href="https://wncgbhu7te.execute-api.eu-west-3.amazonaws.com/test">aws&lt;/a>.&lt;/p>
&lt;h1 id="aller-plus-loin">Aller plus loin&lt;/h1>
&lt;ul>
&lt;li>&lt;a href="https://github.com/tomMoulard/LambdaCSVChart/blob/main/.github/workflows/terraform.yml">github action publish&lt;/a>&lt;/li>
&lt;li>Utiliser un DNS (R53)&lt;/li>
&lt;/ul></description></item><item><title>iptable : Comment debug iptables ?</title><link>https://blog.moulard.org/iptablesdebug/</link><pubDate>Fri, 20 Nov 2020 13:19:36 +0100</pubDate><guid>https://blog.moulard.org/iptablesdebug/</guid><comments>https://blog.moulard.org/iptablesdebug/#disqus_thread</comments><description>&lt;h1 id="iptables-comment-ça-fonctionne-">iptables, comment ça fonctionne ?&lt;/h1>
&lt;p>Mes deux URLs de références :&lt;/p>
&lt;ul>
&lt;li>Le livre: &lt;a href="https://inetdoc.net/pdf/iptables-tutorial.pdf">https://inetdoc.net/pdf/iptables-tutorial.pdf&lt;/a>&lt;/li>
&lt;li>Le man: &lt;a href="http://www.delafond.org/traducmanfr/man/man8/iptables.8.html">http://www.delafond.org/traducmanfr/man/man8/iptables.8.html&lt;/a>&lt;/li>
&lt;/ul>
&lt;h1 id="comment-savoir-si-un-filtre-est-utilisé-">Comment savoir si un filtre est utilisé ?&lt;/h1>
&lt;p>Le paramètre magique est &lt;code>-vnL&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#75715e"># iptables -vnL&lt;/span>
Chain INPUT &lt;span style="color:#f92672">(&lt;/span>policy ACCEPT &lt;span style="color:#ae81ff">0&lt;/span> packets, &lt;span style="color:#ae81ff">0&lt;/span> bytes&lt;span style="color:#f92672">)&lt;/span>
pkts bytes target prot opt in out source destination
&lt;span style="color:#ae81ff">34250&lt;/span> 1884K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
&lt;span style="color:#ae81ff">0&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span> ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
&lt;span style="color:#ae81ff">0&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span> ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
&lt;span style="color:#ae81ff">13&lt;/span> &lt;span style="color:#ae81ff">780&lt;/span> ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
&lt;span style="color:#ae81ff">3068&lt;/span> 1194K REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD &lt;span style="color:#f92672">(&lt;/span>policy ACCEPT &lt;span style="color:#ae81ff">25664&lt;/span> packets, 4647K bytes&lt;span style="color:#f92672">)&lt;/span>
pkts bytes target prot opt in out source destination
Chain OUTPUT &lt;span style="color:#f92672">(&lt;/span>policy ACCEPT &lt;span style="color:#ae81ff">30801&lt;/span> packets, 4552K bytes&lt;span style="color:#f92672">)&lt;/span>
pkts bytes target prot opt in out source destination
&lt;/code>&lt;/pre>&lt;/div>&lt;p>On peut voir que 3068 paquets ont été &lt;code>REJECT&lt;/code> par la règle &lt;code>5&lt;/code> lors de l&amp;rsquo;entrée sur le system &lt;code>INPUT&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#75715e"># iptables -t nat -vnL&lt;/span>
Chain PREROUTING &lt;span style="color:#f92672">(&lt;/span>policy ACCEPT &lt;span style="color:#ae81ff">73305&lt;/span> packets, 4104K bytes&lt;span style="color:#f92672">)&lt;/span>
pkts bytes target prot opt in out source destination
&lt;span style="color:#ae81ff">23&lt;/span> &lt;span style="color:#ae81ff">11316&lt;/span> DNAT udp -- eth1 * xxx.xxx.xxx.xxx 0.0.0.0/0 udp dpt:500 to:yyy.yyy.yyy.yyy:500
&lt;span style="color:#ae81ff">1&lt;/span> &lt;span style="color:#ae81ff">384&lt;/span> DNAT udp -- eth1 * xxx.xxx.xxx.xxx 0.0.0.0/0 udp dpt:4500 to:yyy.yyy.yyy.yyy:4500
&lt;span style="color:#ae81ff">0&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span> DNAT udp -- eth1 * yyy.yyy.yyy.yyy 0.0.0.0/0 udp dpt:500 to:xxx.xxx.xxx.xxx:500
&lt;span style="color:#ae81ff">0&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span> DNAT udp -- eth1 * yyy.yyy.yyy.yyy 0.0.0.0/0 udp dpt:4500 to:xxx.xxx.xxx.xxx:4500
Chain INPUT &lt;span style="color:#f92672">(&lt;/span>policy ACCEPT &lt;span style="color:#ae81ff">4&lt;/span> packets, &lt;span style="color:#ae81ff">240&lt;/span> bytes&lt;span style="color:#f92672">)&lt;/span>
pkts bytes target prot opt in out source destination
Chain OUTPUT &lt;span style="color:#f92672">(&lt;/span>policy ACCEPT &lt;span style="color:#ae81ff">128&lt;/span> packets, &lt;span style="color:#ae81ff">10244&lt;/span> bytes&lt;span style="color:#f92672">)&lt;/span>
pkts bytes target prot opt in out source destination
Chain POSTROUTING &lt;span style="color:#f92672">(&lt;/span>policy ACCEPT &lt;span style="color:#ae81ff">0&lt;/span> packets, &lt;span style="color:#ae81ff">0&lt;/span> bytes&lt;span style="color:#f92672">)&lt;/span>
pkts bytes target prot opt in out source destination
&lt;span style="color:#ae81ff">130&lt;/span> &lt;span style="color:#ae81ff">11120&lt;/span> MASQUERADE all -- * * 0.0.0.0/0 0.0.0.0/0
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Ici on peut voir que la règle de NAT 1 a été appliquée sur 23 paquets.
Les règles &lt;code>3&lt;/code> et &lt;code>4&lt;/code> n&amp;rsquo;ont traité aucun paquet.&lt;/p>
&lt;h1 id="comment-demander-a-iptables-de-loger-les-paquets-">Comment demander a iptables de loger les paquets ?&lt;/h1>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">iptables -I INPUT &lt;span style="color:#ae81ff">1&lt;/span> -j LOG --log-level &lt;span style="color:#ae81ff">7&lt;/span> --log-prefix &lt;span style="color:#e6db74">&amp;#34;INPUT : &amp;#34;&lt;/span>
iptables -I FORWARD &lt;span style="color:#ae81ff">1&lt;/span> -j LOG --log-level &lt;span style="color:#ae81ff">7&lt;/span> --log-prefix &lt;span style="color:#e6db74">&amp;#34;FORWARD : &amp;#34;&lt;/span>
iptables -I OUTPUT &lt;span style="color:#ae81ff">1&lt;/span> -j LOG --log-level &lt;span style="color:#ae81ff">7&lt;/span> --log-prefix &lt;span style="color:#e6db74">&amp;#34;OUTPUT : &amp;#34;&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Avec ces filtres positionnés, &lt;code>iptables&lt;/code> va envoyer les logs pour les paquets qui arrivent &lt;code>INPUT&lt;/code>, ils sont retransmit &lt;code>FORWARD&lt;/code> ou envoyés &lt;code>OUTPUT&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">iptables -t nat -I PREROUTING &lt;span style="color:#ae81ff">1&lt;/span> -j LOG --log-level &lt;span style="color:#ae81ff">7&lt;/span> --log-prefix &lt;span style="color:#e6db74">&amp;#34;PREROUTING : &amp;#34;&lt;/span>
iptables -t nat -I POSTROUTING &lt;span style="color:#ae81ff">1&lt;/span> -j LOG --log-level &lt;span style="color:#ae81ff">7&lt;/span> --log-prefix &lt;span style="color:#e6db74">&amp;#34;POSTROUTING : &amp;#34;&lt;/span>
iptables -t nat -I OUTPUT &lt;span style="color:#ae81ff">1&lt;/span> -j LOG --log-level &lt;span style="color:#ae81ff">7&lt;/span> --log-prefix &lt;span style="color:#e6db74">&amp;#34;NAT OUTPUT : &amp;#34;&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Ici les paquets qui passent par les tables de NAT seront envoyés dans les logs de la machine.&lt;/p>
&lt;p>Depuis la version 3.x il est possible d&amp;rsquo;utiliser &lt;strong>-j TRACE&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">iptables -t raw -A OUTPUT -p icmp -j TRACE
&lt;/code>&lt;/pre>&lt;/div>&lt;p>merci &lt;strong>Ludo&lt;/strong> pour le liens : &lt;a href="https://www.opensourcerers.org/2016/05/27/how-to-trace-iptables-in-rhel7-centos7/">https://www.opensourcerers.org/2016/05/27/how-to-trace-iptables-in-rhel7-centos7/&lt;/a>&lt;/p>
&lt;h2 id="comment-consulter-les-logs">Comment consulter les logs?&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ dmesg -H
&lt;span style="color:#f92672">[&lt;/span>Nov19 14:49&lt;span style="color:#f92672">]&lt;/span> FORWARD : IN&lt;span style="color:#f92672">=&lt;/span>eth1 OUT&lt;span style="color:#f92672">=&lt;/span>eth1 MAC&lt;span style="color:#f92672">=&lt;/span>fa:16:3e:e6:11:db:fa:16:3e:cc:4b:7e:08:00 SRC&lt;span style="color:#f92672">=&lt;/span>195.25.2
&lt;span style="color:#f92672">[&lt;/span> +0.079319&lt;span style="color:#f92672">]&lt;/span> FORWARD : IN&lt;span style="color:#f92672">=&lt;/span>eth1 OUT&lt;span style="color:#f92672">=&lt;/span>eth1 MAC&lt;span style="color:#f92672">=&lt;/span>fa:16:3e:e6:11:db:fa:16:3e:cc:4b:7e:08:00 SRC&lt;span style="color:#f92672">=&lt;/span>90.115.1
&lt;span style="color:#f92672">[&lt;/span> +3.939384&lt;span style="color:#f92672">]&lt;/span> FORWARD : IN&lt;span style="color:#f92672">=&lt;/span>eth1 OUT&lt;span style="color:#f92672">=&lt;/span>eth1 MAC&lt;span style="color:#f92672">=&lt;/span>fa:16:3e:e6:11:db:fa:16:3e:cc:4b:7e:08:00 SRC&lt;span style="color:#f92672">=&lt;/span>195.25.2
&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>VPN : Comment NATer un VPN IPSEC?</title><link>https://blog.moulard.org/nat-vpn/</link><pubDate>Fri, 20 Nov 2020 13:19:36 +0100</pubDate><guid>https://blog.moulard.org/nat-vpn/</guid><comments>https://blog.moulard.org/nat-vpn/#disqus_thread</comments><description>&lt;h1 id="qa">Q/A&lt;/h1>
&lt;h2 id="est-il-possible-de-faire-du-nat-sur-un-firewall">Est-il possible de faire du NAT sur un firewall&lt;/h2>
&lt;p>&lt;strong>Oui&lt;/strong>&lt;/p>
&lt;p>C&amp;rsquo;est un peu contre intuitif, mais oui il est possible de faire du NAT de vpn ipsec.&lt;/p>
&lt;p>Habituellement un VPN IPSEC est entre &lt;code>@IP-Partener1&lt;/code> et &lt;code>@IP-Partener2&lt;/code>.
En fait, il est tout à fait possible d&amp;rsquo;introduire un intermédiaire qui NAT les 2 flux UDP nécessaires au VPN IPSEC &lt;code>500-dpt:isakmp&lt;/code> et &lt;code>4500-dpt:ipsec-nat-t&lt;/code>:&lt;/p>
&lt;script src="https://unpkg.com/mermaid@11.12.0/dist/mermaid.min.js" type="text/javascript">&lt;/script>
&lt;script type="text/javascript">
mermaid.initialize({ startOnLoad:true });
&lt;/script>
&lt;pre class="mermaid" align="center">
graph LR;
A["@IP-Partener1"]
B["@NAT"]
C["@IP-Partener2"]
A --> B --> C
C --> B --> A
&lt;/pre>
&lt;p>Cela à été testé sur de multiples technologies de VPN sans poser de problème d&amp;rsquo;implémentation.&lt;/p>
&lt;h2 id="est-il-possible-dutiliser-des-fqdn-pour-mettre-en-place-des-vpns">Est-il possible d&amp;rsquo;utiliser des FQDN pour mettre en place des VPNs&lt;/h2>
&lt;p>&lt;strong>Oui&lt;/strong>&lt;/p>
&lt;p>Par exemple sur l&amp;rsquo;interface des PFsence pour la remote gateway il est noté:
&lt;code>Enter the public IP address or host name of the remote gateway&lt;/code>.&lt;/p>
&lt;h1 id="mettre-en-place-du-nat-dun-vpn-sur-centos7-iptables">Mettre en place du NAT d&amp;rsquo;un VPN sur &lt;code>centOS7-iptables&lt;/code>.&lt;/h1>
&lt;h2 id="step-1--installer-les-softs-et-paramétrer-los">Step 1 : Installer les softs et paramétrer l&amp;rsquo;OS&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ package yum install -y iptables tcpdump iptables-services
$ systemctl enable iptables
$ systemctl start iptables
$ echo &lt;span style="color:#e6db74">&amp;#34;1&amp;#34;&lt;/span> &amp;gt; /proc/sys/net/ipv4/ip_forward
$ sysctl -w net.ipv4.ip_forward&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="step-2--valider-le-routage">Step 2 : Valider le routage&lt;/h2>
&lt;p>Pour que le NAT fonctionne sur la machine il faut que les 2 partenaires soient accessibles.
L&amp;rsquo;utilisation conjointe de 2 commandes permet de valider cela:&lt;/p>
&lt;ul>
&lt;li>&lt;code>tcpdump -p -i eth1 port 500&lt;/code> permet de voir les paquets passés&lt;/li>
&lt;li>&lt;code>telnet $IP-Partener2 500&lt;/code> permet de générer des paquets&lt;/li>
&lt;/ul>
&lt;h2 id="step-3--installer-les-règles-de-nat-des-2-flux-et-paramétrer-la-bonne-redirection-">Step 3 : Installer les règles de NAT des 2 flux et paramétrer la bonne redirection :&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ iptables -t nat -A PREROUTING -p udp -s $IP-Partener1 --dport &lt;span style="color:#ae81ff">500&lt;/span> -i eth1 -j DNAT --to $IP-Partener2:500
$ iptables -t nat -A PREROUTING -p udp -s $IP-Partener1 --dport &lt;span style="color:#ae81ff">4500&lt;/span> -i eth1 -j DNAT --to $IP-Partener2:4500
$ iptables -t nat -A PREROUTING -p udp -s $IP-Partener2 --dport &lt;span style="color:#ae81ff">500&lt;/span> -i eth1 -j DNAT --to $IP-Partener1:500
$ iptables -t nat -A PREROUTING -p udp -s $IP-Partener2 --dport &lt;span style="color:#ae81ff">4500&lt;/span> -i eth1 -j DNAT --to $IP-Partener1:4500
$ iptables -F FORWARD
$ iptables -t nat -A POSTROUTING -j MASQUERADE
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="mettre-en-place-du-nat-dun-vpn-sur-packet-filter">Mettre en place du NAT d&amp;rsquo;un VPN sur packet filter.&lt;/h1>
&lt;p>Voila un exemple de règle de nat:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#75715e">#rdr on vtnet0 inet proto udp from $IP-Partener1 port = isakmp to $IPInterfaceOne port = isakmp -&amp;gt; $IP-Partener2&lt;/span>
&lt;span style="color:#75715e">#rdr on vtnet0 inet proto udp from $IP-Partener2 port = isakmp to $IPInterfaceOne port = isakmp -&amp;gt; $IP-Partener1&lt;/span>
&lt;span style="color:#75715e">#rdr on vtnet0 inet proto udp from $IP-Partener1 port = sae-urn to $IPInterfaceOne port = sae-urn -&amp;gt; $IP-Partener2&lt;/span>
&lt;span style="color:#75715e">#rdr on vtnet0 inet proto udp from $IP-Partener2 port = sae-urn to $IPInterfaceOne port = sae-urn -&amp;gt; $IP-Partener1&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="quelques-liens-utiles-">Quelques liens utiles :&lt;/h1>
&lt;ul>
&lt;li>Le livre : &lt;a href="https://inetdoc.net/pdf/iptables-tutorial.pdf">https://inetdoc.net/pdf/iptables-tutorial.pdf&lt;/a>&lt;/li>
&lt;li>La doc CentOS pour mettre en place du NAT : &lt;a href="http://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-sg-fr-4/s1-firewall-ipt-fwd.html">http://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-sg-fr-4/s1-firewall-ipt-fwd.html&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>A Traefik Hackaethon</title><link>https://blog.moulard.org/traefik-hackaethon/</link><pubDate>Tue, 27 Oct 2020 16:00:00 +0200</pubDate><guid>https://blog.moulard.org/traefik-hackaethon/</guid><comments>https://blog.moulard.org/traefik-hackaethon/#disqus_thread</comments><description>&lt;h1 id="the-beginning-of-a-long-story">The beginning of a long story&lt;/h1>
&lt;p>At The root of this story, I, one of the author (&lt;a href="https://tom.moulard.org">Tom Moulard&lt;/a>). I used Traefik for my &lt;a href="https://github.com/tomMoulard/make-my-server">home server configuration&lt;/a> and I was looking for an internship. On my journey, I stumbled upon a &lt;a href="https://traefik.io/blog/announcing-the-inaugural-traefik-hackaethon-2020-in-october/">Traefik Hackaethon&lt;/a>, a fun project with a cash prize and mainly goodies \o/&lt;/p>
&lt;p>Looking for a team, I looked for some of the best student to come working with me. And I found:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://github.com/nitra-mfs">Martin Huvelle&lt;/a> (the co author)&lt;/li>
&lt;li>&lt;a href="https://www.linkedin.com/in/alexandre-bossut-lasry/">Alexandre Bossut-Lasry&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/cledavid">Clément David&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>We are a team of EPITA student in the TCOM major, and we are all working as teachers assistants to prepare and teach practical courses on our fields of studies.&lt;/p>
&lt;p>We had a master plan to have fun in this hackaethon. First we build a &amp;ldquo;small&amp;rdquo; plugin to warm up on Tuesday and then the big project to really have fun during those three days.&lt;/p>
&lt;p>The plan:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Day&lt;/th>
&lt;th>Task&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Tuesday&lt;/td>
&lt;td>Warm up and try a simple plugin&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Wednesday&lt;/td>
&lt;td>Implement all main features&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Thursday&lt;/td>
&lt;td>Go full hardcore and fix every bug&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>During this time, we even did some gophers (Go mascots) for each of us.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Tom Moulard&lt;/th>
&lt;th>Clément David&lt;/th>
&lt;th>Martin Huvelle&lt;/th>
&lt;th>Alexandre Bossut-Lasry&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;a href="https://tom.moulard.org">&lt;img src="https://blog.moulard.org/img/2020/traefik/gopher-tom_moulard.png" alt="">&lt;/a>&lt;/td>
&lt;td>&lt;a href="https://github.com/cledavid">&lt;img src="https://blog.moulard.org/img/2020/traefik/gopher-clement_david.png" alt="">&lt;/a>&lt;/td>
&lt;td>&lt;a href="https://github.com/nitra-mfs">&lt;img src="https://blog.moulard.org/img/2020/traefik/gopher-martin_huvelle.png" alt="">&lt;/a>&lt;/td>
&lt;td>&lt;a href="https://www.linkedin.com/in/alexandre-bossut-lasry/">&lt;img src="https://blog.moulard.org/img/2020/traefik/gopher-alexandre_bossut-lasry.png" alt="">&lt;/a>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h1 id="day-1-the-warm-up">Day 1, The warm up.&lt;/h1>
&lt;p>We had a &lt;a href="https://traefik.io/resources/plugin-to-traefik-create-and-publish-your-own-middleware-3/">demo&lt;/a> from &lt;a href="https://twitter.com/notsureifkevin">Kevin Crawley&lt;/a> a few days prior the Tuesday.&lt;/p>
&lt;p>It was a demo on how to add a Header on a request. Thus, starting from there, managing headers was an easy task for us. Therefore we made &lt;a href="https://github.com/tomMoulard/htransformation">htransformation&lt;/a>.&lt;/p>
&lt;p>&lt;a href="https://github.com/tomMoulard/htransformation">&lt;img src="https://gh-card.dev/repos/tommoulard/htransformation.svg" alt="htranformation github card">&lt;/a>&lt;/p>
&lt;p>By the end of the day, we published the plugin on &lt;a href="https://pilot.traefik.io/plugins/279923829278507529/header-transformation">traefik pilot&lt;/a>.&lt;/p>
&lt;h1 id="day-2-some-dark-times">Day 2, Some dark times&lt;/h1>
&lt;p>Wednesday morning, the dark time of our hackatheon. We needed an idea, not only an idea that would be fun (believe me we had a lot) but one that would be useful !
We had a lot of chat with one of the organizer (Thank you &lt;a href="https://twitter.com/manuel_zapf">Santo&lt;/a> for all of your help, support and motivation !). After a lot of &amp;ldquo;Santo! We got an idea !!!&amp;rdquo; and a &amp;ldquo;Yeah that&amp;rsquo;s sounds fun but what would be the purpose of this?&amp;rdquo; we finally extract the idea of &amp;ldquo;fail2ban&amp;rdquo; integration.&lt;/p>
&lt;p>To be sure that no one had did this, as usual we check github, traefik etc. Nothing, until we check discord, our future teammate Mike had the same idea. So we decided to team up (We didn&amp;rsquo;t know how much it would be a good idea) !&lt;/p>
&lt;h1 id="day-3-a-happy-ending">Day 3, A happy ending&lt;/h1>
&lt;p>After a lot of hours, thinking about the design and coding every piece of the plugin, combine every part we each created. We had one last bug, we tried everything, review every lines with differents people at each time.
Last helping call, we ask the discord about our issue, of course after few second we post, we managed to solve it and of course the patch was &amp;ldquo;use caps for your config variables&amp;rdquo;. Typical, we even stumbled upon this reflection for the first plugin.&lt;/p>
&lt;p>The plugin worked, all of the tests displayed &amp;ldquo;&lt;a href="https://travis-ci.com/github/tomMoulard/fail2ban/jobs/403817444">PASSED&lt;/a>&amp;rdquo;, &lt;a href="https://github.com/tomMoulard/fail2ban/commit/ebea16634226d7846c0c9b576872f76740ef1579">we did it&lt;/a> !&lt;/p>
&lt;p>The last job we had was to push the plugin &lt;a href="https://github.com/tomMoulard/fail2ban">Fail2Ban&lt;/a> on &lt;a href="https://pilot.traefik.io/plugins/280093067746214409/fail2-ban">traefik pilot&lt;/a>.&lt;/p>
&lt;p>&lt;a href="https://github.com/tomMoulard/fail2ban">&lt;img src="https://gh-card.dev/repos/tommoulard/fail2ban.svg" alt="Fail2ban github card">&lt;/a>&lt;/p>
&lt;p>We were proud and we learn a lot in a very short period of time but what we didn&amp;rsquo;t know was the next mail which arrived at midnight the next day. I looked quickly thinking it was a simple mail which thanks us to participate but the mention &amp;ldquo;I would like to proudly announce that you have won FIRST PLACE!!&amp;rdquo; did not sound usual for a &amp;ldquo;thanks for your participation&amp;rdquo; kind of mail.&lt;/p>
&lt;h1 id="wrapping-up">Wrapping up&lt;/h1>
&lt;p>We&amp;rsquo;d like to thanks Traefik for organizing this amazing event !
And &lt;a href="https://www.epita.fr">EPITA&lt;/a> for providing the structure to hold us during theses difficult times.&lt;/p>
&lt;p>Thanks to this experience, we became &lt;a href="https://info.traefik.io/traefik-ambassador-program">Traefik Ambassador&lt;/a> !&lt;/p>
&lt;p>&lt;img src="https://blog.moulard.org/img/2020/traefik/traefik-ambassador-flatten.svg" alt="We are Traefik Ambassador">&lt;/p></description></item><item><title>Comment bien installer docker ?</title><link>https://blog.moulard.org/installer-docker/</link><pubDate>Tue, 06 Oct 2020 12:00:00 +0100</pubDate><guid>https://blog.moulard.org/installer-docker/</guid><comments>https://blog.moulard.org/installer-docker/#disqus_thread</comments><description>&lt;p>Vu que c&amp;rsquo;est une question que me revient souvent, voila un petit tutoriel sur comment installer docker proprement et surtout comment le configurer.&lt;/p>
&lt;h1 id="comment-installer-docker-">Comment installer docker ?&lt;/h1>
&lt;h2 id="sur-windows-ou-mac">Sur windows ou Mac&lt;/h2>
&lt;p>&lt;a href="https://www.docker.com/products/docker-desktop">Docker Desktop&lt;/a> est pour moi un bon compromis pour l&amp;rsquo;installation de Docker sur Windows ou Mac.&lt;/p>
&lt;p>Le GUI apporte une manière simple de visualiser se qui se passe dans docker.&lt;/p>
&lt;h2 id="sur-une-distro-basée-sur-debian">Sur une Distro basée sur Debian&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">sudo apt install -y docker docker.io
sudo groupadd docker
sudo gpasswd -a $USER docker
newgrp docker
reboot
&lt;/code>&lt;/pre>&lt;/div>&lt;p>La commande &lt;code>newgrp docker&lt;/code> permet d&amp;rsquo;utiliser docker sans avoir à le préfixer de &lt;code>sudo&lt;/code>.&lt;/p>
&lt;h2 id="sur-une-distro-basée-sur-arch">Sur une Distro basée sur Arch&lt;/h2>
&lt;p>Avec l&amp;rsquo;user &lt;code>root&lt;/code> (&lt;code>sudo su&lt;/code>), faire:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-zsh" data-lang="zsh">pacman -Syu docker docker-compose
groupadd docker
gpasswd -a $USER docker
systemctl enable docker
systemctl start docker
newgrp docker
reboot
&lt;/code>&lt;/pre>&lt;/div>&lt;p>La commande &lt;code>newgrp docker&lt;/code> permet d&amp;rsquo;utiliser docker sans avoir à le préfixer de &lt;code>sudo&lt;/code>.&lt;/p>
&lt;h2 id="sur-une-distro-basée-sur-centos">Sur une Distro basée sur Centos&lt;/h2>
&lt;p>Avec l&amp;rsquo;user &lt;code>root&lt;/code> (&lt;code>sudo su&lt;/code>), faire:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">yum install -y yum-utils
yum-config-manager &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --add-repo &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> https://download.docker.com/linux/centos/docker-ce.repo
yum install --allowerasing -y docker-ce docker-ce-cli containerd.io
systemctl enable docker
systemctl start docker
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="tester-son-installation">Tester son installation:&lt;/h1>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">docker run hello-world
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="comment-installer-docker-compose-">Comment installer docker-compose ?&lt;/h1>
&lt;p>On peut utiliser la dernière version de &lt;code>docker-compose&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">curl -L https://github.com/docker/compose/releases/download/&lt;span style="color:#66d9ef">$(&lt;/span>curl -Ls https://www.servercow.de/docker-compose/latest.php&lt;span style="color:#66d9ef">)&lt;/span>/docker-compose-&lt;span style="color:#66d9ef">$(&lt;/span>uname -s&lt;span style="color:#66d9ef">)&lt;/span>-&lt;span style="color:#66d9ef">$(&lt;/span>uname -m&lt;span style="color:#66d9ef">)&lt;/span> &amp;gt; /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Sinon, il faut utiliser la dernière version présente sur les repository de la distro que vous utilisez.&lt;/p></description></item><item><title>Fibonacci et Phi</title><link>https://blog.moulard.org/phibonacci/</link><pubDate>Thu, 01 Oct 2020 13:10:04 +0200</pubDate><guid>https://blog.moulard.org/phibonacci/</guid><comments>https://blog.moulard.org/phibonacci/#disqus_thread</comments><description>&lt;h1 id="fibonacci-et-phi">Fibonacci et $\phi$&lt;/h1>
&lt;p>En tant qu&amp;rsquo;utilisateur de Youtube, je suis récemment tombé sur la vidéo
&lt;a href="https://www.youtube.com/watch?v=48sCx-wBs34">The Infinite Pattern That Never Repeats&lt;/a>
par &lt;a href="https://www.youtube.com/channel/UCHnyfMqiRRG1u-2MsSQLbXA">Veritasium&lt;/a>.
Et à un moment, (précisément &lt;a href="https://youtu.be/48sCx-wBs34?t=895">14:55&lt;/a>), il explique la relation
entre la suite de Fibonacci et le &lt;code>golden ratio&lt;/code>.&lt;/p>
&lt;blockquote>
&lt;p>The ratio of one fibonacci number to the previous one approaches the golden
ratio&lt;/p>
&lt;p>&amp;ndash; &lt;!-- raw HTML omitted -->&lt;a href="https://youtu.be/48sCx-wBs34?t=895">Derek Muller&lt;/a>&lt;!-- raw HTML omitted -->&lt;/p>
&lt;/blockquote>
&lt;p>Mais ne serait-ce pas quelque chose que nous pourrions observer simplement
avec un peut de python ?&lt;/p>
&lt;h2 id="python">Python&lt;/h2>
&lt;p>Il décidé d&amp;rsquo;écrire la fonction &lt;code>fibo&lt;/code> qui afficherais les &lt;code>n&lt;/code> premières
valeurs de la suite:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-python" data-lang="python">&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">fibo&lt;/span>(n):
&lt;span style="color:#66d9ef">print&lt;/span>(&lt;span style="color:#ae81ff">1&lt;/span>)
prev &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
actual &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> i &lt;span style="color:#f92672">in&lt;/span> range(n):
&lt;span style="color:#66d9ef">print&lt;/span>(actual)
tmp &lt;span style="color:#f92672">=&lt;/span> actual
actual &lt;span style="color:#f92672">+=&lt;/span> prev
prev &lt;span style="color:#f92672">=&lt;/span> tmp
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Si on essaye avec 5, on se retrouve avec:&lt;/p>
&lt;pre>&lt;code>&amp;gt;&amp;gt;&amp;gt; fibo(5)
1
1
2
3
5
8
&lt;/code>&lt;/pre>&lt;p>Maintenant, ajoutons un paramètre supplémentaire qui va permettre
d&amp;rsquo;effectuer un rapport entre les deux dernières valeurs et en afficher le
résultat:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-python" data-lang="python">&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">fibo&lt;/span>(n, f&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#66d9ef">lambda&lt;/span> p, r: p &lt;span style="color:#f92672">/&lt;/span> r):
&lt;span style="color:#66d9ef">print&lt;/span>(f&lt;span style="color:#e6db74">&amp;#34;i: 0, f: 1, r: {f(0, 1)}&amp;#34;&lt;/span>)
prev &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
actual &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> i &lt;span style="color:#f92672">in&lt;/span> range(n):
&lt;span style="color:#66d9ef">print&lt;/span>(f&lt;span style="color:#e6db74">&amp;#34;i: {i}, f: {actual}, r: {f(actual, prev)}&amp;#34;&lt;/span>)
tmp &lt;span style="color:#f92672">=&lt;/span> actual
actual &lt;span style="color:#f92672">+=&lt;/span> prev
prev &lt;span style="color:#f92672">=&lt;/span> tmp
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Si on essaye avec 5 et la fonction qui permet de faire le rapport entre les
deux, on obtient:&lt;/p>
&lt;pre>&lt;code>&amp;gt;&amp;gt;&amp;gt; fibo(5)
i: 0, f: 1, r: 0.0
i: 0, f: 1, r: 1.0
i: 1, f: 2, r: 2.0
i: 2, f: 3, r: 1.5
i: 3, f: 5, r: 1.6666666666666667
i: 4, f: 8, r: 1.6
&lt;/code>&lt;/pre>&lt;p>On peut observer que l&amp;rsquo;on se rapproche de la valeur de $\phi$ qui vaut
$\phi \approx 1.6180339887&amp;hellip;$. On peut d&amp;rsquo;ailleurs l&amp;rsquo;approximer facilement:&lt;/p>
&lt;pre>&lt;code>&amp;gt;&amp;gt;&amp;gt; (1 + 5 ** 0.5) / 2
1.618033988749895
&lt;/code>&lt;/pre>&lt;p>D&amp;rsquo;autre part, si on utilise la fonction que j&amp;rsquo;ai écrite, on peut observer que
le résultat converge vers $\phi$ rapidement mais qu&amp;rsquo;il faut attendre la 39 ième
itération avant de voir la version arrondie de python:&lt;/p>
&lt;pre>&lt;code>&amp;gt;&amp;gt;&amp;gt; fibo(40, f=lambda a,b: a/b)
i: 0, f: 1, r: 0.0
i: 0, f: 1, r: 1.0
i: 1, f: 2, r: 2.0
i: 2, f: 3, r: 1.5
i: 3, f: 5, r: 1.6666666666666667
i: 4, f: 8, r: 1.6
i: 5, f: 13, r: 1.625
i: 6, f: 21, r: 1.6153846153846154
i: 7, f: 34, r: 1.619047619047619
i: 8, f: 55, r: 1.6176470588235294
i: 9, f: 89, r: 1.6181818181818182
i: 10, f: 144, r: 1.6179775280898876
i: 11, f: 233, r: 1.6180555555555556
i: 12, f: 377, r: 1.6180257510729614
i: 13, f: 610, r: 1.6180371352785146
i: 14, f: 987, r: 1.618032786885246
i: 15, f: 1597, r: 1.618034447821682
i: 16, f: 2584, r: 1.6180338134001253
i: 17, f: 4181, r: 1.618034055727554
i: 18, f: 6765, r: 1.6180339631667064
i: 19, f: 10946, r: 1.6180339985218033
i: 20, f: 17711, r: 1.618033985017358
i: 21, f: 28657, r: 1.6180339901755971
i: 22, f: 46368, r: 1.618033988205325
i: 23, f: 75025, r: 1.618033988957902
i: 24, f: 121393, r: 1.6180339886704431
i: 25, f: 196418, r: 1.6180339887802426
i: 26, f: 317811, r: 1.618033988738303
i: 27, f: 514229, r: 1.6180339887543225
i: 28, f: 832040, r: 1.6180339887482036
i: 29, f: 1346269, r: 1.6180339887505408
i: 30, f: 2178309, r: 1.6180339887496482
i: 31, f: 3524578, r: 1.618033988749989
i: 32, f: 5702887, r: 1.618033988749859
i: 33, f: 9227465, r: 1.6180339887499087
i: 34, f: 14930352, r: 1.6180339887498896
i: 35, f: 24157817, r: 1.618033988749897
i: 36, f: 39088169, r: 1.618033988749894
i: 37, f: 63245986, r: 1.6180339887498951
i: 38, f: 102334155, r: 1.6180339887498947
i: 39, f: 165580141, r: 1.618033988749895
i: 40, f: 267914296, r: 1.618033988749895
&lt;/code>&lt;/pre>&lt;p>&lt;img src="https://blog.moulard.org/img/2020/fibonacci/phibonacci.png" alt="Courbe de l&amp;rsquo;évolution des valeurs">&lt;/p></description></item><item><title>Boot in Kali Live</title><link>https://blog.moulard.org/boot-kali-live/</link><pubDate>Thu, 17 Sep 2020 08:09:31 +0200</pubDate><guid>https://blog.moulard.org/boot-kali-live/</guid><comments>https://blog.moulard.org/boot-kali-live/#disqus_thread</comments><description>&lt;p>Ce &amp;ldquo;tutoriel&amp;rdquo; va vous présenter comment installer une clef bootable et comment
l&amp;rsquo;utiliser avec une version live de kali Linux.&lt;/p>
&lt;p>&lt;strong>Attention, par défaut, une version live d&amp;rsquo;un OS ne va pas sauvegarder vos
données, ni configuration&lt;/strong>&lt;/p>
&lt;h2 id="préparation">Préparation&lt;/h2>
&lt;p>Il va falloir télécharger l&amp;rsquo;image &lt;code>.iso&lt;/code> que vous allez vouloir installer sur
la clef USB.&lt;/p>
&lt;h3 id="télécharger-limage">Télécharger l&amp;rsquo;image&lt;/h3>
&lt;p>Pour télécharger l&amp;rsquo;image, il faut aller sur le site de
&lt;a href="https://www.kali.org/">Kali&lt;/a>, dans la section
&lt;a href="https://www.kali.org/downloads/">download&lt;/a>.&lt;/p>
&lt;p>Puis choisir l&amp;rsquo;image qui correspond a la version voulue:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://cdimage.kali.org/kali-2020.3/kali-linux-2020.3-installer-amd64.iso">Kali Linux 64-Bit (installer)&lt;/a>,
&lt;a href="https://images.kali.org/kali-linux-2020.3-installer-amd64.iso.torrent">torrent&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://cdimage.kali.org/kali-2020.3/kali-linux-2020.3-live-amd64.iso">Kali Linux 64-Bit (live)&lt;/a>,
&lt;a href="https://images.kali.org/kali-linux-2020.3-live-amd64.iso.torrent">torrent&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://cdimage.kali.org/kali-2020.3/kali-linux-2020.3-installer-netinst-amd64.iso">Kali Linux 64-Bit (net installer)&lt;/a>,
&lt;a href="https://images.kali.org/kali-linux-2020.3-installer-netinst-amd64.iso.torrent">torrent&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://cdimage.kali.org/kali-2020.3/kali-linux-2020.3-installer-i386.iso">Kali Linux 32-Bit (installer)&lt;/a>,
&lt;a href="https://images.kali.org/kali-linux-2020.3-installer-i386.iso.torrent">torrent&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://cdimage.kali.org/kali-2020.3/kali-linux-2020.3-live-i386.iso">Kali Linux 32-Bit (live)&lt;/a>,
&lt;a href="https://images.kali.org/kali-linux-2020.3-live-i386.iso.torrent">torrent&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://cdimage.kali.org/kali-2020.3/kali-linux-2020.3-installer-netinst-i386.iso">Kali Linux 32-Bit (net installer)&lt;/a>,
&lt;a href="https://images.kali.org/kali-linux-2020.3-installer-netinst-i386.iso.torrent">torrent&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>La version &lt;code>Kali Linux 64-Bit (live)&lt;/code> est préférée.&lt;/p>
&lt;h3 id="burn-la-clef-usb">Burn la clef USB&lt;/h3>
&lt;p>Une fois le fichier &lt;code>.iso&lt;/code> disponible sur votre PC, il faut l&amp;rsquo;installer (ou
le burn) sur la clef USB.&lt;/p>
&lt;p>&lt;strong>Brancher la Clef USB au PC&lt;/strong>&lt;/p>
&lt;h4 id="logiciel-sur-windows">Logiciel sur Windows&lt;/h4>
&lt;p>Utiliser l&amp;rsquo;outil &lt;a href="https://rufus.ie/">rufus&lt;/a>:&lt;/p>
&lt;p>&lt;img src="https://blog.moulard.org/img/2020/kali/rufus_fr.png" alt="Interface rufus">&lt;/p>
&lt;ul>
&lt;li>Télécharger le logiciel, &lt;a href="https://github.com/pbatard/rufus/releases/download/v3.11/rufus-3.11.exe">lien&lt;/a>&lt;/li>
&lt;li>Choisir de périphérique&lt;/li>
&lt;li>Sélectionner le fichier image (dans &lt;code>Type de démarrage&lt;/code>)&lt;/li>
&lt;li>Choisir un schema de partition &lt;code>MBR&lt;/code>&lt;/li>
&lt;li>Utiliser le mode &lt;code>BIOS ou UEFI&lt;/code> pour le &lt;code>Système de destination&lt;/code>&lt;/li>
&lt;li>&lt;code>DEMARRER&lt;/code>&lt;/li>
&lt;/ul>
&lt;h4 id="programme-sur-linux">Programme sur Linux&lt;/h4>
&lt;p>Il faut connaitre le nom du device qui est mount sur votre PC:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ lsblk &lt;span style="color:#75715e"># avant avoir branché la clef&lt;/span>
sda 8:0 &lt;span style="color:#ae81ff">0&lt;/span> 447,1G &lt;span style="color:#ae81ff">0&lt;/span> disk
└─sda1 8:0 &lt;span style="color:#ae81ff">0&lt;/span> 447,1G &lt;span style="color:#ae81ff">0&lt;/span> part /
$ lsblk &lt;span style="color:#75715e"># après avoir branché la clef&lt;/span>
sda 8:0 &lt;span style="color:#ae81ff">0&lt;/span> 447,1G &lt;span style="color:#ae81ff">0&lt;/span> disk
└─sda1 8:0 &lt;span style="color:#ae81ff">0&lt;/span> 447,1G &lt;span style="color:#ae81ff">0&lt;/span> part /
sdb 8:16 &lt;span style="color:#ae81ff">0&lt;/span> 14,6G &lt;span style="color:#ae81ff">0&lt;/span> disk
├─sdb1 8:17 &lt;span style="color:#ae81ff">0&lt;/span> 1K &lt;span style="color:#ae81ff">0&lt;/span> part
└─sdb5 8:21 &lt;span style="color:#ae81ff">0&lt;/span> 14,6K &lt;span style="color:#ae81ff">0&lt;/span> part /media/root/best-usb
&lt;/code>&lt;/pre>&lt;/div>&lt;p>On remarque que &lt;code>sdb&lt;/code> viens d&amp;rsquo;apparaitre.&lt;/p>
&lt;p>On va maintenant Burn l&amp;rsquo;image:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ sudo dd status&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;progress&amp;#34;&lt;/span> conv&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;fdatasync&amp;#34;&lt;/span> bs&lt;span style="color:#f92672">=&lt;/span>4M &lt;span style="color:#66d9ef">if&lt;/span>&lt;span style="color:#f92672">=&lt;/span>/root/Downloads/kali-linux-2020.3-live-amd64.iso of&lt;span style="color:#f92672">=&lt;/span>/dev/sdb
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Décomposons:&lt;/p>
&lt;ul>
&lt;li>&lt;code>sudo&lt;/code>: il faut être root pour pouvoir utiliser le tool&lt;/li>
&lt;li>&lt;code>dd&lt;/code>: (AKA &lt;code>Disk Destroyer&lt;/code>) outils pour convertir et copier des fichiers
(cf &lt;code>man dd&lt;/code>)&lt;/li>
&lt;li>&lt;code>status=&amp;quot;progress&amp;quot;&lt;/code>: Permet de savoir ce qu&amp;rsquo;est en train de faire &lt;code>dd&lt;/code>.&lt;/li>
&lt;li>&lt;code>conv=&amp;quot;fdatasync&amp;quot;&lt;/code>: Permet à &lt;code>dd&lt;/code> de bien flush les buffers d&amp;rsquo;écriture a la
fin de l&amp;rsquo;écriture.&lt;/li>
&lt;li>&lt;code>bs=4M&lt;/code>: Décrit la taille des &amp;ldquo;blocks&amp;rdquo; à écrire sur le support.&lt;/li>
&lt;li>&lt;code>if=&amp;lt;ISO FILE&amp;gt;&lt;/code>: Permet de choisir le fichier à écrire sur la clef USB.&lt;/li>
&lt;li>&lt;code>of=&amp;lt;device&amp;gt;&lt;/code>: Choisis le device où on va écrire le fichier
&lt;strong>Attention: ne pas se tromper de device&lt;/strong>&lt;/li>
&lt;/ul>
&lt;h2 id="booter">Booter&lt;/h2>
&lt;p>Re démarrer le PC.&lt;/p>
&lt;h3 id="entrer-dans-le-bios">Entrer dans le BIOS&lt;/h3>
&lt;p>Lorsque le PC est en train de démarrer, il affiche sur l&amp;rsquo;écran le logo du
constructeur et une touche sur laquelle appuyer pour entre dans le BIOS.&lt;/p>
&lt;p>Ses touches peuvent être:&lt;/p>
&lt;ul>
&lt;li>&lt;code>Suppr&lt;/code>&lt;/li>
&lt;li>&lt;code>Del&lt;/code>&lt;/li>
&lt;li>&lt;code>F1&lt;/code> (ou les autre touches fonction)&lt;/li>
&lt;li>&lt;code>Ctrl + Alt + Echap&lt;/code>&lt;/li>
&lt;li>&lt;code>Ctrl + Alt + S&lt;/code>&lt;/li>
&lt;li>&lt;code>Ctrl + Alt + Ins&lt;/code>&lt;/li>
&lt;li>&amp;hellip;&lt;/li>
&lt;/ul>
&lt;h3 id="choisir-le-disque-usb">Choisir le &amp;ldquo;disque&amp;rdquo; USB&lt;/h3>
&lt;p>On va donc aller chercher dans le BIOS l&amp;rsquo;option qui permet de choisir
l&amp;rsquo;ordre des disques de boot.
C&amp;rsquo;est-à-dire l&amp;rsquo;ordre des devices dans lequel de BIOS va regarder pour
démarrer un OS.&lt;/p>
&lt;p>Dans ce menu, il va falloir mettre le device correspondant a la clef USB en
premier.&lt;/p>
&lt;p>&lt;strong>Attention: Si vous laissez cette option d&amp;rsquo;activée, n&amp;rsquo;importe qui qui
possède une clef bootable va pouvoir utiliser votre ordinateur et pouvoir
utiliser vos disques&lt;/strong>&lt;/p>
&lt;p>Une fois cette options modifiée, il faut sauvegarder les settings et quitter
le BIOS.&lt;/p>
&lt;h3 id="choisir-loption-de-boot-en-live">Choisir l&amp;rsquo;option de boot en live&lt;/h3>
&lt;p>L&amp;rsquo;écran va ensuite afficher le GRUB GNU de Kali.&lt;/p>
&lt;p>&lt;img src="https://blog.moulard.org/img/2020/kali/grub-kali.jpeg" alt="GRUB GNU de Kali Linux">&lt;/p>
&lt;p>Et Voilà, vous avez boot sur une version Live de Kali.&lt;/p>
&lt;p>La première chose a faire est de faire un:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ sudo apt-get update &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> apt-get upgrade -y
&lt;/code>&lt;/pre>&lt;/div>&lt;p>La prochaine fois, si la clef USB est branchée, le PC va démarrer Kali, sinon
il va démarrer sur votre OS de base(celui qui est déjà installé sur votre
machine)&lt;/p></description></item><item><title>ANSSI et automatisation de MOOC Secnumacademie avec Selenium</title><link>https://blog.moulard.org/anssi-mooc-on-hacking/</link><pubDate>Mon, 13 Apr 2020 18:57:41 +0200</pubDate><guid>https://blog.moulard.org/anssi-mooc-on-hacking/</guid><comments>https://blog.moulard.org/anssi-mooc-on-hacking/#disqus_thread</comments><description>&lt;p>Pour mon école, j&amp;rsquo;ai eu a faire un &lt;a href="https://secnumacademie.gouv.fr/">MOOC&lt;/a> de l&amp;rsquo;ANSSI.&lt;/p>
&lt;p>Or après avoir fait tous les tests du mooc à 100% sans avoir écouté les cours, j&amp;rsquo;ai décidé de récupérer l&amp;rsquo;attestation de réussite du MOOC pour le donner à mon école.
Mais j&amp;rsquo;ai eu un message d&amp;rsquo;erreur:&lt;/p>
&lt;p>&lt;img src="https://blog.moulard.org/img/2020/mooc/error.png" alt="Erreur de récupération de l&amp;rsquo;attestation">&lt;/p>
&lt;p>J&amp;rsquo;ai donc voulu suivre les cours, mais ils prenaient beaucoup trop de temps à suivre. Voici donc un bot pour suivre les cours de manière semi-automatique:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-python" data-lang="python">&lt;span style="color:#f92672">from&lt;/span> selenium &lt;span style="color:#f92672">import&lt;/span> webdriver
&lt;span style="color:#f92672">import&lt;/span> time
user &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;REDACTED&amp;#34;&lt;/span>
passw &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;REDACTED&amp;#34;&lt;/span>
&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">main&lt;/span>():
driver &lt;span style="color:#f92672">=&lt;/span> webdriver&lt;span style="color:#f92672">.&lt;/span>Chrome()
driver&lt;span style="color:#f92672">.&lt;/span>get(&lt;span style="color:#e6db74">&amp;#34;https://secnumacademie.gouv.fr/&amp;#34;&lt;/span>)
driver&lt;span style="color:#f92672">.&lt;/span>find_elements_by_id(&lt;span style="color:#e6db74">&amp;#34;btn_access_insc&amp;#34;&lt;/span>)[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">.&lt;/span>click()
driver&lt;span style="color:#f92672">.&lt;/span>find_elements_by_id(&lt;span style="color:#e6db74">&amp;#34;login&amp;#34;&lt;/span>)[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">.&lt;/span>send_keys(user)
driver&lt;span style="color:#f92672">.&lt;/span>find_elements_by_id(&lt;span style="color:#e6db74">&amp;#34;password&amp;#34;&lt;/span>)[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">.&lt;/span>send_keys(passw)
xpath &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#39;/html/body/div[2]/div/div[2]/div/div[1]/div[1]/div[2]/a[1]&amp;#39;&lt;/span>
driver&lt;span style="color:#f92672">.&lt;/span>find_elements_by_xpath(xpath)[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">.&lt;/span>click()
&lt;span style="color:#66d9ef">while&lt;/span> True:
&lt;span style="color:#66d9ef">if&lt;/span> input(&lt;span style="color:#e6db74">&amp;#34;continue ? [Y/n]&amp;#34;&lt;/span>) &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#e6db74">&amp;#34;n&amp;#34;&lt;/span>:
exit(&lt;span style="color:#ae81ff">0&lt;/span>)
driver&lt;span style="color:#f92672">.&lt;/span>switch_to&lt;span style="color:#f92672">.&lt;/span>default_content()
driver&lt;span style="color:#f92672">.&lt;/span>switch_to&lt;span style="color:#f92672">.&lt;/span>frame(&lt;span style="color:#e6db74">&amp;#34;DEFAUT&amp;#34;&lt;/span>)
driver&lt;span style="color:#f92672">.&lt;/span>switch_to&lt;span style="color:#f92672">.&lt;/span>frame(&lt;span style="color:#e6db74">&amp;#34;contents&amp;#34;&lt;/span>)
iframe_id &lt;span style="color:#f92672">=&lt;/span> driver&lt;span style="color:#f92672">.&lt;/span>find_elements_by_id(&lt;span style="color:#e6db74">&amp;#34;content&amp;#34;&lt;/span>)[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">.&lt;/span>find_elements_by_tag_name(&lt;span style="color:#e6db74">&amp;#34;iframe&amp;#34;&lt;/span>)[&lt;span style="color:#ae81ff">0&lt;/span>]&lt;span style="color:#f92672">.&lt;/span>get_attribute(&lt;span style="color:#e6db74">&amp;#34;id&amp;#34;&lt;/span>)
driver&lt;span style="color:#f92672">.&lt;/span>switch_to&lt;span style="color:#f92672">.&lt;/span>frame(iframe_id)
driver&lt;span style="color:#f92672">.&lt;/span>execute_script(&lt;span style="color:#e6db74">&amp;#34;for(var i = 0; i &amp;lt; 15; i++) {document.querySelector(&amp;#39;#Stage_menu_inferieur_bouton_suivant_hit&amp;#39;).click()}&amp;#34;&lt;/span>)
&lt;span style="color:#66d9ef">if&lt;/span> __name__ &lt;span style="color:#f92672">==&lt;/span> &lt;span style="color:#e6db74">&amp;#39;__main__&amp;#39;&lt;/span>:
main()
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Un bot que vous pourrez trouver sur mon &lt;a href="https://github.com/tomMoulard/python-projetcs">repository github&lt;/a>.&lt;/p>
&lt;p>Il suffit de:&lt;/p>
&lt;ul>
&lt;li>mettre son username et son password dans les variables &lt;code>user&lt;/code> et &lt;code>passwd&lt;/code>.&lt;/li>
&lt;li>lancer le bot&lt;/li>
&lt;li>attendre que le bot ait connecté le navigateur&lt;/li>
&lt;li>sélectionner le module, l&amp;rsquo;unité ainsi que le premier cours&lt;/li>
&lt;li>entrer &lt;code>Y&lt;/code> quand le bot demande si on veut continuer (étape à répéter tant qu&amp;rsquo;il y a un sous module à suivre)&lt;/li>
&lt;/ul>
&lt;h1 id="en-images">En images&lt;/h1>
&lt;h2 id="récupérer-le-code">Récupérer le code&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">mkdir mook-hack &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> cd mook-hack
wget https://raw.githubusercontent.com/tomMoulard/python-projetcs/master/anssi-mooc/mooc.py
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="installer-les-dépendances">Installer les dépendances&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">sudo apt install -y python3-selenium chromium-chromedriver
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="mettre-son-usernamepassword">Mettre son username/password&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$EDITOR +4 mooc.py
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="lancer-le-bot">Lancer le bot&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">python3 mooc.py
&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;img src="https://blog.moulard.org/img/2020/mooc/waiting.png" alt="le bot qui attends">&lt;/p>
&lt;h2 id="sélectionner-le-module">Sélectionner le module&lt;/h2>
&lt;p>&lt;img src="https://blog.moulard.org/img/2020/mooc/module.png" alt="Sélectionner le module">&lt;/p>
&lt;h2 id="sélectionner-lunité">Sélectionner l&amp;rsquo;unité&lt;/h2>
&lt;p>&lt;img src="https://blog.moulard.org/img/2020/mooc/unity.png" alt="Sélectionner l&amp;rsquo;unité">&lt;/p>
&lt;h2 id="sélectionner-le-premier-cours">Sélectionner le premier cours&lt;/h2>
&lt;ul>
&lt;li>angry clicking noise *
&lt;img src="https://blog.moulard.org/img/2020/mooc/first-course.png" alt="Sélectionner le premier cours">&lt;/li>
&lt;/ul>
&lt;h2 id="entrer-y">Entrer &lt;code>Y&lt;/code>&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">y
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="upgrades">Upgrades&lt;/h1>
&lt;p>Dans le futur, on pourrait:&lt;/p>
&lt;ul>
&lt;li>lire les vidéos&lt;/li>
&lt;li>ne pas faire &lt;code>Y&lt;/code> pour chaque cours&lt;/li>
&lt;/ul>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;p>bla bla bla il faut suivre ses cours&lt;/p>
&lt;p>Selenium c&amp;rsquo;est cool pour automatiser l&amp;rsquo;utilisation d&amp;rsquo;un site web&lt;/p>
&lt;ul>
&lt;li>Se blog a été écrit en réalisant un mooc ANSSI *&lt;/li>
&lt;/ul></description></item><item><title>Corona et CLI</title><link>https://blog.moulard.org/coronoa-and-cli/</link><pubDate>Fri, 27 Mar 2020 12:22:48 +0100</pubDate><guid>https://blog.moulard.org/coronoa-and-cli/</guid><comments>https://blog.moulard.org/coronoa-and-cli/#disqus_thread</comments><description>&lt;h1 id="comment-utiliser-des-outils-modernes-pour-avoir-des-informations-utiles-sur-létat-actuel-des-choses">Comment utiliser des outils &amp;ldquo;modernes&amp;rdquo; pour avoir des informations utiles sur l&amp;rsquo;état actuel des choses&lt;/h1>
&lt;p>On a des sites qui offrent les données liées au virus accessible grâce à &lt;code>cURL&lt;/code>:&lt;/p>
&lt;h2 id="récupérer-les-informations">Récupérer les informations&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ curl https://corona-stats.online/fr
╔══════╤═════════════╤══════════════╤═════════════╤══════════════╤══════════════╤═══════════╤═════════╤══════════╤════════════════╗
║ Rank │ Country │ Total Cases │ New Cases ▲ │ Total Deaths │ New Deaths ▲ │ Recovered │ Active │ Critical │ Cases / 1M pop ║
╟──────┼─────────────┼──────────────┼─────────────┼──────────────┼──────────────┼───────────┼─────────┼──────────┼────────────────╢
║ &lt;span style="color:#ae81ff">1&lt;/span> │ France &lt;span style="color:#f92672">(&lt;/span>FR&lt;span style="color:#f92672">)&lt;/span> │ 29,155 │ │ 1,696 │ │ 4,948 │ 22,511 │ 3,375 │ &lt;span style="color:#ae81ff">447&lt;/span> ║
╟──────┼─────────────┼──────────────┼─────────────┼──────────────┼──────────────┼───────────┼─────────┼──────────┼────────────────╢
║ │ World │ 548,806 │ 16,996 ▲ │ 24,862 │ &lt;span style="color:#ae81ff">794&lt;/span> ▲ │ 128,599 │ 395,345 │ 20,968 │ 70.41 ║
╚══════╧═════════════╧══════════════╧═════════════╧══════════════╧══════════════╧═══════════╧═════════╧══════════╧════════════════╝
Stay safe. Stay inside.
Code: https://github.com/sagarkarira/coronavirus-tracker-cli
Twitter: https://twitter.com/ekrysis
Last Updated on: 27-Mar-2020 11:03 UTC
UPDATE: Source &lt;span style="color:#ae81ff">2&lt;/span> is now default source
JHU Source &lt;span style="color:#ae81ff">1&lt;/span> table: https://corona-stats.online?source&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>
HELP: https://corona-stats.online/help
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="extraire-les-informations">Extraire les informations&lt;/h2>
&lt;p>Extraire des données de ce curl est donc faisable:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ curl https://corona-stats.online/fr | grep an
║ Rank │ Country │ Total Cases │ New Cases ▲ │ Total Deaths │ New Deaths ▲ │ Recovered │ Active │ Critical │ Cases / 1M pop ║
║ &lt;span style="color:#ae81ff">1&lt;/span> │ France &lt;span style="color:#f92672">(&lt;/span>FR&lt;span style="color:#f92672">)&lt;/span> │ 29,155 │ │ 1,696 │ │ 4,948 │ 22,511 │ 3,375 │ &lt;span style="color:#ae81ff">447&lt;/span> ║
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="nettoyer-les-informations">Nettoyer les informations&lt;/h2>
&lt;p>Il suffit ensuite de nettoyer avec un coup de &lt;code>sed&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ curl https://corona-stats.online/fr |&lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> grep an |&lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> sed &lt;span style="color:#e6db74">&amp;#34;s/\s*//g ; s/║//g ; s/│/;/g&amp;#34;&lt;/span>
Rank;Country;TotalCases;NewCases▲;TotalDeaths;NewDeaths▲;Recovered;Active;Critical;Cases/1Mpop
1;France&lt;span style="color:#f92672">(&lt;/span>FR&lt;span style="color:#f92672">)&lt;/span>;29,155;;1,696;;4,948;22,511;3,375;&lt;span style="color:#ae81ff">447&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Les trois arguments de sed permettent:&lt;/p>
&lt;ul>
&lt;li>&lt;code>s/\s*//g&lt;/code>: supprimer les espaces superflu&lt;/li>
&lt;li>&lt;code>s/║//g &lt;/code>: enlever le caractère de fin&lt;/li>
&lt;li>&lt;code>s/│/;/g&amp;quot;&lt;/code>: Remplacer les séparateurs par quelque chose d&amp;rsquo;utilisable&lt;/li>
&lt;/ul>
&lt;h2 id="formater-les-informations">Formater les informations&lt;/h2>
&lt;p>On peux mieux voir les informations grâce à &lt;code>AWK&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ curl https://corona-stats.online/fr |&lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> grep France |&lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> sed &lt;span style="color:#e6db74">&amp;#34;s/\s*//g ; s/║//g ; s/│/;/g&amp;#34;&lt;/span> |&lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> awk -F&lt;span style="color:#e6db74">&amp;#39;;&amp;#39;&lt;/span> &lt;span style="color:#e6db74">&amp;#39;{print $2&amp;#34;:&amp;#34;$3&amp;#34;(&amp;#34;$7&amp;#34;,&amp;#34;$8&amp;#34;)&amp;#34;}&amp;#39;&lt;/span>
Country:TotalCases&lt;span style="color:#f92672">(&lt;/span>Recovered,Active&lt;span style="color:#f92672">)&lt;/span>
France&lt;span style="color:#f92672">(&lt;/span>FR&lt;span style="color:#f92672">)&lt;/span>:29,155&lt;span style="color:#f92672">(&lt;/span>4,948,22,511&lt;span style="color:#f92672">)&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote>
&lt;p>Attention: ne pas oublier d&amp;rsquo;enlever la ligne avec les informations de champ avec une utilisation un peut plus poussée.&lt;/p>
&lt;/blockquote>
&lt;h1 id="conclusion">Conclusion&lt;/h1>
&lt;p>Il ne nous reste plus qu&amp;rsquo;à utiliser ces informations, dans une barre d&amp;rsquo;état par exemple.&lt;/p>
&lt;p>Pour aller plus loin, on pourrais ne pas utiliser &lt;code>cURL&lt;/code> à chaque appel, mais utiliser un cache car les informations ne sont pas mises a jours toutes les heures:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">curl https://corona-stats.online/fr &amp;gt; $HOME/.cache/corona_data
grep France $HOME/.cache/corona_data |&lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> sed &lt;span style="color:#e6db74">&amp;#34;s/\s*//g ; s/║//g ; s/│/;/g&amp;#34;&lt;/span> |&lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> awk -F&lt;span style="color:#e6db74">&amp;#39;;&amp;#39;&lt;/span> &lt;span style="color:#e6db74">&amp;#39;{print $2&amp;#34;:&amp;#34;$3&amp;#34;(&amp;#34;$7&amp;#34;,&amp;#34;$8&amp;#34;)&amp;#34;}&amp;#39;&lt;/span>
&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>sysadmin function bakup</title><link>https://blog.moulard.org/sysadminfunctionbackup/</link><pubDate>Thu, 12 Mar 2020 10:19:36 +0100</pubDate><guid>https://blog.moulard.org/sysadminfunctionbackup/</guid><comments>https://blog.moulard.org/sysadminfunctionbackup/#disqus_thread</comments><description>&lt;h1 id="sysadmin-function-bakup">sysadmin function bakup&lt;/h1>
&lt;p>Dans les règles d&amp;rsquo;or de tout sysadmin il y a bien sûr la nécessité de mettre en œuvre une politique de backup complet des systèmes.
Ce n&amp;rsquo;est pas le sujet de cet article !!!
Il existe une bonne pratique pour garantir la traçabilité et la capacité de revenir sur une mauvaise manip.&lt;/p>
&lt;p>&lt;strong>Avant de modifier une fichier, il faut en faire une copie !!!&lt;/strong>&lt;/p>
&lt;p>Alors c&amp;rsquo;est simple à première vue:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">cp /etc/fstab /etc/fstab.bkp
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Bon ça c&amp;rsquo;est la base :)
Franchement ça aide dans bien des cas. On peut aller un peu plus loin et ajouter un horodatage.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">cp /etc/fstab /etc/fstab-bkp200312002553
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Pour ma part je me suis souvent demandé pourquoi personne n&amp;rsquo;avait écrit en &lt;code>cp&lt;/code> avec cette fonction&amp;hellip;
Bien probablement car il y a les function en shell :)&lt;/p>
&lt;p>Il faut juste la créer dans son environnement et le mettre dans son fichier &lt;code>$HOME/.bashrc&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">bkp &lt;span style="color:#f92672">(){&lt;/span> cp -a $1 $1-bkp&lt;span style="color:#66d9ef">$(&lt;/span>date +&lt;span style="color:#e6db74">&amp;#34;%y%m%d%H%M%S&amp;#34;&lt;/span>&lt;span style="color:#66d9ef">)&lt;/span> ; &lt;span style="color:#f92672">}&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>On peut alors ensuite l&amp;rsquo;utiliser comme une commande classique&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">root@pi3:~&amp;gt; bkp &lt;span style="color:#f92672">(){&lt;/span> cp -a $1 $1-bkp&lt;span style="color:#66d9ef">$(&lt;/span>date +&lt;span style="color:#e6db74">&amp;#34;%y%m%d%H%M%S&amp;#34;&lt;/span>&lt;span style="color:#66d9ef">)&lt;/span> ; &lt;span style="color:#f92672">}&lt;/span>
root@pi3:~&amp;gt; bkp /etc/fstab
root@pi3:~&amp;gt; ls -l /etc/fstab*
-rw-r--r-- &lt;span style="color:#ae81ff">1&lt;/span> root root &lt;span style="color:#ae81ff">305&lt;/span> nov. &lt;span style="color:#ae81ff">29&lt;/span> 18:40 /etc/fstab
-rw-r--r-- &lt;span style="color:#ae81ff">1&lt;/span> root root &lt;span style="color:#ae81ff">305&lt;/span> nov. &lt;span style="color:#ae81ff">29&lt;/span> 18:40 /etc/fstab-bkp200312003354
&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote>
&lt;p>Cool non!!!&lt;/p>
&lt;/blockquote>
&lt;p>Bien sûr l&amp;rsquo;utilisation des fonctions en bash n&amp;rsquo;a pas de limite, voilà une autre que j&amp;rsquo;utilise souvent pour répéter X fois la même commande&amp;hellip;&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">t10 &lt;span style="color:#f92672">(){&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> x in &lt;span style="color:#f92672">{&lt;/span>01..10&lt;span style="color:#f92672">}&lt;/span>; &lt;span style="color:#66d9ef">do&lt;/span> $@ ; &lt;span style="color:#66d9ef">done&lt;/span> &lt;span style="color:#f92672">}&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Et à l&amp;rsquo;utilisation&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">pi@pi3:~ $ t10 &lt;span style="color:#f92672">(){&lt;/span> &lt;span style="color:#66d9ef">for&lt;/span> x in &lt;span style="color:#f92672">{&lt;/span>01..10&lt;span style="color:#f92672">}&lt;/span>; &lt;span style="color:#66d9ef">do&lt;/span> $@ ; &lt;span style="color:#66d9ef">done&lt;/span> &lt;span style="color:#f92672">}&lt;/span>
pi@pi3:~ $ t10 echo g &amp;gt;&amp;gt; /tmp/10g
pi@pi3:~ $ cat /tmp/10g
g
g
g
g
g
g
g
g
g
g
&lt;/code>&lt;/pre>&lt;/div>&lt;p>On peut faire des choses beaucoup plus sophistiquées&amp;hellip; Voila une fonction qui décompresse les principaux fichiers d&amp;rsquo;archive.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#75715e"># Extract the content of an achive&lt;/span>
&lt;span style="color:#66d9ef">function&lt;/span> extract &lt;span style="color:#f92672">{&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#f92672">[&lt;/span> -z &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$1&lt;span style="color:#e6db74">&amp;#34;&lt;/span> &lt;span style="color:#f92672">]&lt;/span>; &lt;span style="color:#66d9ef">then&lt;/span>
&lt;span style="color:#75715e"># display usage if no parameters given&lt;/span>
echo &lt;span style="color:#e6db74">&amp;#34;Usage: extract &amp;lt;path/file_name&amp;gt;.&amp;lt;zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz&amp;gt;&amp;#34;&lt;/span>
echo &lt;span style="color:#e6db74">&amp;#34; extract &amp;lt;path/file_name_1.ext&amp;gt; [path/file_name_2.ext] [path/file_name_3.ext]&amp;#34;&lt;/span>
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;span style="color:#66d9ef">else&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> n in $@
&lt;span style="color:#66d9ef">do&lt;/span>
&lt;span style="color:#66d9ef">if&lt;/span> &lt;span style="color:#f92672">[&lt;/span> -f &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> &lt;span style="color:#f92672">]&lt;/span> ; &lt;span style="color:#66d9ef">then&lt;/span>
&lt;span style="color:#66d9ef">case&lt;/span> &lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>n%,&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span> in
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar&lt;span style="color:#f92672">)&lt;/span>
tar xvf &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.lzma&lt;span style="color:#f92672">)&lt;/span> unlzma ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.bz2&lt;span style="color:#f92672">)&lt;/span> bunzip2 ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.rar&lt;span style="color:#f92672">)&lt;/span> unrar x -ad ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.gz&lt;span style="color:#f92672">)&lt;/span> gunzip ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.zip&lt;span style="color:#f92672">)&lt;/span> unzip ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.z&lt;span style="color:#f92672">)&lt;/span> uncompress ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar&lt;span style="color:#f92672">)&lt;/span>
7z x ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.xz&lt;span style="color:#f92672">)&lt;/span> unxz ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*.exe&lt;span style="color:#f92672">)&lt;/span> cabextract ./&lt;span style="color:#e6db74">&amp;#34;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#34;&lt;/span> ;;
*&lt;span style="color:#f92672">)&lt;/span>
echo &lt;span style="color:#e6db74">&amp;#34;extract: &amp;#39;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#39; - unknown archive method&amp;#34;&lt;/span>
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
;;
&lt;span style="color:#66d9ef">esac&lt;/span>
&lt;span style="color:#66d9ef">else&lt;/span>
echo &lt;span style="color:#e6db74">&amp;#34;&amp;#39;&lt;/span>$n&lt;span style="color:#e6db74">&amp;#39; - file does not exist&amp;#34;&lt;/span>
&lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>
&lt;span style="color:#66d9ef">fi&lt;/span>
&lt;span style="color:#66d9ef">done&lt;/span>
&lt;span style="color:#66d9ef">fi&lt;/span>
&lt;span style="color:#f92672">}&lt;/span>
&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Sécurisation SSH : Utilisation de certificat à la place des Clés.</title><link>https://blog.moulard.org/ssh-certificat/</link><pubDate>Mon, 09 Mar 2020 13:19:36 +0100</pubDate><guid>https://blog.moulard.org/ssh-certificat/</guid><comments>https://blog.moulard.org/ssh-certificat/#disqus_thread</comments><description>&lt;h1 id="pourquoi-les-certificats-ssl-cest-mieux-quune-clé-ssh-">Pourquoi les certificats SSL c&amp;rsquo;est mieux qu&amp;rsquo;une clé SSH ?&lt;/h1>
&lt;p>Mettre en place des certificats pousse encore la sécurité un peu plus loin car il est alors possible:&lt;/p>
&lt;ul>
&lt;li>de donner des délais de validité&lt;/li>
&lt;li>de faire les liste de révocation&lt;/li>
&lt;li>de faire des restriction d&amp;rsquo;usage du SSH (&lt;code>clear&lt;/code>, &lt;code>force-command=command&lt;/code>, &lt;code>no-agent-forwarding&lt;/code>, &lt;code>no-port-forwarding&lt;/code>, &lt;code>no-pt&lt;/code>, &lt;code>no-user-rc&lt;/code>, &lt;code>no-x11-forwarding&lt;/code>, &lt;code>permit-agent-forwarding&lt;/code>, &lt;code>permit-port-forwarding&lt;/code>, &lt;code>permit-pty&lt;/code>, &lt;code>permit-user-rc&lt;/code>, &lt;code>permit-x11-forwarding&lt;/code>, &lt;code>source-address=address_list&lt;/code>)&lt;/li>
&lt;li>de faire comme &lt;a href="https://engineering.fb.com/production-engineering/scalable-and-secure-access-with-ssh/">facebook&lt;/a> :)&lt;/li>
&lt;/ul>
&lt;h1 id="comment-mettre-en-oeuvre-une-ca-sur-le-serveur-sshd-">Comment mettre en oeuvre une CA sur le serveur SSHD ?&lt;/h1>
&lt;h2 id="1-création-de-la-ca-certificat-autority">1. Création de la CA (Certificat Autority)&lt;/h2>
&lt;pre>&lt;code>root@pi3:~&amp;gt; ssh-keygen -t rsa -b 4096 -f /etc/ssh/ca
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /etc/ssh/ca.
Your public key has been saved in /etc/ssh/ca.pub.
The key fingerprint is:
SHA256:Ax5NHQgoY8kpb3lNA/zElBFvJhQAt1G+EsJfMXyHPdo root@pi3
The keys randomart image is:
+---[RSA 4096]----+
| ..==O@*.=.. |
|..B.o=B*+ = |
| +o+o=*o=+ . |
| +o.+oB. E |
| . .o o S |
| . . |
| |
| |
| |
+----[SHA256]-----+
root@pi3:~&amp;gt; ls -l /etc/ssh/ca*
-rw------- 1 root root 3243 mars 7 12:33 /etc/ssh/ca
-rw-r--r-- 1 root root 734 mars 7 12:33 /etc/ssh/ca.pub
&lt;/code>&lt;/pre>&lt;h2 id="2-utilisation-des-ca-dans-les-serveur-ssh-sshd">2. Utilisation des CA dans les serveur SSH (&lt;code>sshd&lt;/code>)&lt;/h2>
&lt;pre>&lt;code>echo &amp;quot;TrustedUserCAKeys /etc/ssh/ca.pub&amp;quot; &amp;gt;&amp;gt; /etc/ssh/sshd_config
root@pi3:~&amp;gt; systemctl restart sshd
&lt;/code>&lt;/pre>&lt;h1 id="comment-créer-sa-clé-et-la-signer-avec-la-ca-">Comment créer sa clé et la signer avec la CA ?&lt;/h1>
&lt;p>Comme précédemment, pour créer sa clé, rien de plus simple:
Avec openssh c&amp;rsquo;est très simple&lt;/p>
&lt;pre>&lt;code>pi@pi3:~/.ssh $ ssh-keygen -t rsa -b 4096 -f /home/pi/.ssh/cle2
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/pi/.ssh/cle2.
Your public key has been saved in /home/pi/.ssh/cle2.pub.
The key fingerprint is:
SHA256:AAcbm67DjpfcQOS9Ii8JS3H1ZPs9MsCmKA/jXACEeF0 pi@pi3
The keys randomart image is:
+---[RSA 4096]----+
|+. .+oE |
|+ o .O o |
|.+ .= * . |
| ooo. B |
| .+ o.o S . |
|o*o+.. + o |
|=*X= o . |
|+==o. |
|.o. |
+----[SHA256]-----+
&lt;/code>&lt;/pre>&lt;p>et la signature par le CA :&lt;/p>
&lt;pre>&lt;code>pi@pi3:~/.ssh $ sudo ssh-keygen -s /etc/ssh/ca -n &amp;quot;Signature de la clé&amp;quot; -I 1 -V +365d /home/pi/.ssh/cle2.pub
Signed user key /home/pi/.ssh/cle2-cert.pub: id &amp;quot;1&amp;quot; serial 0 for Signature de la clé valid from 2020-03-07T12:49:00 to 2021-03-07T12:50:00
pi@pi3:~/.ssh $ sudo chown pi:pi /home/pi/.ssh/cle2-cert.pub
&lt;/code>&lt;/pre>&lt;p>On a maintenant un ficher &lt;code>/home/pi/.ssh/cle2-cert.pub&lt;/code> qui est comme une clé publique classique mais avec une durée de validité de 365 jours.&lt;/p>
&lt;pre>&lt;code>pi@pi3:~/.ssh $ cat /home/pi/.ssh/cle2-cert.pub
ssh-rsa-cert-v01@openssh.com AAAAHHNzaC1yc2EtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgQzzzhWBcQU08QMMiOO+XKu832ciknAw2CERpoDEhfdUAAAADAQABAAACAQDFREAoEwQG53su6IlJXuXvX10nPcwzgX/aHFY04DdZezlvXlKlU4iab0I7e6lB1JJ8wFu1WlEoXVWqPmncMkBgfYWCWb3fggqV8AQU/gfIuBuVAJycahCd5FclwRqrEP3vD5TvY/O2VqYfNybdMJXM3hAuiLbQsTRzapu6OtLeWITqSn9criMiBBnsUyY8BUZq0dP1o3fQYBMKkzII9+HiuKNBOgWZ2iWlvKboNE8RNgXKx6E4UXyokjV5Zts4Drtp5sy1xc0CK3zWu/iCaGtbvhUSPMDlVLnh+kPQAT/Yv5++8Oy+ac7bkg4gJ6uWtzwIEaaN08a/WRyOoZW7R0Kza6tm3Cr7Wsi5tGiTBAAOtGiWUR5S5Ipg+BDqRixTLduGeza8emm9qo+95MQL4AaBzMRt2mocV20VJ+EByDhzRfI6XK0lGRJRuhGtV5LY0R6GWruNsp2fFzw1xAg4g79ecYlvNMeWLzm3lgGGGDvaMop/N4TLRoERk66gSFevMHXHjZ9s9zxD20mPgsfZoYpEP01rusCpyqNCx99IEGmcp22wBEOcPYV92h8Al/9D+8v/U/yv5ilc5KFC2UtARoJZq0Hkw9h/npTVSeGrLrzFpWDM/uA2C2aF3mgtUI0DPawnMPPgl9pzQX4JEIjvTvcXxDHIdc1CI1oj+0xcBChTeQAAAAAAAAAAAAAAAQAAAAExAAAAFwAAABNTaWduYXR1cmVkZSBsYSBjbGVmAAAAAF5jiiwAAAAAYES96AAAAAAAAACCAAAAFXBlcm1pdC1YMTEtZm9yd2FyZGluZwAAAAAAAAAXcGVybWl0LWFnZW50LWZvcndhcmRpbmcAAAAAAAAAFnBlcm1pdC1wb3J0LWZvcndhcmRpbmcAAAAAAAAACnBlcm1pdC1wdHkAAAAAAAAADnBlcm1pdC11c2VyLXJjAAAAAAAAAAAAAAIXAAAAB3NzaC1yc2EAAAADAQABAAACAQC3QHWkbueW7y0CXF8c8gsxERkrfLdPfttdh9lDwhrQqmmqdb1gOdkCl7sweFD3CmKQA/lGV4j/7npRfkJiMtNHGhj5nBnqUVHYhwqq6/ju0TggcMnkLHNF6ivxvAj+2BtTyOejyR1/qlYDCDfUexwq+k1d+hPrEAFkv1C+PVmmN+ennO/AOcFr2F5oomcNWVrewxk4h3KQYHgLZhIyXzlH1bUGc+OVDzRR2n4Nx4R/rG4NVBtFIVZlUP6Nqewt3xdt66+KcDXtxa1O96GIksbMTqWpMAOgWEXggPwiXkLkezVEun7+E3ps1Gu5c3/xivrawild5x0AKnBPmRI7fY4I7nLR5EP3k0p9plr/Gai/A9q1pEf10T41nfeNOQnAVJSYo3ICx4St3oZ0gdyz0ORDXUpveXRSw+HpdjBCdX8zGKyrCopO/xNGwSPK72QefKexnYi/0BelnDgvfdKxlrixH6BCRsvALBI3RsuQ5xNZUxfHagyjeklEoF5qTiH2hM2kFftLezfqFbNDfK3r3KDD6u8brHSZwRzb2gPp447d1cUEKSDyxKscu4RpiXGoB8p2QKmHWad/gb0wBAc6KUvwBiUB6qRWL8JaRu/+5Rc7fBWsOv2r6dJ3tUgYEu3H+dUzwXFQXGrhjxYvZqg9KxfBjfbJ9Oq+1ZTePweVeDFHEwAAAg8AAAAHc3NoLXJzYQAAAgCGGBRLVLOylwymVqM9i4MJuaXXfGduT1s1P+KmiEJ20PZY2QT1ggbcCsbR3M9o1BjUDRiNzuzMfWlR+Vy2c0wJWPfFhb0E/DtUETFQMLfLGGNYGhdD4136kmKNB0tsB+UsLFCn7ZHBtDwVEzfpGj2/QfL5YnQ2JcgVNyv5NAwM2JfNkGusWcZRzky4UXa2ucDO8tvcaUaqlkKPKDbezQ1AAFMmZX6mu4Q5HUN4aZ0LR8kafSZeZ/XlJmngvoIhLglNpNgVoTpAwun011shsNi9TOmnloskJc0OfuxEWwbU//O+M6Q/vk0mc9K+lh9GzKZDOw+9gH+Ja+HJZj30+7dH2greTZn4TKa7lg6/a8RaYEMsOxY0T9TQ742rXEwwqShoCtHJ1Bpxt105pZZkqzpun0MJvIPuE+/q5LHBDkJgybZ+ZWIYgF+/0rol8k0+zG2Y5/zLZ89R6OCbqffpmvQZEQMVWBehFN9hcfQ1ehNMLGPgVHCG+uL6q2jLnqgqlZC0yRfGmDC4gbH3/OjR7EWQxdWyTqFXDilpnYL90uoXV+P2RHhQe2B0guDK5fzkaW69opXb4JRRjVR726/v6+bWMt4v96/NcIJAAedMLgK835k6NH9D6oKiAgTlfX3+/go8sPItg29acbY0f0QDe1e4He4veKrmlcumkXA3yStBCQ== pi@pi3
&lt;/code>&lt;/pre>&lt;h1 id="comment-pousser-sa-clé-signée-sur-un-serveur-">Comment pousser sa clé signée sur un serveur ?&lt;/h1>
&lt;p>Exactement comme pour une clé publique, il faut la mettre dans le fichier &lt;code>~/.ssh/authorized_keys&lt;/code>.&lt;/p>
&lt;pre>&lt;code>pi@pi3:~/.ssh $ ssh-copy-id -f -i /home/pi/.ssh/cle2-cert.pub pi@pi4b.home
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: &amp;quot;/home/pi/.ssh/cle2-cert.pub&amp;quot;
no such identity: /home/pi/.ssh/identity: No such file or directory
Number of key(s) added: 1
Now try logging into the machine, with: &amp;quot;ssh 'pi@pi4b.home'&amp;quot;
and check to make sure that only the key(s) you wanted were added.
&lt;/code>&lt;/pre>&lt;pre>&lt;code>pi@pi3:~/.ssh $ ssh -i cle2 pi@pi4b.home
no such identity: /home/pi/.ssh/identity: No such file or directory
Linux pi4b 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Mar 7 11:57:23 2020 from 192.168.1.29
pi@pi4b:~ $
&lt;/code>&lt;/pre></description></item><item><title>Sécurisation SSH : Utilisation de clés à la place de password.</title><link>https://blog.moulard.org/ssh-cle/</link><pubDate>Mon, 09 Mar 2020 13:19:36 +0100</pubDate><guid>https://blog.moulard.org/ssh-cle/</guid><comments>https://blog.moulard.org/ssh-cle/#disqus_thread</comments><description>&lt;h1 id="pourquoi-des-clés-ssh-et-pas-des-password-">Pourquoi des clés ssh et pas des password ?&lt;/h1>
&lt;p>Il y a deux raisons d&amp;rsquo;utiliser des clés et pas des password pour le SSH, l&amp;rsquo;une est bonne et l&amp;rsquo;autre mauvaise.
La mauvaise raison est gérer, mémoriser et taper des password. Ce n&amp;rsquo;est pas le but de la vie car cela est pénible.
La bonne est que les passowrd, sur internet, ça ne résiste pas aux attaques de force brute. Un password de 8 caractères, même complexe, est bien moins sécurisé qu&amp;rsquo;une clé de 4096 bits.&lt;/p>
&lt;p>Dans le cloud quand vous laissez un serveur SSH accessible, en quelques minutes c&amp;rsquo;est the final bot attaque !!!&lt;/p>
&lt;p>J&amp;rsquo;aime bien dire que la clé privée est une clé, et que la clé publique est une serrure.
La clé privée permet d&amp;rsquo;ouvrir les portes sécurisée avec la clé publique.
Évidement si vous pouvez partager la clé publique, il faut précieusement garder secrète la clé privée.
La passphrase, est le code secret nécessaire à l&amp;rsquo;utilisation de la clé privée.&lt;/p>
&lt;h2 id="comment-empêcher-les-password-dans-ssh">Comment empêcher les password dans SSH&lt;/h2>
&lt;p>Il suffit de mettre à &lt;code>no&lt;/code> le paramètre de &lt;code>PasswordAuthentication&lt;/code> du fichier &lt;code>/etc/ssh/sshd_config&lt;/code> :&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">pi@pi3:~/.ssh $ grep PasswordAuthentication /etc/ssh/sshd_config
PasswordAuthentication no
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Et de redémarrer le serveur ssh (&lt;code>sshd&lt;/code>)&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">root@pi3:~&amp;gt; systemctl restart sshd
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="comment-faire-une-clé-">Comment faire une clé ?&lt;/h1>
&lt;p>Avec &lt;code>puttygen&lt;/code> sous Windows c&amp;rsquo;est simplissime, il ne faut juste pas oublier de bouger la souris sous la barre verte pour générer de l’aléatoire.&lt;/p>
&lt;p>&lt;img src="https://blog.moulard.org/img/2020/puttyGen.png" alt="puttyGen3">&lt;/p>
&lt;p>Avec openssh, c&amp;rsquo;est encore plus simple :&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">pi@pi3:~/.ssh $ ssh-keygen -t rsa -b &lt;span style="color:#ae81ff">4096&lt;/span>
Generating public/private rsa key pair.
Enter file in which to save the key &lt;span style="color:#f92672">(&lt;/span>/home/pi/.ssh/id_rsa&lt;span style="color:#f92672">)&lt;/span>:
Enter passphrase &lt;span style="color:#f92672">(&lt;/span>empty &lt;span style="color:#66d9ef">for&lt;/span> no passphrase&lt;span style="color:#f92672">)&lt;/span>:
Enter same passphrase again:
Your identification has been saved in /home/pi/.ssh/id_rsa.
Your public key has been saved in /home/pi/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:WJfG2b35KlyIkbY+jo+H3dyMKrtJiSoC0JRyIe9ptlw pi@pi3
The keys randomart image is:
+---&lt;span style="color:#f92672">[&lt;/span>RSA 4096&lt;span style="color:#f92672">]&lt;/span>----+
|. .o |
|.o+ . + . |
| &lt;span style="color:#f92672">=&lt;/span>. . *.. . |
|.... o o+ o |
|. &lt;span style="color:#f92672">=&lt;/span> E . S. + .o |
|.+ o . .o . .. |
|. o . o+ + &lt;span style="color:#f92672">=&lt;/span> .|
|. . . .o+&lt;span style="color:#f92672">=&lt;/span> * o. |
| . .. *B+o .. |
+----&lt;span style="color:#f92672">[&lt;/span>SHA256&lt;span style="color:#f92672">]&lt;/span>-----+
pi@pi3:~/.ssh $ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC0g4DwF...LUSQeFGB7NrP0R9F3A4ose01JCX5kbXp91W6R7Q&lt;span style="color:#f92672">==&lt;/span> pi@pi3
pi@pi3:~/.ssh $ cat id_rsa
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,91FE4EEA4EF377C38F0D56DC7BE40B3F
XgeIahCfT+cL/4tUgUDrPY7p3+b5imo/0FGwLLmX3U9pPY6AlbhOksAaglXYUP/r
Q3dGNBO7zDYiiMB3ZIn2rRYlmVShlLT1xCSryFDy/BEnGDPFA8QSVxD+EnOcevtj
akFbUfC2RYBxMMN4/e1mHK00ILUFqGmCYVR0qFU0SH8QB5BrKXbBfYK7LVQxKrKs
...
...
...
GGR/SS22KBTs4KksYPtgYvOu/cxV4LLdNDS0zBGC89txFhSvsfT/+SwC6vyfaf9G
vqbQ59U8VvNQFPkU9v0DfN6lg5/4mFhbDncc92yGqouXEGS/YVwXUx/BCVaYAadd
Ue+B5sxn6T+0VypJK/0cQvnLZ8o2d2SekAde3lMRLP/Bn4VHt/6S5XfY1z1ILnvB
pFmgdzSEzY37bHQedPcqqSqVposf9dZ1zLRHhLyqcKKx7xRLBX7oY4EPSaT8VwvF
7z16A4Fjrkc4twARvpyIRbX2CYqa7ZELo83tIvWTFzZKA99tL6p0upAOME+0zFwm
-----END RSA PRIVATE KEY-----
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="comment-pousser-sa-clé-sur-un-serveur-">Comment pousser sa clé sur un serveur ?&lt;/h1>
&lt;p>La clé publique doit être mise dans la liste des clés du compte que l&amp;rsquo;on souhaite accéder.
Classiquement &lt;code>/home/&amp;lt;&amp;lt;user&amp;gt;&amp;gt;/.ssh/authorized_keys&lt;/code>.
Il faut mettre, dans le fichier &lt;code>/etc/ssh/sshd_config&lt;/code>, la clé &lt;code>AuthorizedKeysFile&lt;/code> par défaut à &lt;code>%h/.ssh/authorized_keys&lt;/code>.&lt;/p>
&lt;h2 id="copie-de-la-clé-sur-un-server">Copie de la clé sur un server&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">pi@pi3:~/.ssh $ ssh-copy-id pi@pi4b.home
/usr/bin/ssh-copy-id: INFO: Source of key&lt;span style="color:#f92672">(&lt;/span>s&lt;span style="color:#f92672">)&lt;/span> to be installed: &lt;span style="color:#e6db74">&amp;#34;/home/pi/.ssh/id_rsa.pub&amp;#34;&lt;/span>
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key&lt;span style="color:#f92672">(&lt;/span>s&lt;span style="color:#f92672">)&lt;/span>, to filter out any that are already installed
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
&lt;span style="color:#f92672">(&lt;/span>&lt;span style="color:#66d9ef">if&lt;/span> you think this is a mistake, you may want to use -f option&lt;span style="color:#f92672">)&lt;/span>
pi@pi3:~/.ssh $ ssh pi@pi4b.home -i id_rsa
Linux pi4b 4.19.75-v7l+ &lt;span style="color:#75715e">#1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l&lt;/span>
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms &lt;span style="color:#66d9ef">for&lt;/span> each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Mar &lt;span style="color:#ae81ff">7&lt;/span> 11:05:33 &lt;span style="color:#ae81ff">2020&lt;/span> from 192.168.1.29
pi@pi4b:~ $
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="copie-de-la-clé-manuellement">Copie de la clé manuellement&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">pi@pi3:~/.ssh $ cat id_rsa.pub &amp;gt;&amp;gt; /home/pi/.ssh/authorized_keys
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Attention aux autorisations sur le fichier authorized_keys&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">pi@pi3:~/.ssh $ ls -l /home/pi/.ssh/authorized_keys
-rw------- &lt;span style="color:#ae81ff">1&lt;/span> pi pi &lt;span style="color:#ae81ff">3505&lt;/span> mars &lt;span style="color:#ae81ff">7&lt;/span> 12:01 /home/pi/.ssh/authorized_keys
&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Rapports en Markdown avec Pandoc</title><link>https://blog.moulard.org/pandoc-markdown-rapport/</link><pubDate>Wed, 04 Dec 2019 13:35:37 +0100</pubDate><guid>https://blog.moulard.org/pandoc-markdown-rapport/</guid><comments>https://blog.moulard.org/pandoc-markdown-rapport/#disqus_thread</comments><description>&lt;p>Faire un rapport peux être compliqué avec des outils très graphiques. En effet, il est très simple de ne pas être consistent lorsque l&amp;rsquo;on fait la mise en page du rapport. Et cela ne fait pas un rapport très sérieux. C&amp;rsquo;est pour cela que séparer le style du contenu du rapport peux être très intéressant.&lt;/p>
&lt;p>En effet, la séparation du contenant et du contenu permet d&amp;rsquo;être conscient de ce que l&amp;rsquo;on écrit et permet de changer le style global du rapport facilement.&lt;/p>
&lt;p>&lt;img src="https://blog.moulard.org/img/2019/hugo-creation.png" alt="">&lt;/p>
&lt;h1 id="quest-ce-que-le-markdown">Qu&amp;rsquo;est-ce que le Markdown&lt;/h1>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-markdown" data-lang="markdown">Le Markdown est un langage de markup, il permet donc d&amp;#39;écrire du texte que l&amp;#39;on peux formater. Il faut écrire le texte qu&amp;#39;il contiens avec des marqueurs pour indiquer ce que le texte est sensé vouloir exprimer: un Titre, un texte gras ou une liste.
# Le Basique du texte
Ceci est en &lt;span style="font-style:italic">*italique*&lt;/span> et ceci est en &lt;span style="font-weight:bold">**gras**&lt;/span>. Un autre &lt;span style="font-style:italic">_italique_&lt;/span> et un autre &lt;span style="font-weight:bold">__gras__&lt;/span>.
Ceci est un texte &lt;span style="color:#e6db74">`important`&lt;/span> et le signe % et &lt;span style="color:#e6db74">`%`&lt;/span>
Ceci est un paragraphe avec une note[^note-id].
[^note-id]: c&amp;#39;est le texte de la note.
Ceci est un paragraphe avec une note^[les textes directement à l&amp;#39;interieur de la note sont plus symple à lire et à écrire] qui est directement à l&amp;#39;interieure du paragraphe.
# L&amp;#39;Indentation
&lt;span style="color:#66d9ef">&amp;gt; &lt;/span>&lt;span style="font-style:italic">Voila du texte indenté
&lt;/span>&lt;span style="font-style:italic">&lt;/span>&amp;gt;&amp;gt; Encore plus indenté
# Les Titres
# Gros Titre (h1)
&lt;span style="color:#75715e">## Titre moyen (h2)
&lt;/span>&lt;span style="color:#75715e">### Petit Titre (h3)
&lt;/span>&lt;span style="color:#75715e">#### Encore (hX)
&lt;/span>&lt;span style="color:#75715e">##### Encore (hX)
&lt;/span>&lt;span style="color:#75715e">###### encore (hX)
&lt;/span>&lt;span style="color:#75715e">&lt;/span>
# Les Listes
&lt;span style="color:#66d9ef">-&lt;/span> les indicateurs peuvent être &lt;span style="color:#e6db74">`-`&lt;/span>, &lt;span style="color:#e6db74">`+`&lt;/span>, ou &lt;span style="color:#e6db74">`*`&lt;/span>
&lt;span style="color:#66d9ef">-&lt;/span> liste 1
&lt;span style="color:#66d9ef">-&lt;/span> liste 2
&lt;span style="color:#66d9ef">-&lt;/span> sous liste 1
&lt;span style="color:#66d9ef">-&lt;/span> sous liste 2
avec du texte indenté à l’intérieur.
&lt;span style="color:#66d9ef">-&lt;/span> liste 3
+ liste 4
&lt;span style="color:#66d9ef">*&lt;/span> liste 5
# Liens
Ceci est un [&lt;span style="color:#f92672">lien à l&amp;#39;intérieur du paragraphe&lt;/span>](&lt;span style="color:#a6e22e">http://blog.moulard.org/&lt;/span>) et [&lt;span style="color:#f92672">un autre avec un titre&lt;/span>](&lt;span style="color:#a6e22e">http://blog.moulard.org/ &amp;#34;Voila le lien de mon blog&amp;#34;&lt;/span>).
Les Liens peuvent aussi être référencés: [référence 1][ref1] or [référence 2 avec un titre][ref2].
[ref1]: http://blog.moulard.org
[ref2]: http://blog.moulard.org &amp;#34;Voila le lien de mon blog&amp;#34;
Les Références sont en général placées à la fin du document.
# Les Images
Une image test:
![&lt;span style="color:#f92672">china&lt;/span>](&lt;span style="color:#a6e22e">https://tom.moulard.org/assets/img/team/china.jpg &amp;#34;china&amp;#34;&lt;/span>)
Comme une lien, les images peuvent avoir une référence à la place d&amp;#39;un lien:
![china][china-ref]
[china-ref]: https://tom.moulard.org/assets/img/team/china.jpg &amp;#34;china&amp;#34;
# Le Code
C&amp;#39;est plutôt facile de montrer du code dans un fichier markdown.
Les &lt;span style="color:#e6db74">`backticks`&lt;/span> sont utilisées pour mettre en avant du texte.
Aussi, n&amp;#39;importe quel bloc de texte indenté est considéré comme un bloc de code.
&amp;lt;&lt;span style="color:#f92672">script&lt;/span>&amp;gt;
document.&lt;span style="color:#a6e22e">location&lt;/span> &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#39;http://lmgtfy.com/?q=markdown+cheat+sheet&amp;#39;&lt;/span>;
&amp;lt;/&lt;span style="color:#f92672">script&lt;/span>&amp;gt;
On peux spécifier le langage du code après les backticks pour avoir une coloration qui soit en rapport:
```python
import random
class CardGame(object):
&amp;#34;&amp;#34;&amp;#34; a sample python class &amp;#34;&amp;#34;&amp;#34;
NB_CARDS = 32
def &lt;span style="font-weight:bold">__init__&lt;/span>(self, cards=5):
self.cards = random.sample(range(self.NB_CARDS), 5)
print &amp;#39;ready to play&amp;#39;
```
Du code en Javascript:
```js
var config = {
duration: 5,
comment: &amp;#39;WTF&amp;#39;
}
// callbacks beauty un action
async_call(&amp;#39;/path/to/api&amp;#39;, function(json) {
another_call(json, function(result2) {
another_another_call(result2, function(result3) {
another_another_another_call(result3, function(result4) {
alert(&amp;#39;And if all went well, i got my result :)&amp;#39;);
});
});
});
})
```
# Les Math
Des expressions mathématiques peuvent aussi être affichées. Cela permet d&amp;#39;avoir des expression directement dans le texte \\(\frac{\pi}{2}\\) $\pi$.
D&amp;#39;autre part, on paux aussi écrire ses expressions sur leurs propre lignes:
$$F(\omega) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{\infty} f(t) \, e^{ - i \omega t}dt$$
\\[\int_0^1 f(t) \mathrm{d}t\\]
\\[\sum_j \gamma_j^2/d_j\\]
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="quest-ce-que-pandoc">Qu&amp;rsquo;est-ce que Pandoc&lt;/h1>
&lt;p>Selon &lt;code>man pandoc&lt;/code>&lt;/p>
&lt;blockquote>
&lt;p>Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;code>Pandoc&lt;/code> permet donc de convertir un &lt;code>markup language&lt;/code> en un autre.&lt;/p>
&lt;p>Et nous allons utiliser &lt;code>pandoc&lt;/code> pour convertir du &lt;code>markdown&lt;/code> en &lt;code>pdf&lt;/code>.&lt;/p>
&lt;h1 id="les-métadonnées-du-markdown">Les Métadonnées du markdown&lt;/h1>
&lt;p>Les Métadonnées, en &lt;code>markdown&lt;/code>, sont entourée par des &lt;code>---&lt;/code> qui permettent d&amp;rsquo;exprimer des informations importantes à &lt;code>pandoc&lt;/code> pour qu&amp;rsquo;il puisse facilement utiliser certaines valeurs. Ses valeurs sont spécifique au template utilisé(&lt;a href="https://github.com/jgm/pandoc/wiki/User-contributed-templates">liste de templates non exhaustive&lt;/a>). Nous allons utiliser le template &lt;a href="https://github.com/Wandmalfarbe/pandoc-latex-template">Eisvogel&lt;/a>.&lt;/p>
&lt;p>Voici un example des Métadonnées:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-markdown" data-lang="markdown">---
title: Rapport
author: Tom Moulard
date: 2020-01-10
lang: &amp;#34;fr&amp;#34;
toc: true
toc-title: &amp;#34;Sommaire&amp;#34;
fontsize: 14pt
titlepage: true
logo: /tmp/rapport.png
book: true
listings-no-page-break: true
links-as-notes: true
---
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Ce que veulent dire chaque champs:&lt;/p>
&lt;ul>
&lt;li>&lt;code>title&lt;/code>(string): Correspond au titre du rapport&lt;/li>
&lt;li>&lt;code>author&lt;/code>(string): Correspond à l&amp;rsquo;auteur du rapport&lt;/li>
&lt;li>&lt;code>date&lt;/code>(string): Correspond à la date d&amp;rsquo;écriture du rapport&lt;/li>
&lt;li>&lt;code>lang&lt;/code>(string): Correspond à la langue utilisé dans le rapport&lt;/li>
&lt;li>&lt;code>toc&lt;/code>(bool): Exprime si l&amp;rsquo;on veux afficher le sommaire&lt;/li>
&lt;li>&lt;code>toc-title&lt;/code>(string): Permet de définir le titre donné au sommaire&lt;/li>
&lt;li>&lt;code>fontsize&lt;/code>(string): Correspond à la taille du texte du rapport&lt;/li>
&lt;li>&lt;code>titlepage&lt;/code>(bool): Exprime si l&amp;rsquo;on veux qu&amp;rsquo;il y ait une page d’accueil avec le titre du document, l&amp;rsquo;auteur, la date et le logo&lt;/li>
&lt;li>&lt;code>logo&lt;/code>(string): Correspond au chemin absolu du logo du rapport&lt;/li>
&lt;li>&lt;code>book&lt;/code>(bool): Exprime si l&amp;rsquo;on veux avoir une page blanche en plus pour avoir les pages avec un nouveau titre à droite dans un livre&lt;/li>
&lt;li>&lt;code>listings-no-page-break&lt;/code>(bool): Exprime si l&amp;rsquo;on ne veux pas qu&amp;rsquo;une liste d&amp;rsquo;éléments soit sur plusieurs pages&lt;/li>
&lt;/ul>
&lt;h1 id="la-compilation-du-markdown">La compilation du markdown&lt;/h1>
&lt;p>Il faut donc avoir &lt;code>pandoc&lt;/code> d&amp;rsquo;installé, j&amp;rsquo;utilise la version &lt;code>pandoc 2.7.3 Compiled with pandoc-types 1.17.6.1, texmath 0.11.3, skylighting 0.8.2.3&lt;/code> pour cet exemple.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">pandoc &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --from markdown+inline_notes+footnotes &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> -V papersize:a4paper &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> -s &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --number-sections &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --listings &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --template eisvogel &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> --top-level-division&lt;span style="color:#f92672">=&lt;/span>chapter &lt;span style="color:#ae81ff">\
&lt;/span>&lt;span style="color:#ae81ff">&lt;/span> rapport.md -o rapport.pdf
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Les arguments utilisés ici permettent d&amp;rsquo;avoir encore plus de contrôle sur &lt;code>pandoc&lt;/code> et le fichier de sortie.
Leurs signification:&lt;/p>
&lt;ul>
&lt;li>&lt;code>from&lt;/code>: Permet de définir le langage source et ses spécifications&lt;/li>
&lt;li>&lt;code>V&lt;/code>: Permet de définir des variables de la forme CLEF:VALEUR&lt;/li>
&lt;li>&lt;code>s&lt;/code>: Permet d&amp;rsquo;avoir un header et un footer approprié, de ne pas avoir des problèmes d&amp;rsquo;encodage de fichiers et de ne pas avoir des Métadata dans le corps du texte.&lt;/li>
&lt;li>&lt;code>number-sections&lt;/code>: Permet de donner un nombre unique aux sections pour les reconnaître et connaître leurs emplacement dans l&amp;rsquo;organisation du document.&lt;/li>
&lt;li>&lt;code>listings&lt;/code>: Permet d&amp;rsquo;utiliser le package &lt;code>listings&lt;/code> pour les blocs de code.&lt;/li>
&lt;li>&lt;code>template&lt;/code>: Permet de spécifier le nom du template à utiliser&lt;/li>
&lt;li>&lt;code>top-level-division&lt;/code>: Permet de monter les headers à partir d&amp;rsquo;un certain niveau dans la hiérarchie des sections(de &lt;code>part&lt;/code>, &lt;code>chapter&lt;/code> et &lt;code>section&lt;/code>). &lt;code>top-level-division=chapter&lt;/code> permet donc de montrer les headers sur les sections &lt;code>chapter&lt;/code> et &lt;code>section&lt;/code>.&lt;/li>
&lt;/ul></description></item><item><title>OSINT Avec Sherlock</title><link>https://blog.moulard.org/osint-with-sherlock/</link><pubDate>Mon, 02 Dec 2019 23:53:04 +0100</pubDate><guid>https://blog.moulard.org/osint-with-sherlock/</guid><comments>https://blog.moulard.org/osint-with-sherlock/#disqus_thread</comments><description>&lt;p>A la recherche d&amp;rsquo;informations disponible sur les réseaux sociaux grâce à un nom d&amp;rsquo;utilisateur avec Sherlock&lt;/p>
&lt;p>Quand on veux connaître plus d&amp;rsquo;informations sur une personne, on peux aller chercher sur internet des informations utiles. Mais on peux aussi utiliser des outils qui ont été fait pour ça. Des outils comme &lt;a href="https://github.com/sherlock-project/sherlock">sherlock&lt;/a> sont donc utiles pour rechercher des liens entre les personnes.&lt;/p>
&lt;h1 id="mais-cest-quoi-osinthttpsenwikipediaorgwikiopen-source_intelligence-">Mais c&amp;rsquo;est quoi &lt;a href="https://en.wikipedia.org/wiki/Open-source_intelligence">OSINT&lt;/a> ?&lt;/h1>
&lt;blockquote>
&lt;p>OSINT viens de Open-Source INTelligence&lt;/p>
&lt;/blockquote>
&lt;p>Ce sont des &lt;strong>renseignements de sources ouverts&lt;/strong> ou des &lt;strong>Renseignements d&amp;rsquo;Origine Source Ouverte&lt;/strong>(ROSO). Ce sont donc des méthodes d&amp;rsquo;obtention d&amp;rsquo;informations qui sont obtenues avec une source publique d&amp;rsquo;information. Mais il faut dissocier les informations de la méthode d&amp;rsquo;obtention. En effet, les informations obtenues sont appelées OSIF(Open Source inFormation) alors que la méthode est appelée OSINT.&lt;/p>
&lt;h1 id="mais-à-quoi-ça-sert-">Mais à quoi ça sert ?&lt;/h1>
&lt;p>Sherlock permet de regrouper un ensemble de liens qui sont relatifs à un nom d&amp;rsquo;utilisateur.&lt;/p>
&lt;p>&lt;a href="https://asciinema.org/a/233089">&lt;img src="https://asciinema.org/a/233089.svg" alt="asciicast">&lt;/a>&lt;/p>
&lt;p>Cela permet donc de regrouper rapidement des liens qui sont en rapport avec un nom d&amp;rsquo;utilisateur.&lt;/p>
&lt;h1 id="comment-sen-servir-">Comment s&amp;rsquo;en servir ?&lt;/h1>
&lt;p>Je recommande d&amp;rsquo;utiliser docker pour cela car ça évite d’installer trop de dépendances python.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">docker run theyahya/sherlock user123
&lt;/code>&lt;/pre>&lt;/div>&lt;p>et si l&amp;rsquo;on souhaite récupérer le fichier en sortie, il faut créer le fichier &lt;code>docker-compose.yml&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">cat &amp;gt; docker-compose.yml &lt;span style="color:#e6db74">&amp;lt;&amp;lt; EOF
&lt;/span>&lt;span style="color:#e6db74">version: &amp;#34;2&amp;#34;
&lt;/span>&lt;span style="color:#e6db74">services:
&lt;/span>&lt;span style="color:#e6db74"> sherlock:
&lt;/span>&lt;span style="color:#e6db74"> image: theyahya/sherlock
&lt;/span>&lt;span style="color:#e6db74"> volumes:
&lt;/span>&lt;span style="color:#e6db74"> - &amp;#34;./results:/opt/sherlock/results&amp;#34;
&lt;/span>&lt;span style="color:#e6db74">EOF&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Puis faire:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">docker-compose run sherlock -o /opt/sherlock/results/user123.txt user123
cat results/user123.txt
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="pour-les-irréductibles-du-fond">Pour les irréductibles du fond&lt;/h2>
&lt;p>On peux directement installer le script via git et pip:&lt;/p>
&lt;blockquote>
&lt;p>Il faut donc avoir python3, git et python3-pip d&amp;rsquo;installé.&lt;/p>
&lt;/blockquote>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#75715e"># clone the repo&lt;/span>
git clone https://github.com/sherlock-project/sherlock.git
&lt;span style="color:#75715e"># change the working directory to sherlock&lt;/span>
cd sherlock
&lt;span style="color:#75715e"># install the requirements&lt;/span>
python3 -m pip install -r requirements.txt
&lt;/code>&lt;/pre>&lt;/div>&lt;p>puis on peux faire&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">python3 sherlock.py user123
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="récupérer-des-données">Récupérer des données&lt;/h1>
&lt;p>Récupérer ses données là peux être importantes car elle permettent d&amp;rsquo;utiliser d&amp;rsquo;autres outils qui auront une analyse plus profonde d&amp;rsquo;un site en particulier par exemple.&lt;/p>
&lt;p>On peux, par exemple, utiliser le fichier fourni par Sherlock et ouvrir tous les liens obtenu dans un nouvel onglet de notre navigateur:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#66d9ef">for&lt;/span> link in &lt;span style="color:#66d9ef">$(&lt;/span>grep http results/user123.txt&lt;span style="color:#66d9ef">)&lt;/span>; &lt;span style="color:#66d9ef">do&lt;/span> $BROWSER $link; &lt;span style="color:#66d9ef">done&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="les-sites-qui-sont-disponible-actuellement-sont">Les sites qui sont disponible actuellement sont:&lt;/h1>
&lt;ul>
&lt;li>&lt;code> 2Dimensions&lt;/code>&lt;/li>
&lt;li>&lt;code>500px&lt;/code>&lt;/li>
&lt;li>&lt;code>7Cups&lt;/code>&lt;/li>
&lt;li>&lt;code>9GAG&lt;/code>&lt;/li>
&lt;li>&lt;code>About.me&lt;/code>&lt;/li>
&lt;li>&lt;code>Academia.edu&lt;/code>&lt;/li>
&lt;li>&lt;code>Alik.cz&lt;/code>&lt;/li>
&lt;li>&lt;code>Anobii&lt;/code>&lt;/li>
&lt;li>&lt;code>Aptoide&lt;/code>&lt;/li>
&lt;li>&lt;code>Archive.org&lt;/code>&lt;/li>
&lt;li>&lt;code>AskFM&lt;/code>&lt;/li>
&lt;li>&lt;code>Av\u00edzo.cz&lt;/code>&lt;/li>
&lt;li>&lt;code>BLIP.fm&lt;/code>&lt;/li>
&lt;li>&lt;code>Badoo&lt;/code>&lt;/li>
&lt;li>&lt;code>Bandcamp&lt;/code>&lt;/li>
&lt;li>&lt;code>Basecamp&lt;/code>&lt;/li>
&lt;li>&lt;code>Bazar.cz&lt;/code>&lt;/li>
&lt;li>&lt;code>Behance&lt;/code>&lt;/li>
&lt;li>&lt;code>BitBucket&lt;/code>&lt;/li>
&lt;li>&lt;code>BitCoinForum&lt;/code>&lt;/li>
&lt;li>&lt;code>Blogger&lt;/code>&lt;/li>
&lt;li>&lt;code>Bookcrossing&lt;/code>&lt;/li>
&lt;li>&lt;code>Brew&lt;/code>&lt;/li>
&lt;li>&lt;code>BuyMeACoffee&lt;/code>&lt;/li>
&lt;li>&lt;code>BuzzFeed&lt;/code>&lt;/li>
&lt;li>&lt;code>CNET&lt;/code>&lt;/li>
&lt;li>&lt;code>Canva&lt;/code>&lt;/li>
&lt;li>&lt;code>CapFriendly&lt;/code>&lt;/li>
&lt;li>&lt;code>Carbonmade&lt;/code>&lt;/li>
&lt;li>&lt;code>CashMe&lt;/code>&lt;/li>
&lt;li>&lt;code>Cent&lt;/code>&lt;/li>
&lt;li>&lt;code>Chatujme.cz&lt;/code>&lt;/li>
&lt;li>&lt;code>Cloob&lt;/code>&lt;/li>
&lt;li>&lt;code>Codecademy&lt;/code>&lt;/li>
&lt;li>&lt;code>Codechef&lt;/code>&lt;/li>
&lt;li>&lt;code>Codementor&lt;/code>&lt;/li>
&lt;li>&lt;code>Coderwall&lt;/code>&lt;/li>
&lt;li>&lt;code>Codewars&lt;/code>&lt;/li>
&lt;li>&lt;code>ColourLovers&lt;/code>&lt;/li>
&lt;li>&lt;code>Contently&lt;/code>&lt;/li>
&lt;li>&lt;code>Coroflot&lt;/code>&lt;/li>
&lt;li>&lt;code>Cracked&lt;/code>&lt;/li>
&lt;li>&lt;code>CreativeMarket&lt;/code>&lt;/li>
&lt;li>&lt;code>Crevado&lt;/code>&lt;/li>
&lt;li>&lt;code>Crunchyroll&lt;/code>&lt;/li>
&lt;li>&lt;code>DEV Community&lt;/code>&lt;/li>
&lt;li>&lt;code>DailyMotion&lt;/code>&lt;/li>
&lt;li>&lt;code>Designspiration&lt;/code>&lt;/li>
&lt;li>&lt;code>DeviantART&lt;/code>&lt;/li>
&lt;li>&lt;code>Discogs&lt;/code>&lt;/li>
&lt;li>&lt;code>Discuss.Elastic.co&lt;/code>&lt;/li>
&lt;li>&lt;code>Disqus&lt;/code>&lt;/li>
&lt;li>&lt;code>Docker Hub&lt;/code>&lt;/li>
&lt;li>&lt;code>Dribbble&lt;/code>&lt;/li>
&lt;li>&lt;code>Ebay&lt;/code>&lt;/li>
&lt;li>&lt;code>Ello&lt;/code>&lt;/li>
&lt;li>&lt;code>Etsy&lt;/code>&lt;/li>
&lt;li>&lt;code>EyeEm&lt;/code>&lt;/li>
&lt;li>&lt;code>Facebook&lt;/code>&lt;/li>
&lt;li>&lt;code>Fandom&lt;/code>&lt;/li>
&lt;li>&lt;code>Filmogs&lt;/code>&lt;/li>
&lt;li>&lt;code>Fiverr&lt;/code>&lt;/li>
&lt;li>&lt;code>Flickr&lt;/code>&lt;/li>
&lt;li>&lt;code>Flightradar24&lt;/code>&lt;/li>
&lt;li>&lt;code>Flipboard&lt;/code>&lt;/li>
&lt;li>&lt;code>FortniteTracker&lt;/code>&lt;/li>
&lt;li>&lt;code>GDProfiles&lt;/code>&lt;/li>
&lt;li>&lt;code>GPSies&lt;/code>&lt;/li>
&lt;li>&lt;code>Gamespot&lt;/code>&lt;/li>
&lt;li>&lt;code>Giphy&lt;/code>&lt;/li>
&lt;li>&lt;code>GitHub&lt;/code>&lt;/li>
&lt;li>&lt;code>GitLab&lt;/code>&lt;/li>
&lt;li>&lt;code>Gitee&lt;/code>&lt;/li>
&lt;li>&lt;code>GoodReads&lt;/code>&lt;/li>
&lt;li>&lt;code>Gravatar&lt;/code>&lt;/li>
&lt;li>&lt;code>Gumroad&lt;/code>&lt;/li>
&lt;li>&lt;code>GuruShots&lt;/code>&lt;/li>
&lt;li>&lt;code>HackerNews&lt;/code>&lt;/li>
&lt;li>&lt;code>HackerOne&lt;/code>&lt;/li>
&lt;li>&lt;code>HackerRank&lt;/code>&lt;/li>
&lt;li>&lt;code>House-Mixes.com&lt;/code>&lt;/li>
&lt;li>&lt;code>Houzz&lt;/code>&lt;/li>
&lt;li>&lt;code>HubPages&lt;/code>&lt;/li>
&lt;li>&lt;code>Hubski&lt;/code>&lt;/li>
&lt;li>&lt;code>IFTTT&lt;/code>&lt;/li>
&lt;li>&lt;code>ImageShack&lt;/code>&lt;/li>
&lt;li>&lt;code>ImgUp.cz&lt;/code>&lt;/li>
&lt;li>&lt;code>Instagram&lt;/code>&lt;/li>
&lt;li>&lt;code>Instructables&lt;/code>&lt;/li>
&lt;li>&lt;code>Investing.com&lt;/code>&lt;/li>
&lt;li>&lt;code>Issuu&lt;/code>&lt;/li>
&lt;li>&lt;code>Itch.io&lt;/code>&lt;/li>
&lt;li>&lt;code>Jimdo&lt;/code>&lt;/li>
&lt;li>&lt;code>Kaggle&lt;/code>&lt;/li>
&lt;li>&lt;code>KanoWorld&lt;/code>&lt;/li>
&lt;li>&lt;code>Keybase&lt;/code>&lt;/li>
&lt;li>&lt;code>Kik&lt;/code>&lt;/li>
&lt;li>&lt;code>Kongregate&lt;/code>&lt;/li>
&lt;li>&lt;code>Launchpad&lt;/code>&lt;/li>
&lt;li>&lt;code>LeetCode&lt;/code>&lt;/li>
&lt;li>&lt;code>Letterboxd&lt;/code>&lt;/li>
&lt;li>&lt;code>LiveJournal&lt;/code>&lt;/li>
&lt;li>&lt;code>LiveLeak&lt;/code>&lt;/li>
&lt;li>&lt;code>Lobsters&lt;/code>&lt;/li>
&lt;li>&lt;code>Mastodon&lt;/code>&lt;/li>
&lt;li>&lt;code>Medium&lt;/code>&lt;/li>
&lt;li>&lt;code>MeetMe&lt;/code>&lt;/li>
&lt;li>&lt;code>MixCloud&lt;/code>&lt;/li>
&lt;li>&lt;code>MyAnimeList&lt;/code>&lt;/li>
&lt;li>&lt;code>Myspace&lt;/code>&lt;/li>
&lt;li>&lt;code>NPM&lt;/code>&lt;/li>
&lt;li>&lt;code>NPM-Package&lt;/code>&lt;/li>
&lt;li>&lt;code>NameMC (Minecraft.net skins)&lt;/code>&lt;/li>
&lt;li>&lt;code>NationStates Nation&lt;/code>&lt;/li>
&lt;li>&lt;code>NationStates Region&lt;/code>&lt;/li>
&lt;li>&lt;code>Newgrounds&lt;/code>&lt;/li>
&lt;li>&lt;code>OK&lt;/code>&lt;/li>
&lt;li>&lt;code>OpenCollective&lt;/code>&lt;/li>
&lt;li>&lt;code>OpenStreetMap&lt;/code>&lt;/li>
&lt;li>&lt;code>PSNProfiles.com&lt;/code>&lt;/li>
&lt;li>&lt;code>Packagist&lt;/code>&lt;/li>
&lt;li>&lt;code>Pastebin&lt;/code>&lt;/li>
&lt;li>&lt;code>Patreon&lt;/code>&lt;/li>
&lt;li>&lt;code>Pexels&lt;/code>&lt;/li>
&lt;li>&lt;code>Photobucket&lt;/code>&lt;/li>
&lt;li>&lt;code>Pinterest&lt;/code>&lt;/li>
&lt;li>&lt;code>Pixabay&lt;/code>&lt;/li>
&lt;li>&lt;code>PlayStore&lt;/code>&lt;/li>
&lt;li>&lt;code>Plug.DJ&lt;/code>&lt;/li>
&lt;li>&lt;code>Pokemon Showdown&lt;/code>&lt;/li>
&lt;li>&lt;code>Polygon&lt;/code>&lt;/li>
&lt;li>&lt;code>ProductHunt&lt;/code>&lt;/li>
&lt;li>&lt;code>Quora&lt;/code>&lt;/li>
&lt;li>&lt;code>Rajce.net&lt;/code>&lt;/li>
&lt;li>&lt;code>Rate Your Music&lt;/code>&lt;/li>
&lt;li>&lt;code>Reddit&lt;/code>&lt;/li>
&lt;li>&lt;code>Repl.it&lt;/code>&lt;/li>
&lt;li>&lt;code>ResearchGate&lt;/code>&lt;/li>
&lt;li>&lt;code>ReverbNation&lt;/code>&lt;/li>
&lt;li>&lt;code>Roblox&lt;/code>&lt;/li>
&lt;li>&lt;code>Sbazar.cz&lt;/code>&lt;/li>
&lt;li>&lt;code>Scratch&lt;/code>&lt;/li>
&lt;li>&lt;code>Scribd&lt;/code>&lt;/li>
&lt;li>&lt;code>Signal&lt;/code>&lt;/li>
&lt;li>&lt;code>Slack&lt;/code>&lt;/li>
&lt;li>&lt;code>SlideShare&lt;/code>&lt;/li>
&lt;li>&lt;code>Smashcast&lt;/code>&lt;/li>
&lt;li>&lt;code>SoundCloud&lt;/code>&lt;/li>
&lt;li>&lt;code>SourceForge&lt;/code>&lt;/li>
&lt;li>&lt;code>Speedrun.com&lt;/code>&lt;/li>
&lt;li>&lt;code>Splits.io&lt;/code>&lt;/li>
&lt;li>&lt;code>Spotify&lt;/code>&lt;/li>
&lt;li>&lt;code>Star Citizen&lt;/code>&lt;/li>
&lt;li>&lt;code>Steam&lt;/code>&lt;/li>
&lt;li>&lt;code>SteamGroup&lt;/code>&lt;/li>
&lt;li>&lt;code>T-MobileSupport&lt;/code>&lt;/li>
&lt;li>&lt;code>Taringa&lt;/code>&lt;/li>
&lt;li>&lt;code>Telegram&lt;/code>&lt;/li>
&lt;li>&lt;code>Tellonym.me&lt;/code>&lt;/li>
&lt;li>&lt;code>TikTok&lt;/code>&lt;/li>
&lt;li>&lt;code>Tinder&lt;/code>&lt;/li>
&lt;li>&lt;code>TrackmaniaLadder&lt;/code>&lt;/li>
&lt;li>&lt;code>TradingView&lt;/code>&lt;/li>
&lt;li>&lt;code>Trakt&lt;/code>&lt;/li>
&lt;li>&lt;code>Trello&lt;/code>&lt;/li>
&lt;li>&lt;code>Trip&lt;/code>&lt;/li>
&lt;li>&lt;code>TripAdvisor&lt;/code>&lt;/li>
&lt;li>&lt;code>Twitch&lt;/code>&lt;/li>
&lt;li>&lt;code>Twitter&lt;/code>&lt;/li>
&lt;li>&lt;code>Ultimate-Guitar&lt;/code>&lt;/li>
&lt;li>&lt;code>Unsplash&lt;/code>&lt;/li>
&lt;li>&lt;code>VK&lt;/code>&lt;/li>
&lt;li>&lt;code>VSCO&lt;/code>&lt;/li>
&lt;li>&lt;code>Venmo&lt;/code>&lt;/li>
&lt;li>&lt;code>Viadeo&lt;/code>&lt;/li>
&lt;li>&lt;code>Vimeo&lt;/code>&lt;/li>
&lt;li>&lt;code>Virgool&lt;/code>&lt;/li>
&lt;li>&lt;code>VirusTotal&lt;/code>&lt;/li>
&lt;li>&lt;code>Wattpad&lt;/code>&lt;/li>
&lt;li>&lt;code>We Heart It&lt;/code>&lt;/li>
&lt;li>&lt;code>WebNode&lt;/code>&lt;/li>
&lt;li>&lt;code>Wikidot&lt;/code>&lt;/li>
&lt;li>&lt;code>Wikipedia&lt;/code>&lt;/li>
&lt;li>&lt;code>Wix&lt;/code>&lt;/li>
&lt;li>&lt;code>WordPress&lt;/code>&lt;/li>
&lt;li>&lt;code>WordPressOrg&lt;/code>&lt;/li>
&lt;li>&lt;code>YouNow&lt;/code>&lt;/li>
&lt;li>&lt;code>YouPic&lt;/code>&lt;/li>
&lt;li>&lt;code>YouTube&lt;/code>&lt;/li>
&lt;li>&lt;code>Zhihu&lt;/code>&lt;/li>
&lt;li>&lt;code>Zomato&lt;/code>&lt;/li>
&lt;li>&lt;code>authorSTREAM&lt;/code>&lt;/li>
&lt;li>&lt;code>boingboing.net&lt;/code>&lt;/li>
&lt;li>&lt;code>devRant&lt;/code>&lt;/li>
&lt;li>&lt;code>fanpop&lt;/code>&lt;/li>
&lt;li>&lt;code>gfycat&lt;/code>&lt;/li>
&lt;li>&lt;code>habr&lt;/code>&lt;/li>
&lt;li>&lt;code>iMGSRC.RU&lt;/code>&lt;/li>
&lt;li>&lt;code>last.fm&lt;/code>&lt;/li>
&lt;li>&lt;code>mixer.com&lt;/code>&lt;/li>
&lt;li>&lt;code>osu!&lt;/code>&lt;/li>
&lt;li>&lt;code>pikabu&lt;/code>&lt;/li>
&lt;li>&lt;code>segmentfault&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>Si jamais il vous manque un site, en ajouter un est très facile.
Il faut le faire &lt;a href="https://github.com/sherlock-project/sherlock#adding-new-sites">ici&lt;/a>.&lt;/p></description></item><item><title>Une application Multi Architecture en Golang dans Docker</title><link>https://blog.moulard.org/multi-arch-golang-app-docker/</link><pubDate>Wed, 20 Nov 2019 13:19:36 +0100</pubDate><guid>https://blog.moulard.org/multi-arch-golang-app-docker/</guid><comments>https://blog.moulard.org/multi-arch-golang-app-docker/#disqus_thread</comments><description>&lt;h1 id="ce-nest-pas-un-exemple-qui-fonctionne-">Ce n&amp;rsquo;est pas un exemple qui fonctionne !&lt;/h1>
&lt;p>Faire une application en Go et le mettre dans un docker est très important pour la portabilité.&lt;/p>
&lt;p>Un &lt;code>Dockerfile&lt;/code> simple pour une application:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-Dockerfile" data-lang="Dockerfile">&lt;span style="color:#66d9ef">FROM&lt;/span>&lt;span style="color:#e6db74"> scratch&lt;/span>&lt;span style="color:#960050;background-color:#1e0010">
&lt;/span>&lt;span style="color:#960050;background-color:#1e0010">&lt;/span>&lt;span style="color:#66d9ef">COPY&lt;/span> static/ /srv/static/&lt;span style="color:#960050;background-color:#1e0010">
&lt;/span>&lt;span style="color:#960050;background-color:#1e0010">&lt;/span>&lt;span style="color:#66d9ef">COPY&lt;/span> app /srv/app&lt;span style="color:#960050;background-color:#1e0010">
&lt;/span>&lt;span style="color:#960050;background-color:#1e0010">&lt;/span>&lt;span style="color:#66d9ef">CMD&lt;/span> [&lt;span style="color:#e6db74">&amp;#34;/srv/app&amp;#34;&lt;/span>]&lt;span style="color:#960050;background-color:#1e0010">
&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Et le &lt;code>docker-compose&lt;/code> qui va avec:&lt;/p>
&lt;pre>&lt;code class="language-docker-compose" data-lang="docker-compose">version '2'
service:
app:
build: .
port:
- '80:80'
&lt;/code>&lt;/pre>&lt;h1 id="golang-compilation">Golang compilation&lt;/h1>
&lt;p>J&amp;rsquo;ai récupéré sur se &lt;a href="https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63">gist&lt;/a> une liste des GOOS/GOARCH supportés par go:&lt;/p>
&lt;ul>
&lt;li>&lt;code>darwin/386&lt;/code>&lt;/li>
&lt;li>&lt;code>darwin/amd64&lt;/code>&lt;/li>
&lt;li>&lt;code>dragonfly/amd64&lt;/code>&lt;/li>
&lt;li>&lt;code>freebsd/386&lt;/code>&lt;/li>
&lt;li>&lt;code>freebsd/amd64&lt;/code>&lt;/li>
&lt;li>&lt;code>freebsd/arm&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/386&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/amd64&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/arm&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/arm64&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/ppc64&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/ppc64le&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/mips&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/mipsle&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/mips64&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/mips64le&lt;/code>&lt;/li>
&lt;li>&lt;code>linux/s390x&lt;/code>&lt;/li>
&lt;li>&lt;code>nacl/386&lt;/code>&lt;/li>
&lt;li>&lt;code>nacl/amd64p32&lt;/code>&lt;/li>
&lt;li>&lt;code>nacl/arm&lt;/code>&lt;/li>
&lt;li>&lt;code>netbsd/386&lt;/code>&lt;/li>
&lt;li>&lt;code>netbsd/amd64&lt;/code>&lt;/li>
&lt;li>&lt;code>netbsd/arm&lt;/code>&lt;/li>
&lt;li>&lt;code>openbsd/386&lt;/code>&lt;/li>
&lt;li>&lt;code>openbsd/amd64&lt;/code>&lt;/li>
&lt;li>&lt;code>openbsd/arm&lt;/code>&lt;/li>
&lt;li>&lt;code>plan9/386&lt;/code>&lt;/li>
&lt;li>&lt;code>plan9/amd64&lt;/code>&lt;/li>
&lt;li>&lt;code>plan9/arm&lt;/code>&lt;/li>
&lt;li>&lt;code>solaris/amd64&lt;/code>&lt;/li>
&lt;li>&lt;code>windows/386&lt;/code>&lt;/li>
&lt;li>&lt;code>windows/amd64&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>On peux donc construire un script shell simple qui permet de compiler l&amp;rsquo;application:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-sh" data-lang="sh">&lt;span style="color:#75715e">#!/bin/bash
&lt;/span>&lt;span style="color:#75715e">&lt;/span>os_archs&lt;span style="color:#f92672">=(&lt;/span> darwin/386 darwin/amd64 dragonfly/amd64 freebsd/386 freebsd/amd64 freebsd/arm linux/386 linux/amd64 linux/arm linux/arm64 linux/ppc64 linux/ppc64le linux/mips linux/mipsle linux/mips64 linux/mips64le linux/s390x nacl/386 nacl/amd64p32 nacl/arm netbsd/386 netbsd/amd64 netbsd/arm openbsd/386 openbsd/amd64 openbsd/arm plan9/386 plan9/amd64 plan9/arm solaris/amd64 windows/386 windows/amd64 &lt;span style="color:#f92672">)&lt;/span>
build&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;go build -o app&amp;#34;&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> os_arch in &lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_archs[@]&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>; &lt;span style="color:#66d9ef">do&lt;/span>
echo $os_arch
GOARCH&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_arch#*/&lt;span style="color:#e6db74">}&lt;/span> GOOS&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_arch%/*&lt;span style="color:#e6db74">}&lt;/span> CGO_ENABLED&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span> $build
&lt;span style="color:#66d9ef">done&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="docker-manifest">Docker manifest&lt;/h1>
&lt;p>Et comme le dit la &lt;a href="https://docs.docker.com/engine/reference/commandline/manifest/">doc docker&lt;/a>&lt;/p>
&lt;blockquote>
&lt;p>This command is experimental on the Docker client.&lt;/p>
&lt;/blockquote>
&lt;p>(Cette commande est expérimentale sur le client docker)&lt;/p>
&lt;p>Pour activer les fonctions expérimentales du client cli de Docker, il faut ajouter cette ligne &lt;code>&amp;quot;experimental&amp;quot;: &amp;quot;enabled&amp;quot;&lt;/code> dans le fichier de configuration Docker qui à tendance à être ici: &lt;code>$HOME/.docker/config.json&lt;/code>.&lt;/p>
&lt;p>Sur Windows, il faut sélectionner l’icône Docker et sélectionner &lt;code>Settings&lt;/code>.
Il faut ensuite sélectionner &lt;code>Daemon&lt;/code> puis cliquer sur la checkbox &lt;code>Experimental Features&lt;/code> pour les activer&lt;/p>
&lt;h2 id="mais-à-quoi-ça-sert-">Mais à quoi ça sert ?&lt;/h2>
&lt;p>La solution simple pour avoir plusieurs architectures pour une même application est d&amp;rsquo;utiliser les &lt;strong>tags&lt;/strong>(ou repository différents, mais à éviter encore plus).
Il faut donc construire une image par GOOS/GOARCH supportés.
Et on aurait une liste de tags comme ça:&lt;/p>
&lt;ul>
&lt;li>my-app/app:latest&lt;/li>
&lt;li>my-app/app:latest-windows-amd64&lt;/li>
&lt;li>&amp;hellip;&lt;/li>
&lt;li>my-app/app:XXXXXXX-windows-amd64&lt;/li>
&lt;/ul>
&lt;p>Soit faire:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-sh" data-lang="sh">&lt;span style="color:#75715e">#!/bin/bash
&lt;/span>&lt;span style="color:#75715e">&lt;/span>os_archs&lt;span style="color:#f92672">=(&lt;/span> darwin/386 darwin/amd64 dragonfly/amd64 freebsd/386 freebsd/amd64 freebsd/arm linux/386 linux/amd64 linux/arm linux/arm64 linux/ppc64 linux/ppc64le linux/mips linux/mipsle linux/mips64 linux/mips64le linux/s390x nacl/386 nacl/amd64p32 nacl/arm netbsd/386 netbsd/amd64 netbsd/arm openbsd/386 openbsd/amd64 openbsd/arm plan9/386 plan9/amd64 plan9/arm solaris/amd64 windows/386 windows/amd64 &lt;span style="color:#f92672">)&lt;/span>
build&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;go build -o app&amp;#34;&lt;/span>
dk_app&lt;span style="color:#f92672">=&lt;/span>my-app/app
hash&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#66d9ef">$(&lt;/span>git rev-parse --short HEAD&lt;span style="color:#66d9ef">)&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> os_arch in &lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_archs[@]&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>; &lt;span style="color:#66d9ef">do&lt;/span>
echo $os_arch
&lt;span style="color:#75715e"># Compiling&lt;/span>
GOARCH&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_arch#*/&lt;span style="color:#e6db74">}&lt;/span>
GOOS&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_arch%/*&lt;span style="color:#e6db74">}&lt;/span>
GOARCH&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOARCH&lt;span style="color:#e6db74">}&lt;/span> GOOS&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOOS&lt;span style="color:#e6db74">}&lt;/span> CGO_ENABLED&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span> $build
&lt;span style="color:#75715e"># Building and push docker image&lt;/span>
dk_name&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>dk_app&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">:&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>hash&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">-&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOOS&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">-&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOARCH&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>
dk_name_latest&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>dk_app&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">:latest-&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOOS&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">-&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOARCH&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>
docker build -t &lt;span style="color:#e6db74">${&lt;/span>dk_name&lt;span style="color:#e6db74">}&lt;/span> .
docker tag &lt;span style="color:#e6db74">${&lt;/span>dk_name&lt;span style="color:#e6db74">}&lt;/span> &lt;span style="color:#e6db74">${&lt;/span>dk_name_latest&lt;span style="color:#e6db74">}&lt;/span>
docker push &lt;span style="color:#e6db74">${&lt;/span>dk_name&lt;span style="color:#e6db74">}&lt;/span> &lt;span style="color:#e6db74">${&lt;/span>dk_name_latest&lt;span style="color:#e6db74">}&lt;/span>
&lt;span style="color:#66d9ef">done&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Mais il serait mieux de ne pas remplir la liste des tags comme ça.
Et cela ne permet pas d&amp;rsquo;être &lt;strong>vraiment&lt;/strong> multi architecture: sur une machine ARM, il faut un tag différent d&amp;rsquo;une machine x86_64.&lt;/p>
&lt;p>Les manifest de Docker permettent de créer une image qui soit architecture agnostique: Que l&amp;rsquo;on récupère l&amp;rsquo;image sur un ARM ou sur un x86_64, la commande est la même:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">docker pull my-app/app
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Par exemple, sur ma machine amd64:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the &lt;span style="color:#e6db74">&amp;#34;hello-world&amp;#34;&lt;/span> image from the Docker Hub.
&lt;span style="color:#f92672">(&lt;/span>amd64&lt;span style="color:#f92672">)&lt;/span>
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Et sur ma machine arm:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the &lt;span style="color:#e6db74">&amp;#34;hello-world&amp;#34;&lt;/span> image from the Docker Hub.
&lt;span style="color:#f92672">(&lt;/span>arm32v7&lt;span style="color:#f92672">)&lt;/span>
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Où la différence se trouve juste après la deuxième étape où on peux lire:&lt;/p>
&lt;p>&lt;code>The Docker daemon pulled the [...] image [...] (amd64)&lt;/code> puis&lt;/p>
&lt;p>&lt;code>The Docker daemon pulled the [...] image [...] (arm32v7)&lt;/code>.&lt;/p>
&lt;h2 id="création-du-manifest">Création du manifest&lt;/h2>
&lt;p>&lt;strong>Attention, il &lt;strong>faut&lt;/strong> avoir push les images sur un registery avant de créer le manifest&lt;/strong>.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ docker manifest create -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker manifest create MANIFEST_LIST MANIFEST &lt;span style="color:#f92672">[&lt;/span>MANIFEST...&lt;span style="color:#f92672">]&lt;/span>
Create a local manifest list &lt;span style="color:#66d9ef">for&lt;/span> annotating and pushing to a registry
Options:
-a, --amend Amend an existing manifest list
--insecure Allow communication with an insecure registry
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Il faut donc faire la commande &lt;code>docker manifest create&lt;/code> suivi du nom de l'&lt;em>&lt;strong>image&lt;/strong>&lt;/em> à créer et enfin suivi des noms des différentes images précédemment crées à ajouter dans le manifest.&lt;/p>
&lt;p>Ce qui donne, à la main:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ docker push my-app/app:latest-windows-amd64 my-app/app:latest-windows-arm
$ docker manifest create my-app/app:latest my-app/app:latest-windows-amd64 my-app/app:latest-windows-arm ...
Created manifest list docker.io/my-app/app:latest
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Et on peux donc faire:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$ docker manifest inspect my-app/app:latest
&lt;span style="color:#f92672">{&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;schemaVersion&amp;#34;&lt;/span>: 2,
&lt;span style="color:#e6db74">&amp;#34;mediaType&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;application/vnd.docker.distribution.manifest.list.v2+json&amp;#34;&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;manifests&amp;#34;&lt;/span>: &lt;span style="color:#f92672">[&lt;/span>
&lt;span style="color:#f92672">{&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;mediaType&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;application/vnd.docker.distribution.manifest.v2+json&amp;#34;&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;size&amp;#34;&lt;/span>: 42,
&lt;span style="color:#e6db74">&amp;#34;digest&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;sha256:4224&amp;#34;&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;platform&amp;#34;&lt;/span>: &lt;span style="color:#f92672">{&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;architecture&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;amd64&amp;#34;&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;os&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;windows&amp;#34;&lt;/span>
&lt;span style="color:#f92672">}&lt;/span>
&lt;span style="color:#f92672">}&lt;/span>,
&lt;span style="color:#f92672">{&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;mediaType&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;application/vnd.docker.distribution.manifest.v2+json&amp;#34;&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;size&amp;#34;&lt;/span>: 42,
&lt;span style="color:#e6db74">&amp;#34;digest&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;sha256:4224&amp;#34;&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;platform&amp;#34;&lt;/span>: &lt;span style="color:#f92672">{&lt;/span>
&lt;span style="color:#e6db74">&amp;#34;architecture&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;arm&amp;#34;&lt;/span>,
&lt;span style="color:#e6db74">&amp;#34;os&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;windows&amp;#34;&lt;/span>
&lt;span style="color:#f92672">}&lt;/span>
&lt;span style="color:#f92672">}&lt;/span>
&lt;span style="color:#f92672">]&lt;/span>
&lt;span style="color:#f92672">}&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="script-shell">Script Shell&lt;/h2>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#75715e">#!/bin/bash
&lt;/span>&lt;span style="color:#75715e">&lt;/span>os_archs&lt;span style="color:#f92672">=(&lt;/span> darwin/386 darwin/amd64 dragonfly/amd64 freebsd/386 freebsd/amd64 freebsd/arm linux/386 linux/amd64 linux/arm linux/arm64 linux/ppc64 linux/ppc64le linux/mips linux/mipsle linux/mips64 linux/mips64le linux/s390x nacl/386 nacl/amd64p32 nacl/arm netbsd/386 netbsd/amd64 netbsd/arm openbsd/386 openbsd/amd64 openbsd/arm plan9/386 plan9/amd64 plan9/arm solaris/amd64 windows/386 windows/amd64 &lt;span style="color:#f92672">)&lt;/span>
build&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;go build -o app&amp;#34;&lt;/span>
dk_app&lt;span style="color:#f92672">=&lt;/span>my-app/app
hash&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#66d9ef">$(&lt;/span>git rev-parse --short HEAD&lt;span style="color:#66d9ef">)&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> os_arch in &lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_archs[@]&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>; &lt;span style="color:#66d9ef">do&lt;/span>
echo $os_arch
&lt;span style="color:#75715e"># Compiling&lt;/span>
GOARCH&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_arch#*/&lt;span style="color:#e6db74">}&lt;/span>
GOOS&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>os_arch%/*&lt;span style="color:#e6db74">}&lt;/span>
GOARCH&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOARCH&lt;span style="color:#e6db74">}&lt;/span> GOOS&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOOS&lt;span style="color:#e6db74">}&lt;/span> CGO_ENABLED&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span> $build
&lt;span style="color:#75715e"># Building and push docker image&lt;/span>
dk_name&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>dk_app&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">:&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>hash&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">-&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOOS&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">-&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOARCH&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>
dk_name_latest&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>dk_app&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">:latest-&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOOS&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">-&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>GOARCH&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>
docker build -t &lt;span style="color:#e6db74">${&lt;/span>dk_name&lt;span style="color:#e6db74">}&lt;/span> --platform &lt;span style="color:#e6db74">${&lt;/span>GOOS&lt;span style="color:#e6db74">}&lt;/span> . -q
docker tag &lt;span style="color:#e6db74">${&lt;/span>dk_name&lt;span style="color:#e6db74">}&lt;/span> &lt;span style="color:#e6db74">${&lt;/span>dk_name_latest&lt;span style="color:#e6db74">}&lt;/span>
docker push &lt;span style="color:#e6db74">${&lt;/span>dk_name&lt;span style="color:#e6db74">}&lt;/span>
docker push &lt;span style="color:#e6db74">${&lt;/span>dk_name_latest&lt;span style="color:#e6db74">}&lt;/span>
manifests_latest&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>manifests_latest&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74"> &lt;/span>&lt;span style="color:#e6db74">${&lt;/span>dk_name_latest&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>
manifests&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>&lt;span style="color:#e6db74">${&lt;/span>manifests&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74"> &lt;/span>&lt;span style="color:#e6db74">${&lt;/span>dk_name&lt;span style="color:#e6db74">}&lt;/span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span>
&lt;span style="color:#66d9ef">done&lt;/span>
docker manifest create tommoulard/app:latest &lt;span style="color:#e6db74">${&lt;/span>manifests_latest&lt;span style="color:#e6db74">}&lt;/span> --amend
docker manifest create tommoulard/app:&lt;span style="color:#e6db74">${&lt;/span>hash&lt;span style="color:#e6db74">}&lt;/span> &lt;span style="color:#e6db74">${&lt;/span>manifests&lt;span style="color:#e6db74">}&lt;/span> --amend
docker manifest push tommoulard/app:latest
docker manifest push tommoulard/app:&lt;span style="color:#e6db74">${&lt;/span>hash&lt;span style="color:#e6db74">}&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="ce-nest-pas-un-exemple-qui-fonctionne--1">Ce n&amp;rsquo;est pas un exemple qui fonctionne !&lt;/h1></description></item><item><title>Création de site avec Hugo</title><link>https://blog.moulard.org/creation-de-site/</link><pubDate>Wed, 13 Nov 2019 15:17:21 +0100</pubDate><guid>https://blog.moulard.org/creation-de-site/</guid><comments>https://blog.moulard.org/creation-de-site/#disqus_thread</comments><description>&lt;p>Installer un site sur Hugo peux poser des difficultés lors de l&amp;rsquo;installation.&lt;/p>
&lt;h2 id="la-partie-sur-hugo">La partie sur Hugo&lt;/h2>
&lt;h3 id="installation-de-hugo">Installation de Hugo&lt;/h3>
&lt;p>Sur Ubuntu, un simple &lt;code>snap install hugo&lt;/code> fonctionne.&lt;/p>
&lt;h3 id="création-du-site">Création du site&lt;/h3>
&lt;p>Pour créer le site, il suffit de faire la commande&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">hugo new site blog
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="ajouter-un-thème">Ajouter un thème&lt;/h3>
&lt;p>Il faut rechercher dans la &lt;a href="https://themes.gohugo.io/">liste des thèmes&lt;/a> le thème qui plaît. Une fois le thème choisis, il faut l&amp;rsquo;installer dans &lt;code>themes/&amp;lt;nom du thème&amp;gt;&lt;/code> et ajouter &lt;code>theme = &amp;quot;&amp;lt;nom du thème&amp;gt;&amp;quot;&lt;/code> dans le fichier &lt;code>config.toml&lt;/code>.&lt;/p>
&lt;h4 id="installation-du-thème-cactus-plushttpsthemesgohugoiohugo-theme-cactus-plus">Installation du thème &lt;a href="https://themes.gohugo.io/hugo-theme-cactus-plus/">&lt;code>Cactus Plus&lt;/code>&lt;/a>&lt;/h4>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">&lt;span style="color:#75715e"># Récupérer le thème sur GitHub&lt;/span>
git clone https://github.com/nodejh/hugo-theme-cactus-plus themes/hugo-theme-cactus-plus
&lt;span style="color:#75715e"># Installer le bon fichier de configuration à la place de l&amp;#39;ancier&lt;/span>
cp themes/hugo-theme-cactus-plus/exampleSite/config.toml .
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="créer-un-post-sur-le-blog">Créer un post sur le blog&lt;/h3>
&lt;h4 id="en-utilisant-hugo">En utilisant Hugo&lt;/h4>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">hugo new posts/premier-post.md
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="a-la-main">A la main&lt;/h4>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$EDITOR content/posts/premier-post.md
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="metadata-sur-le-post">Metadata sur le post&lt;/h4>
&lt;p>Tout d&amp;rsquo;abord, les metadata sont ajoutée directement dans le fichier markdown grâce au separateurs &lt;code>---&lt;/code>. Cela donne un document qui commence par:&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-markdown" data-lang="markdown">---
title: &amp;#34;Creation de site avec Hugo&amp;#34;
date: 2019-11-13T15:17:21+01:00
---
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Voici une liste exhaustive des éléments que l&amp;rsquo;on peux ajouter dans les metadata:&lt;/p>
&lt;ul>
&lt;li>&lt;code>title&lt;/code>: Spécifie le nom de l&amp;rsquo;article&lt;/li>
&lt;li>&lt;code>date&lt;/code>: Explicite la date de rédaction du document&lt;/li>
&lt;li>&lt;code>url&lt;/code>: Permet de définir l&amp;rsquo;URL utilisé pour le post&lt;/li>
&lt;li>&lt;code>draft&lt;/code>: &lt;code>[true|false]&lt;/code> Permet(ou non) que le post soit visible dans un environnement de production&lt;/li>
&lt;li>&lt;code>tags&lt;/code>: Permet de définir les tags de l&amp;rsquo;article et donc permet de faire le lien entre les post.&lt;/li>
&lt;li>&lt;code>author&lt;/code>: Spécifie le nom de l&amp;rsquo;auteur&lt;/li>
&lt;li>&lt;code>meta_image&lt;/code>: Spécifie l&amp;rsquo;image qui représente l&amp;rsquo;article&lt;/li>
&lt;li>&lt;code>type&lt;/code>: Spécifie le type d&amp;rsquo;article&lt;/li>
&lt;/ul>
&lt;p>Ce qui peux donner une entête comme cela&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-markdown" data-lang="markdown">---
title: &amp;#34;Creation de site avec Hugo&amp;#34;
author: Tom Moulard
draft: false
type: post
date: 2019-11-13T15:17:21+01:00
url: /creation-de-site
categories:
&lt;span style="color:#66d9ef">-&lt;/span> Uncategorized
tags:
&lt;span style="color:#66d9ef">-&lt;/span> tutoriel
&lt;span style="color:#66d9ef">-&lt;/span> installation
&lt;span style="color:#66d9ef">-&lt;/span> hugo
meta_image: 2019/hugo-creation.png
---
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="démarrer-le-serveur-localement">Démarrer le serveur localement&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">hugo server
&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="démarrer-le-serveur-localement-avec-les-drafts">Démarrer le serveur localement avec les drafts&lt;/h4>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">hugo server -D
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="voir-le-site-web">Voir le site web&lt;/h3>
&lt;p>Il suffit maintenant d&amp;rsquo;aller voir &lt;a href="http://localhost:1313">localhost:1313&lt;/a> pour observer le travail effectué.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-bash" data-lang="bash">$BROWSER http://localhost:1313
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="paramétrage-du-site">Paramétrage du site&lt;/h2>
&lt;p>La prochaine section à pour but de modifier le fichier de configuration &lt;code>config.toml&lt;/code>.&lt;/p>
&lt;h3 id="paramètres-sur-lauteur">Paramètres sur l&amp;rsquo;auteur&lt;/h3>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-toml" data-lang="toml">&lt;span style="color:#a6e22e">author&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;&amp;lt;Nom de l&amp;#39;auteur&amp;gt;&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">description&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;&amp;lt;Description du site&amp;gt;&amp;#34;&lt;/span>
&lt;span style="color:#a6e22e">bio&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;&amp;lt;Description de l&amp;#39;auteur&amp;gt;&amp;#34;&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="disqus">Disqus&lt;/h3>
&lt;p>Il faut avoir un compte sur le site &lt;a href="https://disqus.com">Disqus&lt;/a>(ou en &lt;a href="https://disqus.com/profile/signup/">créer un&lt;/a>). Puis il faut créer un &lt;a href="https://disqus.com/admin/create/">nouveau site&lt;/a> et récupérer le nom court du site.&lt;/p>
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-toml" data-lang="toml">&lt;span style="color:#a6e22e">enableDisqus&lt;/span> = &lt;span style="color:#66d9ef">true&lt;/span>
&lt;span style="color:#a6e22e">disqusShortname&lt;/span> = &lt;span style="color:#e6db74">&amp;#34;&amp;lt;nom cours du site&amp;gt;&amp;#34;&lt;/span>
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="déploiement">Déploiement&lt;/h2>
&lt;h3 id="en-utilisant-docker-compose">En utilisant docker-compose&lt;/h3>
&lt;pre>&lt;code class="language-docker-compose" data-lang="docker-compose">hugo:
image: jojomi/hugo:latest
volumes:
- ./src/:/src
environment:
- HUGO_WATCH=true
- HUGO_REFRESH_TIME=3600
- HUGO_THEME=&amp;lt;Nom du thème&amp;gt;
- HUGO_BASEURL=mydomain.com
restart: always
&lt;/code>&lt;/pre>&lt;p>Par exemple:&lt;/p>
&lt;pre>&lt;code class="language-docker-compose" data-lang="docker-compose">hugo:
image: jojomi/hugo:latest
volumes:
- .:/src
environment:
- HUGO_WATCH=true
- HUGO_REFRESH_TIME=3600
- HUGO_THEME=hugo-theme-cactus-plus
- HUGO_BASEURL=mydomain.com
restart: always
&lt;/code>&lt;/pre>&lt;p>Puis &lt;code>docker-compose up&lt;/code>&lt;/p></description></item></channel></rss>