zoukankan      html  css  js  c++  java
  • GOLANG学习之类库-goconfig

    一,相关学习资料

    studygolang: https://studygolang.com/articles/818

    github地址:github.com/goconfig

    API gowalker源码:https://gowalker.org/github.com/Unknwon/goconfig

    二,安装

      go get github.com/Unknwon/goconfig

    三,自测学习

      准备多个配置文件env.ini

      

     1 [global]
     2 env = dev
     3 
     4 [mysql]
     5 host = 127.0.0.1
     6 port = 3306
     7 user = root
     8 dbname = gotest
     9 password = 
    10 charset = utf8mb4
    11 max_idle = 2
    12 max_conn = 27
    13 
    14 [default]
    15 auto_session = 0
    16 
    17 [extra]
    18 - = hello
    19 - = go
    20 - = world
    21 
    22 [redis]
    23 host = 127.0.0.1
    24 port = 6379
    25 password =
    26 ; 连接超时
    27 conn_timeout = 2
    28 read_timeout = 2
    29 write_timeout = 2

      env2.ini

      

    1 [webserver]
    2 host = 127.0.0.1
    3 port = 8080
    4 
    5 [mysql]
    6 host = 111.111.111.111

      加载配置文件

      

     1 ConfigFile,err := goconfig.LoadConfigFile(env.ini,env1.ini)
     2   if err != nil {
     3     fmt.Println("load config file error")
     4     os.Exit(1)
     5   }
     6 
     7   mysqlConfig,err:= ConfigFile.GetSection("mysql")
     8   if err !=nil{
     9     fmt.Println("no mysql section config")
    10     os.Exit(1)
    11   }
    12 
    13   for k,v:=range mysqlConfig {
    14     fmt.Println(k,v)
    15   }

      总结:

      1,配置文件可以有多个,如果后续加载的section有同名的,则后面的section的key会覆盖前面出现的相同key

      2,支持回写配置文件,通过ConfigFile.setValue 和 goconfig.SaveConfigFile

      3,支持单个key获取 ConfigFile.getValue

      .........

    未完待续,学习中。

      

      

      

      

    PHP中常见的问题点,知识点,及盲点。
  • 相关阅读:
    栈及练习
    约瑟夫问题
    双向链表
    链表
    线性表
    高级排序
    建议16:比较函数调用模式
    建议15:推荐动态调用函数
    建议14:灵活使用Arguments
    建议13:禁用Function构造函数
  • 原文地址:https://www.cnblogs.com/sblack/p/12931250.html
Copyright © 2011-2022 走看看