Golang cannot take the address of
今天在使用kubernetes/apimachinery下/pkg/api/resource中的Quantity接收k8s資源資訊的時候,報出如下錯誤:
..\server\handlers\adapter.go:70:
cannot call pointer method on clusterQuota.Hard[admin.ResourceRequestsCPU]
..\server\handlers\adapter.go:70:
cannot take the address of clusterQuota.Hard[admin.ResourceRequestsCPU]
具體出錯程式碼如下:
test:= clusterQuota.Hard[admin.ResourceRequestsCPU].Value()
fmt.Println(test)
Quantity結構及Value()方法如下:
type Quantity struct {
// i is the quantity in int64 scaled form, if d.Dec == nil
i int64Amount
// d is the quantity in inf.Dec form if d.Dec != nil
d infDecAmount
// s is the generated value of this quantity to avoid recalculation
s string
// Change Format at will. See the comment for Canonicalize for
// more details.
Format
}
// Value returns the value of q; any fractional part will be lost.
func (q *Quantity) Value() int64 {
return q.ScaledValue(0)
}
既然呼叫方法指定的是指標,那麼這麼呼叫是否可以?
ii := (&clusterQuota.Hard[tenant_admin.ResourceRequestsCPU]).Value()
fmt.Println(ii)
編譯發現還是不行,那應該怎麼處理呢?
其實會發現,取出變數的地址,需要兩步:
hardRequestCpu := clusterQuota.Hard[tenant_admin.ResourceRequestsCPU]
fmt.Println((&hardRequestCpu).Value())
本文參考:
https://stackoverflow.com/questions/10535743/address-of-a-temporary-in-go
個人微信公眾號:
作者:jiankunking 出處:http://blog.csdn.net/jiankunking
相關文章
- k8s 環境下Cannot assign requested address問題解決K8S
- [異常筆記] zookeeper叢集啟動異常: Cannot open channel to 2 at election address ……筆記
- golang,interface轉換型別 cannot convert t (typGolang型別
- take a risk
- [LeetCode] Validate IP AddressLeetCode
- Window中安裝gitblit時,IP地址或埠衝突,提示Cannot assign requested address: bind的詳細解決方法Git
- Redo Byte Address (RBA)(轉)
- mysql bind_address如何配置多個地址 mysql bind-address選項MySql
- sky-take-out chapter 1APT
- ORA-00130: invalid listener address
- cluster-wide IP address managementIDE
- MLE 5217 : Take-Home Dataset Classification
- 【Lintcode】1559. Take the Element and Query the Sum
- Redis 啟動報錯Address already in useRedis
- Laravel 中 offset,limit 或 skip , take 的使用LaravelMIT
- ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accuratelyErrorYAMLProject
- SSL - SSLHandshakeException: No subject alternative names matching IP address foundException
- telnet localhost 44444 telnet: connect to address ::1: Connection refusedlocalhost
- 解決 eclipse出現 Address already in use: bindEclipse
- 解決cannot find module providing package或cannot find main modulePackageAI
- [LeetCode] 2516. Take K of Each Character From Left and RightLeetCode
- xxx cannot be resolved to a type
- diskgroup "DATADG" cannot be mounted
- cannot instantiate QtProjectEngine objectQTProjectObject
- 郵件地址提取軟體:eMail Address Extractor for MacAIMac
- 關於 rxjs 程式設計中的 take(1) 操作JS程式設計
- Cannot set property 'innerHTML' of nullHTMLNull
- ImportError: cannot import name parseImportError
- fork failed - Cannot allocate memoryAI
- ‘error: ‘‘this‘‘ cannot be implicitly captured in this context‘ErrorAPTContext
- Cannot read property ‘aDataSort‘ of undefinedUndefined
- Uncaught Error: Cannot instantiate interfaceError
- 解決nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)NginxAI
- 關於“INS-40922 Invalid Scan Name – Unresolvable to IP address”
- Redux-Saga原始碼解析(一) 初始化和takeRedux原始碼
- NgRx 裡 first 和 take(1) 操作符的區別
- intel:spectre&Meltdown側通道攻擊(五)—— DRAM address mappingIntelAPP
- Solidity知識點集———Address, Mapping, msg.sender, require, InheritanceSolidAPPUI
- listen原始碼分析第一篇 address:port分析原始碼