本記事では、Go と MySQL を用いた REST API 開発を行なっていきます。ここ最近、アーキテクチャや設計、テスト、API、ログ管理、CI/CD を勉強してきて個人的に納得できる構成が構築できるようになったため、本としてアウトプットしたいと思いました。これから、API を作成しようと考えている方の参考になれば幸いです。
Hello Actor 細かい機能の解説はあとの回として、 まずはアクターシステムを使ったプログラミングを体験してみましょう。 Goではアクターシステムが商用でも十分利用できるものは、 下記のProto Actorとergoがあります。 github.com github.com Proto.Actorは、Akka.NET のオリジナル作成者 Roger Johansson によって開発されているもので、 Akka/Pekko と基本の部分がある程度似た形になっています。 あくまで似ている程度で、現在のAkka/Pekkoほど強力なツールが揃っているわけではありませんが、 Proto Actorで概念や作り方を覚えると、少ない労力でAkk/Pekkoにも移行などもができるようになります。 細部は異なりますが、概念などはかなり似ていますのですんなり理解できるはずです。 ergoは Erlan
はじめに こんにちは、23卒でバックエンドエンジニアをしているたかしゅんです。 私の所属しているプロダクトではサーバーサイドの開発言語としてGoを採用しております。 チームでGoの勉強会をした際にあまりにもGoの流儀や綺麗な書き方を理解していなかったので、以下の書籍を読みました。 [Go言語 100Tips ありがちなミスを把握し、実装を最適化する] この書籍から得た知見、プルリクエストのレビューで受けたアドバイス、そしてコードレビュー時に意識すべき点などを基に、知識を整理し共有したいと思います。 基礎文法は理解しているけど、実際のプロダクトで何を意識して書けば良いのかわからない方に、少しでも参考になれば幸いです。 1. コード 1.1 不用意にネストしない 可読性の悪いコードには命名、一貫性、書式など様々な原因がありますが、その中の重要な原因の一つとしてネストが関係します。 よくある例と
2023 年は念願叶い業務でも趣味でも Go を触ることができました。 そんな 2023 年での Go での気づきに思いを馳せ、タスク管理をするような簡単なサーバーを構築しそのプロジェクトレイアウトをご紹介してみます。 気づきといっても読む方にとっては当たり前のことかもしれません。 また、プロジェクトレイアウトはこれが正義だとは思っていません。紹介するレイアウトは業務では使っていないです。運用などもまともにしたことはありません。私がそこそこの規模のサーバーを新規で構築するならこんな風にしようかなって記事です。 気づき interface を満たすためのコードって VSCode で自動生成できたんだ よくおまじないとかファクトリー関数の戻り値とかで構造体が interface を満たしているかどうかを確認することがあるかと思います。 package main import "context"
この記事はfreeeアドベントカレンダー2023の19日目の記事です。 こんにちは!freeeカードチームのmattsunです。freeeカードUnlimitedの開発運用をしています。私は1年前にfreeeに入社しfreeeカードチームに所属しています。これまでの自分のエンジニアとしてのキャリア(10年強)を通してみても、今のチームではPRレビューやリファクタなどからの学びが多いなぁと感じます。個人的に学びがあったことやチームとしての知見が深まったもののうち、ベスト5(私の主観)をまとめます。 freeeカードシステムは、フロントエンド(TS,React)・BFF(RoR)・Backend(Go)で構成されており、Goでの開発比率が多いことから、本記事はGoのコードに関する言及が多いです。freee社全体をみるとRailsで開発されたシステムも多いですが、Goで開発しているサービスもある
Go は Web 開発に向いているか? 最も向いている領域は「CLI ツール」「ミドルウェア」「マイクロサービス」だと思っている。なぜならそれらはコードベースを比較的小さく抑えることを前提としているからだ。 Go は大きなコードベースを抱えやすい設計の言語になっていない。 ミドルウェアとマイクロサービスに関しては小さく作ることが正義。 CLI ツールに関しては単一責務なツールであれば小さくなるが,複数を束ねるツールであっても Web サービス開発に比べれば考えることは少なくて済む。 Web 業界における「一般的な Web 開発」,すなわちモノリスを基本とした中規模以上の開発にははっきりと 向いていない と言うべきだろう。 フラットパッケージは正義か? 私が SNS で何度か言及した以下の記事がある。 フラットパッケージ戦略は,確かに Go の文化圏においては一定の支持を集めている。Go の
調べようと思ったきっかけは、golang では以下のように ローカル変数のアドレスを戻り値としても問題ないということ。 package main import ( "fmt" ) type Animal struct { Name string Age int } func main() { animal := allocAnimal() fmt.Printf("allocate animal structure %p", animal) } func allocAnimal() *Animal { return &Animal{} } C/C++ ではローカル変数のポインタを戻り値とした場合、 スタック領域のポインタを関数外に渡してしまうため、コンパイル時点で警告が表示されます (なぜエラーにしない) 実行時には最悪、セグメンテーションフォールトで落ちます そのため、malloc や n
tenntenn Conference 2022で登壇しました @tenntennです。tenntenn Conference 2022という@tenntennさんが主催するカンファレンスで登壇を行いました。ブログを書くまでがカンファレンスということでブログを書きたいと思います。 私は、本業はメルペイで働いていますが、副業として株式会社ヤプリで技術顧問をさせて頂いています。主にGoの勉強会の開催ややGoに関する相談などを受けています。 最近はコードリーディング会を行っていて、その方法が非常に良かったのでカンファレンスで紹介しました。発表資料と動画は以下のURLから確認できます。 資料:https://tenn.in/codereading 動画:https://youtu.be/5XRXubGV3tI?t=5098 気軽にコードリーディング会をしよう! ヤプリで行っているコードリーディング
Download and install go get github.com/beego/beego/[email protected] Create file hello.go package main import "github.com/beego/beego/v2/server/web" func main() { web.Run() } Build and run go build hello.go ./hello View effects Open your browser and visit http://localhost:8080 Congratulations! You just built your first beego app. Please see Documentation for going further.
依存がなく、テスト可能であり、クリーン。 Uncle Bobのクリーンアーキテクチャの概念を読んだので、これを私はGoで実装してみたいと思います。このアーキテクチャは、自分たちの会社である Kurio – App Berita Indonesia で使っていたものに似ていますが、少し違っています。大きな違いはなく、概念は一緒なのですが、フォルダ構造が違っています。 サンプルのプロジェクトとして、記事をCRUDで管理するリポジトリを https://github.com/bxcodec/go-clean-arch にpushしてあります。 * 免責条項 ここで使われているどのライブラリあるいはフレームワークも、利用を特別推奨しているものではありませんので、ご自身あるいはサードパーティによる同じ機能のものと入れ替えることが可能です。 基本的な考え方 ご存知のように、クリーンアーキテクチャで設計
同僚がGoを始める上で、案外まとまった資料が無さそうだったので書いてみることにしました。 Macでhomebrewが入っていることが前提です。事前に brew update をおこない formula を最新のものにしておくと躓くことが少ないでしょう。 Goのインストール % brew install go エントリ執筆時点では、1.6.2 が入ります。Goはメジャーバージョンが同じ場合は、後方互換が保たれているので、基本的に新しいやつを入れて問題ありません。 環境変数の設定 $GOPATH だけを決めればOKです。$GOPATH はどこでも良いのですが、ここでは $HOME/dev を $GOPATH に設定します。また、 $GOPATH/bin に $PATH も通しておきます。 export GOPATH=$HOME/dev export PATH=$GOPATH/bin:$PATH
モンキーパッチを、RubyやPythonのような動的言語のみを扱うものと思っている人は多いようですが、それは違います。コンピューターは単独では何もできないマシンで、私たちが指示を与えることで動くものなのです。それでは、Go言語の関数がどのように機能して、実行時にどのように変更することができるのかを見ていきましょう。この記事では、インテルのアセンブリの構文が多く出てきますので、アセンブリ言語を読めない方は リファレンス を使いながら読み進めてください。 もしモンキーパッチがどのように機能しているかには興味がなく、単に使えるようになればいいと思っている方はライブラリがあるので こちら をご覧ください。 注意:サンプルはgo build -gcflags=-lで作成し、インライン展開を無効にしています。この記事の内容は、アーキテクチャが64bitsで、Mac OSXやLinuxバリアントなどのU
CodeReviewComments から Go コードのレビュー時によくされるコメントについて。 gofmt gofmt またはそのスーパーセットである goimports を実行すること。goimports は gofmt に加えて import 行の修正も行う。 コメント文 http://golang.org/doc/effective_go.html#commentary を参照。宣言に対するコメントは少し冗長に見えるかもしれないけど完全な文にする。そうすれば godoc できれいに整形される。次のように説明するものの名前から始めピリオドで終える。 // A Request represents a request to run a command. type Request struct { ... // Encode writes the JSON encoding of re
gistfile1.md Setting up Vim as your Go IDE Intro I've been wanting to do a serious project in Go. One thing holding me back has been a my working environment. As a huge PyCharm user, I was hoping the Go IDE plugin for IntelliJ IDEA would fit my needs. However, it never felt quite right. After a previous experiment a few years ago using Vim, I knew how powerful it could be if I put in the time to m
GitなどのVCSからcloneしたローカルリポジトリをどう管理するのがいい感じなのか、よくわからない。なんとなく自己流でやっているが、もっといい方法を知りたい。 tl;dr - ディレクトリレイアウトをgolangの作法に合わせ、すべてのリモートリポジトリをghqを使ってcloneし、percolを使って簡単に検索できるようにしましょう。 追記: いまならpercolの代わりにpecoというツールを使うのもよいでしょう。というか、僕はそうしています。設定方法はこのエントリとほぼ同様の内容でいけると思います。 背景 そんな課題を抱えつつも、特になにかをするわけでもなく日々暮らしていた折、Rebuild: 42: When in Golang, Do as the Gophers Do (lestrrat)で@lestrratさんが、Goのお作法に、他の言語のリポジトリも含め、すべてあわせる
Go Conference 2014 spring で発表した資料。 受託開発に持ち込んだ事例紹介。 http://connpass.com/event/6370/
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く