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()
  }  */
}

 
标签: <无>
 

代码片段(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()
    }  */

golang 读取 ini配置信息的更多相关文章

  1. spring读取加密配置信息

    描述&背景Spring框架配置数据库等连接等属性时,都是交由 PopertyPlaceholderConfigurer进行读取.properties文件的,但如果项目不允许在配置文件中明文保存 ...

  2. Java读取ini配置

    本文转载地址:       http://www.cnblogs.com/Jermaine/archive/2010/10/24/1859673.html 不够通用,呵呵. 读取ini的配置的格式如下 ...

  3. 部分转 Java读取ini配置

    转自: http://www.cnblogs.com/Jermaine/archive/2010/10/24/1859673.html 读取ini的配置的格式如下: [section1] key1=v ...

  4. spring boot mybatis XML文件读取properties配置信息

    配置文件application.properties中相关配置信息可以在部署以后修改,引用配置信息可以在代码和mybatis的映射文件中 1.JAVA代码 可以通过变量去读取 application. ...

  5. boost::property_tree 读取ini配置

    应用场景: 在后端服务器项目开发中,需要初始化一个Socket服务器,需要IP地址与对应端口号等参数:另外还可能因为对接数据库,就还需要数据库的相关配置参数,如我使用的是MySql数据库,就需要数据库 ...

  6. php读取ini配置文件属性

    ini的内容格式如下,请根据自己的INI,格式修改下段程序. autostart = false font_size = font_color = red =================== fu ...

  7. JDBC通过配置文件(properites)读取数据库配置信息

    扫盲: Classloader 类加载器,用来加载 Java 类到 Java 虚拟机中.与普通程序不同的是.Java程序(class文件)并不是本地的可执行程序.当运行Java程序时,首先运行JVM( ...

  8. 读取.properties配置信息

    package com.ctcti.webcallcenter.utils; import java.io.FileInputStream;import java.io.FileNotFoundExc ...

  9. 读取数据库配置信息的两种方式(以后开发项目用java链接数据库)-------java基础知识

    第一步:先建立jdbc.properties user=root password url/yanlong driver=com.mysql.jdbc.Driver 第一种方式:直接文件读取 pack ...

随机推荐

  1. thinkphp生成二维码

    /** * 生成二维码 * @param string $url url连接 * @param integer $size 尺寸 纯数字 */ function qrcode($url,$size=4 ...

  2. Migrating Your Android App from Eclipse to Android Studio

    By: Jason Snell | Posted in: Mobile, Performance Tech Tips, Top Post, Jun. 7th, 2013 12 inShare One ...

  3. gdb流程控制(例: 循环打印数组)

    参考:https://blog.csdn.net/justlinux2010/article/details/9453151 循环/条件 在gdb的脚本中循环遍历整个哈希表,并且加上判断条件来进行统计 ...

  4. VisualStudio下std::string的内存布局

    主要成员 union _Bxty { // storage for small buffer or pointer to larger one _Elem _Buf[_BUF_SIZE]; _Elem ...

  5. dfs与dp算法之关系与经典入门例题

    目录 声明 dfs与dp的关系 经典例题-数字三角形 - POJ 1163 题目 dfs思路 解题思路 具体代码 dp思路 解题思路 具体代码 声明 本文不介绍dfs.dp算法的基础思路,有想了解的可 ...

  6. VS2008中编译运行MFC应用程序时,出现无法启动程序,因为计算机中丢失mfc90ud.dll的解决方案

     解决方法:"工具"->"选项"->"项目和解决方案"->"VC++目录",在可执行文件栏中加上如 ...

  7. nginx+tomcat负载均衡实验

    导言: 本次实验,tomcat就直接使用录原生的主页,只是简单修改主页识别主机,nginx也是直接在欢迎页上面修改的,直接实现负载均衡. 主机1:192.168.100.156 nginx+tomca ...

  8. docker-compose的scale的用法

    用到的三个文件 docker-compose version: " services: redis: image: redis web: build: context: . dockerfi ...

  9. 线性方程组迭代算法——Gauss-Seidel迭代算法的python实现

    原理: 请看本人博客:线性方程组的迭代求解算法——原理 代码: import numpy as np max=100#迭代次数上限 Delta=0.01 m=2#阶数:矩阵为2阶 n=3#维数:3X3 ...

  10. 安装 sysbench的 报错 /usr/bin/ld: cannot find -lmysqlclient_r 解决办法

    首先你需要找到这个库的位置 一般找的话需要将lib 给加上(注意:我这里是 -lmysqlclient_r 的报错,于是我找就找 libmysqlclient_r ) find / -name lib ...