• 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()
        }  */
  • 相关阅读:
    Leetcode 242.有效的字母异位词 By Python
    Leetcode 344.反转字符串 By Python
    Leetcode 217.存在重复元素 By Python
    js 动态加载select触发事件
    MUI 里js动态添加数字输入框后,增加、减少按钮无效
    【 jquery 】常用
    MySql 常用语句
    CSS 选择器 知识点
    HTML 符号实体
    log4net 配置
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/6502426.html
Copyright © 2020-2023  润新知