• <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
            亚洲国产精品无码久久| 色婷婷久久综合中文久久一本| 91久久精一区二区三区大全| 久久亚洲熟女cc98cm| 欧美日韩精品久久久免费观看 | 久久影视综合亚洲| 久久久久久精品久久久久| 久久久久久国产精品免费无码| 国产精品久久99| 国产精品无码久久久久| 亚洲午夜福利精品久久| 久久精品国产亚洲AV无码偷窥| 91久久精品电影| 久久婷婷色香五月综合激情| 久久精品九九亚洲精品| 久久精品亚洲男人的天堂| 色综合久久综合中文综合网| 国产激情久久久久影院小草| 欧美久久久久久| 久久综合久久久| 久久人人爽人人爽人人片AV不| 久久国产高清字幕中文| 亚洲国产成人乱码精品女人久久久不卡| 亚洲精品美女久久777777| 国产成人精品久久| 久久人人爽人人爽人人AV| 久久久精品波多野结衣| 久久久久99精品成人片直播| 日韩精品无码久久一区二区三| 久久亚洲精品成人AV| 亚洲午夜精品久久久久久app| 国产精品一久久香蕉国产线看| 伊人热热久久原色播放www| 亚洲成人精品久久| 久久精品午夜一区二区福利| 人人狠狠综合久久亚洲| 99久久精品免费看国产免费| 久久婷婷五月综合国产尤物app| 伊人久久大香线蕉精品不卡| 久久亚洲天堂| 久久青青国产|