• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Fork me on GitHub
            隨筆 - 215  文章 - 13  trackbacks - 0
            <2016年12月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567


            專注即時(shí)通訊及網(wǎng)游服務(wù)端編程
            ------------------------------------
            Openresty 官方模塊
            Openresty 標(biāo)準(zhǔn)模塊(Opm)
            Openresty 三方模塊
            ------------------------------------
            本博收藏大部分文章為轉(zhuǎn)載,并在文章開頭給出了原文出處,如有再轉(zhuǎn),敬請(qǐng)保留相關(guān)信息,這是大家對(duì)原創(chuàng)作者勞動(dòng)成果的自覺尊重!!如為您帶來不便,請(qǐng)于本博下留言,謝謝配合。

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            相冊(cè)

            Awesome

            Blog

            Book

            GitHub

            Link

            搜索

            •  

            積分與排名

            • 積分 - 215659
            • 排名 - 118

            最新評(píng)論

            閱讀排行榜

            >> github: https://github.com/widuu/goini
            conf.go
            /**
             * Read the configuration file
             *
             * @copyright           (C) 2014  widuu
             * @lastmodify          2014-2-22
             * @website        
            http://www.widuu.com
             *
             
            */


            package goini

            import (
                
            "bufio"
                
            "fmt"
                
            "io"
                
            "os"
                
            "strings"
            )

            type Config 
            struct {
                filepath 
            string                         //your ini file path directory+file
                conflist []map[string]map[string]string //configuration information slice
            }


            //Create an empty configuration file
            func SetConfig(filepath string*Config {
                c :
            = new(Config)
                c.filepath 
            = filepath

                
            return c
            }


            //To obtain corresponding value of the key values
            func (c *Config) GetValue(section, name stringstring {
                c.ReadList()
                conf :
            = c.ReadList()
                
            for _, v := range conf {
                    
            for key, value := range v {
                        
            if key == section {
                            
            return value[name]
                        }

                    }

                }

                
            return "no value"
            }


            //Set the corresponding value of the key value, if not add, if there is a key change
            func (c *Config) SetValue(section, key, value stringbool {
                c.ReadList()
                data :
            = c.conflist
                var ok 
            bool
                var index 
            = make(map[int]bool)
                var conf 
            = make(map[string]map[string]string)
                
            for i, v := range data {
                    _, ok 
            = v[section]
                    index[i] 
            = ok
                }


                i, ok :
            = func(m map[int]bool) (i int, v bool{
                    
            for i, v := range m {
                        
            if v == true {
                            
            return i, true
                        }

                    }

                    
            return 0false
                }
            (index)

                
            if ok {
                    c.conflist[i][section][key] 
            = value
                    
            return true
                }
             else {
                    conf[section] 
            = make(map[string]string)
                    conf[section][key] 
            = value
                    c.conflist 
            = append(c.conflist, conf)
                    
            return true
                }


                
            return false
            }


            //Delete the corresponding key values
            func (c *Config) DeleteValue(section, name stringbool {
                c.ReadList()
                data :
            = c.conflist
                
            for i, v := range data {
                    
            for key, _ := range v {
                        
            if key == section {
                            delete(c.conflist[i][key], name)
                            
            return true
                        }

                    }

                }

                
            return false
            }


            //List all the configuration file
            func (c *Config) ReadList() []map[string]map[string]string {

                file, err :
            = os.Open(c.filepath)
                
            if err != nil {
                    CheckErr(err)
                }

                defer file.Close()
                var data map[
            string]map[string]string
                var section 
            string
                buf :
            = bufio.NewReader(file)
                
            for {
                    l, err :
            = buf.ReadString('\n')
                    line :
            = strings.TrimSpace(l)
                    
            if err != nil {
                        
            if err != io.EOF {
                            CheckErr(err)
                        }

                        
            if len(line) == 0 {
                            
            break
                        }

                    }

                    
            switch {
                    
            case len(line) == 0:
                    
            case line[0== '[' && line[len(line)-1== ']':
                        section 
            = strings.TrimSpace(line[1 : len(line)-1])
                        data 
            = make(map[string]map[string]string)
                        data[section] 
            = make(map[string]string)
                    
            default:
                        i :
            = strings.IndexAny(line, "=")
                        value :
            = strings.TrimSpace(line[i+1 : len(line)])
                        data[section][strings.TrimSpace(line[
            0:i])] = value
                        
            if c.uniquappend(section) == true {
                            c.conflist 
            = append(c.conflist, data)
                        }

                    }


                }


                
            return c.conflist
            }


            func CheckErr(err error) 
            string {
                
            if err != nil {
                    
            return fmt.Sprintf("Error is :'%s'", err.Error())
                }

                
            return "Notfound this error"
            }


            //Ban repeated appended to the slice method
            func (c *Config) uniquappend(conf stringbool {
                
            for _, v := range c.conflist {
                    
            for k, _ := range v {
                        
            if k == conf {
                            
            return false
                        }

                    }

                }

                
            return true
            }


            posted on 2016-11-24 16:13 思月行云 閱讀(929) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Golang
            久久精品国产亚洲av麻豆色欲 | 国内精品人妻无码久久久影院导航| 国产亚洲婷婷香蕉久久精品| 久久亚洲国产最新网站| 久久久无码精品亚洲日韩蜜臀浪潮| 人妻无码αv中文字幕久久琪琪布| 久久99热这里只有精品国产| 久久精品亚洲中文字幕无码麻豆 | 国产精品福利一区二区久久| 免费观看成人久久网免费观看| 久久se这里只有精品| 久久五月精品中文字幕| 久久精品a亚洲国产v高清不卡 | 久久99久久99精品免视看动漫| 国产AⅤ精品一区二区三区久久| 大香伊人久久精品一区二区| 99热都是精品久久久久久| 久久夜色精品国产亚洲| 国产精品九九久久免费视频 | 一本久久综合亚洲鲁鲁五月天| 久久99精品久久久久子伦| 97视频久久久| 亚洲国产综合久久天堂 | 伊人久久大香线蕉精品不卡| 97久久国产亚洲精品超碰热| 人人妻久久人人澡人人爽人人精品| 久久国产精品-国产精品| 色偷偷偷久久伊人大杳蕉| 久久久精品久久久久影院| 欧美精品一区二区久久| 一本久久久久久久| 久久精品无码一区二区三区| 久久久久无码精品国产| 伊人久久大香线蕉亚洲| 久久久久亚洲AV成人网人人网站| 久久九九久精品国产| 久久精品无码一区二区三区免费| 久久免费高清视频| 亚洲欧美日韩精品久久| 国产午夜精品久久久久九九| 久久国产精品国产自线拍免费|