本文整理汇总了Golang中github.com/uber/tchannel-go/thrift.Context.Headers方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Headers方法的具体用法?Golang Context.Headers怎么用?Golang Context.Headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/uber/tchannel-go/thrift.Context
的用法示例。
在下文中一共展示了Context.Headers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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
}
}
示例3: 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
}
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例7: TestSet
func (thriftTestHandler) TestSet(ctx thrift.Context, thing map[int32]bool) (map[int32]bool, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
示例8: TestStringMap
func (thriftTestHandler) TestStringMap(ctx thrift.Context, thing map[string]string) (map[string]string, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
示例9: TestNest
func (thriftTestHandler) TestNest(ctx thrift.Context, thing *gauntlet_tchannel.Xtruct2) (*gauntlet_tchannel.Xtruct2, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
示例10: TestBinary
func (thriftTestHandler) TestBinary(ctx thrift.Context, thing []byte) ([]byte, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
示例11: isAdmin
func isAdmin(ctx thrift.Context) bool {
return ctx.Headers()["user"] == "admin"
}
示例12: SecondtestString
func (secondServiceHandler) SecondtestString(ctx thrift.Context, thing string) (string, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
示例13: BlahBlah
func (secondServiceHandler) BlahBlah(ctx thrift.Context) error {
ctx.SetResponseHeaders(ctx.Headers())
return nil
}
示例14: TestList
func (thriftTestHandler) TestList(ctx thrift.Context, thing []int32) ([]int32, error) {
ctx.SetResponseHeaders(ctx.Headers())
return thing, nil
}
示例15: TestVoid
func (thriftTestHandler) TestVoid(ctx thrift.Context) error {
ctx.SetResponseHeaders(ctx.Headers())
return nil
}