go-zero整合Excelize并实现Excel导入导出

news2024/10/6 10:37:47

go-zero整合Excelize并实现Excel导入导出

本教程基于go-zero微服务入门教程,项目工程结构同上一个教程。

本教程主要实现go-zero框架整合Excelize,并暴露接口实现Excel模板下载、Excel导入、Excel导出。

go-zero微服务入门教程:https://blog.csdn.net/u011019141/article/details/136233473

本文源码:https://gitee.com/songfayuan/go-zero-demo (教程源码分支:6.zero整合Excelize操作Excel)

准备工作

  • 如不熟悉go-zero项目的,请先查看上一篇go-zero微服务入门教程

安装依赖

Excelize官方文档

项目工程父级目录下执行如下指令安装依赖:

# 下载安装Excelize
go get github.com/xuri/excelize/v2

编写API Gateway代码

编写api文件

excel.api

在api目录下创建新目录doc/excel,在excel目录下创建excel.api文件。

syntax = "v1"

info(
    title: "excel操作相关"
    desc: "excel操作相关"
    author: "宋发元"
)

type (
    ExcelImportReq {
        DeptId string `json:"deptId"`            // 部门id(Content-Type: form-data)
        File interface{} `json:"file,optional"`  // excel文件(Content-Type: form-data)
    }

    ExcelImportData {
        Total int64 `json:"total"`      // 导入总数
        Success int64 `json:"success"`  // 导入成功数
        Msg string `json:"msg"`         // 提示信息
    }

    ExcelImportResp {
        Code int64 `json:"code"`
        Message string `json:"message"`
        Data ExcelImportData `json:"data"`
    }

    ExcelExportlReq{
        TimeStart string `form:"timeStart,optional"`                      // 时间(开始) yyyy-mm-dd
        TimeEnd   string `form:"timeEnd,optional"`                        // 时间(结束) yyyy-mm-dd
    }

    DefaultResponse {
        Code    int64  `json:"code,default=200"`
        Message string `json:"message,default=操作成功"`
    }
)


@server(
    group : excel/test
    prefix : /excel/test
)

service admin-api {
    @doc (
        summary :"excel模板下载"
    )
    @handler ExcelTemplateDownload
    get /excel/templateDownload

    @doc(
        summary :"excel导入"
    )
    @handler ExcelImport
    post /excel/excelImport (ExcelImportReq) returns (ExcelImportResp)

    @doc(
        summary :"excel导出"
    )
    @handler ExcelExport
    get /excel/excelExport (ExcelExportlReq)returns (DefaultResponse)
}
admin.api

在api/doc/admin.api文件添加配置信息。

import "excel/excel.api"

用goctl生成API Gateway代码

生成方法同上篇文章,自行查看。但是此处要基于admin.api文件去生成代码,如果基于excel.api生成,则生成的代码只有excel.api定义的接口代码,其他api文件定义的接口代码不被生成。

api新增文件操作配置

以下操作在api模块执行。

admin-api.yaml

admin-api.yaml配置文件新增文件操作配置信息,如下:

#文件
UploadFile:
  MaxFileNum: 100
  MaxFileSize: 104857600  # 100MB
  SavePath: template/uploads/
  TemplatePath: template/excel/

config.go

config.go文件中新增UploadFile配置信息,如下:

type Config struct {
	rest.RestConf

	SysRpc zrpc.RpcClientConf

  //这里新增
	UploadFile UploadFile
}

type UploadFile struct {
	MaxFileNum   int64
	MaxFileSize  int64
	SavePath     string
	TemplatePath string
}

修改API Gateway代码

exceltemplatedownloadlogic.go

修改api/internal/logic/excel/test/exceltemplatedownloadlogic.go里的ExcelTemplateDownload方法,完整代码如下:

package test

import (
	"context"
	"go-zero-demo/common/errors/errorx"
	"net/http"
	"os"

	"github.com/zeromicro/go-zero/core/logx"
	"go-zero-demo/api/internal/svc"
)

type ExcelTemplateDownloadLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
	writer http.ResponseWriter
}

