# レコードフィールドクラス

{% hint style="info" %}
**Go SDK v1.7.0** - **Go 1.16以上**が必要です。本ページでは標準フィールドおよびPAM用フィールドの型を取り扱います。SDKに登録されているフィールド型文字列の一覧は、`record_data.go` 内の `getKeeperRecordField` の `switch` をご参照ください。
{% endhint %}

Keeperシークレットマネージャー Go SDKでは、レコードフィールドは型付きのGoの構造体として表現されます。各フィールド型は基底型 `KeeperRecordField` を埋め込みます。

### レコードフィールドへのアクセス

レコードフィールドには `GetFieldsByType` 関数を使用します。

**`GetFieldsByType` の使い方**

`GetFieldsByType(fieldType string) []map[string]interface{}`

指定した型に一致する標準フィールドをすべて、生のマップのスライスとして返します。自動デシリアライズは行われません。マップのキーと型アサーションで値にアクセスするか、型付き構造体へアンマーシャルします ([例2: 電話・住所などの複合フィールド](#example-2-access-complex-fields-phone-address))。

```go
// レコードからログインフィールドを取得
if loginFields := record.GetFieldsByType("login"); len(loginFields) > 0 {
  loginField := loginFields[0]
  // loginField は map[string]interface{} — キーで値にアクセス
  if values, ok := loginField["value"].([]interface{}); ok && len(values) > 0 {
    loginValue := values[0].(string)
    fmt.Printf("Login: %s\n", loginValue)
  }
}
```

**`GetFieldValueByType` の使い方 (シンプルに扱う場合)**

```go
import ksm "github.com/keeper-security/secrets-manager-go/core"

// ログイン値を直接取得
login := record.GetFieldValueByType("login")
fmt.Printf("Login: %s\n", login)

// パスワード値を取得
password := record.GetFieldValueByType("password")
fmt.Printf("Password: %s\n", password)
```

{% hint style="info" %}
`GetFieldValueByType` は単純なフィールドの文字列値を返します。電話・住所などの複合フィールドには、`GetFieldsByType` とJSONアンマーシャル、あるいは下記の例2のパターンを使用してください。
{% endhint %}

## フィールド型クラス参照

### KeeperRecordField

すべてのレコードフィールドは `KeeperRecordField` を埋め込み、`Label` と `Type` のフィールドを持ちます。

```go
type KeeperRecordField struct {
	Type  string `json:"type"`
	Label string `json:"label,omitempty"`
}
```

#### フィールド値

| 名前      | 型        | 必須  | デフォルト |
| ------- | -------- | --- | ----- |
| `Label` | `string` | いいえ | `""`  |
| `Type`  | `string` | はい  | `""`  |

### Login

```go
type Login struct {
    KeeperRecordField
    Required      bool     `json:"required,omitempty"`
    PrivacyScreen bool     `json:"privacyScreen,omitempty"`
    Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### PasswordComplexity

```go
type PasswordComplexity struct {
    Length    int `json:"length,omitempty"`
    Caps      int `json:"caps,omitempty"`
    Lowercase int `json:"lowercase,omitempty"`
    Digits    int `json:"digits,omitempty"`
    Special   int `json:"special,omitempty"`
}
```

#### フィールド値

| 名前          | 型     | 必須  | デフォルト | 説明          |
| ----------- | ----- | --- | ----- | ----------- |
| `Length`    | `int` | いいえ | `0`   | パスワード全体の文字数 |
| `Caps`      | `int` | いいえ | `0`   | 大文字の最小文字数   |
| `Lowercase` | `int` | いいえ | `0`   | 小文字の最小文字数   |
| `Digits`    | `int` | いいえ | `0`   | 数字の最小文字数    |
| `Special`   | `int` | いいえ | `0`   | 記号の最小文字数    |

{% hint style="warning" %}
`Password.Complexity` はポインタ型 (`*PasswordComplexity`) です。未設定のデフォルトは `nil` (複雑さポリシーなし) です。フィールドを設定する前に必ず割り当てます。

```go
pwd := &ksm.Password{}
pwd.Complexity = &ksm.PasswordComplexity{
    Length:  16,
    Caps:    2,
    Digits:  2,
    Special: 2,
}
```

{% endhint %}

### Password

```go
type Password struct {
	KeeperRecordField
	Required          bool                `json:"required,omitempty"`
	PrivacyScreen     bool                `json:"privacyScreen,omitempty"`
	EnforceGeneration bool                `json:"enforceGeneration,omitempty"`
	Complexity        *PasswordComplexity `json:"complexity,omitempty"`
	Value             []string            `json:"value,omitempty"`
}
```

#### フィールド値

<table data-header-hidden><thead><tr><th width="237">名前</th><th width="150">型</th><th width="150">必須</th><th>デフォルト</th></tr></thead><tbody><tr><td>名前</td><td>型</td><td>必須</td><td>デフォルト</td></tr><tr><td><code>Label</code></td><td><code>string</code></td><td>いいえ</td><td><code>""</code></td></tr><tr><td><code>Required</code></td><td><code>bool</code></td><td>いいえ</td><td><code>false</code></td></tr><tr><td><code>PrivacyScreen</code></td><td><code>bool</code></td><td>いいえ</td><td><code>false</code></td></tr><tr><td><code>EnforceGeneration</code></td><td><code>bool</code></td><td>いいえ</td><td><code>false</code></td></tr><tr><td><code>Value</code></td><td><code>[]string</code></td><td>はい</td><td></td></tr></tbody></table>

### Url

```go
type Url struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### FileRef

```go
type FileRef struct {
	KeeperRecordField
	Required bool     `json:"required,omitempty"`
	Value    []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型          | 必須  | デフォルト   |
| ---------- | ---------- | --- | ------- |
| `Label`    | `string`   | いいえ | `""`    |
| `Required` | `bool`     | いいえ | `false` |
| `Value`    | `[]string` | はい  |         |

### OneTimeCode

```go
type OneTimeCode struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### OneTimePassword

```go
type OneTimePassword struct {
    KeeperRecordField
    Required      bool     `json:"required,omitempty"`
    PrivacyScreen bool     `json:"privacyScreen,omitempty"`
    Value         []string `json:"value,omitempty"`
}
```

JSONのフィールド型文字列は `"otp"` です (`OneTimeCode` の `"oneTimeCode"` とは別です)。

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### Name

```go
type Name struct {
	First  string `json:"first,omitempty"`
	Middle string `json:"middle,omitempty"`
	Last   string `json:"last,omitempty"`
}
```

#### フィールド値

| 名前       | 型        | 必須  | デフォルト |
| -------- | -------- | --- | ----- |
| `First`  | `string` | いいえ | `""`  |
| `Middle` | `string` | いいえ | `""`  |
| `Last`   | `string` | いいえ | `""`  |

### Names

```go
type Names struct {
	KeeperRecordField
	Required      bool   `json:"required,omitempty"`
	PrivacyScreen bool   `json:"privacyScreen,omitempty"`
	Value         []Name `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型        | 必須  | デフォルト   |
| --------------- | -------- | --- | ------- |
| `Label`         | `string` | いいえ | `""`    |
| `Required`      | `bool`   | いいえ | `false` |
| `PrivacyScreen` | `bool`   | いいえ | `false` |
| `Value`         | `[]Name` | はい  |         |

### BirthDate <a href="#birthdate" id="birthdate"></a>

```go
type BirthDate struct {
	KeeperRecordField
	Required      bool    `json:"required,omitempty"`
	PrivacyScreen bool    `json:"privacyScreen,omitempty"`
	Value         []int64 `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型         | 必須  | デフォルト   |
| --------------- | --------- | --- | ------- |
| `Label`         | `string`  | いいえ | `""`    |
| `Required`      | `bool`    | いいえ | `false` |
| `PrivacyScreen` | `bool`    | いいえ | `false` |
| `Value`         | `[]int64` | はい  |         |

{% hint style="warning" %}
**日付形式**: 日付値は **Unixエポックからのミリ秒** として格納されます。Go の `time.Time` との相互変換は以下のとおりです。

```go
import "time"

// ミリ秒のUnix時刻から time.Time へ
dateValue := int64(1641934793000) // フィールドから取得
goTime := time.Unix(dateValue/1000, (dateValue%1000)*1000000)

// time.Time からミリ秒のUnix時刻へ
goTime := time.Now()
milliseconds := goTime.UnixNano() / 1000000
```

{% endhint %}

### Date

```go
type Date struct {
	KeeperRecordField
	Required      bool    `json:"required,omitempty"`
	PrivacyScreen bool    `json:"privacyScreen,omitempty"`
	Value         []int64 `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型         | 必須  | デフォルト   |
| --------------- | --------- | --- | ------- |
| `Label`         | `string`  | いいえ | `""`    |
| `Required`      | `bool`    | いいえ | `false` |
| `PrivacyScreen` | `bool`    | いいえ | `false` |
| `Value`         | `[]int64` | はい  |         |

{% hint style="warning" %}
**日付形式**: 日付値は **Unixエポックからのミリ秒** として格納されます。

[#birthdate](#birthdate "mention") 見出し直下の注記にあるコード例を用いてください。
{% endhint %}

### ExpirationDate

```go
type ExpirationDate struct {
	KeeperRecordField
	Required      bool    `json:"required,omitempty"`
	PrivacyScreen bool    `json:"privacyScreen,omitempty"`
	Value         []int64 `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型         | 必須  | デフォルト   |
| --------------- | --------- | --- | ------- |
| `Label`         | `string`  | いいえ | `""`    |
| `Required`      | `bool`    | いいえ | `false` |
| `PrivacyScreen` | `bool`    | いいえ | `false` |
| `Value`         | `[]int64` | はい  |         |

{% hint style="warning" %}
**日付形式**: 日付値は **Unixエポックからのミリ秒** として格納されます。

[#birthdate](#birthdate "mention") 見出し直下の注記にあるコード例を用いてください。
{% endhint %}

### Text

```go
type Text struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### SecurityQuestion

```go
type SecurityQuestion struct {
	Question string `json:"question,omitempty"`
	Answer   string `json:"answer,omitempty"`
}
```

#### フィールド値

| 名前         | 型        | 必須  | デフォルト |
| ---------- | -------- | --- | ----- |
| `Question` | `string` | いいえ | `""`  |
| `Answer`   | `string` | いいえ | `""`  |

### SecurityQuestions

```go
type SecurityQuestions struct {
	KeeperRecordField
	Required      bool               `json:"required,omitempty"`
	PrivacyScreen bool               `json:"privacyScreen,omitempty"`
	Value         []SecurityQuestion `json:"value,omitempty"`
}
```

#### フィールド値

<table data-header-hidden><thead><tr><th>名前</th><th width="232">型</th><th width="152">必須</th><th>デフォルト</th></tr></thead><tbody><tr><td>名前</td><td>型</td><td>必須</td><td>デフォルト</td></tr><tr><td><code>Label</code></td><td><code>string</code></td><td>いいえ</td><td><code>""</code></td></tr><tr><td><code>Required</code></td><td><code>bool</code></td><td>いいえ</td><td><code>false</code></td></tr><tr><td><code>PrivacyScreen</code></td><td><code>bool</code></td><td>いいえ</td><td><code>false</code></td></tr><tr><td><code>Value</code></td><td><code>[]SecurityQuestion</code></td><td>はい</td><td></td></tr></tbody></table>

### Multiline

```go
type Multiline struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### Email

```go
type Email struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### CardRef

```go
type CardRef struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### AddressRef

```go
type AddressRef struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### PinCode

```go
type PinCode struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### Phone

```go
type Phone struct {
	Region string `json:"region,omitempty"`
	Number string `json:"number,omitempty"`
	Ext    string `json:"ext,omitempty"`
	Type   string `json:"type,omitempty"`
}
```

#### フィールド値

| 名前       | 型        | 必須  | デフォルト |
| -------- | -------- | --- | ----- |
| `Region` | `string` | いいえ | `""`  |
| `Number` | `string` | いいえ | `""`  |
| `Ext`    | `string` | いいえ | `""`  |
| `Type`   | `string` | いいえ | `""`  |

### Phones

```go
type Phones struct {
	KeeperRecordField
	Required      bool    `json:"required,omitempty"`
	PrivacyScreen bool    `json:"privacyScreen,omitempty"`
	Value         []Phone `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型         | 必須  | デフォルト   |
| --------------- | --------- | --- | ------- |
| `Label`         | `string`  | いいえ | `""`    |
| `Required`      | `bool`    | いいえ | `false` |
| `PrivacyScreen` | `bool`    | いいえ | `false` |
| `Value`         | `[]Phone` | はい  |         |

### Secret

```go
type Secret struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

<table data-header-hidden><thead><tr><th>名前</th><th width="167">型</th><th width="160.3170731707317">必須</th><th>デフォルト</th></tr></thead><tbody><tr><td><code>Label</code></td><td><code>string</code></td><td>いいえ</td><td><code>""</code></td></tr><tr><td><code>Required</code></td><td><code>bool</code></td><td>いいえ</td><td><code>false</code></td></tr><tr><td><code>PrivacyScreen</code></td><td><code>bool</code></td><td>いいえ</td><td><code>false</code></td></tr><tr><td><code>Value</code></td><td><code>[]string</code></td><td>はい</td><td></td></tr></tbody></table>

### SecureNote

```go
type SecureNote struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### AccountNumber

```go
type AccountNumber struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### PaymentCard

```go
type PaymentCard struct {
	CardNumber         string `json:"cardNumber,omitempty"`
	CardExpirationDate string `json:"cardExpirationDate,omitempty"`
	CardSecurityCode   string `json:"cardSecurityCode,omitempty"`
}
```

#### フィールド値

<table><thead><tr><th width="247.202216066482">名前</th><th width="150">型</th><th width="157">必須</th><th>デフォルト</th></tr></thead><tbody><tr><td><code>CardNumber</code></td><td><code>string</code></td><td>いいえ</td><td><code>""</code></td></tr><tr><td><code>CardExpirationDate</code></td><td><code>string</code></td><td>いいえ</td><td><code>""</code></td></tr><tr><td><code>CardSecurityCode</code></td><td><code>string</code></td><td>いいえ</td><td><code>""</code></td></tr></tbody></table>

### PaymentCards

```go
type PaymentCards struct {
	KeeperRecordField
	Required      bool          `json:"required,omitempty"`
	PrivacyScreen bool          `json:"privacyScreen,omitempty"`
	Value         []PaymentCard `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型               | 必須  | デフォルト   |
| --------------- | --------------- | --- | ------- |
| `Label`         | `string`        | いいえ | `""`    |
| `Required`      | `bool`          | いいえ | `false` |
| `PrivacyScreen` | `bool`          | いいえ | `false` |
| `Value`         | `[]PaymentCard` | はい  |         |

### BankAccount

```go
type BankAccount struct {
	AccountType   string `json:"accountType,omitempty"`
	RoutingNumber string `json:"routingNumber,omitempty"`
	AccountNumber string `json:"accountNumber,omitempty"`
	OtherType     string `json:"otherType,omitempty"`
}
```

#### フィールド値

| 名前              | 型        | 必須  | デフォルト |
| --------------- | -------- | --- | ----- |
| `AccountType`   | `string` | いいえ | `""`  |
| `RoutingNumber` | `string` | いいえ | `""`  |
| `AccountNumber` | `string` | いいえ | `""`  |
| `OtherType`     | `string` | いいえ | `""`  |

### BankAccounts

```go
type BankAccounts struct {
	KeeperRecordField
	Required      bool          `json:"required,omitempty"`
	PrivacyScreen bool          `json:"privacyScreen,omitempty"`
	Value         []BankAccount `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型               | 必須  | デフォルト   |
| --------------- | --------------- | --- | ------- |
| `Label`         | `string`        | いいえ | `""`    |
| `Required`      | `bool`          | いいえ | `false` |
| `PrivacyScreen` | `bool`          | いいえ | `false` |
| `Value`         | `[]BankAccount` | はい  |         |

### KeyPair

```go
type KeyPair struct {
	PublicKey  string `json:"publicKey,omitempty"`
	PrivateKey string `json:"privateKey,omitempty"`
}
```

| 名前           | 型        | 必須  | デフォルト |
| ------------ | -------- | --- | ----- |
| `PublicKey`  | `string` | いいえ | `""`  |
| `PrivateKey` | `string` | いいえ | `""`  |

### KeyPairs

```go
type KeyPairs struct {
	KeeperRecordField
	Required      bool      `json:"required,omitempty"`
	PrivacyScreen bool      `json:"privacyScreen,omitempty"`
	Value         []KeyPair `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型           | 必須  | デフォルト   |
| --------------- | ----------- | --- | ------- |
| `Label`         | `string`    | いいえ | `""`    |
| `Required`      | `bool`      | いいえ | `false` |
| `PrivacyScreen` | `bool`      | いいえ | `false` |
| `Value`         | `[]KeyPair` | はい  |         |

### Host

```go
type Host struct {
	Hostname string `json:"hostName,omitempty"`
	Port     string `json:"port,omitempty"`
}
```

#### フィールド値

| 名前         | 型        | 必須  | デフォルト |
| ---------- | -------- | --- | ----- |
| `Hostname` | `string` | いいえ | `""`  |
| `Port`     | `string` | いいえ | `""`  |

### Hosts

```go
type Hosts struct {
	KeeperRecordField
	Required      bool   `json:"required,omitempty"`
	PrivacyScreen bool   `json:"privacyScreen,omitempty"`
	Value         []Host `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型        | 必須  | デフォルト   |
| --------------- | -------- | --- | ------- |
| `Label`         | `string` | いいえ | `""`    |
| `Required`      | `bool`   | いいえ | `false` |
| `PrivacyScreen` | `bool`   | いいえ | `false` |
| `Value`         | `[]Host` | はい  |         |

### Address

```go
type Address struct {
	Street1 string `json:"street1,omitempty"`
	Street2 string `json:"street2,omitempty"`
	City    string `json:"city,omitempty"`
	State   string `json:"state,omitempty"`
	Country string `json:"country,omitempty"`
	Zip     string `json:"zip,omitempty"`
}
```

#### フィールド値

| 名前        | 型        | 必須  | デフォルト |
| --------- | -------- | --- | ----- |
| `Street1` | `string` | いいえ | `""`  |
| `Street2` | `string` | いいえ | `""`  |
| `City`    | `string` | いいえ | `""`  |
| `State`   | `string` | いいえ | `""`  |
| `Country` | `string` | いいえ | `""`  |
| `Zip`     | `string` | いいえ | `""`  |

### Addresses

```go
type Addresses struct {
	KeeperRecordField
	Required      bool      `json:"required,omitempty"`
	PrivacyScreen bool      `json:"privacyScreen,omitempty"`
	Value         []Address `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型           | 必須  | デフォルト   |
| --------------- | ----------- | --- | ------- |
| `Label`         | `string`    | いいえ | `""`    |
| `Required`      | `bool`      | いいえ | `false` |
| `PrivacyScreen` | `bool`      | いいえ | `false` |
| `Value`         | `[]Address` | はい  |         |

### LicenseNumber

```go
type LicenseNumber struct {
	KeeperRecordField
	Required      bool     `json:"required,omitempty"`
	PrivacyScreen bool     `json:"privacyScreen,omitempty"`
	Value         []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]string` | はい  |         |

### RecordRef

```go
type RecordRef struct {
    KeeperRecordField
    Required bool     `json:"required,omitempty"`
    Value    []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型          | 必須  | デフォルト   |
| ---------- | ---------- | --- | ------- |
| `Label`    | `string`   | いいえ | `""`    |
| `Required` | `bool`     | いいえ | `false` |
| `Value`    | `[]string` | はい  |         |

### Checkbox

```go
type Checkbox struct {
    KeeperRecordField
    Required bool   `json:"required,omitempty"`
    Value    []bool `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型        | 必須  | デフォルト   |
| ---------- | -------- | --- | ------- |
| `Label`    | `string` | いいえ | `""`    |
| `Required` | `bool`   | いいえ | `false` |
| `Value`    | `[]bool` | はい  |         |

### Dropdown

```go
type Dropdown struct {
    KeeperRecordField
    Required bool     `json:"required,omitempty"`
    Value    []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型          | 必須  | デフォルト   |
| ---------- | ---------- | --- | ------- |
| `Label`    | `string`   | いいえ | `""`    |
| `Required` | `bool`     | いいえ | `false` |
| `Value`    | `[]string` | はい  |         |

### Schedule

```go
type Schedule struct {
    Type          string `json:"type,omitempty"`
    Cron          string `json:"cron,omitempty"`
    Time          string `json:"time,omitempty"`
    Tz            string `json:"tz,omitempty"`
    Weekday       string `json:"weekday,omitempty"`
    IntervalCount int    `json:"intervalCount,omitempty"`
}
```

#### フィールド値

| 名前              | 型        | 必須  | デフォルト | 説明                                  |
| --------------- | -------- | --- | ----- | ----------------------------------- |
| `Type`          | `string` | いいえ | `""`  | スケジュール種別 (例: `"weekly"`)            |
| `Cron`          | `string` | いいえ | `""`  | Cron式                               |
| `Time`          | `string` | いいえ | `""`  | 時刻 (非推奨の `UtcTime` に代わる)            |
| `Tz`            | `string` | いいえ | `""`  | IANAタイムゾーン (例: `"America/Chicago"`) |
| `Weekday`       | `string` | いいえ | `""`  | 週次スケジュールの曜日                         |
| `IntervalCount` | `int`    | いいえ | `0`   | 繰り返し間隔の回数                           |

### Schedules

```go
type Schedules struct {
    KeeperRecordField
    Required bool       `json:"required,omitempty"`
    Value    []Schedule `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型            | 必須  | デフォルト   |
| ---------- | ------------ | --- | ------- |
| `Label`    | `string`     | いいえ | `""`    |
| `Required` | `bool`       | いいえ | `false` |
| `Value`    | `[]Schedule` | はい  |         |

### DirectoryType

```go
type DirectoryType struct {
    KeeperRecordField
    Required bool     `json:"required,omitempty"`
    Value    []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型          | 必須  | デフォルト   |
| ---------- | ---------- | --- | ------- |
| `Label`    | `string`   | いいえ | `""`    |
| `Required` | `bool`     | いいえ | `false` |
| `Value`    | `[]string` | はい  |         |

### DatabaseType

```go
type DatabaseType struct {
    KeeperRecordField
    Required bool     `json:"required,omitempty"`
    Value    []string `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型          | 必須  | デフォルト   |
| ---------- | ---------- | --- | ------- |
| `Label`    | `string`   | いいえ | `""`    |
| `Required` | `bool`     | いいえ | `false` |
| `Value`    | `[]string` | はい  |         |

### PamHostname

```go
type PamHostname struct {
    KeeperRecordField
    Required      bool   `json:"required,omitempty"`
    PrivacyScreen bool   `json:"privacyScreen,omitempty"`
    Value         []Host `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型        | 必須  | デフォルト   |
| --------------- | -------- | --- | ------- |
| `Label`         | `string` | いいえ | `""`    |
| `Required`      | `bool`   | いいえ | `false` |
| `PrivacyScreen` | `bool`   | いいえ | `false` |
| `Value`         | `[]Host` | はい  |         |

`Value` は `Hosts` と同じ `Host` 構造体を使用します。[Host](#host) をご参照ください。

### AllowedSettings

```go
type AllowedSettings struct {
    Connections         bool `json:"connections,omitempty"`
    PortForwards        bool `json:"portForwards,omitempty"`
    Rotation            bool `json:"rotation,omitempty"`
    SessionRecording    bool `json:"sessionRecording,omitempty"`
    TypescriptRecording bool `json:"typescriptRecording,omitempty"`
}
```

#### フィールド値

| 名前                    | 型      | 必須  | デフォルト   |
| --------------------- | ------ | --- | ------- |
| `Connections`         | `bool` | いいえ | `false` |
| `PortForwards`        | `bool` | いいえ | `false` |
| `Rotation`            | `bool` | いいえ | `false` |
| `SessionRecording`    | `bool` | いいえ | `false` |
| `TypescriptRecording` | `bool` | いいえ | `false` |

### PamResource

```go
type PamResource struct {
    ControllerUid   string          `json:"controllerUid,omitempty"`
    FolderUid       string          `json:"folderUid,omitempty"`
    ResourceRef     []string        `json:"resourceRef,omitempty"`
    AllowedSettings AllowedSettings `json:"allowedSettings,omitempty"`
}
```

#### フィールド値

| 名前                | 型                 | 必須  | デフォルト |
| ----------------- | ----------------- | --- | ----- |
| `ControllerUid`   | `string`          | いいえ | `""`  |
| `FolderUid`       | `string`          | いいえ | `""`  |
| `ResourceRef`     | `[]string`        | いいえ | `nil` |
| `AllowedSettings` | `AllowedSettings` | いいえ |       |

### PamResources

```go
type PamResources struct {
    KeeperRecordField
    Required bool          `json:"required,omitempty"`
    Value    []PamResource `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型               | 必須  | デフォルト   |
| ---------- | --------------- | --- | ------- |
| `Label`    | `string`        | いいえ | `""`    |
| `Required` | `bool`          | いいえ | `false` |
| `Value`    | `[]PamResource` | はい  |         |

### Script

```go
type Script struct {
    FileRef   string   `json:"fileRef,omitempty"`
    Command   string   `json:"command,omitempty"`
    RecordRef []string `json:"recordRef,omitempty"`
}
```

#### フィールド値

| 名前          | 型          | 必須  | デフォルト | 説明                        |
| ----------- | ---------- | --- | ----- | ------------------------- |
| `FileRef`   | `string`   | いいえ | `""`  | 添付スクリプトファイルのUID           |
| `Command`   | `string`   | いいえ | `""`  | 実行するシェルコマンド               |
| `RecordRef` | `[]string` | いいえ | `nil` | スクリプトのコンテキストとして渡すレコードのUID |

### Scripts

```go
type Scripts struct {
    KeeperRecordField
    Required      bool     `json:"required,omitempty"`
    PrivacyScreen bool     `json:"privacyScreen,omitempty"`
    Value         []Script `json:"value,omitempty"`
}
```

#### フィールド値

| 名前              | 型          | 必須  | デフォルト   |
| --------------- | ---------- | --- | ------- |
| `Label`         | `string`   | いいえ | `""`    |
| `Required`      | `bool`     | いいえ | `false` |
| `PrivacyScreen` | `bool`     | いいえ | `false` |
| `Value`         | `[]Script` | はい  |         |

### PamSettingsPortForward

```go
type PamSettingsPortForward struct {
    ReusePort bool   `json:"reusePort,omitempty"`
    Port      string `json:"port,omitempty"`
}
```

#### フィールド値

| 名前          | 型        | 必須  | デフォルト   |
| ----------- | -------- | --- | ------- |
| `ReusePort` | `bool`   | いいえ | `false` |
| `Port`      | `string` | いいえ | `""`    |

### PamSettingsConnection

```go
type PamSettingsConnection struct {
    Protocol     string   `json:"protocol,omitempty"`
    UserRecords  []string `json:"userRecords,omitempty"`
    Security     string   `json:"security,omitempty"`
    IgnoreCert   bool     `json:"ignoreCert,omitempty"`
    ResizeMethod string   `json:"resizeMethod,omitempty"`
    ColorScheme  string   `json:"colorScheme,omitempty"`
}
```

#### フィールド値

| 名前             | 型          | 必須  | デフォルト   |
| -------------- | ---------- | --- | ------- |
| `Protocol`     | `string`   | いいえ | `""`    |
| `UserRecords`  | `[]string` | いいえ | `nil`   |
| `Security`     | `string`   | いいえ | `""`    |
| `IgnoreCert`   | `bool`     | いいえ | `false` |
| `ResizeMethod` | `string`   | いいえ | `""`    |
| `ColorScheme`  | `string`   | いいえ | `""`    |

### PamSetting

```go
type PamSetting struct {
    PortForward []PamSettingsPortForward `json:"portForward,omitempty"`
    Connection  []PamSettingsConnection  `json:"connection,omitempty"`
}
```

#### フィールド値

| 名前            | 型                          | 必須  | デフォルト |
| ------------- | -------------------------- | --- | ----- |
| `PortForward` | `[]PamSettingsPortForward` | いいえ | `nil` |
| `Connection`  | `[]PamSettingsConnection`  | いいえ | `nil` |

### PamSettings

```go
type PamSettings struct {
    KeeperRecordField
    Required bool         `json:"required,omitempty"`
    Value    []PamSetting `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型              | 必須  | デフォルト   |
| ---------- | -------------- | --- | ------- |
| `Label`    | `string`       | いいえ | `""`    |
| `Required` | `bool`         | いいえ | `false` |
| `Value`    | `[]PamSetting` | はい  |         |

### PamRbiConnection

```go
type PamRbiConnection struct {
    Protocol                   string   `json:"protocol,omitempty"`
    UserRecords                []string `json:"userRecords,omitempty"`
    AllowUrlManipulation       bool     `json:"allowUrlManipulation,omitempty"`
    AllowedUrlPatterns         string   `json:"allowedUrlPatterns,omitempty"`
    AllowedResourceUrlPatterns string   `json:"allowedResourceUrlPatterns,omitempty"`
    HttpCredentialsUid         string   `json:"httpCredentialsUid,omitempty"`
    AutofillConfiguration      string   `json:"autofillConfiguration,omitempty"`
}
```

#### フィールド値

| 名前                           | 型          | 必須  | デフォルト   |
| ---------------------------- | ---------- | --- | ------- |
| `Protocol`                   | `string`   | いいえ | `""`    |
| `UserRecords`                | `[]string` | いいえ | `nil`   |
| `AllowUrlManipulation`       | `bool`     | いいえ | `false` |
| `AllowedUrlPatterns`         | `string`   | いいえ | `""`    |
| `AllowedResourceUrlPatterns` | `string`   | いいえ | `""`    |
| `HttpCredentialsUid`         | `string`   | いいえ | `""`    |
| `AutofillConfiguration`      | `string`   | いいえ | `""`    |

### PamRemoteBrowserSetting

```go
type PamRemoteBrowserSetting struct {
    Connection PamRbiConnection `json:"connection,omitempty"`
}
```

#### フィールド値

| 名前           | 型                  | 必須  | デフォルト |
| ------------ | ------------------ | --- | ----- |
| `Connection` | `PamRbiConnection` | いいえ |       |

### PamRemoteBrowserSettings

```go
type PamRemoteBrowserSettings struct {
    KeeperRecordField
    Required bool                      `json:"required,omitempty"`
    Value    []PamRemoteBrowserSetting `json:"value,omitempty"`
}
```

#### フィールド値

| 名前         | 型                           | 必須  | デフォルト   |
| ---------- | --------------------------- | --- | ------- |
| `Label`    | `string`                    | いいえ | `""`    |
| `Required` | `bool`                      | いいえ | `false` |
| `Value`    | `[]PamRemoteBrowserSetting` | はい  |         |

### KeeperFileData

```go
type KeeperFileData struct {
	Title        string `json:"title,omitempty"`
	Name         string `json:"name,omitempty"`
	Type         string `json:"type,omitempty"`
	Size         int64  `json:"size,omitempty"`
	LastModified int64  `json:"lastModified,omitempty"`
}
```

#### フィールド値

| 名前             | 型        | 説明                     |
| -------------- | -------- | ---------------------- |
| `Title`        | `string` | ファイル添付の表示タイトル          |
| `Name`         | `string` | 元のファイル名                |
| `Type`         | `string` | MIMEタイプ                |
| `Size`         | `int64`  | バイト単位のファイルサイズ          |
| `LastModified` | `int64`  | 最終更新のタイムスタンプ (Unixミリ秒) |

{% hint style="info" %}
`KeeperFileData` はファイルアップロード時にサーバー側で埋めます。各フィールドは `omitempty` のため、SDKが特定のフィールドを必須とみなすことはありません。
{% endhint %}

## フィールドアクセスのベストプラクティス

{% hint style="info" %}
**v1.7.0で改善**: 欠損や破損したフィールドデータがあっても、SDKは処理を失敗させずに継続します。
{% endhint %}

#### 安全なフィールドアクセスのパターン

レコードフィールドにアクセスするときは、以下の点を確認します。

1. **フィールドの有無** - レコードにそのフィールドが存在しない場合があります
2. **値の有無** - フィールドはあっても値が空の場合があります
3. **型アサーション** - 値が想定外の型で格納されている場合があります

**推奨パターン:**

```go
import (
  "fmt"
  ksm "github.com/keeper-security/secrets-manager-go/core"
)

func safeGetFieldValue(record *ksm.Record, fieldType string) string {
  fields := record.GetFieldsByType(fieldType)
  if len(fields) == 0 {
    fmt.Printf("Field '%s' not found in record\n", fieldType)
    return ""
  }
  field := fields[0]
  if values, ok := field["value"].([]interface{}); ok && len(values) > 0 {
    if strValue, ok := values[0].(string); ok {
      return strValue
    }
  }
  fmt.Printf("Field '%s' has no valid value\n", fieldType)
  return ""
}

login := safeGetFieldValue(record, "login")
password := safeGetFieldValue(record, "password")
```

**`GetFieldValueByType` を使う場合 (より簡潔):**

```go
import ksm "github.com/keeper-security/secrets-manager-go/core"

login := record.GetFieldValueByType("login")
password := record.GetFieldValueByType("password")
url := record.GetFieldValueByType("url")

if login == "" {
  fmt.Println("Login field is empty or missing")
}
```

#### 破損したフィールドの扱い

{% hint style="success" %}
**v1.7.0の強化**: 暗号化が破損したフィールドは自動的にスキップされ、有効なフィールドの処理は続行されます。
{% endhint %}

レコードに暗号化が破損したフィールドが含まれる場合:

* **有効なフィールド**には引き続きアクセスできます
* **破損したフィールド**は警告を出して黙ってスキップされます
* **個々のフィールド失敗**で例外は発生しません

**例:**

```go
records, err := sm.GetSecrets([]string{"RECORD_UID"})
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}
record := records[0]
title := record.Title()
notes := record.Notes()
password := record.GetFieldValueByType("password")
login := record.GetFieldValueByType("login")
fmt.Printf("Title: %s\n", title)
fmt.Printf("Login: %s\n", login)
fmt.Printf("Password: %s\n", password)
```

### よくあるフィールドアクセスのパターン

#### 例1: ログインレコードからすべてのフィールドを取得

```go
import (
  "fmt"
  ksm "github.com/keeper-security/secrets-manager-go/core"
)

func displayLoginRecord(record *ksm.Record) {
  fmt.Printf("Title: %s\n", record.Title())
  fmt.Printf("Type: %s\n", record.Type())
  login := record.GetFieldValueByType("login")
  password := record.GetFieldValueByType("password")
  url := record.GetFieldValueByType("url")
  fmt.Printf("Login: %s\n", login)
  fmt.Printf("Password: %s\n", password)
  fmt.Printf("URL: %s\n", url)
  fmt.Printf("Notes: %s\n", record.Notes())
}

func main() {
  clientOptions := &ksm.ClientOptions{
    Config: ksm.NewFileKeyValueStorage("ksm-config.json"),
  }
  sm := ksm.NewSecretsManager(clientOptions)
  records, err := sm.GetSecrets([]string{"RECORD_UID"})
  if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
  }
  if len(records) > 0 {
    displayLoginRecord(records[0])
  }
}
```

#### 例2: 複合フィールド (電話・住所) へのアクセス <a href="#example-2-access-complex-fields-phone-address" id="example-2-access-complex-fields-phone-address"></a>

```go
import (
  "encoding/json"
  "fmt"
  ksm "github.com/keeper-security/secrets-manager-go/core"
)

func getPhoneNumbers(record *ksm.Record) []ksm.Phone {
  phones := []ksm.Phone{}
  phoneFields := record.GetFieldsByType("phone")
  for _, field := range phoneFields {
    if values, ok := field["value"].([]interface{}); ok {
      for _, v := range values {
        if jsonBytes, err := json.Marshal(v); err == nil {
          var phone ksm.Phone
          if json.Unmarshal(jsonBytes, &phone) == nil {
            phones = append(phones, phone)
          }
        }
      }
    }
  }
  return phones
}
```

#### 例3: アクセス前にフィールドの有無を確認

```go
import (
  "fmt"
  ksm "github.com/keeper-security/secrets-manager-go/core"
)

func hasField(record *ksm.Record, fieldType string) bool {
  fields := record.GetFieldsByType(fieldType)
  return len(fields) > 0
}
```

## 関連ドキュメント

* [Go SDKのメインドキュメント](/keeperpam/jp/secrets-manager/developer-sdk-library/golang-sdk.md) - 初期化、構成、各操作
* [Keeper表記法](/keeperpam/jp/secrets-manager/about/keeper-notation.md) - 表記法の構文と機能
* [レコードタイプ](/keeperpam/jp/secrets-manager/about/field-record-types.md) - レコードタイプとフィールドの一覧


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/secrets-manager/developer-sdk-library/golang-sdk/record-field-classes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
