-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
golang实现接口注意事项 #3
Comments
关于数据类型作为参数 传入函数一般想用reflect来获取数据的数据类型 比如 type CustomStruct struct {
}
func getTypeName(t interface{}) string {
rt := reflect.TypeOf(t).Elem()
return rt.Name()
}
getTypeName(CustomStruct) 这样会有编译错误,可以这么改 func getTypeName(t reflect.Type) string {
return t.Name()
}
// Calling it:
getTypeName(reflect.TypeOf(CustomStruct{})) 或者 t := reflect.TypeOf((*CustomStruct)(nil)).Elem()
fmt.Println(t.Name()) // Prints CustomStruct |
filecoin 钱包结构理解 抽出interface的使用./docgen-md "api/api_full.go" "FullNode" "api" "./api" > documentation/en/api-v1-unstable-methods.md |
方案找同学: 登录这个网站 授权
开发钱包过程中遇到的问题记录### 1. 因为引用了filecoin工程中的wallet 库 所以需要引入一些依赖,但是ffi这个依赖需要独立编译
因为是rust 写的,golang这边需要cgo来调用
而ffi本身需要先编译出来比如filcrypto.pc这样可以被调用的库 ### 1. extern下 git submodule add ffi库
### 2.进入目录运行./build.sh 会报错
[ERROR cargo_lipo] Failed to build "filcrypto" for "aarch64-apple-darwin": Executing "/Users/imac/.rustup/toolchains/nightly-2021-04-24-x86_64-apple-darwin/bin/cargo" "--color" "auto" "build" "-p" "filcrypto" "--target" "aarch64-apple-darwin" "--release" "--lib" "--no-default-features" "--features" "multicore-sdr,opencl" finished with error status: exit status: 101
### 3.
517 https_proxy=localhost:1089 brew info hwloc
518 LIBRARY_PATH=/opt/homebrew/lib LDFLAGS="-framework OpenCL" make clean
519 LIBRARY_PATH=/opt/homebrew/lib LDFLAGS="-framework OpenCL" make
在编译lotus的时候 文档中提到#### 针对比较老一点的cpu 必要的环境变量
export CGO_CFLAGS_ALLOW="-D__BLST_PORTABLE__"
export CGO_CFLAGS="-D__BLST_PORTABLE__"
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
简介
golang实现接口有很多需要注意的地方
Why can't I assign any slice to an []interface{}
原因:
[]interface{} is not an interface!
长度不一样 []interface{} 占两个words 一个是类型,一个是内容或者指针 对于N长的数据总长是 N*2
如果非要用 可以这样
参考资料
The text was updated successfully, but these errors were encountered: