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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
149,400 | vulcand/oxy | utils/netutils.go | CopyURL | func CopyURL(i *url.URL) *url.URL {
out := *i
if i.User != nil {
out.User = &(*i.User)
}
return &out
} | go | func CopyURL(i *url.URL) *url.URL {
out := *i
if i.User != nil {
out.User = &(*i.User)
}
return &out
} | [
"func",
"CopyURL",
"(",
"i",
"*",
"url",
".",
"URL",
")",
"*",
"url",
".",
"URL",
"{",
"out",
":=",
"*",
"i",
"\n",
"if",
"i",
".",
"User",
"!=",
"nil",
"{",
"out",
".",
"User",
"=",
"&",
"(",
"*",
"i",
".",
"User",
")",
"\n",
"}",
"\n",
... | // CopyURL provides update safe copy by avoiding shallow copying User field | [
"CopyURL",
"provides",
"update",
"safe",
"copy",
"by",
"avoiding",
"shallow",
"copying",
"User",
"field"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L160-L166 |
149,401 | vulcand/oxy | utils/netutils.go | CopyHeaders | func CopyHeaders(dst http.Header, src http.Header) {
for k, vv := range src {
dst[k] = append(dst[k], vv...)
}
} | go | func CopyHeaders(dst http.Header, src http.Header) {
for k, vv := range src {
dst[k] = append(dst[k], vv...)
}
} | [
"func",
"CopyHeaders",
"(",
"dst",
"http",
".",
"Header",
",",
"src",
"http",
".",
"Header",
")",
"{",
"for",
"k",
",",
"vv",
":=",
"range",
"src",
"{",
"dst",
"[",
"k",
"]",
"=",
"append",
"(",
"dst",
"[",
"k",
"]",
",",
"vv",
"...",
")",
"\... | // CopyHeaders copies http headers from source to destination, it
// does not overide, but adds multiple headers | [
"CopyHeaders",
"copies",
"http",
"headers",
"from",
"source",
"to",
"destination",
"it",
"does",
"not",
"overide",
"but",
"adds",
"multiple",
"headers"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L170-L174 |
149,402 | vulcand/oxy | utils/netutils.go | HasHeaders | func HasHeaders(names []string, headers http.Header) bool {
for _, h := range names {
if headers.Get(h) != "" {
return true
}
}
return false
} | go | func HasHeaders(names []string, headers http.Header) bool {
for _, h := range names {
if headers.Get(h) != "" {
return true
}
}
return false
} | [
"func",
"HasHeaders",
"(",
"names",
"[",
"]",
"string",
",",
"headers",
"http",
".",
"Header",
")",
"bool",
"{",
"for",
"_",
",",
"h",
":=",
"range",
"names",
"{",
"if",
"headers",
".",
"Get",
"(",
"h",
")",
"!=",
"\"",
"\"",
"{",
"return",
"true... | // HasHeaders determines whether any of the header names is present in the http headers | [
"HasHeaders",
"determines",
"whether",
"any",
"of",
"the",
"header",
"names",
"is",
"present",
"in",
"the",
"http",
"headers"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/utils/netutils.go#L177-L184 |
149,403 | vulcand/oxy | cbreaker/effect.go | NewWebhookSideEffectsWithLogger | func NewWebhookSideEffectsWithLogger(w Webhook, l *log.Logger) (*WebhookSideEffect, error) {
if w.Method == "" {
return nil, fmt.Errorf("Supply method")
}
_, err := url.Parse(w.URL)
if err != nil {
return nil, err
}
return &WebhookSideEffect{w: w, log: l}, nil
} | go | func NewWebhookSideEffectsWithLogger(w Webhook, l *log.Logger) (*WebhookSideEffect, error) {
if w.Method == "" {
return nil, fmt.Errorf("Supply method")
}
_, err := url.Parse(w.URL)
if err != nil {
return nil, err
}
return &WebhookSideEffect{w: w, log: l}, nil
} | [
"func",
"NewWebhookSideEffectsWithLogger",
"(",
"w",
"Webhook",
",",
"l",
"*",
"log",
".",
"Logger",
")",
"(",
"*",
"WebhookSideEffect",
",",
"error",
")",
"{",
"if",
"w",
".",
"Method",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf"... | // NewWebhookSideEffectsWithLogger creates a new WebhookSideEffect | [
"NewWebhookSideEffectsWithLogger",
"creates",
"a",
"new",
"WebhookSideEffect"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/effect.go#L38-L48 |
149,404 | vulcand/oxy | cbreaker/effect.go | Exec | func (w *WebhookSideEffect) Exec() error {
r, err := http.NewRequest(w.w.Method, w.w.URL, w.getBody())
if err != nil {
return err
}
if len(w.w.Headers) != 0 {
utils.CopyHeaders(r.Header, w.w.Headers)
}
if len(w.w.Form) != 0 {
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
re, err := h... | go | func (w *WebhookSideEffect) Exec() error {
r, err := http.NewRequest(w.w.Method, w.w.URL, w.getBody())
if err != nil {
return err
}
if len(w.w.Headers) != 0 {
utils.CopyHeaders(r.Header, w.w.Headers)
}
if len(w.w.Form) != 0 {
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
re, err := h... | [
"func",
"(",
"w",
"*",
"WebhookSideEffect",
")",
"Exec",
"(",
")",
"error",
"{",
"r",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"w",
".",
"w",
".",
"Method",
",",
"w",
".",
"w",
".",
"URL",
",",
"w",
".",
"getBody",
"(",
")",
")",
"\n... | // Exec execute the side effect | [
"Exec",
"execute",
"the",
"side",
"effect"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/cbreaker/effect.go#L66-L90 |
149,405 | vulcand/oxy | memmetrics/counter.go | CounterClock | func CounterClock(c timetools.TimeProvider) rcOptSetter {
return func(r *RollingCounter) error {
r.clock = c
return nil
}
} | go | func CounterClock(c timetools.TimeProvider) rcOptSetter {
return func(r *RollingCounter) error {
r.clock = c
return nil
}
} | [
"func",
"CounterClock",
"(",
"c",
"timetools",
".",
"TimeProvider",
")",
"rcOptSetter",
"{",
"return",
"func",
"(",
"r",
"*",
"RollingCounter",
")",
"error",
"{",
"r",
".",
"clock",
"=",
"c",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // CounterClock defines a counter clock | [
"CounterClock",
"defines",
"a",
"counter",
"clock"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L13-L18 |
149,406 | vulcand/oxy | memmetrics/counter.go | NewCounter | func NewCounter(buckets int, resolution time.Duration, options ...rcOptSetter) (*RollingCounter, error) {
if buckets <= 0 {
return nil, fmt.Errorf("Buckets should be >= 0")
}
if resolution < time.Second {
return nil, fmt.Errorf("Resolution should be larger than a second")
}
rc := &RollingCounter{
lastBucket... | go | func NewCounter(buckets int, resolution time.Duration, options ...rcOptSetter) (*RollingCounter, error) {
if buckets <= 0 {
return nil, fmt.Errorf("Buckets should be >= 0")
}
if resolution < time.Second {
return nil, fmt.Errorf("Resolution should be larger than a second")
}
rc := &RollingCounter{
lastBucket... | [
"func",
"NewCounter",
"(",
"buckets",
"int",
",",
"resolution",
"time",
".",
"Duration",
",",
"options",
"...",
"rcOptSetter",
")",
"(",
"*",
"RollingCounter",
",",
"error",
")",
"{",
"if",
"buckets",
"<=",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"... | // NewCounter creates a counter with fixed amount of buckets that are rotated every resolution period.
// E.g. 10 buckets with 1 second means that every new second the bucket is refreshed, so it maintains 10 second rolling window.
// By default creates a bucket with 10 buckets and 1 second resolution | [
"NewCounter",
"creates",
"a",
"counter",
"with",
"fixed",
"amount",
"of",
"buckets",
"that",
"are",
"rotated",
"every",
"resolution",
"period",
".",
"E",
".",
"g",
".",
"10",
"buckets",
"with",
"1",
"second",
"means",
"that",
"every",
"new",
"second",
"the... | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L33-L59 |
149,407 | vulcand/oxy | memmetrics/counter.go | Append | func (c *RollingCounter) Append(o *RollingCounter) error {
c.Inc(int(o.Count()))
return nil
} | go | func (c *RollingCounter) Append(o *RollingCounter) error {
c.Inc(int(o.Count()))
return nil
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"Append",
"(",
"o",
"*",
"RollingCounter",
")",
"error",
"{",
"c",
".",
"Inc",
"(",
"int",
"(",
"o",
".",
"Count",
"(",
")",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Append append a counter | [
"Append",
"append",
"a",
"counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L62-L65 |
149,408 | vulcand/oxy | memmetrics/counter.go | Clone | func (c *RollingCounter) Clone() *RollingCounter {
c.cleanup()
other := &RollingCounter{
resolution: c.resolution,
values: make([]int, len(c.values)),
clock: c.clock,
lastBucket: c.lastBucket,
lastUpdated: c.lastUpdated,
}
copy(other.values, c.values)
return other
} | go | func (c *RollingCounter) Clone() *RollingCounter {
c.cleanup()
other := &RollingCounter{
resolution: c.resolution,
values: make([]int, len(c.values)),
clock: c.clock,
lastBucket: c.lastBucket,
lastUpdated: c.lastUpdated,
}
copy(other.values, c.values)
return other
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"Clone",
"(",
")",
"*",
"RollingCounter",
"{",
"c",
".",
"cleanup",
"(",
")",
"\n",
"other",
":=",
"&",
"RollingCounter",
"{",
"resolution",
":",
"c",
".",
"resolution",
",",
"values",
":",
"make",
"(",
"... | // Clone clone a counter | [
"Clone",
"clone",
"a",
"counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L68-L79 |
149,409 | vulcand/oxy | memmetrics/counter.go | Reset | func (c *RollingCounter) Reset() {
c.lastBucket = -1
c.countedBuckets = 0
c.lastUpdated = time.Time{}
for i := range c.values {
c.values[i] = 0
}
} | go | func (c *RollingCounter) Reset() {
c.lastBucket = -1
c.countedBuckets = 0
c.lastUpdated = time.Time{}
for i := range c.values {
c.values[i] = 0
}
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"Reset",
"(",
")",
"{",
"c",
".",
"lastBucket",
"=",
"-",
"1",
"\n",
"c",
".",
"countedBuckets",
"=",
"0",
"\n",
"c",
".",
"lastUpdated",
"=",
"time",
".",
"Time",
"{",
"}",
"\n",
"for",
"i",
":=",
... | // Reset reset a counter | [
"Reset",
"reset",
"a",
"counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L82-L89 |
149,410 | vulcand/oxy | memmetrics/counter.go | WindowSize | func (c *RollingCounter) WindowSize() time.Duration {
return time.Duration(len(c.values)) * c.resolution
} | go | func (c *RollingCounter) WindowSize() time.Duration {
return time.Duration(len(c.values)) * c.resolution
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"WindowSize",
"(",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Duration",
"(",
"len",
"(",
"c",
".",
"values",
")",
")",
"*",
"c",
".",
"resolution",
"\n",
"}"
] | // WindowSize gets windows size | [
"WindowSize",
"gets",
"windows",
"size"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L113-L115 |
149,411 | vulcand/oxy | memmetrics/counter.go | Inc | func (c *RollingCounter) Inc(v int) {
c.cleanup()
c.incBucketValue(v)
} | go | func (c *RollingCounter) Inc(v int) {
c.cleanup()
c.incBucketValue(v)
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"Inc",
"(",
"v",
"int",
")",
"{",
"c",
".",
"cleanup",
"(",
")",
"\n",
"c",
".",
"incBucketValue",
"(",
"v",
")",
"\n",
"}"
] | // Inc increment counter | [
"Inc",
"increment",
"counter"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L118-L121 |
149,412 | vulcand/oxy | memmetrics/counter.go | getBucket | func (c *RollingCounter) getBucket(t time.Time) int {
return int(t.Truncate(c.resolution).Unix() % int64(len(c.values)))
} | go | func (c *RollingCounter) getBucket(t time.Time) int {
return int(t.Truncate(c.resolution).Unix() % int64(len(c.values)))
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"getBucket",
"(",
"t",
"time",
".",
"Time",
")",
"int",
"{",
"return",
"int",
"(",
"t",
".",
"Truncate",
"(",
"c",
".",
"resolution",
")",
".",
"Unix",
"(",
")",
"%",
"int64",
"(",
"len",
"(",
"c",
... | // Returns the number in the moving window bucket that this slot occupies | [
"Returns",
"the",
"number",
"in",
"the",
"moving",
"window",
"bucket",
"that",
"this",
"slot",
"occupies"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L140-L142 |
149,413 | vulcand/oxy | memmetrics/counter.go | cleanup | func (c *RollingCounter) cleanup() {
now := c.clock.UtcNow()
for i := 0; i < len(c.values); i++ {
now = now.Add(time.Duration(-1*i) * c.resolution)
if now.Truncate(c.resolution).After(c.lastUpdated.Truncate(c.resolution)) {
c.values[c.getBucket(now)] = 0
} else {
break
}
}
} | go | func (c *RollingCounter) cleanup() {
now := c.clock.UtcNow()
for i := 0; i < len(c.values); i++ {
now = now.Add(time.Duration(-1*i) * c.resolution)
if now.Truncate(c.resolution).After(c.lastUpdated.Truncate(c.resolution)) {
c.values[c.getBucket(now)] = 0
} else {
break
}
}
} | [
"func",
"(",
"c",
"*",
"RollingCounter",
")",
"cleanup",
"(",
")",
"{",
"now",
":=",
"c",
".",
"clock",
".",
"UtcNow",
"(",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"c",
".",
"values",
")",
";",
"i",
"++",
"{",
"now",
"=... | // Reset buckets that were not updated | [
"Reset",
"buckets",
"that",
"were",
"not",
"updated"
] | c34b0c501e43223bc816ac9b40b0ac29c44c8952 | https://github.com/vulcand/oxy/blob/c34b0c501e43223bc816ac9b40b0ac29c44c8952/memmetrics/counter.go#L145-L155 |
149,414 | rs/xid | id.go | readMachineID | func readMachineID() []byte {
id := make([]byte, 3)
hid, err := readPlatformMachineID()
if err != nil || len(hid) == 0 {
hid, err = os.Hostname()
}
if err == nil && len(hid) != 0 {
hw := md5.New()
hw.Write([]byte(hid))
copy(id, hw.Sum(nil))
} else {
// Fallback to rand number if machine id can't be gath... | go | func readMachineID() []byte {
id := make([]byte, 3)
hid, err := readPlatformMachineID()
if err != nil || len(hid) == 0 {
hid, err = os.Hostname()
}
if err == nil && len(hid) != 0 {
hw := md5.New()
hw.Write([]byte(hid))
copy(id, hw.Sum(nil))
} else {
// Fallback to rand number if machine id can't be gath... | [
"func",
"readMachineID",
"(",
")",
"[",
"]",
"byte",
"{",
"id",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"3",
")",
"\n",
"hid",
",",
"err",
":=",
"readPlatformMachineID",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"len",
"(",
"hid",
")",
... | // readMachineId generates machine id and puts it into the machineId global
// variable. If this function fails to get the hostname, it will cause
// a runtime error. | [
"readMachineId",
"generates",
"machine",
"id",
"and",
"puts",
"it",
"into",
"the",
"machineId",
"global",
"variable",
".",
"If",
"this",
"function",
"fails",
"to",
"get",
"the",
"hostname",
"it",
"will",
"cause",
"a",
"runtime",
"error",
"."
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L117-L134 |
149,415 | rs/xid | id.go | randInt | func randInt() uint32 {
b := make([]byte, 3)
if _, err := rand.Reader.Read(b); err != nil {
panic(fmt.Errorf("xid: cannot generate random number: %v;", err))
}
return uint32(b[0])<<16 | uint32(b[1])<<8 | uint32(b[2])
} | go | func randInt() uint32 {
b := make([]byte, 3)
if _, err := rand.Reader.Read(b); err != nil {
panic(fmt.Errorf("xid: cannot generate random number: %v;", err))
}
return uint32(b[0])<<16 | uint32(b[1])<<8 | uint32(b[2])
} | [
"func",
"randInt",
"(",
")",
"uint32",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"3",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"rand",
".",
"Reader",
".",
"Read",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".... | // randInt generates a random uint32 | [
"randInt",
"generates",
"a",
"random",
"uint32"
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L137-L143 |
149,416 | rs/xid | id.go | NewWithTime | func NewWithTime(t time.Time) ID {
var id ID
// Timestamp, 4 bytes, big endian
binary.BigEndian.PutUint32(id[:], uint32(t.Unix()))
// Machine, first 3 bytes of md5(hostname)
id[4] = machineID[0]
id[5] = machineID[1]
id[6] = machineID[2]
// Pid, 2 bytes, specs don't specify endianness, but we use big endian.
id... | go | func NewWithTime(t time.Time) ID {
var id ID
// Timestamp, 4 bytes, big endian
binary.BigEndian.PutUint32(id[:], uint32(t.Unix()))
// Machine, first 3 bytes of md5(hostname)
id[4] = machineID[0]
id[5] = machineID[1]
id[6] = machineID[2]
// Pid, 2 bytes, specs don't specify endianness, but we use big endian.
id... | [
"func",
"NewWithTime",
"(",
"t",
"time",
".",
"Time",
")",
"ID",
"{",
"var",
"id",
"ID",
"\n",
"// Timestamp, 4 bytes, big endian",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"id",
"[",
":",
"]",
",",
"uint32",
"(",
"t",
".",
"Unix",
"(",
")",
... | // NewWithTime generates a globally unique ID with the passed in time | [
"NewWithTime",
"generates",
"a",
"globally",
"unique",
"ID",
"with",
"the",
"passed",
"in",
"time"
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L151-L168 |
149,417 | rs/xid | id.go | FromString | func FromString(id string) (ID, error) {
i := &ID{}
err := i.UnmarshalText([]byte(id))
return *i, err
} | go | func FromString(id string) (ID, error) {
i := &ID{}
err := i.UnmarshalText([]byte(id))
return *i, err
} | [
"func",
"FromString",
"(",
"id",
"string",
")",
"(",
"ID",
",",
"error",
")",
"{",
"i",
":=",
"&",
"ID",
"{",
"}",
"\n",
"err",
":=",
"i",
".",
"UnmarshalText",
"(",
"[",
"]",
"byte",
"(",
"id",
")",
")",
"\n",
"return",
"*",
"i",
",",
"err",... | // FromString reads an ID from its string representation | [
"FromString",
"reads",
"an",
"ID",
"from",
"its",
"string",
"representation"
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L171-L175 |
149,418 | rs/xid | id.go | encode | func encode(dst, id []byte) {
_ = dst[19]
_ = id[11]
dst[19] = encoding[(id[11]<<4)&0x1F]
dst[18] = encoding[(id[11]>>1)&0x1F]
dst[17] = encoding[(id[11]>>6)&0x1F|(id[10]<<2)&0x1F]
dst[16] = encoding[id[10]>>3]
dst[15] = encoding[id[9]&0x1F]
dst[14] = encoding[(id[9]>>5)|(id[8]<<3)&0x1F]
dst[13] = encoding[(i... | go | func encode(dst, id []byte) {
_ = dst[19]
_ = id[11]
dst[19] = encoding[(id[11]<<4)&0x1F]
dst[18] = encoding[(id[11]>>1)&0x1F]
dst[17] = encoding[(id[11]>>6)&0x1F|(id[10]<<2)&0x1F]
dst[16] = encoding[id[10]>>3]
dst[15] = encoding[id[9]&0x1F]
dst[14] = encoding[(id[9]>>5)|(id[8]<<3)&0x1F]
dst[13] = encoding[(i... | [
"func",
"encode",
"(",
"dst",
",",
"id",
"[",
"]",
"byte",
")",
"{",
"_",
"=",
"dst",
"[",
"19",
"]",
"\n",
"_",
"=",
"id",
"[",
"11",
"]",
"\n\n",
"dst",
"[",
"19",
"]",
"=",
"encoding",
"[",
"(",
"id",
"[",
"11",
"]",
"<<",
"4",
")",
... | // encode by unrolling the stdlib base32 algorithm + removing all safe checks | [
"encode",
"by",
"unrolling",
"the",
"stdlib",
"base32",
"algorithm",
"+",
"removing",
"all",
"safe",
"checks"
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L203-L227 |
149,419 | rs/xid | id.go | decode | func decode(id *ID, src []byte) {
_ = src[19]
_ = id[11]
id[11] = dec[src[17]]<<6 | dec[src[18]]<<1 | dec[src[19]]>>4
id[10] = dec[src[16]]<<3 | dec[src[17]]>>2
id[9] = dec[src[14]]<<5 | dec[src[15]]
id[8] = dec[src[12]]<<7 | dec[src[13]]<<2 | dec[src[14]]>>3
id[7] = dec[src[11]]<<4 | dec[src[12]]>>1
id[6] = d... | go | func decode(id *ID, src []byte) {
_ = src[19]
_ = id[11]
id[11] = dec[src[17]]<<6 | dec[src[18]]<<1 | dec[src[19]]>>4
id[10] = dec[src[16]]<<3 | dec[src[17]]>>2
id[9] = dec[src[14]]<<5 | dec[src[15]]
id[8] = dec[src[12]]<<7 | dec[src[13]]<<2 | dec[src[14]]>>3
id[7] = dec[src[11]]<<4 | dec[src[12]]>>1
id[6] = d... | [
"func",
"decode",
"(",
"id",
"*",
"ID",
",",
"src",
"[",
"]",
"byte",
")",
"{",
"_",
"=",
"src",
"[",
"19",
"]",
"\n",
"_",
"=",
"id",
"[",
"11",
"]",
"\n\n",
"id",
"[",
"11",
"]",
"=",
"dec",
"[",
"src",
"[",
"17",
"]",
"]",
"<<",
"6",... | // decode by unrolling the stdlib base32 algorithm + removing all safe checks | [
"decode",
"by",
"unrolling",
"the",
"stdlib",
"base32",
"algorithm",
"+",
"removing",
"all",
"safe",
"checks"
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L254-L270 |
149,420 | rs/xid | id.go | Time | func (id ID) Time() time.Time {
// First 4 bytes of ObjectId is 32-bit big-endian seconds from epoch.
secs := int64(binary.BigEndian.Uint32(id[0:4]))
return time.Unix(secs, 0)
} | go | func (id ID) Time() time.Time {
// First 4 bytes of ObjectId is 32-bit big-endian seconds from epoch.
secs := int64(binary.BigEndian.Uint32(id[0:4]))
return time.Unix(secs, 0)
} | [
"func",
"(",
"id",
"ID",
")",
"Time",
"(",
")",
"time",
".",
"Time",
"{",
"// First 4 bytes of ObjectId is 32-bit big-endian seconds from epoch.",
"secs",
":=",
"int64",
"(",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"id",
"[",
"0",
":",
"4",
"]",
")",... | // Time returns the timestamp part of the id.
// It's a runtime error to call this method with an invalid id. | [
"Time",
"returns",
"the",
"timestamp",
"part",
"of",
"the",
"id",
".",
"It",
"s",
"a",
"runtime",
"error",
"to",
"call",
"this",
"method",
"with",
"an",
"invalid",
"id",
"."
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L274-L278 |
149,421 | rs/xid | id.go | Counter | func (id ID) Counter() int32 {
b := id[9:12]
// Counter is stored as big-endian 3-byte value
return int32(uint32(b[0])<<16 | uint32(b[1])<<8 | uint32(b[2]))
} | go | func (id ID) Counter() int32 {
b := id[9:12]
// Counter is stored as big-endian 3-byte value
return int32(uint32(b[0])<<16 | uint32(b[1])<<8 | uint32(b[2]))
} | [
"func",
"(",
"id",
"ID",
")",
"Counter",
"(",
")",
"int32",
"{",
"b",
":=",
"id",
"[",
"9",
":",
"12",
"]",
"\n",
"// Counter is stored as big-endian 3-byte value",
"return",
"int32",
"(",
"uint32",
"(",
"b",
"[",
"0",
"]",
")",
"<<",
"16",
"|",
"uin... | // Counter returns the incrementing value part of the id.
// It's a runtime error to call this method with an invalid id. | [
"Counter",
"returns",
"the",
"incrementing",
"value",
"part",
"of",
"the",
"id",
".",
"It",
"s",
"a",
"runtime",
"error",
"to",
"call",
"this",
"method",
"with",
"an",
"invalid",
"id",
"."
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L294-L298 |
149,422 | rs/xid | id.go | FromBytes | func FromBytes(b []byte) (ID, error) {
var id ID
if len(b) != rawLen {
return id, ErrInvalidID
}
copy(id[:], b)
return id, nil
} | go | func FromBytes(b []byte) (ID, error) {
var id ID
if len(b) != rawLen {
return id, ErrInvalidID
}
copy(id[:], b)
return id, nil
} | [
"func",
"FromBytes",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"ID",
",",
"error",
")",
"{",
"var",
"id",
"ID",
"\n",
"if",
"len",
"(",
"b",
")",
"!=",
"rawLen",
"{",
"return",
"id",
",",
"ErrInvalidID",
"\n",
"}",
"\n",
"copy",
"(",
"id",
"[",
"... | // FromBytes convert the byte array representation of `ID` back to `ID` | [
"FromBytes",
"convert",
"the",
"byte",
"array",
"representation",
"of",
"ID",
"back",
"to",
"ID"
] | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L340-L347 |
149,423 | rs/xid | id.go | Compare | func (id ID) Compare(other ID) int {
return bytes.Compare(id[:], other[:])
} | go | func (id ID) Compare(other ID) int {
return bytes.Compare(id[:], other[:])
} | [
"func",
"(",
"id",
"ID",
")",
"Compare",
"(",
"other",
"ID",
")",
"int",
"{",
"return",
"bytes",
".",
"Compare",
"(",
"id",
"[",
":",
"]",
",",
"other",
"[",
":",
"]",
")",
"\n",
"}"
] | // Compare returns an integer comparing two IDs. It behaves just like `bytes.Compare`.
// The result will be 0 if two IDs are identical, -1 if current id is less than the other one,
// and 1 if current id is greater than the other. | [
"Compare",
"returns",
"an",
"integer",
"comparing",
"two",
"IDs",
".",
"It",
"behaves",
"just",
"like",
"bytes",
".",
"Compare",
".",
"The",
"result",
"will",
"be",
"0",
"if",
"two",
"IDs",
"are",
"identical",
"-",
"1",
"if",
"current",
"id",
"is",
"le... | ba6f703301d6c14cbc05faa3b512058f2304e16c | https://github.com/rs/xid/blob/ba6f703301d6c14cbc05faa3b512058f2304e16c/id.go#L352-L354 |
149,424 | crewjam/saml | xmlenc/fuzz.go | Fuzz | func Fuzz(data []byte) int {
doc := etree.NewDocument()
if err := doc.ReadFromBytes(data); err != nil {
return 0
}
if doc.Root() == nil {
return 0
}
if _, err := Decrypt(testKey, doc.Root()); err != nil {
return 0
}
return 1
} | go | func Fuzz(data []byte) int {
doc := etree.NewDocument()
if err := doc.ReadFromBytes(data); err != nil {
return 0
}
if doc.Root() == nil {
return 0
}
if _, err := Decrypt(testKey, doc.Root()); err != nil {
return 0
}
return 1
} | [
"func",
"Fuzz",
"(",
"data",
"[",
"]",
"byte",
")",
"int",
"{",
"doc",
":=",
"etree",
".",
"NewDocument",
"(",
")",
"\n",
"if",
"err",
":=",
"doc",
".",
"ReadFromBytes",
"(",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
... | // Fuzz is the go-fuzz fuzzing function | [
"Fuzz",
"is",
"the",
"go",
"-",
"fuzz",
"fuzzing",
"function"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/xmlenc/fuzz.go#L36-L49 |
149,425 | crewjam/saml | samlidp/session.go | sendLoginForm | func (s *Server) sendLoginForm(w http.ResponseWriter, r *http.Request, req *saml.IdpAuthnRequest, toast string) {
tmpl := template.Must(template.New("saml-post-form").Parse(`` +
`<html>` +
`<p>{{.Toast}}</p>` +
`<form method="post" action="{{.URL}}">` +
`<input type="text" name="user" placeholder="user" value=... | go | func (s *Server) sendLoginForm(w http.ResponseWriter, r *http.Request, req *saml.IdpAuthnRequest, toast string) {
tmpl := template.Must(template.New("saml-post-form").Parse(`` +
`<html>` +
`<p>{{.Toast}}</p>` +
`<form method="post" action="{{.URL}}">` +
`<input type="text" name="user" placeholder="user" value=... | [
"func",
"(",
"s",
"*",
"Server",
")",
"sendLoginForm",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"req",
"*",
"saml",
".",
"IdpAuthnRequest",
",",
"toast",
"string",
")",
"{",
"tmpl",
":=",
"template",
".",
"... | // sendLoginForm produces a form which requests a username and password and directs the user
// back to the IDP authorize URL to restart the SAML login flow, this time establishing a
// session based on the credentials that were provided. | [
"sendLoginForm",
"produces",
"a",
"form",
"which",
"requests",
"a",
"username",
"and",
"password",
"and",
"directs",
"the",
"user",
"back",
"to",
"the",
"IDP",
"authorize",
"URL",
"to",
"restart",
"the",
"SAML",
"login",
"flow",
"this",
"time",
"establishing",... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlidp/session.go#L102-L129 |
149,426 | crewjam/saml | samlsp/token.go | Get | func (a Attributes) Get(key string) string {
if a == nil {
return ""
}
v := a[key]
if len(v) == 0 {
return ""
}
return v[0]
} | go | func (a Attributes) Get(key string) string {
if a == nil {
return ""
}
v := a[key]
if len(v) == 0 {
return ""
}
return v[0]
} | [
"func",
"(",
"a",
"Attributes",
")",
"Get",
"(",
"key",
"string",
")",
"string",
"{",
"if",
"a",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"v",
":=",
"a",
"[",
"key",
"]",
"\n",
"if",
"len",
"(",
"v",
")",
"==",
"0",
"{",
"re... | // Get returns the first attribute named `key` or an empty string if
// no such attributes is present. | [
"Get",
"returns",
"the",
"first",
"attribute",
"named",
"key",
"or",
"an",
"empty",
"string",
"if",
"no",
"such",
"attributes",
"is",
"present",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/token.go#L20-L29 |
149,427 | crewjam/saml | samlsp/token.go | Token | func Token(ctx context.Context) *AuthorizationToken {
v := ctx.Value(tokenIndex)
if v == nil {
return nil
}
return v.(*AuthorizationToken)
} | go | func Token(ctx context.Context) *AuthorizationToken {
v := ctx.Value(tokenIndex)
if v == nil {
return nil
}
return v.(*AuthorizationToken)
} | [
"func",
"Token",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"AuthorizationToken",
"{",
"v",
":=",
"ctx",
".",
"Value",
"(",
"tokenIndex",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"v",
".",
"(",
"*",
... | // Token returns the token associated with ctx, or nil if no token are associated | [
"Token",
"returns",
"the",
"token",
"associated",
"with",
"ctx",
"or",
"nil",
"if",
"no",
"token",
"are",
"associated"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/token.go#L36-L42 |
149,428 | crewjam/saml | samlsp/token.go | WithToken | func WithToken(ctx context.Context, token *AuthorizationToken) context.Context {
return context.WithValue(ctx, tokenIndex, token)
} | go | func WithToken(ctx context.Context, token *AuthorizationToken) context.Context {
return context.WithValue(ctx, tokenIndex, token)
} | [
"func",
"WithToken",
"(",
"ctx",
"context",
".",
"Context",
",",
"token",
"*",
"AuthorizationToken",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"tokenIndex",
",",
"token",
")",
"\n",
"}"
] | // WithToken returns a new context with token associated | [
"WithToken",
"returns",
"a",
"new",
"context",
"with",
"token",
"associated"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/token.go#L45-L47 |
149,429 | crewjam/saml | samlidp/memory_store.go | Get | func (s *MemoryStore) Get(key string, value interface{}) error {
s.mu.RLock()
defer s.mu.RUnlock()
v, ok := s.data[key]
if !ok {
return ErrNotFound
}
return json.Unmarshal([]byte(v), value)
} | go | func (s *MemoryStore) Get(key string, value interface{}) error {
s.mu.RLock()
defer s.mu.RUnlock()
v, ok := s.data[key]
if !ok {
return ErrNotFound
}
return json.Unmarshal([]byte(v), value)
} | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"Get",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"v",
",",
... | // Get fetches the data stored in `key` and unmarshals it into `value`. | [
"Get",
"fetches",
"the",
"data",
"stored",
"in",
"key",
"and",
"unmarshals",
"it",
"into",
"value",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlidp/memory_store.go#L17-L26 |
149,430 | crewjam/saml | samlidp/memory_store.go | Put | func (s *MemoryStore) Put(key string, value interface{}) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.data == nil {
s.data = map[string]string{}
}
buf, err := json.Marshal(value)
if err != nil {
return err
}
s.data[key] = string(buf)
return nil
} | go | func (s *MemoryStore) Put(key string, value interface{}) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.data == nil {
s.data = map[string]string{}
}
buf, err := json.Marshal(value)
if err != nil {
return err
}
s.data[key] = string(buf)
return nil
} | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"Put",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"s",
".... | // Put marshals `value` and stores it in `key`. | [
"Put",
"marshals",
"value",
"and",
"stores",
"it",
"in",
"key",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlidp/memory_store.go#L29-L42 |
149,431 | crewjam/saml | samlidp/memory_store.go | Delete | func (s *MemoryStore) Delete(key string) error {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.data, key)
return nil
} | go | func (s *MemoryStore) Delete(key string) error {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.data, key)
return nil
} | [
"func",
"(",
"s",
"*",
"MemoryStore",
")",
"Delete",
"(",
"key",
"string",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"s",
".",
"data",
",",
"key",
")... | // Delete removes `key` | [
"Delete",
"removes",
"key"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlidp/memory_store.go#L45-L50 |
149,432 | crewjam/saml | example/service.go | CreateLink | func CreateLink(c web.C, w http.ResponseWriter, r *http.Request) {
account := r.Header.Get("X-Remote-User")
l := Link{
ShortLink: uniuri.New(),
Target: r.FormValue("t"),
Owner: account,
}
links[l.ShortLink] = l
fmt.Fprintf(w, "%s\n", l.ShortLink)
return
} | go | func CreateLink(c web.C, w http.ResponseWriter, r *http.Request) {
account := r.Header.Get("X-Remote-User")
l := Link{
ShortLink: uniuri.New(),
Target: r.FormValue("t"),
Owner: account,
}
links[l.ShortLink] = l
fmt.Fprintf(w, "%s\n", l.ShortLink)
return
} | [
"func",
"CreateLink",
"(",
"c",
"web",
".",
"C",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"account",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"l",
":=",
"Link",
"{",
"Sho... | // CreateLink handles requests to create links | [
"CreateLink",
"handles",
"requests",
"to",
"create",
"links"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/example/service.go#L35-L46 |
149,433 | crewjam/saml | example/service.go | ServeLink | func ServeLink(c web.C, w http.ResponseWriter, r *http.Request) {
l, ok := links[strings.TrimPrefix(r.URL.Path, "/")]
if !ok {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
http.Redirect(w, r, l.Target, http.StatusFound)
return
} | go | func ServeLink(c web.C, w http.ResponseWriter, r *http.Request) {
l, ok := links[strings.TrimPrefix(r.URL.Path, "/")]
if !ok {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
http.Redirect(w, r, l.Target, http.StatusFound)
return
} | [
"func",
"ServeLink",
"(",
"c",
"web",
".",
"C",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"l",
",",
"ok",
":=",
"links",
"[",
"strings",
".",
"TrimPrefix",
"(",
"r",
".",
"URL",
".",
"Path",
",",
... | // ServeLink handles requests to redirect to a link | [
"ServeLink",
"handles",
"requests",
"to",
"redirect",
"to",
"a",
"link"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/example/service.go#L49-L57 |
149,434 | crewjam/saml | example/service.go | ListLinks | func ListLinks(c web.C, w http.ResponseWriter, r *http.Request) {
account := r.Header.Get("X-Remote-User")
for _, l := range links {
if l.Owner == account {
fmt.Fprintf(w, "%s\n", l.ShortLink)
}
}
} | go | func ListLinks(c web.C, w http.ResponseWriter, r *http.Request) {
account := r.Header.Get("X-Remote-User")
for _, l := range links {
if l.Owner == account {
fmt.Fprintf(w, "%s\n", l.ShortLink)
}
}
} | [
"func",
"ListLinks",
"(",
"c",
"web",
".",
"C",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"account",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"l",
":=",
... | // ListLinks returns a list of the current user's links | [
"ListLinks",
"returns",
"a",
"list",
"of",
"the",
"current",
"user",
"s",
"links"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/example/service.go#L60-L67 |
149,435 | crewjam/saml | schema.go | Element | func (r *AuthnRequest) Element() *etree.Element {
el := etree.NewElement("samlp:AuthnRequest")
el.CreateAttr("xmlns:saml", "urn:oasis:names:tc:SAML:2.0:assertion")
el.CreateAttr("xmlns:samlp", "urn:oasis:names:tc:SAML:2.0:protocol")
el.CreateAttr("ID", r.ID)
el.CreateAttr("Version", r.Version)
el.CreateAttr("Issu... | go | func (r *AuthnRequest) Element() *etree.Element {
el := etree.NewElement("samlp:AuthnRequest")
el.CreateAttr("xmlns:saml", "urn:oasis:names:tc:SAML:2.0:assertion")
el.CreateAttr("xmlns:samlp", "urn:oasis:names:tc:SAML:2.0:protocol")
el.CreateAttr("ID", r.ID)
el.CreateAttr("Version", r.Version)
el.CreateAttr("Issu... | [
"func",
"(",
"r",
"*",
"AuthnRequest",
")",
"Element",
"(",
")",
"*",
"etree",
".",
"Element",
"{",
"el",
":=",
"etree",
".",
"NewElement",
"(",
"\"",
"\"",
")",
"\n",
"el",
".",
"CreateAttr",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"el",
... | // Element returns an etree.Element representing the object
// Element returns an etree.Element representing the object in XML form. | [
"Element",
"returns",
"an",
"etree",
".",
"Element",
"representing",
"the",
"object",
"Element",
"returns",
"an",
"etree",
".",
"Element",
"representing",
"the",
"object",
"in",
"XML",
"form",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/schema.go#L44-L100 |
149,436 | crewjam/saml | samlsp/middleware.go | ServeHTTP | func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == m.ServiceProvider.MetadataURL.Path {
buf, _ := xml.MarshalIndent(m.ServiceProvider.Metadata(), "", " ")
w.Header().Set("Content-Type", "application/samlmetadata+xml")
w.Write(buf)
return
}
if r.URL.Path == m.ServicePr... | go | func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == m.ServiceProvider.MetadataURL.Path {
buf, _ := xml.MarshalIndent(m.ServiceProvider.Metadata(), "", " ")
w.Header().Set("Content-Type", "application/samlmetadata+xml")
w.Write(buf)
return
}
if r.URL.Path == m.ServicePr... | [
"func",
"(",
"m",
"*",
"Middleware",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"r",
".",
"URL",
".",
"Path",
"==",
"m",
".",
"ServiceProvider",
".",
"MetadataURL",
".",
"Path",
... | // ServeHTTP implements http.Handler and serves the SAML-specific HTTP endpoints
// on the URIs specified by m.ServiceProvider.MetadataURL and
// m.ServiceProvider.AcsURL. | [
"ServeHTTP",
"implements",
"http",
".",
"Handler",
"and",
"serves",
"the",
"SAML",
"-",
"specific",
"HTTP",
"endpoints",
"on",
"the",
"URIs",
"specified",
"by",
"m",
".",
"ServiceProvider",
".",
"MetadataURL",
"and",
"m",
".",
"ServiceProvider",
".",
"AcsURL",... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/middleware.go#L67-L92 |
149,437 | crewjam/saml | samlsp/middleware.go | RequireAccount | func (m *Middleware) RequireAccount(handler http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if token := m.GetAuthorizationToken(r); token != nil {
r = r.WithContext(WithToken(r.Context(), token))
handler.ServeHTTP(w, r)
return
}
m.RequireAccountHandler(w, r)
}
return ... | go | func (m *Middleware) RequireAccount(handler http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if token := m.GetAuthorizationToken(r); token != nil {
r = r.WithContext(WithToken(r.Context(), token))
handler.ServeHTTP(w, r)
return
}
m.RequireAccountHandler(w, r)
}
return ... | [
"func",
"(",
"m",
"*",
"Middleware",
")",
"RequireAccount",
"(",
"handler",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"fn",
":=",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
... | // RequireAccount is HTTP middleware that requires that each request be
// associated with a valid session. If the request is not associated with a valid
// session, then rather than serve the request, the middlware redirects the user
// to start the SAML auth flow. | [
"RequireAccount",
"is",
"HTTP",
"middleware",
"that",
"requires",
"that",
"each",
"request",
"be",
"associated",
"with",
"a",
"valid",
"session",
".",
"If",
"the",
"request",
"is",
"not",
"associated",
"with",
"a",
"valid",
"session",
"then",
"rather",
"than",... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/middleware.go#L98-L108 |
149,438 | crewjam/saml | samlsp/middleware.go | Authorize | func (m *Middleware) Authorize(w http.ResponseWriter, r *http.Request, assertion *saml.Assertion) {
secretBlock := x509.MarshalPKCS1PrivateKey(m.ServiceProvider.Key)
redirectURI := "/"
if relayState := r.Form.Get("RelayState"); relayState != "" {
stateValue := m.ClientState.GetState(r, relayState)
if stateValue... | go | func (m *Middleware) Authorize(w http.ResponseWriter, r *http.Request, assertion *saml.Assertion) {
secretBlock := x509.MarshalPKCS1PrivateKey(m.ServiceProvider.Key)
redirectURI := "/"
if relayState := r.Form.Get("RelayState"); relayState != "" {
stateValue := m.ClientState.GetState(r, relayState)
if stateValue... | [
"func",
"(",
"m",
"*",
"Middleware",
")",
"Authorize",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"assertion",
"*",
"saml",
".",
"Assertion",
")",
"{",
"secretBlock",
":=",
"x509",
".",
"MarshalPKCS1PrivateKey",
... | // Authorize is invoked by ServeHTTP when we have a new, valid SAML assertion.
// It sets a cookie that contains a signed JWT containing the assertion attributes.
// It then redirects the user's browser to the original URL contained in RelayState. | [
"Authorize",
"is",
"invoked",
"by",
"ServeHTTP",
"when",
"we",
"have",
"a",
"new",
"valid",
"SAML",
"assertion",
".",
"It",
"sets",
"a",
"cookie",
"that",
"contains",
"a",
"signed",
"JWT",
"containing",
"the",
"assertion",
"attributes",
".",
"It",
"then",
... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/middleware.go#L204-L265 |
149,439 | crewjam/saml | samlsp/middleware.go | GetAuthorizationToken | func (m *Middleware) GetAuthorizationToken(r *http.Request) *AuthorizationToken {
tokenStr := m.ClientToken.GetToken(r)
if tokenStr == "" {
return nil
}
tokenClaims := AuthorizationToken{}
token, err := jwt.ParseWithClaims(tokenStr, &tokenClaims, func(t *jwt.Token) (interface{}, error) {
secretBlock := x509.M... | go | func (m *Middleware) GetAuthorizationToken(r *http.Request) *AuthorizationToken {
tokenStr := m.ClientToken.GetToken(r)
if tokenStr == "" {
return nil
}
tokenClaims := AuthorizationToken{}
token, err := jwt.ParseWithClaims(tokenStr, &tokenClaims, func(t *jwt.Token) (interface{}, error) {
secretBlock := x509.M... | [
"func",
"(",
"m",
"*",
"Middleware",
")",
"GetAuthorizationToken",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"AuthorizationToken",
"{",
"tokenStr",
":=",
"m",
".",
"ClientToken",
".",
"GetToken",
"(",
"r",
")",
"\n",
"if",
"tokenStr",
"==",
"\"",
... | // GetAuthorizationToken is invoked by RequireAccount to determine if the request
// is already authorized or if the user's browser should be redirected to the
// SAML login flow. If the request is authorized, then the request context is
// ammended with a Context object. | [
"GetAuthorizationToken",
"is",
"invoked",
"by",
"RequireAccount",
"to",
"determine",
"if",
"the",
"request",
"is",
"already",
"authorized",
"or",
"if",
"the",
"user",
"s",
"browser",
"should",
"be",
"redirected",
"to",
"the",
"SAML",
"login",
"flow",
".",
"If"... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/middleware.go#L279-L304 |
149,440 | crewjam/saml | samlidp/shortcut.go | HandleIDPInitiated | func (s *Server) HandleIDPInitiated(c web.C, w http.ResponseWriter, r *http.Request) {
shortcutName := c.URLParams["shortcut"]
shortcut := Shortcut{}
if err := s.Store.Get(fmt.Sprintf("/shortcuts/%s", shortcutName), &shortcut); err != nil {
s.logger.Printf("ERROR: %s", err)
http.Error(w, http.StatusText(http.Sta... | go | func (s *Server) HandleIDPInitiated(c web.C, w http.ResponseWriter, r *http.Request) {
shortcutName := c.URLParams["shortcut"]
shortcut := Shortcut{}
if err := s.Store.Get(fmt.Sprintf("/shortcuts/%s", shortcutName), &shortcut); err != nil {
s.logger.Printf("ERROR: %s", err)
http.Error(w, http.StatusText(http.Sta... | [
"func",
"(",
"s",
"*",
"Server",
")",
"HandleIDPInitiated",
"(",
"c",
"web",
".",
"C",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"shortcutName",
":=",
"c",
".",
"URLParams",
"[",
"\"",
"\"",
"]",
"\n"... | // HandleIDPInitiated handles a request for an IDP initiated login flow. It looks up
// the specified shortcut, generates the appropriate SAML assertion and redirects the
// user via the HTTP-POST binding to the service providers ACS URL. | [
"HandleIDPInitiated",
"handles",
"a",
"request",
"for",
"an",
"IDP",
"initiated",
"login",
"flow",
".",
"It",
"looks",
"up",
"the",
"specified",
"shortcut",
"generates",
"the",
"appropriate",
"SAML",
"assertion",
"and",
"redirects",
"the",
"user",
"via",
"the",
... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlidp/shortcut.go#L89-L109 |
149,441 | crewjam/saml | identity_provider.go | Handler | func (idp *IdentityProvider) Handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc(idp.MetadataURL.Path, idp.ServeMetadata)
mux.HandleFunc(idp.SSOURL.Path, idp.ServeSSO)
return mux
} | go | func (idp *IdentityProvider) Handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc(idp.MetadataURL.Path, idp.ServeMetadata)
mux.HandleFunc(idp.SSOURL.Path, idp.ServeSSO)
return mux
} | [
"func",
"(",
"idp",
"*",
"IdentityProvider",
")",
"Handler",
"(",
")",
"http",
".",
"Handler",
"{",
"mux",
":=",
"http",
".",
"NewServeMux",
"(",
")",
"\n",
"mux",
".",
"HandleFunc",
"(",
"idp",
".",
"MetadataURL",
".",
"Path",
",",
"idp",
".",
"Serv... | // Handler returns an http.Handler that serves the metadata and SSO
// URLs | [
"Handler",
"returns",
"an",
"http",
".",
"Handler",
"that",
"serves",
"the",
"metadata",
"and",
"SSO",
"URLs"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/identity_provider.go#L168-L173 |
149,442 | crewjam/saml | identity_provider.go | MakeAssertionEl | func (req *IdpAuthnRequest) MakeAssertionEl() error {
keyPair := tls.Certificate{
Certificate: [][]byte{req.IDP.Certificate.Raw},
PrivateKey: req.IDP.Key,
Leaf: req.IDP.Certificate,
}
for _, cert := range req.IDP.Intermediates {
keyPair.Certificate = append(keyPair.Certificate, cert.Raw)
}
keyStore... | go | func (req *IdpAuthnRequest) MakeAssertionEl() error {
keyPair := tls.Certificate{
Certificate: [][]byte{req.IDP.Certificate.Raw},
PrivateKey: req.IDP.Key,
Leaf: req.IDP.Certificate,
}
for _, cert := range req.IDP.Intermediates {
keyPair.Certificate = append(keyPair.Certificate, cert.Raw)
}
keyStore... | [
"func",
"(",
"req",
"*",
"IdpAuthnRequest",
")",
"MakeAssertionEl",
"(",
")",
"error",
"{",
"keyPair",
":=",
"tls",
".",
"Certificate",
"{",
"Certificate",
":",
"[",
"]",
"[",
"]",
"byte",
"{",
"req",
".",
"IDP",
".",
"Certificate",
".",
"Raw",
"}",
... | // MakeAssertionEl sets `AssertionEl` to a signed, possibly encrypted, version of `Assertion`. | [
"MakeAssertionEl",
"sets",
"AssertionEl",
"to",
"a",
"signed",
"possibly",
"encrypted",
"version",
"of",
"Assertion",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/identity_provider.go#L713-L778 |
149,443 | crewjam/saml | samlidp/service.go | GetServiceProvider | func (s *Server) GetServiceProvider(r *http.Request, serviceProviderID string) (*saml.EntityDescriptor, error) {
s.idpConfigMu.RLock()
defer s.idpConfigMu.RUnlock()
rv, ok := s.serviceProviders[serviceProviderID]
if !ok {
return nil, os.ErrNotExist
}
return rv, nil
} | go | func (s *Server) GetServiceProvider(r *http.Request, serviceProviderID string) (*saml.EntityDescriptor, error) {
s.idpConfigMu.RLock()
defer s.idpConfigMu.RUnlock()
rv, ok := s.serviceProviders[serviceProviderID]
if !ok {
return nil, os.ErrNotExist
}
return rv, nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"GetServiceProvider",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"serviceProviderID",
"string",
")",
"(",
"*",
"saml",
".",
"EntityDescriptor",
",",
"error",
")",
"{",
"s",
".",
"idpConfigMu",
".",
"RLock",
"(",
"... | // GetServiceProvider returns the Service Provider metadata for the
// service provider ID, which is typically the service provider's
// metadata URL. If an appropriate service provider cannot be found then
// the returned error must be os.ErrNotExist. | [
"GetServiceProvider",
"returns",
"the",
"Service",
"Provider",
"metadata",
"for",
"the",
"service",
"provider",
"ID",
"which",
"is",
"typically",
"the",
"service",
"provider",
"s",
"metadata",
"URL",
".",
"If",
"an",
"appropriate",
"service",
"provider",
"cannot",... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlidp/service.go#L27-L35 |
149,444 | crewjam/saml | samlidp/service.go | initializeServices | func (s *Server) initializeServices() error {
serviceNames, err := s.Store.List("/services/")
if err != nil {
return err
}
for _, serviceName := range serviceNames {
service := Service{}
if err := s.Store.Get(fmt.Sprintf("/services/%s", serviceName), &service); err != nil {
return err
}
s.idpConfigMu.... | go | func (s *Server) initializeServices() error {
serviceNames, err := s.Store.List("/services/")
if err != nil {
return err
}
for _, serviceName := range serviceNames {
service := Service{}
if err := s.Store.Get(fmt.Sprintf("/services/%s", serviceName), &service); err != nil {
return err
}
s.idpConfigMu.... | [
"func",
"(",
"s",
"*",
"Server",
")",
"initializeServices",
"(",
")",
"error",
"{",
"serviceNames",
",",
"err",
":=",
"s",
".",
"Store",
".",
"List",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fo... | // initializeServices reads all the stored services and initializes the underlying
// identity provider to accept them. | [
"initializeServices",
"reads",
"all",
"the",
"stored",
"services",
"and",
"initializes",
"the",
"underlying",
"identity",
"provider",
"to",
"accept",
"them",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlidp/service.go#L118-L134 |
149,445 | crewjam/saml | service_provider.go | Element | func (n NameIDFormat) Element() *etree.Element {
el := etree.NewElement("")
el.SetText(string(n))
return el
} | go | func (n NameIDFormat) Element() *etree.Element {
el := etree.NewElement("")
el.SetText(string(n))
return el
} | [
"func",
"(",
"n",
"NameIDFormat",
")",
"Element",
"(",
")",
"*",
"etree",
".",
"Element",
"{",
"el",
":=",
"etree",
".",
"NewElement",
"(",
"\"",
"\"",
")",
"\n",
"el",
".",
"SetText",
"(",
"string",
"(",
"n",
")",
")",
"\n",
"return",
"el",
"\n"... | // Element returns an XML element representation of n. | [
"Element",
"returns",
"an",
"XML",
"element",
"representation",
"of",
"n",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/service_provider.go#L29-L33 |
149,446 | crewjam/saml | service_provider.go | Redirect | func (req *AuthnRequest) Redirect(relayState string) *url.URL {
w := &bytes.Buffer{}
w1 := base64.NewEncoder(base64.StdEncoding, w)
w2, _ := flate.NewWriter(w1, 9)
doc := etree.NewDocument()
doc.SetRoot(req.Element())
if _, err := doc.WriteTo(w2); err != nil {
panic(err)
}
w2.Close()
w1.Close()
rv, _ := ur... | go | func (req *AuthnRequest) Redirect(relayState string) *url.URL {
w := &bytes.Buffer{}
w1 := base64.NewEncoder(base64.StdEncoding, w)
w2, _ := flate.NewWriter(w1, 9)
doc := etree.NewDocument()
doc.SetRoot(req.Element())
if _, err := doc.WriteTo(w2); err != nil {
panic(err)
}
w2.Close()
w1.Close()
rv, _ := ur... | [
"func",
"(",
"req",
"*",
"AuthnRequest",
")",
"Redirect",
"(",
"relayState",
"string",
")",
"*",
"url",
".",
"URL",
"{",
"w",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"w1",
":=",
"base64",
".",
"NewEncoder",
"(",
"base64",
".",
"StdEncoding... | // Redirect returns a URL suitable for using the redirect binding with the request | [
"Redirect",
"returns",
"a",
"URL",
"suitable",
"for",
"using",
"the",
"redirect",
"binding",
"with",
"the",
"request"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/service_provider.go#L171-L193 |
149,447 | crewjam/saml | service_provider.go | getIDPSigningCerts | func (sp *ServiceProvider) getIDPSigningCerts() ([]*x509.Certificate, error) {
var certStrs []string
for _, idpSSODescriptor := range sp.IDPMetadata.IDPSSODescriptors {
for _, keyDescriptor := range idpSSODescriptor.KeyDescriptors {
if keyDescriptor.Use == "signing" {
certStrs = append(certStrs, keyDescripto... | go | func (sp *ServiceProvider) getIDPSigningCerts() ([]*x509.Certificate, error) {
var certStrs []string
for _, idpSSODescriptor := range sp.IDPMetadata.IDPSSODescriptors {
for _, keyDescriptor := range idpSSODescriptor.KeyDescriptors {
if keyDescriptor.Use == "signing" {
certStrs = append(certStrs, keyDescripto... | [
"func",
"(",
"sp",
"*",
"ServiceProvider",
")",
"getIDPSigningCerts",
"(",
")",
"(",
"[",
"]",
"*",
"x509",
".",
"Certificate",
",",
"error",
")",
"{",
"var",
"certStrs",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"idpSSODescriptor",
":=",
"range",
"sp... | // getIDPSigningCerts returns the certificates which we can use to verify things
// signed by the IDP in PEM format, or nil if no such certificate is found. | [
"getIDPSigningCerts",
"returns",
"the",
"certificates",
"which",
"we",
"can",
"use",
"to",
"verify",
"things",
"signed",
"by",
"the",
"IDP",
"in",
"PEM",
"format",
"or",
"nil",
"if",
"no",
"such",
"certificate",
"is",
"found",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/service_provider.go#L210-L256 |
149,448 | crewjam/saml | service_provider.go | validateSigned | func (sp *ServiceProvider) validateSigned(responseEl *etree.Element) error {
haveSignature := false
// Some SAML responses have the signature on the Response object, and some on the Assertion
// object, and some on both. We will require that at least one signature be present and that
// all signatures be valid
si... | go | func (sp *ServiceProvider) validateSigned(responseEl *etree.Element) error {
haveSignature := false
// Some SAML responses have the signature on the Response object, and some on the Assertion
// object, and some on both. We will require that at least one signature be present and that
// all signatures be valid
si... | [
"func",
"(",
"sp",
"*",
"ServiceProvider",
")",
"validateSigned",
"(",
"responseEl",
"*",
"etree",
".",
"Element",
")",
"error",
"{",
"haveSignature",
":=",
"false",
"\n\n",
"// Some SAML responses have the signature on the Response object, and some on the Assertion",
"// o... | // validateSigned returns a nil error iff each of the signatures on the Response and Assertion elements
// are valid and there is at least one signature. | [
"validateSigned",
"returns",
"a",
"nil",
"error",
"iff",
"each",
"of",
"the",
"signatures",
"on",
"the",
"Response",
"and",
"Assertion",
"elements",
"are",
"valid",
"and",
"there",
"is",
"at",
"least",
"one",
"signature",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/service_provider.go#L594-L632 |
149,449 | crewjam/saml | service_provider.go | validateSignature | func (sp *ServiceProvider) validateSignature(el *etree.Element) error {
certs, err := sp.getIDPSigningCerts()
if err != nil {
return err
}
certificateStore := dsig.MemoryX509CertificateStore{
Roots: certs,
}
validationContext := dsig.NewDefaultValidationContext(&certificateStore)
validationContext.IdAttrib... | go | func (sp *ServiceProvider) validateSignature(el *etree.Element) error {
certs, err := sp.getIDPSigningCerts()
if err != nil {
return err
}
certificateStore := dsig.MemoryX509CertificateStore{
Roots: certs,
}
validationContext := dsig.NewDefaultValidationContext(&certificateStore)
validationContext.IdAttrib... | [
"func",
"(",
"sp",
"*",
"ServiceProvider",
")",
"validateSignature",
"(",
"el",
"*",
"etree",
".",
"Element",
")",
"error",
"{",
"certs",
",",
"err",
":=",
"sp",
".",
"getIDPSigningCerts",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",... | // validateSignature returns nill iff the Signature embedded in the element is valid | [
"validateSignature",
"returns",
"nill",
"iff",
"the",
"Signature",
"embedded",
"in",
"the",
"element",
"is",
"valid"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/service_provider.go#L635-L683 |
149,450 | crewjam/saml | samlidp/samlidp.go | New | func New(opts Options) (*Server, error) {
metadataURL := opts.URL
metadataURL.Path = metadataURL.Path + "/metadata"
ssoURL := opts.URL
ssoURL.Path = ssoURL.Path + "/sso"
logr := opts.Logger
if logr == nil {
logr = logger.DefaultLogger
}
s := &Server{
serviceProviders: map[string]*saml.EntityDescriptor{},
... | go | func New(opts Options) (*Server, error) {
metadataURL := opts.URL
metadataURL.Path = metadataURL.Path + "/metadata"
ssoURL := opts.URL
ssoURL.Path = ssoURL.Path + "/sso"
logr := opts.Logger
if logr == nil {
logr = logger.DefaultLogger
}
s := &Server{
serviceProviders: map[string]*saml.EntityDescriptor{},
... | [
"func",
"New",
"(",
"opts",
"Options",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"metadataURL",
":=",
"opts",
".",
"URL",
"\n",
"metadataURL",
".",
"Path",
"=",
"metadataURL",
".",
"Path",
"+",
"\"",
"\"",
"\n",
"ssoURL",
":=",
"opts",
".",
... | // New returns a new Server | [
"New",
"returns",
"a",
"new",
"Server"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlidp/samlidp.go#L46-L77 |
149,451 | crewjam/saml | samlsp/cookie.go | SetState | func (c ClientCookies) SetState(w http.ResponseWriter, r *http.Request, id string, value string) {
http.SetCookie(w, &http.Cookie{
Name: stateCookiePrefix + id,
Value: value,
MaxAge: int(saml.MaxIssueDelay.Seconds()),
HttpOnly: true,
Secure: c.Secure || r.URL.Scheme == "https",
Path: c.Servi... | go | func (c ClientCookies) SetState(w http.ResponseWriter, r *http.Request, id string, value string) {
http.SetCookie(w, &http.Cookie{
Name: stateCookiePrefix + id,
Value: value,
MaxAge: int(saml.MaxIssueDelay.Seconds()),
HttpOnly: true,
Secure: c.Secure || r.URL.Scheme == "https",
Path: c.Servi... | [
"func",
"(",
"c",
"ClientCookies",
")",
"SetState",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"id",
"string",
",",
"value",
"string",
")",
"{",
"http",
".",
"SetCookie",
"(",
"w",
",",
"&",
"http",
".",
"C... | // SetState stores the named state value by setting a cookie. | [
"SetState",
"stores",
"the",
"named",
"state",
"value",
"by",
"setting",
"a",
"cookie",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/cookie.go#L37-L46 |
149,452 | crewjam/saml | samlsp/cookie.go | GetStates | func (c ClientCookies) GetStates(r *http.Request) map[string]string {
rv := map[string]string{}
for _, cookie := range r.Cookies() {
if !strings.HasPrefix(cookie.Name, stateCookiePrefix) {
continue
}
name := strings.TrimPrefix(cookie.Name, stateCookiePrefix)
rv[name] = cookie.Value
}
return rv
} | go | func (c ClientCookies) GetStates(r *http.Request) map[string]string {
rv := map[string]string{}
for _, cookie := range r.Cookies() {
if !strings.HasPrefix(cookie.Name, stateCookiePrefix) {
continue
}
name := strings.TrimPrefix(cookie.Name, stateCookiePrefix)
rv[name] = cookie.Value
}
return rv
} | [
"func",
"(",
"c",
"ClientCookies",
")",
"GetStates",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"rv",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"cookie",
":=",
"range",
... | // GetStates returns the currently stored states by reading cookies. | [
"GetStates",
"returns",
"the",
"currently",
"stored",
"states",
"by",
"reading",
"cookies",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/cookie.go#L49-L59 |
149,453 | crewjam/saml | samlsp/cookie.go | GetState | func (c ClientCookies) GetState(r *http.Request, id string) string {
stateCookie, err := r.Cookie(stateCookiePrefix + id)
if err != nil {
return ""
}
return stateCookie.Value
} | go | func (c ClientCookies) GetState(r *http.Request, id string) string {
stateCookie, err := r.Cookie(stateCookiePrefix + id)
if err != nil {
return ""
}
return stateCookie.Value
} | [
"func",
"(",
"c",
"ClientCookies",
")",
"GetState",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"id",
"string",
")",
"string",
"{",
"stateCookie",
",",
"err",
":=",
"r",
".",
"Cookie",
"(",
"stateCookiePrefix",
"+",
"id",
")",
"\n",
"if",
"err",
"!="... | // GetState returns a single stored state by reading the cookies | [
"GetState",
"returns",
"a",
"single",
"stored",
"state",
"by",
"reading",
"the",
"cookies"
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/cookie.go#L62-L68 |
149,454 | crewjam/saml | samlsp/cookie.go | DeleteState | func (c ClientCookies) DeleteState(w http.ResponseWriter, r *http.Request, id string) error {
cookie, err := r.Cookie(stateCookiePrefix + id)
if err != nil {
return err
}
cookie.Value = ""
cookie.Expires = time.Unix(1, 0) // past time as close to epoch as possible, but not zero time.Time{}
http.SetCookie(w, coo... | go | func (c ClientCookies) DeleteState(w http.ResponseWriter, r *http.Request, id string) error {
cookie, err := r.Cookie(stateCookiePrefix + id)
if err != nil {
return err
}
cookie.Value = ""
cookie.Expires = time.Unix(1, 0) // past time as close to epoch as possible, but not zero time.Time{}
http.SetCookie(w, coo... | [
"func",
"(",
"c",
"ClientCookies",
")",
"DeleteState",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"id",
"string",
")",
"error",
"{",
"cookie",
",",
"err",
":=",
"r",
".",
"Cookie",
"(",
"stateCookiePrefix",
"+"... | // DeleteState removes the named stored state by clearing the corresponding cookie. | [
"DeleteState",
"removes",
"the",
"named",
"stored",
"state",
"by",
"clearing",
"the",
"corresponding",
"cookie",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/cookie.go#L71-L80 |
149,455 | crewjam/saml | samlsp/cookie.go | SetToken | func (c ClientCookies) SetToken(w http.ResponseWriter, r *http.Request, value string, maxAge time.Duration) {
http.SetCookie(w, &http.Cookie{
Name: c.Name,
Domain: c.Domain,
Value: value,
MaxAge: int(maxAge.Seconds()),
HttpOnly: true,
Secure: c.Secure || r.URL.Scheme == "https",
Path: "/... | go | func (c ClientCookies) SetToken(w http.ResponseWriter, r *http.Request, value string, maxAge time.Duration) {
http.SetCookie(w, &http.Cookie{
Name: c.Name,
Domain: c.Domain,
Value: value,
MaxAge: int(maxAge.Seconds()),
HttpOnly: true,
Secure: c.Secure || r.URL.Scheme == "https",
Path: "/... | [
"func",
"(",
"c",
"ClientCookies",
")",
"SetToken",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"value",
"string",
",",
"maxAge",
"time",
".",
"Duration",
")",
"{",
"http",
".",
"SetCookie",
"(",
"w",
",",
"&"... | // SetToken assigns the specified token by setting a cookie. | [
"SetToken",
"assigns",
"the",
"specified",
"token",
"by",
"setting",
"a",
"cookie",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/cookie.go#L83-L93 |
149,456 | crewjam/saml | samlsp/cookie.go | GetToken | func (c ClientCookies) GetToken(r *http.Request) string {
cookie, err := r.Cookie(c.Name)
if err != nil {
return ""
}
return cookie.Value
} | go | func (c ClientCookies) GetToken(r *http.Request) string {
cookie, err := r.Cookie(c.Name)
if err != nil {
return ""
}
return cookie.Value
} | [
"func",
"(",
"c",
"ClientCookies",
")",
"GetToken",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"cookie",
",",
"err",
":=",
"r",
".",
"Cookie",
"(",
"c",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
... | // GetToken returns the token by reading the cookie. | [
"GetToken",
"returns",
"the",
"token",
"by",
"reading",
"the",
"cookie",
"."
] | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/samlsp/cookie.go#L96-L102 |
149,457 | crewjam/saml | xmlenc/pubkey.go | OAEP | func OAEP() RSA {
return RSA{
BlockCipher: AES256CBC,
DigestMethod: SHA256,
algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p",
keyEncrypter: func(e RSA, pubKey *rsa.PublicKey, plaintext []byte) ([]byte, error) {
return rsa.EncryptOAEP(e.DigestMethod.Hash(), RandReader, pubKey, plaintext, nil)... | go | func OAEP() RSA {
return RSA{
BlockCipher: AES256CBC,
DigestMethod: SHA256,
algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p",
keyEncrypter: func(e RSA, pubKey *rsa.PublicKey, plaintext []byte) ([]byte, error) {
return rsa.EncryptOAEP(e.DigestMethod.Hash(), RandReader, pubKey, plaintext, nil)... | [
"func",
"OAEP",
"(",
")",
"RSA",
"{",
"return",
"RSA",
"{",
"BlockCipher",
":",
"AES256CBC",
",",
"DigestMethod",
":",
"SHA256",
",",
"algorithm",
":",
"\"",
"\"",
",",
"keyEncrypter",
":",
"func",
"(",
"e",
"RSA",
",",
"pubKey",
"*",
"rsa",
".",
"Pu... | // OAEP returns a version of RSA that implements RSA in OAEP-MGF1P mode. By default
// the block cipher used is AES-256 CBC and the digest method is SHA-256. You can
// specify other ciphers and digest methods by assigning to BlockCipher or
// DigestMethod. | [
"OAEP",
"returns",
"a",
"version",
"of",
"RSA",
"that",
"implements",
"RSA",
"in",
"OAEP",
"-",
"MGF1P",
"mode",
".",
"By",
"default",
"the",
"block",
"cipher",
"used",
"is",
"AES",
"-",
"256",
"CBC",
"and",
"the",
"digest",
"method",
"is",
"SHA",
"-",... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/xmlenc/pubkey.go#L127-L139 |
149,458 | crewjam/saml | xmlenc/pubkey.go | PKCS1v15 | func PKCS1v15() RSA {
return RSA{
BlockCipher: AES256CBC,
DigestMethod: nil,
algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-1_5",
keyEncrypter: func(e RSA, pubKey *rsa.PublicKey, plaintext []byte) ([]byte, error) {
return rsa.EncryptPKCS1v15(RandReader, pubKey, plaintext)
},
keyDecrypter: func(e R... | go | func PKCS1v15() RSA {
return RSA{
BlockCipher: AES256CBC,
DigestMethod: nil,
algorithm: "http://www.w3.org/2001/04/xmlenc#rsa-1_5",
keyEncrypter: func(e RSA, pubKey *rsa.PublicKey, plaintext []byte) ([]byte, error) {
return rsa.EncryptPKCS1v15(RandReader, pubKey, plaintext)
},
keyDecrypter: func(e R... | [
"func",
"PKCS1v15",
"(",
")",
"RSA",
"{",
"return",
"RSA",
"{",
"BlockCipher",
":",
"AES256CBC",
",",
"DigestMethod",
":",
"nil",
",",
"algorithm",
":",
"\"",
"\"",
",",
"keyEncrypter",
":",
"func",
"(",
"e",
"RSA",
",",
"pubKey",
"*",
"rsa",
".",
"P... | // PKCS1v15 returns a version of RSA that implements RSA in PKCS1v15 mode. By default
// the block cipher used is AES-256 CBC. The DigestMethod field is ignored because PKCS1v15
// does not use a digest function. | [
"PKCS1v15",
"returns",
"a",
"version",
"of",
"RSA",
"that",
"implements",
"RSA",
"in",
"PKCS1v15",
"mode",
".",
"By",
"default",
"the",
"block",
"cipher",
"used",
"is",
"AES",
"-",
"256",
"CBC",
".",
"The",
"DigestMethod",
"field",
"is",
"ignored",
"becaus... | 724cb1c4fab17ba90fa24c4dde8f6f594d105071 | https://github.com/crewjam/saml/blob/724cb1c4fab17ba90fa24c4dde8f6f594d105071/xmlenc/pubkey.go#L144-L156 |
149,459 | tidwall/redcon | append.go | AppendUint | func AppendUint(b []byte, n uint64) []byte {
b = append(b, ':')
b = strconv.AppendUint(b, n, 10)
return append(b, '\r', '\n')
} | go | func AppendUint(b []byte, n uint64) []byte {
b = append(b, ':')
b = strconv.AppendUint(b, n, 10)
return append(b, '\r', '\n')
} | [
"func",
"AppendUint",
"(",
"b",
"[",
"]",
"byte",
",",
"n",
"uint64",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"':'",
")",
"\n",
"b",
"=",
"strconv",
".",
"AppendUint",
"(",
"b",
",",
"n",
",",
"10",
")",
"\n",
"return",... | // AppendUint appends a Redis protocol uint64 to the input bytes. | [
"AppendUint",
"appends",
"a",
"Redis",
"protocol",
"uint64",
"to",
"the",
"input",
"bytes",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/append.go#L243-L247 |
149,460 | tidwall/redcon | append.go | AppendArray | func AppendArray(b []byte, n int) []byte {
return appendPrefix(b, '*', int64(n))
} | go | func AppendArray(b []byte, n int) []byte {
return appendPrefix(b, '*', int64(n))
} | [
"func",
"AppendArray",
"(",
"b",
"[",
"]",
"byte",
",",
"n",
"int",
")",
"[",
"]",
"byte",
"{",
"return",
"appendPrefix",
"(",
"b",
",",
"'*'",
",",
"int64",
"(",
"n",
")",
")",
"\n",
"}"
] | // AppendArray appends a Redis protocol array to the input bytes. | [
"AppendArray",
"appends",
"a",
"Redis",
"protocol",
"array",
"to",
"the",
"input",
"bytes",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/append.go#L255-L257 |
149,461 | tidwall/redcon | append.go | AppendBulk | func AppendBulk(b []byte, bulk []byte) []byte {
b = appendPrefix(b, '$', int64(len(bulk)))
b = append(b, bulk...)
return append(b, '\r', '\n')
} | go | func AppendBulk(b []byte, bulk []byte) []byte {
b = appendPrefix(b, '$', int64(len(bulk)))
b = append(b, bulk...)
return append(b, '\r', '\n')
} | [
"func",
"AppendBulk",
"(",
"b",
"[",
"]",
"byte",
",",
"bulk",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"appendPrefix",
"(",
"b",
",",
"'$'",
",",
"int64",
"(",
"len",
"(",
"bulk",
")",
")",
")",
"\n",
"b",
"=",
"append",
"(",
... | // AppendBulk appends a Redis protocol bulk byte slice to the input bytes. | [
"AppendBulk",
"appends",
"a",
"Redis",
"protocol",
"bulk",
"byte",
"slice",
"to",
"the",
"input",
"bytes",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/append.go#L260-L264 |
149,462 | tidwall/redcon | append.go | AppendBulkString | func AppendBulkString(b []byte, bulk string) []byte {
b = appendPrefix(b, '$', int64(len(bulk)))
b = append(b, bulk...)
return append(b, '\r', '\n')
} | go | func AppendBulkString(b []byte, bulk string) []byte {
b = appendPrefix(b, '$', int64(len(bulk)))
b = append(b, bulk...)
return append(b, '\r', '\n')
} | [
"func",
"AppendBulkString",
"(",
"b",
"[",
"]",
"byte",
",",
"bulk",
"string",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"appendPrefix",
"(",
"b",
",",
"'$'",
",",
"int64",
"(",
"len",
"(",
"bulk",
")",
")",
")",
"\n",
"b",
"=",
"append",
"(",
"b",... | // AppendBulkString appends a Redis protocol bulk string to the input bytes. | [
"AppendBulkString",
"appends",
"a",
"Redis",
"protocol",
"bulk",
"string",
"to",
"the",
"input",
"bytes",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/append.go#L267-L271 |
149,463 | tidwall/redcon | append.go | AppendString | func AppendString(b []byte, s string) []byte {
b = append(b, '+')
b = append(b, stripNewlines(s)...)
return append(b, '\r', '\n')
} | go | func AppendString(b []byte, s string) []byte {
b = append(b, '+')
b = append(b, stripNewlines(s)...)
return append(b, '\r', '\n')
} | [
"func",
"AppendString",
"(",
"b",
"[",
"]",
"byte",
",",
"s",
"string",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'+'",
")",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"stripNewlines",
"(",
"s",
")",
"...",
")",
"\n",
"ret... | // AppendString appends a Redis protocol string to the input bytes. | [
"AppendString",
"appends",
"a",
"Redis",
"protocol",
"string",
"to",
"the",
"input",
"bytes",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/append.go#L274-L278 |
149,464 | tidwall/redcon | append.go | AppendError | func AppendError(b []byte, s string) []byte {
b = append(b, '-')
b = append(b, stripNewlines(s)...)
return append(b, '\r', '\n')
} | go | func AppendError(b []byte, s string) []byte {
b = append(b, '-')
b = append(b, stripNewlines(s)...)
return append(b, '\r', '\n')
} | [
"func",
"AppendError",
"(",
"b",
"[",
"]",
"byte",
",",
"s",
"string",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'-'",
")",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"stripNewlines",
"(",
"s",
")",
"...",
")",
"\n",
"retu... | // AppendError appends a Redis protocol error to the input bytes. | [
"AppendError",
"appends",
"a",
"Redis",
"protocol",
"error",
"to",
"the",
"input",
"bytes",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/append.go#L281-L285 |
149,465 | tidwall/redcon | append.go | AppendTile38 | func AppendTile38(b []byte, data []byte) []byte {
b = append(b, '$')
b = strconv.AppendInt(b, int64(len(data)), 10)
b = append(b, ' ')
b = append(b, data...)
return append(b, '\r', '\n')
} | go | func AppendTile38(b []byte, data []byte) []byte {
b = append(b, '$')
b = strconv.AppendInt(b, int64(len(data)), 10)
b = append(b, ' ')
b = append(b, data...)
return append(b, '\r', '\n')
} | [
"func",
"AppendTile38",
"(",
"b",
"[",
"]",
"byte",
",",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"'$'",
")",
"\n",
"b",
"=",
"strconv",
".",
"AppendInt",
"(",
"b",
",",
"int64",
"(",
"len",
"("... | // AppendTile38 appends a Tile38 message to the input bytes. | [
"AppendTile38",
"appends",
"a",
"Tile38",
"message",
"to",
"the",
"input",
"bytes",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/append.go#L303-L309 |
149,466 | tidwall/redcon | redcon.go | NewServer | func NewServer(addr string,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
) *Server {
return NewServerNetwork("tcp", addr, handler, accept, closed)
} | go | func NewServer(addr string,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
) *Server {
return NewServerNetwork("tcp", addr, handler, accept, closed)
} | [
"func",
"NewServer",
"(",
"addr",
"string",
",",
"handler",
"func",
"(",
"conn",
"Conn",
",",
"cmd",
"Command",
")",
",",
"accept",
"func",
"(",
"conn",
"Conn",
")",
"bool",
",",
"closed",
"func",
"(",
"conn",
"Conn",
",",
"err",
"error",
")",
",",
... | // NewServer returns a new Redcon server configured on "tcp" network net. | [
"NewServer",
"returns",
"a",
"new",
"Redcon",
"server",
"configured",
"on",
"tcp",
"network",
"net",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L96-L102 |
149,467 | tidwall/redcon | redcon.go | NewServerTLS | func NewServerTLS(addr string,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
config *tls.Config,
) *TLSServer {
return NewServerNetworkTLS("tcp", addr, handler, accept, closed, config)
} | go | func NewServerTLS(addr string,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
config *tls.Config,
) *TLSServer {
return NewServerNetworkTLS("tcp", addr, handler, accept, closed, config)
} | [
"func",
"NewServerTLS",
"(",
"addr",
"string",
",",
"handler",
"func",
"(",
"conn",
"Conn",
",",
"cmd",
"Command",
")",
",",
"accept",
"func",
"(",
"conn",
"Conn",
")",
"bool",
",",
"closed",
"func",
"(",
"conn",
"Conn",
",",
"err",
"error",
")",
","... | // NewServerTLS returns a new Redcon TLS server configured on "tcp" network net. | [
"NewServerTLS",
"returns",
"a",
"new",
"Redcon",
"TLS",
"server",
"configured",
"on",
"tcp",
"network",
"net",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L105-L112 |
149,468 | tidwall/redcon | redcon.go | Close | func (s *Server) Close() error {
s.mu.Lock()
defer s.mu.Unlock()
if s.ln == nil {
return errors.New("not serving")
}
s.done = true
return s.ln.Close()
} | go | func (s *Server) Close() error {
s.mu.Lock()
defer s.mu.Unlock()
if s.ln == nil {
return errors.New("not serving")
}
s.done = true
return s.ln.Close()
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Close",
"(",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"s",
".",
"ln",
"==",
"nil",
"{",
"return",
"errors",
".",
"Ne... | // Close stops listening on the TCP address.
// Already Accepted connections will be closed. | [
"Close",
"stops",
"listening",
"on",
"the",
"TCP",
"address",
".",
"Already",
"Accepted",
"connections",
"will",
"be",
"closed",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L166-L174 |
149,469 | tidwall/redcon | redcon.go | Serve | func Serve(ln net.Listener,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
) error {
s := &Server{
net: ln.Addr().Network(),
laddr: ln.Addr().String(),
ln: ln,
handler: handler,
accept: accept,
closed: closed,
conns: make(map[*conn]... | go | func Serve(ln net.Listener,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
) error {
s := &Server{
net: ln.Addr().Network(),
laddr: ln.Addr().String(),
ln: ln,
handler: handler,
accept: accept,
closed: closed,
conns: make(map[*conn]... | [
"func",
"Serve",
"(",
"ln",
"net",
".",
"Listener",
",",
"handler",
"func",
"(",
"conn",
"Conn",
",",
"cmd",
"Command",
")",
",",
"accept",
"func",
"(",
"conn",
"Conn",
")",
"bool",
",",
"closed",
"func",
"(",
"conn",
"Conn",
",",
"err",
"error",
"... | // Serve creates a new server and serves with the given net.Listener. | [
"Serve",
"creates",
"a",
"new",
"server",
"and",
"serves",
"with",
"the",
"given",
"net",
".",
"Listener",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L204-L220 |
149,470 | tidwall/redcon | redcon.go | ListenAndServe | func ListenAndServe(addr string,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
) error {
return ListenAndServeNetwork("tcp", addr, handler, accept, closed)
} | go | func ListenAndServe(addr string,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
) error {
return ListenAndServeNetwork("tcp", addr, handler, accept, closed)
} | [
"func",
"ListenAndServe",
"(",
"addr",
"string",
",",
"handler",
"func",
"(",
"conn",
"Conn",
",",
"cmd",
"Command",
")",
",",
"accept",
"func",
"(",
"conn",
"Conn",
")",
"bool",
",",
"closed",
"func",
"(",
"conn",
"Conn",
",",
"err",
"error",
")",
"... | // ListenAndServe creates a new server and binds to addr configured on "tcp" network net. | [
"ListenAndServe",
"creates",
"a",
"new",
"server",
"and",
"binds",
"to",
"addr",
"configured",
"on",
"tcp",
"network",
"net",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L223-L229 |
149,471 | tidwall/redcon | redcon.go | ListenAndServeTLS | func ListenAndServeTLS(addr string,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
config *tls.Config,
) error {
return ListenAndServeNetworkTLS("tcp", addr, handler, accept, closed, config)
} | go | func ListenAndServeTLS(addr string,
handler func(conn Conn, cmd Command),
accept func(conn Conn) bool,
closed func(conn Conn, err error),
config *tls.Config,
) error {
return ListenAndServeNetworkTLS("tcp", addr, handler, accept, closed, config)
} | [
"func",
"ListenAndServeTLS",
"(",
"addr",
"string",
",",
"handler",
"func",
"(",
"conn",
"Conn",
",",
"cmd",
"Command",
")",
",",
"accept",
"func",
"(",
"conn",
"Conn",
")",
"bool",
",",
"closed",
"func",
"(",
"conn",
"Conn",
",",
"err",
"error",
")",
... | // ListenAndServeTLS creates a new TLS server and binds to addr configured on "tcp" network net. | [
"ListenAndServeTLS",
"creates",
"a",
"new",
"TLS",
"server",
"and",
"binds",
"to",
"addr",
"configured",
"on",
"tcp",
"network",
"net",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L232-L239 |
149,472 | tidwall/redcon | redcon.go | ListenServeAndSignal | func (s *Server) ListenServeAndSignal(signal chan error) error {
ln, err := net.Listen(s.net, s.laddr)
if err != nil {
if signal != nil {
signal <- err
}
return err
}
s.ln = ln
if signal != nil {
signal <- nil
}
return serve(s)
} | go | func (s *Server) ListenServeAndSignal(signal chan error) error {
ln, err := net.Listen(s.net, s.laddr)
if err != nil {
if signal != nil {
signal <- err
}
return err
}
s.ln = ln
if signal != nil {
signal <- nil
}
return serve(s)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"ListenServeAndSignal",
"(",
"signal",
"chan",
"error",
")",
"error",
"{",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"s",
".",
"net",
",",
"s",
".",
"laddr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",... | // ListenServeAndSignal serves incoming connections and passes nil or error
// when listening. signal can be nil. | [
"ListenServeAndSignal",
"serves",
"incoming",
"connections",
"and",
"passes",
"nil",
"or",
"error",
"when",
"listening",
".",
"signal",
"can",
"be",
"nil",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L266-L279 |
149,473 | tidwall/redcon | redcon.go | Serve | func (s *Server) Serve(ln net.Listener) error {
s.ln = ln
s.net = ln.Addr().Network()
s.laddr = ln.Addr().String()
return serve(s)
} | go | func (s *Server) Serve(ln net.Listener) error {
s.ln = ln
s.net = ln.Addr().Network()
s.laddr = ln.Addr().String()
return serve(s)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Serve",
"(",
"ln",
"net",
".",
"Listener",
")",
"error",
"{",
"s",
".",
"ln",
"=",
"ln",
"\n",
"s",
".",
"net",
"=",
"ln",
".",
"Addr",
"(",
")",
".",
"Network",
"(",
")",
"\n",
"s",
".",
"laddr",
"=",... | // Serve serves incoming connections with the given net.Listener. | [
"Serve",
"serves",
"incoming",
"connections",
"with",
"the",
"given",
"net",
".",
"Listener",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L282-L287 |
149,474 | tidwall/redcon | redcon.go | handle | func handle(s *Server, c *conn) {
var err error
defer func() {
if err != errDetached {
// do not close the connection when a detach is detected.
c.conn.Close()
}
func() {
// remove the conn from the server
s.mu.Lock()
defer s.mu.Unlock()
delete(s.conns, c)
if s.closed != nil {
if err ==... | go | func handle(s *Server, c *conn) {
var err error
defer func() {
if err != errDetached {
// do not close the connection when a detach is detected.
c.conn.Close()
}
func() {
// remove the conn from the server
s.mu.Lock()
defer s.mu.Unlock()
delete(s.conns, c)
if s.closed != nil {
if err ==... | [
"func",
"handle",
"(",
"s",
"*",
"Server",
",",
"c",
"*",
"conn",
")",
"{",
"var",
"err",
"error",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"errDetached",
"{",
"// do not close the connection when a detach is detected.",
"c",
".",
"conn",
"... | // handle manages the server connection. | [
"handle",
"manages",
"the",
"server",
"connection",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L350-L407 |
149,475 | tidwall/redcon | redcon.go | BaseWriter | func BaseWriter(c Conn) *Writer {
if c, ok := c.(*conn); ok {
return c.wr
}
return nil
} | go | func BaseWriter(c Conn) *Writer {
if c, ok := c.(*conn); ok {
return c.wr
}
return nil
} | [
"func",
"BaseWriter",
"(",
"c",
"Conn",
")",
"*",
"Writer",
"{",
"if",
"c",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"conn",
")",
";",
"ok",
"{",
"return",
"c",
".",
"wr",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // BaseWriter returns the underlying connection writer, if any | [
"BaseWriter",
"returns",
"the",
"underlying",
"connection",
"writer",
"if",
"any"
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L452-L457 |
149,476 | tidwall/redcon | redcon.go | ReadCommand | func (dc *detachedConn) ReadCommand() (Command, error) {
if dc.closed {
return Command{}, errors.New("closed")
}
if len(dc.cmds) > 0 {
cmd := dc.cmds[0]
if len(dc.cmds) == 1 {
dc.cmds = nil
} else {
dc.cmds = dc.cmds[1:]
}
return cmd, nil
}
cmd, err := dc.rd.ReadCommand()
if err != nil {
retur... | go | func (dc *detachedConn) ReadCommand() (Command, error) {
if dc.closed {
return Command{}, errors.New("closed")
}
if len(dc.cmds) > 0 {
cmd := dc.cmds[0]
if len(dc.cmds) == 1 {
dc.cmds = nil
} else {
dc.cmds = dc.cmds[1:]
}
return cmd, nil
}
cmd, err := dc.rd.ReadCommand()
if err != nil {
retur... | [
"func",
"(",
"dc",
"*",
"detachedConn",
")",
"ReadCommand",
"(",
")",
"(",
"Command",
",",
"error",
")",
"{",
"if",
"dc",
".",
"closed",
"{",
"return",
"Command",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
... | // ReadCommand read the next command from the client. | [
"ReadCommand",
"read",
"the",
"next",
"command",
"from",
"the",
"client",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L492-L510 |
149,477 | tidwall/redcon | redcon.go | WriteBulk | func (w *Writer) WriteBulk(bulk []byte) {
w.b = AppendBulk(w.b, bulk)
} | go | func (w *Writer) WriteBulk(bulk []byte) {
w.b = AppendBulk(w.b, bulk)
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"WriteBulk",
"(",
"bulk",
"[",
"]",
"byte",
")",
"{",
"w",
".",
"b",
"=",
"AppendBulk",
"(",
"w",
".",
"b",
",",
"bulk",
")",
"\n",
"}"
] | // WriteBulk writes bulk bytes to the client. | [
"WriteBulk",
"writes",
"bulk",
"bytes",
"to",
"the",
"client",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L569-L571 |
149,478 | tidwall/redcon | redcon.go | WriteBulkString | func (w *Writer) WriteBulkString(bulk string) {
w.b = AppendBulkString(w.b, bulk)
} | go | func (w *Writer) WriteBulkString(bulk string) {
w.b = AppendBulkString(w.b, bulk)
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"WriteBulkString",
"(",
"bulk",
"string",
")",
"{",
"w",
".",
"b",
"=",
"AppendBulkString",
"(",
"w",
".",
"b",
",",
"bulk",
")",
"\n",
"}"
] | // WriteBulkString writes a bulk string to the client. | [
"WriteBulkString",
"writes",
"a",
"bulk",
"string",
"to",
"the",
"client",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L574-L576 |
149,479 | tidwall/redcon | redcon.go | SetBuffer | func (w *Writer) SetBuffer(raw []byte) {
w.b = w.b[:0]
w.b = append(w.b, raw...)
} | go | func (w *Writer) SetBuffer(raw []byte) {
w.b = w.b[:0]
w.b = append(w.b, raw...)
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"SetBuffer",
"(",
"raw",
"[",
"]",
"byte",
")",
"{",
"w",
".",
"b",
"=",
"w",
".",
"b",
"[",
":",
"0",
"]",
"\n",
"w",
".",
"b",
"=",
"append",
"(",
"w",
".",
"b",
",",
"raw",
"...",
")",
"\n",
"}"
... | // SetBuffer replaces the unflushed buffer with new bytes. | [
"SetBuffer",
"replaces",
"the",
"unflushed",
"buffer",
"with",
"new",
"bytes",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L585-L588 |
149,480 | tidwall/redcon | redcon.go | WriteError | func (w *Writer) WriteError(msg string) {
w.b = AppendError(w.b, msg)
} | go | func (w *Writer) WriteError(msg string) {
w.b = AppendError(w.b, msg)
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"WriteError",
"(",
"msg",
"string",
")",
"{",
"w",
".",
"b",
"=",
"AppendError",
"(",
"w",
".",
"b",
",",
"msg",
")",
"\n",
"}"
] | // WriteError writes an error to the client. | [
"WriteError",
"writes",
"an",
"error",
"to",
"the",
"client",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L600-L602 |
149,481 | tidwall/redcon | redcon.go | WriteString | func (w *Writer) WriteString(msg string) {
w.b = AppendString(w.b, msg)
} | go | func (w *Writer) WriteString(msg string) {
w.b = AppendString(w.b, msg)
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"WriteString",
"(",
"msg",
"string",
")",
"{",
"w",
".",
"b",
"=",
"AppendString",
"(",
"w",
".",
"b",
",",
"msg",
")",
"\n",
"}"
] | // WriteString writes a string to the client. | [
"WriteString",
"writes",
"a",
"string",
"to",
"the",
"client",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L605-L607 |
149,482 | tidwall/redcon | redcon.go | WriteInt64 | func (w *Writer) WriteInt64(num int64) {
w.b = AppendInt(w.b, num)
} | go | func (w *Writer) WriteInt64(num int64) {
w.b = AppendInt(w.b, num)
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"WriteInt64",
"(",
"num",
"int64",
")",
"{",
"w",
".",
"b",
"=",
"AppendInt",
"(",
"w",
".",
"b",
",",
"num",
")",
"\n",
"}"
] | // WriteInt64 writes a 64-bit signed integer to the client. | [
"WriteInt64",
"writes",
"a",
"64",
"-",
"bit",
"signed",
"integer",
"to",
"the",
"client",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L615-L617 |
149,483 | tidwall/redcon | redcon.go | WriteRaw | func (w *Writer) WriteRaw(data []byte) {
w.b = append(w.b, data...)
} | go | func (w *Writer) WriteRaw(data []byte) {
w.b = append(w.b, data...)
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"WriteRaw",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"w",
".",
"b",
"=",
"append",
"(",
"w",
".",
"b",
",",
"data",
"...",
")",
"\n",
"}"
] | // WriteRaw writes raw data to the client. | [
"WriteRaw",
"writes",
"raw",
"data",
"to",
"the",
"client",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L620-L622 |
149,484 | tidwall/redcon | redcon.go | NewReader | func NewReader(rd io.Reader) *Reader {
return &Reader{
rd: bufio.NewReader(rd),
buf: make([]byte, 4096),
}
} | go | func NewReader(rd io.Reader) *Reader {
return &Reader{
rd: bufio.NewReader(rd),
buf: make([]byte, 4096),
}
} | [
"func",
"NewReader",
"(",
"rd",
"io",
".",
"Reader",
")",
"*",
"Reader",
"{",
"return",
"&",
"Reader",
"{",
"rd",
":",
"bufio",
".",
"NewReader",
"(",
"rd",
")",
",",
"buf",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"4096",
")",
",",
"}",
"\n",
... | // NewReader returns a command reader which will read RESP or telnet commands. | [
"NewReader",
"returns",
"a",
"command",
"reader",
"which",
"will",
"read",
"RESP",
"or",
"telnet",
"commands",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L634-L639 |
149,485 | tidwall/redcon | redcon.go | ReadCommand | func (rd *Reader) ReadCommand() (Command, error) {
if len(rd.cmds) > 0 {
cmd := rd.cmds[0]
rd.cmds = rd.cmds[1:]
return cmd, nil
}
cmds, err := rd.readCommands(nil)
if err != nil {
return Command{}, err
}
rd.cmds = cmds
return rd.ReadCommand()
} | go | func (rd *Reader) ReadCommand() (Command, error) {
if len(rd.cmds) > 0 {
cmd := rd.cmds[0]
rd.cmds = rd.cmds[1:]
return cmd, nil
}
cmds, err := rd.readCommands(nil)
if err != nil {
return Command{}, err
}
rd.cmds = cmds
return rd.ReadCommand()
} | [
"func",
"(",
"rd",
"*",
"Reader",
")",
"ReadCommand",
"(",
")",
"(",
"Command",
",",
"error",
")",
"{",
"if",
"len",
"(",
"rd",
".",
"cmds",
")",
">",
"0",
"{",
"cmd",
":=",
"rd",
".",
"cmds",
"[",
"0",
"]",
"\n",
"rd",
".",
"cmds",
"=",
"r... | // ReadCommand reads the next command. | [
"ReadCommand",
"reads",
"the",
"next",
"command",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L875-L887 |
149,486 | tidwall/redcon | redcon.go | Parse | func Parse(raw []byte) (Command, error) {
rd := Reader{buf: raw, end: len(raw)}
var leftover int
cmds, err := rd.readCommands(&leftover)
if err != nil {
return Command{}, err
}
if leftover > 0 {
return Command{}, errTooMuchData
}
return cmds[0], nil
} | go | func Parse(raw []byte) (Command, error) {
rd := Reader{buf: raw, end: len(raw)}
var leftover int
cmds, err := rd.readCommands(&leftover)
if err != nil {
return Command{}, err
}
if leftover > 0 {
return Command{}, errTooMuchData
}
return cmds[0], nil
} | [
"func",
"Parse",
"(",
"raw",
"[",
"]",
"byte",
")",
"(",
"Command",
",",
"error",
")",
"{",
"rd",
":=",
"Reader",
"{",
"buf",
":",
"raw",
",",
"end",
":",
"len",
"(",
"raw",
")",
"}",
"\n",
"var",
"leftover",
"int",
"\n",
"cmds",
",",
"err",
... | // Parse parses a raw RESP message and returns a command. | [
"Parse",
"parses",
"a",
"raw",
"RESP",
"message",
"and",
"returns",
"a",
"command",
"."
] | c964c660adb68a16a0f890ceb01d25e05d0ab49e | https://github.com/tidwall/redcon/blob/c964c660adb68a16a0f890ceb01d25e05d0ab49e/redcon.go#L890-L902 |
149,487 | sony/gobreaker | gobreaker.go | String | func (s State) String() string {
switch s {
case StateClosed:
return "closed"
case StateHalfOpen:
return "half-open"
case StateOpen:
return "open"
default:
return fmt.Sprintf("unknown state: %d", s)
}
} | go | func (s State) String() string {
switch s {
case StateClosed:
return "closed"
case StateHalfOpen:
return "half-open"
case StateOpen:
return "open"
default:
return fmt.Sprintf("unknown state: %d", s)
}
} | [
"func",
"(",
"s",
"State",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"s",
"{",
"case",
"StateClosed",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StateHalfOpen",
":",
"return",
"\"",
"\"",
"\n",
"case",
"StateOpen",
":",
"return",
"\"",
"\"",
"... | // String implements stringer interface. | [
"String",
"implements",
"stringer",
"interface",
"."
] | a9b2a3fc7395bc2e784d8f4df34fa953ce115b78 | https://github.com/sony/gobreaker/blob/a9b2a3fc7395bc2e784d8f4df34fa953ce115b78/gobreaker.go#L30-L41 |
149,488 | sony/gobreaker | gobreaker.go | NewCircuitBreaker | func NewCircuitBreaker(st Settings) *CircuitBreaker {
cb := new(CircuitBreaker)
cb.name = st.Name
cb.interval = st.Interval
cb.onStateChange = st.OnStateChange
if st.MaxRequests == 0 {
cb.maxRequests = 1
} else {
cb.maxRequests = st.MaxRequests
}
if st.Timeout == 0 {
cb.timeout = defaultTimeout
} else... | go | func NewCircuitBreaker(st Settings) *CircuitBreaker {
cb := new(CircuitBreaker)
cb.name = st.Name
cb.interval = st.Interval
cb.onStateChange = st.OnStateChange
if st.MaxRequests == 0 {
cb.maxRequests = 1
} else {
cb.maxRequests = st.MaxRequests
}
if st.Timeout == 0 {
cb.timeout = defaultTimeout
} else... | [
"func",
"NewCircuitBreaker",
"(",
"st",
"Settings",
")",
"*",
"CircuitBreaker",
"{",
"cb",
":=",
"new",
"(",
"CircuitBreaker",
")",
"\n\n",
"cb",
".",
"name",
"=",
"st",
".",
"Name",
"\n",
"cb",
".",
"interval",
"=",
"st",
".",
"Interval",
"\n",
"cb",
... | // NewCircuitBreaker returns a new CircuitBreaker configured with the given Settings. | [
"NewCircuitBreaker",
"returns",
"a",
"new",
"CircuitBreaker",
"configured",
"with",
"the",
"given",
"Settings",
"."
] | a9b2a3fc7395bc2e784d8f4df34fa953ce115b78 | https://github.com/sony/gobreaker/blob/a9b2a3fc7395bc2e784d8f4df34fa953ce115b78/gobreaker.go#L134-L162 |
149,489 | sony/gobreaker | gobreaker.go | State | func (cb *CircuitBreaker) State() State {
cb.mutex.Lock()
defer cb.mutex.Unlock()
now := time.Now()
state, _ := cb.currentState(now)
return state
} | go | func (cb *CircuitBreaker) State() State {
cb.mutex.Lock()
defer cb.mutex.Unlock()
now := time.Now()
state, _ := cb.currentState(now)
return state
} | [
"func",
"(",
"cb",
"*",
"CircuitBreaker",
")",
"State",
"(",
")",
"State",
"{",
"cb",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cb",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"sta... | // State returns the current state of the CircuitBreaker. | [
"State",
"returns",
"the",
"current",
"state",
"of",
"the",
"CircuitBreaker",
"."
] | a9b2a3fc7395bc2e784d8f4df34fa953ce115b78 | https://github.com/sony/gobreaker/blob/a9b2a3fc7395bc2e784d8f4df34fa953ce115b78/gobreaker.go#L183-L190 |
149,490 | sony/gobreaker | gobreaker.go | Execute | func (cb *CircuitBreaker) Execute(req func() (interface{}, error)) (interface{}, error) {
generation, err := cb.beforeRequest()
if err != nil {
return nil, err
}
defer func() {
e := recover()
if e != nil {
cb.afterRequest(generation, false)
panic(e)
}
}()
result, err := req()
cb.afterRequest(gene... | go | func (cb *CircuitBreaker) Execute(req func() (interface{}, error)) (interface{}, error) {
generation, err := cb.beforeRequest()
if err != nil {
return nil, err
}
defer func() {
e := recover()
if e != nil {
cb.afterRequest(generation, false)
panic(e)
}
}()
result, err := req()
cb.afterRequest(gene... | [
"func",
"(",
"cb",
"*",
"CircuitBreaker",
")",
"Execute",
"(",
"req",
"func",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"generation",
",",
"err",
":=",
"cb",
".",
"beforeReques... | // Execute runs the given request if the CircuitBreaker accepts it.
// Execute returns an error instantly if the CircuitBreaker rejects the request.
// Otherwise, Execute returns the result of the request.
// If a panic occurs in the request, the CircuitBreaker handles it as an error
// and causes the same panic again. | [
"Execute",
"runs",
"the",
"given",
"request",
"if",
"the",
"CircuitBreaker",
"accepts",
"it",
".",
"Execute",
"returns",
"an",
"error",
"instantly",
"if",
"the",
"CircuitBreaker",
"rejects",
"the",
"request",
".",
"Otherwise",
"Execute",
"returns",
"the",
"resul... | a9b2a3fc7395bc2e784d8f4df34fa953ce115b78 | https://github.com/sony/gobreaker/blob/a9b2a3fc7395bc2e784d8f4df34fa953ce115b78/gobreaker.go#L197-L214 |
149,491 | sony/gobreaker | gobreaker.go | Allow | func (tscb *TwoStepCircuitBreaker) Allow() (done func(success bool), err error) {
generation, err := tscb.cb.beforeRequest()
if err != nil {
return nil, err
}
return func(success bool) {
tscb.cb.afterRequest(generation, success)
}, nil
} | go | func (tscb *TwoStepCircuitBreaker) Allow() (done func(success bool), err error) {
generation, err := tscb.cb.beforeRequest()
if err != nil {
return nil, err
}
return func(success bool) {
tscb.cb.afterRequest(generation, success)
}, nil
} | [
"func",
"(",
"tscb",
"*",
"TwoStepCircuitBreaker",
")",
"Allow",
"(",
")",
"(",
"done",
"func",
"(",
"success",
"bool",
")",
",",
"err",
"error",
")",
"{",
"generation",
",",
"err",
":=",
"tscb",
".",
"cb",
".",
"beforeRequest",
"(",
")",
"\n",
"if",... | // Allow checks if a new request can proceed. It returns a callback that should be used to
// register the success or failure in a separate step. If the circuit breaker doesn't allow
// requests, it returns an error. | [
"Allow",
"checks",
"if",
"a",
"new",
"request",
"can",
"proceed",
".",
"It",
"returns",
"a",
"callback",
"that",
"should",
"be",
"used",
"to",
"register",
"the",
"success",
"or",
"failure",
"in",
"a",
"separate",
"step",
".",
"If",
"the",
"circuit",
"bre... | a9b2a3fc7395bc2e784d8f4df34fa953ce115b78 | https://github.com/sony/gobreaker/blob/a9b2a3fc7395bc2e784d8f4df34fa953ce115b78/gobreaker.go#L229-L238 |
149,492 | sony/gobreaker | example/http_breaker.go | Get | func Get(url string) ([]byte, error) {
body, err := cb.Execute(func() (interface{}, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
})
if err != nil {
retu... | go | func Get(url string) ([]byte, error) {
body, err := cb.Execute(func() (interface{}, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
})
if err != nil {
retu... | [
"func",
"Get",
"(",
"url",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"cb",
".",
"Execute",
"(",
"func",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"htt... | // Get wraps http.Get in CircuitBreaker. | [
"Get",
"wraps",
"http",
".",
"Get",
"in",
"CircuitBreaker",
"."
] | a9b2a3fc7395bc2e784d8f4df34fa953ce115b78 | https://github.com/sony/gobreaker/blob/a9b2a3fc7395bc2e784d8f4df34fa953ce115b78/example/http_breaker.go#L26-L46 |
149,493 | ncabatoff/process-exporter | proc/tracker.go | NewTracker | func NewTracker(namer common.MatchNamer, trackChildren, trackThreads, alwaysRecheck, debug bool) *Tracker {
return &Tracker{
namer: namer,
tracked: make(map[ID]*trackedProc),
procIds: make(map[int]ID),
trackChildren: trackChildren,
trackThreads: trackThreads,
alwaysRecheck: alwaysReche... | go | func NewTracker(namer common.MatchNamer, trackChildren, trackThreads, alwaysRecheck, debug bool) *Tracker {
return &Tracker{
namer: namer,
tracked: make(map[ID]*trackedProc),
procIds: make(map[int]ID),
trackChildren: trackChildren,
trackThreads: trackThreads,
alwaysRecheck: alwaysReche... | [
"func",
"NewTracker",
"(",
"namer",
"common",
".",
"MatchNamer",
",",
"trackChildren",
",",
"trackThreads",
",",
"alwaysRecheck",
",",
"debug",
"bool",
")",
"*",
"Tracker",
"{",
"return",
"&",
"Tracker",
"{",
"namer",
":",
"namer",
",",
"tracked",
":",
"ma... | // NewTracker creates a Tracker. | [
"NewTracker",
"creates",
"a",
"Tracker",
"."
] | 0f1987d2db4f6fccdec912784031c966b066765d | https://github.com/ncabatoff/process-exporter/blob/0f1987d2db4f6fccdec912784031c966b066765d/proc/tracker.go#L141-L152 |
149,494 | ncabatoff/process-exporter | proc/tracker.go | update | func (t *Tracker) update(procs Iter) ([]IDInfo, CollectErrors, error) {
var newProcs []IDInfo
var colErrs CollectErrors
var now = time.Now()
for procs.Next() {
newProc, cerrs := t.handleProc(procs, now)
if newProc != nil {
newProcs = append(newProcs, *newProc)
}
colErrs.Read += cerrs.Read
colErrs.Part... | go | func (t *Tracker) update(procs Iter) ([]IDInfo, CollectErrors, error) {
var newProcs []IDInfo
var colErrs CollectErrors
var now = time.Now()
for procs.Next() {
newProc, cerrs := t.handleProc(procs, now)
if newProc != nil {
newProcs = append(newProcs, *newProc)
}
colErrs.Read += cerrs.Read
colErrs.Part... | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"update",
"(",
"procs",
"Iter",
")",
"(",
"[",
"]",
"IDInfo",
",",
"CollectErrors",
",",
"error",
")",
"{",
"var",
"newProcs",
"[",
"]",
"IDInfo",
"\n",
"var",
"colErrs",
"CollectErrors",
"\n",
"var",
"now",
"="... | // update scans procs and updates metrics for those which are tracked. Processes
// that have gone away get removed from the Tracked map. New processes are
// returned, along with the count of nonfatal errors. | [
"update",
"scans",
"procs",
"and",
"updates",
"metrics",
"for",
"those",
"which",
"are",
"tracked",
".",
"Processes",
"that",
"have",
"gone",
"away",
"get",
"removed",
"from",
"the",
"Tracked",
"map",
".",
"New",
"processes",
"are",
"returned",
"along",
"wit... | 0f1987d2db4f6fccdec912784031c966b066765d | https://github.com/ncabatoff/process-exporter/blob/0f1987d2db4f6fccdec912784031c966b066765d/proc/tracker.go#L287-L323 |
149,495 | ncabatoff/process-exporter | proc/tracker.go | checkAncestry | func (t *Tracker) checkAncestry(idinfo IDInfo, newprocs map[ID]IDInfo) string {
ppid := idinfo.ParentPid
pProcID := t.procIds[ppid]
if pProcID.Pid < 1 {
if t.debug {
log.Printf("ignoring unmatched proc with no matched parent: %+v", idinfo)
}
// Reached root of process tree without finding a tracked parent.
... | go | func (t *Tracker) checkAncestry(idinfo IDInfo, newprocs map[ID]IDInfo) string {
ppid := idinfo.ParentPid
pProcID := t.procIds[ppid]
if pProcID.Pid < 1 {
if t.debug {
log.Printf("ignoring unmatched proc with no matched parent: %+v", idinfo)
}
// Reached root of process tree without finding a tracked parent.
... | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"checkAncestry",
"(",
"idinfo",
"IDInfo",
",",
"newprocs",
"map",
"[",
"ID",
"]",
"IDInfo",
")",
"string",
"{",
"ppid",
":=",
"idinfo",
".",
"ParentPid",
"\n",
"pProcID",
":=",
"t",
".",
"procIds",
"[",
"ppid",
... | // checkAncestry walks the process tree recursively towards the root,
// stopping at pid 1 or upon finding a parent that's already tracked
// or ignored. If we find a tracked parent track this one too; if not,
// ignore this one. | [
"checkAncestry",
"walks",
"the",
"process",
"tree",
"recursively",
"towards",
"the",
"root",
"stopping",
"at",
"pid",
"1",
"or",
"upon",
"finding",
"a",
"parent",
"that",
"s",
"already",
"tracked",
"or",
"ignored",
".",
"If",
"we",
"find",
"a",
"tracked",
... | 0f1987d2db4f6fccdec912784031c966b066765d | https://github.com/ncabatoff/process-exporter/blob/0f1987d2db4f6fccdec912784031c966b066765d/proc/tracker.go#L329-L376 |
149,496 | ncabatoff/process-exporter | proc/tracker.go | Update | func (t *Tracker) Update(iter Iter) (CollectErrors, []Update, error) {
newProcs, colErrs, err := t.update(iter)
if err != nil {
return colErrs, nil, err
}
// Step 1: track any new proc that should be tracked based on its name and cmdline.
untracked := make(map[ID]IDInfo)
for _, idinfo := range newProcs {
nac... | go | func (t *Tracker) Update(iter Iter) (CollectErrors, []Update, error) {
newProcs, colErrs, err := t.update(iter)
if err != nil {
return colErrs, nil, err
}
// Step 1: track any new proc that should be tracked based on its name and cmdline.
untracked := make(map[ID]IDInfo)
for _, idinfo := range newProcs {
nac... | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"Update",
"(",
"iter",
"Iter",
")",
"(",
"CollectErrors",
",",
"[",
"]",
"Update",
",",
"error",
")",
"{",
"newProcs",
",",
"colErrs",
",",
"err",
":=",
"t",
".",
"update",
"(",
"iter",
")",
"\n",
"if",
"err... | // Update modifies the tracker's internal state based on what it reads from
// iter. Tracks any new procs the namer wants tracked, and updates
// its metrics for existing tracked procs. Returns nonfatal errors
// and the status of all tracked procs, or an error if fatal. | [
"Update",
"modifies",
"the",
"tracker",
"s",
"internal",
"state",
"based",
"on",
"what",
"it",
"reads",
"from",
"iter",
".",
"Tracks",
"any",
"new",
"procs",
"the",
"namer",
"wants",
"tracked",
"and",
"updates",
"its",
"metrics",
"for",
"existing",
"tracked"... | 0f1987d2db4f6fccdec912784031c966b066765d | https://github.com/ncabatoff/process-exporter/blob/0f1987d2db4f6fccdec912784031c966b066765d/proc/tracker.go#L399-L443 |
149,497 | ncabatoff/process-exporter | proc/read.go | Add | func (c *Counts) Add(c2 Delta) {
c.CPUUserTime += c2.CPUUserTime
c.CPUSystemTime += c2.CPUSystemTime
c.ReadBytes += c2.ReadBytes
c.WriteBytes += c2.WriteBytes
c.MajorPageFaults += c2.MajorPageFaults
c.MinorPageFaults += c2.MinorPageFaults
c.CtxSwitchVoluntary += c2.CtxSwitchVoluntary
c.CtxSwitchNonvoluntary += ... | go | func (c *Counts) Add(c2 Delta) {
c.CPUUserTime += c2.CPUUserTime
c.CPUSystemTime += c2.CPUSystemTime
c.ReadBytes += c2.ReadBytes
c.WriteBytes += c2.WriteBytes
c.MajorPageFaults += c2.MajorPageFaults
c.MinorPageFaults += c2.MinorPageFaults
c.CtxSwitchVoluntary += c2.CtxSwitchVoluntary
c.CtxSwitchNonvoluntary += ... | [
"func",
"(",
"c",
"*",
"Counts",
")",
"Add",
"(",
"c2",
"Delta",
")",
"{",
"c",
".",
"CPUUserTime",
"+=",
"c2",
".",
"CPUUserTime",
"\n",
"c",
".",
"CPUSystemTime",
"+=",
"c2",
".",
"CPUSystemTime",
"\n",
"c",
".",
"ReadBytes",
"+=",
"c2",
".",
"Re... | // Add adds c2 to the counts. | [
"Add",
"adds",
"c2",
"to",
"the",
"counts",
"."
] | 0f1987d2db4f6fccdec912784031c966b066765d | https://github.com/ncabatoff/process-exporter/blob/0f1987d2db4f6fccdec912784031c966b066765d/proc/read.go#L201-L210 |
149,498 | ncabatoff/process-exporter | proc/read.go | GetCounts | func (p IDInfo) GetCounts() (Counts, int, error) {
return p.Metrics.Counts, 0, nil
} | go | func (p IDInfo) GetCounts() (Counts, int, error) {
return p.Metrics.Counts, 0, nil
} | [
"func",
"(",
"p",
"IDInfo",
")",
"GetCounts",
"(",
")",
"(",
"Counts",
",",
"int",
",",
"error",
")",
"{",
"return",
"p",
".",
"Metrics",
".",
"Counts",
",",
"0",
",",
"nil",
"\n",
"}"
] | // GetCounts implements Proc. | [
"GetCounts",
"implements",
"Proc",
"."
] | 0f1987d2db4f6fccdec912784031c966b066765d | https://github.com/ncabatoff/process-exporter/blob/0f1987d2db4f6fccdec912784031c966b066765d/proc/read.go#L253-L255 |
149,499 | ncabatoff/process-exporter | proc/read.go | GetProcID | func (p *proccache) GetProcID() (ID, error) {
if p.procid == nil {
stat, err := p.getStat()
if err != nil {
return ID{}, err
}
p.procid = &ID{Pid: p.GetPid(), StartTimeRel: stat.Starttime}
}
return *p.procid, nil
} | go | func (p *proccache) GetProcID() (ID, error) {
if p.procid == nil {
stat, err := p.getStat()
if err != nil {
return ID{}, err
}
p.procid = &ID{Pid: p.GetPid(), StartTimeRel: stat.Starttime}
}
return *p.procid, nil
} | [
"func",
"(",
"p",
"*",
"proccache",
")",
"GetProcID",
"(",
")",
"(",
"ID",
",",
"error",
")",
"{",
"if",
"p",
".",
"procid",
"==",
"nil",
"{",
"stat",
",",
"err",
":=",
"p",
".",
"getStat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retu... | // GetProcID implements Proc. | [
"GetProcID",
"implements",
"Proc",
"."
] | 0f1987d2db4f6fccdec912784031c966b066765d | https://github.com/ncabatoff/process-exporter/blob/0f1987d2db4f6fccdec912784031c966b066765d/proc/read.go#L300-L310 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.