golang 读取 ini配置信息
//BY: 29295842@qq.com
//这个有一定问题 如果配置信息里有中文就不行
//[Server] ;MYSQL配置
//Server=localhost ;主机
//golang 读取 ini配置信息
//http://www.widuu.com/archives/02/961.html
import (
"fmt"
"github.com/widuu/goini"
//"runtime"
//"time"
)
func Read_ini_string(file_data string, KEY1 string, KEY2 string) string {
conf := goini.SetConfig(file_data) //goini.SetConfig(filepath) 其中filepath是你ini 配置文件的所在位置
return conf.GetValue(KEY1, KEY2) //database是你的[section],username是你要获取值的key名称
}
func main() {
fmt.Println(Read_ini_string("server.ini", "Server", "Username1"))
//conf := goini.SetConfig("server.ini") //goini.SetConfig(filepath) 其中filepath是你ini 配置文件的所在位置
//username := conf.GetValue("Server", "Username") //database是你的[section],username是你要获取值的key名称
//fmt.Println(username)
/*for {
time.Sleep(1 * time.Second)
runtime.Gosched()
} */
}
代码片段(1)[全屏查看所有代码]
1. [文件] main.go ~ 1KB 下载(2) 跳至 [1] [全屏预览]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package main //BY: 29295842@qq.com //这个有一定问题 如果配置信息里有中文就不行 //[Server] ;MYSQL配置 //Server=localhost ;主机 //golang 读取 ini配置信息 //http://www.widuu.com/archives/02/961.html import ( "fmt" "github.com/widuu/goini" //"runtime" //"time" ) func Read_ini_string(file_data string, KEY1 string, KEY2 string) string { conf := goini.SetConfig(file_data) //goini.SetConfig(filepath) 其中filepath是你ini 配置文件的所在位置 return conf.GetValue(KEY1, KEY2) //database是你的[section],username是你要获取值的key名称 } func main() { fmt.Println(Read_ini_string( "server.ini" , "Server" , "Username1" )) //conf := goini.SetConfig("server.ini") //goini.SetConfig(filepath) 其中filepath是你ini 配置文件的所在位置 //username := conf.GetValue("Server", "Username") //database是你的[section],username是你要获取值的key名称 //fmt.Println(username) /*for { time.Sleep(1 * time.Second) runtime.Gosched() } */ |
最新文章
- 安装nodejs express框架时express命令行无效
- [react native] react-native-tab-navigator在子Component中隐藏
- MYSQL:使用\G参数改变输出结果集的显示方式
- c++ poco库https调用
- eclipse设置字体、背景(豆绿)色、自动提示
- 元素设置position:fixed属性后IE下宽度无法100%延伸
- 让Grub 2来拯救你的 bootloader
- 洛谷P1983 车站分级
- 单片机usb转串口的时灵时不灵的解答
- apache点NET环境
- python包管理-distutils,setuptools,pip,virtualenv等介绍
- sublime Text3配置及快捷键、插件推荐总结
- 关于导出oracle多个表的建表语句DLL,生成.sql语句。
- DNF(一.YUM已死,DNF代之)
- web2py官方文档翻译01
- Android Bluetooth Stack: Bluedroid(五岁以下儿童):The analysis of A2DP Source
- 使用filter方法过滤集合元素
- Ubuntu 自动选择最快的镜像源
- Linux colrm命令详解
- linux基本格式和常用目录命令一