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 ...
随机推荐
- ASP.NET Error Handling
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspn ...
- python四种方法实现去除列表中的重复元素
转载:https://blog.csdn.net/together_cz/article/details/76201975 def func1(one_list): ''''' 使用集合,个人最常用 ...
- HTML-参考手册: 画布
ylbtech-HTML-参考手册: 画布 1.返回顶部 1. HTML5 <canvas> 参考手册 描述 HTML5 <canvas> 标签用于绘制图像(通过脚本,通常是 ...
- VTemplate模板引擎的使用--进阶篇
1.<vt:template>与<vt:include>标签的不同 <vt:template>和<vt:include> 标签都包含file属性,如果这 ...
- FPGA前仿真后仿真
前仿真 后仿真 时序(综合后)仿真 时序仿真将时延考虑进去,包括综合后产生的(与.或.非)门时延,还有布局布线产生的时延. 综合(Synthesize),就是将HDL语言设计输入翻译成由与.或.非门和 ...
- Eclipes更改主题及字体
1.打开Eclipse的Help->Eclipse Marketplace 2.在Find里搜索Eclipse Color Theme,点击Install按钮(lz已经安过了所以没有) 3.打开 ...
- maven命名
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcl ...
- Tomcat启动脚本(3)setclasspath.bat
@echo off rem Licensed to the Apache Software Foundation (ASF) under one or more rem contributor lic ...
- The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间
/*655.二分图-安排房间 (10分)C时间限制:3000 毫秒 | C内存限制:3000 Kb题目内容: 有一群学生,他们之间有的认识有的不认识.现在要求把学生分成2组,其中同一个组的人相互不认 ...
- 32-python基础-python3-列表永久排序方法-sort()方法
1-数值的列表或字符串的列表,能用 sort()方法排序. 实例1: 实例2: 2-可以指定 reverse 关键字参数为 True,让 sort()按逆序排序. 实例1: 3-关于 sort()方法 ...