func NewExcelTemplateDownloadLogic(ctx context.Context, svcCtx *svc.ServiceContext, writer http.ResponseWriter) *ExcelTemplateDownloadLogic {
	return &ExcelTemplateDownloadLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
		writer: writer,
	}
}

func (l *ExcelTemplateDownloadLogic) ExcelTemplateDownload() (err error) {
	SavePath := l.svcCtx.Config.UploadFile.TemplatePath
	filePath := "demo_excel_template.xlsx"

	fullPath := SavePath + filePath
	fileName := "Excel导入模板.xlsx"

	//fullPath = "/Users/songfayuan/GolandProjects/go-zero-demo/template/excel/demo_excel_template.xlsx"  //测试地址,绝对路径
	_, err = os.Stat(fullPath)
	if err != nil || os.IsNotExist(err) {
		return errorx.New("文件不存在")
	}
	bytes, err := os.ReadFile(fullPath)
	if err != nil {
		return errorx.New("读取文件失败")
	}

	l.writer.Header().Add("Content-Type", "application/octet-stream")
	l.writer.Header().Add("Content-Disposition", "attachment; filename= "+fileName)
	l.writer.Write(bytes)

	return
}

excelimportlogic.go

修改api/internal/logic/excel/test/excelimportlogic.go里的ExcelImport方法,完整代码如下:

package test

