Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go言語のモジュール管理_完全に理解した
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
h.isoe
February 26, 2023
Programming
0
260
Go言語のモジュール管理_完全に理解した
エンジニア達の「完全に理解した」Talk #38
https://easy2.connpass.com/event/273874/
h.isoe
February 26, 2023
Tweet
Share
More Decks by h.isoe
See All by h.isoe
コードレビューで開発を止めないために
ih6109
0
80
AIを「完全に理解」するG検定合格体験記
ih6109
1
130
2022_07_14_おすすめの技術書 LT会 - vol.4_ 問題解決を仕事にする 全ての人へ
ih6109
0
120
Kotlinでサーバーレス! 「Kotless」の紹介
ih6109
1
570
2021_08_19 おすすめの技術書 LT会 - vol.2 Vue.js3超入門がとにかくやさしい
ih6109
0
22k
Other Decks in Programming
See All in Programming
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
140
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
180
Claude Code Skill入門
mayahoney
0
390
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
950
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
480
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
290
CSC307 Lecture 14
javiergs
PRO
0
470
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
590
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
240
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
220
20260315 AWSなんもわからん🥲
chiilog
2
150
クライアントワークでSREをするということ。あるいは事業会社におけるSREと同じこと・違うこと
nnaka2992
1
340
Featured
See All Featured
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Designing for Performance
lara
611
70k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.7k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
140
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
470
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
480
Exploring anti-patterns in Rails
aemeredith
2
290
Discover your Explorer Soul
emna__ayadi
2
1.1k
Everyday Curiosity
cassininazir
0
160
Transcript
Go言語のモジュール管理 完全に理解した 2023/02/23 エンジニア達の「完全に理解した」Talk #38 磯江 宏由紀
自己紹介 名前:磯江 宏由紀 所属:虎の穴ラボ株式会社 クリエイター支援プラットフォーム開発 読んでいる書籍:「教養としての決済」 決済周りの開発をしたことがあったので興味を惹かれた 決済にまつわる歴史や雑学的が楽しい
サンプルにするプロジェクト エンジニア達の「〇〇完全に理解した」Talk #33で話した GolangでOGP用に画像を作る自作プログラム https://github.com/HiroyukiIsoe/golang-image-util • 画像の読み込み、保存 ◦ 標準モジュール+α •
画像をぼかす、文字を書き込む ◦ 外部モジュール • 画像をS3に保存する ◦ 自作モジュール(外部モジュールのラッパー)
Go言語のモジュール管理 • Go Module ◦ Go1.11からサポートされたモジュール管理方法 ◦ モジュールの初期化は以下コマンド ▪ go
mod init “モジュール名” • GOPATH ◦ Go1.10以前利用していたモジュール管理方法 ◦ 昔の情報を漁っていることがあるので注意
Go言語のモジュールを管理で利用するファイル モジュール管理に利用しているファイルは以下2つ • go.mod ◦ モジュールも依存関係やバージョン情報を記録しているファイル • go.sum ◦ チェックサムを記録しているファイル
ライブラリ改ざんなどを検知できるが、個人開発の規模だと気にすることはない
go.mod 自分自身のモジュール名→ Go言語のバージョン→ → 依存モジュールのパスと バージョン module image-util go 1.19
require ( github.com/aws/aws-sdk-go-v2 v1.17.3 github.com/aws/aws-sdk-go-v2/config v1.18.10 github.com/aws/aws-sdk-go-v2/service/s3 v1.30.1 github.com/esimov/stackblur-go v1.1.0 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 )
モジュールの利用:標準モジュール モジュールを扱うときは「import」を利用し てモジュールを読み込む。 今回は標準モジュール「fmt」をつかって標 準出力に「Hello World」と表示している。 package main import "fmt"
func main() { fmt.Println("Hello World") }
package s3 import ( =(中略)= "github.com/aws/aws-sdk-go-v2/service/s3" ) var client *s3.Client
func init() { cfg, err := config.LoadDefaultConfig(context.TODO()) if err != nil { log.Fatal(err) } client = s3.NewFromConfig(cfg) } モジュールの利用:外部モジュール 利用したいモジュールを「go get」コマンド などで取得した後、 標準モジュールの利用と同様に 「import」を利用して読み込む。 サンプルは自作モジュール。 golang-image-util ┗internal ┗s3 ┗s3.go
モジュール利用:自作モジュール package main import ( =(中略)= "image-util/internal/s3" =(中略)= ) =(略)=
go.modで定義した自分自身のモジュール 名から始める必要がある以下に依存して いるわけではない • ディレクトリ名 • 相対的なパス 自分が「go mod init image-util」としていた ことを忘れていた(1敗)
まとめ • Go言語のパッケージ管理は「GoModule」で行っている • go.modファイルで依存関係を管理 • 自作モジュールを読み込むときには、自身のモジュール名を要確認
おわり