当前位置:网站首页>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)
}
边栏推荐
- 国标GB28181协议视频平台EasyGBS新增拉流超时配置
- Splunk子查询模糊匹配csv中字段值为*
- Lua programming learning notes
- SSM 整合
- 如何理解分布式架构和微服务架构呢
- DeiT学习笔记
- Use of out covariance and in inversion in kotlin
- One click deployment of highly available emqx clusters in rainbow
- Using helm to install rainbow in various kubernetes
- Four items that should be included in the management system of integral mall
猜你喜欢
Opencv learning notes 1 -- several methods of reading images
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
CTF-WEB shrine模板注入nmap的基本使用
Deit learning notes
Make LIVELINK's initial pose consistent with that of the mobile capture actor
Application of slip ring of shipborne radar antenna
Unityhub cracking & unity cracking
opencv学习笔记五——梯度计算/边缘检测
Avatary's livedriver trial experience
JS copy picture to clipboard read clipboard
随机推荐
【雅思口语】安娜口语学习记录 Part2
Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验
The reified keyword in kotlin is used for generics
Avatary's livedriver trial experience
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
Splunk查询csv lookup table数据动态查询
Rainbow version 5.6 was released, adding a variety of installation methods and optimizing the topology operation experience
Snyk dependency security vulnerability scanning tool
漏洞复现-easy_tornado
[go ~ 0 to 1] obtain timestamp, time comparison, time format conversion, sleep and timer on the seventh day
The single value view in Splunk uses to replace numeric values with text
发挥创客教育空间的广泛实用性
IELTS review progress and method use [daily revision]
Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
CTF-WEB shrine模板注入nmap的基本使用
Automatic upgrading of database structure in rainbow
解析机器人科技发展观对社会研究论
Use of any superclass and generic extension function in kotlin
BiSeNet的特点
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster