• <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年3月>
            282912345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789


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

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            相冊

            Awesome

            Blog

            Book

            GitHub

            Link

            搜索

            •  

            積分與排名

            • 積分 - 216758
            • 排名 - 118

            最新評論

            閱讀排行榜

            >> 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 思月行云 閱讀(931) 評論(0)  編輯 收藏 引用 所屬分類: Golang
            久久精品嫩草影院| 久久精品夜色噜噜亚洲A∨| 久久精品国产亚洲AV麻豆网站| 国产成人综合久久综合| 国产成人精品久久亚洲| 久久青青草视频| 国产高潮国产高潮久久久| 久久久无码精品午夜| 久久66热人妻偷产精品9| 久久婷婷五月综合97色直播| 久久SE精品一区二区| 久久www免费人成看国产片| 久久综合给合久久狠狠狠97色69| 精品久久久久中文字幕一区| 高清免费久久午夜精品| 狠狠色婷婷久久综合频道日韩| Xx性欧美肥妇精品久久久久久 | 久久精品国产亚洲AV电影| 久久久久亚洲AV成人网人人网站 | 日产精品久久久久久久性色| 国产成人无码精品久久久久免费| 亚洲国产精品成人久久| 日产久久强奸免费的看| AAA级久久久精品无码区| 精品久久8x国产免费观看| 99精品国产综合久久久久五月天| 久久久久亚洲精品中文字幕| 国产精品99久久久久久宅男| 久久中文字幕一区二区| 三上悠亚久久精品| 久久精品国产免费观看三人同眠| 久久久久18| 日日狠狠久久偷偷色综合0 | 狠狠88综合久久久久综合网 | 欧美日韩成人精品久久久免费看| 国产香蕉97碰碰久久人人| 91麻豆精品国产91久久久久久| 免费国产99久久久香蕉| 久久综合久久综合九色| 国产精品激情综合久久| 久久久久99精品成人片三人毛片|