zoukankan      html  css  js  c++  java
  • golang 读取 ini配置信息

     
    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()
        }  */
  • 相关阅读:
    发布说明
    Python批量读取人脸图片与数据互相转换
    Python图片与其矩阵数据互相转换
    在sklearn上读取人脸数据集保存图片到本地
    Python图片转换成矩阵,矩阵数据转换成图片
    lintcode :continuous subarray sum 连续子数组之和
    lintcode 中等题:digits counts 统计数字
    lintcode 中等题:Single number III 落单的数III
    lintcode 中等题:Singleton number II 落单的数 II
    lintcode 中等题:majority number III主元素III
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/6502426.html
Copyright © 2011-2022 走看看