• <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
            久久午夜综合久久| 精品99久久aaa一级毛片| 四虎国产精品成人免费久久| 久久精品国产色蜜蜜麻豆| 成人妇女免费播放久久久| 精品久久久久久无码中文野结衣 | 久久人人爽人人爽人人片AV不| 久久精品中文闷骚内射| 久久99精品久久久久久水蜜桃 | 久久久久久极精品久久久| 久久久久久久91精品免费观看| 久久精品国产影库免费看| 久久强奷乱码老熟女网站| 韩国三级大全久久网站| 久久婷婷色香五月综合激情| 色综合久久精品中文字幕首页 | 久久久精品免费国产四虎| 人妻无码αv中文字幕久久琪琪布| 久久精品国产91久久麻豆自制| 伊人热热久久原色播放www| 国产精品伊人久久伊人电影| 久久久久久久久无码精品亚洲日韩 | 亚洲精品97久久中文字幕无码| 91久久精品91久久性色| 久久人人爽人人爽人人av东京热 | 亚洲综合久久夜AV | 国产AⅤ精品一区二区三区久久| 久久综合色老色| 亚洲伊人久久成综合人影院 | 国产午夜福利精品久久| 国产成人久久激情91| 久久亚洲春色中文字幕久久久| 热综合一本伊人久久精品| 国产精品99久久精品爆乳| 久久精品国产秦先生| 91精品国产91热久久久久福利| 99久久99久久| 国内精品久久久久久麻豆 | 久久综合丝袜日本网| 国内精品久久久久久野外| 久久精品成人国产午夜|