[PR #316] [MERGED] refactor: use generics for Pointer func #389

Closed
opened 2026-02-28 00:42:00 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Telmate/proxmox-api-go/pull/316
Author: @Tinyblargon
Created: 3/6/2024
Status: Merged
Merged: 3/9/2024
Merged by: @Tinyblargon

Base: masterHead: refactor-pointer


📝 Commits (1)

  • 3a9b206 refactor: use generics for Pointer func

📊 Changes

35 files changed (+245 additions, -222 deletions)

View changed files

internal/util/util.go (+5 -0)
📝 proxmox/config_qemu.go (+9 -7)
📝 proxmox/config_storage.go (+33 -31)
📝 proxmox/util.go (+0 -15)
📝 test/api/CloudInit/shared_test.go (+4 -3)
📝 test/api/Qemu/shared_test.go (+4 -3)
📝 test/cli/Storage/Storage_PBS_0_test.go (+4 -3)
📝 test/cli/Storage/Storage_PBS_1_test.go (+4 -3)
📝 test/cli/Storage/Storage_RBD_0_test.go (+2 -2)
📝 test/cli/Storage/Storage_RBD_1_test.go (+2 -2)
📝 test/cli/Storage/Storage_SMB_0_test.go (+2 -1)
📝 test/cli/Storage/Storage_SMB_1_test.go (+2 -1)
📝 test/cli/Storage/Storage_ZFS-over-ISCSI_0_test.go (+4 -3)
📝 test/cli/Storage/Storage_ZFS-over-ISCSI_1_test.go (+4 -3)
📝 test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_0_test.go (+3 -2)
📝 test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_1_test.go (+4 -3)
📝 test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_0_test.go (+3 -2)
📝 test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_1_test.go (+4 -3)
📝 test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_0_test.go (+3 -2)
📝 test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_1_test.go (+4 -3)

...and 15 more files

📄 Description

Removed the type specific pointer creation functions and replaced it with one that uses generics.
Created the util package in the internal folder as the integration tests where using the old pointer functions. Putting it in internal ensures it can't be imported by a third party project.

Before:

func PointerString(text string) *string {
	return &text
}

// Creates a pointer to an int
func PointerInt(number int) *int {
	return &number
}

// Creates a pointer to a bool
func PointerBool(boolean bool) *bool {
	return &boolean
}

After:

func Pointer[T any](item T) *T {
	return &item
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Telmate/proxmox-api-go/pull/316 **Author:** [@Tinyblargon](https://github.com/Tinyblargon) **Created:** 3/6/2024 **Status:** ✅ Merged **Merged:** 3/9/2024 **Merged by:** [@Tinyblargon](https://github.com/Tinyblargon) **Base:** `master` ← **Head:** `refactor-pointer` --- ### 📝 Commits (1) - [`3a9b206`](https://github.com/Telmate/proxmox-api-go/commit/3a9b206de584656b3d6f89341dfcaa3ae3dffec4) refactor: use generics for `Pointer` func ### 📊 Changes **35 files changed** (+245 additions, -222 deletions) <details> <summary>View changed files</summary> ➕ `internal/util/util.go` (+5 -0) 📝 `proxmox/config_qemu.go` (+9 -7) 📝 `proxmox/config_storage.go` (+33 -31) 📝 `proxmox/util.go` (+0 -15) 📝 `test/api/CloudInit/shared_test.go` (+4 -3) 📝 `test/api/Qemu/shared_test.go` (+4 -3) 📝 `test/cli/Storage/Storage_PBS_0_test.go` (+4 -3) 📝 `test/cli/Storage/Storage_PBS_1_test.go` (+4 -3) 📝 `test/cli/Storage/Storage_RBD_0_test.go` (+2 -2) 📝 `test/cli/Storage/Storage_RBD_1_test.go` (+2 -2) 📝 `test/cli/Storage/Storage_SMB_0_test.go` (+2 -1) 📝 `test/cli/Storage/Storage_SMB_1_test.go` (+2 -1) 📝 `test/cli/Storage/Storage_ZFS-over-ISCSI_0_test.go` (+4 -3) 📝 `test/cli/Storage/Storage_ZFS-over-ISCSI_1_test.go` (+4 -3) 📝 `test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_0_test.go` (+3 -2) 📝 `test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_1_test.go` (+4 -3) 📝 `test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_0_test.go` (+3 -2) 📝 `test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_1_test.go` (+4 -3) 📝 `test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_0_test.go` (+3 -2) 📝 `test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_1_test.go` (+4 -3) _...and 15 more files_ </details> ### 📄 Description Removed the type specific pointer creation functions and replaced it with one that uses generics. Created the `util` package in the `internal` folder as the integration tests where using the old pointer functions. Putting it in `internal` ensures it can't be imported by a third party project. Before: ```go func PointerString(text string) *string { return &text } // Creates a pointer to an int func PointerInt(number int) *int { return &number } // Creates a pointer to a bool func PointerBool(boolean bool) *bool { return &boolean } ``` After: ```go func Pointer[T any](item T) *T { return &item } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 00:42:00 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/proxmox-api-go#389
No description provided.