- 投稿日:2020-01-07T13:50:32+09:00
Goの内部パッケージ関係をコミットごとに可視化する
使用したプログラム: bxcodec/go-clean-arch概要
- Goの内部パッケージの関係が複雑なプログラムは理解するのが大変
- 可視化したい
- せっかくだからコミットごとに可視化してアニメーションにしてみる
準備
コード
やったこと
- コミットログを取得
- コミットごとにコマンドを実行
- Goの内部パッケージ関係をdotファリルに出力し、gifを作成
- コミットごとのgifのサイズを揃えて、アニメーションを作成
1. コミットログを取得
git log --pretty=onelineで取得できる。
pythonでかくとres = subprocess.check_output(["git", "-C", path_dir, "log", "--pretty=oneline"])コミットのハッシュ値だけを取得したい(ハッシュ値+コメントになっている)。空白で区切って一番最初のハッシュ値だけを取得してリストにした。
2. コミットごとにコマンド実行
コミットごとにresetしてコマンドを実行した(reset以外にいい方法がある??)。
for commit in log_list: subprocess.call(["git", "-C", path_dir, "reset", "--hard", commit]) | command(path_dir)コマンドを実行するときはプログラムのあるディレクトリのパスを使用する。
3. Goの内部パッケージ関係をdotファリルに出力し、gifを作成
3.1. dotファイル作成
ここが一番難しい。
parser というとても便利なパッケージがあり、ファイル内でimportしているパッケージを取得してくれる。これをファイルごとからパッケージごとにまとめれば良い。困ったこと
- ファイルごと --> パッケージごと
parserはファイルのパッケージ名も取得してくれるが、別のディレクトリに同じパッケージ名があると区別できない。ディレクトリを保存したが、もっと簡単な方法がありそう- 外部パッケージの区別
内部パッケージ(自分で作ったもの)だけを対象にしたかったがどうやって区別すればいいか??「githubってあれば外部」みたいにしたが、あまりいい方法ではなさそう。3.2. dotファイルからgifファイル作成
graphvizを使用する。
dot -T gif sample.dot -o sample.gif4. コミットごとのgifのサイズを揃えて、アニメーションを作成
4.1. gifのサイズを揃える
アニメーションにするときファイルごとのサイズが違うと大きいサイズは切れてしまう。
mogrify -resize (width)x(height)! *.gif
指定するサイズはいい感じのを選ぶ。4.2. アニメーション作成
ImageMagickを使用する。
convert -delay 5 -loop 0 *.gif animation.gif参考にしたサイト
- Gitディレクトリ外からgitコマンドを実行する
- Pythonでsubprocessを使ってコマンドを実行する方法
- package parser
- 画像の拡大・縮小
- アニメーションGIF ImageMagick編
- st34-satoshi/for-each-commit
- st34-satoshi/call-graph
これから
コミットごとにグラフの表示位置がバラバラになってしまいアニメーションにしたとき見にくい。どうにか揃えたい。
- 投稿日:2020-01-07T08:42:34+09:00
goでSTUNサーバを使ってパブリックIPアドレスを取得
以下の記事を参考に Go の実装に置き換えてみた。
以下のパッケージ使って同等のことが割と簡単に実装できた。
Go言語楽しい。
実行結果
# go run webrtc/main.go 2020/01/06 23:31:08 Local IP Address: 192.168.xxx.xxx 2020/01/06 23:31:08 Public IP Address: 113.xxx.xxx.xxx実装
main.gopackage main import ( "log" "os" "github.com/pion/webrtc/v2" ) func main() { config := webrtc.Configuration{ ICEServers: []webrtc.ICEServer{ { URLs: []string{"stun:stun.l.google.com:19302"}, }, }, } // generate a new connection peerConnection, err := webrtc.NewPeerConnection(config) if err != nil { log.Fatal(err) } peerConnection.OnICECandidate(func(c *webrtc.ICECandidate) { if c == nil { os.Exit(0) } switch c.Typ { case webrtc.ICECandidateTypeHost: log.Println("Local IP Address:", c.Address) case webrtc.ICECandidateTypeSrflx: log.Println("Public IP Address:", c.Address) } }) if _, err := peerConnection.CreateDataChannel("", nil); err != nil { log.Fatal(err) } offer, err := peerConnection.CreateOffer(nil) if err != nil { log.Fatal(err) } if err = peerConnection.SetLocalDescription(offer); err != nil { log.Fatal(err) } // block forever select {} }
- 投稿日:2020-01-07T08:42:34+09:00
GoでSTUNサーバを使ってパブリックIPアドレスを取得
以下の記事を参考に Go の実装に置き換えてみた。
以下のパッケージ使って同等のことが割と簡単に実装できた。
Go言語楽しい。
実行結果
# go run webrtc/main.go 2020/01/06 23:31:08 Local IP Address: 192.168.xxx.xxx 2020/01/06 23:31:08 Public IP Address: 113.xxx.xxx.xxx実装
main.gopackage main import ( "log" "os" "github.com/pion/webrtc/v2" ) func main() { config := webrtc.Configuration{ ICEServers: []webrtc.ICEServer{ { URLs: []string{"stun:stun.l.google.com:19302"}, }, }, } // generate a new connection peerConnection, err := webrtc.NewPeerConnection(config) if err != nil { log.Fatal(err) } peerConnection.OnICECandidate(func(c *webrtc.ICECandidate) { if c == nil { os.Exit(0) } switch c.Typ { case webrtc.ICECandidateTypeHost: log.Println("Local IP Address:", c.Address) case webrtc.ICECandidateTypeSrflx: log.Println("Public IP Address:", c.Address) } }) if _, err := peerConnection.CreateDataChannel("", nil); err != nil { log.Fatal(err) } offer, err := peerConnection.CreateOffer(nil) if err != nil { log.Fatal(err) } if err = peerConnection.SetLocalDescription(offer); err != nil { log.Fatal(err) } // block forever select {} }
- 投稿日:2020-01-07T08:42:34+09:00
GoでSTUNサーバを使って自分のパブリックIPアドレスを取得
以下の記事を参考に Go の実装に置き換えてみた。
以下のパッケージ使って同等のことが割と簡単に実装できた。
Go言語楽しい。
実行結果
# go run webrtc/main.go 2020/01/06 23:31:08 Local IP Address: 192.168.xxx.xxx 2020/01/06 23:31:08 Public IP Address: 113.xxx.xxx.xxx実装
main.gopackage main import ( "log" "os" "github.com/pion/webrtc/v2" ) func main() { config := webrtc.Configuration{ ICEServers: []webrtc.ICEServer{ { URLs: []string{"stun:stun.l.google.com:19302"}, }, }, } // generate a new connection peerConnection, err := webrtc.NewPeerConnection(config) if err != nil { log.Fatal(err) } peerConnection.OnICECandidate(func(c *webrtc.ICECandidate) { if c == nil { os.Exit(0) } switch c.Typ { case webrtc.ICECandidateTypeHost: log.Println("Local IP Address:", c.Address) case webrtc.ICECandidateTypeSrflx: log.Println("Public IP Address:", c.Address) } }) if _, err := peerConnection.CreateDataChannel("", nil); err != nil { log.Fatal(err) } offer, err := peerConnection.CreateOffer(nil) if err != nil { log.Fatal(err) } if err = peerConnection.SetLocalDescription(offer); err != nil { log.Fatal(err) } // block forever select {} }