import (
	"context"
	"fmt"
	"github.com/xuri/excelize/v2"
	"github.com/zeromicro/go-zero/core/mapping"
	"go-zero-demo/common/errors/errorx"
	"go-zero-demo/common/utils"
	"path/filepath"
	"strings"

	"go-zero-demo/api/internal/svc"
	"go-zero-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ExcelImportLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

type excelDataForDept struct {
	DeptId       string `json:"DeptId,optional" excel:"col=1"`       // 第1列:部门id
	ParentDeptId string `json:"ParentDeptId,optional" excel:"col=2"` // 第2列:上级部门id
	DeptName     string `json:"DeptName,optional" excel:"col=3"`     // 第3列:部门名称
	Level        string `json:"Level,optional" excel:"col=4"`        // 第4列:部门等级(分级名称)
}

type excelDataForMember struct {
	DeptId  string `json:"DeptId,optional" excel:"col=1"`  // 第1列:部门
	Name    string `json:"Name,optional" excel:"col=2"`    // 第2列:姓名
	Account string `json:"Account,optional" excel:"col=3"` // 第3列:帐号
	Level   string `json:"Level,optional" excel:"col=4"`   // 第4列:等级(分级名称)
	IpAddr  string `json:"IpAddr,optional" excel:"col=5"`  // 第5列:IP
	MacAddr string `json:"MacAddr,optional" excel:"col=6"` // 第6列:MAC
}

var (
	validUploadFileExt = map[string]any{
		".xlsx": nil,
		".xls":  nil,
	}
)

func NewExcelImportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ExcelImportLogic {
	return &ExcelImportLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ExcelImportLogic) ExcelImport(req *types.ExcelUploadReq) (resp *types.ExcelImportResp, err error) {

	if _, ok := validUploadFileExt[strings.ToLower(filepath.Ext(req.File.FileHeader.Filename))]; !ok {
		return nil, errorx.New("无效的文件格式")
	}
	// 打开文件
	f, err := excelize.OpenReader(req.File.File)
	if err != nil {
		return nil, errorx.New("无效的文件")
	}

	/* 解析部门Sheet数据 start */
	// 解析文件参数
	var excelDept []excelDataForDept
	if excelDept, err = parseFileDept(f); err != nil {
		return
	}
	// format
	for _, i := range excelDept {
		fmt.Printf("Excel数据:%v/%v/%v/%v", i.DeptId, i.ParentDeptId, i.DeptName, i.Level)
	}
	/* 解析部门Sheet数据 end */

	/* 解析用户Sheet数据 start */
	// 解析文件参数
	var excelMember []excelDataForMember
	if excelMember, err = parseFileUser(f); err != nil {
		return
	}
	// format
	for _, i := range excelMember {
		fmt.Printf("Excel数据:%v/%v/%v/%v/%v/%v", i.DeptId, i.Name, i.Account, i.Level, i.IpAddr, i.MacAddr)
	}
	/* 解析用户Sheet数据 end */

	return &types.ExcelImportResp{
		Code:    200,
		Message: "导入成功",
		Data: types.ExcelImportData{
			Total:   10,
			Success: 10,
			Msg:     "成功",
		},
	}, nil
}

// 解析部门Sheet数据
func parseFileDept(f *excelize.File) ([]excelDataForDept, error) {

	// 解析参数(可选)
	excelOption := utils.ExcelOption{Sheet: "部门", StartRow: 2}

	// 映射回调
	all := make([]excelDataForDept, 0)
	cbHandler := func(data map[string]interface{}) error {
		temp := excelDataForDept{}
		err := mapping.UnmarshalJsonMap(data, &temp)
		if err != nil {
			return err
		}
		all = append(all, temp)
		return nil
	}

	// 映射
	if err := utils.ParseExcel(f, excelDataForDept{}, cbHandler, excelOption); err != nil {
		return nil, errorx.New("解析文件时出错:" + err.Error())
	}

	if len(all) == 0 {
		return nil, errorx.New("文件中无有效数据")
	}

	return all, nil
}

// 解析用户Sheet数据
func parseFileUser(f *excelize.File) ([]excelDataForMember, error) {
	// 解析参数(可选)
	excelOption := utils.ExcelOption{Sheet: "用户", StartRow: 2}

	// 映射回调
	all := make([]excelDataForMember, 0)
	cbHandler := func(data map[string]interface{}) error {
		temp := excelDataForMember{}
		err := mapping.UnmarshalJsonMap(data, &temp)
		if err != nil {
			return err
		}
		all = append(all, temp)
		return nil
	}

	// 映射
	if err := utils.ParseExcel(f, excelDataForMember{}, cbHandler, excelOption); err != nil {
		return nil, errorx.New("解析文件时出错:" + err.Error())
	}

	if len(all) == 0 {
		return nil, errorx.New("文件中无有效数据")
	}

	return all, nil
}

excelexportlogic.go

修改api/internal/logic/excel/test/excelexportlogic.go里的ExcelExport方法,完整代码如下:

package test

import (
	"context"
	"fmt"
	"github.com/xuri/excelize/v2"
	"net/http"

	"go-zero-demo/api/internal/svc"
	"go-zero-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ExcelExportLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
	writer http.ResponseWriter
}

type cellValue struct {
	sheet string
	cell  string
	value string
}

func NewExcelExportLogic(ctx context.Context, svcCtx *svc.ServiceContext, writer http.ResponseWriter) *ExcelExportLogic {
	return &ExcelExportLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
		writer: writer,
	}
}

