<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] ## 值選項模式 > [參考](https://segmentfault.com/a/1190000013653494) <details> <summary>main.go</summary> ``` type IComponent interface { Mount(...IComponent) Remove(IComponent) Do(ctx context.Context) error SubDo(ctx context.Context) error } type BaseComponent struct { Components []IComponent } func (b *BaseComponent) Mount(component ...IComponent) { for _, v := range component { b.Components = append(b.Components, v) } } func (b *BaseComponent) Remove(component IComponent) { for k, v := range b.Components { if v == component { fmt.Printf("move %+v\n", reflect.TypeOf(v)) b.Components = append(b.Components[:k], b.Components[k+1:]...) } } } func (b *BaseComponent) Do(ctx context.Context) (err error) { // code return } func (b *BaseComponent) SubDo(ctx context.Context) error { for _, v := range b.Components { if err := v.Do(ctx); err != nil { return err } } return nil } type All struct { BaseComponent } func (a *All) Do(ctx context.Context) (err error) { fmt.Printf("%+v\n", runFuncName()) return a.SubDo(ctx) } type A1 struct { BaseComponent } func (a *A1) Do(ctx context.Context) (err error) { fmt.Printf("%+v\n", runFuncName()) return a.SubDo(ctx) } type A12 struct { BaseComponent } func (a *A12) Do(ctx context.Context) (err error) { fmt.Printf("%+v\n", runFuncName()) return a.SubDo(ctx) } type A11 struct { BaseComponent } func (a *A11) Do(ctx context.Context) (err error) { fmt.Printf("%+v\n", runFuncName()) return a.SubDo(ctx) } type B1 struct { BaseComponent } func (a *B1) Do(ctx context.Context) (err error) { fmt.Printf("%+v\n", runFuncName()) return a.SubDo(ctx) } type C1 struct { BaseComponent } func (a *C1) Do(ctx context.Context) (err error) { fmt.Printf("%+v\n", runFuncName()) return a.SubDo(ctx) } func main() { // 初始化訂單結算頁面 這個大組件 all := &All{} a1 := &A1{} a1.Mount(&A11{}, &A12{}) b1 := &B1{} all.Mount(a1, b1, &C1{}) // 只能刪除本身的子組件 all.Remove(b1) // 開始構建頁面組件數據 ctx := context.WithValue(context.Background(), "a", "b") all.SubDo(ctx) //output //move *main.B1 //main.(*A1).Do //main.(*A11).Do //main.(*A12).Do //main.(*C1).Do } // 獲取正在運行的函數名 func runFuncName() string { pc := make([]uintptr, 1) runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return f.Name() } ``` </details> <br />
                  <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>

                              哎呀哎呀视频在线观看