当前位置:网站首页>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)
}
边栏推荐
- 解读创客思维与数学课程的实际运用
- opencv学习笔记五——梯度计算/边缘检测
- Function extension, attribute extension and non empty type extension in kotlin
- 【雅思口语】安娜口语学习记录 Part2
- IELTS review progress and method use [daily revision]
- Opencv learning note 4 - expansion / corrosion / open operation / close operation
- What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
- The largest 3 same digits in the string of leetcode simple question
- [step on the pit series] H5 cross domain problem of uniapp
- 使用BiSeNet实现自己的数据集
猜你喜欢
JS copy picture to clipboard read clipboard
BiSeNet的特點
opencv学习笔记五——梯度计算/边缘检测
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
Deit learning notes
Rsync remote synchronization
Xcit learning notes
CTF-WEB shrine模板注入nmap的基本使用
Excel import function of jeesite form page
随机推荐
Use of JMeter
【雅思口语】安娜口语学习记录 Part3
Function extension, attribute extension and non empty type extension in kotlin
[step on the pit series] H5 cross domain problem of uniapp
PVTV2--Pyramid Vision TransformerV2学习笔记
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
Réplication de vulnérabilité - désrialisation fastjson
Opencv learning note 5 - gradient calculation / edge detection
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
在Rainbond中一键部署高可用 EMQX 集群
Qinglong panel - today's headlines
2-3查找树
Rainbow combines neuvector to practice container safety management
[go ~ 0 to 1] obtain timestamp, time comparison, time format conversion, sleep and timer on the seventh day
藏书馆App基于Rainbond实现云原生DevOps的实践
Famine cloud service management script
The field value in Splunk subquery fuzzy matching CSV is*
Le système mes est un choix nécessaire pour la production de l'entreprise
Practice of implementing cloud native Devops based on rainbow library app
[quick start of Digital IC Verification] 10. Verilog RTL design must know FIFO