路由器做网站主机要备案吗,襄阳专业做网站,湖南住房和城乡建设厅网站首页,公众号如何推广产品一、版本说明
本版本在整合上两次的功能基础上#xff0c;引进ini配置文件的读取事项#xff0c;快速读取本地配置文件#xff0c;完成读取设置 第一版#xff1a;实现了严格匹配模式的查找 https://blog.csdn.net/wtt234/article/details/131979385 第二版#xff1a;实… 一、版本说明
本版本在整合上两次的功能基础上引进ini配置文件的读取事项快速读取本地配置文件完成读取设置 第一版实现了严格匹配模式的查找 https://blog.csdn.net/wtt234/article/details/131979385 第二版实现了严格匹配模式的查找以及宽松关键字的查找 https://blog.csdn.net/wtt234/article/details/131981275 本版本在整合上两次的功能基础上引进ini配置文件的读取事项快速读取本地配置文件完成读取设置 二、前置知识ini文件读取
ini配置文件
#配置文件的配置地方
#全局配置
static_foldel./tools
#mysql局部配置
[mysql]
host localhost:3306
user root
password root
dbname test[pm]
keydevicelists语音配线架, 网络配线架, 网络理线架, 终端盒, 光纤收发器, 光纤配线架
devicelists50对语音配线架, 24口网络配线架, 24口网络理线架, 4口终端盒, 光纤收发器, 96芯光纤配线架 ini文件读取代码
package mainimport (fmtgithub.com/go-ini/ini
)//中文网站 https://ini.unknwon.cn
//如果您不需要任何对值的自动转变功能例如递归读取可以直接获取原值这种方式性能最佳
//
//val : cfg.Section().Key(key name).Value()
//
//判断某个原值是否存在
//
//yes : cfg.Section().HasValue(test value)func main() {// 读取INI文件cfg, err : ini.Load(pm.ini)//cfg, err : ini.Load(pm.ini)if err ! nil {fmt.Printf(Failed to read file: %v, err)return}//全局配置的获取,//分区读取默认分区用空字符串表示quanjupm : cfg.Section().Key(static_foldel).String()fmt.Println(quanjupm)////获取mysql配置段,//读取指定分区mysql : cfg.Section(mysql)fmt.Println(mysql.Key(host).String())fmt.Println(mysql.Key(user).String())//读取一个长字符串格式进行处理keydevicelists : cfg.Section(pm)keySlice : keydevicelists.Key(keydevicelists).Strings(,)fmt.Printf(%v,%T, keySlice, keySlice)fmt.Println()//修改文件// 更新INI文件--修改文件//mysql.Key(host).SetValue(newhost)//mysql.Key(user).SetValue(newuser)//mysql.Key(password).SetValue(newpassword)//mysql.Key(dbname).SetValue(newdb)//cfg.SaveTo(conf.ini)
}//vals cfg.Section().Key(STRINGS).Strings(,)三、全部实现代码 项目组织图 配置文件
pm.ini #检索关键字的说明信息keydevicelists关键字检索
#devicelists完全内容匹配检索[pm]
keydevicelists语音配线架, 网络配线架, 网络理线架, 终端盒, 光纤收发器, 光纤配线架
devicelists50对语音配线架, 24口网络配线架, 24口网络理线架, 4口终端盒, 光纤收发器, 96芯光纤配线架
全部代码核心
package mainimport (fmtgithub.com/go-ini/inigithub.com/xuri/excelize/v2strings
)// 我需要检索的信息
// var devicelists []string []string{50对语音配线架, 24口网络配线架, 24口网络理线架, 4口终端盒, 光纤收发器, 96芯光纤配线架}
// var devicelists []string{50对语音配线架, 24口网络配线架, 24口网络理线架, 4口终端盒, 光纤收发器, 96芯光纤配线架}
//
// var keydevicelists []string{语音配线架, 网络配线架, 网络理线架, 终端盒, 光纤收发器, 光纤配线架}
var devicelists []stringvar keydevicelists []stringfunc init() {// 读取INI文件cfg, err : ini.Load(pm.ini)if err ! nil {fmt.Printf(Failed to read file: %v, err)return}//读取一个长字符串格式进行处理pmget : cfg.Section(pm)keydevicelists pmget.Key(keydevicelists).Strings(,)devicelists pmget.Key(devicelists).Strings(,)}// InSlice 判断字符串是否在 slice 中。
func InSlice(items []string, item string) bool {for _, eachItem : range items {if eachItem item {return true}}return false
}// InSlice 判断字符串是否在 slice 中。
func includeSlice(items []string, item string) bool {for _, eachItem : range items {//字符串包含函数判断表格中名字是否包含我的列表中的内容//这样我的找寻字符串中写入关键字就可以了if strings.Contains(item, eachItem) {return true}}return false
}func sheet(sheetname string, f *excelize.File, format int) {//fmt.Println()// 获取 Sheet1 上所有单元格rows, err : f.GetRows(sheetname)if err ! nil {fmt.Println(err)return}//fmt.Println(rows)for _, row : range rows {//fmt.Println(row, , index)//判断每行的里的字段长度如果是小于6 那就是不获取设备名字和设备价格if len(row) 6 {continue}//获取excel中设备的名称kindname : row[1]//获取excel中设备的数量kcount : row[4]//如果表格中 kcount没有内容那就是给复制一个“0”字符串if kcount {kcount 0}//判断模式可以进行采用 不同的检索方式//1.包含模式我检索的都是“关键字” 2.严格模式 内容必须得一模一样的查找if format 1 {//fmt.Println(你匹配的模式为包含模式)//包含的调用if includeSlice(keydevicelists, kindname) {//fmt.Println(sheetname, kindname, 》, kcount)fmt.Printf(获取信息:sheet表%s;设备名称%s;设备数量%s\n;, sheetname, kindname, kcount)//fmt.Println()}} else {//fmt.Println(你匹配的模式为严格模式)if InSlice(devicelists, kindname) {//fmt.Println(sheetname, kindname, 》, kcount)fmt.Printf(获取信息:sheet表%s;设备名称%s;设备数量%s\n;, sheetname, kindname, kcount)//fmt.Println()}}}}// 读取Excel表格
func main() {//fmt.Println()//选择的匹配模式1-包含模式2-严格模式var mode intf, err : excelize.OpenFile(by.xlsx)if err ! nil {fmt.Println(err)return}defer func() {if err : f.Close(); err ! nil {fmt.Println(err)}}()sheetnames : f.GetSheetList()//fmt.Printf(本excel表格的sheetnames:%s, sheetnames)//fmt.Println()for {fmt.Println(请输入你需要的匹配模式1-包含模式2-严格模式,输入 1 或者 2 :)fmt.Scan(mode)//fmt.Printf(%T模式为, mode)//退出内容if mode 88 {fmt.Println(88..88..)break}//遍历所有的表格sheet,调用处理函数for _, sheetname : range sheetnames {//fmt.Println(sheetname)//fmt.Println(, sheetname)sheet(sheetname, f, mode)}}}