我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

运行接口中存储的任何功能{}

I want to store a function with any parameters in an interface{} and be able to run it elsewhere.

So it could store a func(string) string or a func(int, int) string or etc, but I need to be able to call it later and be able to tell it what type of function it is. I tried to use .(func(string) string) and .(func(int,int) string), but got nothing.

Any help is appreciated.

Have you looked at the reflect package?

Particularly Type and ValueOf and Value.Call.

近期文章

  • 是否可以通过docker golang:alpine image构建静态的sqlite Go应用程序?
  • 使用计数器,服务器崩溃后如何继续计数?
  • 切片的MySQL查询抽象接口
  • 使用s3上载多个文件
  • Go中有限的并发连接
  • 使用Golang启动D-Bus服务
  • 如何更改界面参数?
  • Golang中的事件驱动模型
  • 从YAML对象列表创建API对象
  • 如何在socks5代理中将2字节的端口号返回给客户端?
  • 回历日期到戈兰公历
  • 检测哪个Lock()导致程序挂起?
  • 如何在Go中获取指向地图中的值的指针
  • 如何使用bufio检查用户输入是否为空?
  • 遍历结构并执行数据库查询
  • Google appengine / ah / health“方法不存在。”
  • DynamoDB ConsistentRead用于全局索引
  • 如何在Golang中获取带引号的可打印字符串
  • 从image.RGBA实现io.Reader
  • 从net / html令牌生成器获取流中的当前位置

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华