当前位置: 首页 > news >正文

Go语言基础:Interface接口、Goroutines线程、Channels通道详细案例教程

目录标题

  • 一、Interface
    • 1. Declaring and implementing an interface
    • 2. Practical use of an interface
    • 3. Nterface internal representation
    • 4. Empty interface
    • 5. Type assertion
    • 6. Type switch
    • 7. Implementing interfaces using pointer receivers VS value receivers
    • 8. Implementing multiple interfaces
    • 9. Embedding interfaces
    • 10. Zero value of Interface
  • 二、Goroutines
    • 1. How to start a Goroutine?
    • 2. Starting multiple Goroutines
  • 三、Channels
    • 1. Declaring channels
    • 2. Channel example program
    • 3. Another example for channels
    • 4. Deadlock
    • 5. Unidirectional channels
    • 6. Closing channels and for range loops on channels

一、Interface

1. Declaring and implementing an interface

        package mainimport "fmt"type VowelsFinder interface {FindVowels() []rune}type MyString stringfunc (ms MyString) FindVowels() []rune {var vowels []runefor _, rune := range ms {if rune == 'a' || rune == 'e' || rune == 'i' || rune == 'o' || rune == 'u' {vowels = append(vowels, rune)}}return vowels}func main() {name := MyString("LiangXiaoQing")var v VowelsFinderv = namefmt.Printf("vowels are %c", v.FindVowels())}// vowels are [i a i a o i]