func (l *ExcelExportLogic) ExcelExport(req *types.ExcelExportlReq) (resp *types.DefaultResponse, err error) {
	//这里仅演示Excel导出逻辑,真实数据自己增加对应的查询逻辑。
	excelFile := excelize.NewFile()
	//insert title
	cellValues := make([]*cellValue, 0)
	cellValues = append(cellValues, &cellValue{
		sheet: "sheet1",
		cell:  "A1",
		value: "序号",
	}, &cellValue{
		sheet: "sheet1",
		cell:  "B1",
		value: "IP地址",
	}, &cellValue{
		sheet: "sheet1",
		cell:  "C1",
		value: "账号",
	}, &cellValue{
		sheet: "sheet1",
		cell:  "D1",
		value: "姓名",
	}, &cellValue{
		sheet: "sheet1",
		cell:  "E1",
		value: "最近访问时间",
	}, &cellValue{
		sheet: "sheet1",
		cell:  "F1",
		value: "设备状态",
	}, &cellValue{
		sheet: "sheet1",
		cell:  "G1",
		value: "访问分级",
	})
	// 创建一个工作表
	index, _ := excelFile.NewSheet("Sheet1")
	// 设置工作簿的默认工作表
	excelFile.SetActiveSheet(index)
	//插入表格头
	for _, cellValue := range cellValues {
		excelFile.SetCellValue(cellValue.sheet, cellValue.cell, cellValue.value)
	}
	//设置表格头字体样式
	styleId, err := excelFile.NewStyle(&excelize.Style{
		Font: &excelize.Font{
			Bold:   true,  //黑体
			Italic: false, //倾斜
			Family: "宋体",
			Size:   14,
			//Color:  "微软雅黑",
		},
	})
	if err != nil {
		fmt.Println(err)
	}
	for _, data := range cellValues {
		excelFile.SetCellStyle(data.sheet, data.cell, data.cell, styleId)
	}
	excelFile.SetColWidth("sheet1", "B", "G", 20)

	cnt := 1
	for i := 0; i <= 6; i++ {
		cnt = cnt + 1
		for k1, v1 := range cellValues {
			switch k1 {
			case 0:
				v1.cell = fmt.Sprintf("A%d", cnt)
				v1.value = fmt.Sprintf("%d", i+1)
			case 1:
				v1.cell = fmt.Sprintf("B%d", cnt)
				v1.value = "1"
			case 2:
				v1.cell = fmt.Sprintf("C%d", cnt)
				v1.value = "2"
			case 3:
				v1.cell = fmt.Sprintf("D%d", cnt)
				v1.value = "3"
			case 4:
				v1.cell = fmt.Sprintf("E%d", cnt)
				v1.value = "4"
			case 5:
				v1.cell = fmt.Sprintf("F%d", cnt)
				v1.value = "5"
			case 6:
				v1.cell = fmt.Sprintf("G%d", cnt)
				v1.value = "6"
			}
		}
		for _, vc := range cellValues {
			excelFile.SetCellValue(vc.sheet, vc.cell, vc.value)
		}
	}
	fileName := "ABCD.xlsx"

	//如果是下载,则需要在Header中设置这两个参数
	l.writer.Header().Add("Content-Type", "application/octet-stream")
	l.writer.Header().Add("Content-Disposition", "attachment; filename= "+fileName)
	//l.writer.Header().Add("Content-Transfer-Encoding", "binary")
	excelFile.Write(l.writer)
	return
}

exceltemplatedownloadhandler.go

exceltemplatedownloadhandler.go代码微调整。

func ExcelTemplateDownloadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		l := test.NewExcelTemplateDownloadLogic(r.Context(), svcCtx, w)
		err := l.ExcelTemplateDownload()
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.Ok(w)
		}
	}
}

excelimporthandler.go

excelimporthandler.go代码微调整。

func ExcelImportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.ExcelUploadReq
		req.DeptId = r.FormValue("deptId")
		f, fh, e := utils.ParseFile(r, "file")
		if e != nil {
			httpx.Error(w, e)
			return
		}
		req.File = &types.File{File: f, FileHeader: fh}

		l := test.NewExcelImportLogic(r.Context(), svcCtx)
		resp, err := l.ExcelImport(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJson(w, resp)
		}
	}
}

excelexporthandler.go

excelexporthandler.go代码微调整。

func ExcelExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.ExcelExportlReq
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := test.NewExcelExportLogic(r.Context(), svcCtx, w)
		resp, err := l.ExcelExport(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}

base.go

在路径api/internal/types下创建base.go,内容如下:

package types

import "mime/multipart"

type File struct {
	File       multipart.File
	FileHeader *multipart.FileHeader
}

type ExcelUploadReq struct {
	DeptId string `json:"deptId"` // 部门id
	File   *File  `json:"file"`   // excel文件
}

Excel导入模板

在项目根目录下创建template/excel目录,里面存放Excel导入模板demo_excel_template.xlsx。

模板内容见源码!!!
在这里插入图片描述
在这里插入图片描述

完整调用演示

最后,在根目录go-zero-demo执行下命令。

go mod tidy

运行rpc服务

运行方法同上篇文章,具体查看教程go-zero微服务入门教程完整调用演示部分。

