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()
        }  */
  • 相关阅读:
    爬取豆瓣影评1寻找json格式的电影信息
    打开SSM项目后打开tomcat找不到路径问题
    爬取豆瓣影评2完整代码
    打开SSM项目无法启动问题补充
    使用python制作国民经济行业国标的json格式
    MVC前端AJAX向后端传递数据——正常传值
    国民经济行业维度清洗,将数据清洗成标准的四级信息。
    使用vue的element组件网址
    Mybais中sql语句的抽取
    mybatis找不到mapper_Springboot整合Mybatis
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/6502426.html
Copyright © 2011-2022 走看看