• 2024-05-30golang context.Context 使用示例
    context在golang程序中经常被用到,它可以被用来携带一些变量,例如requestID,也可以用来做运行控制,比如TimeoutDeadline,或者人为逻辑控制Cancel。本实例程序用来简单展示各个context的使用方法。packagemainimport( "context" "fmt" "log" "time")typeCtxKeystring
  • 2024-04-07Golang context (上下文)是什么
    Golangcontext(上下文)是什么?原创 几颗酥 几颗酥 2024-03-1111:24 广西 1人听过介绍Context 是golang中十分重要的接口,用于定义 goroutine 中的上下文信息,context 常用于以下几种情况:数据传递:在多个 goroutine 中传递数据超时管理:通过配置超时时间,可以
  • 2024-02-25Go - context keys and values
    ISTHEREAWAYTOLISTKEYSINCONTEXT.CONTEXT?Nothereisnowaytolistallthekeysof context.Context.Becausethattypeisjustaninterface.Sowhatdoesthismean?Ingeneralavariablescanholdaconcretetypeoraninterface.Avariablewithan
  • 2024-02-19grpc-go通过context传递额外数据
    使用ctx.Value从context读取数据//ValueFromIncomingContextreturnsthemetadatavaluecorrespondingtothemetadata//keyfromtheincomingmetadataifitexists.Keymustbelower-case.////#Experimental////Notice:ThisAPIisEXPERIMENTALandm