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
相關文章
- 【TCP/IP的狀態圖解決Cannot assign requested address】TCP圖解
- take a risk
- Golang Cannot use ss(type AAA) as type AAA in map indexGolangIndex
- golang,interface轉換型別 cannot convert t (typGolang型別
- k8s 環境下Cannot assign requested address問題解決K8S
- [異常筆記] zookeeper叢集啟動異常: Cannot open channel to 2 at election address ……筆記
- sky-take-out chapter 1APT
- MLE 5217 : Take-Home Dataset Classification
- Take-Two財報:2013Q1 Take-Two淨營收2.995億美元營收
- LINQ系列:LINQ to SQL Take/SkipSQL
- 'MessageBoxA' : function does not take 1 parameterFunction
- Laravel 中 offset,limit 或 skip , take 的使用LaravelMIT
- Window中安裝gitblit時,IP地址或埠衝突,提示Cannot assign requested address: bind的詳細解決方法Git
- 【Lintcode】1559. Take the Element and Query the Sum
- Java Get local IP addressJava
- 組播地址Multicase address
- Mac address setting For RedhatMacRedhat
- Take-Two財報:2015年Q1財季Take-Two營收1.254億美元 同比下滑12%營收
- mysql bind_address如何配置多個地址 mysql bind-address選項MySql
- oracle block phisical address to block#OracleBloC
- How to update the IP address of the SCAN VIP
- NgRx 裡 first 和 take(1) 操作符的區別
- 關於 rxjs 程式設計中的 take(1) 操作JS程式設計
- [LeetCode] Validate IP AddressLeetCode
- Location 下的Address Style設定
- cluster-wide IP address managementIDE
- ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accuratelyErrorYAMLProject
- Redux-Saga原始碼解析(一) 初始化和takeRedux原始碼
- Script:Translate RDBA relative data block addressBloC
- 解決cannot find module providing package或cannot find main modulePackageAI
- fork failed - Cannot allocate memoryAI
- Cannot set property 'innerHTML' of nullHTMLNull
- ImportError: cannot import name parseImportError
- cannot mount database in EXCLUSIVE modeDatabase
- Cannot find folder "Maintenance Plans".AINaN
- The type List is not generic; it cannot …
- 【轉】cannot allocate new log
- Cannot infer type arguments for PageImpl