Skip to content
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

Open
woshidama323 opened this issue Sep 7, 2021 · 4 comments
Open

golang实现接口注意事项 #3

woshidama323 opened this issue Sep 7, 2021 · 4 comments

Comments

@woshidama323
Copy link
Owner

woshidama323 commented Sep 7, 2021

简介

golang实现接口有很多需要注意的地方

var dataSlice []int = foo()
var interfaceSlice []interface{} = dataSlice

Why can't I assign any slice to an []interface{}

原因:
[]interface{} is not an interface!
长度不一样 []interface{} 占两个words 一个是类型,一个是内容或者指针 对于N长的数据总长是 N*2

如果非要用 可以这样

var dataSlice []int = foo()
var interfaceSlice []interface{} = make([]interface{}, len(dataSlice)) //这里指定已知类型的长度
for i, d := range dataSlice {
	interfaceSlice[i] = d
}

参考资料

@woshidama323
Copy link
Owner Author

错误1

./main.go:156:39: cannot use fn (type rpcserver.ImplementFullNode) as type rpcserver.FullNode in argument to rpcserver.FlutterHandler:
        rpcserver.ImplementFullNode does not implement rpcserver.FullNode (TestHandler method has pointer receiver)

原因解释
代码示例

@woshidama323
Copy link
Owner Author

关于数据类型作为参数 传入函数

一般想用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

参考资料

@woshidama323
Copy link
Owner Author

woshidama323 commented Oct 9, 2021

filecoin 钱包结构理解 抽出interface的使用

./docgen-md "api/api_full.go" "FullNode" "api" "./api" > documentation/en/api-v1-unstable-methods.md

@woshidama323
Copy link
Owner Author

woshidama323 commented Oct 9, 2021

方案

找同学:
github账户 超过180天
https://verify.glif.io/

登录这个网站 授权
然后填写 给定的地址,这样可以获取更多的数据

  • woshidama323 f1n6nkd4647ekep2zwyod6tlfbzfnpuxakqxuzd6q 32G 新机房备用101机器上

开发钱包过程中遇到的问题记录

### 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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant