<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kota on Medium]]></title>
        <description><![CDATA[Stories by Kota on Medium]]></description>
        <link>https://medium.com/@yagikota?source=rss-d56f72b03f9a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rvFmQq_VTzqWIfEolK5dyg.jpeg</url>
            <title>Stories by Kota on Medium</title>
            <link>https://medium.com/@yagikota?source=rss-d56f72b03f9a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:43:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yagikota/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[3 Lessons from My First Year: Maximizing Impact and Growth]]></title>
            <link>https://yagikota.medium.com/3-lessons-from-my-first-year-maximizing-impact-and-growth-fe712aaf1fd2?source=rss-d56f72b03f9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe712aaf1fd2</guid>
            <category><![CDATA[questions]]></category>
            <category><![CDATA[mindset]]></category>
            <category><![CDATA[growth]]></category>
            <category><![CDATA[delegation]]></category>
            <category><![CDATA[impact]]></category>
            <dc:creator><![CDATA[Kota]]></dc:creator>
            <pubDate>Fri, 11 Apr 2025 15:07:51 GMT</pubDate>
            <atom:updated>2025-04-11T15:07:51.634Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AtElURtOiOdPKi-Ja007rw.png" /><figcaption>Article thumbnail made by author</figcaption></figure><h3>Introduction</h3><p>This document explores <strong>three critical lessons</strong> learned during my first year as a Software Engineer (SRE). Based on both personal experience and research-backed strategies, these insights are designed to support <strong>not only engineers but also designers, business professionals</strong>. By applying these lessons, early-career professionals can navigate their initial year with confidence, establish a strong foundation for career growth, and maximize their impact within their organizations.</p><h3>Focus on High-Impact, Low-Effort Tasks: The Power of Quick Wins</h3><h4>Understanding Quick Wins</h4><p>“Quick wins” refer to strategies or actions that can achieve <strong>significant results quickly with relatively little effort</strong>. This concept is particularly valuable during your first year as it allows you to demonstrate value promptly while building confidence and momentum. Quick wins create visible outcomes that not only advance organizational goals but also establish your credibility early.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4KYFqC3m81h93AzquT9lVg.png" /><figcaption>(ref. <a href="https://www.bitesizelearning.co.uk/resources/impact-vs-effort-matrix-explanation-template">Impact vs. effort matrix | A 2x2 template for prioritising tasks — BiteSize Learning</a>)</figcaption></figure><p>These early successes serve multiple purposes: they provide visible evidence of your capabilities, boost your professional confidence, and generate positive momentum that can carry forward into more complex initiatives. For example, improving the CI/CD pipeline might be a relatively straightforward task that yields immediate productivity improvements and demonstrates your problem-solving abilities.</p><h4>Applying the 80–20 Rule to Task Management</h4><p>The Pareto Principle, commonly known as the 80–20 rule, complements the “Quick Wins” approach by suggesting that <strong>80% of outcomes typically result from 20% of inputs</strong>. In your first year, identifying which activities generate the most significant results and focusing your energy accordingly can dramatically increase your effectiveness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9rT_0BXBSnNqe1dsavbVg.png" /><figcaption>(ref. <a href="https://asana.com/resources/pareto-principle-80-20-rule">Learn the Pareto Principle (The 80/20 Rule) [2025] • Asana</a>)</figcaption></figure><p>By applying this principle, you can <strong>focus on the vital few tasks that drive the majority of results rather than dispersing your efforts across numerous less impactful activities</strong>. This focused approach not only improves efficiency but also ensures maximum return on your invested time and energy.</p><h3>Ask Many Questions: Leveraging Your First Year Learning Opportunity</h3><p>Your first year represents a unique window of opportunity for learning and relationship building. During this period, asking thoughtful questions is <strong>not only expected but can significantly accelerate your professional development and integration into the team</strong>.</p><h4>The First Year as a Golden Period</h4><p>The initial year in a new position is comparable to <strong>having temporary invincibility — similar to the star power-up in Mario games</strong>. During this time, your colleagues and supervisors typically expect and encourage questions as part of your onboarding and development process. This period offers a unique opportunity to establish your reputation as someone who is engaged, curious, and committed to understanding the organization’s operations and culture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubc0hxwgYslpSQYZq81p1Q.png" /><figcaption>(ref. <a href="https://www.nintendo.com/jp/switch/aqmxa/powerup/index.html">スーパーマリオブラザーズ ワンダー : アイテムでパワーアップ | Nintendo Switch | 任天堂</a>)</figcaption></figure><p>Taking full advantage of this golden period requires recognizing its temporary nature and maximizing the learning opportunities it presents. <strong>Questions asked during this time are generally viewed as signs of engagement rather than indicators of incompetence</strong>, making it the ideal moment to address fundamental aspects of your role and the organization — although, of course, <strong>asking questions should always be seen as a positive behavior, not limited to just the first year</strong>.</p><h4>Building Relationships Through Thoughtful Inquiry</h4><p>Asking questions serves as <strong>a powerful relationship-building tool.</strong> By approaching colleagues with thoughtful inquiries, you demonstrate respect for their expertise while creating opportunities for meaningful interaction. <strong>This approach helps establish you as approachable and collaborative, key traits that contribute to positive workplace relationships</strong>.</p><p>When you ask questions thoughtfully, you signal your interest in understanding others’ perspectives and experiences. <strong>This open-minded attitude creates stronger professional connections and helps you build a supportive network within your organization</strong>. Additionally, it creates the <strong>impression that you’re easy to work with</strong> — a reputation that can prove invaluable throughout your career.</p><h4>Accept Feedback as a Valuable Gift with Open Arms</h4><p><strong>Feedback represents one of the most important types of information you can seek during your first year</strong>. Viewing feedback as a gift rather than criticism creates a mindset conducive to growth and improvement. Research indicates that employees who actively engage in giving and receiving feedback tend to be more involved in the workplace overall.</p><p>The benefits of feedback are multifaceted: it inspires <strong>personal and professional growth</strong> by offering new perspectives on how your behavior impacts others; it provides <strong>a sense of purpose</strong> by highlighting the significance of your contributions; and it helps build <strong>strong relationships</strong> through open communication channels. Seeking regular feedback during your first year establishes a pattern of continuous improvement that can serve you throughout your career.</p><h3>Enabling Other Members: The Path to Higher-Level Contributions</h3><p>As you establish yourself in your role, one of the most powerful ways to <strong>increase your impact is by transitioning from handling all tasks personally to enabling and developing others</strong>. This shift allows you to focus on higher-level contributions while building team capacity.</p><h4>Moving Beyond Solo Performance by Delegating</h4><p>While demonstrating individual capability is important during your early tenure, long-term success often depends on your ability to <strong>multiply your impact through others</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zOk0y-KNpkzrcEtGbgRzTQ.png" /><figcaption>The Power of Delegation</figcaption></figure><p>Delegating tasks and empowering other members can lead to increased efficiency and personal growth within the team or the organization. According to the <a href="https://online.hbs.edu/blog/post/how-to-delegate-effectively">How to Delegate Effectively: 9 Tips for Managers</a>, the effective delegation includes:</p><ol><li><strong>Know What to Delegate</strong><br>Focus on tasks that others can do, freeing you up for higher-impact work (<strong>Quick Wins concept can be applied here as well</strong>)</li><li><strong>Play to Your Employees’ Strengths and Goals</strong><br>Assign tasks that align with their skills and help them grow</li><li><strong>Define the Desired Outcome</strong><br>Clearly communicate what success looks like from the start</li><li><strong>Provide the Right Resources and Level of Authority</strong><br>Equip them with the tools and decision-making power they need</li><li><strong>Establish a Clear Communication Channel</strong><br>Set up a way to check in and address questions without micromanaging</li><li><strong>Allow for Failure</strong><br>Create a safe space for mistakes as part of the learning process</li><li><strong>Be Patient</strong><br>Give time and space for learning and ownership to develop</li><li><strong>Deliver (and Ask For) Feedback</strong><br>Share constructive input and welcome feedback to improve delegation</li><li><strong>Give Credit Where It’s Due</strong><br>Acknowledge and celebrate their contributions publicly</li></ol><h4>Teaching as a Path to Leadership</h4><p>Taking the time to teach others is an investment that yields returns at multiple levels. When you share your knowledge and skills, <strong>you help colleagues develop new capabilities as well as deepen your own understanding</strong>. The act of explaining processes often reveals insights that might otherwise remain unconscious.</p><p>Moreover, teaching others demonstrates leadership potential and commitment to organizational success beyond your individual performance. <strong>This approach aligns with the concept of feedback as a gift — by providing guidance and instruction, you’re offering valuable input that helps others grow professionally</strong>. The relationships built through these teaching interactions also strengthen your professional network and establish you as a valuable resource within the organization.</p><h3>Conculusion</h3><p>These three lessons — <strong>focusing on quick wins, asking questions during your golden period</strong>, and <strong>enabling other members</strong> — form a powerful framework for maximizing your impact during your first year.</p><ol><li><strong>Focus on Quick Wins</strong><br>Strategically prioritize high-impact, low-effort tasks to quickly demonstrate value and build momentum.</li><li><strong>Ask Questions During Your Golden Period</strong><br>Use your unique newcomer status to ask questions and seek feedback, accelerating learning and building strong relationships.</li><li><strong>Enable Other Members</strong><br>Shift from individual contributions to empowering your team, multiplying your impact, and preparing for higher-level responsibilities.</li></ol><p>By implementing these lessons thoughtfully during your first year, I hope you establish patterns of success that can serve you throughout your career</p><h3>References</h3><ul><li><a href="https://asana.com/resources/pareto-principle-80-20-rule">Understanding the Pareto principle (The 80/20 rule)</a></li><li><a href="https://www.humentic.com/articles/a-guide-for-effective-delegation-empowering-your-team-for-success?utm_source=chatgpt.com">A Guide for Effective Delegation: Empowering Your Team for Success | Leadership Development and Management Training Resources</a></li><li><a href="https://your.yale.edu/ct-scene-feedback-gift-keeps-giving">C&amp;T Scene: Feedback is a gift that keeps on giving | It’s Your Yale</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe712aaf1fd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[GitHub Actions]Draft Pull RequestでのCI無効化方法]]></title>
            <link>https://techblog.finatext.com/github-actions-how-to-disable-ci-in-draft-pull-requests-5989a228afaf?source=rss-d56f72b03f9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5989a228afaf</guid>
            <category><![CDATA[draft-pull-request]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[ci]]></category>
            <category><![CDATA[internship-experience]]></category>
            <dc:creator><![CDATA[Kota]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 00:41:57 GMT</pubDate>
            <atom:updated>2023-04-03T00:41:57.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZKWs5l8nqn1RrqC9" /><figcaption>Photo by <a href="https://unsplash.com/es/@richygreat?utm_source=medium&amp;utm_medium=referral">Richy Great</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>💡はじめに</h3><p>こんにちは、Finatextグループでサーバーサイドエンジニアの長期インターンをしている<a href="https://twitter.com/88888888_kota">@88888888_kota</a>です。</p><p>インターンでは、「<a href="https://www.goalnavi.com/">Goal Navi</a>」という投資一任運用サービスのバックエンド開発に携わっています。</p><p>先日、migrationファイルに変更があった際にDB schema documentを修正するCIを実装しました。そこで、PRを一旦Draft状態で上げたのですが、CIが回るような設定になっていました。</p><p>Draft Pull Request(以下、Draft PR)を用いたコード共有は一般的ですが、特別な設定をしない限りCIが回ってしまいます。Draft PRはWIP(作業中)であることを示すために使われることが多く、その場合、CIが回ることはコスト面で無駄になります。また、Draft PRを作成した際に複数のCIが回ってしまうと「とりあえずDraft PRでコード共有して実装の方向性を確認する」といったようなフローを気軽に行うことが難しくなり、そのせいで出戻りが発生しうることもあるかと思います。</p><p>そこで、コスト削減目的だけでなくPRのハードルを下げる目的で、Draft PRでのCI無効化をチームに提案し、実装を行いました。</p><p>この記事では、その実装方法について説明します。</p><h3>🛠 実装</h3><h4>検証及び説明</h4><p><strong>まず、下記ファイルの挙動について説明します。</strong></p><pre>on:<br>  push:<br>    branches:<br>      - main<br>  pull_request:<br>jobs:<br>  echo:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Greeting<br>        run: echo &quot;Hello World&quot;<br>      - name: Greeting<br>        run: echo &quot;Goodbye World&quot;</pre><p>1. 単純にDraft PRを上げてみると、以下のようにCI(on.pull_request)が実行されます。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A5I0u6AUlQdQZMMy52xnCw.png" /></figure><p>2. 上記の状態からReady for reviewにしてみるとその瞬間はCIは実行されません。</p><p>3. 適当にcommitしてみるとCI(on.pull_request)が実行されます。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o761wb-xN_QlhhPoSxjBnQ.png" /></figure><p>4. mergeするとCI(on.push)が実行されます。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4o66K7E3cad_-nwaWTgAnw.png" /></figure><p>というのが現状のコードでの挙動です。</p><p>最終的に期待する挙動としては以下になります。</p><ul><li>1の場合はCIは実行ない</li><li>2, 3, 4の場合にのみCIが実行される</li></ul><p><strong>次に、トリガーにready_for_reviewを追加してみます。</strong></p><pre>on:<br>  push:<br>    branches:<br>      - main<br>  pull_request:<br>    types:<br>      - ready_for_review # 追記<br>jobs:<br>  echo:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Greeting<br>        run: echo &quot;Hello World&quot;<br>      - name: Greeting<br>        run: echo &quot;Goodbye World&quot;</pre><p>1. 単純にDraft PRを上げてみると、以下のようにCIが実行されません。(期待通り)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLMfsbPcj6DN3BmpGOXhRw.png" /></figure><p>2. 上記の状態からReady for reviewにしてみると、その瞬間はCI(on.pull_request)は実行されます。(期待通り)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sWnScduLRH7cT2etR9vivg.png" /></figure><p>3. 適当にcommitしてみるとCIが実行されません。(ダメ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0oGYJCJ45VrWTpWzoMOZPQ.png" /></figure><p>4. mergeするとCI(on.push)が実行されます。(期待通り)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Mbe1wR7hjrBVEbCtHgA7A.png" /></figure><p>結果、このコードだと、</p><ul><li>Draft→Ready for reviewに変更した時のみCIが回る</li><li>Ready for reviewに変更後commitしてもCI回らない(ダメ)</li></ul><p>となります。</p><p><strong>そこでトリガーを修正し、さらにif: github.event.pull_request.draft == falseを追記します。</strong></p><pre>on:<br>  push:<br>    branches:<br>      - main<br>  pull_request:<br>    types:<br>      - opened # default<br>      - reopened # default<br>      - synchronize # default<br>      - ready_for_review<br>jobs:<br>  echo:<br>    if: github.event.pull_request.draft == false # 追記<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Greeting<br>        run: echo &quot;Hello World&quot;<br>      - name: Greeting<br>        run: echo &quot;Goodbye World&quot;</pre><p>1. 単純にDraft PRを上げてみると、以下のようにCIがskipされます。(期待通り)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jDFPNf_EA1D1aOJu8vgM2Q.png" /></figure><p>2. 上記の状態からReady for reviewにしてみるとその瞬間はCIは実行されます。(期待通り)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*srSgcQBSAi52pqy4Bgu6Eg.png" /></figure><p>3. 適当にcommitしてみるとCI(on.pull_request)が実行されます。(期待通り)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8YW4NhB8QzF-ltcj_9jfRw.png" /></figure><p>4. mergeするとCI(on.push)が実行されます。(期待通り)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lqYWhwuIPePtjZIASC_rvA.png" /></figure><h4>検証のまとめ</h4><pre>on:<br>  pull_request:<br>    types:<br>      - ready_for_review</pre><ul><li>draft→ready for reviewに変更した時のみCIが回る</li><li>ready for reviewに変更後commitするとCIが回る</li></ul><pre>jobs:<br>  [job name]:<br>    if: github.event.pull_request.draft == false</pre><ul><li>draft状態でPR送るとjobがスキップされる</li><li>draft→ready for reviewに変更した瞬間はCI回らない</li><li>ready for reviewに変更後commitするとCI回る</li></ul><pre>on:<br>  pull_request:<br>    types:<br>      - opened # default<br>      - reopened # default<br>      - synchronize # default<br>      - ready_for_review # 必要<br><br>jobs:<br>  [job name]:<br>    if: github.event.pull_request.draft == false # 必要<br>    # some steps</pre><ul><li>draft状態でPR送るとjobがスキップされる</li><li>draft→ready for reviewに変更した瞬間はCI回る</li><li>ready for reviewに変更後commitするとCI回る</li></ul><h3>🍀 補足</h3><p>以上、Draft PRでCIを回さないようにする設定方法を検証コードと共に紹介させていただきました。</p><p>補足ですが、Draft PR時のCI無効化以外にも、以下のような設定はCIの稼働削減に効果的だと思われます。</p><ul><li>特定のファイルやディレクトリが変更されたときのみ(pathsで対象を絞る)</li><li>特定のブランチに対してのみ(branchesを指定)</li></ul><h3>📖参考文献</h3><ul><li><a href="https://docs.github.com/en/actions">https://docs.github.com/en/actions</a></li></ul><h3>📢さいごに</h3><p>Finatextグループでは、SaaS型金融基幹システムの大規模API開発に取り組んでいただけるエンジニアを募集しております！「組込型金融（エンベデッドファイナンス）」の実装を加速させ、「金融がもっと暮らしに寄り添う世の中」を一緒に実現しましょう！</p><p><strong>▼Finatext開発チーム 採用情報</strong></p><p><a href="https://finatext.notion.site/Finatext-cd4ff36fb8bd4aa78a7835565c655396">Finatext 開発チーム 採用情報</a></p><p><strong>▼募集一覧（インターンも常時募集中です！）</strong></p><p><a href="https://herp.careers/v1/finatexthd">株式会社Finatextホールディングス の全ての求人一覧</a></p><p><strong>▼カジュアル面談の応募フォーム</strong><br><a href="https://forms.gle/r69LwG3cLAjiGvY66">https://forms.gle/r69LwG3cLAjiGvY66</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5989a228afaf" width="1" height="1" alt=""><hr><p><a href="https://techblog.finatext.com/github-actions-how-to-disable-ci-in-draft-pull-requests-5989a228afaf">[GitHub Actions]Draft Pull RequestでのCI無効化方法</a> was originally published in <a href="https://techblog.finatext.com/">The Finatext Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Architecture with Go]]></title>
            <link>https://yagikota.medium.com/clean-architecture-with-go-25fb42a5a2c5?source=rss-d56f72b03f9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/25fb42a5a2c5</guid>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[echo]]></category>
            <category><![CDATA[sqlboiler]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Kota]]></dc:creator>
            <pubDate>Wed, 23 Nov 2022 11:42:13 GMT</pubDate>
            <atom:updated>2022-11-23T11:44:10.304Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s create a template repository of clean architecture using Go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*TfvX7n-OwzwpQuZ918r4ig.jpeg" /></figure><h3>💡 Introduction</h3><p>This article is a summary of the findings of someone who has studied Clean Architecture and Go for about six months. The target of readers in this post is who:</p><ul><li>know the basic idea of Clean Architecture, but don&#39;t know how to implement it with Go.</li></ul><p>I can’t say that I fully understand it, but I have accumulated some knowledge, so I’ll summarize it here. I hope this will be helpful for those who want to implement Clean Architecture with Go.</p><h4>🤔 What is Clean Architecture?</h4><p>One of the system design guidelines</p><p>pros</p><ul><li>flexible because of loose coupling and separation of interests</li><li>easy to test</li></ul><p>cons</p><ul><li>code is reductant and difficult to read</li></ul><h4>🛠 Implementation</h4><p>It may be difficult to understand the idea of clean architecture by reading articles on the Internet, so the best way to understand it is to<strong> actually implement</strong> it or read the <strong>actual code</strong>. The following repositories helps you to catch up(There are many other sample repositories on Github, so you can <a href="https://github.com/search?q=go+clean+architecture">check them out</a>).</p><ul><li><a href="https://github.com/bxcodec/go-clean-arch">GitHub - bxcodec/go-clean-arch: Go (Golang) Clean Architecture based on Reading Uncle Bob&#39;s Clean Architecture</a></li><li><a href="https://github.com/zhashkevych/go-clean-architecture">GitHub - zhashkevych/go-clean-architecture: 👨‍💻 REST API example, built by following Uncle Bob&#39;s clean architecture principles</a></li><li><a href="https://github.com/eminetto/clean-architecture-go-v2">GitHub - eminetto/clean-architecture-go-v2: Clean Architecture sample</a></li></ul><h4>Goal</h4><p>The Goal in this article is to create template repository of clean architecture using Go. I think having the template will be usefule for some future study. Here is the full code:</p><p><a href="https://github.com/yagikota/clean_architecture_with_go">GitHub - yagikota/clean_architecture_with_go: This is a sample API buil by Go(echo) and SQLBoiler according to Clean Architecture.</a></p><h4>Tech</h4><ul><li>Go</li><li>MySQL</li><li>echo</li><li>SQLBoiler</li></ul><h4><strong>What we implement</strong></h4><p>We will create a simple API to retrieve student information. Check out the API document by pasting <a href="https://github.com/yagikota/clean_architecture_with_go/blob/main/api_doc.yml">this</a> into <a href="https://editor.swagger.io/">https://editor.swagger.io/</a>.</p><h4>Prepare code</h4><ul><li>incomplete code for implementing by yourself</li></ul><pre>git clone -b develop git@github.com:yagikota/clean_architecture_with_go.git</pre><ul><li>full code</li></ul><pre>git clone git@github.com:yagikota/clean_architecture_with_go.git</pre><ul><li>folder structure:</li></ul><pre>pkg<br>├── adapter<br>│   └── http<br>│       ├── health_check.go<br>│       ├── router.go // Register endpoints.<br>│       └── student_handler.go // Implement handlers.<br>├── config<br>│   └── config.go // Implement load func of environment variables.<br>├── domain<br>│   ├── model // Modles are auto generated by SQLBoiler.<br>│   │   ├── boil_queries.go<br>│   │   ├── boil_table_names.go<br>│   │   ├── boil_types.go<br>│   │   ├── boil_view_names.go<br>│   │   ├── mysql_upsert.go<br>│   │   └── students.go<br>│   ├── repository // Define DB operations by interface.<br>│   │   └── student_repository.go<br>│   └── service // Bridge between repository and usecase.<br>│       └── student_service.go<br>├── infra<br>│   ├── db_conn.go // Make a connection to the DB.<br>│   └── mysql<br>│       └── mysql.go // Implement specifuc operations to DB <br>|                       defined in domain/repository.<br>└── usecase<br>    ├── model // Convert(abstract) auto generated modles.<br>    │   └── student.go<br>    └── student_usecase.go // Implement some logics.</pre><p>If you clone incomplete code, one API is already implemented. So, when you build API then access http://localhost:8080/v1/students .</p><pre>[<br>   {<br>       &quot;id&quot;: 1,<br>       &quot;name&quot;: &quot;Yamada Ichirou&quot;,<br>       &quot;age&quot;: 22,<br>       &quot;class&quot;: 1<br>   },<br>   {<br>       &quot;id&quot;: 2,<br>       &quot;name&quot;: &quot;Yamada Jirou&quot;,<br>       &quot;age&quot;: 22,<br>       &quot;class&quot;: 1<br>   },<br> ...<br>   {<br>       &quot;id&quot;: 10,<br>       &quot;name&quot;: &quot;Yamada Jurou&quot;,<br>       &quot;age&quot;: 21,<br>       &quot;class&quot;: 4<br>   }<br>]</pre><p>will return. In the following, we will add APIs to the current code. In the process, we will also take a deep dive on code.</p><h4>Coding</h4><p><strong>repository layer</strong></p><p>First, we implement pkg/domain/repository/student_repository.go .</p><pre>package repository<br><br>import (<br> &quot;context&quot;<br><br> &quot;github.com/yagikota/clean_architecture_wtih_go/pkg/domain/model&quot;<br>)<br><br>// I presents interface.<br>type IStudentRepository interface {<br> SelectAllStudents(ctx context.Context) (model.StudentSlice, error)<br> SelectStudentByID(ctx context.Context, id int) (*model.Student, error) // add<br>}</pre><p>In this layer, we define minimum operations to each DB table by interface. So, in this time, we define two operations( SelectAllStudents, SelectStudentByID) and do not write specific operations(they are written in in pkg/infra/mysql/mysql.go).</p><p>To explain interface, it is a manual(specifications).</p><pre>// manual<br>type IDummy interface {<br> Method1() // condition1<br> Method2() // condition2<br>}</pre><p>For example, above interface presents IDummy manual. In this time, IStudentRepository means:</p><pre>manual of IStudentRepository<br>* IStudentRepository have the following methods.<br>  * SelectAllStudents(ctx context.Context) (model.StudentSlice, error)<br>  * SelectStudentByID(ctx context.Context, id int) (*model.Student, error)</pre><p>The merits of using interface will be mentioned in the next chapter.</p><p><strong>infra layer</strong></p><p>Second, we implement pkg/infra/mysql/mysql.go.</p><pre>type studentRepository struct {<br> DB *sql.DB<br>}<br><br>func NewRoomRepository(db *sql.DB) repository.IStudentRepository {<br> return &amp;studentRepository{<br>  DB: db,<br> }<br>}<br><br>func (sr *studentRepository) SelectAllStudents(ctx context.Context) (model.StudentSlice, error) {<br> // specific operation<br> return model.Students().All(ctx, sr.DB)<br>}<br><br>// add<br>func (sr *studentRepository) SelectStudentByID(ctx context.Context, studentID int) (*model.Student, error) {<br> // specific operation<br> whereID := fmt.Sprintf(&quot;%s = ?&quot;, model.StudentColumns.ID)<br> return model.Students(<br>  qm.Where(whereID, studentID),<br> ).One(ctx, sr.DB)<br>}</pre><p>In this layer, we implement specific operation. In this case, we add concrete process of FindStudentByIDthat we added in the repository layer. Then, *studentRepositorywill satisfy IStudentRepositorydefined in pkg/domain/repository/student_repository.go. Therefore, it can be said that the infra and the repository layer are connected based on the manual called IStudentRepository. In this way, by connecting each layer based on the interface, sparse coupling (as long as the interface is satisfied, processing in one layer can be implemented without worrying about processing in the other layer) can be realized. Testing is also easier because you only need to focus on the layer in front of you.</p><p><strong>service layer</strong></p><p>Next, we implement pkg/domain/service/student_service.go.</p><pre>package service<br><br>import (<br> &quot;context&quot;<br><br> &quot;github.com/yagikota/clean_architecture_wtih_go/pkg/domain/model&quot;<br> &quot;github.com/yagikota/clean_architecture_wtih_go/pkg/domain/repository&quot;<br>)<br><br>type IStudentService interface {<br> FindAllStudents(ctx context.Context) (model.StudentSlice, error)<br> FindStudentByID(ctx context.Context, id int) (*model.Student, error)<br>}<br><br>type studentService struct {<br> repo repository.IStudentRepository<br>}<br><br><br>func NewStudentService(sr repository.IStudentRepository) IStudentService {<br> return &amp;studentService{<br>  repo: sr,<br> }<br>}<br><br>func (ss *studentService) FindAllStudents(ctx context.Context) (model.StudentSlice, error) {<br> return ss.repo.SelectAllStudents(ctx)<br>}<br><br>// add<br>func (ss *studentService) FindStudentByID(ctx context.Context, id int) (*model.Student, error) {<br> return ss.repo.SelectStudentByID(ctx, id)<br>}</pre><p>In this layer, we implement the processes that combines operations of the repository layers. In this case, we receive process from repository layer to usecase layer.</p><p><strong>usecase layer</strong></p><p>Next, we implement pkg/usecase/student_usecase.go.</p><pre>import (<br> &quot;context&quot;<br> &quot;github.com/yagikota/clean_architecture_wtih_go/pkg/usecase/model&quot;<br>&quot;github.com/yagikota/clean_architecture_wtih_go/pkg/domain/service&quot;<br>)<br><br>type IStudentUsecase interface {<br> FindAllStudents(ctx context.Context) (model.StudentSlice, error)<br> FindStudentByID(ctx context.Context, id int) (*model.Student, error) // 追加<br>}<br><br>type studentUsecase struct {<br> svc service.IStudentService<br>}<br><br>func NewUserUsecase(ss service.IStudentService) IStudentUsecase {<br> return &amp;studentUsecase{<br>  svc: ss,<br> }<br>}<br><br>func (su *studentUsecase) FindAllStudents(ctx context.Context) (model.StudentSlice, error) {<br> msSlice, err := su.svc.FindAllStudents(ctx)<br> if err != nil {<br>  return nil, err<br> }<br><br> sSlice := make(model.StudentSlice, 0, len(msSlice))<br> for _, ms := range msSlice {<br>  sSlice = append(sSlice, model.StudentFromDomainModel(ms))<br> }<br><br> return sSlice, nil<br>}<br><br>// add<br>func (su *studentUsecase) FindStudentByID(ctx context.Context, id int) (*model.Student, error) {<br> ms, err := su.svc.FindStudentByID(ctx, id)<br> if err != nil {<br>  return nil, err<br> }<br><br> return model.StudentFromDomainModel(ms), nil<br>}</pre><p>In this layer, we convert data from service layer and pass it to adaptor layer. In this case, StudentFromDomainModel(ms) converts data and the logic is written in pkg/usecase/student_usecase.go.</p><p><strong>adapter layer</strong></p><p><strong>handler</strong></p><p>Next, we implement pkg/adapter/http/student_handler.go.</p><pre>type studentHandler struct {<br> usecase usecase.IStudentUsecase<br>}<br><br>func NewStudentHandler(su usecase.IStudentUsecase) *studentHandler {<br> return &amp;studentHandler{<br>  usecase: su,<br> }<br>}<br><br>func (sh *studentHandler) FindAllStudents() echo.HandlerFunc {<br> return func(c echo.Context) error {<br>  ctx := c.Request().Context()<br>  student, err := sh.usecase.FindAllStudents(ctx)<br>  if err != nil {<br>   return c.JSON(http.StatusInternalServerError, err.Error())<br>  }<br>  return c.JSON(http.StatusOK, student)<br> }<br>}<br><br>func (sh *studentHandler) FindStudentByID() echo.HandlerFunc {<br> return func(c echo.Context) error {<br>  ctx := c.Request().Context()<br>  studentID, err := strconv.Atoi(c.Param(&quot;student_id&quot;))<br>  if err != nil {<br>   return c.JSON(http.StatusBadRequest, err.Error())<br>  }<br>  student, err := sh.usecase.FindStudentByID(ctx, studentID)<br>  if err != nil {<br>   return c.JSON(http.StatusInternalServerError, err.Error())<br>  }<br>  return c.JSON(http.StatusOK, student)<br> }<br>}</pre><p>In the rooter of this layer, we register endpoints and inject dependency(DI).</p><pre>mySQLConn := infra.NewMySQLConnector()<br>studentRepository := mysql.NewStudentRepository(mySQLConn.Conn)<br>studentService := service.NewUserService(studentRepository)<br>studentUsecase := usecase.NewUserUsecase(studentService)<br>handler := NewStudentHandler(studentUsecase)</pre><p>The above part is DI.</p><pre>studentRepository := mysql.NewStudentRepository(mySQLConn.Conn)<br>studentService := service.NewUserService(studentRepository)<br>studentUsecase := usecase.NewUserUsecase(studentService)<br>handler := NewStudentHandler(studentUsecase)</pre><p>In Clean Architecture, there is a dependancies like this: handler→usecase→service→repository ,</p><p>we need usecase when initializing handler, service when initializing usecase and repository when initializing service. When initializing them, we use NewXXX function(constructor) implemented each file. In other words, the handler is created by calling the constructors defined in each layer and passed to the subsequent process(the image is to create a matryoshka🪆 in the handler, open one 🪆, pass it to usecase, and pass it to serivice, repository in the same way). By using constructor which returned value is interface, each layer can be connected by interface, enabling loose coupling.</p><h3>🍀 conclusion</h3><p>What do you think? Perhaps some of you found it helpful, and some of you did not find it helpful at all. Also, the contents of this article may not be correct. Therefore, I think it is important to read various articles and sample codes, and to actually try your hand at it. I would appreciate it if you could point out any mistakes. I will correct them accordingly 😀.</p><p><a href="https://zenn.dev/88888888_kota/articles/1a5caac8d743b8">JP Ver</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25fb42a5a2c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>