golang で UPnP をサポートするルーターを検出し、ルーターの外部ポートをローカル PC の転送ポートにマップする / Detects routers that support UPnP and maps the router’s external ports to forward ports on the local PC with golang

下記のパッケージで機能が提供されています:

  • https://github.com/huin/goupnp
  • https://gitlab.com/NebulousLabs/go-upnp
  • https://gitlab.com/NebulousLabs/fastrand

gitlab.com/NebulousLabs/go-upnp は、このままでは
現在の github.com/huin/goupnp とマッチしないので
ローカルの upnp/upnp.go に必要な箇所をコピーして修正して使用しました。

最低限のソースのみ

upnp/upnp.go:

main.go:

golang でログ出力を止める / stop logging in golang

filepath and path packages

path の操作ではまった。
path の操作には2つのパッケージが使用できるですが
filepath と path
path の方知りませんでした

パスの区切り文字が違う
filepath パッケージは OS固有のものが使用され
path パッケージは “/” が使用されるとのことで

当たり前ですが、
embed パッケージで使用する path は区切りが常に “/”

vscode に golang の build tag 指定方法 / How to specify golang build tag for vscode

“staticcheck” に替わってから? vscode で golang開発する際に
下記のように build tag でソースコードの置き換えをしていると

この build tag を書いたファイルで vscode の機能が上手く働いてくれない場合がありました。チェックが厳密?正確?になったから?でしょうか。

環境変数指定で解決しました。複数指定はカンマ区切りでした…
と言うことで開発の際には環境変数をちゃんと指定しとけよってことでした。

vscode の設定で何とかするには、Goの公式拡張機能を入れて
プロジェクト内に “.vscode/settings.json” を作成してこんな感じです。

Environment variables that will be passed to the tools that run the Go tools (e.g. CGO_CFLAGS) and debuggee process launched by Delve. Format as string key:value pairs. When debugging, merged with envFile and env values with precedence env > envFile > go.toolsEnvVars.

説明に書かれている「環境ファイル」はおそらく “~/.config/go/env”

vscode の EXPLORERバーの下の方の GOセクション?の env で編集できるようです。

電子帳簿保存法なにやらで pdf ファイルが増えて何のファイルか分からなくなるので取り敢えず、自動でファイル名を変更してみるテスト / Rename the pdf receipt using pdftotext and golang

Convert JSON with comments to JSON with Golang

コメント付きの JSON (JSONC) を JSON にコンバート
JSON ファイルってコメント付けておかないとすぐになんだか分からなくなるのです。

“github.com/tidwall/jsonc” を使いました。