Go Wiki: よく知られた構造体タグ

背景

Goには、リフレクションを介して検出可能な構造体タグがあります。これらは、標準ライブラリのJSON/XMLやその他のエンコーディングパッケージで幅広く利用されています。

コミュニティはこれらを歓迎し、以来、ORM、さらなるエンコーディング、フラグパーサーなどを構築してきました。特にこれらのタスクでは、データ構造のシングルソース化が有益です。

問題の説明

Go、ひいてはGoの構造体タグの使用が増加したため、競合が避けられなくなっています。

解決策

以下のリストは、公開されているパッケージで使用されているよく知られた構造体タグを文書化するための最善の努力です。

リストのフォーマット

エントリ例

タグ ドキュメント
xml https://pkg.go.dev/encoding/xml

変更管理

リストエントリは、新しいタグを使用する公開パッケージを作成した人なら誰でも追加できます。パッケージドキュメントへのリンクが機能しなくなった場合、またはそのパッケージの作成者が要求した場合、リストエントリは削除できます。

よく知られた構造体タグのリスト

タグ ドキュメント
asn1 https://pkg.go.dev/encoding/asn1
bigquery https://pkg.go.dev/cloud.google.com/go/bigquery
bson https://pkg.go.dev/go.mongodb.org/mongo-driver/bson
cue https://pkg.go.dev/cuelang.org/go/cuego
datastore https://pkg.go.dev/cloud.google.com/go/datastore
db https://github.com/jmoiron/sqlx
dynamodbav https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/dynamodbattribute/#Marshal
egg https://github.com/andrewwphillips/eggql
feature https://github.com/nikolaydubina/go-featureprocessing
gorm https://pkg.go.dev/github.com/jinzhu/gorm
graphql https://github.com/samsarahq/thunder
json https://pkg.go.dev/encoding/json
mapstructure https://pkg.go.dev/github.com/mitchellh/mapstructure
parser https://pkg.go.dev/github.com/alecthomas/participle
properties https://pkg.go.dev/github.com/magiconair/properties#Properties.Decode
protobuf https://github.com/golang/protobuf
reform https://pkg.go.dev/gopkg.in/reform.v1
spanner https://pkg.go.dev/cloud.google.com/go/spanner
toml https://pkg.go.dev/github.com/pelletier/go-toml
url https://github.com/google/go-querystring
validate https://github.com/go-playground/validator
xml https://pkg.go.dev/encoding/xml
yaml https://pkg.go.dev/gopkg.in/yaml.v2

このコンテンツはGo Wikiの一部です。