github.com/code-reading/golang@v0.0.0-20220303082512-ba5bc0e589a3/design/context.pu (about)

     1  @startuml
     2  ' 单行注释
     3  /'
     4      多行注释
     5      多行注释
     6  '/
     7  ' golang 中没有面向对象中的class类关键字
     8  ' 可以通过结构体内嵌匿名结构体来模拟继承关系
     9  hide empty fields 
    10  interface Context
    11  interface canceler
    12  
    13  interface Context{
    14      +Deadline() (deadline time.Time, ok bool)
    15  	+Done() <-chan struct{}
    16  	+Err() error
    17  	+Value(key interface{}) interface{}
    18  }
    19  
    20  interface canceler{
    21      +cancel(removeFromParent bool, err error)
    22  	+Done() <-chan struct{}
    23  }
    24  
    25  class emptyCtx {
    26      +String() string
    27  } 
    28  class valueCtx {
    29      Context
    30  	key, val interface{}
    31      +String() string
    32  }
    33  
    34  class cancelCtx {
    35      Context
    36  	mu sync.Mutex
    37  	done atomic.Value
    38  	children map[canceler]struct{} 
    39  	err      error
    40      +String() string            
    41  }
    42  
    43  class timerCtx {
    44      cancelCtx
    45  	timer *time.Timer
    46  	deadline time.Time
    47      +String() string
    48  }
    49  Context <|.. emptyCtx
    50  canceler <|.. cancelCtx
    51  Context <|-- cancelCtx
    52  cancelCtx <|-- timerCtx
    53  Context <|-- valueCtx
    54  
    55  
    56  
    57  @enduml