运行api

运行方法同上篇文章,具体查看教程go-zero微服务入门教程完整调用演示部分。

api调用

以下调用采用postman调用。

Excel模板下载
localhost:8888/excel/test/excel/templateDownload
Excel导入
localhost:8888/excel/test/excel/excelImport
Excel导出
localhost:8888/excel/test/excel/excelExport

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1813430.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

科技云报道:“元年”之后,生成式AI将走向何方?

科技云报道原创。 近两年&#xff0c;以大模型为代表的生成式AI技术&#xff0c;成为引爆数字原生最重要的技术奇点&#xff0c;人们见证了各类文生应用的进展速度。Gartner预测&#xff0c;到2026年&#xff0c;超过80%的企业将使用生成式AI的API或模型&#xff0c;或在生产环…

分布式光纤测温DTS与红外热成像系统的主要区别是什么?

分布式光纤测温DTS和红外热成像系统在应用领域和工作原理上存在显著的区别&#xff0c;两者具有明显的差异性。红外热成像系统适用于表现扩散式发热、面式场景以及环境条件较好的情况下。它主要用于检测物体表面的温度&#xff0c;并且受到镜头遮挡或灰尘等因素的影响会导致失效…

论文中表格跨页了做续表的正确方法

在上方加表格 粘贴即可 文章来源于论文中表格跨页了做续表的正确方法&#xff01;论文人快来学习_哔哩哔哩_bilibili 小姐姐用WPS弄的&#xff0c;微软的不理想&#xff0c;我试了试&#xff0c;觉得在上面增加格子再粘贴表头&#xff0c;效果还行

Python | Leetcode Python题解之第145题二叉树的后序遍历

题目&#xff1a; 题解&#xff1a; class Solution:def postorderTraversal(self, root: TreeNode) -> List[int]:def addPath(node: TreeNode):count 0while node:count 1res.append(node.val)node node.righti, j len(res) - count, len(res) - 1while i < j:res…

使用fprintf函数实现写日志文件的功能(附源码)

输出打印日志是排查软件异常问题一个非常重要的手段,无论是业务上的异常,还是软件异常崩溃。一个成熟的软件产品,必然有一个功能完备的日志记录与打印系统。本文就来介绍一种简单易用的写日志文件的方法,给大家提供一个参考。 1、实现思路 主要使用C库中的fopen、fprintf和…

问题:设开环系统的频率特性为则其相频特性穿越-180°线时对应的频率为()。 #学习方法#微信

问题&#xff1a;设开环系统的频率特性为则其相频特性穿越-180线时对应的频率为&#xff08;&#xff09;。 ? A、10rad1s B、3rad/s C、lradIs D、√3rad/s 参考答案如图所示

AIGC简介

目录 1.概述 2.诞生背景 3.作用 4.优缺点 4.1.优点 4.2.缺点 5.应用场景 5.1.十个应用场景 5.2.社交媒体内容 6.如何使用 7.未来展望 8.总结 1.概述 AIGC 是“人工智能生成内容”&#xff08;Artificial Intelligence Generated Content&#xff09;的缩写&#x…

uniapp自定义tabbar——中间特殊按钮放大

在APP.vue里面 .uni-tabbar__item:nth-child(4) .uni-tabbar__icon {width: 50px !important;height: 50px !important;position: relative;bottom: 30rpx;}.uni-tabbar__item:nth-child(4) .uni-tabbar__label {position: relative;bottom: 25rpx;}

Stability AI发布AI音频模型Stable Audio Open,文本生成47秒高清音效

前言 Stability AI这家以开源图像生成模型 Stable Diffusion 而闻名的公司&#xff0c;在 6 月 6 日宣布开源其最新的 AI 音频模型 Stable Audio Open。这一新模型可以根据简单的文本提示生成最多 47 秒的高质量音频数据&#xff0c;为音乐制作和声音设计领域带来了新的可能性…

背景渐变动画登录页

b站视频演示效果: 效果图: 完整代码: <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>背景…

分布式安装安装LNMP_......

