当前位置:网站首页>In go language, function is a type
In go language, function is a type
2022-07-07 08:27:00 【Code two brother】
0 grpc-go、protobuf、multus-cni Technical column The main entrance
1 grpc-go Source code analysis and actual combat List of articles
2 Protobuf Introduction and actual combat Graphic column List of articles
3 multus-cni List of articles (k8s Multi network implementation scheme )
4 grpc、oauth2、openssl、 Two-way authentication 、 One way authentication and other column contents
summary ( Remember the following three sentences
)
1、
function
, It is also a kind oftype
(Pay special attention to
)
2、function
, I can assign a value toVariable
( wantspecial
Be careful )
3、function
, It can be used asParameters
, To pass
package func5_test
import (
"testing"
"fmt"
)
// Make a statement fire function
func fire() {
fmt.Print("--->this is fire func")
}
func study(str string) {
fmt.Printf("--->I'm studying %s", str)
}
// test , Whether the function is assigned to a variable
func TestFuncVariable(t *testing.T) {
// Declare variables f, The type is func type , Function type
// Put the variable f Declare as func() type ,
// call f When , It's actually calling theta fire function , here f It is commonly known as “ Callback function ”,
// here f The value of is nil
var f func()
f = fire
f()
}
// test , Whether the function is assigned to a variable
func TestStudy(t *testing.T) {
st := study
st("English")
}
// test , Whether the function type can be passed as a parameter
func learning(f func()) {
fmt.Printf("--->this is running func")
f()
}
func TestFuncParams(t *testing.T) {
f := fire
// Pass the function as an argument
learning(f)
}
边栏推荐
- 拓维信息使用 Rainbond 的云原生落地实践
- Kotlin combines flatmap for filtering and zip merge operators
- 【雅思口语】安娜口语学习记录 Part2
- 在Rainbond中实现数据库结构自动化升级
- [IELTS speaking] Anna's oral learning records part2
- 漏洞复现-easy_tornado
- Opencv learning notes 1 -- several methods of reading images
- Automatic upgrading of database structure in rainbow
- The use of generics and vararg variable parameters in kotlin
- CTF-WEB shrine模板注入nmap的基本使用
猜你喜欢
Deit learning notes
SSM 整合
Ebpf cilium practice (2) - underlying network observability
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
Openvscode cloud ide joins rainbow integrated development system
opencv学习笔记二——图像基本操作
opencv学习笔记五——梯度计算/边缘检测
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
一文了解如何源码编译Rainbond基础组件
随机推荐
Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
Interactive book delivery - signed version of Oracle DBA work notes
使用BiSeNet实现自己的数据集
Open3d ISS key points
Opencv learning notes 1 -- several methods of reading images
Deit learning notes
Qinglong panel -- Huahua reading
拓维信息使用 Rainbond 的云原生落地实践
One click installation of highly available Nacos clusters in rainbow
Qinglong panel - today's headlines
单场带货涨粉10万,农村主播竟将男装卖爆单?
Understanding of out covariance, in inversion and invariance in kotlin
雅思考试自己的复习进度以及方法使用【日更版】
Full text query classification
Using helm to install rainbow in various kubernetes
Ebpf cilium practice (1) - team based network isolation
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
Bayes' law
在 Rainbond 中一键安装高可用 Nacos 集群
[IELTS speaking] Anna's oral learning records part2