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.htmlimport ( "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() } */ |
golang 读取 ini配置信息的更多相关文章
- spring读取加密配置信息
描述&背景Spring框架配置数据库等连接等属性时,都是交由 PopertyPlaceholderConfigurer进行读取.properties文件的,但如果项目不允许在配置文件中明文保存 ...
- Java读取ini配置
本文转载地址: http://www.cnblogs.com/Jermaine/archive/2010/10/24/1859673.html 不够通用,呵呵. 读取ini的配置的格式如下 ...
- 部分转 Java读取ini配置
转自: http://www.cnblogs.com/Jermaine/archive/2010/10/24/1859673.html 读取ini的配置的格式如下: [section1] key1=v ...
- spring boot mybatis XML文件读取properties配置信息
配置文件application.properties中相关配置信息可以在部署以后修改,引用配置信息可以在代码和mybatis的映射文件中 1.JAVA代码 可以通过变量去读取 application. ...
- boost::property_tree 读取ini配置
应用场景: 在后端服务器项目开发中,需要初始化一个Socket服务器,需要IP地址与对应端口号等参数:另外还可能因为对接数据库,就还需要数据库的相关配置参数,如我使用的是MySql数据库,就需要数据库 ...
- php读取ini配置文件属性
ini的内容格式如下,请根据自己的INI,格式修改下段程序. autostart = false font_size = font_color = red =================== fu ...
- JDBC通过配置文件(properites)读取数据库配置信息
扫盲: Classloader 类加载器,用来加载 Java 类到 Java 虚拟机中.与普通程序不同的是.Java程序(class文件)并不是本地的可执行程序.当运行Java程序时,首先运行JVM( ...
- 读取.properties配置信息
package com.ctcti.webcallcenter.utils; import java.io.FileInputStream;import java.io.FileNotFoundExc ...
- 读取数据库配置信息的两种方式(以后开发项目用java链接数据库)-------java基础知识
第一步:先建立jdbc.properties user=root password url/yanlong driver=com.mysql.jdbc.Driver 第一种方式:直接文件读取 pack ...
随机推荐
- paper 133:结构张量Structure Tensor(一)
1.结构张量的作用: 能够区分图像中的平坦区域,边缘,角点: 2.图像中的结构张量的定义 1)是一个矩阵: 2)与图像的水平,垂直梯度有关,定义如下: 在MATLAB中,可以用 ...
- 树状数组,Fenwick Tree
Fenwick Tree, (also known as Binary Indexed Tree,二叉索引树), is a high-performance data structure to cal ...
- prototype、proto和constructor 关系
记录: 1.构造函数:如下,Foo()就是一个构造函数 function Foo(){} 2.prototype:每一个构造函数都有一个属性叫prototype,相当于一个指针,指向它的原型对象 Fo ...
- 【Shiro】三、Apache Shiro认证
配置好并获取到SecurityManager,代表Shiro正常运行起来了,可以使用Shiro的其它功能. 1.认证流程(API的使用流程) 认证的数据: Principals:标识 ·识别Subje ...
- 安装纯净版debian!
kali更新了1.1.0a,不知道新版的内核哪地方有bug,用着用着就卡死了,一怒之下卸载了装debian. 下载的netinst只有200M,基本上就是刚好能用,不要用硬盘装,会找不到网卡,无线也没 ...
- WebX.0:Web1.0
ylbtech-WebX.0:Web1.0 web1.0时代是一个群雄并起,逐鹿网络的时代,虽然各个网站采用的手段和方法不同,但第一代互联网有诸多共同的特征,表现在技术创新主导模式.基于点击流量的盈利 ...
- 9、继续matlab数值分析
1.matlab拉格朗日插值 function yi=Lagrange(x,y,xi) %x为向量,全部的插值节点 %y为向量,插值节点处的函数值 %xi为标量或向量,被估计函数的自变量: %yi为x ...
- GDB can't continue if no space left
[root@premta ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda3 36G 36G 0 100% /tmpfs 1.5G ...
- CFile CStdioFile CArchive 文件操作之异同(详细)
两者的主要区别: 一. CFile类操作文件默认的是Binary模式,CStdioFile类操作文件默认的是Text模式. 在Binary模式下我们必须输入'\r\n',才能起到回车换行的效果, ...
- linux python3换pip 源
linux下python3 pip 安装模块 # python3 -m pip install pymysql 1)检查pip.conf文件是否存在 >> cd ~ > ...