pointers - 当我传递一个指针时,我失去了该接口上所有可用的方法
问题描述
当我需要跨一个应用程序(自定义 kubernetes 控制器)传递指针时,我有一项任务 - 它每 60 秒读取一次 crd 并修改该接口。问题是当我传递一个指针时,我会丢失该接口上所有可用的方法。
它与client-go/cache cache.Store有关
有没有办法在指针上调用方法?
package main
import (
"k8s.io/client-go/tools/cache"
)
func main() {
store := cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc)
writeObject(&store)
}
func writeObject(store *cache.Store) {
store.
}
谢谢
解决方案
你store
已经是一个指针,所以传递 a*cache.Store
是可能的,但没有用。
接受 acache.Store
时,您应该能够以正常方式访问其方法,例如
func writeObject(store cache.Store) {
err := store.Add(...)
}
推荐阅读
- validation - Appmaker:如何在创建记录之前在服务器端验证我的数据?
- python-3.x - 没有名为“adsk”的模块问题 - Autodesk Fusion 360 的 Python 脚本
- javascript - 如何使用 autonumeric.js 获取空字段
- java - ImageView 未显示在三星 One UI 设备的显示剪切区域中
- java - 如何测试类是否是盒装原语?
- javascript - javascript中多个复选框的总和显示值
- regex - 无法替换正则表达式中的某些值
- python - 如何使用 Python 打印此动态模式?
- azure - 具有多个用户名的 Azure 文件共享映射驱动器
- google-play - 在 Google Play 商店中,Internal Test Track 如何与 Production 更新交互?