分布式安装安装LNMP LNMP是什么Nginx源码编译安装准备工作关闭安全防护配置上传源码包并解压安装编译源码依赖包创建运行用户 编译安装预配置安装选项编译源代码&&安装 配置优化优化路径添加 Nginx 系统服务 Mysql源码编译安装准备工作关闭安全防护配置卸载mariadb上传…

【云原生】创建harbor私有仓库及使用aliyun个人仓库

1.安装docker #删除已有dockersystemctl stop docker yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine #安装docker yum install -y docker-ce-20.10.1…

经济订货批量EOQ模型

一、什么是EOQ模型 EOQ是economic order quantity&#xff08;经济订货&#xff09;原理非常简单。就是把订货带来的成本&#xff0c;分为采购成本和持有成本两部分。 采购成本&#xff1a;每次订货时发生的&#xff0c;谈判、签约、物流等成本 持有成本&#xff1a;货物入仓后…

Linux kernel本地权限提升漏洞(CentOS8升级内核的解决方案)

一、CentOS8升级kernel内核的必要性 1、增强系统的安全性。 升级CentOS内核可以提供更好的安全性保障。新的内核版本通常包含了的安全补丁和漏洞修复&#xff0c;可以有效防止系统遭受恶意攻击&#xff0c;提高系统的稳定性和安全性。 2、优化硬件兼容性。 CentOS升级内核可以…

HTML静态网页成品作业(HTML+CSS)—— 小米商城首页网页(1个页面)

&#x1f389;不定期分享源码&#xff0c;关注不丢失哦 文章目录 一、作品介绍二、作品演示三、代码目录四、网站代码HTML部分代码 五、源码获取 一、作品介绍 &#x1f3f7;️本套采用HTMLCSS&#xff0c;未使用Javacsript代码&#xff0c;共有1个页面。 二、作品演示 三、代…

【ARM Cache 及 MMU 系列文章 1.3 -- 如何判断 L2 Cache 是否实现?】

请阅读【ARM Cache 及 MMU/MPU 系列文章专栏导读】 及【嵌入式开发学习必备专栏】 文章目录 CPU Configuration Register代码实现CPU Configuration Register 在 Armv9 架构中,我们可以通过arm 提供的自定义寄存器IMP_CPUCFR_EL1 来判断当前系统中是否实现了 L2 Cache, 如下所…

【stm32】——基于I2C协议的OLED显示

目录 一、I2C通讯 二、U8G2 1.U8g2简介 2.CubexMX配置 3.移植U8g2 4.编写移植代码 三、显示汉字 四、字体滚动 五、图片显示 总结 一、I2C通讯 IIC(Inter&#xff0d;Integrated Circuit)总线是一种由 PHILIPS 公司开发的两线式串行总线&#xff0c;用于连接微控制器及其外围设…

【Ardiuno】使用ESP32单片机创建web服务通过网页控制小灯开关的实验(图文)

经过实验测试ESP32单片机的网络连接还是很方便的&#xff0c;这里小飞鱼按照程序实例的代码亲自实验一下使用Esp32生成的网页服务来实现远程无线控制小灯开关功能&#xff0c;这样真的是离物联网开发越来越近了&#xff0c;哈哈&#xff01; 连接好开发板和电路&#xff0c;将…

Linux电话本的编写-shell脚本编写

该电话本可以实现以下功能 1.添加用户 2.查询用户 3.删除用户 4.展示用户 5.退出 代码展示&#xff1a; #!/bin/bash PHONEBOOKphonebook.txt function add_contact() { echo "Adding new contact..." read -p "Enter name: " name …

苹果WWDC24一文总结,携手OpenAi,开启Ai新篇章

北京时间6月11日凌晨1点&#xff0c;苹果2024年全球开发者大会&#xff08;WWDC&#xff09;正式开幕。按照往年惯例&#xff0c;每年的WWDC大会&#xff0c;苹果都会将重心放在对新版系统的介绍上&#xff0c;本次也不例外&#xff0c;苹果发布了包括iOS 18、iPadOS18、macOS1…