### Per-file SPDX header example Source: https://github.com/hstern/go-subjectid/blob/main/AGENTS.md Every .go file must start with a SPDX header. ```go // Copyright 2026 The go-subjectid Authors // SPDX-License-Identifier: Apache-2.0 package subjectid ``` -------------------------------- ### Install Source: https://github.com/hstern/go-subjectid/blob/main/README.md Install the go-subjectid library. ```sh go get github.com/hstern/go-subjectid@latest ``` -------------------------------- ### Quickstart: Build and marshal Source: https://github.com/hstern/go-subjectid/blob/main/README.md Build a Subject Identifier value in Go and emit canonical wire bytes. ```go package main import ( "encoding/json" "fmt" "github.com/hstern/go-subjectid" ) func main() { id := subjectid.IssSubID{ Iss: "https://issuer.example.com/", Sub: "145234573", } if err := id.Validate(); err != nil { panic(err) } out, err := json.Marshal(id) if err != nil { panic(err) } fmt.Println(string(out)) // {"format":"iss_sub","iss":"https://issuer.example.com/","sub":"145234573"} } ``` -------------------------------- ### SPDX Header Example Source: https://github.com/hstern/go-subjectid/blob/main/README.md Example of the SPDX header comment found in source files. ```go // Copyright 2026 The go-subjectid Authors // SPDX-License-Identifier: Apache-2.0 ``` -------------------------------- ### Quickstart: Decode and validate Source: https://github.com/hstern/go-subjectid/blob/main/README.md Decode a Subject Identifier from JSON, validate it, and act on the result. ```go package main import ( "encoding/json" "fmt" "github.com/hstern/go-subjectid" ) func main() { wire := []byte(`{"format":"email","email":"user@example.com"}`) id, err := subjectid.Parse(json.RawMessage(wire)) if err != nil { panic(err) } if err := id.Validate(); err != nil { panic(err) } fmt.Printf("%s identifier: %#v\n", id.Format(), id) } ``` -------------------------------- ### Custom Subject Identifier Format Source: https://github.com/hstern/go-subjectid/blob/main/README.md Example of defining a new Go type embedding subjectid.Seal and registering a constructor for a custom format. ```go type OrgTenantID struct { subjectid.Seal Tenant string } func (OrgTenantID) Format() string { return "org.example.tenant" } func (OrgTenantID) Validate() error { /* … */ return nil } func (o OrgTenantID) MarshalJSON() ([]byte, error) { /* spec-order */ } func (o *OrgTenantID) UnmarshalJSON(b []byte) error { /* … */ } func init() { _ = subjectid.RegisterFormat("org.example.tenant", func() subjectid.SubjectIdentifier { return &OrgTenantID{} }) } ``` -------------------------------- ### Build prerequisites Source: https://github.com/hstern/go-subjectid/blob/main/README.md Build the pap CLI for regenerating validation regexes. ```sh git clone --depth=1 https://github.com/pandatix/go-abnf.git /tmp/go-abnf go build -C /tmp/go-abnf/cmd/pap -o "$(go env GOPATH)/bin/pap" ``` -------------------------------- ### Quick checks before pushing Source: https://github.com/hstern/go-subjectid/blob/main/AGENTS.md These commands should be run before pushing code to ensure code quality and correctness. ```sh gofmt -l . go vet ./... go mod tidy -diff go test -race -shuffle=on ./... golangci-lint run ./... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.