2. Practical use of an interface

        type SalaryCalculator interface {CalculateSalary() int}type Permanent struct {empId    intbasicapy intpf       int}type Contract struct {empId    intbasicapy int}type Freelancer struct {empId       intratePerHour inttotalHours  int}func (p Permanent) CalculateSalary() int {return p.basicapy + p.pf}func (c Contract) CalculateSalary() int {return c.basicapy}func (f Freelancer) CalculateSalary() int {return f.ratePerHour * f.totalHours}func totalExpense(s []SalaryCalculator) {expense := 0for _, v := range s {expense = expense + v.CalculateSalary()		// 循环添加每个值}fmt.Printf("Total Expense Per Month $%d", expense)}func main() {p1 := Permanent{empId:    1,basicapy: 4999,pf:       10,}p2 := Permanent{empId:    2,basicapy: 5999,pf:       20,}c1 := Contract{empId:    3,basicapy: 3000,}f1 := Freelancer{empId:       4,ratePerHour: 77,totalHours:  666,}f2 := Freelancer{empId:       5,ratePerHour: 66,totalHours:  111,}employees := []SalaryCalculator{p1, p2, c1, f1, f2}fmt.Println(employees)totalExpense(employees)}// [{1 4999 10} {2 5999 20} {3 3000} {4 77 666} {5 66 111}]// Total Expense Per Month $72636

3. Nterface internal representation

        type Worker interface {Work()}type Person struct {name string}func (p Person) Work() {fmt.Println(p.name, "is Working")}func describe(w Worker) {fmt.Printf("Interface type %T value %v\n", w, w)}func main() {p := Person{name: "Like",}var w Worker = pdescribe(w)w.Work()}// Interface type main.Person value {Like}// Like is Working

4. Empty interface

        func describe(i interface{}) {fmt.Printf("type = %T, value= %v\n", i, i)}func main() {s := "Hello World"describe(s)i := 55describe(i)strt := struct {name string}{name: "Like",}describe(strt)}// type = string, value= Hello World// type = int, value= 55// type = struct { name string }, value= {Like}

5. Type assertion

        func assert(i interface{}) {s := i.(int)fmt.Println(s)//v, s := i.(int)//fmt.Println(v, s) // 56, true 如果是两个值 则是值和true or false}func main() {var i interface{} = 56assert(i) // 56var s interface{} = "Like"assert(s) // panic: interface conversion: interface {} is string, not int}

6. Type switch

        func findType(i interface{}) {switch i.(type) {case string:fmt.Printf("I am string and my value is %s\n", i.(string))case int:fmt.Printf("I am an int and my value is %d\n", i.(int))default:fmt.Printf("Unknown type\n")}}func main() {findType("Like")findType(666)findType(66.99)}// I am string and my value is Like// I am an int and my value is 666// Unknown type

7. Implementing interfaces using pointer receivers VS value receivers

        package mainimport "fmt"type Describer interface {Describe()}type Person struct {name stringage  int}type Address struct {state   stringcountry string}func (p Person) Describe() {fmt.Printf("%s is %d years old\n", p.name, p.age)}func (a *Address) Describe() {fmt.Printf("State %s Counrty %s", a.state, a.country)}func main() {var d1 Describerp1 := Person{"Like", 11}d1 = p1d1.Describe() // Like is 11 years oldp2 := Person{"Jack", 22}d1 = &p2      //{Jack 22}d1.Describe() // Jack is 22 years oldvar d2 Describera := Address{"LiangXiaoXiao", "China"}d2 = &ad2.Describe() // State LiangXiaoXiao Counrty China}// Like is 11 years old// Jack is 22 years old// State LiangXiaoXiao Counrty China`

8. Implementing multiple interfaces

        type SalaryCalculators interface {DisplaySalary()}type LeaveCalculator interface {CalculateLeavesLeft() int}type Employee struct {firstName   stringlastName    stringbasicPay    intpf          inttotalLeaves intleavesTaken int}func (e Employee) DisplaySalary() {fmt.Printf("%s %s has salary $%d", e.firstName, e.lastName, (e.basicPay + e.pf))}func (e Employee) CalculateLeavesLeft() int {return e.totalLeaves - e.leavesTaken}func main() {e := Employee{firstName:   "Naveen",lastName:    "Ramanathan",basicPay:    5000,pf:          200,totalLeaves: 30,leavesTaken: 5,}var s SalaryCalculators = es.DisplaySalary()var l LeaveCalculator = efmt.Println("\nLeaves left =", l.CalculateLeavesLeft())}// Naveen Ramanathan has salary $5200// Leaves left = 25

9. Embedding interfaces

        type SalaryCalculators interface {DisplaySalary()}type LeaveCalculator interface {CalculateLeavesLeft() int}type EmployeeOperations interface {SalaryCalculatorsLeaveCalculator}type Employee struct {firstName   stringlastName    stringbasicPay    intpf          inttotalLeaves intleavesTaken int}func (e Employee) DisplaySalary() {fmt.Printf("%s %s has salary $%d", e.firstName, e.lastName, (e.basicPay + e.pf))}func (e Employee) CalculateLeavesLeft() int {return e.totalLeaves - e.leavesTaken}func main() {e := Employee{firstName:   "Naveen",lastName:    "Ramanathan",basicPay:    5000,pf:          200,totalLeaves: 30,leavesTaken: 5,}var s EmployeeOperations = es.DisplaySalary()fmt.Println("\nLeaves left =", s.CalculateLeavesLeft())}// Naveen Ramanathan has salary $5200// Leaves left = 25

10. Zero value of Interface

        package mainimport "fmt"type Describer interface {  Describe()}func main() {  var d1 Describerif d1 == nil {fmt.Printf("d1 is nil and has type %T value %v\n", d1, d1)}}// d1 is nil and has type <nil> value <nil> 

二、Goroutines

1. How to start a Goroutine?

        package mainimport ("fmt""time")func hello() {fmt.Println("Hello world goroutine")}func main() {go hello()                  // 没有等待完成就下一步了time.Sleep(1 * time.Second) // 优化添加io操作 则看见了运行hello的输入fmt.Println("main function")}

2. Starting multiple Goroutines

        package mainimport (  "fmt""time")func numbers() {  for i := 1; i <= 5; i++ {time.Sleep(250 * time.Millisecond)fmt.Printf("%d ", i)}}func alphabets() {  for i := 'a'; i <= 'e'; i++ {time.Sleep(400 * time.Millisecond)fmt.Printf("%c ", i)}}func main() {  go numbers()go alphabets()time.Sleep(3000 * time.Millisecond)fmt.Println("main terminated")}// 1a23b4c5deMain Terminated

三、Channels

1. Declaring channels

        package mainimport "fmt"func main() {var a chan intif a == nil {fmt.Println("Channel a is nil, going to define it")a = make(chan int)fmt.Printf("Type of a is %T", a)}}// Channel a is nil, going to define it// Type of a is chan int

2. Channel example program

        package mainimport ("fmt""time")func hello(done chan bool) {fmt.Println("Hello go routine is going to sleep")time.Sleep(4 * time.Second)fmt.Println("hello go routine awake and going to write to done")done <- true // 将 true发送给done通道 表示hello结束运行}func main() {done := make(chan bool) // 创建done通道 bool类型fmt.Println("Main going to call hello go goroutine")go hello(done) // 启动goroutine线程并发 不会阻塞主线程 运行hello<-done         //  done 通道接收数据 阻塞操作 直到接收到数据为止 hello发送了true解除阻塞time.Sleep(1 * time.Second)fmt.Println("Main received data")}// Main going to call hello go goroutine// Hello go routine is going to sleep// hello go routine awake and going to write to done// Main received data

3. Another example for channels

        package mainimport (  "fmt")func calcSquares(number int, squareop chan int) {  sum := 0for number != 0 {digit := number % 10sum += digit * digitnumber /= 10}squareop <- sum}func calcCubes(number int, cubeop chan int) {  sum := 0 for number != 0 {digit := number % 10sum += digit * digit * digitnumber /= 10}cubeop <- sum} func main() {  number := 589sqrch := make(chan int)cubech := make(chan int)go calcSquares(number, sqrch)go calcCubes(number, cubech)squares, cubes := <-sqrch, <-cubechfmt.Println("Final output", squares + cubes)}// Final output 1536  

4. Deadlock

        package mainfunc main() {  ch := make(chan int)ch <- 5}// fatal error: all goroutines are asleep - deadlock!// goroutine 1 [chan send]:// main.main()//        D:/one/channel.go:34 +0x31

5. Unidirectional channels

        func sendData(sendch chan<- int) {sendch <- 10}func main() {chnl := make(chan int)go sendData(chnl)fmt.Println(<-chnl) // 接收数据 并打印}// 10

6. Closing channels and for range loops on channels

        func producer(chnl chan int) {for i := 0; i < 10; i++ {chnl <- i}close(chnl)}func main() {ch := make(chan int)go producer(ch)for {v, ok := <-chfmt.Println(v, ok)if ok == false {break}fmt.Println("Received", v, ok)}}// Received  0 true  // Received  1 true  // Received  2 true  // Received  3 true  // Received  4 true  // Received  5 true  // Received  6 true  // Received  7 true  // Received  8 true  // Received  9 true 

相关文章:

Go语言基础:Interface接口、Goroutines线程、Channels通道详细案例教程

目录标题 一、Interface1. Declaring and implementing an interface2. Practical use of an interface3. Nterface internal representation4. Empty interface5. Type assertion6. Type switch7. Implementing interfaces using pointer receivers VS value receivers8. Impl…...

Cesium加载ArcGIS Server4490且orgin -400 400的切片服务

Cesium在使用加载Cesium.ArcGisMapServerImageryProvider加载切片服务时&#xff0c;默认只支持wgs84的4326坐标系&#xff0c;不支持CGCS2000的4490坐标系。 如果是ArcGIS发布的4490坐标系的切片服务&#xff0c;如果原点在orgin X: -180.0Y: 90.0的情况下&#xff0c;我们可…...

Objectarx 2021使用vs2019生成报错 /RTCc rejects conformant code

error C2338: /RTCc rejects conformant code错误解决 使用VS2019/VS2022生成项目报错 严重性 代码 说明 项目 文件 行 禁止显示状态 错误 C1189 #error: /RTCc rejects conformant code, so it is not supported by the C Standard Library. Either remove this compiler opti…...

QT中使用QtXlsx库的三种方法 QT基础入门【Excel的操作】

对于Linux用户,如果Qt是通过“ apt-get”之类的软件包管理器工具安装的,请确保已安装Qt5开发软件包qtbase5-private-dev QtXlsx是一个可以读写Excel文件的库。它不需要Microsoft Excel,可以在Qt5支持的任何平台上使用。该库可用于从头开始生成新的.xlsx文件从现有.xlsx文件中…...

容器和云原生(二):Docker容器化技术

目录 Docker容器的使用 Docker容器关键技术 Namespace Cgroups UnionFS Docker容器的使用 首先直观地了解docker如何安装使用&#xff0c;并快速启动mysql服务的&#xff0c;启动时候绑定主机上的3306端口&#xff0c;查找mysql容器的ip&#xff0c;使用mysql -h contain…...

学习总结(TAT)

项目写完了&#xff0c;来写一个总的总结啦&#xff1a; 1.后期错误 Connection&#xff0c;Statement&#xff0c;Prestatement&#xff0c;ResultSet都要记得关闭接口&#xff1b;&#xff08;一定要按顺序关闭&#xff09;&#xff1b; 在写群聊的时候写数据库名的时候不要…...

2023java异常之八股文——面试题

Java异常架构与异常关键字 Java异常简介 Java异常是Java提供的一种识别及响应错误的一致性机制。 Java异常机制可以使程序中异常处理代码和正常业务代码分离&#xff0c;保证程序代码更加优雅&#xff0c;并提高程序健壮性。在有效使用异常的情况下&#xff0c;异常能清晰的…...

数据可视化和数字孪生相互促进的关系

数据可视化和数字孪生是当今数字化时代中备受关注的两大领域&#xff0c;它们在不同层面和领域为我们提供了深入洞察和智能决策的机会&#xff0c;随着两种技术的不断融合发展&#xff0c;很多人会将他们联系在一起&#xff0c;本文就带大家浅谈一下二者之间相爱相杀的关系。 …...

axios使用axiosSource.cancel取消请求后怎么恢复请求,axios取消请求和恢复请求实现

在前端做大文件分片上传&#xff0c;或者其它中断请求时&#xff0c;需要暂停或重新请求&#xff0c;比如这里大文件上传时&#xff0c;可能会需要暂停、继续上传&#xff0c;如下GIF演示&#xff1a; 这里不详细说文件上传的处理和切片细节&#xff0c;后续有时间在出一篇&a…...

SAP动态安全库存简介

动态安全库存:跑需求计划时,ERP系统按设置的库存方式自动计算出满足一定时间内可保障生产的库存数量 SAP动态安全库存的计算公式:动态安全库存=平均日需求*覆盖范围。 平均日需求=特定时期内的总需求/特定时期内的工作天数 覆盖范围指在没又货物供应的情况下,库存可以维…...

JVM基础了解

JVM 是java虚拟机。 作用&#xff1a;运行并管理java源码文件锁生成的Class文件&#xff1b;在不同的操作系统上安装不同的JVM&#xff0c;从而实现了跨平台的保证。一般在安装完JDK或者JRE之后&#xff0c;其中就已经内置了JVM&#xff0c;只需要将Class文件交给JVM即可 写好的…...

QT:event事件分发器,事件过滤器(了解)

Event事件分发器 用于事件的分发 可以用事件分发器做拦截&#xff0c;从而不进入到后面的虚函数中&#xff0c;但是不建议 bool event(QEvent *e); 返回值 如果是true 代表用户处理这个事件&#xff0c;不向下进行分发 e->type&#xff08;&#xff09;中可选择进行拦截的类…...

若依项目的介绍(前后端分离版本)

目录 一、若依介绍 &#xff08;一&#xff09;简单介绍 &#xff08;二&#xff09;若依版本 &#xff08;三&#xff09;Git远程拉取步骤 二、项目的技术介绍 &#xff08;一&#xff09;后端技术 1.spring boot 2.Spring Security安全控制 3.MyBatis 4.MySQL和R…...

DT游乐场建模

丢了一个...

Servlet+JDBC实战开发书店项目讲解第9篇:VIP等级优惠实现

ServletJDBC实战开发书店项目讲解第9篇&#xff1a;VIP等级优惠实现 介绍 在这篇博客中&#xff0c;我们将讲解如何在书店项目中实现VIP等级优惠功能。VIP等级优惠是一种常见的商业策略&#xff0c;可以吸引更多的顾客并提高销售额。我们将使用Servlet和JDBC来实现这个功能。…...

Azure文件共享

什么是Azure文件共享 Azure文件共享是一种在云中存储和访问文件的服务。它允许用户在不同的计算机、虚拟机和服务之间共享数据&#xff0c;并在应用程序中进行访问、修改和管理。 Azure文件共享可以用于各种用途&#xff0c;例如&#xff1a; 共享文件资源给多个虚拟机或服务…...

idea新建web项目

步骤一 步骤二 步骤三 新建两个目录lib、classes 步骤四 设置两个目录的功能lib、classes 步骤五 发布到tomcat...

回归预测 | MATLAB实现BES-SVM秃鹰搜索优化算法优化支持向量机多输入单输出回归预测(多指标,多图)

回归预测 | MATLAB实现BES-SVM秃鹰搜索优化算法优化支持向量机多输入单输出回归预测&#xff08;多指标&#xff0c;多图&#xff09; 目录 回归预测 | MATLAB实现BES-SVM秃鹰搜索优化算法优化支持向量机多输入单输出回归预测&#xff08;多指标&#xff0c;多图&#xff09;效…...

电商增强现实3D模型优化需要关注的4个方面

到目前为止&#xff0c;AR技术已经发展到足以在更广泛的范围内实施。 在电子商务中&#xff0c;这项技术有望提供更令人兴奋的购物体验。 为了实现这一目标&#xff0c;在这篇博客中&#xff0c;我将介绍如何针对电子商务中的 AR 优化 3D 模型。 推荐&#xff1a;用 NSDT编辑器…...

【Effective Python】读书笔记-04推导与生成

1. 用列表推导取代 map 与 filter 因为不需要写 lambda 表达式。 可以很容易地跳过原列表中的某些数据。 # 列表推导l [i for i in range(5)] # [0, 1, 2, 3, 4] print(l)# 字典推导d {i: i ** 2 for i in range(5)} # {0: 0, 1: 1, 2: 4, 3: 9, 4: 16} print(d)2. 控制推导…...

Android内存泄漏总结和性能优化技巧

我们在开发安卓应用时&#xff0c;性能优化是非常重要的方面。一方面&#xff0c;优化可以提高应用的响应速度、降低卡顿率和提升应用流畅度&#xff0c;从而提升用户体验&#xff1b;另一方面&#xff0c;优化也可以减少应用的资源占用&#xff0c;提高应用的稳定性和安全性&a…...

leetcode 125.验证回文串

⭐️ 题目描述 &#x1f31f; leetcode链接&#xff1a;https://leetcode.cn/problems/valid-palindrome/ 思路&#xff1a; 这道题只判断字符串中的字母与数字是否是回文。虽然小写大写字母可以互相转换&#xff0c;但是里面是含有数字字符的&#xff0c;所以先统一&#xff…...

ZooKeeper客户端使用与经典应用场景

概述 ZooKeeper的应用场景依赖于ZNode节点特性和Watch监听机制。 应用场景 数据发布/订阅 常用于实现配置中心&#xff0c;类似的有nacos。数据发布/订阅的一个常见的场景是配置中心&#xff0c;发布者把数据发布到ZooKeeper的一个或一系列的节点上&#xff0c;供订阅者进行…...

标签准备——labelIMG工具使用——自动化标注

在实际生产项目中,为了提升目标识别的准确性,我们往往需要3000-5000张图片进行标注。而直接参与过标注的人都有一个共同的感觉,就是标注是一个简单、枯燥、无聊且十分耗时费力的差事。为此,我们可以在有了初步训练模型的基础上,采用更加自动化的方式进行标注,届时,你讲不…...

关于vant2 组件van-dropdown-item,在IOS手机上,特定条件下无法点击问题的探讨

情景重现 先贴有问题的代码 <template><div :class"showBar ? homeContain : homeContain-nobar"><div class"contant" id"content"><van-dialog v-model"loading" :before-close"onBeforeClose" :…...

一零七一、Spring大海捞针篇

IOC&#xff0c;AOP&#xff1f; IOC&#xff08;控制反转&#xff09;是一种设计模式&#xff0c;它将对象的创建、依赖注入和管理交给了容器来完成&#xff0c;而不是由开发者手动管理。 这样做的好处是降低了组件之间的耦合度&#xff0c;提高了代码的可维护性和可扩展性。 …...

请求并发控制

请求并发数量控制 并发限制 要求&#xff1a;多个请求做并发限制&#xff0c;请求完成后执行回调 思路&#xff1a; 首次循环启动能够执行的任务 取出能执行的任务推入执行器执行 执行器更新当前并发数&#xff0c;并且再请求完成时继续取出任务推入执行器 当所有请求完…...

创建密码库/创建用户帐户/更新 Ansible 库的密钥/ 配置cron作业

目录 创建密码库 创建用户帐户 更新 Ansible 库的密钥 配置cron作业 创建密码库 按照下方所述&#xff0c;创建一个 Ansible 库来存储用户密码&#xff1a; 库名称为 /home/curtis/ansible/locker.yml 库中含有两个变量&#xff0c;名称如下&#xff1a; pw_developer&#…...

vue实现穿梭框,ctrl多选,shift多选

效果图 代码 <template><div class"container"><!--左侧--><div><div class"title">{{ titles[0] }}</div><div class"layerContainer"><div v-for"item in leftLayerArray":key"…...

Win11中zookeeper的下载与安装

下载步骤 打开浏览器&#xff0c;前往 Apache ZooKeeper 的官方网站&#xff1a;zookeeper官方。在主页上点击"Project"选项&#xff0c;并点击"Release" 点击Download按钮&#xff0c;跳转到下载目录 在下载页面中&#xff0c;选择版本号&#xff0c;并点…...

ubuntu22.04 找不到串口,串口ttyusb时断时续的问题(拔插以后能检测到,过会儿就检测不到了)

1. 问题描述 ubuntu22.04的PC&#xff0c;在连接USB串口的时候&#xff0c;有时能找到ttyUSB0,有时找不到&#xff0c;如下&#xff1a; base) airsairs-Precision-3630-Tower:~$ ls -l /dev/ttyUSB* crwxrwxrwx 1 root dialout 188, 0 Aug 17 16:36 /dev/ttyUSB0 (base) air…...

Pinia基础教程

Pinia wiki Pinia 起始于 2019 年 11 月左右的一次实验&#xff0c;其目的是设计一个拥有组合式 API 的 Vue 状态管理库。从那时起&#xff0c;我们就倾向于同时支持 Vue 2 和 Vue 3&#xff0c;并且不强制要求开发者使用组合式 API&#xff0c;我们的初心至今没有改变。除了安…...

【NOIP】标题统计

author&#xff1a;&Carlton tags&#xff1a;模拟&#xff0c;字符串 topic&#xff1a;【NOIP】标题统计 language&#xff1a;C website&#xff1a;P5015 [NOIP2018 普及组] 标题统计 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) date&#xff1a;2023年8月20日…...

BOXTRADE-天启量化分析平台 系统功能预览

BOXTRADE-天启量化分析平台 系统功能预览 系统功能预览 1.登录 首页 参考登录文档 2. A股 行情与策略分析 2.1 A股股票列表 可以筛选和搜索 2.2 A股行情及策略回测 2.2.1 行情数据提供除权和前复权&#xff0c;后复权数据&#xff1b;外链公司信息 2.2.2 内置策略执行结果…...

解决Kibana(OpenSearch)某些字段无法搜索问题

背景 最近在OpenSearch查看线上日志的时候&#xff0c;发现某个索引下有些字段无法直接在界面上筛选&#xff0c;搜索到也不高亮&#xff0c;非常的不方便&#xff0c;就像下面这样 字段左侧两个筛选按钮禁用了无法点击&#xff0c;提示 Unindexed fields can not be searched…...

代码随想录训练营day15|102.层序遍历 226.翻转二叉树 101.对称二叉树

TOC 前言 代码随想录算法训练营day15 一、Leetcode 102.层序遍历 1.题目 给你二叉树的根节点 root &#xff0c;返回其节点值的 层序遍历 。 (即逐层地&#xff0c;从左到右访问所有节点)。 示例 1&#xff1a; 输入&#xff1a;root [3,9,20,null,null,15,7] 输出&#xff1a…...

Nginx 配置https以及wss

一、申请https证书 可以在阿里云申请免费ssl证书&#xff0c;一年更换一次 二、Nginx配置ssl upstream tomcat_web{server 127.0.0.1:8080; }server {listen 443 ssl;server_name www.xxx.com;## 配置日志文件access_log /var/log/nginx/web/xxx-ssl-access.log main;er…...

Log4net在.Net Winform项目中的使用

引言&#xff1a; Log4net是一个流行的日志记录工具&#xff0c;可以帮助开发人员在应用程序中实现高效的日志记录。本文将提供一个详细的分步骤示例&#xff0c;来帮助您在.Net Winform项目中使用Log4net。 目录 一、安装Log4net二、配置Log4net三、在项目中使用Log4net四、初…...

从零到一制作扫雷游戏——C语言

什么是扫雷游戏&#xff1f; 扫雷游戏作为一种老少咸宜的益智游戏&#xff0c; 它的游戏目标十分简单&#xff0c;就是要求玩家在最短的时间内&#xff0c; 根据点击格子之后所出现的数字来找出所有没有炸弹的格子&#xff0c; 同时在找的时候要避免点到炸弹&#xff0c;一…...

Python 数据挖掘与机器学习教程

详情点击链接&#xff1a;Python 数据挖掘与机器学习教程 模块一&#xff1a;Python编程 Python编程入门 1、Python环境搭建&#xff08; 下载、安装与版本选择&#xff09;。 2、如何选择Python编辑器&#xff1f;&#xff08;IDLE、Notepad、PyCharm、Jupyter…&#xff…...

排序小白必读:掌握插入排序的基本原理

一、插入排序是什么&#xff1f; 它是一种简单直观的排序算法。类似于整理扑克牌&#xff0c;想象你手上有一堆未排序的牌&#xff0c;你将它们逐个插入已排序的牌堆中的正确位置。拿起一张牌&#xff0c;与已排序的牌进行比较&#xff0c;将它插入到合适的位置。重复这个过程…...

html常见兼容性问题

1. png24位的图片在iE6浏览器上出现背景 解决方案&#xff1a;做成PNG8&#xff0c;也可以引用一段脚本处理. 2. 浏览器默认的margin和padding不同 解决方案&#xff1a;加一个全局的 *{margin:0;padding:0;} 来统一。 3. IE6双边距bug&#xff1a;在IE6下&#xff0c;如果对…...

Docker实战:docker compose 搭建Redis

1、配置文件准备 redis 配置文件&#xff1a;https://pan.baidu.com/s/1YreI9_1BMh8XRyyV9BH08g2、创建目录并赋权 mkdir -p /home/docker/redis/data /home/redis/logs /home/redis/conf chmod -R 777 /home/docker/redis/data* chmod -R 777 /home/docker/redis/logs*3、re…...

Debian11 Crontab

Crontab用户命令 可执行文件 crontab命令的可执行文件在哪儿&#xff1f; $ which -a crontab /usr/bin/crontab /bin/crontabcrontab命令的可执行文件有2个&#xff1a;/usr/bin/crontab 和 /bin/crontab $ diff /usr/bin/crontab /bin/crontab $diff 发现这两个文件并无区…...

css 文字排版-平铺

序&#xff1a; 1、表格的宽度要有&#xff01;&#xff01;&#xff01;&#xff01;&#xff01; 2、容器不能是display:inline 3、扩展---》node全栈框架 代码 text-align-last: justify; width: 70px; display: inline-block; 主要是用于表单左侧文字排序&#xff01;...

把握潮流:服装定制小程序的发展与趋势

随着互联网的快速发展&#xff0c;小程序成为了人们生活中不可或缺的一部分。尤其在服装行业&#xff0c;定制化已经成为了一种趋势。为了满足消费者个性化的需求&#xff0c;服装定制小程序应运而生。 为了方便开发者的设计和制作&#xff0c;我们可以使用第三方的制作平台来创…...

Go 安装配置

介绍Ubuntu20.04 安装和配置Go 可以参考官网的这个为 Go 开发配置Visual Studio Code - Go on Azure | Microsoft Learn 1.安装Go 去这个地方下载Go https://go.dev/doc/install 如果之前安装过&#xff0c;可以参考这个&#xff08;没有可以忽略&#xff09; 下载完成后执…...

镜像底层原理详解和基于Docker file创建镜像

目录 一、镜像底层原理 1.联合文件系统(UnionFS) 2.镜像加载原理 3.为什么Docker里的centos的大小才200M? 二、Dockerfile 1.简介 2.Dockerfile操作常用命令 &#xff08;1&#xff09;FORM 镜像 &#xff08;2&#xff09;MAINTAINER 维护人信息 &#xff08;3&…...

k8s扩缩容与滚动更新

使用kubectl run创建应用 kubectl run kubernetes-bootcamp \> --imagedocker.io/jocatalin/kubernetes-bootcamp:v1 \> --port8080 端口暴露出去 kubectl expose pod kubernetes-bootcamp --type"NodePort" --port 8080 使用kubectl create创建应用 kubect…...

4.小程序的运行机制

启动过程 把小程序的代码包下载到本地解析app.json全局配置文件执行app.js小程序入口文件&#xff0c;调用App()创建小程序的实例渲染小程序首页小程序启动完成 页面渲染过程 加载解析页面的.json配置文件加载页面.wxml模板和.scss样式执行页面的.ts文件&#xff0c;调用Pag…...