id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
11,000 | yarpc/yarpc-go | internal/config/attributemap.go | Decode | func (m AttributeMap) Decode(dst interface{}, opts ...mapdecode.Option) error {
return DecodeInto(dst, m, opts...)
} | go | func (m AttributeMap) Decode(dst interface{}, opts ...mapdecode.Option) error {
return DecodeInto(dst, m, opts...)
} | [
"func",
"(",
"m",
"AttributeMap",
")",
"Decode",
"(",
"dst",
"interface",
"{",
"}",
",",
"opts",
"...",
"mapdecode",
".",
"Option",
")",
"error",
"{",
"return",
"DecodeInto",
"(",
"dst",
",",
"m",
",",
"opts",
"...",
")",
"\n",
"}"
]
| // Decode attempts to decode the AttributeMap into the dst interface. | [
"Decode",
"attempts",
"to",
"decode",
"the",
"AttributeMap",
"into",
"the",
"dst",
"interface",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/config/attributemap.go#L84-L86 |
11,001 | yarpc/yarpc-go | internal/crossdock/client/apachethrift/behavior.go | Run | func Run(t crossdock.T) {
fatals := crossdock.Fatals(t)
server := t.Param(serverParam)
fatals.NotEmpty(server, "apachethriftserver is required")
httpTransport := http.NewTransport()
url := fmt.Sprintf("http://%v:%v", server, serverPort)
thriftOutbound := httpTransport.NewSingleOutbound(url + "/thrift/ThriftTest")
secondOutbound := httpTransport.NewSingleOutbound(url + "/thrift/SecondService")
multiplexOutbound := httpTransport.NewSingleOutbound(url + "/thrift/multiplexed")
dispatcher := yarpc.NewDispatcher(yarpc.Config{
Name: "apache-thrift-client",
Outbounds: yarpc.Outbounds{
"ThriftTest": {
Unary: thriftOutbound,
Oneway: thriftOutbound,
},
"SecondService": {
Unary: secondOutbound,
},
"Multiplexed": {
Unary: multiplexOutbound,
Oneway: multiplexOutbound,
},
},
})
fatals.NoError(dispatcher.Start(), "could not start Dispatcher")
defer dispatcher.Stop()
// We can just run all the gauntlet tests against each URL because
// tests for undefined methods are skipped.
tests := []struct {
ServerName string
Services gauntlet.ServiceSet
Options []thrift.ClientOption
}{
{
ServerName: "ThriftTest",
Services: gauntlet.ThriftTest,
},
{
ServerName: "SecondService",
Services: gauntlet.SecondService,
},
{
ServerName: "Multiplexed",
Services: gauntlet.AllServices,
Options: []thrift.ClientOption{thrift.Multiplexed},
},
}
for _, tt := range tests {
t.Tag("outbound", tt.ServerName)
gauntlet.RunGauntlet(t, gauntlet.Config{
Dispatcher: dispatcher,
ServerName: tt.ServerName,
Envelope: true,
Services: tt.Services,
ClientOptions: tt.Options,
})
}
} | go | func Run(t crossdock.T) {
fatals := crossdock.Fatals(t)
server := t.Param(serverParam)
fatals.NotEmpty(server, "apachethriftserver is required")
httpTransport := http.NewTransport()
url := fmt.Sprintf("http://%v:%v", server, serverPort)
thriftOutbound := httpTransport.NewSingleOutbound(url + "/thrift/ThriftTest")
secondOutbound := httpTransport.NewSingleOutbound(url + "/thrift/SecondService")
multiplexOutbound := httpTransport.NewSingleOutbound(url + "/thrift/multiplexed")
dispatcher := yarpc.NewDispatcher(yarpc.Config{
Name: "apache-thrift-client",
Outbounds: yarpc.Outbounds{
"ThriftTest": {
Unary: thriftOutbound,
Oneway: thriftOutbound,
},
"SecondService": {
Unary: secondOutbound,
},
"Multiplexed": {
Unary: multiplexOutbound,
Oneway: multiplexOutbound,
},
},
})
fatals.NoError(dispatcher.Start(), "could not start Dispatcher")
defer dispatcher.Stop()
// We can just run all the gauntlet tests against each URL because
// tests for undefined methods are skipped.
tests := []struct {
ServerName string
Services gauntlet.ServiceSet
Options []thrift.ClientOption
}{
{
ServerName: "ThriftTest",
Services: gauntlet.ThriftTest,
},
{
ServerName: "SecondService",
Services: gauntlet.SecondService,
},
{
ServerName: "Multiplexed",
Services: gauntlet.AllServices,
Options: []thrift.ClientOption{thrift.Multiplexed},
},
}
for _, tt := range tests {
t.Tag("outbound", tt.ServerName)
gauntlet.RunGauntlet(t, gauntlet.Config{
Dispatcher: dispatcher,
ServerName: tt.ServerName,
Envelope: true,
Services: tt.Services,
ClientOptions: tt.Options,
})
}
} | [
"func",
"Run",
"(",
"t",
"crossdock",
".",
"T",
")",
"{",
"fatals",
":=",
"crossdock",
".",
"Fatals",
"(",
"t",
")",
"\n\n",
"server",
":=",
"t",
".",
"Param",
"(",
"serverParam",
")",
"\n",
"fatals",
".",
"NotEmpty",
"(",
"server",
",",
"\"",
"\"",
")",
"\n\n",
"httpTransport",
":=",
"http",
".",
"NewTransport",
"(",
")",
"\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"server",
",",
"serverPort",
")",
"\n\n",
"thriftOutbound",
":=",
"httpTransport",
".",
"NewSingleOutbound",
"(",
"url",
"+",
"\"",
"\"",
")",
"\n",
"secondOutbound",
":=",
"httpTransport",
".",
"NewSingleOutbound",
"(",
"url",
"+",
"\"",
"\"",
")",
"\n",
"multiplexOutbound",
":=",
"httpTransport",
".",
"NewSingleOutbound",
"(",
"url",
"+",
"\"",
"\"",
")",
"\n\n",
"dispatcher",
":=",
"yarpc",
".",
"NewDispatcher",
"(",
"yarpc",
".",
"Config",
"{",
"Name",
":",
"\"",
"\"",
",",
"Outbounds",
":",
"yarpc",
".",
"Outbounds",
"{",
"\"",
"\"",
":",
"{",
"Unary",
":",
"thriftOutbound",
",",
"Oneway",
":",
"thriftOutbound",
",",
"}",
",",
"\"",
"\"",
":",
"{",
"Unary",
":",
"secondOutbound",
",",
"}",
",",
"\"",
"\"",
":",
"{",
"Unary",
":",
"multiplexOutbound",
",",
"Oneway",
":",
"multiplexOutbound",
",",
"}",
",",
"}",
",",
"}",
")",
"\n",
"fatals",
".",
"NoError",
"(",
"dispatcher",
".",
"Start",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"defer",
"dispatcher",
".",
"Stop",
"(",
")",
"\n\n",
"// We can just run all the gauntlet tests against each URL because",
"// tests for undefined methods are skipped.",
"tests",
":=",
"[",
"]",
"struct",
"{",
"ServerName",
"string",
"\n",
"Services",
"gauntlet",
".",
"ServiceSet",
"\n",
"Options",
"[",
"]",
"thrift",
".",
"ClientOption",
"\n",
"}",
"{",
"{",
"ServerName",
":",
"\"",
"\"",
",",
"Services",
":",
"gauntlet",
".",
"ThriftTest",
",",
"}",
",",
"{",
"ServerName",
":",
"\"",
"\"",
",",
"Services",
":",
"gauntlet",
".",
"SecondService",
",",
"}",
",",
"{",
"ServerName",
":",
"\"",
"\"",
",",
"Services",
":",
"gauntlet",
".",
"AllServices",
",",
"Options",
":",
"[",
"]",
"thrift",
".",
"ClientOption",
"{",
"thrift",
".",
"Multiplexed",
"}",
",",
"}",
",",
"}",
"\n\n",
"for",
"_",
",",
"tt",
":=",
"range",
"tests",
"{",
"t",
".",
"Tag",
"(",
"\"",
"\"",
",",
"tt",
".",
"ServerName",
")",
"\n",
"gauntlet",
".",
"RunGauntlet",
"(",
"t",
",",
"gauntlet",
".",
"Config",
"{",
"Dispatcher",
":",
"dispatcher",
",",
"ServerName",
":",
"tt",
".",
"ServerName",
",",
"Envelope",
":",
"true",
",",
"Services",
":",
"tt",
".",
"Services",
",",
"ClientOptions",
":",
"tt",
".",
"Options",
",",
"}",
")",
"\n",
"}",
"\n",
"}"
]
| // Run runs the apachethrift behavior | [
"Run",
"runs",
"the",
"apachethrift",
"behavior"
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/client/apachethrift/behavior.go#L39-L103 |
11,002 | yarpc/yarpc-go | internal/clock/fake.go | Add | func (fc *FakeClock) Add(d time.Duration) {
fc.Lock()
// Calculate the final time.
end := fc.now.Add(d)
fc.flush(end)
if fc.now.Before(end) {
fc.now = end
}
fc.Unlock()
nap()
} | go | func (fc *FakeClock) Add(d time.Duration) {
fc.Lock()
// Calculate the final time.
end := fc.now.Add(d)
fc.flush(end)
if fc.now.Before(end) {
fc.now = end
}
fc.Unlock()
nap()
} | [
"func",
"(",
"fc",
"*",
"FakeClock",
")",
"Add",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"fc",
".",
"Lock",
"(",
")",
"\n",
"// Calculate the final time.",
"end",
":=",
"fc",
".",
"now",
".",
"Add",
"(",
"d",
")",
"\n",
"fc",
".",
"flush",
"(",
"end",
")",
"\n\n",
"if",
"fc",
".",
"now",
".",
"Before",
"(",
"end",
")",
"{",
"fc",
".",
"now",
"=",
"end",
"\n",
"}",
"\n",
"fc",
".",
"Unlock",
"(",
")",
"\n",
"nap",
"(",
")",
"\n",
"}"
]
| // Add moves the current time of the fake clock forward by the duration.
// This should only be called from a single goroutine at a time. | [
"Add",
"moves",
"the",
"current",
"time",
"of",
"the",
"fake",
"clock",
"forward",
"by",
"the",
"duration",
".",
"This",
"should",
"only",
"be",
"called",
"from",
"a",
"single",
"goroutine",
"at",
"a",
"time",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/clock/fake.go#L53-L64 |
11,003 | yarpc/yarpc-go | internal/clock/fake.go | Set | func (fc *FakeClock) Set(end time.Time) {
fc.Lock()
fc.flush(end)
if fc.now.Before(end) {
fc.now = end
}
fc.Unlock()
nap()
} | go | func (fc *FakeClock) Set(end time.Time) {
fc.Lock()
fc.flush(end)
if fc.now.Before(end) {
fc.now = end
}
fc.Unlock()
nap()
} | [
"func",
"(",
"fc",
"*",
"FakeClock",
")",
"Set",
"(",
"end",
"time",
".",
"Time",
")",
"{",
"fc",
".",
"Lock",
"(",
")",
"\n",
"fc",
".",
"flush",
"(",
"end",
")",
"\n\n",
"if",
"fc",
".",
"now",
".",
"Before",
"(",
"end",
")",
"{",
"fc",
".",
"now",
"=",
"end",
"\n",
"}",
"\n",
"fc",
".",
"Unlock",
"(",
")",
"\n",
"nap",
"(",
")",
"\n",
"}"
]
| // Set advances the current time of the fake clock to the given absolute time. | [
"Set",
"advances",
"the",
"current",
"time",
"of",
"the",
"fake",
"clock",
"to",
"the",
"given",
"absolute",
"time",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/clock/fake.go#L67-L76 |
11,004 | yarpc/yarpc-go | internal/clock/fake.go | FakeTimer | func (fc *FakeClock) FakeTimer(d time.Duration) *FakeTimer {
fc.Lock()
defer fc.Unlock()
c := make(chan time.Time, 1)
t := &FakeTimer{
c: c,
clock: fc,
time: fc.now.Add(d),
}
fc.addTimer(t)
return t
} | go | func (fc *FakeClock) FakeTimer(d time.Duration) *FakeTimer {
fc.Lock()
defer fc.Unlock()
c := make(chan time.Time, 1)
t := &FakeTimer{
c: c,
clock: fc,
time: fc.now.Add(d),
}
fc.addTimer(t)
return t
} | [
"func",
"(",
"fc",
"*",
"FakeClock",
")",
"FakeTimer",
"(",
"d",
"time",
".",
"Duration",
")",
"*",
"FakeTimer",
"{",
"fc",
".",
"Lock",
"(",
")",
"\n",
"defer",
"fc",
".",
"Unlock",
"(",
")",
"\n\n",
"c",
":=",
"make",
"(",
"chan",
"time",
".",
"Time",
",",
"1",
")",
"\n",
"t",
":=",
"&",
"FakeTimer",
"{",
"c",
":",
"c",
",",
"clock",
":",
"fc",
",",
"time",
":",
"fc",
".",
"now",
".",
"Add",
"(",
"d",
")",
",",
"}",
"\n",
"fc",
".",
"addTimer",
"(",
"t",
")",
"\n",
"return",
"t",
"\n",
"}"
]
| // FakeTimer produces a timer that will emit a time some duration after now,
// exposing the fake timer internals and type. | [
"FakeTimer",
"produces",
"a",
"timer",
"that",
"will",
"emit",
"a",
"time",
"some",
"duration",
"after",
"now",
"exposing",
"the",
"fake",
"timer",
"internals",
"and",
"type",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/clock/fake.go#L95-L107 |
11,005 | yarpc/yarpc-go | internal/clock/fake.go | FakeAfterFunc | func (fc *FakeClock) FakeAfterFunc(d time.Duration, f func()) *FakeTimer {
t := fc.FakeTimer(d)
go func() {
<-t.c
f()
}()
nap()
return t
} | go | func (fc *FakeClock) FakeAfterFunc(d time.Duration, f func()) *FakeTimer {
t := fc.FakeTimer(d)
go func() {
<-t.c
f()
}()
nap()
return t
} | [
"func",
"(",
"fc",
"*",
"FakeClock",
")",
"FakeAfterFunc",
"(",
"d",
"time",
".",
"Duration",
",",
"f",
"func",
"(",
")",
")",
"*",
"FakeTimer",
"{",
"t",
":=",
"fc",
".",
"FakeTimer",
"(",
"d",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"<-",
"t",
".",
"c",
"\n",
"f",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"nap",
"(",
")",
"\n",
"return",
"t",
"\n",
"}"
]
| // FakeAfterFunc waits for the duration to elapse and then executes a function.
// A Timer is returned that can be stopped. | [
"FakeAfterFunc",
"waits",
"for",
"the",
"duration",
"to",
"elapse",
"and",
"then",
"executes",
"a",
"function",
".",
"A",
"Timer",
"is",
"returned",
"that",
"can",
"be",
"stopped",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/clock/fake.go#L126-L134 |
11,006 | yarpc/yarpc-go | internal/clock/fake.go | Now | func (fc *FakeClock) Now() time.Time {
fc.Lock()
defer fc.Unlock()
return fc.now
} | go | func (fc *FakeClock) Now() time.Time {
fc.Lock()
defer fc.Unlock()
return fc.now
} | [
"func",
"(",
"fc",
"*",
"FakeClock",
")",
"Now",
"(",
")",
"time",
".",
"Time",
"{",
"fc",
".",
"Lock",
"(",
")",
"\n",
"defer",
"fc",
".",
"Unlock",
"(",
")",
"\n",
"return",
"fc",
".",
"now",
"\n",
"}"
]
| // Now returns the current time on the fake clock. | [
"Now",
"returns",
"the",
"current",
"time",
"on",
"the",
"fake",
"clock",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/clock/fake.go#L143-L147 |
11,007 | yarpc/yarpc-go | internal/clock/fake.go | Reset | func (t *FakeTimer) Reset(d time.Duration) bool {
t.time = t.clock.now.Add(d)
// Empty the channel if already filled.
select {
case <-t.c:
default:
}
if t.index >= 0 {
heap.Fix(&t.clock.timers, t.index)
return true
}
heap.Push(&t.clock.timers, t)
return false
} | go | func (t *FakeTimer) Reset(d time.Duration) bool {
t.time = t.clock.now.Add(d)
// Empty the channel if already filled.
select {
case <-t.c:
default:
}
if t.index >= 0 {
heap.Fix(&t.clock.timers, t.index)
return true
}
heap.Push(&t.clock.timers, t)
return false
} | [
"func",
"(",
"t",
"*",
"FakeTimer",
")",
"Reset",
"(",
"d",
"time",
".",
"Duration",
")",
"bool",
"{",
"t",
".",
"time",
"=",
"t",
".",
"clock",
".",
"now",
".",
"Add",
"(",
"d",
")",
"\n\n",
"// Empty the channel if already filled.",
"select",
"{",
"case",
"<-",
"t",
".",
"c",
":",
"default",
":",
"}",
"\n\n",
"if",
"t",
".",
"index",
">=",
"0",
"{",
"heap",
".",
"Fix",
"(",
"&",
"t",
".",
"clock",
".",
"timers",
",",
"t",
".",
"index",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"heap",
".",
"Push",
"(",
"&",
"t",
".",
"clock",
".",
"timers",
",",
"t",
")",
"\n",
"return",
"false",
"\n",
"}"
]
| // Reset adjusts the timer's scheduled time forward from now, unless it has
// already fired. | [
"Reset",
"adjusts",
"the",
"timer",
"s",
"scheduled",
"time",
"forward",
"from",
"now",
"unless",
"it",
"has",
"already",
"fired",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/clock/fake.go#L179-L194 |
11,008 | yarpc/yarpc-go | internal/clock/fake.go | Stop | func (t *FakeTimer) Stop() bool {
if t.index < 0 {
return false
}
// Empty the channel if already filled.
select {
case <-t.c:
default:
}
t.clock.timers.Swap(t.index, len(t.clock.timers)-1)
t.clock.timers.Pop()
heap.Fix(&t.clock.timers, t.index)
return true
} | go | func (t *FakeTimer) Stop() bool {
if t.index < 0 {
return false
}
// Empty the channel if already filled.
select {
case <-t.c:
default:
}
t.clock.timers.Swap(t.index, len(t.clock.timers)-1)
t.clock.timers.Pop()
heap.Fix(&t.clock.timers, t.index)
return true
} | [
"func",
"(",
"t",
"*",
"FakeTimer",
")",
"Stop",
"(",
")",
"bool",
"{",
"if",
"t",
".",
"index",
"<",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// Empty the channel if already filled.",
"select",
"{",
"case",
"<-",
"t",
".",
"c",
":",
"default",
":",
"}",
"\n\n",
"t",
".",
"clock",
".",
"timers",
".",
"Swap",
"(",
"t",
".",
"index",
",",
"len",
"(",
"t",
".",
"clock",
".",
"timers",
")",
"-",
"1",
")",
"\n",
"t",
".",
"clock",
".",
"timers",
".",
"Pop",
"(",
")",
"\n",
"heap",
".",
"Fix",
"(",
"&",
"t",
".",
"clock",
".",
"timers",
",",
"t",
".",
"index",
")",
"\n",
"return",
"true",
"\n",
"}"
]
| // Stop removes a timer from the scheduled timers. | [
"Stop",
"removes",
"a",
"timer",
"from",
"the",
"scheduled",
"timers",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/clock/fake.go#L197-L212 |
11,009 | yarpc/yarpc-go | internal/examples/streaming/stream.pb.yarpc.go | NewHelloYARPCClient | func NewHelloYARPCClient(clientConfig transport.ClientConfig, options ...protobuf.ClientOption) HelloYARPCClient {
return &_HelloYARPCCaller{protobuf.NewStreamClient(
protobuf.ClientParams{
ServiceName: "uber.yarpc.internal.examples.streaming.Hello",
ClientConfig: clientConfig,
Options: options,
},
)}
} | go | func NewHelloYARPCClient(clientConfig transport.ClientConfig, options ...protobuf.ClientOption) HelloYARPCClient {
return &_HelloYARPCCaller{protobuf.NewStreamClient(
protobuf.ClientParams{
ServiceName: "uber.yarpc.internal.examples.streaming.Hello",
ClientConfig: clientConfig,
Options: options,
},
)}
} | [
"func",
"NewHelloYARPCClient",
"(",
"clientConfig",
"transport",
".",
"ClientConfig",
",",
"options",
"...",
"protobuf",
".",
"ClientOption",
")",
"HelloYARPCClient",
"{",
"return",
"&",
"_HelloYARPCCaller",
"{",
"protobuf",
".",
"NewStreamClient",
"(",
"protobuf",
".",
"ClientParams",
"{",
"ServiceName",
":",
"\"",
"\"",
",",
"ClientConfig",
":",
"clientConfig",
",",
"Options",
":",
"options",
",",
"}",
",",
")",
"}",
"\n",
"}"
]
| // NewHelloYARPCClient builds a new YARPC client for the Hello service. | [
"NewHelloYARPCClient",
"builds",
"a",
"new",
"YARPC",
"client",
"for",
"the",
"Hello",
"service",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/streaming/stream.pb.yarpc.go#L73-L81 |
11,010 | yarpc/yarpc-go | internal/examples/streaming/stream.pb.yarpc.go | BuildHelloYARPCProcedures | func BuildHelloYARPCProcedures(server HelloYARPCServer) []transport.Procedure {
handler := &_HelloYARPCHandler{server}
return protobuf.BuildProcedures(
protobuf.BuildProceduresParams{
ServiceName: "uber.yarpc.internal.examples.streaming.Hello",
UnaryHandlerParams: []protobuf.BuildProceduresUnaryHandlerParams{
{
MethodName: "HelloUnary",
Handler: protobuf.NewUnaryHandler(
protobuf.UnaryHandlerParams{
Handle: handler.HelloUnary,
NewRequest: newHelloServiceHelloUnaryYARPCRequest,
},
),
},
},
OnewayHandlerParams: []protobuf.BuildProceduresOnewayHandlerParams{},
StreamHandlerParams: []protobuf.BuildProceduresStreamHandlerParams{
{
MethodName: "HelloThere",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.HelloThere,
},
),
},
{
MethodName: "HelloInStream",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.HelloInStream,
},
),
},
{
MethodName: "HelloOutStream",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.HelloOutStream,
},
),
},
},
},
)
} | go | func BuildHelloYARPCProcedures(server HelloYARPCServer) []transport.Procedure {
handler := &_HelloYARPCHandler{server}
return protobuf.BuildProcedures(
protobuf.BuildProceduresParams{
ServiceName: "uber.yarpc.internal.examples.streaming.Hello",
UnaryHandlerParams: []protobuf.BuildProceduresUnaryHandlerParams{
{
MethodName: "HelloUnary",
Handler: protobuf.NewUnaryHandler(
protobuf.UnaryHandlerParams{
Handle: handler.HelloUnary,
NewRequest: newHelloServiceHelloUnaryYARPCRequest,
},
),
},
},
OnewayHandlerParams: []protobuf.BuildProceduresOnewayHandlerParams{},
StreamHandlerParams: []protobuf.BuildProceduresStreamHandlerParams{
{
MethodName: "HelloThere",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.HelloThere,
},
),
},
{
MethodName: "HelloInStream",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.HelloInStream,
},
),
},
{
MethodName: "HelloOutStream",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.HelloOutStream,
},
),
},
},
},
)
} | [
"func",
"BuildHelloYARPCProcedures",
"(",
"server",
"HelloYARPCServer",
")",
"[",
"]",
"transport",
".",
"Procedure",
"{",
"handler",
":=",
"&",
"_HelloYARPCHandler",
"{",
"server",
"}",
"\n",
"return",
"protobuf",
".",
"BuildProcedures",
"(",
"protobuf",
".",
"BuildProceduresParams",
"{",
"ServiceName",
":",
"\"",
"\"",
",",
"UnaryHandlerParams",
":",
"[",
"]",
"protobuf",
".",
"BuildProceduresUnaryHandlerParams",
"{",
"{",
"MethodName",
":",
"\"",
"\"",
",",
"Handler",
":",
"protobuf",
".",
"NewUnaryHandler",
"(",
"protobuf",
".",
"UnaryHandlerParams",
"{",
"Handle",
":",
"handler",
".",
"HelloUnary",
",",
"NewRequest",
":",
"newHelloServiceHelloUnaryYARPCRequest",
",",
"}",
",",
")",
",",
"}",
",",
"}",
",",
"OnewayHandlerParams",
":",
"[",
"]",
"protobuf",
".",
"BuildProceduresOnewayHandlerParams",
"{",
"}",
",",
"StreamHandlerParams",
":",
"[",
"]",
"protobuf",
".",
"BuildProceduresStreamHandlerParams",
"{",
"{",
"MethodName",
":",
"\"",
"\"",
",",
"Handler",
":",
"protobuf",
".",
"NewStreamHandler",
"(",
"protobuf",
".",
"StreamHandlerParams",
"{",
"Handle",
":",
"handler",
".",
"HelloThere",
",",
"}",
",",
")",
",",
"}",
",",
"{",
"MethodName",
":",
"\"",
"\"",
",",
"Handler",
":",
"protobuf",
".",
"NewStreamHandler",
"(",
"protobuf",
".",
"StreamHandlerParams",
"{",
"Handle",
":",
"handler",
".",
"HelloInStream",
",",
"}",
",",
")",
",",
"}",
",",
"{",
"MethodName",
":",
"\"",
"\"",
",",
"Handler",
":",
"protobuf",
".",
"NewStreamHandler",
"(",
"protobuf",
".",
"StreamHandlerParams",
"{",
"Handle",
":",
"handler",
".",
"HelloOutStream",
",",
"}",
",",
")",
",",
"}",
",",
"}",
",",
"}",
",",
")",
"\n",
"}"
]
| // BuildHelloYARPCProcedures prepares an implementation of the Hello service for YARPC registration. | [
"BuildHelloYARPCProcedures",
"prepares",
"an",
"implementation",
"of",
"the",
"Hello",
"service",
"for",
"YARPC",
"registration",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/streaming/stream.pb.yarpc.go#L111-L158 |
11,011 | yarpc/yarpc-go | dispatcher_startup.go | StartTransports | func (s *PhasedStarter) StartTransports() error {
if s.transportsStartInitiated.Swap(true) {
return errors.New("already began starting transports")
}
defer s.transportsStarted.Store(true)
s.log.Info("starting transports")
wait := errorsync.ErrorWaiter{}
for _, t := range s.dispatcher.transports {
wait.Submit(s.start(t))
}
if errs := wait.Wait(); len(errs) != 0 {
return s.abort(errs)
}
s.log.Debug("started transports")
return nil
} | go | func (s *PhasedStarter) StartTransports() error {
if s.transportsStartInitiated.Swap(true) {
return errors.New("already began starting transports")
}
defer s.transportsStarted.Store(true)
s.log.Info("starting transports")
wait := errorsync.ErrorWaiter{}
for _, t := range s.dispatcher.transports {
wait.Submit(s.start(t))
}
if errs := wait.Wait(); len(errs) != 0 {
return s.abort(errs)
}
s.log.Debug("started transports")
return nil
} | [
"func",
"(",
"s",
"*",
"PhasedStarter",
")",
"StartTransports",
"(",
")",
"error",
"{",
"if",
"s",
".",
"transportsStartInitiated",
".",
"Swap",
"(",
"true",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"s",
".",
"transportsStarted",
".",
"Store",
"(",
"true",
")",
"\n",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"wait",
":=",
"errorsync",
".",
"ErrorWaiter",
"{",
"}",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"s",
".",
"dispatcher",
".",
"transports",
"{",
"wait",
".",
"Submit",
"(",
"s",
".",
"start",
"(",
"t",
")",
")",
"\n",
"}",
"\n",
"if",
"errs",
":=",
"wait",
".",
"Wait",
"(",
")",
";",
"len",
"(",
"errs",
")",
"!=",
"0",
"{",
"return",
"s",
".",
"abort",
"(",
"errs",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // StartTransports is the first step in startup. It starts all transports
// configured on the dispatcher, which is a necessary precondition for making
// and receiving RPCs. It's safe to call concurrently, but all calls after the
// first return an error. | [
"StartTransports",
"is",
"the",
"first",
"step",
"in",
"startup",
".",
"It",
"starts",
"all",
"transports",
"configured",
"on",
"the",
"dispatcher",
"which",
"is",
"a",
"necessary",
"precondition",
"for",
"making",
"and",
"receiving",
"RPCs",
".",
"It",
"s",
"safe",
"to",
"call",
"concurrently",
"but",
"all",
"calls",
"after",
"the",
"first",
"return",
"an",
"error",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/dispatcher_startup.go#L62-L77 |
11,012 | yarpc/yarpc-go | dispatcher_startup.go | StartOutbounds | func (s *PhasedStarter) StartOutbounds() error {
if !s.transportsStarted.Load() {
return errors.New("must start outbounds after transports")
}
if s.outboundsStartInitiated.Swap(true) {
return errors.New("already began starting outbounds")
}
defer s.outboundsStarted.Store(true)
s.log.Info("starting outbounds")
wait := errorsync.ErrorWaiter{}
for _, o := range s.dispatcher.outbounds {
wait.Submit(s.start(o.Unary))
wait.Submit(s.start(o.Oneway))
wait.Submit(s.start(o.Stream))
}
if errs := wait.Wait(); len(errs) != 0 {
return s.abort(errs)
}
s.log.Debug("started outbounds")
return nil
} | go | func (s *PhasedStarter) StartOutbounds() error {
if !s.transportsStarted.Load() {
return errors.New("must start outbounds after transports")
}
if s.outboundsStartInitiated.Swap(true) {
return errors.New("already began starting outbounds")
}
defer s.outboundsStarted.Store(true)
s.log.Info("starting outbounds")
wait := errorsync.ErrorWaiter{}
for _, o := range s.dispatcher.outbounds {
wait.Submit(s.start(o.Unary))
wait.Submit(s.start(o.Oneway))
wait.Submit(s.start(o.Stream))
}
if errs := wait.Wait(); len(errs) != 0 {
return s.abort(errs)
}
s.log.Debug("started outbounds")
return nil
} | [
"func",
"(",
"s",
"*",
"PhasedStarter",
")",
"StartOutbounds",
"(",
")",
"error",
"{",
"if",
"!",
"s",
".",
"transportsStarted",
".",
"Load",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"outboundsStartInitiated",
".",
"Swap",
"(",
"true",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"s",
".",
"outboundsStarted",
".",
"Store",
"(",
"true",
")",
"\n",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"wait",
":=",
"errorsync",
".",
"ErrorWaiter",
"{",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"s",
".",
"dispatcher",
".",
"outbounds",
"{",
"wait",
".",
"Submit",
"(",
"s",
".",
"start",
"(",
"o",
".",
"Unary",
")",
")",
"\n",
"wait",
".",
"Submit",
"(",
"s",
".",
"start",
"(",
"o",
".",
"Oneway",
")",
")",
"\n",
"wait",
".",
"Submit",
"(",
"s",
".",
"start",
"(",
"o",
".",
"Stream",
")",
")",
"\n",
"}",
"\n",
"if",
"errs",
":=",
"wait",
".",
"Wait",
"(",
")",
";",
"len",
"(",
"errs",
")",
"!=",
"0",
"{",
"return",
"s",
".",
"abort",
"(",
"errs",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // StartOutbounds is the second phase of startup. It starts all outbounds
// configured on the dispatcher, which allows users of the dispatcher to
// construct clients and begin making outbound RPCs. It's safe to call
// concurrently, but all calls after the first return an error. | [
"StartOutbounds",
"is",
"the",
"second",
"phase",
"of",
"startup",
".",
"It",
"starts",
"all",
"outbounds",
"configured",
"on",
"the",
"dispatcher",
"which",
"allows",
"users",
"of",
"the",
"dispatcher",
"to",
"construct",
"clients",
"and",
"begin",
"making",
"outbound",
"RPCs",
".",
"It",
"s",
"safe",
"to",
"call",
"concurrently",
"but",
"all",
"calls",
"after",
"the",
"first",
"return",
"an",
"error",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/dispatcher_startup.go#L83-L103 |
11,013 | yarpc/yarpc-go | dispatcher_startup.go | StartInbounds | func (s *PhasedStarter) StartInbounds() error {
if !s.transportsStarted.Load() || !s.outboundsStarted.Load() {
return errors.New("must start inbounds after transports and outbounds")
}
if s.inboundsStartInitiated.Swap(true) {
return errors.New("already began starting inbounds")
}
s.log.Info("starting inbounds")
wait := errorsync.ErrorWaiter{}
for _, i := range s.dispatcher.inbounds {
wait.Submit(s.start(i))
}
if errs := wait.Wait(); len(errs) != 0 {
return s.abort(errs)
}
s.log.Debug("started inbounds")
return nil
} | go | func (s *PhasedStarter) StartInbounds() error {
if !s.transportsStarted.Load() || !s.outboundsStarted.Load() {
return errors.New("must start inbounds after transports and outbounds")
}
if s.inboundsStartInitiated.Swap(true) {
return errors.New("already began starting inbounds")
}
s.log.Info("starting inbounds")
wait := errorsync.ErrorWaiter{}
for _, i := range s.dispatcher.inbounds {
wait.Submit(s.start(i))
}
if errs := wait.Wait(); len(errs) != 0 {
return s.abort(errs)
}
s.log.Debug("started inbounds")
return nil
} | [
"func",
"(",
"s",
"*",
"PhasedStarter",
")",
"StartInbounds",
"(",
")",
"error",
"{",
"if",
"!",
"s",
".",
"transportsStarted",
".",
"Load",
"(",
")",
"||",
"!",
"s",
".",
"outboundsStarted",
".",
"Load",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"inboundsStartInitiated",
".",
"Swap",
"(",
"true",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"wait",
":=",
"errorsync",
".",
"ErrorWaiter",
"{",
"}",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"s",
".",
"dispatcher",
".",
"inbounds",
"{",
"wait",
".",
"Submit",
"(",
"s",
".",
"start",
"(",
"i",
")",
")",
"\n",
"}",
"\n",
"if",
"errs",
":=",
"wait",
".",
"Wait",
"(",
")",
";",
"len",
"(",
"errs",
")",
"!=",
"0",
"{",
"return",
"s",
".",
"abort",
"(",
"errs",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // StartInbounds is the final phase of startup. It starts all inbounds
// configured on the dispatcher, which allows any registered procedures to
// begin receiving requests. It's safe to call concurrently, but all calls
// after the first return an error. | [
"StartInbounds",
"is",
"the",
"final",
"phase",
"of",
"startup",
".",
"It",
"starts",
"all",
"inbounds",
"configured",
"on",
"the",
"dispatcher",
"which",
"allows",
"any",
"registered",
"procedures",
"to",
"begin",
"receiving",
"requests",
".",
"It",
"s",
"safe",
"to",
"call",
"concurrently",
"but",
"all",
"calls",
"after",
"the",
"first",
"return",
"an",
"error",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/dispatcher_startup.go#L109-L126 |
11,014 | yarpc/yarpc-go | dispatcher_startup.go | StopInbounds | func (s *PhasedStopper) StopInbounds() error {
if s.inboundsStopInitiated.Swap(true) {
return errors.New("already began stopping inbounds")
}
defer s.inboundsStopped.Store(true)
s.log.Debug("stopping inbounds")
wait := errorsync.ErrorWaiter{}
for _, ib := range s.dispatcher.inbounds {
wait.Submit(ib.Stop)
}
if errs := wait.Wait(); len(errs) > 0 {
return multierr.Combine(errs...)
}
s.log.Debug("stopped inbounds")
return nil
} | go | func (s *PhasedStopper) StopInbounds() error {
if s.inboundsStopInitiated.Swap(true) {
return errors.New("already began stopping inbounds")
}
defer s.inboundsStopped.Store(true)
s.log.Debug("stopping inbounds")
wait := errorsync.ErrorWaiter{}
for _, ib := range s.dispatcher.inbounds {
wait.Submit(ib.Stop)
}
if errs := wait.Wait(); len(errs) > 0 {
return multierr.Combine(errs...)
}
s.log.Debug("stopped inbounds")
return nil
} | [
"func",
"(",
"s",
"*",
"PhasedStopper",
")",
"StopInbounds",
"(",
")",
"error",
"{",
"if",
"s",
".",
"inboundsStopInitiated",
".",
"Swap",
"(",
"true",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"s",
".",
"inboundsStopped",
".",
"Store",
"(",
"true",
")",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"wait",
":=",
"errorsync",
".",
"ErrorWaiter",
"{",
"}",
"\n",
"for",
"_",
",",
"ib",
":=",
"range",
"s",
".",
"dispatcher",
".",
"inbounds",
"{",
"wait",
".",
"Submit",
"(",
"ib",
".",
"Stop",
")",
"\n",
"}",
"\n",
"if",
"errs",
":=",
"wait",
".",
"Wait",
"(",
")",
";",
"len",
"(",
"errs",
")",
">",
"0",
"{",
"return",
"multierr",
".",
"Combine",
"(",
"errs",
"...",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // StopInbounds is the first step in shutdown. It stops all inbounds
// configured on the dispatcher, which stops routing RPCs to all registered
// procedures. It's safe to call concurrently, but all calls after the first
// return an error. | [
"StopInbounds",
"is",
"the",
"first",
"step",
"in",
"shutdown",
".",
"It",
"stops",
"all",
"inbounds",
"configured",
"on",
"the",
"dispatcher",
"which",
"stops",
"routing",
"RPCs",
"to",
"all",
"registered",
"procedures",
".",
"It",
"s",
"safe",
"to",
"call",
"concurrently",
"but",
"all",
"calls",
"after",
"the",
"first",
"return",
"an",
"error",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/dispatcher_startup.go#L195-L210 |
11,015 | yarpc/yarpc-go | dispatcher_startup.go | StopOutbounds | func (s *PhasedStopper) StopOutbounds() error {
if !s.inboundsStopped.Load() {
return errors.New("must stop inbounds first")
}
if s.outboundsStopInitiated.Swap(true) {
return errors.New("already began stopping outbounds")
}
defer s.outboundsStopped.Store(true)
s.log.Debug("stopping outbounds")
wait := errorsync.ErrorWaiter{}
for _, o := range s.dispatcher.outbounds {
if o.Unary != nil {
wait.Submit(o.Unary.Stop)
}
if o.Oneway != nil {
wait.Submit(o.Oneway.Stop)
}
if o.Stream != nil {
wait.Submit(o.Stream.Stop)
}
}
if errs := wait.Wait(); len(errs) > 0 {
return multierr.Combine(errs...)
}
s.log.Debug("stopped outbounds")
return nil
} | go | func (s *PhasedStopper) StopOutbounds() error {
if !s.inboundsStopped.Load() {
return errors.New("must stop inbounds first")
}
if s.outboundsStopInitiated.Swap(true) {
return errors.New("already began stopping outbounds")
}
defer s.outboundsStopped.Store(true)
s.log.Debug("stopping outbounds")
wait := errorsync.ErrorWaiter{}
for _, o := range s.dispatcher.outbounds {
if o.Unary != nil {
wait.Submit(o.Unary.Stop)
}
if o.Oneway != nil {
wait.Submit(o.Oneway.Stop)
}
if o.Stream != nil {
wait.Submit(o.Stream.Stop)
}
}
if errs := wait.Wait(); len(errs) > 0 {
return multierr.Combine(errs...)
}
s.log.Debug("stopped outbounds")
return nil
} | [
"func",
"(",
"s",
"*",
"PhasedStopper",
")",
"StopOutbounds",
"(",
")",
"error",
"{",
"if",
"!",
"s",
".",
"inboundsStopped",
".",
"Load",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"outboundsStopInitiated",
".",
"Swap",
"(",
"true",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"s",
".",
"outboundsStopped",
".",
"Store",
"(",
"true",
")",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"wait",
":=",
"errorsync",
".",
"ErrorWaiter",
"{",
"}",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"s",
".",
"dispatcher",
".",
"outbounds",
"{",
"if",
"o",
".",
"Unary",
"!=",
"nil",
"{",
"wait",
".",
"Submit",
"(",
"o",
".",
"Unary",
".",
"Stop",
")",
"\n",
"}",
"\n",
"if",
"o",
".",
"Oneway",
"!=",
"nil",
"{",
"wait",
".",
"Submit",
"(",
"o",
".",
"Oneway",
".",
"Stop",
")",
"\n",
"}",
"\n",
"if",
"o",
".",
"Stream",
"!=",
"nil",
"{",
"wait",
".",
"Submit",
"(",
"o",
".",
"Stream",
".",
"Stop",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"errs",
":=",
"wait",
".",
"Wait",
"(",
")",
";",
"len",
"(",
"errs",
")",
">",
"0",
"{",
"return",
"multierr",
".",
"Combine",
"(",
"errs",
"...",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // StopOutbounds is the second step in shutdown. It stops all outbounds
// configured on the dispatcher, which stops clients from making outbound
// RPCs. It's safe to call concurrently, but all calls after the first return
// an error. | [
"StopOutbounds",
"is",
"the",
"second",
"step",
"in",
"shutdown",
".",
"It",
"stops",
"all",
"outbounds",
"configured",
"on",
"the",
"dispatcher",
"which",
"stops",
"clients",
"from",
"making",
"outbound",
"RPCs",
".",
"It",
"s",
"safe",
"to",
"call",
"concurrently",
"but",
"all",
"calls",
"after",
"the",
"first",
"return",
"an",
"error",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/dispatcher_startup.go#L216-L242 |
11,016 | yarpc/yarpc-go | dispatcher_startup.go | StopTransports | func (s *PhasedStopper) StopTransports() error {
if !s.inboundsStopped.Load() || !s.outboundsStopped.Load() {
return errors.New("must stop inbounds and outbounds first")
}
if s.transportsStopInitiated.Swap(true) {
return errors.New("already began stopping transports")
}
s.log.Debug("stopping transports")
wait := errorsync.ErrorWaiter{}
for _, t := range s.dispatcher.transports {
wait.Submit(t.Stop)
}
if errs := wait.Wait(); len(errs) > 0 {
return multierr.Combine(errs...)
}
s.log.Debug("stopped transports")
s.log.Debug("stopping metrics push loop, if any")
s.dispatcher.stopMeter()
s.log.Debug("stopped metrics push loop, if any")
return nil
} | go | func (s *PhasedStopper) StopTransports() error {
if !s.inboundsStopped.Load() || !s.outboundsStopped.Load() {
return errors.New("must stop inbounds and outbounds first")
}
if s.transportsStopInitiated.Swap(true) {
return errors.New("already began stopping transports")
}
s.log.Debug("stopping transports")
wait := errorsync.ErrorWaiter{}
for _, t := range s.dispatcher.transports {
wait.Submit(t.Stop)
}
if errs := wait.Wait(); len(errs) > 0 {
return multierr.Combine(errs...)
}
s.log.Debug("stopped transports")
s.log.Debug("stopping metrics push loop, if any")
s.dispatcher.stopMeter()
s.log.Debug("stopped metrics push loop, if any")
return nil
} | [
"func",
"(",
"s",
"*",
"PhasedStopper",
")",
"StopTransports",
"(",
")",
"error",
"{",
"if",
"!",
"s",
".",
"inboundsStopped",
".",
"Load",
"(",
")",
"||",
"!",
"s",
".",
"outboundsStopped",
".",
"Load",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"transportsStopInitiated",
".",
"Swap",
"(",
"true",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"wait",
":=",
"errorsync",
".",
"ErrorWaiter",
"{",
"}",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"s",
".",
"dispatcher",
".",
"transports",
"{",
"wait",
".",
"Submit",
"(",
"t",
".",
"Stop",
")",
"\n",
"}",
"\n",
"if",
"errs",
":=",
"wait",
".",
"Wait",
"(",
")",
";",
"len",
"(",
"errs",
")",
">",
"0",
"{",
"return",
"multierr",
".",
"Combine",
"(",
"errs",
"...",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"s",
".",
"dispatcher",
".",
"stopMeter",
"(",
")",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // StopTransports is the final step in shutdown. It stops all transports
// configured on the dispatcher and cleans up any ancillary goroutines. It's
// safe to call concurrently, but all calls after the first return an error. | [
"StopTransports",
"is",
"the",
"final",
"step",
"in",
"shutdown",
".",
"It",
"stops",
"all",
"transports",
"configured",
"on",
"the",
"dispatcher",
"and",
"cleans",
"up",
"any",
"ancillary",
"goroutines",
".",
"It",
"s",
"safe",
"to",
"call",
"concurrently",
"but",
"all",
"calls",
"after",
"the",
"first",
"return",
"an",
"error",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/dispatcher_startup.go#L247-L269 |
11,017 | yarpc/yarpc-go | transport/http/inbound.go | Mux | func Mux(pattern string, mux *http.ServeMux) InboundOption {
return func(i *Inbound) {
i.mux = mux
i.muxPattern = pattern
}
} | go | func Mux(pattern string, mux *http.ServeMux) InboundOption {
return func(i *Inbound) {
i.mux = mux
i.muxPattern = pattern
}
} | [
"func",
"Mux",
"(",
"pattern",
"string",
",",
"mux",
"*",
"http",
".",
"ServeMux",
")",
"InboundOption",
"{",
"return",
"func",
"(",
"i",
"*",
"Inbound",
")",
"{",
"i",
".",
"mux",
"=",
"mux",
"\n",
"i",
".",
"muxPattern",
"=",
"pattern",
"\n",
"}",
"\n",
"}"
]
| // Mux specifies that the HTTP server should make the YARPC endpoint available
// under the given pattern on the given ServeMux. By default, the YARPC
// service is made available on all paths of the HTTP server. By specifying a
// ServeMux, users can narrow the endpoints under which the YARPC service is
// available and offer their own non-YARPC endpoints. | [
"Mux",
"specifies",
"that",
"the",
"HTTP",
"server",
"should",
"make",
"the",
"YARPC",
"endpoint",
"available",
"under",
"the",
"given",
"pattern",
"on",
"the",
"given",
"ServeMux",
".",
"By",
"default",
"the",
"YARPC",
"service",
"is",
"made",
"available",
"on",
"all",
"paths",
"of",
"the",
"HTTP",
"server",
".",
"By",
"specifying",
"a",
"ServeMux",
"users",
"can",
"narrow",
"the",
"endpoints",
"under",
"which",
"the",
"YARPC",
"service",
"is",
"available",
"and",
"offer",
"their",
"own",
"non",
"-",
"YARPC",
"endpoints",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/http/inbound.go#L52-L57 |
11,018 | yarpc/yarpc-go | transport/http/inbound.go | Interceptor | func Interceptor(interceptor func(yarpcHandler http.Handler) http.Handler) InboundOption {
return func(i *Inbound) {
i.interceptor = interceptor
}
} | go | func Interceptor(interceptor func(yarpcHandler http.Handler) http.Handler) InboundOption {
return func(i *Inbound) {
i.interceptor = interceptor
}
} | [
"func",
"Interceptor",
"(",
"interceptor",
"func",
"(",
"yarpcHandler",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
")",
"InboundOption",
"{",
"return",
"func",
"(",
"i",
"*",
"Inbound",
")",
"{",
"i",
".",
"interceptor",
"=",
"interceptor",
"\n",
"}",
"\n",
"}"
]
| // Interceptor specifies a function which can wrap the YARPC handler. If
// provided, this function will be called with an http.Handler which will
// route requests through YARPC. The http.Handler returned by this function
// may delegate requests to the provided YARPC handler to route them through
// YARPC. | [
"Interceptor",
"specifies",
"a",
"function",
"which",
"can",
"wrap",
"the",
"YARPC",
"handler",
".",
"If",
"provided",
"this",
"function",
"will",
"be",
"called",
"with",
"an",
"http",
".",
"Handler",
"which",
"will",
"route",
"requests",
"through",
"YARPC",
".",
"The",
"http",
".",
"Handler",
"returned",
"by",
"this",
"function",
"may",
"delegate",
"requests",
"to",
"the",
"provided",
"YARPC",
"handler",
"to",
"route",
"them",
"through",
"YARPC",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/http/inbound.go#L64-L68 |
11,019 | yarpc/yarpc-go | transport/http/inbound.go | ShutdownTimeout | func ShutdownTimeout(timeout time.Duration) InboundOption {
return func(i *Inbound) {
i.shutdownTimeout = timeout
}
} | go | func ShutdownTimeout(timeout time.Duration) InboundOption {
return func(i *Inbound) {
i.shutdownTimeout = timeout
}
} | [
"func",
"ShutdownTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"InboundOption",
"{",
"return",
"func",
"(",
"i",
"*",
"Inbound",
")",
"{",
"i",
".",
"shutdownTimeout",
"=",
"timeout",
"\n",
"}",
"\n",
"}"
]
| // ShutdownTimeout specifies the maximum duration the inbound should wait for
// closing idle connections, and pending calls to complete.
//
// Set to 0 to wait for a complete drain.
//
// Defaults to 5 seconds. | [
"ShutdownTimeout",
"specifies",
"the",
"maximum",
"duration",
"the",
"inbound",
"should",
"wait",
"for",
"closing",
"idle",
"connections",
"and",
"pending",
"calls",
"to",
"complete",
".",
"Set",
"to",
"0",
"to",
"wait",
"for",
"a",
"complete",
"drain",
".",
"Defaults",
"to",
"5",
"seconds",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/http/inbound.go#L92-L96 |
11,020 | yarpc/yarpc-go | transport/http/inbound.go | NewInbound | func (t *Transport) NewInbound(addr string, opts ...InboundOption) *Inbound {
i := &Inbound{
once: lifecycle.NewOnce(),
addr: addr,
shutdownTimeout: defaultShutdownTimeout,
tracer: t.tracer,
logger: t.logger,
transport: t,
grabHeaders: make(map[string]struct{}),
bothResponseError: true,
}
for _, opt := range opts {
opt(i)
}
return i
} | go | func (t *Transport) NewInbound(addr string, opts ...InboundOption) *Inbound {
i := &Inbound{
once: lifecycle.NewOnce(),
addr: addr,
shutdownTimeout: defaultShutdownTimeout,
tracer: t.tracer,
logger: t.logger,
transport: t,
grabHeaders: make(map[string]struct{}),
bothResponseError: true,
}
for _, opt := range opts {
opt(i)
}
return i
} | [
"func",
"(",
"t",
"*",
"Transport",
")",
"NewInbound",
"(",
"addr",
"string",
",",
"opts",
"...",
"InboundOption",
")",
"*",
"Inbound",
"{",
"i",
":=",
"&",
"Inbound",
"{",
"once",
":",
"lifecycle",
".",
"NewOnce",
"(",
")",
",",
"addr",
":",
"addr",
",",
"shutdownTimeout",
":",
"defaultShutdownTimeout",
",",
"tracer",
":",
"t",
".",
"tracer",
",",
"logger",
":",
"t",
".",
"logger",
",",
"transport",
":",
"t",
",",
"grabHeaders",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
",",
"bothResponseError",
":",
"true",
",",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"i",
")",
"\n",
"}",
"\n",
"return",
"i",
"\n",
"}"
]
| // NewInbound builds a new HTTP inbound that listens on the given address and
// sharing this transport. | [
"NewInbound",
"builds",
"a",
"new",
"HTTP",
"inbound",
"that",
"listens",
"on",
"the",
"given",
"address",
"and",
"sharing",
"this",
"transport",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/http/inbound.go#L100-L115 |
11,021 | yarpc/yarpc-go | transport/http/inbound.go | Tracer | func (i *Inbound) Tracer(tracer opentracing.Tracer) *Inbound {
i.tracer = tracer
return i
} | go | func (i *Inbound) Tracer(tracer opentracing.Tracer) *Inbound {
i.tracer = tracer
return i
} | [
"func",
"(",
"i",
"*",
"Inbound",
")",
"Tracer",
"(",
"tracer",
"opentracing",
".",
"Tracer",
")",
"*",
"Inbound",
"{",
"i",
".",
"tracer",
"=",
"tracer",
"\n",
"return",
"i",
"\n",
"}"
]
| // Tracer configures a tracer on this inbound. | [
"Tracer",
"configures",
"a",
"tracer",
"on",
"this",
"inbound",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/http/inbound.go#L139-L142 |
11,022 | yarpc/yarpc-go | transport/http/inbound.go | Stop | func (i *Inbound) Stop() error {
ctx, cancel := context.WithTimeout(context.Background(), i.shutdownTimeout)
defer cancel()
return i.shutdown(ctx)
} | go | func (i *Inbound) Stop() error {
ctx, cancel := context.WithTimeout(context.Background(), i.shutdownTimeout)
defer cancel()
return i.shutdown(ctx)
} | [
"func",
"(",
"i",
"*",
"Inbound",
")",
"Stop",
"(",
")",
"error",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"context",
".",
"Background",
"(",
")",
",",
"i",
".",
"shutdownTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"return",
"i",
".",
"shutdown",
"(",
"ctx",
")",
"\n",
"}"
]
| // Stop the inbound using Shutdown. | [
"Stop",
"the",
"inbound",
"using",
"Shutdown",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/http/inbound.go#L204-L209 |
11,023 | yarpc/yarpc-go | transport/http/inbound.go | shutdown | func (i *Inbound) shutdown(ctx context.Context) error {
return i.once.Stop(func() error {
if i.server == nil {
return nil
}
return i.server.Shutdown(ctx)
})
} | go | func (i *Inbound) shutdown(ctx context.Context) error {
return i.once.Stop(func() error {
if i.server == nil {
return nil
}
return i.server.Shutdown(ctx)
})
} | [
"func",
"(",
"i",
"*",
"Inbound",
")",
"shutdown",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"return",
"i",
".",
"once",
".",
"Stop",
"(",
"func",
"(",
")",
"error",
"{",
"if",
"i",
".",
"server",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"i",
".",
"server",
".",
"Shutdown",
"(",
"ctx",
")",
"\n",
"}",
")",
"\n",
"}"
]
| // shutdown the inbound, closing the listening socket, closing idle
// connections, and waiting for all pending calls to complete. | [
"shutdown",
"the",
"inbound",
"closing",
"the",
"listening",
"socket",
"closing",
"idle",
"connections",
"and",
"waiting",
"for",
"all",
"pending",
"calls",
"to",
"complete",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/http/inbound.go#L213-L221 |
11,024 | yarpc/yarpc-go | transport/http/inbound.go | Addr | func (i *Inbound) Addr() net.Addr {
if i.server == nil {
return nil
}
listener := i.server.Listener()
if listener == nil {
return nil
}
return listener.Addr()
} | go | func (i *Inbound) Addr() net.Addr {
if i.server == nil {
return nil
}
listener := i.server.Listener()
if listener == nil {
return nil
}
return listener.Addr()
} | [
"func",
"(",
"i",
"*",
"Inbound",
")",
"Addr",
"(",
")",
"net",
".",
"Addr",
"{",
"if",
"i",
".",
"server",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"listener",
":=",
"i",
".",
"server",
".",
"Listener",
"(",
")",
"\n",
"if",
"listener",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"listener",
".",
"Addr",
"(",
")",
"\n",
"}"
]
| // Addr returns the address on which the server is listening. Returns nil if
// Start has not been called yet. | [
"Addr",
"returns",
"the",
"address",
"on",
"which",
"the",
"server",
"is",
"listening",
".",
"Returns",
"nil",
"if",
"Start",
"has",
"not",
"been",
"called",
"yet",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/http/inbound.go#L230-L241 |
11,025 | yarpc/yarpc-go | peer/pendingheap/heap.go | Swap | func (ph *pendingHeap) Swap(i, j int) {
p1 := ph.peers[i]
p2 := ph.peers[j]
ph.peers[i], ph.peers[j] = ph.peers[j], ph.peers[i]
p1.index = j
p2.index = i
} | go | func (ph *pendingHeap) Swap(i, j int) {
p1 := ph.peers[i]
p2 := ph.peers[j]
ph.peers[i], ph.peers[j] = ph.peers[j], ph.peers[i]
p1.index = j
p2.index = i
} | [
"func",
"(",
"ph",
"*",
"pendingHeap",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"p1",
":=",
"ph",
".",
"peers",
"[",
"i",
"]",
"\n",
"p2",
":=",
"ph",
".",
"peers",
"[",
"j",
"]",
"\n\n",
"ph",
".",
"peers",
"[",
"i",
"]",
",",
"ph",
".",
"peers",
"[",
"j",
"]",
"=",
"ph",
".",
"peers",
"[",
"j",
"]",
",",
"ph",
".",
"peers",
"[",
"i",
"]",
"\n",
"p1",
".",
"index",
"=",
"j",
"\n",
"p2",
".",
"index",
"=",
"i",
"\n",
"}"
]
| // Swap implements the heap.Interface. Do NOT use this method directly.
// Swap must be called in the context of a lock, as it is indirectly called
// through heap.Push and heap.Pop. | [
"Swap",
"implements",
"the",
"heap",
".",
"Interface",
".",
"Do",
"NOT",
"use",
"this",
"method",
"directly",
".",
"Swap",
"must",
"be",
"called",
"in",
"the",
"context",
"of",
"a",
"lock",
"as",
"it",
"is",
"indirectly",
"called",
"through",
"heap",
".",
"Push",
"and",
"heap",
".",
"Pop",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/pendingheap/heap.go#L132-L139 |
11,026 | yarpc/yarpc-go | peer/pendingheap/heap.go | Push | func (ph *pendingHeap) Push(x interface{}) {
ps := x.(*peerScore)
ps.index = len(ph.peers)
ph.peers = append(ph.peers, ps)
} | go | func (ph *pendingHeap) Push(x interface{}) {
ps := x.(*peerScore)
ps.index = len(ph.peers)
ph.peers = append(ph.peers, ps)
} | [
"func",
"(",
"ph",
"*",
"pendingHeap",
")",
"Push",
"(",
"x",
"interface",
"{",
"}",
")",
"{",
"ps",
":=",
"x",
".",
"(",
"*",
"peerScore",
")",
"\n",
"ps",
".",
"index",
"=",
"len",
"(",
"ph",
".",
"peers",
")",
"\n",
"ph",
".",
"peers",
"=",
"append",
"(",
"ph",
".",
"peers",
",",
"ps",
")",
"\n",
"}"
]
| // Push implements the heap.Interface. Do NOT use this method directly.
// Use pushPeer instead.
// Push must be called in the context of a lock, as it is indirectly called
// through heap.Push. | [
"Push",
"implements",
"the",
"heap",
".",
"Interface",
".",
"Do",
"NOT",
"use",
"this",
"method",
"directly",
".",
"Use",
"pushPeer",
"instead",
".",
"Push",
"must",
"be",
"called",
"in",
"the",
"context",
"of",
"a",
"lock",
"as",
"it",
"is",
"indirectly",
"called",
"through",
"heap",
".",
"Push",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/pendingheap/heap.go#L145-L149 |
11,027 | yarpc/yarpc-go | peer/pendingheap/heap.go | Pop | func (ph *pendingHeap) Pop() interface{} {
lastIndex := len(ph.peers) - 1
last := ph.peers[lastIndex]
ph.peers = ph.peers[:lastIndex]
return last
} | go | func (ph *pendingHeap) Pop() interface{} {
lastIndex := len(ph.peers) - 1
last := ph.peers[lastIndex]
ph.peers = ph.peers[:lastIndex]
return last
} | [
"func",
"(",
"ph",
"*",
"pendingHeap",
")",
"Pop",
"(",
")",
"interface",
"{",
"}",
"{",
"lastIndex",
":=",
"len",
"(",
"ph",
".",
"peers",
")",
"-",
"1",
"\n",
"last",
":=",
"ph",
".",
"peers",
"[",
"lastIndex",
"]",
"\n",
"ph",
".",
"peers",
"=",
"ph",
".",
"peers",
"[",
":",
"lastIndex",
"]",
"\n",
"return",
"last",
"\n",
"}"
]
| // Pop implements the heap.Interface. Do NOT use this method directly.
// Use popPeer instead.
// Pop must be called in the context of a lock, as it is indirectly called
// through heap.Pop. | [
"Pop",
"implements",
"the",
"heap",
".",
"Interface",
".",
"Do",
"NOT",
"use",
"this",
"method",
"directly",
".",
"Use",
"popPeer",
"instead",
".",
"Pop",
"must",
"be",
"called",
"in",
"the",
"context",
"of",
"a",
"lock",
"as",
"it",
"is",
"indirectly",
"called",
"through",
"heap",
".",
"Pop",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/pendingheap/heap.go#L155-L160 |
11,028 | yarpc/yarpc-go | peer/pendingheap/heap.go | delete | func (ph *pendingHeap) delete(ps *peerScore) {
if ps.index < 0 {
return
}
index := ps.index
// Swap the element we want to delete with the last element, then pop it off.
ph.Swap(index, ph.Len()-1)
ph.Pop()
// If the original index still exists in the list, it contains a different
// element so update the heap.
if index < ph.Len() {
ph.update(index)
}
// Set the index to negative so we do not try to delete it again.
ps.index = -1
} | go | func (ph *pendingHeap) delete(ps *peerScore) {
if ps.index < 0 {
return
}
index := ps.index
// Swap the element we want to delete with the last element, then pop it off.
ph.Swap(index, ph.Len()-1)
ph.Pop()
// If the original index still exists in the list, it contains a different
// element so update the heap.
if index < ph.Len() {
ph.update(index)
}
// Set the index to negative so we do not try to delete it again.
ps.index = -1
} | [
"func",
"(",
"ph",
"*",
"pendingHeap",
")",
"delete",
"(",
"ps",
"*",
"peerScore",
")",
"{",
"if",
"ps",
".",
"index",
"<",
"0",
"{",
"return",
"\n",
"}",
"\n",
"index",
":=",
"ps",
".",
"index",
"\n\n",
"// Swap the element we want to delete with the last element, then pop it off.",
"ph",
".",
"Swap",
"(",
"index",
",",
"ph",
".",
"Len",
"(",
")",
"-",
"1",
")",
"\n",
"ph",
".",
"Pop",
"(",
")",
"\n\n",
"// If the original index still exists in the list, it contains a different",
"// element so update the heap.",
"if",
"index",
"<",
"ph",
".",
"Len",
"(",
")",
"{",
"ph",
".",
"update",
"(",
"index",
")",
"\n",
"}",
"\n\n",
"// Set the index to negative so we do not try to delete it again.",
"ps",
".",
"index",
"=",
"-",
"1",
"\n",
"}"
]
| // delete removes the score at the given index.
// delete must be called in a lock. | [
"delete",
"removes",
"the",
"score",
"at",
"the",
"given",
"index",
".",
"delete",
"must",
"be",
"called",
"in",
"a",
"lock",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/pendingheap/heap.go#L164-L182 |
11,029 | yarpc/yarpc-go | peer/pendingheap/heap.go | pushPeerRandom | func (ph *pendingHeap) pushPeerRandom(ps *peerScore) {
ph.next++
ps.last = ph.next
random := ph.nextRand(len(ph.peers) + 1)
if random < len(ph.peers) {
randPeer := ph.peers[random]
ps.last, randPeer.last = randPeer.last, ps.last
heap.Fix(ph, random)
}
heap.Push(ph, ps)
} | go | func (ph *pendingHeap) pushPeerRandom(ps *peerScore) {
ph.next++
ps.last = ph.next
random := ph.nextRand(len(ph.peers) + 1)
if random < len(ph.peers) {
randPeer := ph.peers[random]
ps.last, randPeer.last = randPeer.last, ps.last
heap.Fix(ph, random)
}
heap.Push(ph, ps)
} | [
"func",
"(",
"ph",
"*",
"pendingHeap",
")",
"pushPeerRandom",
"(",
"ps",
"*",
"peerScore",
")",
"{",
"ph",
".",
"next",
"++",
"\n",
"ps",
".",
"last",
"=",
"ph",
".",
"next",
"\n\n",
"random",
":=",
"ph",
".",
"nextRand",
"(",
"len",
"(",
"ph",
".",
"peers",
")",
"+",
"1",
")",
"\n",
"if",
"random",
"<",
"len",
"(",
"ph",
".",
"peers",
")",
"{",
"randPeer",
":=",
"ph",
".",
"peers",
"[",
"random",
"]",
"\n",
"ps",
".",
"last",
",",
"randPeer",
".",
"last",
"=",
"randPeer",
".",
"last",
",",
"ps",
".",
"last",
"\n",
"heap",
".",
"Fix",
"(",
"ph",
",",
"random",
")",
"\n",
"}",
"\n\n",
"heap",
".",
"Push",
"(",
"ph",
",",
"ps",
")",
"\n",
"}"
]
| // pushPeerRandom inserts a peer randomly into the heap among equally scored
// peers. This is expected to be called only by Add.
//
// This ensures that batches of peer updates are inserted randomly throughout
// the heap, preventing hearding behavior that may be observed during batch
// deployments.
//
// This must be called in the context of a lock. | [
"pushPeerRandom",
"inserts",
"a",
"peer",
"randomly",
"into",
"the",
"heap",
"among",
"equally",
"scored",
"peers",
".",
"This",
"is",
"expected",
"to",
"be",
"called",
"only",
"by",
"Add",
".",
"This",
"ensures",
"that",
"batches",
"of",
"peer",
"updates",
"are",
"inserted",
"randomly",
"throughout",
"the",
"heap",
"preventing",
"hearding",
"behavior",
"that",
"may",
"be",
"observed",
"during",
"batch",
"deployments",
".",
"This",
"must",
"be",
"called",
"in",
"the",
"context",
"of",
"a",
"lock",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/peer/pendingheap/heap.go#L199-L211 |
11,030 | yarpc/yarpc-go | internal/examples/thrift-oneway/main.go | Sink | func (h *helloHandler) Sink(ctx context.Context, snk *sink.SinkRequest) error {
log.Println("received message:", snk.Message)
return nil
} | go | func (h *helloHandler) Sink(ctx context.Context, snk *sink.SinkRequest) error {
log.Println("received message:", snk.Message)
return nil
} | [
"func",
"(",
"h",
"*",
"helloHandler",
")",
"Sink",
"(",
"ctx",
"context",
".",
"Context",
",",
"snk",
"*",
"sink",
".",
"SinkRequest",
")",
"error",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"snk",
".",
"Message",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Sink is our server-side handler implementation | [
"Sink",
"is",
"our",
"server",
"-",
"side",
"handler",
"implementation"
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/examples/thrift-oneway/main.go#L81-L84 |
11,031 | yarpc/yarpc-go | internal/inboundmiddleware/chain.go | UnaryChain | func UnaryChain(mw ...middleware.UnaryInbound) middleware.UnaryInbound {
unchained := make([]middleware.UnaryInbound, 0, len(mw))
for _, m := range mw {
if m == nil {
continue
}
if c, ok := m.(unaryChain); ok {
unchained = append(unchained, c...)
continue
}
unchained = append(unchained, m)
}
switch len(unchained) {
case 0:
return middleware.NopUnaryInbound
case 1:
return unchained[0]
default:
return unaryChain(unchained)
}
} | go | func UnaryChain(mw ...middleware.UnaryInbound) middleware.UnaryInbound {
unchained := make([]middleware.UnaryInbound, 0, len(mw))
for _, m := range mw {
if m == nil {
continue
}
if c, ok := m.(unaryChain); ok {
unchained = append(unchained, c...)
continue
}
unchained = append(unchained, m)
}
switch len(unchained) {
case 0:
return middleware.NopUnaryInbound
case 1:
return unchained[0]
default:
return unaryChain(unchained)
}
} | [
"func",
"UnaryChain",
"(",
"mw",
"...",
"middleware",
".",
"UnaryInbound",
")",
"middleware",
".",
"UnaryInbound",
"{",
"unchained",
":=",
"make",
"(",
"[",
"]",
"middleware",
".",
"UnaryInbound",
",",
"0",
",",
"len",
"(",
"mw",
")",
")",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"mw",
"{",
"if",
"m",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"c",
",",
"ok",
":=",
"m",
".",
"(",
"unaryChain",
")",
";",
"ok",
"{",
"unchained",
"=",
"append",
"(",
"unchained",
",",
"c",
"...",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"unchained",
"=",
"append",
"(",
"unchained",
",",
"m",
")",
"\n",
"}",
"\n\n",
"switch",
"len",
"(",
"unchained",
")",
"{",
"case",
"0",
":",
"return",
"middleware",
".",
"NopUnaryInbound",
"\n",
"case",
"1",
":",
"return",
"unchained",
"[",
"0",
"]",
"\n",
"default",
":",
"return",
"unaryChain",
"(",
"unchained",
")",
"\n",
"}",
"\n",
"}"
]
| // UnaryChain combines a series of `UnaryInbound`s into a single `InboundMiddleware`. | [
"UnaryChain",
"combines",
"a",
"series",
"of",
"UnaryInbound",
"s",
"into",
"a",
"single",
"InboundMiddleware",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/inboundmiddleware/chain.go#L31-L52 |
11,032 | yarpc/yarpc-go | internal/inboundmiddleware/chain.go | OnewayChain | func OnewayChain(mw ...middleware.OnewayInbound) middleware.OnewayInbound {
unchained := make([]middleware.OnewayInbound, 0, len(mw))
for _, m := range mw {
if m == nil {
continue
}
if c, ok := m.(onewayChain); ok {
unchained = append(unchained, c...)
continue
}
unchained = append(unchained, m)
}
switch len(unchained) {
case 0:
return middleware.NopOnewayInbound
case 1:
return unchained[0]
default:
return onewayChain(unchained)
}
} | go | func OnewayChain(mw ...middleware.OnewayInbound) middleware.OnewayInbound {
unchained := make([]middleware.OnewayInbound, 0, len(mw))
for _, m := range mw {
if m == nil {
continue
}
if c, ok := m.(onewayChain); ok {
unchained = append(unchained, c...)
continue
}
unchained = append(unchained, m)
}
switch len(unchained) {
case 0:
return middleware.NopOnewayInbound
case 1:
return unchained[0]
default:
return onewayChain(unchained)
}
} | [
"func",
"OnewayChain",
"(",
"mw",
"...",
"middleware",
".",
"OnewayInbound",
")",
"middleware",
".",
"OnewayInbound",
"{",
"unchained",
":=",
"make",
"(",
"[",
"]",
"middleware",
".",
"OnewayInbound",
",",
"0",
",",
"len",
"(",
"mw",
")",
")",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"mw",
"{",
"if",
"m",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"c",
",",
"ok",
":=",
"m",
".",
"(",
"onewayChain",
")",
";",
"ok",
"{",
"unchained",
"=",
"append",
"(",
"unchained",
",",
"c",
"...",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"unchained",
"=",
"append",
"(",
"unchained",
",",
"m",
")",
"\n",
"}",
"\n\n",
"switch",
"len",
"(",
"unchained",
")",
"{",
"case",
"0",
":",
"return",
"middleware",
".",
"NopOnewayInbound",
"\n",
"case",
"1",
":",
"return",
"unchained",
"[",
"0",
"]",
"\n",
"default",
":",
"return",
"onewayChain",
"(",
"unchained",
")",
"\n",
"}",
"\n",
"}"
]
| // OnewayChain combines a series of `OnewayInbound`s into a single `InboundMiddleware`. | [
"OnewayChain",
"combines",
"a",
"series",
"of",
"OnewayInbound",
"s",
"into",
"a",
"single",
"InboundMiddleware",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/inboundmiddleware/chain.go#L80-L101 |
11,033 | yarpc/yarpc-go | internal/inboundmiddleware/chain.go | StreamChain | func StreamChain(mw ...middleware.StreamInbound) middleware.StreamInbound {
unchained := make([]middleware.StreamInbound, 0, len(mw))
for _, m := range mw {
if m == nil {
continue
}
if c, ok := m.(streamChain); ok {
unchained = append(unchained, c...)
continue
}
unchained = append(unchained, m)
}
switch len(unchained) {
case 0:
return middleware.NopStreamInbound
case 1:
return unchained[0]
default:
return streamChain(unchained)
}
} | go | func StreamChain(mw ...middleware.StreamInbound) middleware.StreamInbound {
unchained := make([]middleware.StreamInbound, 0, len(mw))
for _, m := range mw {
if m == nil {
continue
}
if c, ok := m.(streamChain); ok {
unchained = append(unchained, c...)
continue
}
unchained = append(unchained, m)
}
switch len(unchained) {
case 0:
return middleware.NopStreamInbound
case 1:
return unchained[0]
default:
return streamChain(unchained)
}
} | [
"func",
"StreamChain",
"(",
"mw",
"...",
"middleware",
".",
"StreamInbound",
")",
"middleware",
".",
"StreamInbound",
"{",
"unchained",
":=",
"make",
"(",
"[",
"]",
"middleware",
".",
"StreamInbound",
",",
"0",
",",
"len",
"(",
"mw",
")",
")",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"mw",
"{",
"if",
"m",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"c",
",",
"ok",
":=",
"m",
".",
"(",
"streamChain",
")",
";",
"ok",
"{",
"unchained",
"=",
"append",
"(",
"unchained",
",",
"c",
"...",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"unchained",
"=",
"append",
"(",
"unchained",
",",
"m",
")",
"\n",
"}",
"\n\n",
"switch",
"len",
"(",
"unchained",
")",
"{",
"case",
"0",
":",
"return",
"middleware",
".",
"NopStreamInbound",
"\n",
"case",
"1",
":",
"return",
"unchained",
"[",
"0",
"]",
"\n",
"default",
":",
"return",
"streamChain",
"(",
"unchained",
")",
"\n",
"}",
"\n",
"}"
]
| // StreamChain combines a series of `StreamInbound`s into a single `InboundMiddleware`. | [
"StreamChain",
"combines",
"a",
"series",
"of",
"StreamInbound",
"s",
"into",
"a",
"single",
"InboundMiddleware",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/inboundmiddleware/chain.go#L129-L150 |
11,034 | yarpc/yarpc-go | internal/crossdock/server/apachethrift/server.go | Start | func Start() {
// We expose the following endpoints:
// /thrift/ThriftTest:
// Thrift service using TBinaryProtocol
// /thrift/SecondService
// Thrift service using TBinaryProtocol
// /thrift/mutliplexed
// Thrift service using TBinaryProtocol with TMultiplexedProtocol,
// serving both, ThriftTest and SecondService
pfactory := thrift.NewTBinaryProtocolFactoryDefault()
thriftTest := gauntlet_apache.NewThriftTestProcessor(thriftTestHandler{})
secondService := gauntlet_apache.NewSecondServiceProcessor(secondServiceHandler{})
multiplexed := thrift.NewTMultiplexedProcessor()
multiplexed.RegisterProcessor("ThriftTest", thriftTest)
multiplexed.RegisterProcessor("SecondService", secondService)
mux := http.NewServeMux()
mux.HandleFunc("/thrift/ThriftTest", newThriftHandlerFunc(thriftTest, pfactory, pfactory))
mux.HandleFunc("/thrift/SecondService", newThriftHandlerFunc(secondService, pfactory, pfactory))
mux.HandleFunc("/thrift/multiplexed", newThriftHandlerFunc(multiplexed, pfactory, pfactory))
server = net.NewHTTPServer(&http.Server{
Addr: addr,
Handler: mux,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
})
if err := server.ListenAndServe(); err != nil {
log.Fatalf("failed to start Apache Thrift server: %v", err)
}
} | go | func Start() {
// We expose the following endpoints:
// /thrift/ThriftTest:
// Thrift service using TBinaryProtocol
// /thrift/SecondService
// Thrift service using TBinaryProtocol
// /thrift/mutliplexed
// Thrift service using TBinaryProtocol with TMultiplexedProtocol,
// serving both, ThriftTest and SecondService
pfactory := thrift.NewTBinaryProtocolFactoryDefault()
thriftTest := gauntlet_apache.NewThriftTestProcessor(thriftTestHandler{})
secondService := gauntlet_apache.NewSecondServiceProcessor(secondServiceHandler{})
multiplexed := thrift.NewTMultiplexedProcessor()
multiplexed.RegisterProcessor("ThriftTest", thriftTest)
multiplexed.RegisterProcessor("SecondService", secondService)
mux := http.NewServeMux()
mux.HandleFunc("/thrift/ThriftTest", newThriftHandlerFunc(thriftTest, pfactory, pfactory))
mux.HandleFunc("/thrift/SecondService", newThriftHandlerFunc(secondService, pfactory, pfactory))
mux.HandleFunc("/thrift/multiplexed", newThriftHandlerFunc(multiplexed, pfactory, pfactory))
server = net.NewHTTPServer(&http.Server{
Addr: addr,
Handler: mux,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
})
if err := server.ListenAndServe(); err != nil {
log.Fatalf("failed to start Apache Thrift server: %v", err)
}
} | [
"func",
"Start",
"(",
")",
"{",
"// We expose the following endpoints:",
"// /thrift/ThriftTest:",
"// Thrift service using TBinaryProtocol",
"// /thrift/SecondService",
"// Thrift service using TBinaryProtocol",
"// /thrift/mutliplexed",
"// Thrift service using TBinaryProtocol with TMultiplexedProtocol,",
"// serving both, ThriftTest and SecondService",
"pfactory",
":=",
"thrift",
".",
"NewTBinaryProtocolFactoryDefault",
"(",
")",
"\n\n",
"thriftTest",
":=",
"gauntlet_apache",
".",
"NewThriftTestProcessor",
"(",
"thriftTestHandler",
"{",
"}",
")",
"\n",
"secondService",
":=",
"gauntlet_apache",
".",
"NewSecondServiceProcessor",
"(",
"secondServiceHandler",
"{",
"}",
")",
"\n\n",
"multiplexed",
":=",
"thrift",
".",
"NewTMultiplexedProcessor",
"(",
")",
"\n",
"multiplexed",
".",
"RegisterProcessor",
"(",
"\"",
"\"",
",",
"thriftTest",
")",
"\n",
"multiplexed",
".",
"RegisterProcessor",
"(",
"\"",
"\"",
",",
"secondService",
")",
"\n\n",
"mux",
":=",
"http",
".",
"NewServeMux",
"(",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"newThriftHandlerFunc",
"(",
"thriftTest",
",",
"pfactory",
",",
"pfactory",
")",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"newThriftHandlerFunc",
"(",
"secondService",
",",
"pfactory",
",",
"pfactory",
")",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"newThriftHandlerFunc",
"(",
"multiplexed",
",",
"pfactory",
",",
"pfactory",
")",
")",
"\n\n",
"server",
"=",
"net",
".",
"NewHTTPServer",
"(",
"&",
"http",
".",
"Server",
"{",
"Addr",
":",
"addr",
",",
"Handler",
":",
"mux",
",",
"ReadTimeout",
":",
"5",
"*",
"time",
".",
"Second",
",",
"WriteTimeout",
":",
"5",
"*",
"time",
".",
"Second",
",",
"}",
")",
"\n\n",
"if",
"err",
":=",
"server",
".",
"ListenAndServe",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
]
| // Start starts an Apache Thrift server on port 8088 | [
"Start",
"starts",
"an",
"Apache",
"Thrift",
"server",
"on",
"port",
"8088"
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/crossdock/server/apachethrift/server.go#L39-L73 |
11,035 | yarpc/yarpc-go | transport/grpc/headers.go | transportRequestToMetadata | func transportRequestToMetadata(request *transport.Request) (metadata.MD, error) {
md := metadata.New(nil)
if err := multierr.Combine(
addToMetadata(md, CallerHeader, request.Caller),
addToMetadata(md, ServiceHeader, request.Service),
addToMetadata(md, ShardKeyHeader, request.ShardKey),
addToMetadata(md, RoutingKeyHeader, request.RoutingKey),
addToMetadata(md, RoutingDelegateHeader, request.RoutingDelegate),
addToMetadata(md, EncodingHeader, string(request.Encoding)),
); err != nil {
return md, err
}
return md, addApplicationHeaders(md, request.Headers)
} | go | func transportRequestToMetadata(request *transport.Request) (metadata.MD, error) {
md := metadata.New(nil)
if err := multierr.Combine(
addToMetadata(md, CallerHeader, request.Caller),
addToMetadata(md, ServiceHeader, request.Service),
addToMetadata(md, ShardKeyHeader, request.ShardKey),
addToMetadata(md, RoutingKeyHeader, request.RoutingKey),
addToMetadata(md, RoutingDelegateHeader, request.RoutingDelegate),
addToMetadata(md, EncodingHeader, string(request.Encoding)),
); err != nil {
return md, err
}
return md, addApplicationHeaders(md, request.Headers)
} | [
"func",
"transportRequestToMetadata",
"(",
"request",
"*",
"transport",
".",
"Request",
")",
"(",
"metadata",
".",
"MD",
",",
"error",
")",
"{",
"md",
":=",
"metadata",
".",
"New",
"(",
"nil",
")",
"\n",
"if",
"err",
":=",
"multierr",
".",
"Combine",
"(",
"addToMetadata",
"(",
"md",
",",
"CallerHeader",
",",
"request",
".",
"Caller",
")",
",",
"addToMetadata",
"(",
"md",
",",
"ServiceHeader",
",",
"request",
".",
"Service",
")",
",",
"addToMetadata",
"(",
"md",
",",
"ShardKeyHeader",
",",
"request",
".",
"ShardKey",
")",
",",
"addToMetadata",
"(",
"md",
",",
"RoutingKeyHeader",
",",
"request",
".",
"RoutingKey",
")",
",",
"addToMetadata",
"(",
"md",
",",
"RoutingDelegateHeader",
",",
"request",
".",
"RoutingDelegate",
")",
",",
"addToMetadata",
"(",
"md",
",",
"EncodingHeader",
",",
"string",
"(",
"request",
".",
"Encoding",
")",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"md",
",",
"err",
"\n",
"}",
"\n",
"return",
"md",
",",
"addApplicationHeaders",
"(",
"md",
",",
"request",
".",
"Headers",
")",
"\n",
"}"
]
| // transportRequestToMetadata will populate all reserved and application headers
// from the Request into a new MD. | [
"transportRequestToMetadata",
"will",
"populate",
"all",
"reserved",
"and",
"application",
"headers",
"from",
"the",
"Request",
"into",
"a",
"new",
"MD",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/headers.go#L90-L103 |
11,036 | yarpc/yarpc-go | transport/grpc/headers.go | metadataToTransportRequest | func metadataToTransportRequest(md metadata.MD) (*transport.Request, error) {
request := &transport.Request{
Headers: transport.NewHeadersWithCapacity(md.Len()),
}
for header, values := range md {
var value string
switch len(values) {
case 0:
continue
case 1:
value = values[0]
default:
return nil, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s", header)
}
header = transport.CanonicalizeHeaderKey(header)
switch header {
case CallerHeader:
request.Caller = value
case ServiceHeader:
request.Service = value
case ShardKeyHeader:
request.ShardKey = value
case RoutingKeyHeader:
request.RoutingKey = value
case RoutingDelegateHeader:
request.RoutingDelegate = value
case EncodingHeader:
request.Encoding = transport.Encoding(value)
case contentTypeHeader:
// if request.Encoding was set, do not parse content-type
// this results in EncodingHeader overriding content-type
if request.Encoding == "" {
request.Encoding = transport.Encoding(getContentSubtype(value))
}
default:
request.Headers = request.Headers.With(header, value)
}
}
return request, nil
} | go | func metadataToTransportRequest(md metadata.MD) (*transport.Request, error) {
request := &transport.Request{
Headers: transport.NewHeadersWithCapacity(md.Len()),
}
for header, values := range md {
var value string
switch len(values) {
case 0:
continue
case 1:
value = values[0]
default:
return nil, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s", header)
}
header = transport.CanonicalizeHeaderKey(header)
switch header {
case CallerHeader:
request.Caller = value
case ServiceHeader:
request.Service = value
case ShardKeyHeader:
request.ShardKey = value
case RoutingKeyHeader:
request.RoutingKey = value
case RoutingDelegateHeader:
request.RoutingDelegate = value
case EncodingHeader:
request.Encoding = transport.Encoding(value)
case contentTypeHeader:
// if request.Encoding was set, do not parse content-type
// this results in EncodingHeader overriding content-type
if request.Encoding == "" {
request.Encoding = transport.Encoding(getContentSubtype(value))
}
default:
request.Headers = request.Headers.With(header, value)
}
}
return request, nil
} | [
"func",
"metadataToTransportRequest",
"(",
"md",
"metadata",
".",
"MD",
")",
"(",
"*",
"transport",
".",
"Request",
",",
"error",
")",
"{",
"request",
":=",
"&",
"transport",
".",
"Request",
"{",
"Headers",
":",
"transport",
".",
"NewHeadersWithCapacity",
"(",
"md",
".",
"Len",
"(",
")",
")",
",",
"}",
"\n",
"for",
"header",
",",
"values",
":=",
"range",
"md",
"{",
"var",
"value",
"string",
"\n",
"switch",
"len",
"(",
"values",
")",
"{",
"case",
"0",
":",
"continue",
"\n",
"case",
"1",
":",
"value",
"=",
"values",
"[",
"0",
"]",
"\n",
"default",
":",
"return",
"nil",
",",
"yarpcerrors",
".",
"InvalidArgumentErrorf",
"(",
"\"",
"\"",
",",
"header",
")",
"\n",
"}",
"\n",
"header",
"=",
"transport",
".",
"CanonicalizeHeaderKey",
"(",
"header",
")",
"\n",
"switch",
"header",
"{",
"case",
"CallerHeader",
":",
"request",
".",
"Caller",
"=",
"value",
"\n",
"case",
"ServiceHeader",
":",
"request",
".",
"Service",
"=",
"value",
"\n",
"case",
"ShardKeyHeader",
":",
"request",
".",
"ShardKey",
"=",
"value",
"\n",
"case",
"RoutingKeyHeader",
":",
"request",
".",
"RoutingKey",
"=",
"value",
"\n",
"case",
"RoutingDelegateHeader",
":",
"request",
".",
"RoutingDelegate",
"=",
"value",
"\n",
"case",
"EncodingHeader",
":",
"request",
".",
"Encoding",
"=",
"transport",
".",
"Encoding",
"(",
"value",
")",
"\n",
"case",
"contentTypeHeader",
":",
"// if request.Encoding was set, do not parse content-type",
"// this results in EncodingHeader overriding content-type",
"if",
"request",
".",
"Encoding",
"==",
"\"",
"\"",
"{",
"request",
".",
"Encoding",
"=",
"transport",
".",
"Encoding",
"(",
"getContentSubtype",
"(",
"value",
")",
")",
"\n",
"}",
"\n",
"default",
":",
"request",
".",
"Headers",
"=",
"request",
".",
"Headers",
".",
"With",
"(",
"header",
",",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"request",
",",
"nil",
"\n",
"}"
]
| // metadataToTransportRequest will populate the Request with all reserved and application
// headers into a new Request, only not setting the Body field. | [
"metadataToTransportRequest",
"will",
"populate",
"the",
"Request",
"with",
"all",
"reserved",
"and",
"application",
"headers",
"into",
"a",
"new",
"Request",
"only",
"not",
"setting",
"the",
"Body",
"field",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/headers.go#L107-L146 |
11,037 | yarpc/yarpc-go | transport/grpc/headers.go | addApplicationHeaders | func addApplicationHeaders(md metadata.MD, headers transport.Headers) error {
for header, value := range headers.Items() {
header = transport.CanonicalizeHeaderKey(header)
if isReserved(header) {
return yarpcerrors.InvalidArgumentErrorf("cannot use reserved header in application headers: %s", header)
}
if err := addToMetadata(md, header, value); err != nil {
return err
}
}
return nil
} | go | func addApplicationHeaders(md metadata.MD, headers transport.Headers) error {
for header, value := range headers.Items() {
header = transport.CanonicalizeHeaderKey(header)
if isReserved(header) {
return yarpcerrors.InvalidArgumentErrorf("cannot use reserved header in application headers: %s", header)
}
if err := addToMetadata(md, header, value); err != nil {
return err
}
}
return nil
} | [
"func",
"addApplicationHeaders",
"(",
"md",
"metadata",
".",
"MD",
",",
"headers",
"transport",
".",
"Headers",
")",
"error",
"{",
"for",
"header",
",",
"value",
":=",
"range",
"headers",
".",
"Items",
"(",
")",
"{",
"header",
"=",
"transport",
".",
"CanonicalizeHeaderKey",
"(",
"header",
")",
"\n",
"if",
"isReserved",
"(",
"header",
")",
"{",
"return",
"yarpcerrors",
".",
"InvalidArgumentErrorf",
"(",
"\"",
"\"",
",",
"header",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"addToMetadata",
"(",
"md",
",",
"header",
",",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // addApplicationHeaders adds the headers to md. | [
"addApplicationHeaders",
"adds",
"the",
"headers",
"to",
"md",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/headers.go#L149-L160 |
11,038 | yarpc/yarpc-go | transport/grpc/headers.go | getApplicationHeaders | func getApplicationHeaders(md metadata.MD) (transport.Headers, error) {
if len(md) == 0 {
return transport.Headers{}, nil
}
headers := transport.NewHeadersWithCapacity(md.Len())
for header, values := range md {
header = transport.CanonicalizeHeaderKey(header)
if isReserved(header) {
continue
}
var value string
switch len(values) {
case 0:
continue
case 1:
value = values[0]
default:
return headers, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s", header)
}
headers = headers.With(header, value)
}
return headers, nil
} | go | func getApplicationHeaders(md metadata.MD) (transport.Headers, error) {
if len(md) == 0 {
return transport.Headers{}, nil
}
headers := transport.NewHeadersWithCapacity(md.Len())
for header, values := range md {
header = transport.CanonicalizeHeaderKey(header)
if isReserved(header) {
continue
}
var value string
switch len(values) {
case 0:
continue
case 1:
value = values[0]
default:
return headers, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s", header)
}
headers = headers.With(header, value)
}
return headers, nil
} | [
"func",
"getApplicationHeaders",
"(",
"md",
"metadata",
".",
"MD",
")",
"(",
"transport",
".",
"Headers",
",",
"error",
")",
"{",
"if",
"len",
"(",
"md",
")",
"==",
"0",
"{",
"return",
"transport",
".",
"Headers",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"headers",
":=",
"transport",
".",
"NewHeadersWithCapacity",
"(",
"md",
".",
"Len",
"(",
")",
")",
"\n",
"for",
"header",
",",
"values",
":=",
"range",
"md",
"{",
"header",
"=",
"transport",
".",
"CanonicalizeHeaderKey",
"(",
"header",
")",
"\n",
"if",
"isReserved",
"(",
"header",
")",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"value",
"string",
"\n",
"switch",
"len",
"(",
"values",
")",
"{",
"case",
"0",
":",
"continue",
"\n",
"case",
"1",
":",
"value",
"=",
"values",
"[",
"0",
"]",
"\n",
"default",
":",
"return",
"headers",
",",
"yarpcerrors",
".",
"InvalidArgumentErrorf",
"(",
"\"",
"\"",
",",
"header",
")",
"\n",
"}",
"\n",
"headers",
"=",
"headers",
".",
"With",
"(",
"header",
",",
"value",
")",
"\n",
"}",
"\n",
"return",
"headers",
",",
"nil",
"\n",
"}"
]
| // getApplicationHeaders returns the headers from md without any reserved headers. | [
"getApplicationHeaders",
"returns",
"the",
"headers",
"from",
"md",
"without",
"any",
"reserved",
"headers",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/headers.go#L163-L185 |
11,039 | yarpc/yarpc-go | transport/grpc/headers.go | addToMetadata | func addToMetadata(md metadata.MD, key string, value string) error {
if value == "" {
return nil
}
if _, ok := md[key]; ok {
return yarpcerrors.InvalidArgumentErrorf("duplicate key: %s", key)
}
md[key] = []string{value}
return nil
} | go | func addToMetadata(md metadata.MD, key string, value string) error {
if value == "" {
return nil
}
if _, ok := md[key]; ok {
return yarpcerrors.InvalidArgumentErrorf("duplicate key: %s", key)
}
md[key] = []string{value}
return nil
} | [
"func",
"addToMetadata",
"(",
"md",
"metadata",
".",
"MD",
",",
"key",
"string",
",",
"value",
"string",
")",
"error",
"{",
"if",
"value",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"md",
"[",
"key",
"]",
";",
"ok",
"{",
"return",
"yarpcerrors",
".",
"InvalidArgumentErrorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"}",
"\n",
"md",
"[",
"key",
"]",
"=",
"[",
"]",
"string",
"{",
"value",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // add to md
// return error if key already in md | [
"add",
"to",
"md",
"return",
"error",
"if",
"key",
"already",
"in",
"md"
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/headers.go#L189-L198 |
11,040 | yarpc/yarpc-go | transport/grpc/headers.go | getContentSubtype | func getContentSubtype(contentType string) string {
if !strings.HasPrefix(contentType, baseContentType) || len(contentType) == len(baseContentType) {
return ""
}
switch contentType[len(baseContentType)] {
case '+', ';':
return contentType[len(baseContentType)+1:]
default:
return ""
}
} | go | func getContentSubtype(contentType string) string {
if !strings.HasPrefix(contentType, baseContentType) || len(contentType) == len(baseContentType) {
return ""
}
switch contentType[len(baseContentType)] {
case '+', ';':
return contentType[len(baseContentType)+1:]
default:
return ""
}
} | [
"func",
"getContentSubtype",
"(",
"contentType",
"string",
")",
"string",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"contentType",
",",
"baseContentType",
")",
"||",
"len",
"(",
"contentType",
")",
"==",
"len",
"(",
"baseContentType",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"switch",
"contentType",
"[",
"len",
"(",
"baseContentType",
")",
"]",
"{",
"case",
"'+'",
",",
"';'",
":",
"return",
"contentType",
"[",
"len",
"(",
"baseContentType",
")",
"+",
"1",
":",
"]",
"\n",
"default",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}"
]
| // getContentSubtype attempts to get the content subtype.
// returns "" if no content subtype can be parsed. | [
"getContentSubtype",
"attempts",
"to",
"get",
"the",
"content",
"subtype",
".",
"returns",
"if",
"no",
"content",
"subtype",
"can",
"be",
"parsed",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/headers.go#L202-L212 |
11,041 | yarpc/yarpc-go | transport/grpc/headers.go | ForeachKey | func (md mdReadWriter) ForeachKey(handler func(string, string) error) error {
for key, values := range md {
for _, value := range values {
if err := handler(key, value); err != nil {
return err
}
}
}
return nil
} | go | func (md mdReadWriter) ForeachKey(handler func(string, string) error) error {
for key, values := range md {
for _, value := range values {
if err := handler(key, value); err != nil {
return err
}
}
}
return nil
} | [
"func",
"(",
"md",
"mdReadWriter",
")",
"ForeachKey",
"(",
"handler",
"func",
"(",
"string",
",",
"string",
")",
"error",
")",
"error",
"{",
"for",
"key",
",",
"values",
":=",
"range",
"md",
"{",
"for",
"_",
",",
"value",
":=",
"range",
"values",
"{",
"if",
"err",
":=",
"handler",
"(",
"key",
",",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // ForeachKey implements opentracing.TextMapReader. | [
"ForeachKey",
"implements",
"opentracing",
".",
"TextMapReader",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/headers.go#L217-L226 |
11,042 | yarpc/yarpc-go | transport/grpc/headers.go | Set | func (md mdReadWriter) Set(key string, value string) {
key = strings.ToLower(key)
md[key] = []string{value}
} | go | func (md mdReadWriter) Set(key string, value string) {
key = strings.ToLower(key)
md[key] = []string{value}
} | [
"func",
"(",
"md",
"mdReadWriter",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"string",
")",
"{",
"key",
"=",
"strings",
".",
"ToLower",
"(",
"key",
")",
"\n",
"md",
"[",
"key",
"]",
"=",
"[",
"]",
"string",
"{",
"value",
"}",
"\n",
"}"
]
| // Set implements opentracing.TextMapWriter. | [
"Set",
"implements",
"opentracing",
".",
"TextMapWriter",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/transport/grpc/headers.go#L229-L232 |
11,043 | yarpc/yarpc-go | internal/config/mapdecode.go | DecodeInto | func DecodeInto(dst interface{}, src interface{}, opts ...mapdecode.Option) error {
opts = append(opts, mapdecode.TagName(_tagName))
return mapdecode.Decode(dst, src, opts...)
} | go | func DecodeInto(dst interface{}, src interface{}, opts ...mapdecode.Option) error {
opts = append(opts, mapdecode.TagName(_tagName))
return mapdecode.Decode(dst, src, opts...)
} | [
"func",
"DecodeInto",
"(",
"dst",
"interface",
"{",
"}",
",",
"src",
"interface",
"{",
"}",
",",
"opts",
"...",
"mapdecode",
".",
"Option",
")",
"error",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"mapdecode",
".",
"TagName",
"(",
"_tagName",
")",
")",
"\n",
"return",
"mapdecode",
".",
"Decode",
"(",
"dst",
",",
"src",
",",
"opts",
"...",
")",
"\n",
"}"
]
| // DecodeInto will decode the src's data into the dst interface. | [
"DecodeInto",
"will",
"decode",
"the",
"src",
"s",
"data",
"into",
"the",
"dst",
"interface",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/config/mapdecode.go#L38-L41 |
11,044 | yarpc/yarpc-go | internal/config/mapdecode.go | InterpolateWith | func InterpolateWith(resolver interpolate.VariableResolver) mapdecode.Option {
return mapdecode.FieldHook(func(dest reflect.StructField, srcData reflect.Value) (reflect.Value, error) {
shouldInterpolate := false
options := strings.Split(dest.Tag.Get(_tagName), ",")[1:]
for _, option := range options {
if option == _interpolateOption {
shouldInterpolate = true
break
}
}
if !shouldInterpolate {
return srcData, nil
}
// Use Interface().(string) so that we handle the case where data is an
// interface{} holding a string.
v, ok := srcData.Interface().(string)
if !ok {
// Cannot interpolate non-string type. This shouldn't be an error
// because an integer field may be marked as interpolatable and may
// have received an integer as expected.
return srcData, nil
}
s, err := interpolate.Parse(v)
if err != nil {
return srcData, fmt.Errorf("failed to parse %q for interpolation: %v", v, err)
}
newV, err := s.Render(resolver)
if err != nil {
return srcData, fmt.Errorf("failed to render %q with environment variables: %v", v, err)
}
return reflect.ValueOf(newV), nil
})
} | go | func InterpolateWith(resolver interpolate.VariableResolver) mapdecode.Option {
return mapdecode.FieldHook(func(dest reflect.StructField, srcData reflect.Value) (reflect.Value, error) {
shouldInterpolate := false
options := strings.Split(dest.Tag.Get(_tagName), ",")[1:]
for _, option := range options {
if option == _interpolateOption {
shouldInterpolate = true
break
}
}
if !shouldInterpolate {
return srcData, nil
}
// Use Interface().(string) so that we handle the case where data is an
// interface{} holding a string.
v, ok := srcData.Interface().(string)
if !ok {
// Cannot interpolate non-string type. This shouldn't be an error
// because an integer field may be marked as interpolatable and may
// have received an integer as expected.
return srcData, nil
}
s, err := interpolate.Parse(v)
if err != nil {
return srcData, fmt.Errorf("failed to parse %q for interpolation: %v", v, err)
}
newV, err := s.Render(resolver)
if err != nil {
return srcData, fmt.Errorf("failed to render %q with environment variables: %v", v, err)
}
return reflect.ValueOf(newV), nil
})
} | [
"func",
"InterpolateWith",
"(",
"resolver",
"interpolate",
".",
"VariableResolver",
")",
"mapdecode",
".",
"Option",
"{",
"return",
"mapdecode",
".",
"FieldHook",
"(",
"func",
"(",
"dest",
"reflect",
".",
"StructField",
",",
"srcData",
"reflect",
".",
"Value",
")",
"(",
"reflect",
".",
"Value",
",",
"error",
")",
"{",
"shouldInterpolate",
":=",
"false",
"\n\n",
"options",
":=",
"strings",
".",
"Split",
"(",
"dest",
".",
"Tag",
".",
"Get",
"(",
"_tagName",
")",
",",
"\"",
"\"",
")",
"[",
"1",
":",
"]",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"if",
"option",
"==",
"_interpolateOption",
"{",
"shouldInterpolate",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"shouldInterpolate",
"{",
"return",
"srcData",
",",
"nil",
"\n",
"}",
"\n\n",
"// Use Interface().(string) so that we handle the case where data is an",
"// interface{} holding a string.",
"v",
",",
"ok",
":=",
"srcData",
".",
"Interface",
"(",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"// Cannot interpolate non-string type. This shouldn't be an error",
"// because an integer field may be marked as interpolatable and may",
"// have received an integer as expected.",
"return",
"srcData",
",",
"nil",
"\n",
"}",
"\n\n",
"s",
",",
"err",
":=",
"interpolate",
".",
"Parse",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"srcData",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
",",
"err",
")",
"\n",
"}",
"\n\n",
"newV",
",",
"err",
":=",
"s",
".",
"Render",
"(",
"resolver",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"srcData",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"reflect",
".",
"ValueOf",
"(",
"newV",
")",
",",
"nil",
"\n",
"}",
")",
"\n",
"}"
]
| // InterpolateWith is a MapDecode option that will read a structField's tag
// information, and if the `interpolate` option is set, it will use the
// interpolate resolver to alter data as it's being decoded into the struct. | [
"InterpolateWith",
"is",
"a",
"MapDecode",
"option",
"that",
"will",
"read",
"a",
"structField",
"s",
"tag",
"information",
"and",
"if",
"the",
"interpolate",
"option",
"is",
"set",
"it",
"will",
"use",
"the",
"interpolate",
"resolver",
"to",
"alter",
"data",
"as",
"it",
"s",
"being",
"decoded",
"into",
"the",
"struct",
"."
]
| bd70ffbd17e635243988ba62be97eebff738204d | https://github.com/yarpc/yarpc-go/blob/bd70ffbd17e635243988ba62be97eebff738204d/internal/config/mapdecode.go#L46-L84 |
11,045 | square/certigo | starttls/mysql/utils.go | readLengthEncodedString | func readLengthEncodedString(b []byte) ([]byte, bool, int, error) {
// Get length
num, isNull, n := readLengthEncodedInteger(b)
if num < 1 {
return b[n:n], isNull, n, nil
}
n += int(num)
// Check data length
if len(b) >= n {
return b[n-int(num) : n], false, n, nil
}
return nil, false, n, io.EOF
} | go | func readLengthEncodedString(b []byte) ([]byte, bool, int, error) {
// Get length
num, isNull, n := readLengthEncodedInteger(b)
if num < 1 {
return b[n:n], isNull, n, nil
}
n += int(num)
// Check data length
if len(b) >= n {
return b[n-int(num) : n], false, n, nil
}
return nil, false, n, io.EOF
} | [
"func",
"readLengthEncodedString",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"bool",
",",
"int",
",",
"error",
")",
"{",
"// Get length",
"num",
",",
"isNull",
",",
"n",
":=",
"readLengthEncodedInteger",
"(",
"b",
")",
"\n",
"if",
"num",
"<",
"1",
"{",
"return",
"b",
"[",
"n",
":",
"n",
"]",
",",
"isNull",
",",
"n",
",",
"nil",
"\n",
"}",
"\n\n",
"n",
"+=",
"int",
"(",
"num",
")",
"\n\n",
"// Check data length",
"if",
"len",
"(",
"b",
")",
">=",
"n",
"{",
"return",
"b",
"[",
"n",
"-",
"int",
"(",
"num",
")",
":",
"n",
"]",
",",
"false",
",",
"n",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"false",
",",
"n",
",",
"io",
".",
"EOF",
"\n",
"}"
]
| // returns the string read as a bytes slice, wheter the value is NULL,
// the number of bytes read and an error, in case the string is longer than
// the input slice | [
"returns",
"the",
"string",
"read",
"as",
"a",
"bytes",
"slice",
"wheter",
"the",
"value",
"is",
"NULL",
"the",
"number",
"of",
"bytes",
"read",
"and",
"an",
"error",
"in",
"case",
"the",
"string",
"is",
"longer",
"than",
"the",
"input",
"slice"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/mysql/utils.go#L511-L525 |
11,046 | square/certigo | starttls/mysql/utils.go | readLengthEncodedInteger | func readLengthEncodedInteger(b []byte) (uint64, bool, int) {
// See issue #349
if len(b) == 0 {
return 0, true, 1
}
switch b[0] {
// 251: NULL
case 0xfb:
return 0, true, 1
// 252: value of following 2
case 0xfc:
return uint64(b[1]) | uint64(b[2])<<8, false, 3
// 253: value of following 3
case 0xfd:
return uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16, false, 4
// 254: value of following 8
case 0xfe:
return uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16 |
uint64(b[4])<<24 | uint64(b[5])<<32 | uint64(b[6])<<40 |
uint64(b[7])<<48 | uint64(b[8])<<56,
false, 9
}
// 0-250: value of first byte
return uint64(b[0]), false, 1
} | go | func readLengthEncodedInteger(b []byte) (uint64, bool, int) {
// See issue #349
if len(b) == 0 {
return 0, true, 1
}
switch b[0] {
// 251: NULL
case 0xfb:
return 0, true, 1
// 252: value of following 2
case 0xfc:
return uint64(b[1]) | uint64(b[2])<<8, false, 3
// 253: value of following 3
case 0xfd:
return uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16, false, 4
// 254: value of following 8
case 0xfe:
return uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16 |
uint64(b[4])<<24 | uint64(b[5])<<32 | uint64(b[6])<<40 |
uint64(b[7])<<48 | uint64(b[8])<<56,
false, 9
}
// 0-250: value of first byte
return uint64(b[0]), false, 1
} | [
"func",
"readLengthEncodedInteger",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"uint64",
",",
"bool",
",",
"int",
")",
"{",
"// See issue #349",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"return",
"0",
",",
"true",
",",
"1",
"\n",
"}",
"\n",
"switch",
"b",
"[",
"0",
"]",
"{",
"// 251: NULL",
"case",
"0xfb",
":",
"return",
"0",
",",
"true",
",",
"1",
"\n\n",
"// 252: value of following 2",
"case",
"0xfc",
":",
"return",
"uint64",
"(",
"b",
"[",
"1",
"]",
")",
"|",
"uint64",
"(",
"b",
"[",
"2",
"]",
")",
"<<",
"8",
",",
"false",
",",
"3",
"\n\n",
"// 253: value of following 3",
"case",
"0xfd",
":",
"return",
"uint64",
"(",
"b",
"[",
"1",
"]",
")",
"|",
"uint64",
"(",
"b",
"[",
"2",
"]",
")",
"<<",
"8",
"|",
"uint64",
"(",
"b",
"[",
"3",
"]",
")",
"<<",
"16",
",",
"false",
",",
"4",
"\n\n",
"// 254: value of following 8",
"case",
"0xfe",
":",
"return",
"uint64",
"(",
"b",
"[",
"1",
"]",
")",
"|",
"uint64",
"(",
"b",
"[",
"2",
"]",
")",
"<<",
"8",
"|",
"uint64",
"(",
"b",
"[",
"3",
"]",
")",
"<<",
"16",
"|",
"uint64",
"(",
"b",
"[",
"4",
"]",
")",
"<<",
"24",
"|",
"uint64",
"(",
"b",
"[",
"5",
"]",
")",
"<<",
"32",
"|",
"uint64",
"(",
"b",
"[",
"6",
"]",
")",
"<<",
"40",
"|",
"uint64",
"(",
"b",
"[",
"7",
"]",
")",
"<<",
"48",
"|",
"uint64",
"(",
"b",
"[",
"8",
"]",
")",
"<<",
"56",
",",
"false",
",",
"9",
"\n",
"}",
"\n\n",
"// 0-250: value of first byte",
"return",
"uint64",
"(",
"b",
"[",
"0",
"]",
")",
",",
"false",
",",
"1",
"\n",
"}"
]
| // returns the number read, whether the value is NULL and the number of bytes read | [
"returns",
"the",
"number",
"read",
"whether",
"the",
"value",
"is",
"NULL",
"and",
"the",
"number",
"of",
"bytes",
"read"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/mysql/utils.go#L546-L575 |
11,047 | square/certigo | starttls/ldap/conn.go | ReadPacket | func (pr *PacketResponse) ReadPacket() (*ber.Packet, error) {
if (pr == nil) || (pr.Packet == nil && pr.Error == nil) {
return nil, NewError(ErrorNetwork, errors.New("ldap: could not retrieve response"))
}
return pr.Packet, pr.Error
} | go | func (pr *PacketResponse) ReadPacket() (*ber.Packet, error) {
if (pr == nil) || (pr.Packet == nil && pr.Error == nil) {
return nil, NewError(ErrorNetwork, errors.New("ldap: could not retrieve response"))
}
return pr.Packet, pr.Error
} | [
"func",
"(",
"pr",
"*",
"PacketResponse",
")",
"ReadPacket",
"(",
")",
"(",
"*",
"ber",
".",
"Packet",
",",
"error",
")",
"{",
"if",
"(",
"pr",
"==",
"nil",
")",
"||",
"(",
"pr",
".",
"Packet",
"==",
"nil",
"&&",
"pr",
".",
"Error",
"==",
"nil",
")",
"{",
"return",
"nil",
",",
"NewError",
"(",
"ErrorNetwork",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"return",
"pr",
".",
"Packet",
",",
"pr",
".",
"Error",
"\n",
"}"
]
| // ReadPacket returns the packet or an error | [
"ReadPacket",
"returns",
"the",
"packet",
"or",
"an",
"error"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/conn.go#L42-L47 |
11,048 | square/certigo | starttls/ldap/conn.go | Dial | func Dial(network, addr string, timeout time.Duration) (*Conn, error) {
c, err := net.DialTimeout(network, addr, timeout)
if err != nil {
return nil, NewError(ErrorNetwork, err)
}
conn := NewConn(c, false)
conn.Start()
return conn, nil
} | go | func Dial(network, addr string, timeout time.Duration) (*Conn, error) {
c, err := net.DialTimeout(network, addr, timeout)
if err != nil {
return nil, NewError(ErrorNetwork, err)
}
conn := NewConn(c, false)
conn.Start()
return conn, nil
} | [
"func",
"Dial",
"(",
"network",
",",
"addr",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"net",
".",
"DialTimeout",
"(",
"network",
",",
"addr",
",",
"timeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"NewError",
"(",
"ErrorNetwork",
",",
"err",
")",
"\n",
"}",
"\n",
"conn",
":=",
"NewConn",
"(",
"c",
",",
"false",
")",
"\n",
"conn",
".",
"Start",
"(",
")",
"\n",
"return",
"conn",
",",
"nil",
"\n",
"}"
]
| // Dial connects to the given address on the given network using net.Dial
// and then returns a new Conn for the connection. | [
"Dial",
"connects",
"to",
"the",
"given",
"address",
"on",
"the",
"given",
"network",
"using",
"net",
".",
"Dial",
"and",
"then",
"returns",
"a",
"new",
"Conn",
"for",
"the",
"connection",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/conn.go#L113-L121 |
11,049 | square/certigo | starttls/ldap/conn.go | DialTLS | func DialTLS(network, addr string, config *tls.Config) (*Conn, error) {
dc, err := net.DialTimeout(network, addr, DefaultTimeout)
if err != nil {
return nil, NewError(ErrorNetwork, err)
}
c := tls.Client(dc, config)
err = c.Handshake()
if err != nil {
// Handshake error, close the established connection before we return an error
dc.Close()
return nil, NewError(ErrorNetwork, err)
}
conn := NewConn(c, true)
conn.Start()
return conn, nil
} | go | func DialTLS(network, addr string, config *tls.Config) (*Conn, error) {
dc, err := net.DialTimeout(network, addr, DefaultTimeout)
if err != nil {
return nil, NewError(ErrorNetwork, err)
}
c := tls.Client(dc, config)
err = c.Handshake()
if err != nil {
// Handshake error, close the established connection before we return an error
dc.Close()
return nil, NewError(ErrorNetwork, err)
}
conn := NewConn(c, true)
conn.Start()
return conn, nil
} | [
"func",
"DialTLS",
"(",
"network",
",",
"addr",
"string",
",",
"config",
"*",
"tls",
".",
"Config",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"dc",
",",
"err",
":=",
"net",
".",
"DialTimeout",
"(",
"network",
",",
"addr",
",",
"DefaultTimeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"NewError",
"(",
"ErrorNetwork",
",",
"err",
")",
"\n",
"}",
"\n",
"c",
":=",
"tls",
".",
"Client",
"(",
"dc",
",",
"config",
")",
"\n",
"err",
"=",
"c",
".",
"Handshake",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Handshake error, close the established connection before we return an error",
"dc",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"NewError",
"(",
"ErrorNetwork",
",",
"err",
")",
"\n",
"}",
"\n",
"conn",
":=",
"NewConn",
"(",
"c",
",",
"true",
")",
"\n",
"conn",
".",
"Start",
"(",
")",
"\n",
"return",
"conn",
",",
"nil",
"\n",
"}"
]
| // DialTLS connects to the given address on the given network using tls.Dial
// and then returns a new Conn for the connection. | [
"DialTLS",
"connects",
"to",
"the",
"given",
"address",
"on",
"the",
"given",
"network",
"using",
"tls",
".",
"Dial",
"and",
"then",
"returns",
"a",
"new",
"Conn",
"for",
"the",
"connection",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/conn.go#L125-L140 |
11,050 | square/certigo | starttls/ldap/conn.go | Start | func (l *Conn) Start() {
go l.reader()
go l.processMessages()
l.wgClose.Add(1)
} | go | func (l *Conn) Start() {
go l.reader()
go l.processMessages()
l.wgClose.Add(1)
} | [
"func",
"(",
"l",
"*",
"Conn",
")",
"Start",
"(",
")",
"{",
"go",
"l",
".",
"reader",
"(",
")",
"\n",
"go",
"l",
".",
"processMessages",
"(",
")",
"\n",
"l",
".",
"wgClose",
".",
"Add",
"(",
"1",
")",
"\n",
"}"
]
| // Start initializes goroutines to read responses and process messages | [
"Start",
"initializes",
"goroutines",
"to",
"read",
"responses",
"and",
"process",
"messages"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/conn.go#L156-L160 |
11,051 | square/certigo | starttls/ldap/conn.go | SetTimeout | func (l *Conn) SetTimeout(timeout time.Duration) {
if timeout > 0 {
l.requestTimeout = timeout
}
} | go | func (l *Conn) SetTimeout(timeout time.Duration) {
if timeout > 0 {
l.requestTimeout = timeout
}
} | [
"func",
"(",
"l",
"*",
"Conn",
")",
"SetTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"{",
"if",
"timeout",
">",
"0",
"{",
"l",
".",
"requestTimeout",
"=",
"timeout",
"\n",
"}",
"\n",
"}"
]
| // SetTimeout sets the time after a request is sent that a MessageTimeout triggers | [
"SetTimeout",
"sets",
"the",
"time",
"after",
"a",
"request",
"is",
"sent",
"that",
"a",
"MessageTimeout",
"triggers"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/conn.go#L194-L198 |
11,052 | square/certigo | starttls/ldap/conn.go | nextMessageID | func (l *Conn) nextMessageID() int64 {
if l.chanMessageID != nil {
if messageID, ok := <-l.chanMessageID; ok {
return messageID
}
}
return 0
} | go | func (l *Conn) nextMessageID() int64 {
if l.chanMessageID != nil {
if messageID, ok := <-l.chanMessageID; ok {
return messageID
}
}
return 0
} | [
"func",
"(",
"l",
"*",
"Conn",
")",
"nextMessageID",
"(",
")",
"int64",
"{",
"if",
"l",
".",
"chanMessageID",
"!=",
"nil",
"{",
"if",
"messageID",
",",
"ok",
":=",
"<-",
"l",
".",
"chanMessageID",
";",
"ok",
"{",
"return",
"messageID",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
]
| // Returns the next available messageID | [
"Returns",
"the",
"next",
"available",
"messageID"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/conn.go#L201-L208 |
11,053 | square/certigo | starttls/ldap/conn.go | StartTLS | func (l *Conn) StartTLS(config *tls.Config) error {
if l.isTLS {
return NewError(ErrorNetwork, errors.New("ldap: already encrypted"))
}
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationExtendedRequest, nil, "Start TLS")
request.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, "1.3.6.1.4.1.1466.20037", "TLS Extended Command"))
packet.AppendChild(request)
l.Debug.PrintPacket(packet)
msgCtx, err := l.sendMessageWithFlags(packet, startTLS)
if err != nil {
return err
}
defer l.finishMessage(msgCtx)
l.Debug.Printf("%d: waiting for response", msgCtx.id)
packetResponse, ok := <-msgCtx.responses
if !ok {
return NewError(ErrorNetwork, errors.New("ldap: response channel closed"))
}
packet, err = packetResponse.ReadPacket()
l.Debug.Printf("%d: got response %p", msgCtx.id, packet)
if err != nil {
return err
}
if l.Debug {
if err := addLDAPDescriptions(packet); err != nil {
l.Close()
return err
}
ber.PrintPacket(packet)
}
if resultCode, message := getLDAPResultCode(packet); resultCode == LDAPResultSuccess {
conn := tls.Client(l.conn, config)
if err := conn.Handshake(); err != nil {
l.Close()
return NewError(ErrorNetwork, fmt.Errorf("TLS handshake failed (%v)", err))
}
l.isTLS = true
l.conn = conn
} else {
return NewError(resultCode, fmt.Errorf("ldap: cannot StartTLS (%s)", message))
}
go l.reader()
return nil
} | go | func (l *Conn) StartTLS(config *tls.Config) error {
if l.isTLS {
return NewError(ErrorNetwork, errors.New("ldap: already encrypted"))
}
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationExtendedRequest, nil, "Start TLS")
request.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, "1.3.6.1.4.1.1466.20037", "TLS Extended Command"))
packet.AppendChild(request)
l.Debug.PrintPacket(packet)
msgCtx, err := l.sendMessageWithFlags(packet, startTLS)
if err != nil {
return err
}
defer l.finishMessage(msgCtx)
l.Debug.Printf("%d: waiting for response", msgCtx.id)
packetResponse, ok := <-msgCtx.responses
if !ok {
return NewError(ErrorNetwork, errors.New("ldap: response channel closed"))
}
packet, err = packetResponse.ReadPacket()
l.Debug.Printf("%d: got response %p", msgCtx.id, packet)
if err != nil {
return err
}
if l.Debug {
if err := addLDAPDescriptions(packet); err != nil {
l.Close()
return err
}
ber.PrintPacket(packet)
}
if resultCode, message := getLDAPResultCode(packet); resultCode == LDAPResultSuccess {
conn := tls.Client(l.conn, config)
if err := conn.Handshake(); err != nil {
l.Close()
return NewError(ErrorNetwork, fmt.Errorf("TLS handshake failed (%v)", err))
}
l.isTLS = true
l.conn = conn
} else {
return NewError(resultCode, fmt.Errorf("ldap: cannot StartTLS (%s)", message))
}
go l.reader()
return nil
} | [
"func",
"(",
"l",
"*",
"Conn",
")",
"StartTLS",
"(",
"config",
"*",
"tls",
".",
"Config",
")",
"error",
"{",
"if",
"l",
".",
"isTLS",
"{",
"return",
"NewError",
"(",
"ErrorNetwork",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"packet",
":=",
"ber",
".",
"Encode",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypeConstructed",
",",
"ber",
".",
"TagSequence",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"packet",
".",
"AppendChild",
"(",
"ber",
".",
"NewInteger",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypePrimitive",
",",
"ber",
".",
"TagInteger",
",",
"l",
".",
"nextMessageID",
"(",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"request",
":=",
"ber",
".",
"Encode",
"(",
"ber",
".",
"ClassApplication",
",",
"ber",
".",
"TypeConstructed",
",",
"ApplicationExtendedRequest",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"request",
".",
"AppendChild",
"(",
"ber",
".",
"NewString",
"(",
"ber",
".",
"ClassContext",
",",
"ber",
".",
"TypePrimitive",
",",
"0",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
"\n",
"packet",
".",
"AppendChild",
"(",
"request",
")",
"\n",
"l",
".",
"Debug",
".",
"PrintPacket",
"(",
"packet",
")",
"\n\n",
"msgCtx",
",",
"err",
":=",
"l",
".",
"sendMessageWithFlags",
"(",
"packet",
",",
"startTLS",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"l",
".",
"finishMessage",
"(",
"msgCtx",
")",
"\n\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
")",
"\n\n",
"packetResponse",
",",
"ok",
":=",
"<-",
"msgCtx",
".",
"responses",
"\n",
"if",
"!",
"ok",
"{",
"return",
"NewError",
"(",
"ErrorNetwork",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"packet",
",",
"err",
"=",
"packetResponse",
".",
"ReadPacket",
"(",
")",
"\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
",",
"packet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"l",
".",
"Debug",
"{",
"if",
"err",
":=",
"addLDAPDescriptions",
"(",
"packet",
")",
";",
"err",
"!=",
"nil",
"{",
"l",
".",
"Close",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"ber",
".",
"PrintPacket",
"(",
"packet",
")",
"\n",
"}",
"\n\n",
"if",
"resultCode",
",",
"message",
":=",
"getLDAPResultCode",
"(",
"packet",
")",
";",
"resultCode",
"==",
"LDAPResultSuccess",
"{",
"conn",
":=",
"tls",
".",
"Client",
"(",
"l",
".",
"conn",
",",
"config",
")",
"\n\n",
"if",
"err",
":=",
"conn",
".",
"Handshake",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"l",
".",
"Close",
"(",
")",
"\n",
"return",
"NewError",
"(",
"ErrorNetwork",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n\n",
"l",
".",
"isTLS",
"=",
"true",
"\n",
"l",
".",
"conn",
"=",
"conn",
"\n",
"}",
"else",
"{",
"return",
"NewError",
"(",
"resultCode",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"message",
")",
")",
"\n",
"}",
"\n",
"go",
"l",
".",
"reader",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // StartTLS sends the command to start a TLS session and then creates a new TLS Client | [
"StartTLS",
"sends",
"the",
"command",
"to",
"start",
"a",
"TLS",
"session",
"and",
"then",
"creates",
"a",
"new",
"TLS",
"Client"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/conn.go#L211-L265 |
11,054 | square/certigo | starttls/ldap/conn.go | TLSConnectionState | func (l *Conn) TLSConnectionState() (*tls.ConnectionState, error) {
if !l.isTLS {
return nil, errors.New("ldap: Cannot get TLS Connection State for non-TLS connection")
}
state := l.conn.(*tls.Conn).ConnectionState()
return &state, nil
} | go | func (l *Conn) TLSConnectionState() (*tls.ConnectionState, error) {
if !l.isTLS {
return nil, errors.New("ldap: Cannot get TLS Connection State for non-TLS connection")
}
state := l.conn.(*tls.Conn).ConnectionState()
return &state, nil
} | [
"func",
"(",
"l",
"*",
"Conn",
")",
"TLSConnectionState",
"(",
")",
"(",
"*",
"tls",
".",
"ConnectionState",
",",
"error",
")",
"{",
"if",
"!",
"l",
".",
"isTLS",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"state",
":=",
"l",
".",
"conn",
".",
"(",
"*",
"tls",
".",
"Conn",
")",
".",
"ConnectionState",
"(",
")",
"\n",
"return",
"&",
"state",
",",
"nil",
"\n",
"}"
]
| // TLSConnectionState returns the current connection's TLS ConnectionState, or an error if not TLS. | [
"TLSConnectionState",
"returns",
"the",
"current",
"connection",
"s",
"TLS",
"ConnectionState",
"or",
"an",
"error",
"if",
"not",
"TLS",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/conn.go#L268-L274 |
11,055 | square/certigo | starttls/psql/array.go | Value | func (a ByteaArray) Value() (driver.Value, error) {
if a == nil {
return nil, nil
}
if n := len(a); n > 0 {
// There will be at least two curly brackets, 2*N bytes of quotes,
// 3*N bytes of hex formatting, and N-1 bytes of delimiters.
size := 1 + 6*n
for _, x := range a {
size += hex.EncodedLen(len(x))
}
b := make([]byte, size)
for i, s := 0, b; i < n; i++ {
o := copy(s, `,"\\x`)
o += hex.Encode(s[o:], a[i])
s[o] = '"'
s = s[o+1:]
}
b[0] = '{'
b[size-1] = '}'
return string(b), nil
}
return "{}", nil
} | go | func (a ByteaArray) Value() (driver.Value, error) {
if a == nil {
return nil, nil
}
if n := len(a); n > 0 {
// There will be at least two curly brackets, 2*N bytes of quotes,
// 3*N bytes of hex formatting, and N-1 bytes of delimiters.
size := 1 + 6*n
for _, x := range a {
size += hex.EncodedLen(len(x))
}
b := make([]byte, size)
for i, s := 0, b; i < n; i++ {
o := copy(s, `,"\\x`)
o += hex.Encode(s[o:], a[i])
s[o] = '"'
s = s[o+1:]
}
b[0] = '{'
b[size-1] = '}'
return string(b), nil
}
return "{}", nil
} | [
"func",
"(",
"a",
"ByteaArray",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"if",
"a",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"n",
":=",
"len",
"(",
"a",
")",
";",
"n",
">",
"0",
"{",
"// There will be at least two curly brackets, 2*N bytes of quotes,",
"// 3*N bytes of hex formatting, and N-1 bytes of delimiters.",
"size",
":=",
"1",
"+",
"6",
"*",
"n",
"\n",
"for",
"_",
",",
"x",
":=",
"range",
"a",
"{",
"size",
"+=",
"hex",
".",
"EncodedLen",
"(",
"len",
"(",
"x",
")",
")",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n\n",
"for",
"i",
",",
"s",
":=",
"0",
",",
"b",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"o",
":=",
"copy",
"(",
"s",
",",
"`,\"\\\\x`",
")",
"\n",
"o",
"+=",
"hex",
".",
"Encode",
"(",
"s",
"[",
"o",
":",
"]",
",",
"a",
"[",
"i",
"]",
")",
"\n",
"s",
"[",
"o",
"]",
"=",
"'\"'",
"\n",
"s",
"=",
"s",
"[",
"o",
"+",
"1",
":",
"]",
"\n",
"}",
"\n\n",
"b",
"[",
"0",
"]",
"=",
"'{'",
"\n",
"b",
"[",
"size",
"-",
"1",
"]",
"=",
"'}'",
"\n\n",
"return",
"string",
"(",
"b",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
]
| // Value implements the driver.Valuer interface. It uses the "hex" format which
// is only supported on PostgreSQL 9.0 or newer. | [
"Value",
"implements",
"the",
"driver",
".",
"Valuer",
"interface",
".",
"It",
"uses",
"the",
"hex",
"format",
"which",
"is",
"only",
"supported",
"on",
"PostgreSQL",
"9",
".",
"0",
"or",
"newer",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/array.go#L177-L206 |
11,056 | square/certigo | starttls/psql/array.go | appendArray | func appendArray(b []byte, rv reflect.Value, n int) ([]byte, string, error) {
var del string
var err error
b = append(b, '{')
if b, del, err = appendArrayElement(b, rv.Index(0)); err != nil {
return b, del, err
}
for i := 1; i < n; i++ {
b = append(b, del...)
if b, del, err = appendArrayElement(b, rv.Index(i)); err != nil {
return b, del, err
}
}
return append(b, '}'), del, nil
} | go | func appendArray(b []byte, rv reflect.Value, n int) ([]byte, string, error) {
var del string
var err error
b = append(b, '{')
if b, del, err = appendArrayElement(b, rv.Index(0)); err != nil {
return b, del, err
}
for i := 1; i < n; i++ {
b = append(b, del...)
if b, del, err = appendArrayElement(b, rv.Index(i)); err != nil {
return b, del, err
}
}
return append(b, '}'), del, nil
} | [
"func",
"appendArray",
"(",
"b",
"[",
"]",
"byte",
",",
"rv",
"reflect",
".",
"Value",
",",
"n",
"int",
")",
"(",
"[",
"]",
"byte",
",",
"string",
",",
"error",
")",
"{",
"var",
"del",
"string",
"\n",
"var",
"err",
"error",
"\n\n",
"b",
"=",
"append",
"(",
"b",
",",
"'{'",
")",
"\n\n",
"if",
"b",
",",
"del",
",",
"err",
"=",
"appendArrayElement",
"(",
"b",
",",
"rv",
".",
"Index",
"(",
"0",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"b",
",",
"del",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"del",
"...",
")",
"\n",
"if",
"b",
",",
"del",
",",
"err",
"=",
"appendArrayElement",
"(",
"b",
",",
"rv",
".",
"Index",
"(",
"i",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"b",
",",
"del",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"append",
"(",
"b",
",",
"'}'",
")",
",",
"del",
",",
"nil",
"\n",
"}"
]
| // appendArray appends rv to the buffer, returning the extended buffer and
// the delimiter used between elements.
//
// It panics when n <= 0 or rv's Kind is not reflect.Array nor reflect.Slice. | [
"appendArray",
"appends",
"rv",
"to",
"the",
"buffer",
"returning",
"the",
"extended",
"buffer",
"and",
"the",
"delimiter",
"used",
"between",
"elements",
".",
"It",
"panics",
"when",
"n",
"<",
"=",
"0",
"or",
"rv",
"s",
"Kind",
"is",
"not",
"reflect",
".",
"Array",
"nor",
"reflect",
".",
"Slice",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/array.go#L551-L569 |
11,057 | square/certigo | starttls/ldap/add.go | Attribute | func (a *AddRequest) Attribute(attrType string, attrVals []string) {
a.Attributes = append(a.Attributes, Attribute{Type: attrType, Vals: attrVals})
} | go | func (a *AddRequest) Attribute(attrType string, attrVals []string) {
a.Attributes = append(a.Attributes, Attribute{Type: attrType, Vals: attrVals})
} | [
"func",
"(",
"a",
"*",
"AddRequest",
")",
"Attribute",
"(",
"attrType",
"string",
",",
"attrVals",
"[",
"]",
"string",
")",
"{",
"a",
".",
"Attributes",
"=",
"append",
"(",
"a",
".",
"Attributes",
",",
"Attribute",
"{",
"Type",
":",
"attrType",
",",
"Vals",
":",
"attrVals",
"}",
")",
"\n",
"}"
]
| // Attribute adds an attribute with the given type and values | [
"Attribute",
"adds",
"an",
"attribute",
"with",
"the",
"given",
"type",
"and",
"values"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/add.go#L58-L60 |
11,058 | square/certigo | starttls/psql/uuid.go | decodeUUIDBinary | func decodeUUIDBinary(src []byte) ([]byte, error) {
if len(src) != 16 {
return nil, fmt.Errorf("pq: unable to decode uuid; bad length: %d", len(src))
}
dst := make([]byte, 36)
dst[8], dst[13], dst[18], dst[23] = '-', '-', '-', '-'
hex.Encode(dst[0:], src[0:4])
hex.Encode(dst[9:], src[4:6])
hex.Encode(dst[14:], src[6:8])
hex.Encode(dst[19:], src[8:10])
hex.Encode(dst[24:], src[10:16])
return dst, nil
} | go | func decodeUUIDBinary(src []byte) ([]byte, error) {
if len(src) != 16 {
return nil, fmt.Errorf("pq: unable to decode uuid; bad length: %d", len(src))
}
dst := make([]byte, 36)
dst[8], dst[13], dst[18], dst[23] = '-', '-', '-', '-'
hex.Encode(dst[0:], src[0:4])
hex.Encode(dst[9:], src[4:6])
hex.Encode(dst[14:], src[6:8])
hex.Encode(dst[19:], src[8:10])
hex.Encode(dst[24:], src[10:16])
return dst, nil
} | [
"func",
"decodeUUIDBinary",
"(",
"src",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"src",
")",
"!=",
"16",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"src",
")",
")",
"\n",
"}",
"\n\n",
"dst",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"36",
")",
"\n",
"dst",
"[",
"8",
"]",
",",
"dst",
"[",
"13",
"]",
",",
"dst",
"[",
"18",
"]",
",",
"dst",
"[",
"23",
"]",
"=",
"'-'",
",",
"'-'",
",",
"'-'",
",",
"'-'",
"\n",
"hex",
".",
"Encode",
"(",
"dst",
"[",
"0",
":",
"]",
",",
"src",
"[",
"0",
":",
"4",
"]",
")",
"\n",
"hex",
".",
"Encode",
"(",
"dst",
"[",
"9",
":",
"]",
",",
"src",
"[",
"4",
":",
"6",
"]",
")",
"\n",
"hex",
".",
"Encode",
"(",
"dst",
"[",
"14",
":",
"]",
",",
"src",
"[",
"6",
":",
"8",
"]",
")",
"\n",
"hex",
".",
"Encode",
"(",
"dst",
"[",
"19",
":",
"]",
",",
"src",
"[",
"8",
":",
"10",
"]",
")",
"\n",
"hex",
".",
"Encode",
"(",
"dst",
"[",
"24",
":",
"]",
",",
"src",
"[",
"10",
":",
"16",
"]",
")",
"\n\n",
"return",
"dst",
",",
"nil",
"\n",
"}"
]
| // decodeUUIDBinary interprets the binary format of a uuid, returning it in text format. | [
"decodeUUIDBinary",
"interprets",
"the",
"binary",
"format",
"of",
"a",
"uuid",
"returning",
"it",
"in",
"text",
"format",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/uuid.go#L9-L23 |
11,059 | square/certigo | starttls/ldap/search.go | NewEntry | func NewEntry(dn string, attributes map[string][]string) *Entry {
var attributeNames []string
for attributeName := range attributes {
attributeNames = append(attributeNames, attributeName)
}
sort.Strings(attributeNames)
var encodedAttributes []*EntryAttribute
for _, attributeName := range attributeNames {
encodedAttributes = append(encodedAttributes, NewEntryAttribute(attributeName, attributes[attributeName]))
}
return &Entry{
DN: dn,
Attributes: encodedAttributes,
}
} | go | func NewEntry(dn string, attributes map[string][]string) *Entry {
var attributeNames []string
for attributeName := range attributes {
attributeNames = append(attributeNames, attributeName)
}
sort.Strings(attributeNames)
var encodedAttributes []*EntryAttribute
for _, attributeName := range attributeNames {
encodedAttributes = append(encodedAttributes, NewEntryAttribute(attributeName, attributes[attributeName]))
}
return &Entry{
DN: dn,
Attributes: encodedAttributes,
}
} | [
"func",
"NewEntry",
"(",
"dn",
"string",
",",
"attributes",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"*",
"Entry",
"{",
"var",
"attributeNames",
"[",
"]",
"string",
"\n",
"for",
"attributeName",
":=",
"range",
"attributes",
"{",
"attributeNames",
"=",
"append",
"(",
"attributeNames",
",",
"attributeName",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"attributeNames",
")",
"\n\n",
"var",
"encodedAttributes",
"[",
"]",
"*",
"EntryAttribute",
"\n",
"for",
"_",
",",
"attributeName",
":=",
"range",
"attributeNames",
"{",
"encodedAttributes",
"=",
"append",
"(",
"encodedAttributes",
",",
"NewEntryAttribute",
"(",
"attributeName",
",",
"attributes",
"[",
"attributeName",
"]",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"Entry",
"{",
"DN",
":",
"dn",
",",
"Attributes",
":",
"encodedAttributes",
",",
"}",
"\n",
"}"
]
| // NewEntry returns an Entry object with the specified distinguished name and attribute key-value pairs.
// The map of attributes is accessed in alphabetical order of the keys in order to ensure that, for the
// same input map of attributes, the output entry will contain the same order of attributes | [
"NewEntry",
"returns",
"an",
"Entry",
"object",
"with",
"the",
"specified",
"distinguished",
"name",
"and",
"attribute",
"key",
"-",
"value",
"pairs",
".",
"The",
"map",
"of",
"attributes",
"is",
"accessed",
"in",
"alphabetical",
"order",
"of",
"the",
"keys",
"in",
"order",
"to",
"ensure",
"that",
"for",
"the",
"same",
"input",
"map",
"of",
"attributes",
"the",
"output",
"entry",
"will",
"contain",
"the",
"same",
"order",
"of",
"attributes"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L104-L119 |
11,060 | square/certigo | starttls/ldap/search.go | GetAttributeValues | func (e *Entry) GetAttributeValues(attribute string) []string {
for _, attr := range e.Attributes {
if attr.Name == attribute {
return attr.Values
}
}
return []string{}
} | go | func (e *Entry) GetAttributeValues(attribute string) []string {
for _, attr := range e.Attributes {
if attr.Name == attribute {
return attr.Values
}
}
return []string{}
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"GetAttributeValues",
"(",
"attribute",
"string",
")",
"[",
"]",
"string",
"{",
"for",
"_",
",",
"attr",
":=",
"range",
"e",
".",
"Attributes",
"{",
"if",
"attr",
".",
"Name",
"==",
"attribute",
"{",
"return",
"attr",
".",
"Values",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}"
]
| // GetAttributeValues returns the values for the named attribute, or an empty list | [
"GetAttributeValues",
"returns",
"the",
"values",
"for",
"the",
"named",
"attribute",
"or",
"an",
"empty",
"list"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L130-L137 |
11,061 | square/certigo | starttls/ldap/search.go | GetRawAttributeValues | func (e *Entry) GetRawAttributeValues(attribute string) [][]byte {
for _, attr := range e.Attributes {
if attr.Name == attribute {
return attr.ByteValues
}
}
return [][]byte{}
} | go | func (e *Entry) GetRawAttributeValues(attribute string) [][]byte {
for _, attr := range e.Attributes {
if attr.Name == attribute {
return attr.ByteValues
}
}
return [][]byte{}
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"GetRawAttributeValues",
"(",
"attribute",
"string",
")",
"[",
"]",
"[",
"]",
"byte",
"{",
"for",
"_",
",",
"attr",
":=",
"range",
"e",
".",
"Attributes",
"{",
"if",
"attr",
".",
"Name",
"==",
"attribute",
"{",
"return",
"attr",
".",
"ByteValues",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"[",
"]",
"[",
"]",
"byte",
"{",
"}",
"\n",
"}"
]
| // GetRawAttributeValues returns the byte values for the named attribute, or an empty list | [
"GetRawAttributeValues",
"returns",
"the",
"byte",
"values",
"for",
"the",
"named",
"attribute",
"or",
"an",
"empty",
"list"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L140-L147 |
11,062 | square/certigo | starttls/ldap/search.go | GetAttributeValue | func (e *Entry) GetAttributeValue(attribute string) string {
values := e.GetAttributeValues(attribute)
if len(values) == 0 {
return ""
}
return values[0]
} | go | func (e *Entry) GetAttributeValue(attribute string) string {
values := e.GetAttributeValues(attribute)
if len(values) == 0 {
return ""
}
return values[0]
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"GetAttributeValue",
"(",
"attribute",
"string",
")",
"string",
"{",
"values",
":=",
"e",
".",
"GetAttributeValues",
"(",
"attribute",
")",
"\n",
"if",
"len",
"(",
"values",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"values",
"[",
"0",
"]",
"\n",
"}"
]
| // GetAttributeValue returns the first value for the named attribute, or "" | [
"GetAttributeValue",
"returns",
"the",
"first",
"value",
"for",
"the",
"named",
"attribute",
"or"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L150-L156 |
11,063 | square/certigo | starttls/ldap/search.go | GetRawAttributeValue | func (e *Entry) GetRawAttributeValue(attribute string) []byte {
values := e.GetRawAttributeValues(attribute)
if len(values) == 0 {
return []byte{}
}
return values[0]
} | go | func (e *Entry) GetRawAttributeValue(attribute string) []byte {
values := e.GetRawAttributeValues(attribute)
if len(values) == 0 {
return []byte{}
}
return values[0]
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"GetRawAttributeValue",
"(",
"attribute",
"string",
")",
"[",
"]",
"byte",
"{",
"values",
":=",
"e",
".",
"GetRawAttributeValues",
"(",
"attribute",
")",
"\n",
"if",
"len",
"(",
"values",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"byte",
"{",
"}",
"\n",
"}",
"\n",
"return",
"values",
"[",
"0",
"]",
"\n",
"}"
]
| // GetRawAttributeValue returns the first value for the named attribute, or an empty slice | [
"GetRawAttributeValue",
"returns",
"the",
"first",
"value",
"for",
"the",
"named",
"attribute",
"or",
"an",
"empty",
"slice"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L159-L165 |
11,064 | square/certigo | starttls/ldap/search.go | Print | func (e *Entry) Print() {
fmt.Printf("DN: %s\n", e.DN)
for _, attr := range e.Attributes {
attr.Print()
}
} | go | func (e *Entry) Print() {
fmt.Printf("DN: %s\n", e.DN)
for _, attr := range e.Attributes {
attr.Print()
}
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"Print",
"(",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"e",
".",
"DN",
")",
"\n",
"for",
"_",
",",
"attr",
":=",
"range",
"e",
".",
"Attributes",
"{",
"attr",
".",
"Print",
"(",
")",
"\n",
"}",
"\n",
"}"
]
| // Print outputs a human-readable description | [
"Print",
"outputs",
"a",
"human",
"-",
"readable",
"description"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L168-L173 |
11,065 | square/certigo | starttls/ldap/search.go | PrettyPrint | func (e *Entry) PrettyPrint(indent int) {
fmt.Printf("%sDN: %s\n", strings.Repeat(" ", indent), e.DN)
for _, attr := range e.Attributes {
attr.PrettyPrint(indent + 2)
}
} | go | func (e *Entry) PrettyPrint(indent int) {
fmt.Printf("%sDN: %s\n", strings.Repeat(" ", indent), e.DN)
for _, attr := range e.Attributes {
attr.PrettyPrint(indent + 2)
}
} | [
"func",
"(",
"e",
"*",
"Entry",
")",
"PrettyPrint",
"(",
"indent",
"int",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"indent",
")",
",",
"e",
".",
"DN",
")",
"\n",
"for",
"_",
",",
"attr",
":=",
"range",
"e",
".",
"Attributes",
"{",
"attr",
".",
"PrettyPrint",
"(",
"indent",
"+",
"2",
")",
"\n",
"}",
"\n",
"}"
]
| // PrettyPrint outputs a human-readable description indenting | [
"PrettyPrint",
"outputs",
"a",
"human",
"-",
"readable",
"description",
"indenting"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L176-L181 |
11,066 | square/certigo | starttls/ldap/search.go | NewEntryAttribute | func NewEntryAttribute(name string, values []string) *EntryAttribute {
var bytes [][]byte
for _, value := range values {
bytes = append(bytes, []byte(value))
}
return &EntryAttribute{
Name: name,
Values: values,
ByteValues: bytes,
}
} | go | func NewEntryAttribute(name string, values []string) *EntryAttribute {
var bytes [][]byte
for _, value := range values {
bytes = append(bytes, []byte(value))
}
return &EntryAttribute{
Name: name,
Values: values,
ByteValues: bytes,
}
} | [
"func",
"NewEntryAttribute",
"(",
"name",
"string",
",",
"values",
"[",
"]",
"string",
")",
"*",
"EntryAttribute",
"{",
"var",
"bytes",
"[",
"]",
"[",
"]",
"byte",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"values",
"{",
"bytes",
"=",
"append",
"(",
"bytes",
",",
"[",
"]",
"byte",
"(",
"value",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"EntryAttribute",
"{",
"Name",
":",
"name",
",",
"Values",
":",
"values",
",",
"ByteValues",
":",
"bytes",
",",
"}",
"\n",
"}"
]
| // NewEntryAttribute returns a new EntryAttribute with the desired key-value pair | [
"NewEntryAttribute",
"returns",
"a",
"new",
"EntryAttribute",
"with",
"the",
"desired",
"key",
"-",
"value",
"pair"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L184-L194 |
11,067 | square/certigo | starttls/ldap/search.go | NewSearchRequest | func NewSearchRequest(
BaseDN string,
Scope, DerefAliases, SizeLimit, TimeLimit int,
TypesOnly bool,
Filter string,
Attributes []string,
Controls []Control,
) *SearchRequest {
return &SearchRequest{
BaseDN: BaseDN,
Scope: Scope,
DerefAliases: DerefAliases,
SizeLimit: SizeLimit,
TimeLimit: TimeLimit,
TypesOnly: TypesOnly,
Filter: Filter,
Attributes: Attributes,
Controls: Controls,
}
} | go | func NewSearchRequest(
BaseDN string,
Scope, DerefAliases, SizeLimit, TimeLimit int,
TypesOnly bool,
Filter string,
Attributes []string,
Controls []Control,
) *SearchRequest {
return &SearchRequest{
BaseDN: BaseDN,
Scope: Scope,
DerefAliases: DerefAliases,
SizeLimit: SizeLimit,
TimeLimit: TimeLimit,
TypesOnly: TypesOnly,
Filter: Filter,
Attributes: Attributes,
Controls: Controls,
}
} | [
"func",
"NewSearchRequest",
"(",
"BaseDN",
"string",
",",
"Scope",
",",
"DerefAliases",
",",
"SizeLimit",
",",
"TimeLimit",
"int",
",",
"TypesOnly",
"bool",
",",
"Filter",
"string",
",",
"Attributes",
"[",
"]",
"string",
",",
"Controls",
"[",
"]",
"Control",
",",
")",
"*",
"SearchRequest",
"{",
"return",
"&",
"SearchRequest",
"{",
"BaseDN",
":",
"BaseDN",
",",
"Scope",
":",
"Scope",
",",
"DerefAliases",
":",
"DerefAliases",
",",
"SizeLimit",
":",
"SizeLimit",
",",
"TimeLimit",
":",
"TimeLimit",
",",
"TypesOnly",
":",
"TypesOnly",
",",
"Filter",
":",
"Filter",
",",
"Attributes",
":",
"Attributes",
",",
"Controls",
":",
"Controls",
",",
"}",
"\n",
"}"
]
| // NewSearchRequest creates a new search request | [
"NewSearchRequest",
"creates",
"a",
"new",
"search",
"request"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/search.go#L277-L296 |
11,068 | square/certigo | starttls/psql/error.go | Get | func (err *Error) Get(k byte) (v string) {
switch k {
case 'S':
return err.Severity
case 'C':
return string(err.Code)
case 'M':
return err.Message
case 'D':
return err.Detail
case 'H':
return err.Hint
case 'P':
return err.Position
case 'p':
return err.InternalPosition
case 'q':
return err.InternalQuery
case 'W':
return err.Where
case 's':
return err.Schema
case 't':
return err.Table
case 'c':
return err.Column
case 'd':
return err.DataTypeName
case 'n':
return err.Constraint
case 'F':
return err.File
case 'L':
return err.Line
case 'R':
return err.Routine
}
return ""
} | go | func (err *Error) Get(k byte) (v string) {
switch k {
case 'S':
return err.Severity
case 'C':
return string(err.Code)
case 'M':
return err.Message
case 'D':
return err.Detail
case 'H':
return err.Hint
case 'P':
return err.Position
case 'p':
return err.InternalPosition
case 'q':
return err.InternalQuery
case 'W':
return err.Where
case 's':
return err.Schema
case 't':
return err.Table
case 'c':
return err.Column
case 'd':
return err.DataTypeName
case 'n':
return err.Constraint
case 'F':
return err.File
case 'L':
return err.Line
case 'R':
return err.Routine
}
return ""
} | [
"func",
"(",
"err",
"*",
"Error",
")",
"Get",
"(",
"k",
"byte",
")",
"(",
"v",
"string",
")",
"{",
"switch",
"k",
"{",
"case",
"'S'",
":",
"return",
"err",
".",
"Severity",
"\n",
"case",
"'C'",
":",
"return",
"string",
"(",
"err",
".",
"Code",
")",
"\n",
"case",
"'M'",
":",
"return",
"err",
".",
"Message",
"\n",
"case",
"'D'",
":",
"return",
"err",
".",
"Detail",
"\n",
"case",
"'H'",
":",
"return",
"err",
".",
"Hint",
"\n",
"case",
"'P'",
":",
"return",
"err",
".",
"Position",
"\n",
"case",
"'p'",
":",
"return",
"err",
".",
"InternalPosition",
"\n",
"case",
"'q'",
":",
"return",
"err",
".",
"InternalQuery",
"\n",
"case",
"'W'",
":",
"return",
"err",
".",
"Where",
"\n",
"case",
"'s'",
":",
"return",
"err",
".",
"Schema",
"\n",
"case",
"'t'",
":",
"return",
"err",
".",
"Table",
"\n",
"case",
"'c'",
":",
"return",
"err",
".",
"Column",
"\n",
"case",
"'d'",
":",
"return",
"err",
".",
"DataTypeName",
"\n",
"case",
"'n'",
":",
"return",
"err",
".",
"Constraint",
"\n",
"case",
"'F'",
":",
"return",
"err",
".",
"File",
"\n",
"case",
"'L'",
":",
"return",
"err",
".",
"Line",
"\n",
"case",
"'R'",
":",
"return",
"err",
".",
"Routine",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // Get implements the legacy PGError interface. New code should use the fields
// of the Error struct directly. | [
"Get",
"implements",
"the",
"legacy",
"PGError",
"interface",
".",
"New",
"code",
"should",
"use",
"the",
"fields",
"of",
"the",
"Error",
"struct",
"directly",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/error.go#L406-L444 |
11,069 | square/certigo | starttls/ldap/dn.go | Equal | func (a *AttributeTypeAndValue) Equal(other *AttributeTypeAndValue) bool {
return strings.EqualFold(a.Type, other.Type) && a.Value == other.Value
} | go | func (a *AttributeTypeAndValue) Equal(other *AttributeTypeAndValue) bool {
return strings.EqualFold(a.Type, other.Type) && a.Value == other.Value
} | [
"func",
"(",
"a",
"*",
"AttributeTypeAndValue",
")",
"Equal",
"(",
"other",
"*",
"AttributeTypeAndValue",
")",
"bool",
"{",
"return",
"strings",
".",
"EqualFold",
"(",
"a",
".",
"Type",
",",
"other",
".",
"Type",
")",
"&&",
"a",
".",
"Value",
"==",
"other",
".",
"Value",
"\n",
"}"
]
| // Equal returns true if the AttributeTypeAndValue is equivalent to the specified AttributeTypeAndValue
// Case of the attribute type is not significant | [
"Equal",
"returns",
"true",
"if",
"the",
"AttributeTypeAndValue",
"is",
"equivalent",
"to",
"the",
"specified",
"AttributeTypeAndValue",
"Case",
"of",
"the",
"attribute",
"type",
"is",
"not",
"significant"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/dn.go#L242-L244 |
11,070 | square/certigo | starttls/ldap/passwdmodify.go | PasswordModify | func (l *Conn) PasswordModify(passwordModifyRequest *PasswordModifyRequest) (*PasswordModifyResult, error) {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
encodedPasswordModifyRequest, err := passwordModifyRequest.encode()
if err != nil {
return nil, err
}
packet.AppendChild(encodedPasswordModifyRequest)
l.Debug.PrintPacket(packet)
msgCtx, err := l.sendMessage(packet)
if err != nil {
return nil, err
}
defer l.finishMessage(msgCtx)
result := &PasswordModifyResult{}
l.Debug.Printf("%d: waiting for response", msgCtx.id)
packetResponse, ok := <-msgCtx.responses
if !ok {
return nil, NewError(ErrorNetwork, errors.New("ldap: response channel closed"))
}
packet, err = packetResponse.ReadPacket()
l.Debug.Printf("%d: got response %p", msgCtx.id, packet)
if err != nil {
return nil, err
}
if packet == nil {
return nil, NewError(ErrorNetwork, errors.New("ldap: could not retrieve message"))
}
if l.Debug {
if err := addLDAPDescriptions(packet); err != nil {
return nil, err
}
ber.PrintPacket(packet)
}
if packet.Children[1].Tag == ApplicationExtendedResponse {
resultCode, resultDescription := getLDAPResultCode(packet)
if resultCode != 0 {
return nil, NewError(resultCode, errors.New(resultDescription))
}
} else {
return nil, NewError(ErrorUnexpectedResponse, fmt.Errorf("Unexpected Response: %d", packet.Children[1].Tag))
}
extendedResponse := packet.Children[1]
for _, child := range extendedResponse.Children {
if child.Tag == 11 {
passwordModifyReponseValue := ber.DecodePacket(child.Data.Bytes())
if len(passwordModifyReponseValue.Children) == 1 {
if passwordModifyReponseValue.Children[0].Tag == 0 {
result.GeneratedPassword = ber.DecodeString(passwordModifyReponseValue.Children[0].Data.Bytes())
}
}
}
}
return result, nil
} | go | func (l *Conn) PasswordModify(passwordModifyRequest *PasswordModifyRequest) (*PasswordModifyResult, error) {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
encodedPasswordModifyRequest, err := passwordModifyRequest.encode()
if err != nil {
return nil, err
}
packet.AppendChild(encodedPasswordModifyRequest)
l.Debug.PrintPacket(packet)
msgCtx, err := l.sendMessage(packet)
if err != nil {
return nil, err
}
defer l.finishMessage(msgCtx)
result := &PasswordModifyResult{}
l.Debug.Printf("%d: waiting for response", msgCtx.id)
packetResponse, ok := <-msgCtx.responses
if !ok {
return nil, NewError(ErrorNetwork, errors.New("ldap: response channel closed"))
}
packet, err = packetResponse.ReadPacket()
l.Debug.Printf("%d: got response %p", msgCtx.id, packet)
if err != nil {
return nil, err
}
if packet == nil {
return nil, NewError(ErrorNetwork, errors.New("ldap: could not retrieve message"))
}
if l.Debug {
if err := addLDAPDescriptions(packet); err != nil {
return nil, err
}
ber.PrintPacket(packet)
}
if packet.Children[1].Tag == ApplicationExtendedResponse {
resultCode, resultDescription := getLDAPResultCode(packet)
if resultCode != 0 {
return nil, NewError(resultCode, errors.New(resultDescription))
}
} else {
return nil, NewError(ErrorUnexpectedResponse, fmt.Errorf("Unexpected Response: %d", packet.Children[1].Tag))
}
extendedResponse := packet.Children[1]
for _, child := range extendedResponse.Children {
if child.Tag == 11 {
passwordModifyReponseValue := ber.DecodePacket(child.Data.Bytes())
if len(passwordModifyReponseValue.Children) == 1 {
if passwordModifyReponseValue.Children[0].Tag == 0 {
result.GeneratedPassword = ber.DecodeString(passwordModifyReponseValue.Children[0].Data.Bytes())
}
}
}
}
return result, nil
} | [
"func",
"(",
"l",
"*",
"Conn",
")",
"PasswordModify",
"(",
"passwordModifyRequest",
"*",
"PasswordModifyRequest",
")",
"(",
"*",
"PasswordModifyResult",
",",
"error",
")",
"{",
"packet",
":=",
"ber",
".",
"Encode",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypeConstructed",
",",
"ber",
".",
"TagSequence",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"packet",
".",
"AppendChild",
"(",
"ber",
".",
"NewInteger",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypePrimitive",
",",
"ber",
".",
"TagInteger",
",",
"l",
".",
"nextMessageID",
"(",
")",
",",
"\"",
"\"",
")",
")",
"\n\n",
"encodedPasswordModifyRequest",
",",
"err",
":=",
"passwordModifyRequest",
".",
"encode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"packet",
".",
"AppendChild",
"(",
"encodedPasswordModifyRequest",
")",
"\n\n",
"l",
".",
"Debug",
".",
"PrintPacket",
"(",
"packet",
")",
"\n\n",
"msgCtx",
",",
"err",
":=",
"l",
".",
"sendMessage",
"(",
"packet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"l",
".",
"finishMessage",
"(",
"msgCtx",
")",
"\n\n",
"result",
":=",
"&",
"PasswordModifyResult",
"{",
"}",
"\n\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
")",
"\n",
"packetResponse",
",",
"ok",
":=",
"<-",
"msgCtx",
".",
"responses",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"NewError",
"(",
"ErrorNetwork",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"packet",
",",
"err",
"=",
"packetResponse",
".",
"ReadPacket",
"(",
")",
"\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
",",
"packet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"packet",
"==",
"nil",
"{",
"return",
"nil",
",",
"NewError",
"(",
"ErrorNetwork",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"if",
"l",
".",
"Debug",
"{",
"if",
"err",
":=",
"addLDAPDescriptions",
"(",
"packet",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ber",
".",
"PrintPacket",
"(",
"packet",
")",
"\n",
"}",
"\n\n",
"if",
"packet",
".",
"Children",
"[",
"1",
"]",
".",
"Tag",
"==",
"ApplicationExtendedResponse",
"{",
"resultCode",
",",
"resultDescription",
":=",
"getLDAPResultCode",
"(",
"packet",
")",
"\n",
"if",
"resultCode",
"!=",
"0",
"{",
"return",
"nil",
",",
"NewError",
"(",
"resultCode",
",",
"errors",
".",
"New",
"(",
"resultDescription",
")",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"NewError",
"(",
"ErrorUnexpectedResponse",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"packet",
".",
"Children",
"[",
"1",
"]",
".",
"Tag",
")",
")",
"\n",
"}",
"\n\n",
"extendedResponse",
":=",
"packet",
".",
"Children",
"[",
"1",
"]",
"\n",
"for",
"_",
",",
"child",
":=",
"range",
"extendedResponse",
".",
"Children",
"{",
"if",
"child",
".",
"Tag",
"==",
"11",
"{",
"passwordModifyReponseValue",
":=",
"ber",
".",
"DecodePacket",
"(",
"child",
".",
"Data",
".",
"Bytes",
"(",
")",
")",
"\n",
"if",
"len",
"(",
"passwordModifyReponseValue",
".",
"Children",
")",
"==",
"1",
"{",
"if",
"passwordModifyReponseValue",
".",
"Children",
"[",
"0",
"]",
".",
"Tag",
"==",
"0",
"{",
"result",
".",
"GeneratedPassword",
"=",
"ber",
".",
"DecodeString",
"(",
"passwordModifyReponseValue",
".",
"Children",
"[",
"0",
"]",
".",
"Data",
".",
"Bytes",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
]
| // PasswordModify performs the modification request | [
"PasswordModify",
"performs",
"the",
"modification",
"request"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/passwdmodify.go#L84-L148 |
11,071 | square/certigo | lib/display.go | EncodeX509ToJSON | func EncodeX509ToJSON(cert *x509.Certificate) []byte {
out := createSimpleCertificate("", cert)
raw, err := json.Marshal(out)
if err != nil {
panic(err)
}
return raw
} | go | func EncodeX509ToJSON(cert *x509.Certificate) []byte {
out := createSimpleCertificate("", cert)
raw, err := json.Marshal(out)
if err != nil {
panic(err)
}
return raw
} | [
"func",
"EncodeX509ToJSON",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
")",
"[",
"]",
"byte",
"{",
"out",
":=",
"createSimpleCertificate",
"(",
"\"",
"\"",
",",
"cert",
")",
"\n",
"raw",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"raw",
"\n",
"}"
]
| // EncodeX509ToJSON encodes an X.509 certificate into a JSON string. | [
"EncodeX509ToJSON",
"encodes",
"an",
"X",
".",
"509",
"certificate",
"into",
"a",
"JSON",
"string",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/lib/display.go#L188-L195 |
11,072 | square/certigo | lib/display.go | EncodeX509ToText | func EncodeX509ToText(cert *x509.Certificate, terminalWidth int, verbose bool) []byte {
c := createSimpleCertificate("", cert)
c.Width = terminalWidth - 8 /* Need some margin for tab */
return displayCert(c, verbose)
} | go | func EncodeX509ToText(cert *x509.Certificate, terminalWidth int, verbose bool) []byte {
c := createSimpleCertificate("", cert)
c.Width = terminalWidth - 8 /* Need some margin for tab */
return displayCert(c, verbose)
} | [
"func",
"EncodeX509ToText",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
",",
"terminalWidth",
"int",
",",
"verbose",
"bool",
")",
"[",
"]",
"byte",
"{",
"c",
":=",
"createSimpleCertificate",
"(",
"\"",
"\"",
",",
"cert",
")",
"\n",
"c",
".",
"Width",
"=",
"terminalWidth",
"-",
"8",
"/* Need some margin for tab */",
"\n\n",
"return",
"displayCert",
"(",
"c",
",",
"verbose",
")",
"\n",
"}"
]
| // EncodeX509ToText encodes an X.509 certificate into human-readable text. | [
"EncodeX509ToText",
"encodes",
"an",
"X",
".",
"509",
"certificate",
"into",
"human",
"-",
"readable",
"text",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/lib/display.go#L203-L208 |
11,073 | square/certigo | lib/display.go | timeString | func timeString(t time.Time, c *color.Color) string {
return c.SprintfFunc()(t.Format("2006-01-02 15:04 MST"))
} | go | func timeString(t time.Time, c *color.Color) string {
return c.SprintfFunc()(t.Format("2006-01-02 15:04 MST"))
} | [
"func",
"timeString",
"(",
"t",
"time",
".",
"Time",
",",
"c",
"*",
"color",
".",
"Color",
")",
"string",
"{",
"return",
"c",
".",
"SprintfFunc",
"(",
")",
"(",
"t",
".",
"Format",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
]
| // timeString formats a time in UTC with minute precision, in the given color. | [
"timeString",
"formats",
"a",
"time",
"in",
"UTC",
"with",
"minute",
"precision",
"in",
"the",
"given",
"color",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/lib/display.go#L290-L292 |
11,074 | square/certigo | lib/display.go | certStart | func certStart(start time.Time) string {
now := time.Now()
day, _ := time.ParseDuration("24h")
threshold := start.Add(day)
if now.After(threshold) {
return timeString(start, green)
} else if now.After(start) {
return timeString(start, yellow)
} else {
return timeString(start, red)
}
} | go | func certStart(start time.Time) string {
now := time.Now()
day, _ := time.ParseDuration("24h")
threshold := start.Add(day)
if now.After(threshold) {
return timeString(start, green)
} else if now.After(start) {
return timeString(start, yellow)
} else {
return timeString(start, red)
}
} | [
"func",
"certStart",
"(",
"start",
"time",
".",
"Time",
")",
"string",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"day",
",",
"_",
":=",
"time",
".",
"ParseDuration",
"(",
"\"",
"\"",
")",
"\n",
"threshold",
":=",
"start",
".",
"Add",
"(",
"day",
")",
"\n",
"if",
"now",
".",
"After",
"(",
"threshold",
")",
"{",
"return",
"timeString",
"(",
"start",
",",
"green",
")",
"\n",
"}",
"else",
"if",
"now",
".",
"After",
"(",
"start",
")",
"{",
"return",
"timeString",
"(",
"start",
",",
"yellow",
")",
"\n",
"}",
"else",
"{",
"return",
"timeString",
"(",
"start",
",",
"red",
")",
"\n",
"}",
"\n",
"}"
]
| // certStart takes a given start time for the validity of
// a certificate and returns that time colored properly
// based on how close it is to expiry. If it's more than
// a day after the certificate became valid the string will
// be green. If it has been less than a day the string will
// be yellow. If the certificate is not yet valid, the string
// will be red. | [
"certStart",
"takes",
"a",
"given",
"start",
"time",
"for",
"the",
"validity",
"of",
"a",
"certificate",
"and",
"returns",
"that",
"time",
"colored",
"properly",
"based",
"on",
"how",
"close",
"it",
"is",
"to",
"expiry",
".",
"If",
"it",
"s",
"more",
"than",
"a",
"day",
"after",
"the",
"certificate",
"became",
"valid",
"the",
"string",
"will",
"be",
"green",
".",
"If",
"it",
"has",
"been",
"less",
"than",
"a",
"day",
"the",
"string",
"will",
"be",
"yellow",
".",
"If",
"the",
"certificate",
"is",
"not",
"yet",
"valid",
"the",
"string",
"will",
"be",
"red",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/lib/display.go#L301-L312 |
11,075 | square/certigo | lib/display.go | certEnd | func certEnd(end time.Time) string {
now := time.Now()
month, _ := time.ParseDuration("720h")
threshold := now.Add(month)
if threshold.Before(end) {
return timeString(end, green)
} else if now.Before(end) {
return timeString(end, yellow)
} else {
return timeString(end, red)
}
} | go | func certEnd(end time.Time) string {
now := time.Now()
month, _ := time.ParseDuration("720h")
threshold := now.Add(month)
if threshold.Before(end) {
return timeString(end, green)
} else if now.Before(end) {
return timeString(end, yellow)
} else {
return timeString(end, red)
}
} | [
"func",
"certEnd",
"(",
"end",
"time",
".",
"Time",
")",
"string",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"month",
",",
"_",
":=",
"time",
".",
"ParseDuration",
"(",
"\"",
"\"",
")",
"\n",
"threshold",
":=",
"now",
".",
"Add",
"(",
"month",
")",
"\n",
"if",
"threshold",
".",
"Before",
"(",
"end",
")",
"{",
"return",
"timeString",
"(",
"end",
",",
"green",
")",
"\n",
"}",
"else",
"if",
"now",
".",
"Before",
"(",
"end",
")",
"{",
"return",
"timeString",
"(",
"end",
",",
"yellow",
")",
"\n",
"}",
"else",
"{",
"return",
"timeString",
"(",
"end",
",",
"red",
")",
"\n",
"}",
"\n",
"}"
]
| // certEnd takes a given end time for the validity of
// a certificate and returns that time colored properly
// based on how close it is to expiry. If the certificate
// is more than a month away from expiring it returns a
// green string. If the certificate is less than a month
// from expiry it returns a yellow string. If the certificate
// is expired it returns a red string. | [
"certEnd",
"takes",
"a",
"given",
"end",
"time",
"for",
"the",
"validity",
"of",
"a",
"certificate",
"and",
"returns",
"that",
"time",
"colored",
"properly",
"based",
"on",
"how",
"close",
"it",
"is",
"to",
"expiry",
".",
"If",
"the",
"certificate",
"is",
"more",
"than",
"a",
"month",
"away",
"from",
"expiring",
"it",
"returns",
"a",
"green",
"string",
".",
"If",
"the",
"certificate",
"is",
"less",
"than",
"a",
"month",
"from",
"expiry",
"it",
"returns",
"a",
"yellow",
"string",
".",
"If",
"the",
"certificate",
"is",
"expired",
"it",
"returns",
"a",
"red",
"string",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/lib/display.go#L321-L332 |
11,076 | square/certigo | lib/display.go | PrintCommonName | func PrintCommonName(name pkix.Name) (out string) {
if name.CommonName != "" {
return fmt.Sprintf("CN=%s", name.CommonName)
}
return PrintShortName(name)
} | go | func PrintCommonName(name pkix.Name) (out string) {
if name.CommonName != "" {
return fmt.Sprintf("CN=%s", name.CommonName)
}
return PrintShortName(name)
} | [
"func",
"PrintCommonName",
"(",
"name",
"pkix",
".",
"Name",
")",
"(",
"out",
"string",
")",
"{",
"if",
"name",
".",
"CommonName",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
".",
"CommonName",
")",
"\n",
"}",
"\n",
"return",
"PrintShortName",
"(",
"name",
")",
"\n",
"}"
]
| // PrintCommonName prints the CN from a pkix.Name, or falls back to PrintShortName if CN is missing. | [
"PrintCommonName",
"prints",
"the",
"CN",
"from",
"a",
"pkix",
".",
"Name",
"or",
"falls",
"back",
"to",
"PrintShortName",
"if",
"CN",
"is",
"missing",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/lib/display.go#L343-L348 |
11,077 | square/certigo | lib/display.go | PrintShortName | func PrintShortName(name pkix.Name) (out string) {
printed := false
for _, name := range name.Names {
short := oidShort(name.Type)
if short != "" {
if printed {
out += ", "
}
out += fmt.Sprintf("%s=%v", short, name.Value)
printed = true
}
}
return
} | go | func PrintShortName(name pkix.Name) (out string) {
printed := false
for _, name := range name.Names {
short := oidShort(name.Type)
if short != "" {
if printed {
out += ", "
}
out += fmt.Sprintf("%s=%v", short, name.Value)
printed = true
}
}
return
} | [
"func",
"PrintShortName",
"(",
"name",
"pkix",
".",
"Name",
")",
"(",
"out",
"string",
")",
"{",
"printed",
":=",
"false",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"name",
".",
"Names",
"{",
"short",
":=",
"oidShort",
"(",
"name",
".",
"Type",
")",
"\n",
"if",
"short",
"!=",
"\"",
"\"",
"{",
"if",
"printed",
"{",
"out",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"out",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"short",
",",
"name",
".",
"Value",
")",
"\n",
"printed",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
]
| // PrintShortName turns a pkix.Name into a string of RDN tuples. | [
"PrintShortName",
"turns",
"a",
"pkix",
".",
"Name",
"into",
"a",
"string",
"of",
"RDN",
"tuples",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/lib/display.go#L351-L365 |
11,078 | square/certigo | starttls/psql/conn.go | handleDriverSettings | func (c *conn) handleDriverSettings(o values) (err error) {
boolSetting := func(key string, val *bool) error {
if value := o.Get(key); value != "" {
if value == "yes" {
*val = true
} else if value == "no" {
*val = false
} else {
return fmt.Errorf("unrecognized value %q for %s", value, key)
}
}
return nil
}
err = boolSetting("disable_prepared_binary_result", &c.disablePreparedBinaryResult)
if err != nil {
return err
}
err = boolSetting("binary_parameters", &c.binaryParameters)
if err != nil {
return err
}
return nil
} | go | func (c *conn) handleDriverSettings(o values) (err error) {
boolSetting := func(key string, val *bool) error {
if value := o.Get(key); value != "" {
if value == "yes" {
*val = true
} else if value == "no" {
*val = false
} else {
return fmt.Errorf("unrecognized value %q for %s", value, key)
}
}
return nil
}
err = boolSetting("disable_prepared_binary_result", &c.disablePreparedBinaryResult)
if err != nil {
return err
}
err = boolSetting("binary_parameters", &c.binaryParameters)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"handleDriverSettings",
"(",
"o",
"values",
")",
"(",
"err",
"error",
")",
"{",
"boolSetting",
":=",
"func",
"(",
"key",
"string",
",",
"val",
"*",
"bool",
")",
"error",
"{",
"if",
"value",
":=",
"o",
".",
"Get",
"(",
"key",
")",
";",
"value",
"!=",
"\"",
"\"",
"{",
"if",
"value",
"==",
"\"",
"\"",
"{",
"*",
"val",
"=",
"true",
"\n",
"}",
"else",
"if",
"value",
"==",
"\"",
"\"",
"{",
"*",
"val",
"=",
"false",
"\n",
"}",
"else",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
",",
"key",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"err",
"=",
"boolSetting",
"(",
"\"",
"\"",
",",
"&",
"c",
".",
"disablePreparedBinaryResult",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"boolSetting",
"(",
"\"",
"\"",
",",
"&",
"c",
".",
"binaryParameters",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Handle driver-side settings in parsed connection string. | [
"Handle",
"driver",
"-",
"side",
"settings",
"in",
"parsed",
"connection",
"string",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L135-L158 |
11,079 | square/certigo | starttls/psql/conn.go | decideColumnFormats | func decideColumnFormats(colTyps []oid.Oid, forceText bool) (colFmts []format, colFmtData []byte) {
if len(colTyps) == 0 {
return nil, colFmtDataAllText
}
colFmts = make([]format, len(colTyps))
if forceText {
return colFmts, colFmtDataAllText
}
allBinary := true
allText := true
for i, o := range colTyps {
switch o {
// This is the list of types to use binary mode for when receiving them
// through a prepared statement. If a type appears in this list, it
// must also be implemented in binaryDecode in encode.go.
case oid.T_bytea:
fallthrough
case oid.T_int8:
fallthrough
case oid.T_int4:
fallthrough
case oid.T_int2:
fallthrough
case oid.T_uuid:
colFmts[i] = formatBinary
allText = false
default:
allBinary = false
}
}
if allBinary {
return colFmts, colFmtDataAllBinary
} else if allText {
return colFmts, colFmtDataAllText
} else {
colFmtData = make([]byte, 2+len(colFmts)*2)
binary.BigEndian.PutUint16(colFmtData, uint16(len(colFmts)))
for i, v := range colFmts {
binary.BigEndian.PutUint16(colFmtData[2+i*2:], uint16(v))
}
return colFmts, colFmtData
}
} | go | func decideColumnFormats(colTyps []oid.Oid, forceText bool) (colFmts []format, colFmtData []byte) {
if len(colTyps) == 0 {
return nil, colFmtDataAllText
}
colFmts = make([]format, len(colTyps))
if forceText {
return colFmts, colFmtDataAllText
}
allBinary := true
allText := true
for i, o := range colTyps {
switch o {
// This is the list of types to use binary mode for when receiving them
// through a prepared statement. If a type appears in this list, it
// must also be implemented in binaryDecode in encode.go.
case oid.T_bytea:
fallthrough
case oid.T_int8:
fallthrough
case oid.T_int4:
fallthrough
case oid.T_int2:
fallthrough
case oid.T_uuid:
colFmts[i] = formatBinary
allText = false
default:
allBinary = false
}
}
if allBinary {
return colFmts, colFmtDataAllBinary
} else if allText {
return colFmts, colFmtDataAllText
} else {
colFmtData = make([]byte, 2+len(colFmts)*2)
binary.BigEndian.PutUint16(colFmtData, uint16(len(colFmts)))
for i, v := range colFmts {
binary.BigEndian.PutUint16(colFmtData[2+i*2:], uint16(v))
}
return colFmts, colFmtData
}
} | [
"func",
"decideColumnFormats",
"(",
"colTyps",
"[",
"]",
"oid",
".",
"Oid",
",",
"forceText",
"bool",
")",
"(",
"colFmts",
"[",
"]",
"format",
",",
"colFmtData",
"[",
"]",
"byte",
")",
"{",
"if",
"len",
"(",
"colTyps",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"colFmtDataAllText",
"\n",
"}",
"\n\n",
"colFmts",
"=",
"make",
"(",
"[",
"]",
"format",
",",
"len",
"(",
"colTyps",
")",
")",
"\n",
"if",
"forceText",
"{",
"return",
"colFmts",
",",
"colFmtDataAllText",
"\n",
"}",
"\n\n",
"allBinary",
":=",
"true",
"\n",
"allText",
":=",
"true",
"\n",
"for",
"i",
",",
"o",
":=",
"range",
"colTyps",
"{",
"switch",
"o",
"{",
"// This is the list of types to use binary mode for when receiving them",
"// through a prepared statement. If a type appears in this list, it",
"// must also be implemented in binaryDecode in encode.go.",
"case",
"oid",
".",
"T_bytea",
":",
"fallthrough",
"\n",
"case",
"oid",
".",
"T_int8",
":",
"fallthrough",
"\n",
"case",
"oid",
".",
"T_int4",
":",
"fallthrough",
"\n",
"case",
"oid",
".",
"T_int2",
":",
"fallthrough",
"\n",
"case",
"oid",
".",
"T_uuid",
":",
"colFmts",
"[",
"i",
"]",
"=",
"formatBinary",
"\n",
"allText",
"=",
"false",
"\n\n",
"default",
":",
"allBinary",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"allBinary",
"{",
"return",
"colFmts",
",",
"colFmtDataAllBinary",
"\n",
"}",
"else",
"if",
"allText",
"{",
"return",
"colFmts",
",",
"colFmtDataAllText",
"\n",
"}",
"else",
"{",
"colFmtData",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
"+",
"len",
"(",
"colFmts",
")",
"*",
"2",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"colFmtData",
",",
"uint16",
"(",
"len",
"(",
"colFmts",
")",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"colFmts",
"{",
"binary",
".",
"BigEndian",
".",
"PutUint16",
"(",
"colFmtData",
"[",
"2",
"+",
"i",
"*",
"2",
":",
"]",
",",
"uint16",
"(",
"v",
")",
")",
"\n",
"}",
"\n",
"return",
"colFmts",
",",
"colFmtData",
"\n",
"}",
"\n",
"}"
]
| // Decides which column formats to use for a prepared statement. The input is
// an array of type oids, one element per result column. | [
"Decides",
"which",
"column",
"formats",
"to",
"use",
"for",
"a",
"prepared",
"statement",
".",
"The",
"input",
"is",
"an",
"array",
"of",
"type",
"oids",
"one",
"element",
"per",
"result",
"column",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L827-L873 |
11,080 | square/certigo | starttls/psql/conn.go | Query | func (cn *conn) Query(query string, args []driver.Value) (driver.Rows, error) {
return cn.query(query, args)
} | go | func (cn *conn) Query(query string, args []driver.Value) (driver.Rows, error) {
return cn.query(query, args)
} | [
"func",
"(",
"cn",
"*",
"conn",
")",
"Query",
"(",
"query",
"string",
",",
"args",
"[",
"]",
"driver",
".",
"Value",
")",
"(",
"driver",
".",
"Rows",
",",
"error",
")",
"{",
"return",
"cn",
".",
"query",
"(",
"query",
",",
"args",
")",
"\n",
"}"
]
| // Implement the "Queryer" interface | [
"Implement",
"the",
"Queryer",
"interface"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L932-L934 |
11,081 | square/certigo | starttls/psql/conn.go | sendSimpleMessage | func (cn *conn) sendSimpleMessage(typ byte) (err error) {
_, err = cn.c.Write([]byte{typ, '\x00', '\x00', '\x00', '\x04'})
return err
} | go | func (cn *conn) sendSimpleMessage(typ byte) (err error) {
_, err = cn.c.Write([]byte{typ, '\x00', '\x00', '\x00', '\x04'})
return err
} | [
"func",
"(",
"cn",
"*",
"conn",
")",
"sendSimpleMessage",
"(",
"typ",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"cn",
".",
"c",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"typ",
",",
"'\\x00'",
",",
"'\\x00'",
",",
"'\\x00'",
",",
"'\\x04'",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
]
| // Send a message of type typ to the server on the other end of cn. The
// message should have no payload. This method does not use the scratch
// buffer. | [
"Send",
"a",
"message",
"of",
"type",
"typ",
"to",
"the",
"server",
"on",
"the",
"other",
"end",
"of",
"cn",
".",
"The",
"message",
"should",
"have",
"no",
"payload",
".",
"This",
"method",
"does",
"not",
"use",
"the",
"scratch",
"buffer",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L1031-L1034 |
11,082 | square/certigo | starttls/psql/conn.go | recvMessage | func (cn *conn) recvMessage(r *readBuf) (byte, error) {
// workaround for a QueryRow bug, see exec
if cn.saveMessageType != 0 {
t := cn.saveMessageType
*r = cn.saveMessageBuffer
cn.saveMessageType = 0
cn.saveMessageBuffer = nil
return t, nil
}
x := cn.scratch[:5]
_, err := io.ReadFull(cn.buf, x)
if err != nil {
return 0, err
}
// read the type and length of the message that follows
t := x[0]
n := int(binary.BigEndian.Uint32(x[1:])) - 4
var y []byte
if n <= len(cn.scratch) {
y = cn.scratch[:n]
} else {
y = make([]byte, n)
}
_, err = io.ReadFull(cn.buf, y)
if err != nil {
return 0, err
}
*r = y
return t, nil
} | go | func (cn *conn) recvMessage(r *readBuf) (byte, error) {
// workaround for a QueryRow bug, see exec
if cn.saveMessageType != 0 {
t := cn.saveMessageType
*r = cn.saveMessageBuffer
cn.saveMessageType = 0
cn.saveMessageBuffer = nil
return t, nil
}
x := cn.scratch[:5]
_, err := io.ReadFull(cn.buf, x)
if err != nil {
return 0, err
}
// read the type and length of the message that follows
t := x[0]
n := int(binary.BigEndian.Uint32(x[1:])) - 4
var y []byte
if n <= len(cn.scratch) {
y = cn.scratch[:n]
} else {
y = make([]byte, n)
}
_, err = io.ReadFull(cn.buf, y)
if err != nil {
return 0, err
}
*r = y
return t, nil
} | [
"func",
"(",
"cn",
"*",
"conn",
")",
"recvMessage",
"(",
"r",
"*",
"readBuf",
")",
"(",
"byte",
",",
"error",
")",
"{",
"// workaround for a QueryRow bug, see exec",
"if",
"cn",
".",
"saveMessageType",
"!=",
"0",
"{",
"t",
":=",
"cn",
".",
"saveMessageType",
"\n",
"*",
"r",
"=",
"cn",
".",
"saveMessageBuffer",
"\n",
"cn",
".",
"saveMessageType",
"=",
"0",
"\n",
"cn",
".",
"saveMessageBuffer",
"=",
"nil",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}",
"\n\n",
"x",
":=",
"cn",
".",
"scratch",
"[",
":",
"5",
"]",
"\n",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"cn",
".",
"buf",
",",
"x",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"// read the type and length of the message that follows",
"t",
":=",
"x",
"[",
"0",
"]",
"\n",
"n",
":=",
"int",
"(",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"x",
"[",
"1",
":",
"]",
")",
")",
"-",
"4",
"\n",
"var",
"y",
"[",
"]",
"byte",
"\n",
"if",
"n",
"<=",
"len",
"(",
"cn",
".",
"scratch",
")",
"{",
"y",
"=",
"cn",
".",
"scratch",
"[",
":",
"n",
"]",
"\n",
"}",
"else",
"{",
"y",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"cn",
".",
"buf",
",",
"y",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"*",
"r",
"=",
"y",
"\n",
"return",
"t",
",",
"nil",
"\n",
"}"
]
| // recvMessage receives any message from the backend, or returns an error if
// a problem occurred while reading the message. | [
"recvMessage",
"receives",
"any",
"message",
"from",
"the",
"backend",
"or",
"returns",
"an",
"error",
"if",
"a",
"problem",
"occurred",
"while",
"reading",
"the",
"message",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L1052-L1083 |
11,083 | square/certigo | starttls/psql/conn.go | recv | func (cn *conn) recv() (t byte, r *readBuf) {
for {
var err error
r = &readBuf{}
t, err = cn.recvMessage(r)
if err != nil {
panic(err)
}
switch t {
case 'E':
panic(parseError(r))
case 'N':
// ignore
default:
return
}
}
} | go | func (cn *conn) recv() (t byte, r *readBuf) {
for {
var err error
r = &readBuf{}
t, err = cn.recvMessage(r)
if err != nil {
panic(err)
}
switch t {
case 'E':
panic(parseError(r))
case 'N':
// ignore
default:
return
}
}
} | [
"func",
"(",
"cn",
"*",
"conn",
")",
"recv",
"(",
")",
"(",
"t",
"byte",
",",
"r",
"*",
"readBuf",
")",
"{",
"for",
"{",
"var",
"err",
"error",
"\n",
"r",
"=",
"&",
"readBuf",
"{",
"}",
"\n",
"t",
",",
"err",
"=",
"cn",
".",
"recvMessage",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"switch",
"t",
"{",
"case",
"'E'",
":",
"panic",
"(",
"parseError",
"(",
"r",
")",
")",
"\n",
"case",
"'N'",
":",
"// ignore",
"default",
":",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // recv receives a message from the backend, but if an error happened while
// reading the message or the received message was an ErrorResponse, it panics.
// NoticeResponses are ignored. This function should generally be used only
// during the startup sequence. | [
"recv",
"receives",
"a",
"message",
"from",
"the",
"backend",
"but",
"if",
"an",
"error",
"happened",
"while",
"reading",
"the",
"message",
"or",
"the",
"received",
"message",
"was",
"an",
"ErrorResponse",
"it",
"panics",
".",
"NoticeResponses",
"are",
"ignored",
".",
"This",
"function",
"should",
"generally",
"be",
"used",
"only",
"during",
"the",
"startup",
"sequence",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L1089-L1107 |
11,084 | square/certigo | starttls/psql/conn.go | recv1Buf | func (cn *conn) recv1Buf(r *readBuf) byte {
for {
t, err := cn.recvMessage(r)
if err != nil {
panic(err)
}
switch t {
case 'A', 'N':
// ignore
case 'S':
cn.processParameterStatus(r)
default:
return t
}
}
} | go | func (cn *conn) recv1Buf(r *readBuf) byte {
for {
t, err := cn.recvMessage(r)
if err != nil {
panic(err)
}
switch t {
case 'A', 'N':
// ignore
case 'S':
cn.processParameterStatus(r)
default:
return t
}
}
} | [
"func",
"(",
"cn",
"*",
"conn",
")",
"recv1Buf",
"(",
"r",
"*",
"readBuf",
")",
"byte",
"{",
"for",
"{",
"t",
",",
"err",
":=",
"cn",
".",
"recvMessage",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"switch",
"t",
"{",
"case",
"'A'",
",",
"'N'",
":",
"// ignore",
"case",
"'S'",
":",
"cn",
".",
"processParameterStatus",
"(",
"r",
")",
"\n",
"default",
":",
"return",
"t",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // recv1Buf is exactly equivalent to recv1, except it uses a buffer supplied by
// the caller to avoid an allocation. | [
"recv1Buf",
"is",
"exactly",
"equivalent",
"to",
"recv1",
"except",
"it",
"uses",
"a",
"buffer",
"supplied",
"by",
"the",
"caller",
"to",
"avoid",
"an",
"allocation",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L1111-L1127 |
11,085 | square/certigo | starttls/psql/conn.go | recv1 | func (cn *conn) recv1() (t byte, r *readBuf) {
r = &readBuf{}
t = cn.recv1Buf(r)
return t, r
} | go | func (cn *conn) recv1() (t byte, r *readBuf) {
r = &readBuf{}
t = cn.recv1Buf(r)
return t, r
} | [
"func",
"(",
"cn",
"*",
"conn",
")",
"recv1",
"(",
")",
"(",
"t",
"byte",
",",
"r",
"*",
"readBuf",
")",
"{",
"r",
"=",
"&",
"readBuf",
"{",
"}",
"\n",
"t",
"=",
"cn",
".",
"recv1Buf",
"(",
"r",
")",
"\n",
"return",
"t",
",",
"r",
"\n",
"}"
]
| // recv1 receives a message from the backend, panicking if an error occurs
// while attempting to read it. All asynchronous messages are ignored, with
// the exception of ErrorResponse. | [
"recv1",
"receives",
"a",
"message",
"from",
"the",
"backend",
"panicking",
"if",
"an",
"error",
"occurs",
"while",
"attempting",
"to",
"read",
"it",
".",
"All",
"asynchronous",
"messages",
"are",
"ignored",
"with",
"the",
"exception",
"of",
"ErrorResponse",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L1132-L1136 |
11,086 | square/certigo | starttls/psql/conn.go | isDriverSetting | func isDriverSetting(key string) bool {
switch key {
case "host", "port":
return true
case "password":
return true
case "sslmode", "sslcert", "sslkey", "sslrootcert":
return true
case "fallback_application_name":
return true
case "connect_timeout":
return true
case "disable_prepared_binary_result":
return true
case "binary_parameters":
return true
default:
return false
}
} | go | func isDriverSetting(key string) bool {
switch key {
case "host", "port":
return true
case "password":
return true
case "sslmode", "sslcert", "sslkey", "sslrootcert":
return true
case "fallback_application_name":
return true
case "connect_timeout":
return true
case "disable_prepared_binary_result":
return true
case "binary_parameters":
return true
default:
return false
}
} | [
"func",
"isDriverSetting",
"(",
"key",
"string",
")",
"bool",
"{",
"switch",
"key",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"return",
"true",
"\n\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
]
| // isDriverSetting returns true iff a setting is purely for configuring the
// driver's options and should not be sent to the server in the connection
// startup packet. | [
"isDriverSetting",
"returns",
"true",
"iff",
"a",
"setting",
"is",
"purely",
"for",
"configuring",
"the",
"driver",
"s",
"options",
"and",
"should",
"not",
"be",
"sent",
"to",
"the",
"server",
"in",
"the",
"connection",
"startup",
"packet",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L1165-L1185 |
11,087 | square/certigo | starttls/psql/conn.go | isUTF8 | func isUTF8(name string) bool {
// Recognize all sorts of silly things as "UTF-8", like Postgres does
s := strings.Map(alnumLowerASCII, name)
return s == "utf8" || s == "unicode"
} | go | func isUTF8(name string) bool {
// Recognize all sorts of silly things as "UTF-8", like Postgres does
s := strings.Map(alnumLowerASCII, name)
return s == "utf8" || s == "unicode"
} | [
"func",
"isUTF8",
"(",
"name",
"string",
")",
"bool",
"{",
"// Recognize all sorts of silly things as \"UTF-8\", like Postgres does",
"s",
":=",
"strings",
".",
"Map",
"(",
"alnumLowerASCII",
",",
"name",
")",
"\n",
"return",
"s",
"==",
"\"",
"\"",
"||",
"s",
"==",
"\"",
"\"",
"\n",
"}"
]
| // isUTF8 returns whether name is a fuzzy variation of the string "UTF-8". | [
"isUTF8",
"returns",
"whether",
"name",
"is",
"a",
"fuzzy",
"variation",
"of",
"the",
"string",
"UTF",
"-",
"8",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/conn.go#L1925-L1929 |
11,088 | square/certigo | starttls/ldap/modify.go | Add | func (m *ModifyRequest) Add(attrType string, attrVals []string) {
m.AddAttributes = append(m.AddAttributes, PartialAttribute{Type: attrType, Vals: attrVals})
} | go | func (m *ModifyRequest) Add(attrType string, attrVals []string) {
m.AddAttributes = append(m.AddAttributes, PartialAttribute{Type: attrType, Vals: attrVals})
} | [
"func",
"(",
"m",
"*",
"ModifyRequest",
")",
"Add",
"(",
"attrType",
"string",
",",
"attrVals",
"[",
"]",
"string",
")",
"{",
"m",
".",
"AddAttributes",
"=",
"append",
"(",
"m",
".",
"AddAttributes",
",",
"PartialAttribute",
"{",
"Type",
":",
"attrType",
",",
"Vals",
":",
"attrVals",
"}",
")",
"\n",
"}"
]
| // Add inserts the given attribute to the list of attributes to add | [
"Add",
"inserts",
"the",
"given",
"attribute",
"to",
"the",
"list",
"of",
"attributes",
"to",
"add"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/modify.go#L78-L80 |
11,089 | square/certigo | starttls/ldap/modify.go | Delete | func (m *ModifyRequest) Delete(attrType string, attrVals []string) {
m.DeleteAttributes = append(m.DeleteAttributes, PartialAttribute{Type: attrType, Vals: attrVals})
} | go | func (m *ModifyRequest) Delete(attrType string, attrVals []string) {
m.DeleteAttributes = append(m.DeleteAttributes, PartialAttribute{Type: attrType, Vals: attrVals})
} | [
"func",
"(",
"m",
"*",
"ModifyRequest",
")",
"Delete",
"(",
"attrType",
"string",
",",
"attrVals",
"[",
"]",
"string",
")",
"{",
"m",
".",
"DeleteAttributes",
"=",
"append",
"(",
"m",
".",
"DeleteAttributes",
",",
"PartialAttribute",
"{",
"Type",
":",
"attrType",
",",
"Vals",
":",
"attrVals",
"}",
")",
"\n",
"}"
]
| // Delete inserts the given attribute to the list of attributes to delete | [
"Delete",
"inserts",
"the",
"given",
"attribute",
"to",
"the",
"list",
"of",
"attributes",
"to",
"delete"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/modify.go#L83-L85 |
11,090 | square/certigo | starttls/ldap/modify.go | Replace | func (m *ModifyRequest) Replace(attrType string, attrVals []string) {
m.ReplaceAttributes = append(m.ReplaceAttributes, PartialAttribute{Type: attrType, Vals: attrVals})
} | go | func (m *ModifyRequest) Replace(attrType string, attrVals []string) {
m.ReplaceAttributes = append(m.ReplaceAttributes, PartialAttribute{Type: attrType, Vals: attrVals})
} | [
"func",
"(",
"m",
"*",
"ModifyRequest",
")",
"Replace",
"(",
"attrType",
"string",
",",
"attrVals",
"[",
"]",
"string",
")",
"{",
"m",
".",
"ReplaceAttributes",
"=",
"append",
"(",
"m",
".",
"ReplaceAttributes",
",",
"PartialAttribute",
"{",
"Type",
":",
"attrType",
",",
"Vals",
":",
"attrVals",
"}",
")",
"\n",
"}"
]
| // Replace inserts the given attribute to the list of attributes to replace | [
"Replace",
"inserts",
"the",
"given",
"attribute",
"to",
"the",
"list",
"of",
"attributes",
"to",
"replace"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/modify.go#L88-L90 |
11,091 | square/certigo | starttls/ldap/modify.go | Modify | func (l *Conn) Modify(modifyRequest *ModifyRequest) error {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
packet.AppendChild(modifyRequest.encode())
l.Debug.PrintPacket(packet)
msgCtx, err := l.sendMessage(packet)
if err != nil {
return err
}
defer l.finishMessage(msgCtx)
l.Debug.Printf("%d: waiting for response", msgCtx.id)
packetResponse, ok := <-msgCtx.responses
if !ok {
return NewError(ErrorNetwork, errors.New("ldap: response channel closed"))
}
packet, err = packetResponse.ReadPacket()
l.Debug.Printf("%d: got response %p", msgCtx.id, packet)
if err != nil {
return err
}
if l.Debug {
if err := addLDAPDescriptions(packet); err != nil {
return err
}
ber.PrintPacket(packet)
}
if packet.Children[1].Tag == ApplicationModifyResponse {
resultCode, resultDescription := getLDAPResultCode(packet)
if resultCode != 0 {
return NewError(resultCode, errors.New(resultDescription))
}
} else {
log.Printf("Unexpected Response: %d", packet.Children[1].Tag)
}
l.Debug.Printf("%d: returning", msgCtx.id)
return nil
} | go | func (l *Conn) Modify(modifyRequest *ModifyRequest) error {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
packet.AppendChild(modifyRequest.encode())
l.Debug.PrintPacket(packet)
msgCtx, err := l.sendMessage(packet)
if err != nil {
return err
}
defer l.finishMessage(msgCtx)
l.Debug.Printf("%d: waiting for response", msgCtx.id)
packetResponse, ok := <-msgCtx.responses
if !ok {
return NewError(ErrorNetwork, errors.New("ldap: response channel closed"))
}
packet, err = packetResponse.ReadPacket()
l.Debug.Printf("%d: got response %p", msgCtx.id, packet)
if err != nil {
return err
}
if l.Debug {
if err := addLDAPDescriptions(packet); err != nil {
return err
}
ber.PrintPacket(packet)
}
if packet.Children[1].Tag == ApplicationModifyResponse {
resultCode, resultDescription := getLDAPResultCode(packet)
if resultCode != 0 {
return NewError(resultCode, errors.New(resultDescription))
}
} else {
log.Printf("Unexpected Response: %d", packet.Children[1].Tag)
}
l.Debug.Printf("%d: returning", msgCtx.id)
return nil
} | [
"func",
"(",
"l",
"*",
"Conn",
")",
"Modify",
"(",
"modifyRequest",
"*",
"ModifyRequest",
")",
"error",
"{",
"packet",
":=",
"ber",
".",
"Encode",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypeConstructed",
",",
"ber",
".",
"TagSequence",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"packet",
".",
"AppendChild",
"(",
"ber",
".",
"NewInteger",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypePrimitive",
",",
"ber",
".",
"TagInteger",
",",
"l",
".",
"nextMessageID",
"(",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"packet",
".",
"AppendChild",
"(",
"modifyRequest",
".",
"encode",
"(",
")",
")",
"\n\n",
"l",
".",
"Debug",
".",
"PrintPacket",
"(",
"packet",
")",
"\n\n",
"msgCtx",
",",
"err",
":=",
"l",
".",
"sendMessage",
"(",
"packet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"l",
".",
"finishMessage",
"(",
"msgCtx",
")",
"\n\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
")",
"\n",
"packetResponse",
",",
"ok",
":=",
"<-",
"msgCtx",
".",
"responses",
"\n",
"if",
"!",
"ok",
"{",
"return",
"NewError",
"(",
"ErrorNetwork",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"packet",
",",
"err",
"=",
"packetResponse",
".",
"ReadPacket",
"(",
")",
"\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
",",
"packet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"l",
".",
"Debug",
"{",
"if",
"err",
":=",
"addLDAPDescriptions",
"(",
"packet",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ber",
".",
"PrintPacket",
"(",
"packet",
")",
"\n",
"}",
"\n\n",
"if",
"packet",
".",
"Children",
"[",
"1",
"]",
".",
"Tag",
"==",
"ApplicationModifyResponse",
"{",
"resultCode",
",",
"resultDescription",
":=",
"getLDAPResultCode",
"(",
"packet",
")",
"\n",
"if",
"resultCode",
"!=",
"0",
"{",
"return",
"NewError",
"(",
"resultCode",
",",
"errors",
".",
"New",
"(",
"resultDescription",
")",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"packet",
".",
"Children",
"[",
"1",
"]",
".",
"Tag",
")",
"\n",
"}",
"\n\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
")",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Modify performs the ModifyRequest | [
"Modify",
"performs",
"the",
"ModifyRequest"
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/modify.go#L128-L170 |
11,092 | square/certigo | starttls/ldap/compare.go | Compare | func (l *Conn) Compare(dn, attribute, value string) (bool, error) {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationCompareRequest, nil, "Compare Request")
request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, dn, "DN"))
ava := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "AttributeValueAssertion")
ava.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "AttributeDesc"))
ava.AppendChild(ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagOctetString, value, "AssertionValue"))
request.AppendChild(ava)
packet.AppendChild(request)
l.Debug.PrintPacket(packet)
msgCtx, err := l.sendMessage(packet)
if err != nil {
return false, err
}
defer l.finishMessage(msgCtx)
l.Debug.Printf("%d: waiting for response", msgCtx.id)
packetResponse, ok := <-msgCtx.responses
if !ok {
return false, NewError(ErrorNetwork, errors.New("ldap: response channel closed"))
}
packet, err = packetResponse.ReadPacket()
l.Debug.Printf("%d: got response %p", msgCtx.id, packet)
if err != nil {
return false, err
}
if l.Debug {
if err := addLDAPDescriptions(packet); err != nil {
return false, err
}
ber.PrintPacket(packet)
}
if packet.Children[1].Tag == ApplicationCompareResponse {
resultCode, resultDescription := getLDAPResultCode(packet)
if resultCode == LDAPResultCompareTrue {
return true, nil
} else if resultCode == LDAPResultCompareFalse {
return false, nil
} else {
return false, NewError(resultCode, errors.New(resultDescription))
}
}
return false, fmt.Errorf("Unexpected Response: %d", packet.Children[1].Tag)
} | go | func (l *Conn) Compare(dn, attribute, value string) (bool, error) {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationCompareRequest, nil, "Compare Request")
request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, dn, "DN"))
ava := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "AttributeValueAssertion")
ava.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "AttributeDesc"))
ava.AppendChild(ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagOctetString, value, "AssertionValue"))
request.AppendChild(ava)
packet.AppendChild(request)
l.Debug.PrintPacket(packet)
msgCtx, err := l.sendMessage(packet)
if err != nil {
return false, err
}
defer l.finishMessage(msgCtx)
l.Debug.Printf("%d: waiting for response", msgCtx.id)
packetResponse, ok := <-msgCtx.responses
if !ok {
return false, NewError(ErrorNetwork, errors.New("ldap: response channel closed"))
}
packet, err = packetResponse.ReadPacket()
l.Debug.Printf("%d: got response %p", msgCtx.id, packet)
if err != nil {
return false, err
}
if l.Debug {
if err := addLDAPDescriptions(packet); err != nil {
return false, err
}
ber.PrintPacket(packet)
}
if packet.Children[1].Tag == ApplicationCompareResponse {
resultCode, resultDescription := getLDAPResultCode(packet)
if resultCode == LDAPResultCompareTrue {
return true, nil
} else if resultCode == LDAPResultCompareFalse {
return false, nil
} else {
return false, NewError(resultCode, errors.New(resultDescription))
}
}
return false, fmt.Errorf("Unexpected Response: %d", packet.Children[1].Tag)
} | [
"func",
"(",
"l",
"*",
"Conn",
")",
"Compare",
"(",
"dn",
",",
"attribute",
",",
"value",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"packet",
":=",
"ber",
".",
"Encode",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypeConstructed",
",",
"ber",
".",
"TagSequence",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"packet",
".",
"AppendChild",
"(",
"ber",
".",
"NewInteger",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypePrimitive",
",",
"ber",
".",
"TagInteger",
",",
"l",
".",
"nextMessageID",
"(",
")",
",",
"\"",
"\"",
")",
")",
"\n\n",
"request",
":=",
"ber",
".",
"Encode",
"(",
"ber",
".",
"ClassApplication",
",",
"ber",
".",
"TypeConstructed",
",",
"ApplicationCompareRequest",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"request",
".",
"AppendChild",
"(",
"ber",
".",
"NewString",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypePrimitive",
",",
"ber",
".",
"TagOctetString",
",",
"dn",
",",
"\"",
"\"",
")",
")",
"\n\n",
"ava",
":=",
"ber",
".",
"Encode",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypeConstructed",
",",
"ber",
".",
"TagSequence",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"ava",
".",
"AppendChild",
"(",
"ber",
".",
"NewString",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypePrimitive",
",",
"ber",
".",
"TagOctetString",
",",
"attribute",
",",
"\"",
"\"",
")",
")",
"\n",
"ava",
".",
"AppendChild",
"(",
"ber",
".",
"Encode",
"(",
"ber",
".",
"ClassUniversal",
",",
"ber",
".",
"TypeConstructed",
",",
"ber",
".",
"TagOctetString",
",",
"value",
",",
"\"",
"\"",
")",
")",
"\n",
"request",
".",
"AppendChild",
"(",
"ava",
")",
"\n",
"packet",
".",
"AppendChild",
"(",
"request",
")",
"\n\n",
"l",
".",
"Debug",
".",
"PrintPacket",
"(",
"packet",
")",
"\n\n",
"msgCtx",
",",
"err",
":=",
"l",
".",
"sendMessage",
"(",
"packet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"defer",
"l",
".",
"finishMessage",
"(",
"msgCtx",
")",
"\n\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
")",
"\n",
"packetResponse",
",",
"ok",
":=",
"<-",
"msgCtx",
".",
"responses",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
",",
"NewError",
"(",
"ErrorNetwork",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"packet",
",",
"err",
"=",
"packetResponse",
".",
"ReadPacket",
"(",
")",
"\n",
"l",
".",
"Debug",
".",
"Printf",
"(",
"\"",
"\"",
",",
"msgCtx",
".",
"id",
",",
"packet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"l",
".",
"Debug",
"{",
"if",
"err",
":=",
"addLDAPDescriptions",
"(",
"packet",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"ber",
".",
"PrintPacket",
"(",
"packet",
")",
"\n",
"}",
"\n\n",
"if",
"packet",
".",
"Children",
"[",
"1",
"]",
".",
"Tag",
"==",
"ApplicationCompareResponse",
"{",
"resultCode",
",",
"resultDescription",
":=",
"getLDAPResultCode",
"(",
"packet",
")",
"\n",
"if",
"resultCode",
"==",
"LDAPResultCompareTrue",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"else",
"if",
"resultCode",
"==",
"LDAPResultCompareFalse",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"false",
",",
"NewError",
"(",
"resultCode",
",",
"errors",
".",
"New",
"(",
"resultDescription",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"packet",
".",
"Children",
"[",
"1",
"]",
".",
"Tag",
")",
"\n",
"}"
]
| // Compare checks to see if the attribute of the dn matches value. Returns true if it does otherwise
// false with any error that occurs if any. | [
"Compare",
"checks",
"to",
"see",
"if",
"the",
"attribute",
"of",
"the",
"dn",
"matches",
"value",
".",
"Returns",
"true",
"if",
"it",
"does",
"otherwise",
"false",
"with",
"any",
"error",
"that",
"occurs",
"if",
"any",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/ldap/compare.go#L35-L85 |
11,093 | square/certigo | starttls/psql/notify.go | NewListenerConn | func NewListenerConn(name string, notificationChan chan<- *Notification) (*ListenerConn, error) {
return newDialListenerConn(defaultDialer{}, name, notificationChan)
} | go | func NewListenerConn(name string, notificationChan chan<- *Notification) (*ListenerConn, error) {
return newDialListenerConn(defaultDialer{}, name, notificationChan)
} | [
"func",
"NewListenerConn",
"(",
"name",
"string",
",",
"notificationChan",
"chan",
"<-",
"*",
"Notification",
")",
"(",
"*",
"ListenerConn",
",",
"error",
")",
"{",
"return",
"newDialListenerConn",
"(",
"defaultDialer",
"{",
"}",
",",
"name",
",",
"notificationChan",
")",
"\n",
"}"
]
| // Creates a new ListenerConn. Use NewListener instead. | [
"Creates",
"a",
"new",
"ListenerConn",
".",
"Use",
"NewListener",
"instead",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/notify.go#L64-L66 |
11,094 | square/certigo | starttls/psql/notify.go | acquireSenderLock | func (l *ListenerConn) acquireSenderLock() error {
// we must acquire senderLock first to avoid deadlocks; see ExecSimpleQuery
l.senderLock.Lock()
l.connectionLock.Lock()
err := l.err
l.connectionLock.Unlock()
if err != nil {
l.senderLock.Unlock()
return err
}
return nil
} | go | func (l *ListenerConn) acquireSenderLock() error {
// we must acquire senderLock first to avoid deadlocks; see ExecSimpleQuery
l.senderLock.Lock()
l.connectionLock.Lock()
err := l.err
l.connectionLock.Unlock()
if err != nil {
l.senderLock.Unlock()
return err
}
return nil
} | [
"func",
"(",
"l",
"*",
"ListenerConn",
")",
"acquireSenderLock",
"(",
")",
"error",
"{",
"// we must acquire senderLock first to avoid deadlocks; see ExecSimpleQuery",
"l",
".",
"senderLock",
".",
"Lock",
"(",
")",
"\n\n",
"l",
".",
"connectionLock",
".",
"Lock",
"(",
")",
"\n",
"err",
":=",
"l",
".",
"err",
"\n",
"l",
".",
"connectionLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"l",
".",
"senderLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // We can only allow one goroutine at a time to be running a query on the
// connection for various reasons, so the goroutine sending on the connection
// must be holding senderLock.
//
// Returns an error if an unrecoverable error has occurred and the ListenerConn
// should be abandoned. | [
"We",
"can",
"only",
"allow",
"one",
"goroutine",
"at",
"a",
"time",
"to",
"be",
"running",
"a",
"query",
"on",
"the",
"connection",
"for",
"various",
"reasons",
"so",
"the",
"goroutine",
"sending",
"on",
"the",
"connection",
"must",
"be",
"holding",
"senderLock",
".",
"Returns",
"an",
"error",
"if",
"an",
"unrecoverable",
"error",
"has",
"occurred",
"and",
"the",
"ListenerConn",
"should",
"be",
"abandoned",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/notify.go#L92-L104 |
11,095 | square/certigo | starttls/psql/notify.go | setState | func (l *ListenerConn) setState(newState int32) bool {
var expectedState int32
switch newState {
case connStateIdle:
expectedState = connStateExpectReadyForQuery
case connStateExpectResponse:
expectedState = connStateIdle
case connStateExpectReadyForQuery:
expectedState = connStateExpectResponse
default:
panic(fmt.Sprintf("unexpected listenerConnState %d", newState))
}
return atomic.CompareAndSwapInt32(&l.connState, expectedState, newState)
} | go | func (l *ListenerConn) setState(newState int32) bool {
var expectedState int32
switch newState {
case connStateIdle:
expectedState = connStateExpectReadyForQuery
case connStateExpectResponse:
expectedState = connStateIdle
case connStateExpectReadyForQuery:
expectedState = connStateExpectResponse
default:
panic(fmt.Sprintf("unexpected listenerConnState %d", newState))
}
return atomic.CompareAndSwapInt32(&l.connState, expectedState, newState)
} | [
"func",
"(",
"l",
"*",
"ListenerConn",
")",
"setState",
"(",
"newState",
"int32",
")",
"bool",
"{",
"var",
"expectedState",
"int32",
"\n\n",
"switch",
"newState",
"{",
"case",
"connStateIdle",
":",
"expectedState",
"=",
"connStateExpectReadyForQuery",
"\n",
"case",
"connStateExpectResponse",
":",
"expectedState",
"=",
"connStateIdle",
"\n",
"case",
"connStateExpectReadyForQuery",
":",
"expectedState",
"=",
"connStateExpectResponse",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"newState",
")",
")",
"\n",
"}",
"\n\n",
"return",
"atomic",
".",
"CompareAndSwapInt32",
"(",
"&",
"l",
".",
"connState",
",",
"expectedState",
",",
"newState",
")",
"\n",
"}"
]
| // setState advances the protocol state to newState. Returns false if moving
// to that state from the current state is not allowed. | [
"setState",
"advances",
"the",
"protocol",
"state",
"to",
"newState",
".",
"Returns",
"false",
"if",
"moving",
"to",
"that",
"state",
"from",
"the",
"current",
"state",
"is",
"not",
"allowed",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/notify.go#L112-L127 |
11,096 | square/certigo | starttls/psql/notify.go | listenerConnMain | func (l *ListenerConn) listenerConnMain() {
err := l.listenerConnLoop()
// listenerConnLoop terminated; we're done, but we still have to clean up.
// Make sure nobody tries to start any new queries by making sure the err
// pointer is set. It is important that we do not overwrite its value; a
// connection could be closed by either this goroutine or one sending on
// the connection -- whoever closes the connection is assumed to have the
// more meaningful error message (as the other one will probably get
// net.errClosed), so that goroutine sets the error we expose while the
// other error is discarded. If the connection is lost while two
// goroutines are operating on the socket, it probably doesn't matter which
// error we expose so we don't try to do anything more complex.
l.connectionLock.Lock()
if l.err == nil {
l.err = err
}
l.cn.Close()
l.connectionLock.Unlock()
// There might be a query in-flight; make sure nobody's waiting for a
// response to it, since there's not going to be one.
close(l.replyChan)
// let the listener know we're done
close(l.notificationChan)
// this ListenerConn is done
} | go | func (l *ListenerConn) listenerConnMain() {
err := l.listenerConnLoop()
// listenerConnLoop terminated; we're done, but we still have to clean up.
// Make sure nobody tries to start any new queries by making sure the err
// pointer is set. It is important that we do not overwrite its value; a
// connection could be closed by either this goroutine or one sending on
// the connection -- whoever closes the connection is assumed to have the
// more meaningful error message (as the other one will probably get
// net.errClosed), so that goroutine sets the error we expose while the
// other error is discarded. If the connection is lost while two
// goroutines are operating on the socket, it probably doesn't matter which
// error we expose so we don't try to do anything more complex.
l.connectionLock.Lock()
if l.err == nil {
l.err = err
}
l.cn.Close()
l.connectionLock.Unlock()
// There might be a query in-flight; make sure nobody's waiting for a
// response to it, since there's not going to be one.
close(l.replyChan)
// let the listener know we're done
close(l.notificationChan)
// this ListenerConn is done
} | [
"func",
"(",
"l",
"*",
"ListenerConn",
")",
"listenerConnMain",
"(",
")",
"{",
"err",
":=",
"l",
".",
"listenerConnLoop",
"(",
")",
"\n\n",
"// listenerConnLoop terminated; we're done, but we still have to clean up.",
"// Make sure nobody tries to start any new queries by making sure the err",
"// pointer is set. It is important that we do not overwrite its value; a",
"// connection could be closed by either this goroutine or one sending on",
"// the connection -- whoever closes the connection is assumed to have the",
"// more meaningful error message (as the other one will probably get",
"// net.errClosed), so that goroutine sets the error we expose while the",
"// other error is discarded. If the connection is lost while two",
"// goroutines are operating on the socket, it probably doesn't matter which",
"// error we expose so we don't try to do anything more complex.",
"l",
".",
"connectionLock",
".",
"Lock",
"(",
")",
"\n",
"if",
"l",
".",
"err",
"==",
"nil",
"{",
"l",
".",
"err",
"=",
"err",
"\n",
"}",
"\n",
"l",
".",
"cn",
".",
"Close",
"(",
")",
"\n",
"l",
".",
"connectionLock",
".",
"Unlock",
"(",
")",
"\n\n",
"// There might be a query in-flight; make sure nobody's waiting for a",
"// response to it, since there's not going to be one.",
"close",
"(",
"l",
".",
"replyChan",
")",
"\n\n",
"// let the listener know we're done",
"close",
"(",
"l",
".",
"notificationChan",
")",
"\n\n",
"// this ListenerConn is done",
"}"
]
| // This is the main routine for the goroutine receiving on the database
// connection. Most of the main logic is in listenerConnLoop. | [
"This",
"is",
"the",
"main",
"routine",
"for",
"the",
"goroutine",
"receiving",
"on",
"the",
"database",
"connection",
".",
"Most",
"of",
"the",
"main",
"logic",
"is",
"in",
"listenerConnLoop",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/notify.go#L187-L215 |
11,097 | square/certigo | starttls/psql/notify.go | Listen | func (l *ListenerConn) Listen(channel string) (bool, error) {
return l.ExecSimpleQuery("LISTEN " + QuoteIdentifier(channel))
} | go | func (l *ListenerConn) Listen(channel string) (bool, error) {
return l.ExecSimpleQuery("LISTEN " + QuoteIdentifier(channel))
} | [
"func",
"(",
"l",
"*",
"ListenerConn",
")",
"Listen",
"(",
"channel",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"l",
".",
"ExecSimpleQuery",
"(",
"\"",
"\"",
"+",
"QuoteIdentifier",
"(",
"channel",
")",
")",
"\n",
"}"
]
| // Send a LISTEN query to the server. See ExecSimpleQuery. | [
"Send",
"a",
"LISTEN",
"query",
"to",
"the",
"server",
".",
"See",
"ExecSimpleQuery",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/notify.go#L218-L220 |
11,098 | square/certigo | starttls/psql/notify.go | Ping | func (l *ListenerConn) Ping() error {
sent, err := l.ExecSimpleQuery("")
if !sent {
return err
}
if err != nil {
// shouldn't happen
panic(err)
}
return nil
} | go | func (l *ListenerConn) Ping() error {
sent, err := l.ExecSimpleQuery("")
if !sent {
return err
}
if err != nil {
// shouldn't happen
panic(err)
}
return nil
} | [
"func",
"(",
"l",
"*",
"ListenerConn",
")",
"Ping",
"(",
")",
"error",
"{",
"sent",
",",
"err",
":=",
"l",
".",
"ExecSimpleQuery",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"sent",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// shouldn't happen",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Ping the remote server to make sure it's alive. Non-nil error means the
// connection has failed and should be abandoned. | [
"Ping",
"the",
"remote",
"server",
"to",
"make",
"sure",
"it",
"s",
"alive",
".",
"Non",
"-",
"nil",
"error",
"means",
"the",
"connection",
"has",
"failed",
"and",
"should",
"be",
"abandoned",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/notify.go#L234-L244 |
11,099 | square/certigo | starttls/psql/notify.go | NewDialListener | func NewDialListener(d Dialer,
name string,
minReconnectInterval time.Duration,
maxReconnectInterval time.Duration,
eventCallback EventCallbackType) *Listener {
l := &Listener{
name: name,
minReconnectInterval: minReconnectInterval,
maxReconnectInterval: maxReconnectInterval,
dialer: d,
eventCallback: eventCallback,
channels: make(map[string]struct{}),
Notify: make(chan *Notification, 32),
}
l.reconnectCond = sync.NewCond(&l.lock)
go l.listenerMain()
return l
} | go | func NewDialListener(d Dialer,
name string,
minReconnectInterval time.Duration,
maxReconnectInterval time.Duration,
eventCallback EventCallbackType) *Listener {
l := &Listener{
name: name,
minReconnectInterval: minReconnectInterval,
maxReconnectInterval: maxReconnectInterval,
dialer: d,
eventCallback: eventCallback,
channels: make(map[string]struct{}),
Notify: make(chan *Notification, 32),
}
l.reconnectCond = sync.NewCond(&l.lock)
go l.listenerMain()
return l
} | [
"func",
"NewDialListener",
"(",
"d",
"Dialer",
",",
"name",
"string",
",",
"minReconnectInterval",
"time",
".",
"Duration",
",",
"maxReconnectInterval",
"time",
".",
"Duration",
",",
"eventCallback",
"EventCallbackType",
")",
"*",
"Listener",
"{",
"l",
":=",
"&",
"Listener",
"{",
"name",
":",
"name",
",",
"minReconnectInterval",
":",
"minReconnectInterval",
",",
"maxReconnectInterval",
":",
"maxReconnectInterval",
",",
"dialer",
":",
"d",
",",
"eventCallback",
":",
"eventCallback",
",",
"channels",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
",",
"Notify",
":",
"make",
"(",
"chan",
"*",
"Notification",
",",
"32",
")",
",",
"}",
"\n",
"l",
".",
"reconnectCond",
"=",
"sync",
".",
"NewCond",
"(",
"&",
"l",
".",
"lock",
")",
"\n\n",
"go",
"l",
".",
"listenerMain",
"(",
")",
"\n\n",
"return",
"l",
"\n",
"}"
]
| // NewDialListener is like NewListener but it takes a Dialer. | [
"NewDialListener",
"is",
"like",
"NewListener",
"but",
"it",
"takes",
"a",
"Dialer",
"."
]
| 9ce8f40ef6de69064855a1ebe32e97360ca75c9c | https://github.com/square/certigo/blob/9ce8f40ef6de69064855a1ebe32e97360ca75c9c/starttls/psql/notify.go#L433-L455 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.