<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ### 讀取整個yaml配置文件 ***** #### 設計ymal文件和struct 一個`.ymal`文件: ``` ## Balancing name: "hash" host: host1: ip: "192.168.0.106" port: 6661 role: master host2: ip: "192.168.0.106" port: 6662 role: slave host3: ip: "192.168.0.106" port: 6663 role: slave ``` 設計數據結構 struct ``` type NodeServer struct { Address string `yaml:"address"` Ip string `yaml:"ip"` Port int `yaml:"port"` Role string `yaml:"role"` status bool `default:true` } type ConfServer struct { ReverseProxy map[string]*NodeServer `yaml:"host"` BalanceName string `yaml:"name"` } ``` #### 從ymal文件中獲取配置 ``` func (c *ConfServer) GetConf(fileName string) *ConfServer { yamlFile, err := ioutil.ReadFile(fileName) if nil != err { fmt.Errorf("%v", err) return nil } err = yaml.UnmarshalStrict(yamlFile, c) if err != nil { fmt.Println(err.Error()) } return c } ``` #### 單元測試 ``` func TestConfServer_GetConf(t *testing.T) { var c ConfServer conf := c.GetConf("../conf/conf.yaml") if conf == nil { fmt.Print("conf is nil") return } data, err := json.Marshal(conf) if err != nil { fmt.Println("err:\t", err.Error()) return } fmt.Println("data:\t", string(data)) } ``` ### 讀取yaml配置文件中的某一個屬性 ``` ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看