当前位置:网站首页>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)
}
边栏推荐
猜你喜欢
随机推荐
PLSQL的安装和配置
Unityhub cracking & unity cracking
Explore creativity in steam art design
Lua 编程学习笔记
Splunk query CSV lookup table data dynamic query
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
GFS distributed file system
Easy to understand SSO
Analysis of maker education in innovative education system
Use of any superclass and generic extension function in kotlin
opencv学习笔记五——梯度计算/边缘检测
机器人教育在动手实践中的真理
使用SwinUnet训练自己的数据集
【雅思口语】安娜口语学习记录 Part2
One click deployment of highly available emqx clusters in rainbow
[untitled]
PVTV2--Pyramid Vision TransformerV2学习笔记
Leetcode simple question: find the K beauty value of a number
在 Rainbond 中一键安装高可用 Nacos 集群