本文整理汇总了Golang中github.com/uber/tchannel-go/thrift.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SetForwardedHeader
// SetForwardedHeader adds a header to the current thrift context indicating
// that the call has been forwarded by another node in the ringpop ring.
// This header is used when a remote call is received to determine if forwarding
// checks needs to be applied. By not forwarding already forwarded calls we
// prevent unbound forwarding in the ring in case of memebership disagreement.
func SetForwardedHeader(ctx thrift.Context) thrift.Context {
headers := ctx.Headers()
if len(headers) == 0 {
return thrift.WithHeaders(ctx, staticForwardHeaders)
}
headers[forwardedHeaderName] = "true"
return thrift.WithHeaders(ctx, headers)
}
开发者ID:gl-works,项目名称:ringpop-go,代码行数:14,代码来源:forwarder.go
示例2: TestException
func (thriftTestHandler) TestException(ctx thrift.Context, arg string) error {
ctx.SetResponseHeaders(ctx.Headers())
switch arg {
case "Xception":
code := int32(1001)
return &gauntlet_tchannel.Xception{ErrorCode: &code, Message: &arg}
case "TException":
// unexpected exception.
return errors.New("great sadness")
default:
return nil
}
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:13,代码来源:gauntlet.go
示例3: Set
// Set sets the value for a given key.
func (h *kvHandler) Set(ctx thrift.Context, key, value string) error {
if err := isValidKey(key); err != nil {
return err
}
h.mut.Lock()
defer h.mut.Unlock()
h.vals[key] = value
// Example of how to use response headers. Normally, these values should be passed via result structs.
ctx.SetResponseHeaders(map[string]string{"count": fmt.Sprint(len(h.vals))})
return nil
}
开发者ID:glycerine,项目名称:tchannel-go,代码行数:14,代码来源:server.go
示例4: TestMultiException
func (thriftTestHandler) TestMultiException(ctx thrift.Context, arg0 string, arg1 string) (*gauntlet_tchannel.Xtruct, error) {
ctx.SetResponseHeaders(ctx.Headers())
structThing := &gauntlet_tchannel.Xtruct{StringThing: &arg1}
switch arg0 {
case "Xception":
code := int32(1001)
message := "This is an Xception"
return nil, &gauntlet_tchannel.Xception{ErrorCode: &code, Message: &message}
case "Xception2":
code := int32(2002)
return nil, &gauntlet_tchannel.Xception2{ErrorCode: &code, StructThing: structThing}
default:
return structThing, nil
}
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:15,代码来源:gauntlet.go
示例5: TestInsanity
func (thriftTestHandler) TestInsanity(ctx thrift.Context, argument *gauntlet_tchannel.Insanity) (
map[gauntlet_tchannel.UserId]map[gauntlet_tchannel.Numberz]*gauntlet_tchannel.Insanity, error) {
ctx.SetResponseHeaders(ctx.Headers())
result := map[gauntlet_tchannel.UserId]map[gauntlet_tchannel.Numberz]*gauntlet_tchannel.Insanity{
1: {
gauntlet_tchannel.Numberz_TWO: argument,
gauntlet_tchannel.Numberz_THREE: argument,
},
2: {
gauntlet_tchannel.Numberz_SIX: &gauntlet_tchannel.Insanity{},
},
}
return result, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:15,代码来源:gauntlet.go
示例6: TestMapMap
func (thriftTestHandler) TestMapMap(ctx thrift.Context, hello int32) (map[int32]map[int32]int32, error) {
ctx.SetResponseHeaders(ctx.Headers())
result := map[int32]map[int32]int32{
-4: {
-4: -4,
-3: -3,
-2: -2,
-1: -1,
},
4: {
1: 1,
2: 2,
3: 3,
4: 4,
},
}
return result, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:18,代码来源:gauntlet.go
示例7: TestMulti
func (thriftTestHandler) TestMulti(
ctx thrift.Context,
arg0 int8,
arg1 int32,
arg2 int64,
arg3 map[int16]string,
arg4 gauntlet_tchannel.Numberz,
arg5 gauntlet_tchannel.UserId,
) (*gauntlet_tchannel.Xtruct, error) {
ctx.SetResponseHeaders(ctx.Headers())
hello := "Hello2"
result := &gauntlet_tchannel.Xtruct{
StringThing: &hello,
ByteThing: &arg0,
I32Thing: &arg1,
I64Thing: &arg2,
}
return result, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:20,代码来源:gauntlet.go
示例8: TestList
func (thriftTestHandler) TestList(ctx thrift.Context, thing []int32) ([]int32, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例9: TestSet
func (thriftTestHandler) TestSet(ctx thrift.Context, thing map[int32]bool) (map[int32]bool, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例10: TestStringMap
func (thriftTestHandler) TestStringMap(ctx thrift.Context, thing map[string]string) (map[string]string, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例11: TestNest
func (thriftTestHandler) TestNest(ctx thrift.Context, thing *gauntlet_tchannel.Xtruct2) (*gauntlet_tchannel.Xtruct2, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例12: isAdmin
func isAdmin(ctx thrift.Context) bool {
return ctx.Headers()["user"] == "admin"
}
开发者ID:glycerine,项目名称:tchannel-go,代码行数:3,代码来源:server.go
示例13: TestVoid
func (thriftTestHandler) TestVoid(ctx thrift.Context) error {
ctx.SetResponseHeaders(ctx.Headers())
return nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例14: SecondtestString
func (secondServiceHandler) SecondtestString(ctx thrift.Context, thing string) (string, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例15: BlahBlah
func (secondServiceHandler) BlahBlah(ctx thrift.Context) error {
ctx.SetResponseHeaders(ctx.Headers())
return nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例16: TestEnum
func (thriftTestHandler) TestEnum(ctx thrift.Context, thing gauntlet_tchannel.Numberz) (gauntlet_tchannel.Numberz, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例17: TestI64
func (thriftTestHandler) TestI64(ctx thrift.Context, thing int64) (int64, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例18: TestDouble
func (thriftTestHandler) TestDouble(ctx thrift.Context, thing float64) (float64, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
示例19: Echo
func (h *echoThriftHandler) Echo(ctx thrift.Context, ping *echo.Ping) (*echo.Pong, error) {
ctx.SetResponseHeaders(ctx.Headers())
return &echo.Pong{Boop: ping.Beep}, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:echo.go
示例20: TestBinary
func (thriftTestHandler) TestBinary(ctx thrift.Context, thing []byte) ([]byte, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:gauntlet.go
注:本文中的github.com/uber/tchannel-go/thrift.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论