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
|
---|---|---|---|---|---|---|---|---|---|---|---|
8,700 | getsentry/raven-go | client.go | SetDefaultLoggerName | func (client *Client) SetDefaultLoggerName(name string) {
client.mu.Lock()
defer client.mu.Unlock()
client.defaultLoggerName = name
} | go | func (client *Client) SetDefaultLoggerName(name string) {
client.mu.Lock()
defer client.mu.Unlock()
client.defaultLoggerName = name
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"SetDefaultLoggerName",
"(",
"name",
"string",
")",
"{",
"client",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"client",
".",
"defaultLoggerName",
"=",
"name",
"\n",
"}"
]
| // SetDefaultLoggerName sets the default logger name. | [
"SetDefaultLoggerName",
"sets",
"the",
"default",
"logger",
"name",
"."
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L543-L547 |
8,701 | getsentry/raven-go | client.go | SetSampleRate | func (client *Client) SetSampleRate(rate float32) error {
client.mu.Lock()
defer client.mu.Unlock()
if rate < 0 || rate > 1 {
return ErrInvalidSampleRate
}
client.sampleRate = rate
return nil
} | go | func (client *Client) SetSampleRate(rate float32) error {
client.mu.Lock()
defer client.mu.Unlock()
if rate < 0 || rate > 1 {
return ErrInvalidSampleRate
}
client.sampleRate = rate
return nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"SetSampleRate",
"(",
"rate",
"float32",
")",
"error",
"{",
"client",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"rate",
"<",
"0",
"||",
"rate",
">",
"1",
"{",
"return",
"ErrInvalidSampleRate",
"\n",
"}",
"\n",
"client",
".",
"sampleRate",
"=",
"rate",
"\n",
"return",
"nil",
"\n",
"}"
]
| // SetSampleRate sets how much sampling we want on client side | [
"SetSampleRate",
"sets",
"how",
"much",
"sampling",
"we",
"want",
"on",
"client",
"side"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L550-L559 |
8,702 | getsentry/raven-go | client.go | Capture | func (client *Client) Capture(packet *Packet, captureTags map[string]string) (eventID string, ch chan error) {
ch = make(chan error, 1)
if client == nil {
// return a chan that always returns nil when the caller receives from it
close(ch)
return
}
if client.sampleRate < 1.0 && mrand.Float32() > client.sampleRate {
return
}
if packet == nil {
close(ch)
return
}
if client.shouldExcludeErr(packet.Message) {
return
}
// Keep track of all running Captures so that we can wait for them all to finish
// *Must* call client.wg.Done() on any path that indicates that an event was
// finished being acted upon, whether success or failure
client.wg.Add(1)
// Merge capture tags and client tags
packet.AddTags(captureTags)
packet.AddTags(client.Tags)
// Initialize any required packet fields
client.mu.RLock()
packet.AddTags(client.context.tags)
projectID := client.projectID
release := client.release
environment := client.environment
defaultLoggerName := client.defaultLoggerName
client.mu.RUnlock()
// set the global logger name on the packet if we must
if packet.Logger == "" && defaultLoggerName != "" {
packet.Logger = defaultLoggerName
}
err := packet.Init(projectID)
if err != nil {
ch <- err
client.wg.Done()
return
}
if packet.Release == "" {
packet.Release = release
}
if packet.Environment == "" {
packet.Environment = environment
}
outgoingPacket := &outgoingPacket{packet, ch}
// Lazily start background worker until we
// do our first write into the queue.
client.start.Do(func() {
go client.worker()
})
select {
case client.queue <- outgoingPacket:
default:
// Send would block, drop the packet
if client.DropHandler != nil {
client.DropHandler(packet)
}
ch <- ErrPacketDropped
client.wg.Done()
}
return packet.EventID, ch
} | go | func (client *Client) Capture(packet *Packet, captureTags map[string]string) (eventID string, ch chan error) {
ch = make(chan error, 1)
if client == nil {
// return a chan that always returns nil when the caller receives from it
close(ch)
return
}
if client.sampleRate < 1.0 && mrand.Float32() > client.sampleRate {
return
}
if packet == nil {
close(ch)
return
}
if client.shouldExcludeErr(packet.Message) {
return
}
// Keep track of all running Captures so that we can wait for them all to finish
// *Must* call client.wg.Done() on any path that indicates that an event was
// finished being acted upon, whether success or failure
client.wg.Add(1)
// Merge capture tags and client tags
packet.AddTags(captureTags)
packet.AddTags(client.Tags)
// Initialize any required packet fields
client.mu.RLock()
packet.AddTags(client.context.tags)
projectID := client.projectID
release := client.release
environment := client.environment
defaultLoggerName := client.defaultLoggerName
client.mu.RUnlock()
// set the global logger name on the packet if we must
if packet.Logger == "" && defaultLoggerName != "" {
packet.Logger = defaultLoggerName
}
err := packet.Init(projectID)
if err != nil {
ch <- err
client.wg.Done()
return
}
if packet.Release == "" {
packet.Release = release
}
if packet.Environment == "" {
packet.Environment = environment
}
outgoingPacket := &outgoingPacket{packet, ch}
// Lazily start background worker until we
// do our first write into the queue.
client.start.Do(func() {
go client.worker()
})
select {
case client.queue <- outgoingPacket:
default:
// Send would block, drop the packet
if client.DropHandler != nil {
client.DropHandler(packet)
}
ch <- ErrPacketDropped
client.wg.Done()
}
return packet.EventID, ch
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"Capture",
"(",
"packet",
"*",
"Packet",
",",
"captureTags",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"eventID",
"string",
",",
"ch",
"chan",
"error",
")",
"{",
"ch",
"=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n\n",
"if",
"client",
"==",
"nil",
"{",
"// return a chan that always returns nil when the caller receives from it",
"close",
"(",
"ch",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"client",
".",
"sampleRate",
"<",
"1.0",
"&&",
"mrand",
".",
"Float32",
"(",
")",
">",
"client",
".",
"sampleRate",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"packet",
"==",
"nil",
"{",
"close",
"(",
"ch",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"client",
".",
"shouldExcludeErr",
"(",
"packet",
".",
"Message",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"// Keep track of all running Captures so that we can wait for them all to finish",
"// *Must* call client.wg.Done() on any path that indicates that an event was",
"// finished being acted upon, whether success or failure",
"client",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n\n",
"// Merge capture tags and client tags",
"packet",
".",
"AddTags",
"(",
"captureTags",
")",
"\n",
"packet",
".",
"AddTags",
"(",
"client",
".",
"Tags",
")",
"\n\n",
"// Initialize any required packet fields",
"client",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"packet",
".",
"AddTags",
"(",
"client",
".",
"context",
".",
"tags",
")",
"\n",
"projectID",
":=",
"client",
".",
"projectID",
"\n",
"release",
":=",
"client",
".",
"release",
"\n",
"environment",
":=",
"client",
".",
"environment",
"\n",
"defaultLoggerName",
":=",
"client",
".",
"defaultLoggerName",
"\n",
"client",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"// set the global logger name on the packet if we must",
"if",
"packet",
".",
"Logger",
"==",
"\"",
"\"",
"&&",
"defaultLoggerName",
"!=",
"\"",
"\"",
"{",
"packet",
".",
"Logger",
"=",
"defaultLoggerName",
"\n",
"}",
"\n\n",
"err",
":=",
"packet",
".",
"Init",
"(",
"projectID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ch",
"<-",
"err",
"\n",
"client",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"packet",
".",
"Release",
"==",
"\"",
"\"",
"{",
"packet",
".",
"Release",
"=",
"release",
"\n",
"}",
"\n\n",
"if",
"packet",
".",
"Environment",
"==",
"\"",
"\"",
"{",
"packet",
".",
"Environment",
"=",
"environment",
"\n",
"}",
"\n\n",
"outgoingPacket",
":=",
"&",
"outgoingPacket",
"{",
"packet",
",",
"ch",
"}",
"\n\n",
"// Lazily start background worker until we",
"// do our first write into the queue.",
"client",
".",
"start",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"go",
"client",
".",
"worker",
"(",
")",
"\n",
"}",
")",
"\n\n",
"select",
"{",
"case",
"client",
".",
"queue",
"<-",
"outgoingPacket",
":",
"default",
":",
"// Send would block, drop the packet",
"if",
"client",
".",
"DropHandler",
"!=",
"nil",
"{",
"client",
".",
"DropHandler",
"(",
"packet",
")",
"\n",
"}",
"\n",
"ch",
"<-",
"ErrPacketDropped",
"\n",
"client",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"packet",
".",
"EventID",
",",
"ch",
"\n",
"}"
]
| // Capture asynchronously delivers a packet to the Sentry server. It is a no-op
// when client is nil. A channel is provided if it is important to check for a
// send's success. | [
"Capture",
"asynchronously",
"delivers",
"a",
"packet",
"to",
"the",
"Sentry",
"server",
".",
"It",
"is",
"a",
"no",
"-",
"op",
"when",
"client",
"is",
"nil",
".",
"A",
"channel",
"is",
"provided",
"if",
"it",
"is",
"important",
"to",
"check",
"for",
"a",
"send",
"s",
"success",
"."
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L601-L681 |
8,703 | getsentry/raven-go | client.go | CaptureMessage | func (client *Client) CaptureMessage(message string, tags map[string]string, interfaces ...Interface) string {
if client == nil {
return ""
}
if client.shouldExcludeErr(message) {
return ""
}
packet := NewPacket(message, append(append(interfaces, client.context.interfaces()...), &Message{message, nil})...)
eventID, _ := client.Capture(packet, tags)
return eventID
} | go | func (client *Client) CaptureMessage(message string, tags map[string]string, interfaces ...Interface) string {
if client == nil {
return ""
}
if client.shouldExcludeErr(message) {
return ""
}
packet := NewPacket(message, append(append(interfaces, client.context.interfaces()...), &Message{message, nil})...)
eventID, _ := client.Capture(packet, tags)
return eventID
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"CaptureMessage",
"(",
"message",
"string",
",",
"tags",
"map",
"[",
"string",
"]",
"string",
",",
"interfaces",
"...",
"Interface",
")",
"string",
"{",
"if",
"client",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"client",
".",
"shouldExcludeErr",
"(",
"message",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"packet",
":=",
"NewPacket",
"(",
"message",
",",
"append",
"(",
"append",
"(",
"interfaces",
",",
"client",
".",
"context",
".",
"interfaces",
"(",
")",
"...",
")",
",",
"&",
"Message",
"{",
"message",
",",
"nil",
"}",
")",
"...",
")",
"\n",
"eventID",
",",
"_",
":=",
"client",
".",
"Capture",
"(",
"packet",
",",
"tags",
")",
"\n\n",
"return",
"eventID",
"\n",
"}"
]
| // CaptureMessage formats and delivers a string message to the Sentry server. | [
"CaptureMessage",
"formats",
"and",
"delivers",
"a",
"string",
"message",
"to",
"the",
"Sentry",
"server",
"."
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L691-L704 |
8,704 | getsentry/raven-go | client.go | CaptureMessageAndWait | func CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) string {
return DefaultClient.CaptureMessageAndWait(message, tags, interfaces...)
} | go | func CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) string {
return DefaultClient.CaptureMessageAndWait(message, tags, interfaces...)
} | [
"func",
"CaptureMessageAndWait",
"(",
"message",
"string",
",",
"tags",
"map",
"[",
"string",
"]",
"string",
",",
"interfaces",
"...",
"Interface",
")",
"string",
"{",
"return",
"DefaultClient",
".",
"CaptureMessageAndWait",
"(",
"message",
",",
"tags",
",",
"interfaces",
"...",
")",
"\n",
"}"
]
| // CaptureMessageAndWait is identical to CaptureMessage except it blocks and waits for the message to be sent. | [
"CaptureMessageAndWait",
"is",
"identical",
"to",
"CaptureMessage",
"except",
"it",
"blocks",
"and",
"waits",
"for",
"the",
"message",
"to",
"be",
"sent",
"."
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L731-L733 |
8,705 | getsentry/raven-go | client.go | CaptureError | func (client *Client) CaptureError(err error, tags map[string]string, interfaces ...Interface) string {
if client == nil {
return ""
}
if err == nil {
return ""
}
if client.shouldExcludeErr(err.Error()) {
return ""
}
extra := extractExtra(err)
cause := Cause(err)
packet := NewPacketWithExtra(err.Error(), extra, append(append(interfaces, client.context.interfaces()...), NewException(cause, GetOrNewStacktrace(cause, 1, 3, client.includePaths)))...)
eventID, _ := client.Capture(packet, tags)
return eventID
} | go | func (client *Client) CaptureError(err error, tags map[string]string, interfaces ...Interface) string {
if client == nil {
return ""
}
if err == nil {
return ""
}
if client.shouldExcludeErr(err.Error()) {
return ""
}
extra := extractExtra(err)
cause := Cause(err)
packet := NewPacketWithExtra(err.Error(), extra, append(append(interfaces, client.context.interfaces()...), NewException(cause, GetOrNewStacktrace(cause, 1, 3, client.includePaths)))...)
eventID, _ := client.Capture(packet, tags)
return eventID
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"CaptureError",
"(",
"err",
"error",
",",
"tags",
"map",
"[",
"string",
"]",
"string",
",",
"interfaces",
"...",
"Interface",
")",
"string",
"{",
"if",
"client",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"client",
".",
"shouldExcludeErr",
"(",
"err",
".",
"Error",
"(",
")",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"extra",
":=",
"extractExtra",
"(",
"err",
")",
"\n",
"cause",
":=",
"Cause",
"(",
"err",
")",
"\n\n",
"packet",
":=",
"NewPacketWithExtra",
"(",
"err",
".",
"Error",
"(",
")",
",",
"extra",
",",
"append",
"(",
"append",
"(",
"interfaces",
",",
"client",
".",
"context",
".",
"interfaces",
"(",
")",
"...",
")",
",",
"NewException",
"(",
"cause",
",",
"GetOrNewStacktrace",
"(",
"cause",
",",
"1",
",",
"3",
",",
"client",
".",
"includePaths",
")",
")",
")",
"...",
")",
"\n",
"eventID",
",",
"_",
":=",
"client",
".",
"Capture",
"(",
"packet",
",",
"tags",
")",
"\n\n",
"return",
"eventID",
"\n",
"}"
]
| // CaptureError formats and delivers an error to the Sentry server.
// Adds a stacktrace to the packet, excluding the call to this method. | [
"CaptureError",
"formats",
"and",
"delivers",
"an",
"error",
"to",
"the",
"Sentry",
"server",
".",
"Adds",
"a",
"stacktrace",
"to",
"the",
"packet",
"excluding",
"the",
"call",
"to",
"this",
"method",
"."
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L737-L757 |
8,706 | getsentry/raven-go | client.go | CaptureErrorAndWait | func CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string {
return DefaultClient.CaptureErrorAndWait(err, tags, interfaces...)
} | go | func CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string {
return DefaultClient.CaptureErrorAndWait(err, tags, interfaces...)
} | [
"func",
"CaptureErrorAndWait",
"(",
"err",
"error",
",",
"tags",
"map",
"[",
"string",
"]",
"string",
",",
"interfaces",
"...",
"Interface",
")",
"string",
"{",
"return",
"DefaultClient",
".",
"CaptureErrorAndWait",
"(",
"err",
",",
"tags",
",",
"interfaces",
"...",
")",
"\n",
"}"
]
| // CaptureErrorAndWait is identical to CaptureError, except it blocks and assures that the event was sent | [
"CaptureErrorAndWait",
"is",
"identical",
"to",
"CaptureError",
"except",
"it",
"blocks",
"and",
"assures",
"that",
"the",
"event",
"was",
"sent"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L788-L790 |
8,707 | getsentry/raven-go | client.go | CapturePanicAndWait | func CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (interface{}, string) {
return DefaultClient.CapturePanicAndWait(f, tags, interfaces...)
} | go | func CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (interface{}, string) {
return DefaultClient.CapturePanicAndWait(f, tags, interfaces...)
} | [
"func",
"CapturePanicAndWait",
"(",
"f",
"func",
"(",
")",
",",
"tags",
"map",
"[",
"string",
"]",
"string",
",",
"interfaces",
"...",
"Interface",
")",
"(",
"interface",
"{",
"}",
",",
"string",
")",
"{",
"return",
"DefaultClient",
".",
"CapturePanicAndWait",
"(",
"f",
",",
"tags",
",",
"interfaces",
"...",
")",
"\n",
"}"
]
| // CapturePanicAndWait is identical to CapturePanic, except it blocks and assures that the event was sent | [
"CapturePanicAndWait",
"is",
"identical",
"to",
"CapturePanic",
"except",
"it",
"blocks",
"and",
"assures",
"that",
"the",
"event",
"was",
"sent"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L868-L870 |
8,708 | getsentry/raven-go | client.go | URL | func (client *Client) URL() string {
client.mu.RLock()
defer client.mu.RUnlock()
return client.url
} | go | func (client *Client) URL() string {
client.mu.RLock()
defer client.mu.RUnlock()
return client.url
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"URL",
"(",
")",
"string",
"{",
"client",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"client",
".",
"url",
"\n",
"}"
]
| // URL returns configured url of given client | [
"URL",
"returns",
"configured",
"url",
"of",
"given",
"client"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L889-L894 |
8,709 | getsentry/raven-go | client.go | ProjectID | func (client *Client) ProjectID() string {
client.mu.RLock()
defer client.mu.RUnlock()
return client.projectID
} | go | func (client *Client) ProjectID() string {
client.mu.RLock()
defer client.mu.RUnlock()
return client.projectID
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"ProjectID",
"(",
")",
"string",
"{",
"client",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"client",
".",
"projectID",
"\n",
"}"
]
| // ProjectID returns configured ProjectID of given client | [
"ProjectID",
"returns",
"configured",
"ProjectID",
"of",
"given",
"client"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L900-L905 |
8,710 | getsentry/raven-go | client.go | Release | func (client *Client) Release() string {
client.mu.RLock()
defer client.mu.RUnlock()
return client.release
} | go | func (client *Client) Release() string {
client.mu.RLock()
defer client.mu.RUnlock()
return client.release
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"Release",
"(",
")",
"string",
"{",
"client",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"client",
".",
"release",
"\n",
"}"
]
| // Release returns configured Release of given client | [
"Release",
"returns",
"configured",
"Release",
"of",
"given",
"client"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L911-L916 |
8,711 | getsentry/raven-go | client.go | IncludePaths | func (client *Client) IncludePaths() []string {
client.mu.RLock()
defer client.mu.RUnlock()
return client.includePaths
} | go | func (client *Client) IncludePaths() []string {
client.mu.RLock()
defer client.mu.RUnlock()
return client.includePaths
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"IncludePaths",
"(",
")",
"[",
"]",
"string",
"{",
"client",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"client",
".",
"includePaths",
"\n",
"}"
]
| // IncludePaths returns configured includePaths of given client | [
"IncludePaths",
"returns",
"configured",
"includePaths",
"of",
"given",
"client"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L922-L927 |
8,712 | getsentry/raven-go | client.go | SetIncludePaths | func (client *Client) SetIncludePaths(p []string) {
client.mu.Lock()
defer client.mu.Unlock()
client.includePaths = p
} | go | func (client *Client) SetIncludePaths(p []string) {
client.mu.Lock()
defer client.mu.Unlock()
client.includePaths = p
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"SetIncludePaths",
"(",
"p",
"[",
"]",
"string",
")",
"{",
"client",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"client",
".",
"includePaths",
"=",
"p",
"\n",
"}"
]
| // SetIncludePaths updates includePaths config on given client | [
"SetIncludePaths",
"updates",
"includePaths",
"config",
"on",
"given",
"client"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L933-L938 |
8,713 | getsentry/raven-go | client.go | SetUserContext | func (client *Client) SetUserContext(u *User) {
client.mu.Lock()
defer client.mu.Unlock()
client.context.setUser(u)
} | go | func (client *Client) SetUserContext(u *User) {
client.mu.Lock()
defer client.mu.Unlock()
client.context.setUser(u)
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"SetUserContext",
"(",
"u",
"*",
"User",
")",
"{",
"client",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"client",
".",
"context",
".",
"setUser",
"(",
"u",
")",
"\n",
"}"
]
| // SetUserContext updates User of Context interface on given client | [
"SetUserContext",
"updates",
"User",
"of",
"Context",
"interface",
"on",
"given",
"client"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L944-L948 |
8,714 | getsentry/raven-go | client.go | SetHttpContext | func (client *Client) SetHttpContext(h *Http) {
client.mu.Lock()
defer client.mu.Unlock()
client.context.setHttp(h)
} | go | func (client *Client) SetHttpContext(h *Http) {
client.mu.Lock()
defer client.mu.Unlock()
client.context.setHttp(h)
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"SetHttpContext",
"(",
"h",
"*",
"Http",
")",
"{",
"client",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"client",
".",
"context",
".",
"setHttp",
"(",
"h",
")",
"\n",
"}"
]
| // SetHttpContext updates Http of Context interface on given client | [
"SetHttpContext",
"updates",
"Http",
"of",
"Context",
"interface",
"on",
"given",
"client"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L951-L955 |
8,715 | getsentry/raven-go | client.go | SetTagsContext | func (client *Client) SetTagsContext(t map[string]string) {
client.mu.Lock()
defer client.mu.Unlock()
client.context.setTags(t)
} | go | func (client *Client) SetTagsContext(t map[string]string) {
client.mu.Lock()
defer client.mu.Unlock()
client.context.setTags(t)
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"SetTagsContext",
"(",
"t",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"client",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"client",
".",
"context",
".",
"setTags",
"(",
"t",
")",
"\n",
"}"
]
| // SetTagsContext updates Tags of Context interface on given client | [
"SetTagsContext",
"updates",
"Tags",
"of",
"Context",
"interface",
"on",
"given",
"client"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L958-L962 |
8,716 | getsentry/raven-go | client.go | ClearContext | func (client *Client) ClearContext() {
client.mu.Lock()
defer client.mu.Unlock()
client.context.clear()
} | go | func (client *Client) ClearContext() {
client.mu.Lock()
defer client.mu.Unlock()
client.context.clear()
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"ClearContext",
"(",
")",
"{",
"client",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"client",
".",
"context",
".",
"clear",
"(",
")",
"\n",
"}"
]
| // ClearContext clears Context interface on given client by removing tags, user and request information | [
"ClearContext",
"clears",
"Context",
"interface",
"on",
"given",
"client",
"by",
"removing",
"tags",
"user",
"and",
"request",
"information"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L965-L969 |
8,717 | getsentry/raven-go | client.go | Send | func (t *HTTPTransport) Send(url, authHeader string, packet *Packet) error {
if url == "" {
return nil
}
body, contentType, err := serializedPacket(packet)
if err != nil {
return fmt.Errorf("raven: error serializing packet: %v", err)
}
req, err := http.NewRequest("POST", url, body)
if err != nil {
return fmt.Errorf("raven: can't create new request: %v", err)
}
req.Header.Set("X-Sentry-Auth", authHeader)
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", contentType)
res, err := t.Do(req)
if err != nil {
return err
}
// Response body needs to be drained and closed in order for TCP connection to stay opened (via keep-alive) and reused
_, err = io.Copy(ioutil.Discard, res.Body)
if err != nil {
debugLogger.Println("Error while reading response body", res)
}
err = res.Body.Close()
if err != nil {
debugLogger.Println("Error while closing response body", err)
}
if res.StatusCode != 200 {
return fmt.Errorf("raven: got http status %d - x-sentry-error: %s", res.StatusCode, res.Header.Get("X-Sentry-Error"))
}
return nil
} | go | func (t *HTTPTransport) Send(url, authHeader string, packet *Packet) error {
if url == "" {
return nil
}
body, contentType, err := serializedPacket(packet)
if err != nil {
return fmt.Errorf("raven: error serializing packet: %v", err)
}
req, err := http.NewRequest("POST", url, body)
if err != nil {
return fmt.Errorf("raven: can't create new request: %v", err)
}
req.Header.Set("X-Sentry-Auth", authHeader)
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", contentType)
res, err := t.Do(req)
if err != nil {
return err
}
// Response body needs to be drained and closed in order for TCP connection to stay opened (via keep-alive) and reused
_, err = io.Copy(ioutil.Discard, res.Body)
if err != nil {
debugLogger.Println("Error while reading response body", res)
}
err = res.Body.Close()
if err != nil {
debugLogger.Println("Error while closing response body", err)
}
if res.StatusCode != 200 {
return fmt.Errorf("raven: got http status %d - x-sentry-error: %s", res.StatusCode, res.Header.Get("X-Sentry-Error"))
}
return nil
} | [
"func",
"(",
"t",
"*",
"HTTPTransport",
")",
"Send",
"(",
"url",
",",
"authHeader",
"string",
",",
"packet",
"*",
"Packet",
")",
"error",
"{",
"if",
"url",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"body",
",",
"contentType",
",",
"err",
":=",
"serializedPacket",
"(",
"packet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"authHeader",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"userAgent",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"contentType",
")",
"\n\n",
"res",
",",
"err",
":=",
"t",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Response body needs to be drained and closed in order for TCP connection to stay opened (via keep-alive) and reused",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"ioutil",
".",
"Discard",
",",
"res",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"debugLogger",
".",
"Println",
"(",
"\"",
"\"",
",",
"res",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"res",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"debugLogger",
".",
"Println",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"res",
".",
"StatusCode",
"!=",
"200",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"StatusCode",
",",
"res",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Send uses HTTPTransport to send a Packet to configured Sentry's DSN endpoint | [
"Send",
"uses",
"HTTPTransport",
"to",
"send",
"a",
"Packet",
"to",
"configured",
"Sentry",
"s",
"DSN",
"endpoint"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/client.go#L990-L1027 |
8,718 | getsentry/raven-go | http.go | NewHttp | func NewHttp(req *http.Request) *Http {
proto := "http"
if req.TLS != nil || req.Header.Get("X-Forwarded-Proto") == "https" {
proto = "https"
}
h := &Http{
Method: req.Method,
Cookies: req.Header.Get("Cookie"),
Query: sanitizeQuery(req.URL.Query()).Encode(),
URL: proto + "://" + req.Host + req.URL.Path,
Headers: make(map[string]string, len(req.Header)),
}
if addr, port, err := net.SplitHostPort(req.RemoteAddr); err == nil {
h.Env = map[string]string{"REMOTE_ADDR": addr, "REMOTE_PORT": port}
}
for k, v := range req.Header {
h.Headers[k] = strings.Join(v, ",")
}
h.Headers["Host"] = req.Host
return h
} | go | func NewHttp(req *http.Request) *Http {
proto := "http"
if req.TLS != nil || req.Header.Get("X-Forwarded-Proto") == "https" {
proto = "https"
}
h := &Http{
Method: req.Method,
Cookies: req.Header.Get("Cookie"),
Query: sanitizeQuery(req.URL.Query()).Encode(),
URL: proto + "://" + req.Host + req.URL.Path,
Headers: make(map[string]string, len(req.Header)),
}
if addr, port, err := net.SplitHostPort(req.RemoteAddr); err == nil {
h.Env = map[string]string{"REMOTE_ADDR": addr, "REMOTE_PORT": port}
}
for k, v := range req.Header {
h.Headers[k] = strings.Join(v, ",")
}
h.Headers["Host"] = req.Host
return h
} | [
"func",
"NewHttp",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"*",
"Http",
"{",
"proto",
":=",
"\"",
"\"",
"\n",
"if",
"req",
".",
"TLS",
"!=",
"nil",
"||",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"{",
"proto",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"h",
":=",
"&",
"Http",
"{",
"Method",
":",
"req",
".",
"Method",
",",
"Cookies",
":",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"Query",
":",
"sanitizeQuery",
"(",
"req",
".",
"URL",
".",
"Query",
"(",
")",
")",
".",
"Encode",
"(",
")",
",",
"URL",
":",
"proto",
"+",
"\"",
"\"",
"+",
"req",
".",
"Host",
"+",
"req",
".",
"URL",
".",
"Path",
",",
"Headers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"req",
".",
"Header",
")",
")",
",",
"}",
"\n",
"if",
"addr",
",",
"port",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"req",
".",
"RemoteAddr",
")",
";",
"err",
"==",
"nil",
"{",
"h",
".",
"Env",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"addr",
",",
"\"",
"\"",
":",
"port",
"}",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"req",
".",
"Header",
"{",
"h",
".",
"Headers",
"[",
"k",
"]",
"=",
"strings",
".",
"Join",
"(",
"v",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"h",
".",
"Headers",
"[",
"\"",
"\"",
"]",
"=",
"req",
".",
"Host",
"\n",
"return",
"h",
"\n",
"}"
]
| // NewHttp creates new HTTP object that follows Sentry's HTTP interface spec and will be attached to the Packet | [
"NewHttp",
"creates",
"new",
"HTTP",
"object",
"that",
"follows",
"Sentry",
"s",
"HTTP",
"interface",
"spec",
"and",
"will",
"be",
"attached",
"to",
"the",
"Packet"
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/http.go#L14-L34 |
8,719 | getsentry/raven-go | writer.go | Write | func (w *Writer) Write(p []byte) (int, error) {
message := string(p)
packet := NewPacket(message, &Message{message, nil})
packet.Level = w.Level
packet.Logger = w.Logger
w.Client.Capture(packet, nil)
return len(p), nil
} | go | func (w *Writer) Write(p []byte) (int, error) {
message := string(p)
packet := NewPacket(message, &Message{message, nil})
packet.Level = w.Level
packet.Logger = w.Logger
w.Client.Capture(packet, nil)
return len(p), nil
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"message",
":=",
"string",
"(",
"p",
")",
"\n\n",
"packet",
":=",
"NewPacket",
"(",
"message",
",",
"&",
"Message",
"{",
"message",
",",
"nil",
"}",
")",
"\n",
"packet",
".",
"Level",
"=",
"w",
".",
"Level",
"\n",
"packet",
".",
"Logger",
"=",
"w",
".",
"Logger",
"\n",
"w",
".",
"Client",
".",
"Capture",
"(",
"packet",
",",
"nil",
")",
"\n\n",
"return",
"len",
"(",
"p",
")",
",",
"nil",
"\n",
"}"
]
| // Write formats the byte slice p into a string, and sends a message to
// Sentry at the severity level indicated by the Writer w. | [
"Write",
"formats",
"the",
"byte",
"slice",
"p",
"into",
"a",
"string",
"and",
"sends",
"a",
"message",
"to",
"Sentry",
"at",
"the",
"severity",
"level",
"indicated",
"by",
"the",
"Writer",
"w",
"."
]
| 919484f041ea21e7e27be291cee1d6af7bc98864 | https://github.com/getsentry/raven-go/blob/919484f041ea21e7e27be291cee1d6af7bc98864/writer.go#L12-L21 |
8,720 | cornelk/hashmap | util.go | roundUpPower2 | func roundUpPower2(i uintptr) uintptr {
i--
i |= i >> 1
i |= i >> 2
i |= i >> 4
i |= i >> 8
i |= i >> 16
i |= i >> 32
i++
return i
} | go | func roundUpPower2(i uintptr) uintptr {
i--
i |= i >> 1
i |= i >> 2
i |= i >> 4
i |= i >> 8
i |= i >> 16
i |= i >> 32
i++
return i
} | [
"func",
"roundUpPower2",
"(",
"i",
"uintptr",
")",
"uintptr",
"{",
"i",
"--",
"\n",
"i",
"|=",
"i",
">>",
"1",
"\n",
"i",
"|=",
"i",
">>",
"2",
"\n",
"i",
"|=",
"i",
">>",
"4",
"\n",
"i",
"|=",
"i",
">>",
"8",
"\n",
"i",
"|=",
"i",
">>",
"16",
"\n",
"i",
"|=",
"i",
">>",
"32",
"\n",
"i",
"++",
"\n",
"return",
"i",
"\n",
"}"
]
| // roundUpPower2 rounds a number to the next power of 2. | [
"roundUpPower2",
"rounds",
"a",
"number",
"to",
"the",
"next",
"power",
"of",
"2",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/util.go#L22-L32 |
8,721 | cornelk/hashmap | util.go | log2 | func log2(i uintptr) uintptr {
var n, p uintptr
for p = 1; p < i; p += p {
n++
}
return n
} | go | func log2(i uintptr) uintptr {
var n, p uintptr
for p = 1; p < i; p += p {
n++
}
return n
} | [
"func",
"log2",
"(",
"i",
"uintptr",
")",
"uintptr",
"{",
"var",
"n",
",",
"p",
"uintptr",
"\n",
"for",
"p",
"=",
"1",
";",
"p",
"<",
"i",
";",
"p",
"+=",
"p",
"{",
"n",
"++",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
]
| // log2 computes the binary logarithm of x, rounded up to the next integer. | [
"log2",
"computes",
"the",
"binary",
"logarithm",
"of",
"x",
"rounded",
"up",
"to",
"the",
"next",
"integer",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/util.go#L35-L41 |
8,722 | cornelk/hashmap | util.go | getKeyHash | func getKeyHash(key interface{}) uintptr {
switch x := key.(type) {
case string:
return getStringHash(x)
case []byte:
return uintptr(siphash.Hash(sipHashKey1, sipHashKey2, x))
case int:
return getUintptrHash(uintptr(x))
case int8:
return getUintptrHash(uintptr(x))
case int16:
return getUintptrHash(uintptr(x))
case int32:
return getUintptrHash(uintptr(x))
case int64:
return getUintptrHash(uintptr(x))
case uint:
return getUintptrHash(uintptr(x))
case uint8:
return getUintptrHash(uintptr(x))
case uint16:
return getUintptrHash(uintptr(x))
case uint32:
return getUintptrHash(uintptr(x))
case uint64:
return getUintptrHash(uintptr(x))
case uintptr:
return getUintptrHash(x)
}
panic(fmt.Errorf("unsupported key type %T", key))
} | go | func getKeyHash(key interface{}) uintptr {
switch x := key.(type) {
case string:
return getStringHash(x)
case []byte:
return uintptr(siphash.Hash(sipHashKey1, sipHashKey2, x))
case int:
return getUintptrHash(uintptr(x))
case int8:
return getUintptrHash(uintptr(x))
case int16:
return getUintptrHash(uintptr(x))
case int32:
return getUintptrHash(uintptr(x))
case int64:
return getUintptrHash(uintptr(x))
case uint:
return getUintptrHash(uintptr(x))
case uint8:
return getUintptrHash(uintptr(x))
case uint16:
return getUintptrHash(uintptr(x))
case uint32:
return getUintptrHash(uintptr(x))
case uint64:
return getUintptrHash(uintptr(x))
case uintptr:
return getUintptrHash(x)
}
panic(fmt.Errorf("unsupported key type %T", key))
} | [
"func",
"getKeyHash",
"(",
"key",
"interface",
"{",
"}",
")",
"uintptr",
"{",
"switch",
"x",
":=",
"key",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"getStringHash",
"(",
"x",
")",
"\n",
"case",
"[",
"]",
"byte",
":",
"return",
"uintptr",
"(",
"siphash",
".",
"Hash",
"(",
"sipHashKey1",
",",
"sipHashKey2",
",",
"x",
")",
")",
"\n",
"case",
"int",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"int8",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"int16",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"int32",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"int64",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"uint",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"uint8",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"uint16",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"uint32",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"uint64",
":",
"return",
"getUintptrHash",
"(",
"uintptr",
"(",
"x",
")",
")",
"\n",
"case",
"uintptr",
":",
"return",
"getUintptrHash",
"(",
"x",
")",
"\n",
"}",
"\n",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
")",
"\n",
"}"
]
| // getKeyHash returns a hash for the key. Only string and number types are supported. | [
"getKeyHash",
"returns",
"a",
"hash",
"for",
"the",
"key",
".",
"Only",
"string",
"and",
"number",
"types",
"are",
"supported",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/util.go#L44-L74 |
8,723 | cornelk/hashmap | hashmap.go | New | func New(size uintptr) *HashMap {
m := &HashMap{}
m.allocate(size)
return m
} | go | func New(size uintptr) *HashMap {
m := &HashMap{}
m.allocate(size)
return m
} | [
"func",
"New",
"(",
"size",
"uintptr",
")",
"*",
"HashMap",
"{",
"m",
":=",
"&",
"HashMap",
"{",
"}",
"\n",
"m",
".",
"allocate",
"(",
"size",
")",
"\n",
"return",
"m",
"\n",
"}"
]
| // New returns a new HashMap instance with a specific initialization size. | [
"New",
"returns",
"a",
"new",
"HashMap",
"instance",
"with",
"a",
"specific",
"initialization",
"size",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L41-L45 |
8,724 | cornelk/hashmap | hashmap.go | Fillrate | func (m *HashMap) Fillrate() uintptr {
data := m.mapData()
count := atomic.LoadUintptr(&data.count)
l := uintptr(len(data.index))
return (count * 100) / l
} | go | func (m *HashMap) Fillrate() uintptr {
data := m.mapData()
count := atomic.LoadUintptr(&data.count)
l := uintptr(len(data.index))
return (count * 100) / l
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"Fillrate",
"(",
")",
"uintptr",
"{",
"data",
":=",
"m",
".",
"mapData",
"(",
")",
"\n",
"count",
":=",
"atomic",
".",
"LoadUintptr",
"(",
"&",
"data",
".",
"count",
")",
"\n",
"l",
":=",
"uintptr",
"(",
"len",
"(",
"data",
".",
"index",
")",
")",
"\n",
"return",
"(",
"count",
"*",
"100",
")",
"/",
"l",
"\n",
"}"
]
| // Fillrate returns the fill rate of the map as an percentage integer. | [
"Fillrate",
"returns",
"the",
"fill",
"rate",
"of",
"the",
"map",
"as",
"an",
"percentage",
"integer",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L72-L77 |
8,725 | cornelk/hashmap | hashmap.go | DelHashedKey | func (m *HashMap) DelHashedKey(hashedKey uintptr) {
list := m.list()
if list == nil {
return
}
_, element := m.indexElement(hashedKey)
if element == nil {
return
}
m.deleteElement(element)
list.Delete(element)
} | go | func (m *HashMap) DelHashedKey(hashedKey uintptr) {
list := m.list()
if list == nil {
return
}
_, element := m.indexElement(hashedKey)
if element == nil {
return
}
m.deleteElement(element)
list.Delete(element)
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"DelHashedKey",
"(",
"hashedKey",
"uintptr",
")",
"{",
"list",
":=",
"m",
".",
"list",
"(",
")",
"\n",
"if",
"list",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"_",
",",
"element",
":=",
"m",
".",
"indexElement",
"(",
"hashedKey",
")",
"\n",
"if",
"element",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"m",
".",
"deleteElement",
"(",
"element",
")",
"\n",
"list",
".",
"Delete",
"(",
"element",
")",
"\n",
"}"
]
| // DelHashedKey deletes the hashed key from the map. | [
"DelHashedKey",
"deletes",
"the",
"hashed",
"key",
"from",
"the",
"map",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L154-L167 |
8,726 | cornelk/hashmap | hashmap.go | deleteElement | func (m *HashMap) deleteElement(element *ListElement) {
for {
data := m.mapData()
index := element.keyHash >> data.keyshifts
ptr := (*unsafe.Pointer)(unsafe.Pointer(uintptr(data.data) + index*intSizeBytes))
next := element.Next()
if next != nil && element.keyHash>>data.keyshifts != index {
next = nil // do not set index to next item if it's not the same slice index
}
atomic.CompareAndSwapPointer(ptr, unsafe.Pointer(element), unsafe.Pointer(next))
currentdata := m.mapData()
if data == currentdata { // check that no resize happened
break
}
}
} | go | func (m *HashMap) deleteElement(element *ListElement) {
for {
data := m.mapData()
index := element.keyHash >> data.keyshifts
ptr := (*unsafe.Pointer)(unsafe.Pointer(uintptr(data.data) + index*intSizeBytes))
next := element.Next()
if next != nil && element.keyHash>>data.keyshifts != index {
next = nil // do not set index to next item if it's not the same slice index
}
atomic.CompareAndSwapPointer(ptr, unsafe.Pointer(element), unsafe.Pointer(next))
currentdata := m.mapData()
if data == currentdata { // check that no resize happened
break
}
}
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"deleteElement",
"(",
"element",
"*",
"ListElement",
")",
"{",
"for",
"{",
"data",
":=",
"m",
".",
"mapData",
"(",
")",
"\n",
"index",
":=",
"element",
".",
"keyHash",
">>",
"data",
".",
"keyshifts",
"\n",
"ptr",
":=",
"(",
"*",
"unsafe",
".",
"Pointer",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"data",
".",
"data",
")",
"+",
"index",
"*",
"intSizeBytes",
")",
")",
"\n\n",
"next",
":=",
"element",
".",
"Next",
"(",
")",
"\n",
"if",
"next",
"!=",
"nil",
"&&",
"element",
".",
"keyHash",
">>",
"data",
".",
"keyshifts",
"!=",
"index",
"{",
"next",
"=",
"nil",
"// do not set index to next item if it's not the same slice index",
"\n",
"}",
"\n",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"ptr",
",",
"unsafe",
".",
"Pointer",
"(",
"element",
")",
",",
"unsafe",
".",
"Pointer",
"(",
"next",
")",
")",
"\n\n",
"currentdata",
":=",
"m",
".",
"mapData",
"(",
")",
"\n",
"if",
"data",
"==",
"currentdata",
"{",
"// check that no resize happened",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // deleteElement deletes an element from index | [
"deleteElement",
"deletes",
"an",
"element",
"from",
"index"
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L170-L187 |
8,727 | cornelk/hashmap | hashmap.go | Insert | func (m *HashMap) Insert(key interface{}, value interface{}) bool {
h := getKeyHash(key)
element := &ListElement{
key: key,
keyHash: h,
value: unsafe.Pointer(&value),
}
return m.insertListElement(element, false)
} | go | func (m *HashMap) Insert(key interface{}, value interface{}) bool {
h := getKeyHash(key)
element := &ListElement{
key: key,
keyHash: h,
value: unsafe.Pointer(&value),
}
return m.insertListElement(element, false)
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"Insert",
"(",
"key",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"h",
":=",
"getKeyHash",
"(",
"key",
")",
"\n",
"element",
":=",
"&",
"ListElement",
"{",
"key",
":",
"key",
",",
"keyHash",
":",
"h",
",",
"value",
":",
"unsafe",
".",
"Pointer",
"(",
"&",
"value",
")",
",",
"}",
"\n",
"return",
"m",
".",
"insertListElement",
"(",
"element",
",",
"false",
")",
"\n",
"}"
]
| // Insert sets the value under the specified key to the map if it does not exist yet.
// If a resizing operation is happening concurrently while calling Set, the item might show up in the map only after the resize operation is finished.
// Returns true if the item was inserted or false if it existed. | [
"Insert",
"sets",
"the",
"value",
"under",
"the",
"specified",
"key",
"to",
"the",
"map",
"if",
"it",
"does",
"not",
"exist",
"yet",
".",
"If",
"a",
"resizing",
"operation",
"is",
"happening",
"concurrently",
"while",
"calling",
"Set",
"the",
"item",
"might",
"show",
"up",
"in",
"the",
"map",
"only",
"after",
"the",
"resize",
"operation",
"is",
"finished",
".",
"Returns",
"true",
"if",
"the",
"item",
"was",
"inserted",
"or",
"false",
"if",
"it",
"existed",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L192-L200 |
8,728 | cornelk/hashmap | hashmap.go | Set | func (m *HashMap) Set(key interface{}, value interface{}) {
h := getKeyHash(key)
element := &ListElement{
key: key,
keyHash: h,
value: unsafe.Pointer(&value),
}
m.insertListElement(element, true)
} | go | func (m *HashMap) Set(key interface{}, value interface{}) {
h := getKeyHash(key)
element := &ListElement{
key: key,
keyHash: h,
value: unsafe.Pointer(&value),
}
m.insertListElement(element, true)
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"Set",
"(",
"key",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"h",
":=",
"getKeyHash",
"(",
"key",
")",
"\n",
"element",
":=",
"&",
"ListElement",
"{",
"key",
":",
"key",
",",
"keyHash",
":",
"h",
",",
"value",
":",
"unsafe",
".",
"Pointer",
"(",
"&",
"value",
")",
",",
"}",
"\n",
"m",
".",
"insertListElement",
"(",
"element",
",",
"true",
")",
"\n",
"}"
]
| // Set sets the value under the specified key to the map. An existing item for this key will be overwritten.
// If a resizing operation is happening concurrently while calling Set, the item might show up in the map only after the resize operation is finished. | [
"Set",
"sets",
"the",
"value",
"under",
"the",
"specified",
"key",
"to",
"the",
"map",
".",
"An",
"existing",
"item",
"for",
"this",
"key",
"will",
"be",
"overwritten",
".",
"If",
"a",
"resizing",
"operation",
"is",
"happening",
"concurrently",
"while",
"calling",
"Set",
"the",
"item",
"might",
"show",
"up",
"in",
"the",
"map",
"only",
"after",
"the",
"resize",
"operation",
"is",
"finished",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L204-L212 |
8,729 | cornelk/hashmap | hashmap.go | SetHashedKey | func (m *HashMap) SetHashedKey(hashedKey uintptr, value interface{}) {
element := &ListElement{
key: hashedKey,
keyHash: hashedKey,
value: unsafe.Pointer(&value),
}
m.insertListElement(element, true)
} | go | func (m *HashMap) SetHashedKey(hashedKey uintptr, value interface{}) {
element := &ListElement{
key: hashedKey,
keyHash: hashedKey,
value: unsafe.Pointer(&value),
}
m.insertListElement(element, true)
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"SetHashedKey",
"(",
"hashedKey",
"uintptr",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"element",
":=",
"&",
"ListElement",
"{",
"key",
":",
"hashedKey",
",",
"keyHash",
":",
"hashedKey",
",",
"value",
":",
"unsafe",
".",
"Pointer",
"(",
"&",
"value",
")",
",",
"}",
"\n",
"m",
".",
"insertListElement",
"(",
"element",
",",
"true",
")",
"\n",
"}"
]
| // SetHashedKey sets the value under the specified hash key to the map. An existing item for this key will be overwritten.
// You can use this function if your keys are already hashes and you want to avoid another hashing of the key.
// Do not use non hashes as keys for this function, the performance would decrease!
// If a resizing operation is happening concurrently while calling Set, the item might show up in the map only after the resize operation is finished. | [
"SetHashedKey",
"sets",
"the",
"value",
"under",
"the",
"specified",
"hash",
"key",
"to",
"the",
"map",
".",
"An",
"existing",
"item",
"for",
"this",
"key",
"will",
"be",
"overwritten",
".",
"You",
"can",
"use",
"this",
"function",
"if",
"your",
"keys",
"are",
"already",
"hashes",
"and",
"you",
"want",
"to",
"avoid",
"another",
"hashing",
"of",
"the",
"key",
".",
"Do",
"not",
"use",
"non",
"hashes",
"as",
"keys",
"for",
"this",
"function",
"the",
"performance",
"would",
"decrease!",
"If",
"a",
"resizing",
"operation",
"is",
"happening",
"concurrently",
"while",
"calling",
"Set",
"the",
"item",
"might",
"show",
"up",
"in",
"the",
"map",
"only",
"after",
"the",
"resize",
"operation",
"is",
"finished",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L218-L225 |
8,730 | cornelk/hashmap | hashmap.go | CasHashedKey | func (m *HashMap) CasHashedKey(hashedKey uintptr, from, to interface{}) bool {
data, existing := m.indexElement(hashedKey)
if data == nil {
return false
}
list := m.list()
if list == nil {
return false
}
element := &ListElement{
key: hashedKey,
keyHash: hashedKey,
value: unsafe.Pointer(&to),
}
return list.Cas(element, from, existing)
} | go | func (m *HashMap) CasHashedKey(hashedKey uintptr, from, to interface{}) bool {
data, existing := m.indexElement(hashedKey)
if data == nil {
return false
}
list := m.list()
if list == nil {
return false
}
element := &ListElement{
key: hashedKey,
keyHash: hashedKey,
value: unsafe.Pointer(&to),
}
return list.Cas(element, from, existing)
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"CasHashedKey",
"(",
"hashedKey",
"uintptr",
",",
"from",
",",
"to",
"interface",
"{",
"}",
")",
"bool",
"{",
"data",
",",
"existing",
":=",
"m",
".",
"indexElement",
"(",
"hashedKey",
")",
"\n",
"if",
"data",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"list",
":=",
"m",
".",
"list",
"(",
")",
"\n",
"if",
"list",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"element",
":=",
"&",
"ListElement",
"{",
"key",
":",
"hashedKey",
",",
"keyHash",
":",
"hashedKey",
",",
"value",
":",
"unsafe",
".",
"Pointer",
"(",
"&",
"to",
")",
",",
"}",
"\n",
"return",
"list",
".",
"Cas",
"(",
"element",
",",
"from",
",",
"existing",
")",
"\n",
"}"
]
| // CasHashedKey performs a compare and swap operation sets the value under the specified hash key to the map. An existing item for this key will be overwritten. | [
"CasHashedKey",
"performs",
"a",
"compare",
"and",
"swap",
"operation",
"sets",
"the",
"value",
"under",
"the",
"specified",
"hash",
"key",
"to",
"the",
"map",
".",
"An",
"existing",
"item",
"for",
"this",
"key",
"will",
"be",
"overwritten",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L261-L277 |
8,731 | cornelk/hashmap | hashmap.go | Cas | func (m *HashMap) Cas(key, from, to interface{}) bool {
h := getKeyHash(key)
return m.CasHashedKey(h, from, to)
} | go | func (m *HashMap) Cas(key, from, to interface{}) bool {
h := getKeyHash(key)
return m.CasHashedKey(h, from, to)
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"Cas",
"(",
"key",
",",
"from",
",",
"to",
"interface",
"{",
"}",
")",
"bool",
"{",
"h",
":=",
"getKeyHash",
"(",
"key",
")",
"\n",
"return",
"m",
".",
"CasHashedKey",
"(",
"h",
",",
"from",
",",
"to",
")",
"\n",
"}"
]
| // Cas performs a compare and swap operation sets the value under the specified hash key to the map. An existing item for this key will be overwritten. | [
"Cas",
"performs",
"a",
"compare",
"and",
"swap",
"operation",
"sets",
"the",
"value",
"under",
"the",
"specified",
"hash",
"key",
"to",
"the",
"map",
".",
"An",
"existing",
"item",
"for",
"this",
"key",
"will",
"be",
"overwritten",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L280-L283 |
8,732 | cornelk/hashmap | hashmap.go | addItemToIndex | func (mapData *hashMapData) addItemToIndex(item *ListElement) uintptr {
index := item.keyHash >> mapData.keyshifts
ptr := (*unsafe.Pointer)(unsafe.Pointer(uintptr(mapData.data) + index*intSizeBytes))
for { // loop until the smallest key hash is in the index
element := (*ListElement)(atomic.LoadPointer(ptr)) // get the current item in the index
if element == nil { // no item yet at this index
if atomic.CompareAndSwapPointer(ptr, nil, unsafe.Pointer(item)) {
return atomic.AddUintptr(&mapData.count, 1)
}
continue // a new item was inserted concurrently, retry
}
if item.keyHash < element.keyHash {
// the new item is the smallest for this index?
if !atomic.CompareAndSwapPointer(ptr, unsafe.Pointer(element), unsafe.Pointer(item)) {
continue // a new item was inserted concurrently, retry
}
}
return 0
}
} | go | func (mapData *hashMapData) addItemToIndex(item *ListElement) uintptr {
index := item.keyHash >> mapData.keyshifts
ptr := (*unsafe.Pointer)(unsafe.Pointer(uintptr(mapData.data) + index*intSizeBytes))
for { // loop until the smallest key hash is in the index
element := (*ListElement)(atomic.LoadPointer(ptr)) // get the current item in the index
if element == nil { // no item yet at this index
if atomic.CompareAndSwapPointer(ptr, nil, unsafe.Pointer(item)) {
return atomic.AddUintptr(&mapData.count, 1)
}
continue // a new item was inserted concurrently, retry
}
if item.keyHash < element.keyHash {
// the new item is the smallest for this index?
if !atomic.CompareAndSwapPointer(ptr, unsafe.Pointer(element), unsafe.Pointer(item)) {
continue // a new item was inserted concurrently, retry
}
}
return 0
}
} | [
"func",
"(",
"mapData",
"*",
"hashMapData",
")",
"addItemToIndex",
"(",
"item",
"*",
"ListElement",
")",
"uintptr",
"{",
"index",
":=",
"item",
".",
"keyHash",
">>",
"mapData",
".",
"keyshifts",
"\n",
"ptr",
":=",
"(",
"*",
"unsafe",
".",
"Pointer",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"mapData",
".",
"data",
")",
"+",
"index",
"*",
"intSizeBytes",
")",
")",
"\n\n",
"for",
"{",
"// loop until the smallest key hash is in the index",
"element",
":=",
"(",
"*",
"ListElement",
")",
"(",
"atomic",
".",
"LoadPointer",
"(",
"ptr",
")",
")",
"// get the current item in the index",
"\n",
"if",
"element",
"==",
"nil",
"{",
"// no item yet at this index",
"if",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"ptr",
",",
"nil",
",",
"unsafe",
".",
"Pointer",
"(",
"item",
")",
")",
"{",
"return",
"atomic",
".",
"AddUintptr",
"(",
"&",
"mapData",
".",
"count",
",",
"1",
")",
"\n",
"}",
"\n",
"continue",
"// a new item was inserted concurrently, retry",
"\n",
"}",
"\n\n",
"if",
"item",
".",
"keyHash",
"<",
"element",
".",
"keyHash",
"{",
"// the new item is the smallest for this index?",
"if",
"!",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"ptr",
",",
"unsafe",
".",
"Pointer",
"(",
"element",
")",
",",
"unsafe",
".",
"Pointer",
"(",
"item",
")",
")",
"{",
"continue",
"// a new item was inserted concurrently, retry",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"}"
]
| // adds an item to the index if needed and returns the new item counter if it changed, otherwise 0 | [
"adds",
"an",
"item",
"to",
"the",
"index",
"if",
"needed",
"and",
"returns",
"the",
"new",
"item",
"counter",
"if",
"it",
"changed",
"otherwise",
"0"
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L286-L307 |
8,733 | cornelk/hashmap | hashmap.go | Grow | func (m *HashMap) Grow(newSize uintptr) {
if atomic.CompareAndSwapUintptr(&m.resizing, uintptr(0), uintptr(1)) {
go m.grow(newSize, true)
}
} | go | func (m *HashMap) Grow(newSize uintptr) {
if atomic.CompareAndSwapUintptr(&m.resizing, uintptr(0), uintptr(1)) {
go m.grow(newSize, true)
}
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"Grow",
"(",
"newSize",
"uintptr",
")",
"{",
"if",
"atomic",
".",
"CompareAndSwapUintptr",
"(",
"&",
"m",
".",
"resizing",
",",
"uintptr",
"(",
"0",
")",
",",
"uintptr",
"(",
"1",
")",
")",
"{",
"go",
"m",
".",
"grow",
"(",
"newSize",
",",
"true",
")",
"\n",
"}",
"\n",
"}"
]
| // Grow resizes the hashmap to a new size, gets rounded up to next power of 2.
// To double the size of the hashmap use newSize 0.
// This function returns immediately, the resize operation is done in a goroutine.
// No resizing is done in case of another resize operation already being in progress. | [
"Grow",
"resizes",
"the",
"hashmap",
"to",
"a",
"new",
"size",
"gets",
"rounded",
"up",
"to",
"next",
"power",
"of",
"2",
".",
"To",
"double",
"the",
"size",
"of",
"the",
"hashmap",
"use",
"newSize",
"0",
".",
"This",
"function",
"returns",
"immediately",
"the",
"resize",
"operation",
"is",
"done",
"in",
"a",
"goroutine",
".",
"No",
"resizing",
"is",
"done",
"in",
"case",
"of",
"another",
"resize",
"operation",
"already",
"being",
"in",
"progress",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L313-L317 |
8,734 | cornelk/hashmap | hashmap.go | String | func (m *HashMap) String() string {
list := m.list()
if list == nil {
return "[]"
}
buffer := bytes.NewBufferString("")
buffer.WriteRune('[')
first := list.First()
item := first
for item != nil {
if item != first {
buffer.WriteRune(',')
}
fmt.Fprint(buffer, item.keyHash)
item = item.Next()
}
buffer.WriteRune(']')
return buffer.String()
} | go | func (m *HashMap) String() string {
list := m.list()
if list == nil {
return "[]"
}
buffer := bytes.NewBufferString("")
buffer.WriteRune('[')
first := list.First()
item := first
for item != nil {
if item != first {
buffer.WriteRune(',')
}
fmt.Fprint(buffer, item.keyHash)
item = item.Next()
}
buffer.WriteRune(']')
return buffer.String()
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"String",
"(",
")",
"string",
"{",
"list",
":=",
"m",
".",
"list",
"(",
")",
"\n",
"if",
"list",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"buffer",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"",
"\"",
")",
"\n",
"buffer",
".",
"WriteRune",
"(",
"'['",
")",
"\n\n",
"first",
":=",
"list",
".",
"First",
"(",
")",
"\n",
"item",
":=",
"first",
"\n\n",
"for",
"item",
"!=",
"nil",
"{",
"if",
"item",
"!=",
"first",
"{",
"buffer",
".",
"WriteRune",
"(",
"','",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprint",
"(",
"buffer",
",",
"item",
".",
"keyHash",
")",
"\n",
"item",
"=",
"item",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"buffer",
".",
"WriteRune",
"(",
"']'",
")",
"\n",
"return",
"buffer",
".",
"String",
"(",
")",
"\n",
"}"
]
| // String returns the map as a string, only hashed keys are printed. | [
"String",
"returns",
"the",
"map",
"as",
"a",
"string",
"only",
"hashed",
"keys",
"are",
"printed",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L378-L399 |
8,735 | cornelk/hashmap | hashmap.go | Iter | func (m *HashMap) Iter() <-chan KeyValue {
ch := make(chan KeyValue) // do not use a size here since items can get added during iteration
go func() {
list := m.list()
if list == nil {
close(ch)
return
}
item := list.First()
for item != nil {
value := item.Value()
ch <- KeyValue{item.key, value}
item = item.Next()
}
close(ch)
}()
return ch
} | go | func (m *HashMap) Iter() <-chan KeyValue {
ch := make(chan KeyValue) // do not use a size here since items can get added during iteration
go func() {
list := m.list()
if list == nil {
close(ch)
return
}
item := list.First()
for item != nil {
value := item.Value()
ch <- KeyValue{item.key, value}
item = item.Next()
}
close(ch)
}()
return ch
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"Iter",
"(",
")",
"<-",
"chan",
"KeyValue",
"{",
"ch",
":=",
"make",
"(",
"chan",
"KeyValue",
")",
"// do not use a size here since items can get added during iteration",
"\n\n",
"go",
"func",
"(",
")",
"{",
"list",
":=",
"m",
".",
"list",
"(",
")",
"\n",
"if",
"list",
"==",
"nil",
"{",
"close",
"(",
"ch",
")",
"\n",
"return",
"\n",
"}",
"\n",
"item",
":=",
"list",
".",
"First",
"(",
")",
"\n",
"for",
"item",
"!=",
"nil",
"{",
"value",
":=",
"item",
".",
"Value",
"(",
")",
"\n",
"ch",
"<-",
"KeyValue",
"{",
"item",
".",
"key",
",",
"value",
"}",
"\n",
"item",
"=",
"item",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"close",
"(",
"ch",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"ch",
"\n",
"}"
]
| // Iter returns an iterator which could be used in a for range loop.
// The order of the items is sorted by hash keys. | [
"Iter",
"returns",
"an",
"iterator",
"which",
"could",
"be",
"used",
"in",
"a",
"for",
"range",
"loop",
".",
"The",
"order",
"of",
"the",
"items",
"is",
"sorted",
"by",
"hash",
"keys",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap.go#L403-L422 |
8,736 | cornelk/hashmap | hashmap_get.go | GetUintKey | func (m *HashMap) GetUintKey(key uintptr) (value interface{}, ok bool) {
// inline getUintptrHash()
bh := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(&key)),
Len: intSizeBytes,
Cap: intSizeBytes,
}
buf := *(*[]byte)(unsafe.Pointer(&bh))
h := uintptr(siphash.Hash(sipHashKey1, sipHashKey2, buf))
data, element := m.indexElement(h)
if data == nil {
return nil, false
}
// inline HashMap.searchItem()
for element != nil {
if element.keyHash == h && element.key == key {
return element.Value(), true
}
if element.keyHash > h {
return nil, false
}
element = element.Next()
}
return nil, false
} | go | func (m *HashMap) GetUintKey(key uintptr) (value interface{}, ok bool) {
// inline getUintptrHash()
bh := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(&key)),
Len: intSizeBytes,
Cap: intSizeBytes,
}
buf := *(*[]byte)(unsafe.Pointer(&bh))
h := uintptr(siphash.Hash(sipHashKey1, sipHashKey2, buf))
data, element := m.indexElement(h)
if data == nil {
return nil, false
}
// inline HashMap.searchItem()
for element != nil {
if element.keyHash == h && element.key == key {
return element.Value(), true
}
if element.keyHash > h {
return nil, false
}
element = element.Next()
}
return nil, false
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"GetUintKey",
"(",
"key",
"uintptr",
")",
"(",
"value",
"interface",
"{",
"}",
",",
"ok",
"bool",
")",
"{",
"// inline getUintptrHash()",
"bh",
":=",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"key",
")",
")",
",",
"Len",
":",
"intSizeBytes",
",",
"Cap",
":",
"intSizeBytes",
",",
"}",
"\n",
"buf",
":=",
"*",
"(",
"*",
"[",
"]",
"byte",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"bh",
")",
")",
"\n",
"h",
":=",
"uintptr",
"(",
"siphash",
".",
"Hash",
"(",
"sipHashKey1",
",",
"sipHashKey2",
",",
"buf",
")",
")",
"\n\n",
"data",
",",
"element",
":=",
"m",
".",
"indexElement",
"(",
"h",
")",
"\n",
"if",
"data",
"==",
"nil",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"// inline HashMap.searchItem()",
"for",
"element",
"!=",
"nil",
"{",
"if",
"element",
".",
"keyHash",
"==",
"h",
"&&",
"element",
".",
"key",
"==",
"key",
"{",
"return",
"element",
".",
"Value",
"(",
")",
",",
"true",
"\n",
"}",
"\n\n",
"if",
"element",
".",
"keyHash",
">",
"h",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"element",
"=",
"element",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}"
]
| // GetUintKey retrieves an element from the map under given integer key. | [
"GetUintKey",
"retrieves",
"an",
"element",
"from",
"the",
"map",
"under",
"given",
"integer",
"key",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap_get.go#L46-L74 |
8,737 | cornelk/hashmap | hashmap_get.go | GetHashedKey | func (m *HashMap) GetHashedKey(hashedKey uintptr) (value interface{}, ok bool) {
data, element := m.indexElement(hashedKey)
if data == nil {
return nil, false
}
// inline HashMap.searchItem()
for element != nil {
if element.keyHash == hashedKey {
return element.Value(), true
}
if element.keyHash > hashedKey {
return nil, false
}
element = element.Next()
}
return nil, false
} | go | func (m *HashMap) GetHashedKey(hashedKey uintptr) (value interface{}, ok bool) {
data, element := m.indexElement(hashedKey)
if data == nil {
return nil, false
}
// inline HashMap.searchItem()
for element != nil {
if element.keyHash == hashedKey {
return element.Value(), true
}
if element.keyHash > hashedKey {
return nil, false
}
element = element.Next()
}
return nil, false
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"GetHashedKey",
"(",
"hashedKey",
"uintptr",
")",
"(",
"value",
"interface",
"{",
"}",
",",
"ok",
"bool",
")",
"{",
"data",
",",
"element",
":=",
"m",
".",
"indexElement",
"(",
"hashedKey",
")",
"\n",
"if",
"data",
"==",
"nil",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"// inline HashMap.searchItem()",
"for",
"element",
"!=",
"nil",
"{",
"if",
"element",
".",
"keyHash",
"==",
"hashedKey",
"{",
"return",
"element",
".",
"Value",
"(",
")",
",",
"true",
"\n",
"}",
"\n\n",
"if",
"element",
".",
"keyHash",
">",
"hashedKey",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"element",
"=",
"element",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}"
]
| // GetHashedKey retrieves an element from the map under given hashed key. | [
"GetHashedKey",
"retrieves",
"an",
"element",
"from",
"the",
"map",
"under",
"given",
"hashed",
"key",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap_get.go#L109-L128 |
8,738 | cornelk/hashmap | hashmap_get.go | GetOrInsert | func (m *HashMap) GetOrInsert(key interface{}, value interface{}) (actual interface{}, loaded bool) {
h := getKeyHash(key)
var newelement *ListElement
for {
data, element := m.indexElement(h)
if data == nil {
m.allocate(DefaultSize)
continue
}
for element != nil {
if element.keyHash == h {
switch key.(type) {
case []byte:
if bytes.Compare(element.key.([]byte), key.([]byte)) == 0 {
return element.Value(), true
}
default:
if element.key == key {
actual = element.Value()
return actual, true
}
}
}
if element.keyHash > h {
break
}
element = element.Next()
}
if newelement == nil { // allocate only once
newelement = &ListElement{
key: key,
keyHash: h,
value: unsafe.Pointer(&value),
}
}
if m.insertListElement(newelement, false) {
return value, false
}
}
} | go | func (m *HashMap) GetOrInsert(key interface{}, value interface{}) (actual interface{}, loaded bool) {
h := getKeyHash(key)
var newelement *ListElement
for {
data, element := m.indexElement(h)
if data == nil {
m.allocate(DefaultSize)
continue
}
for element != nil {
if element.keyHash == h {
switch key.(type) {
case []byte:
if bytes.Compare(element.key.([]byte), key.([]byte)) == 0 {
return element.Value(), true
}
default:
if element.key == key {
actual = element.Value()
return actual, true
}
}
}
if element.keyHash > h {
break
}
element = element.Next()
}
if newelement == nil { // allocate only once
newelement = &ListElement{
key: key,
keyHash: h,
value: unsafe.Pointer(&value),
}
}
if m.insertListElement(newelement, false) {
return value, false
}
}
} | [
"func",
"(",
"m",
"*",
"HashMap",
")",
"GetOrInsert",
"(",
"key",
"interface",
"{",
"}",
",",
"value",
"interface",
"{",
"}",
")",
"(",
"actual",
"interface",
"{",
"}",
",",
"loaded",
"bool",
")",
"{",
"h",
":=",
"getKeyHash",
"(",
"key",
")",
"\n",
"var",
"newelement",
"*",
"ListElement",
"\n\n",
"for",
"{",
"data",
",",
"element",
":=",
"m",
".",
"indexElement",
"(",
"h",
")",
"\n",
"if",
"data",
"==",
"nil",
"{",
"m",
".",
"allocate",
"(",
"DefaultSize",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"for",
"element",
"!=",
"nil",
"{",
"if",
"element",
".",
"keyHash",
"==",
"h",
"{",
"switch",
"key",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"byte",
":",
"if",
"bytes",
".",
"Compare",
"(",
"element",
".",
"key",
".",
"(",
"[",
"]",
"byte",
")",
",",
"key",
".",
"(",
"[",
"]",
"byte",
")",
")",
"==",
"0",
"{",
"return",
"element",
".",
"Value",
"(",
")",
",",
"true",
"\n",
"}",
"\n",
"default",
":",
"if",
"element",
".",
"key",
"==",
"key",
"{",
"actual",
"=",
"element",
".",
"Value",
"(",
")",
"\n",
"return",
"actual",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"element",
".",
"keyHash",
">",
"h",
"{",
"break",
"\n",
"}",
"\n\n",
"element",
"=",
"element",
".",
"Next",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"newelement",
"==",
"nil",
"{",
"// allocate only once",
"newelement",
"=",
"&",
"ListElement",
"{",
"key",
":",
"key",
",",
"keyHash",
":",
"h",
",",
"value",
":",
"unsafe",
".",
"Pointer",
"(",
"&",
"value",
")",
",",
"}",
"\n",
"}",
"\n\n",
"if",
"m",
".",
"insertListElement",
"(",
"newelement",
",",
"false",
")",
"{",
"return",
"value",
",",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // GetOrInsert returns the existing value for the key if present.
// Otherwise, it stores and returns the given value.
// The loaded result is true if the value was loaded, false if stored. | [
"GetOrInsert",
"returns",
"the",
"existing",
"value",
"for",
"the",
"key",
"if",
"present",
".",
"Otherwise",
"it",
"stores",
"and",
"returns",
"the",
"given",
"value",
".",
"The",
"loaded",
"result",
"is",
"true",
"if",
"the",
"value",
"was",
"loaded",
"false",
"if",
"stored",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/hashmap_get.go#L133-L178 |
8,739 | cornelk/hashmap | list.go | Len | func (l *List) Len() int {
if l == nil { // not initialized yet?
return 0
}
return int(atomic.LoadUintptr(&l.count))
} | go | func (l *List) Len() int {
if l == nil { // not initialized yet?
return 0
}
return int(atomic.LoadUintptr(&l.count))
} | [
"func",
"(",
"l",
"*",
"List",
")",
"Len",
"(",
")",
"int",
"{",
"if",
"l",
"==",
"nil",
"{",
"// not initialized yet?",
"return",
"0",
"\n",
"}",
"\n\n",
"return",
"int",
"(",
"atomic",
".",
"LoadUintptr",
"(",
"&",
"l",
".",
"count",
")",
")",
"\n",
"}"
]
| // Len returns the number of elements within the list. | [
"Len",
"returns",
"the",
"number",
"of",
"elements",
"within",
"the",
"list",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/list.go#L20-L26 |
8,740 | cornelk/hashmap | list.go | First | func (l *List) First() *ListElement {
if l == nil { // not initialized yet?
return nil
}
return l.head.Next()
} | go | func (l *List) First() *ListElement {
if l == nil { // not initialized yet?
return nil
}
return l.head.Next()
} | [
"func",
"(",
"l",
"*",
"List",
")",
"First",
"(",
")",
"*",
"ListElement",
"{",
"if",
"l",
"==",
"nil",
"{",
"// not initialized yet?",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"l",
".",
"head",
".",
"Next",
"(",
")",
"\n",
"}"
]
| // First returns the first item of the list. | [
"First",
"returns",
"the",
"first",
"item",
"of",
"the",
"list",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/list.go#L38-L44 |
8,741 | cornelk/hashmap | list.go | Add | func (l *List) Add(element *ListElement, searchStart *ListElement) (existed bool, inserted bool) {
left, found, right := l.search(searchStart, element)
if found != nil { // existing item found
return true, false
}
return false, l.insertAt(element, left, right)
} | go | func (l *List) Add(element *ListElement, searchStart *ListElement) (existed bool, inserted bool) {
left, found, right := l.search(searchStart, element)
if found != nil { // existing item found
return true, false
}
return false, l.insertAt(element, left, right)
} | [
"func",
"(",
"l",
"*",
"List",
")",
"Add",
"(",
"element",
"*",
"ListElement",
",",
"searchStart",
"*",
"ListElement",
")",
"(",
"existed",
"bool",
",",
"inserted",
"bool",
")",
"{",
"left",
",",
"found",
",",
"right",
":=",
"l",
".",
"search",
"(",
"searchStart",
",",
"element",
")",
"\n",
"if",
"found",
"!=",
"nil",
"{",
"// existing item found",
"return",
"true",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"false",
",",
"l",
".",
"insertAt",
"(",
"element",
",",
"left",
",",
"right",
")",
"\n",
"}"
]
| // Add adds an item to the list and returns false if an item for the hash existed.
// searchStart = nil will start to search at the head item | [
"Add",
"adds",
"an",
"item",
"to",
"the",
"list",
"and",
"returns",
"false",
"if",
"an",
"item",
"for",
"the",
"hash",
"existed",
".",
"searchStart",
"=",
"nil",
"will",
"start",
"to",
"search",
"at",
"the",
"head",
"item"
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/list.go#L48-L55 |
8,742 | cornelk/hashmap | list.go | AddOrUpdate | func (l *List) AddOrUpdate(element *ListElement, searchStart *ListElement) bool {
left, found, right := l.search(searchStart, element)
if found != nil { // existing item found
found.setValue(element.value) // update the value
return true
}
return l.insertAt(element, left, right)
} | go | func (l *List) AddOrUpdate(element *ListElement, searchStart *ListElement) bool {
left, found, right := l.search(searchStart, element)
if found != nil { // existing item found
found.setValue(element.value) // update the value
return true
}
return l.insertAt(element, left, right)
} | [
"func",
"(",
"l",
"*",
"List",
")",
"AddOrUpdate",
"(",
"element",
"*",
"ListElement",
",",
"searchStart",
"*",
"ListElement",
")",
"bool",
"{",
"left",
",",
"found",
",",
"right",
":=",
"l",
".",
"search",
"(",
"searchStart",
",",
"element",
")",
"\n",
"if",
"found",
"!=",
"nil",
"{",
"// existing item found",
"found",
".",
"setValue",
"(",
"element",
".",
"value",
")",
"// update the value",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"l",
".",
"insertAt",
"(",
"element",
",",
"left",
",",
"right",
")",
"\n",
"}"
]
| // AddOrUpdate adds or updates an item to the list. | [
"AddOrUpdate",
"adds",
"or",
"updates",
"an",
"item",
"to",
"the",
"list",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/list.go#L58-L66 |
8,743 | cornelk/hashmap | list.go | Cas | func (l *List) Cas(element *ListElement, oldValue interface{}, searchStart *ListElement) bool {
_, found, _ := l.search(searchStart, element)
if found == nil { // no existing item found
return false
}
if found.casValue(oldValue, element.value) {
atomic.AddUintptr(&l.count, 1)
return true
}
return false
} | go | func (l *List) Cas(element *ListElement, oldValue interface{}, searchStart *ListElement) bool {
_, found, _ := l.search(searchStart, element)
if found == nil { // no existing item found
return false
}
if found.casValue(oldValue, element.value) {
atomic.AddUintptr(&l.count, 1)
return true
}
return false
} | [
"func",
"(",
"l",
"*",
"List",
")",
"Cas",
"(",
"element",
"*",
"ListElement",
",",
"oldValue",
"interface",
"{",
"}",
",",
"searchStart",
"*",
"ListElement",
")",
"bool",
"{",
"_",
",",
"found",
",",
"_",
":=",
"l",
".",
"search",
"(",
"searchStart",
",",
"element",
")",
"\n",
"if",
"found",
"==",
"nil",
"{",
"// no existing item found",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"found",
".",
"casValue",
"(",
"oldValue",
",",
"element",
".",
"value",
")",
"{",
"atomic",
".",
"AddUintptr",
"(",
"&",
"l",
".",
"count",
",",
"1",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
]
| // Cas compares and swaps the value of an item in the list. | [
"Cas",
"compares",
"and",
"swaps",
"the",
"value",
"of",
"an",
"item",
"in",
"the",
"list",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/list.go#L69-L80 |
8,744 | cornelk/hashmap | list.go | Delete | func (l *List) Delete(element *ListElement) {
if !atomic.CompareAndSwapUintptr(&element.deleted, uintptr(0), uintptr(1)) {
return // concurrent delete of the item in progress
}
for {
left := element.Previous()
right := element.Next()
if left == nil { // element is first item in list?
if !atomic.CompareAndSwapPointer(&l.head.nextElement, unsafe.Pointer(element), unsafe.Pointer(right)) {
continue // now head item was inserted concurrently
}
} else {
if !atomic.CompareAndSwapPointer(&left.nextElement, unsafe.Pointer(element), unsafe.Pointer(right)) {
continue // item was modified concurrently
}
}
if right != nil {
atomic.CompareAndSwapPointer(&right.previousElement, unsafe.Pointer(element), unsafe.Pointer(left))
}
break
}
atomic.AddUintptr(&l.count, ^uintptr(0)) // decrease counter
} | go | func (l *List) Delete(element *ListElement) {
if !atomic.CompareAndSwapUintptr(&element.deleted, uintptr(0), uintptr(1)) {
return // concurrent delete of the item in progress
}
for {
left := element.Previous()
right := element.Next()
if left == nil { // element is first item in list?
if !atomic.CompareAndSwapPointer(&l.head.nextElement, unsafe.Pointer(element), unsafe.Pointer(right)) {
continue // now head item was inserted concurrently
}
} else {
if !atomic.CompareAndSwapPointer(&left.nextElement, unsafe.Pointer(element), unsafe.Pointer(right)) {
continue // item was modified concurrently
}
}
if right != nil {
atomic.CompareAndSwapPointer(&right.previousElement, unsafe.Pointer(element), unsafe.Pointer(left))
}
break
}
atomic.AddUintptr(&l.count, ^uintptr(0)) // decrease counter
} | [
"func",
"(",
"l",
"*",
"List",
")",
"Delete",
"(",
"element",
"*",
"ListElement",
")",
"{",
"if",
"!",
"atomic",
".",
"CompareAndSwapUintptr",
"(",
"&",
"element",
".",
"deleted",
",",
"uintptr",
"(",
"0",
")",
",",
"uintptr",
"(",
"1",
")",
")",
"{",
"return",
"// concurrent delete of the item in progress",
"\n",
"}",
"\n\n",
"for",
"{",
"left",
":=",
"element",
".",
"Previous",
"(",
")",
"\n",
"right",
":=",
"element",
".",
"Next",
"(",
")",
"\n\n",
"if",
"left",
"==",
"nil",
"{",
"// element is first item in list?",
"if",
"!",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"&",
"l",
".",
"head",
".",
"nextElement",
",",
"unsafe",
".",
"Pointer",
"(",
"element",
")",
",",
"unsafe",
".",
"Pointer",
"(",
"right",
")",
")",
"{",
"continue",
"// now head item was inserted concurrently",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"!",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"&",
"left",
".",
"nextElement",
",",
"unsafe",
".",
"Pointer",
"(",
"element",
")",
",",
"unsafe",
".",
"Pointer",
"(",
"right",
")",
")",
"{",
"continue",
"// item was modified concurrently",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"right",
"!=",
"nil",
"{",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"&",
"right",
".",
"previousElement",
",",
"unsafe",
".",
"Pointer",
"(",
"element",
")",
",",
"unsafe",
".",
"Pointer",
"(",
"left",
")",
")",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n\n",
"atomic",
".",
"AddUintptr",
"(",
"&",
"l",
".",
"count",
",",
"^",
"uintptr",
"(",
"0",
")",
")",
"// decrease counter",
"\n",
"}"
]
| // Delete deletes an element from the list. | [
"Delete",
"deletes",
"an",
"element",
"from",
"the",
"list",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/list.go#L156-L181 |
8,745 | cornelk/hashmap | listelement.go | setValue | func (e *ListElement) setValue(value unsafe.Pointer) {
atomic.StorePointer(&e.value, value)
} | go | func (e *ListElement) setValue(value unsafe.Pointer) {
atomic.StorePointer(&e.value, value)
} | [
"func",
"(",
"e",
"*",
"ListElement",
")",
"setValue",
"(",
"value",
"unsafe",
".",
"Pointer",
")",
"{",
"atomic",
".",
"StorePointer",
"(",
"&",
"e",
".",
"value",
",",
"value",
")",
"\n",
"}"
]
| // setValue sets the value of the item.
// The value needs to be wrapped in unsafe.Pointer already. | [
"setValue",
"sets",
"the",
"value",
"of",
"the",
"item",
".",
"The",
"value",
"needs",
"to",
"be",
"wrapped",
"in",
"unsafe",
".",
"Pointer",
"already",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/listelement.go#L35-L37 |
8,746 | cornelk/hashmap | listelement.go | casValue | func (e *ListElement) casValue(from interface{}, to unsafe.Pointer) bool {
old := atomic.LoadPointer(&e.value)
if *(*interface{})(old) != from {
return false
}
return atomic.CompareAndSwapPointer(&e.value, old, to)
} | go | func (e *ListElement) casValue(from interface{}, to unsafe.Pointer) bool {
old := atomic.LoadPointer(&e.value)
if *(*interface{})(old) != from {
return false
}
return atomic.CompareAndSwapPointer(&e.value, old, to)
} | [
"func",
"(",
"e",
"*",
"ListElement",
")",
"casValue",
"(",
"from",
"interface",
"{",
"}",
",",
"to",
"unsafe",
".",
"Pointer",
")",
"bool",
"{",
"old",
":=",
"atomic",
".",
"LoadPointer",
"(",
"&",
"e",
".",
"value",
")",
"\n",
"if",
"*",
"(",
"*",
"interface",
"{",
"}",
")",
"(",
"old",
")",
"!=",
"from",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"atomic",
".",
"CompareAndSwapPointer",
"(",
"&",
"e",
".",
"value",
",",
"old",
",",
"to",
")",
"\n",
"}"
]
| // casValue compares and swaps the values of the item.
// The to value needs to be wrapped in unsafe.Pointer already. | [
"casValue",
"compares",
"and",
"swaps",
"the",
"values",
"of",
"the",
"item",
".",
"The",
"to",
"value",
"needs",
"to",
"be",
"wrapped",
"in",
"unsafe",
".",
"Pointer",
"already",
"."
]
| 33e58823eb9d4426a8d2b604cece33c3c15df8cc | https://github.com/cornelk/hashmap/blob/33e58823eb9d4426a8d2b604cece33c3c15df8cc/listelement.go#L41-L47 |
8,747 | lunny/tango | cookie.go | NewCookie | func NewCookie(name string, value string, age ...int64) *http.Cookie {
if !isValidCookieName(name) || !isValidCookieValue([]byte(value)) {
return nil
}
var utctime time.Time
if len(age) == 0 {
// 2^31 - 1 seconds (roughly 2038)
utctime = time.Unix(2147483647, 0)
} else {
utctime = time.Unix(time.Now().Unix()+age[0], 0)
}
return &http.Cookie{Name: name, Value: value, Expires: utctime}
} | go | func NewCookie(name string, value string, age ...int64) *http.Cookie {
if !isValidCookieName(name) || !isValidCookieValue([]byte(value)) {
return nil
}
var utctime time.Time
if len(age) == 0 {
// 2^31 - 1 seconds (roughly 2038)
utctime = time.Unix(2147483647, 0)
} else {
utctime = time.Unix(time.Now().Unix()+age[0], 0)
}
return &http.Cookie{Name: name, Value: value, Expires: utctime}
} | [
"func",
"NewCookie",
"(",
"name",
"string",
",",
"value",
"string",
",",
"age",
"...",
"int64",
")",
"*",
"http",
".",
"Cookie",
"{",
"if",
"!",
"isValidCookieName",
"(",
"name",
")",
"||",
"!",
"isValidCookieValue",
"(",
"[",
"]",
"byte",
"(",
"value",
")",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"utctime",
"time",
".",
"Time",
"\n",
"if",
"len",
"(",
"age",
")",
"==",
"0",
"{",
"// 2^31 - 1 seconds (roughly 2038)",
"utctime",
"=",
"time",
".",
"Unix",
"(",
"2147483647",
",",
"0",
")",
"\n",
"}",
"else",
"{",
"utctime",
"=",
"time",
".",
"Unix",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
"+",
"age",
"[",
"0",
"]",
",",
"0",
")",
"\n",
"}",
"\n",
"return",
"&",
"http",
".",
"Cookie",
"{",
"Name",
":",
"name",
",",
"Value",
":",
"value",
",",
"Expires",
":",
"utctime",
"}",
"\n",
"}"
]
| // NewCookie return a http.Cookie via give name and value | [
"NewCookie",
"return",
"a",
"http",
".",
"Cookie",
"via",
"give",
"name",
"and",
"value"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L86-L99 |
8,748 | lunny/tango | cookie.go | Get | func (c *cookies) Get(key string) *http.Cookie {
ck, err := c.req.Cookie(key)
if err != nil {
return nil
}
return ck
} | go | func (c *cookies) Get(key string) *http.Cookie {
ck, err := c.req.Cookie(key)
if err != nil {
return nil
}
return ck
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Get",
"(",
"key",
"string",
")",
"*",
"http",
".",
"Cookie",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"ck",
"\n",
"}"
]
| // Get return http.Cookie via key | [
"Get",
"return",
"http",
".",
"Cookie",
"via",
"key"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L102-L108 |
8,749 | lunny/tango | cookie.go | Set | func (c *cookies) Set(ck *http.Cookie) {
http.SetCookie(c.ResponseWriter, ck)
} | go | func (c *cookies) Set(ck *http.Cookie) {
http.SetCookie(c.ResponseWriter, ck)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Set",
"(",
"ck",
"*",
"http",
".",
"Cookie",
")",
"{",
"http",
".",
"SetCookie",
"(",
"c",
".",
"ResponseWriter",
",",
"ck",
")",
"\n",
"}"
]
| // Set set a http.Cookie | [
"Set",
"set",
"a",
"http",
".",
"Cookie"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L111-L113 |
8,750 | lunny/tango | cookie.go | Expire | func (c *cookies) Expire(key string, expire time.Time) {
ck := c.Get(key)
if ck != nil {
ck.Expires = expire
ck.MaxAge = int(expire.Sub(time.Now()).Seconds())
c.Set(ck)
}
} | go | func (c *cookies) Expire(key string, expire time.Time) {
ck := c.Get(key)
if ck != nil {
ck.Expires = expire
ck.MaxAge = int(expire.Sub(time.Now()).Seconds())
c.Set(ck)
}
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Expire",
"(",
"key",
"string",
",",
"expire",
"time",
".",
"Time",
")",
"{",
"ck",
":=",
"c",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"ck",
"!=",
"nil",
"{",
"ck",
".",
"Expires",
"=",
"expire",
"\n",
"ck",
".",
"MaxAge",
"=",
"int",
"(",
"expire",
".",
"Sub",
"(",
"time",
".",
"Now",
"(",
")",
")",
".",
"Seconds",
"(",
")",
")",
"\n",
"c",
".",
"Set",
"(",
"ck",
")",
"\n",
"}",
"\n",
"}"
]
| // Expire let a cookie named key when expire address | [
"Expire",
"let",
"a",
"cookie",
"named",
"key",
"when",
"expire",
"address"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L116-L123 |
8,751 | lunny/tango | cookie.go | Del | func (c *cookies) Del(key string) {
c.Expire(key, time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local))
} | go | func (c *cookies) Del(key string) {
c.Expire(key, time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local))
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Del",
"(",
"key",
"string",
")",
"{",
"c",
".",
"Expire",
"(",
"key",
",",
"time",
".",
"Date",
"(",
"1900",
",",
"1",
",",
"1",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"time",
".",
"Local",
")",
")",
"\n",
"}"
]
| // Del del cookie by key | [
"Del",
"del",
"cookie",
"by",
"key"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L126-L128 |
8,752 | lunny/tango | cookie.go | String | func (c *cookies) String(key string) (string, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return "", err
}
return ck.Value, nil
} | go | func (c *cookies) String(key string) (string, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return "", err
}
return ck.Value, nil
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"String",
"(",
"key",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"ck",
".",
"Value",
",",
"nil",
"\n",
"}"
]
| // String get cookie as string | [
"String",
"get",
"cookie",
"as",
"string"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L131-L137 |
8,753 | lunny/tango | cookie.go | Int | func (c *cookies) Int(key string) (int, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
return strconv.Atoi(ck.Value)
} | go | func (c *cookies) Int(key string) (int, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
return strconv.Atoi(ck.Value)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Int",
"(",
"key",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"strconv",
".",
"Atoi",
"(",
"ck",
".",
"Value",
")",
"\n",
"}"
]
| // Int get cookie as int | [
"Int",
"get",
"cookie",
"as",
"int"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L140-L146 |
8,754 | lunny/tango | cookie.go | Int32 | func (c *cookies) Int32(key string) (int32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
v, err := strconv.ParseInt(ck.Value, 10, 32)
return int32(v), err
} | go | func (c *cookies) Int32(key string) (int32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
v, err := strconv.ParseInt(ck.Value, 10, 32)
return int32(v), err
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Int32",
"(",
"key",
"string",
")",
"(",
"int32",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"32",
")",
"\n",
"return",
"int32",
"(",
"v",
")",
",",
"err",
"\n",
"}"
]
| // Int32 get cookie as int32 | [
"Int32",
"get",
"cookie",
"as",
"int32"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L149-L156 |
8,755 | lunny/tango | cookie.go | Int64 | func (c *cookies) Int64(key string) (int64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
return strconv.ParseInt(ck.Value, 10, 64)
} | go | func (c *cookies) Int64(key string) (int64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
return strconv.ParseInt(ck.Value, 10, 64)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Int64",
"(",
"key",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"strconv",
".",
"ParseInt",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"64",
")",
"\n",
"}"
]
| // Int64 get cookie as int64 | [
"Int64",
"get",
"cookie",
"as",
"int64"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L159-L165 |
8,756 | lunny/tango | cookie.go | Uint | func (c *cookies) Uint(key string) (uint, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
v, err := strconv.ParseUint(ck.Value, 10, 64)
return uint(v), err
} | go | func (c *cookies) Uint(key string) (uint, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
v, err := strconv.ParseUint(ck.Value, 10, 64)
return uint(v), err
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Uint",
"(",
"key",
"string",
")",
"(",
"uint",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"64",
")",
"\n",
"return",
"uint",
"(",
"v",
")",
",",
"err",
"\n",
"}"
]
| // Uint get cookie as uint | [
"Uint",
"get",
"cookie",
"as",
"uint"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L168-L175 |
8,757 | lunny/tango | cookie.go | Uint32 | func (c *cookies) Uint32(key string) (uint32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
v, err := strconv.ParseUint(ck.Value, 10, 32)
return uint32(v), err
} | go | func (c *cookies) Uint32(key string) (uint32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
v, err := strconv.ParseUint(ck.Value, 10, 32)
return uint32(v), err
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Uint32",
"(",
"key",
"string",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"32",
")",
"\n",
"return",
"uint32",
"(",
"v",
")",
",",
"err",
"\n",
"}"
]
| // Uint32 get cookie as uint32 | [
"Uint32",
"get",
"cookie",
"as",
"uint32"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L178-L185 |
8,758 | lunny/tango | cookie.go | Uint64 | func (c *cookies) Uint64(key string) (uint64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
return strconv.ParseUint(ck.Value, 10, 64)
} | go | func (c *cookies) Uint64(key string) (uint64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
return strconv.ParseUint(ck.Value, 10, 64)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Uint64",
"(",
"key",
"string",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"strconv",
".",
"ParseUint",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"64",
")",
"\n",
"}"
]
| // Uint64 get cookie as uint64 | [
"Uint64",
"get",
"cookie",
"as",
"uint64"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L188-L194 |
8,759 | lunny/tango | cookie.go | Float32 | func (c *cookies) Float32(key string) (float32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
v, err := strconv.ParseFloat(ck.Value, 32)
return float32(v), err
} | go | func (c *cookies) Float32(key string) (float32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
v, err := strconv.ParseFloat(ck.Value, 32)
return float32(v), err
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Float32",
"(",
"key",
"string",
")",
"(",
"float32",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"ck",
".",
"Value",
",",
"32",
")",
"\n",
"return",
"float32",
"(",
"v",
")",
",",
"err",
"\n",
"}"
]
| // Float32 get cookie as float32 | [
"Float32",
"get",
"cookie",
"as",
"float32"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L197-L204 |
8,760 | lunny/tango | cookie.go | Float64 | func (c *cookies) Float64(key string) (float64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
return strconv.ParseFloat(ck.Value, 32)
} | go | func (c *cookies) Float64(key string) (float64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
return strconv.ParseFloat(ck.Value, 32)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Float64",
"(",
"key",
"string",
")",
"(",
"float64",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"strconv",
".",
"ParseFloat",
"(",
"ck",
".",
"Value",
",",
"32",
")",
"\n",
"}"
]
| // Float64 get cookie as float64 | [
"Float64",
"get",
"cookie",
"as",
"float64"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L207-L213 |
8,761 | lunny/tango | cookie.go | Bool | func (c *cookies) Bool(key string) (bool, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return false, err
}
return strconv.ParseBool(ck.Value)
} | go | func (c *cookies) Bool(key string) (bool, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return false, err
}
return strconv.ParseBool(ck.Value)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"Bool",
"(",
"key",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"return",
"strconv",
".",
"ParseBool",
"(",
"ck",
".",
"Value",
")",
"\n",
"}"
]
| // Bool get cookie as bool | [
"Bool",
"get",
"cookie",
"as",
"bool"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L216-L222 |
8,762 | lunny/tango | cookie.go | MustString | func (c *cookies) MustString(key string, defaults ...string) string {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
return ck.Value
} | go | func (c *cookies) MustString(key string, defaults ...string) string {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
return ck.Value
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustString",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"ck",
".",
"Value",
"\n",
"}"
]
| // MustString get cookie as string with default | [
"MustString",
"get",
"cookie",
"as",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L225-L234 |
8,763 | lunny/tango | cookie.go | MustEscape | func (c *cookies) MustEscape(key string, defaults ...string) string {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
return template.HTMLEscapeString(ck.Value)
} | go | func (c *cookies) MustEscape(key string, defaults ...string) string {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
return template.HTMLEscapeString(ck.Value)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustEscape",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"template",
".",
"HTMLEscapeString",
"(",
"ck",
".",
"Value",
")",
"\n",
"}"
]
| // MustEscape get cookie as escaped string with default | [
"MustEscape",
"get",
"cookie",
"as",
"escaped",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L237-L246 |
8,764 | lunny/tango | cookie.go | MustInt | func (c *cookies) MustInt(key string, defaults ...int) int {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.Atoi(ck.Value)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | go | func (c *cookies) MustInt(key string, defaults ...int) int {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.Atoi(ck.Value)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustInt",
"(",
"key",
"string",
",",
"defaults",
"...",
"int",
")",
"int",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"ck",
".",
"Value",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
]
| // MustInt get cookie as int with default | [
"MustInt",
"get",
"cookie",
"as",
"int",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L249-L262 |
8,765 | lunny/tango | cookie.go | MustInt32 | func (c *cookies) MustInt32(key string, defaults ...int32) int32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseInt(ck.Value, 10, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return int32(v)
} | go | func (c *cookies) MustInt32(key string, defaults ...int32) int32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseInt(ck.Value, 10, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return int32(v)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustInt32",
"(",
"key",
"string",
",",
"defaults",
"...",
"int32",
")",
"int32",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"32",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"int32",
"(",
"v",
")",
"\n",
"}"
]
| // MustInt32 get cookie as int32 with default | [
"MustInt32",
"get",
"cookie",
"as",
"int32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L265-L278 |
8,766 | lunny/tango | cookie.go | MustInt64 | func (c *cookies) MustInt64(key string, defaults ...int64) int64 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseInt(ck.Value, 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | go | func (c *cookies) MustInt64(key string, defaults ...int64) int64 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseInt(ck.Value, 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustInt64",
"(",
"key",
"string",
",",
"defaults",
"...",
"int64",
")",
"int64",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"64",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
]
| // MustInt64 get cookie as int64 with default | [
"MustInt64",
"get",
"cookie",
"as",
"int64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L281-L294 |
8,767 | lunny/tango | cookie.go | MustUint | func (c *cookies) MustUint(key string, defaults ...uint) uint {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseUint(ck.Value, 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return uint(v)
} | go | func (c *cookies) MustUint(key string, defaults ...uint) uint {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseUint(ck.Value, 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return uint(v)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustUint",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint",
")",
"uint",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"64",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"uint",
"(",
"v",
")",
"\n",
"}"
]
| // MustUint get cookie as uint with default | [
"MustUint",
"get",
"cookie",
"as",
"uint",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L297-L310 |
8,768 | lunny/tango | cookie.go | MustUint32 | func (c *cookies) MustUint32(key string, defaults ...uint32) uint32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseUint(ck.Value, 10, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return uint32(v)
} | go | func (c *cookies) MustUint32(key string, defaults ...uint32) uint32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseUint(ck.Value, 10, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return uint32(v)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustUint32",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint32",
")",
"uint32",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"32",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"uint32",
"(",
"v",
")",
"\n",
"}"
]
| // MustUint32 get cookie as uint32 with default | [
"MustUint32",
"get",
"cookie",
"as",
"uint32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L313-L326 |
8,769 | lunny/tango | cookie.go | MustUint64 | func (c *cookies) MustUint64(key string, defaults ...uint64) uint64 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseUint(ck.Value, 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | go | func (c *cookies) MustUint64(key string, defaults ...uint64) uint64 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseUint(ck.Value, 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustUint64",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint64",
")",
"uint64",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"ck",
".",
"Value",
",",
"10",
",",
"64",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
]
| // MustUint64 get cookie as uint64 with default | [
"MustUint64",
"get",
"cookie",
"as",
"uint64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L329-L342 |
8,770 | lunny/tango | cookie.go | MustFloat32 | func (c *cookies) MustFloat32(key string, defaults ...float32) float32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseFloat(ck.Value, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return float32(v)
} | go | func (c *cookies) MustFloat32(key string, defaults ...float32) float32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseFloat(ck.Value, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return float32(v)
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustFloat32",
"(",
"key",
"string",
",",
"defaults",
"...",
"float32",
")",
"float32",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"ck",
".",
"Value",
",",
"32",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"float32",
"(",
"v",
")",
"\n",
"}"
]
| // MustFloat32 get cookie as float32 with default | [
"MustFloat32",
"get",
"cookie",
"as",
"float32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L345-L358 |
8,771 | lunny/tango | cookie.go | MustFloat64 | func (c *cookies) MustFloat64(key string, defaults ...float64) float64 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseFloat(ck.Value, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | go | func (c *cookies) MustFloat64(key string, defaults ...float64) float64 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
v, err := strconv.ParseFloat(ck.Value, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustFloat64",
"(",
"key",
"string",
",",
"defaults",
"...",
"float64",
")",
"float64",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"ck",
".",
"Value",
",",
"32",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
]
| // MustFloat64 get cookie as float64 with default | [
"MustFloat64",
"get",
"cookie",
"as",
"float64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L361-L374 |
8,772 | lunny/tango | cookie.go | MustBool | func (c *cookies) MustBool(key string, defaults ...bool) bool {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return false
}
v, err := strconv.ParseBool(ck.Value)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | go | func (c *cookies) MustBool(key string, defaults ...bool) bool {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return false
}
v, err := strconv.ParseBool(ck.Value)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | [
"func",
"(",
"c",
"*",
"cookies",
")",
"MustBool",
"(",
"key",
"string",
",",
"defaults",
"...",
"bool",
")",
"bool",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"ck",
".",
"Value",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
]
| // MustBool get cookie as bool with default | [
"MustBool",
"get",
"cookie",
"as",
"bool",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L377-L390 |
8,773 | lunny/tango | cookie.go | Cookie | func (ctx *Context) Cookie(key string, defaults ...string) string {
return ctx.Cookies().MustString(key, defaults...)
} | go | func (ctx *Context) Cookie(key string, defaults ...string) string {
return ctx.Cookies().MustString(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"Cookie",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustString",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // Cookie returns cookie as string with default | [
"Cookie",
"returns",
"cookie",
"as",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L393-L395 |
8,774 | lunny/tango | cookie.go | CookieEscape | func (ctx *Context) CookieEscape(key string, defaults ...string) string {
return ctx.Cookies().MustEscape(key, defaults...)
} | go | func (ctx *Context) CookieEscape(key string, defaults ...string) string {
return ctx.Cookies().MustEscape(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieEscape",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustEscape",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieEscape returns cookie as escaped string with default | [
"CookieEscape",
"returns",
"cookie",
"as",
"escaped",
"string",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L398-L400 |
8,775 | lunny/tango | cookie.go | CookieInt | func (ctx *Context) CookieInt(key string, defaults ...int) int {
return ctx.Cookies().MustInt(key, defaults...)
} | go | func (ctx *Context) CookieInt(key string, defaults ...int) int {
return ctx.Cookies().MustInt(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieInt",
"(",
"key",
"string",
",",
"defaults",
"...",
"int",
")",
"int",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustInt",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieInt returns cookie as int with default | [
"CookieInt",
"returns",
"cookie",
"as",
"int",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L403-L405 |
8,776 | lunny/tango | cookie.go | CookieInt32 | func (ctx *Context) CookieInt32(key string, defaults ...int32) int32 {
return ctx.Cookies().MustInt32(key, defaults...)
} | go | func (ctx *Context) CookieInt32(key string, defaults ...int32) int32 {
return ctx.Cookies().MustInt32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieInt32",
"(",
"key",
"string",
",",
"defaults",
"...",
"int32",
")",
"int32",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustInt32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieInt32 returns cookie as int32 with default | [
"CookieInt32",
"returns",
"cookie",
"as",
"int32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L408-L410 |
8,777 | lunny/tango | cookie.go | CookieInt64 | func (ctx *Context) CookieInt64(key string, defaults ...int64) int64 {
return ctx.Cookies().MustInt64(key, defaults...)
} | go | func (ctx *Context) CookieInt64(key string, defaults ...int64) int64 {
return ctx.Cookies().MustInt64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieInt64",
"(",
"key",
"string",
",",
"defaults",
"...",
"int64",
")",
"int64",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustInt64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieInt64 returns cookie as int64 with default | [
"CookieInt64",
"returns",
"cookie",
"as",
"int64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L413-L415 |
8,778 | lunny/tango | cookie.go | CookieUint | func (ctx *Context) CookieUint(key string, defaults ...uint) uint {
return ctx.Cookies().MustUint(key, defaults...)
} | go | func (ctx *Context) CookieUint(key string, defaults ...uint) uint {
return ctx.Cookies().MustUint(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieUint",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint",
")",
"uint",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustUint",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieUint returns cookie as uint with default | [
"CookieUint",
"returns",
"cookie",
"as",
"uint",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L418-L420 |
8,779 | lunny/tango | cookie.go | CookieUint32 | func (ctx *Context) CookieUint32(key string, defaults ...uint32) uint32 {
return ctx.Cookies().MustUint32(key, defaults...)
} | go | func (ctx *Context) CookieUint32(key string, defaults ...uint32) uint32 {
return ctx.Cookies().MustUint32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieUint32",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint32",
")",
"uint32",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustUint32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieUint32 returns cookie as uint32 with default | [
"CookieUint32",
"returns",
"cookie",
"as",
"uint32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L423-L425 |
8,780 | lunny/tango | cookie.go | CookieUint64 | func (ctx *Context) CookieUint64(key string, defaults ...uint64) uint64 {
return ctx.Cookies().MustUint64(key, defaults...)
} | go | func (ctx *Context) CookieUint64(key string, defaults ...uint64) uint64 {
return ctx.Cookies().MustUint64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieUint64",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint64",
")",
"uint64",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustUint64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieUint64 returns cookie as uint64 with default | [
"CookieUint64",
"returns",
"cookie",
"as",
"uint64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L428-L430 |
8,781 | lunny/tango | cookie.go | CookieFloat32 | func (ctx *Context) CookieFloat32(key string, defaults ...float32) float32 {
return ctx.Cookies().MustFloat32(key, defaults...)
} | go | func (ctx *Context) CookieFloat32(key string, defaults ...float32) float32 {
return ctx.Cookies().MustFloat32(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieFloat32",
"(",
"key",
"string",
",",
"defaults",
"...",
"float32",
")",
"float32",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustFloat32",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieFloat32 returns cookie as float32 with default | [
"CookieFloat32",
"returns",
"cookie",
"as",
"float32",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L433-L435 |
8,782 | lunny/tango | cookie.go | CookieFloat64 | func (ctx *Context) CookieFloat64(key string, defaults ...float64) float64 {
return ctx.Cookies().MustFloat64(key, defaults...)
} | go | func (ctx *Context) CookieFloat64(key string, defaults ...float64) float64 {
return ctx.Cookies().MustFloat64(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieFloat64",
"(",
"key",
"string",
",",
"defaults",
"...",
"float64",
")",
"float64",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustFloat64",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieFloat64 returns cookie as float64 with default | [
"CookieFloat64",
"returns",
"cookie",
"as",
"float64",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L438-L440 |
8,783 | lunny/tango | cookie.go | CookieBool | func (ctx *Context) CookieBool(key string, defaults ...bool) bool {
return ctx.Cookies().MustBool(key, defaults...)
} | go | func (ctx *Context) CookieBool(key string, defaults ...bool) bool {
return ctx.Cookies().MustBool(key, defaults...)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"CookieBool",
"(",
"key",
"string",
",",
"defaults",
"...",
"bool",
")",
"bool",
"{",
"return",
"ctx",
".",
"Cookies",
"(",
")",
".",
"MustBool",
"(",
"key",
",",
"defaults",
"...",
")",
"\n",
"}"
]
| // CookieBool returns cookie as bool with default | [
"CookieBool",
"returns",
"cookie",
"as",
"bool",
"with",
"default"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L443-L445 |
8,784 | lunny/tango | cookie.go | Int32 | func (c *secureCookies) Int32(key string) (int32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseInt(s, 10, 32)
return int32(v), err
} | go | func (c *secureCookies) Int32(key string) (int32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseInt(s, 10, 32)
return int32(v), err
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"Int32",
"(",
"key",
"string",
")",
"(",
"int32",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"32",
")",
"\n",
"return",
"int32",
"(",
"v",
")",
",",
"err",
"\n",
"}"
]
| // Int32 gets int32 data | [
"Int32",
"gets",
"int32",
"data"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L520-L528 |
8,785 | lunny/tango | cookie.go | Int64 | func (c *secureCookies) Int64(key string) (int64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
return strconv.ParseInt(s, 10, 64)
} | go | func (c *secureCookies) Int64(key string) (int64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
return strconv.ParseInt(s, 10, 64)
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"Int64",
"(",
"key",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"return",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"}"
]
| // Int64 gets int64 data | [
"Int64",
"gets",
"int64",
"data"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L531-L538 |
8,786 | lunny/tango | cookie.go | Uint | func (c *secureCookies) Uint(key string) (uint, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseUint(s, 10, 64)
return uint(v), err
} | go | func (c *secureCookies) Uint(key string) (uint, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseUint(s, 10, 64)
return uint(v), err
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"Uint",
"(",
"key",
"string",
")",
"(",
"uint",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"return",
"uint",
"(",
"v",
")",
",",
"err",
"\n",
"}"
]
| // Uint gets uint data | [
"Uint",
"gets",
"uint",
"data"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L541-L549 |
8,787 | lunny/tango | cookie.go | Uint64 | func (c *secureCookies) Uint64(key string) (uint64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
return strconv.ParseUint(s, 10, 64)
} | go | func (c *secureCookies) Uint64(key string) (uint64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
return strconv.ParseUint(s, 10, 64)
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"Uint64",
"(",
"key",
"string",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"return",
"strconv",
".",
"ParseUint",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"}"
]
| // Uint64 gets unit64 data | [
"Uint64",
"gets",
"unit64",
"data"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L563-L570 |
8,788 | lunny/tango | cookie.go | Float32 | func (c *secureCookies) Float32(key string) (float32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseFloat(s, 32)
return float32(v), err
} | go | func (c *secureCookies) Float32(key string) (float32, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseFloat(s, 32)
return float32(v), err
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"Float32",
"(",
"key",
"string",
")",
"(",
"float32",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"s",
",",
"32",
")",
"\n",
"return",
"float32",
"(",
"v",
")",
",",
"err",
"\n",
"}"
]
| // Float32 gets float32 data | [
"Float32",
"gets",
"float32",
"data"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L573-L581 |
8,789 | lunny/tango | cookie.go | Float64 | func (c *secureCookies) Float64(key string) (float64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
return strconv.ParseFloat(s, 32)
} | go | func (c *secureCookies) Float64(key string) (float64, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return 0, err
}
s := parseSecureCookie(c.secret, ck.Value)
return strconv.ParseFloat(s, 32)
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"Float64",
"(",
"key",
"string",
")",
"(",
"float64",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"return",
"strconv",
".",
"ParseFloat",
"(",
"s",
",",
"32",
")",
"\n",
"}"
]
| // Float64 gets float64 data | [
"Float64",
"gets",
"float64",
"data"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L584-L591 |
8,790 | lunny/tango | cookie.go | Bool | func (c *secureCookies) Bool(key string) (bool, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return false, err
}
s := parseSecureCookie(c.secret, ck.Value)
return strconv.ParseBool(s)
} | go | func (c *secureCookies) Bool(key string) (bool, error) {
ck, err := c.req.Cookie(key)
if err != nil {
return false, err
}
s := parseSecureCookie(c.secret, ck.Value)
return strconv.ParseBool(s)
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"Bool",
"(",
"key",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"return",
"strconv",
".",
"ParseBool",
"(",
"s",
")",
"\n",
"}"
]
| // Bool gets bool data | [
"Bool",
"gets",
"bool",
"data"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L594-L601 |
8,791 | lunny/tango | cookie.go | MustString | func (c *secureCookies) MustString(key string, defaults ...string) string {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
s := parseSecureCookie(c.secret, ck.Value)
return s
} | go | func (c *secureCookies) MustString(key string, defaults ...string) string {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
s := parseSecureCookie(c.secret, ck.Value)
return s
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"MustString",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"return",
"s",
"\n",
"}"
]
| // MustString gets data | [
"MustString",
"gets",
"data"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L604-L614 |
8,792 | lunny/tango | cookie.go | MustEscape | func (c *secureCookies) MustEscape(key string, defaults ...string) string {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
s := parseSecureCookie(c.secret, ck.Value)
return template.HTMLEscapeString(s)
} | go | func (c *secureCookies) MustEscape(key string, defaults ...string) string {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return ""
}
s := parseSecureCookie(c.secret, ck.Value)
return template.HTMLEscapeString(s)
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"MustEscape",
"(",
"key",
"string",
",",
"defaults",
"...",
"string",
")",
"string",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"return",
"template",
".",
"HTMLEscapeString",
"(",
"s",
")",
"\n",
"}"
]
| // MustEscape gets data escaped | [
"MustEscape",
"gets",
"data",
"escaped"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L617-L627 |
8,793 | lunny/tango | cookie.go | MustInt | func (c *secureCookies) MustInt(key string, defaults ...int) int {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.Atoi(s)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | go | func (c *secureCookies) MustInt(key string, defaults ...int) int {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.Atoi(s)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"MustInt",
"(",
"key",
"string",
",",
"defaults",
"...",
"int",
")",
"int",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"s",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
]
| // MustInt gets data int | [
"MustInt",
"gets",
"data",
"int"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L630-L644 |
8,794 | lunny/tango | cookie.go | MustInt32 | func (c *secureCookies) MustInt32(key string, defaults ...int32) int32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseInt(s, 10, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return int32(v)
} | go | func (c *secureCookies) MustInt32(key string, defaults ...int32) int32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseInt(s, 10, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return int32(v)
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"MustInt32",
"(",
"key",
"string",
",",
"defaults",
"...",
"int32",
")",
"int32",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"32",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"int32",
"(",
"v",
")",
"\n",
"}"
]
| // MustInt32 gets data int32 | [
"MustInt32",
"gets",
"data",
"int32"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L647-L661 |
8,795 | lunny/tango | cookie.go | MustUint | func (c *secureCookies) MustUint(key string, defaults ...uint) uint {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseUint(s, 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return uint(v)
} | go | func (c *secureCookies) MustUint(key string, defaults ...uint) uint {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseUint(s, 10, 64)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return uint(v)
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"MustUint",
"(",
"key",
"string",
",",
"defaults",
"...",
"uint",
")",
"uint",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"uint",
"(",
"v",
")",
"\n",
"}"
]
| // MustUint gets data unit type | [
"MustUint",
"gets",
"data",
"unit",
"type"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L681-L695 |
8,796 | lunny/tango | cookie.go | MustFloat32 | func (c *secureCookies) MustFloat32(key string, defaults ...float32) float32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseFloat(s, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return float32(v)
} | go | func (c *secureCookies) MustFloat32(key string, defaults ...float32) float32 {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return 0
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseFloat(s, 32)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return float32(v)
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"MustFloat32",
"(",
"key",
"string",
",",
"defaults",
"...",
"float32",
")",
"float32",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"s",
",",
"32",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"float32",
"(",
"v",
")",
"\n",
"}"
]
| // MustFloat32 gets data float32 type | [
"MustFloat32",
"gets",
"data",
"float32",
"type"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L732-L746 |
8,797 | lunny/tango | cookie.go | MustBool | func (c *secureCookies) MustBool(key string, defaults ...bool) bool {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return false
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseBool(s)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | go | func (c *secureCookies) MustBool(key string, defaults ...bool) bool {
ck, err := c.req.Cookie(key)
if err != nil {
if len(defaults) > 0 {
return defaults[0]
}
return false
}
s := parseSecureCookie(c.secret, ck.Value)
v, err := strconv.ParseBool(s)
if len(defaults) > 0 && err != nil {
return defaults[0]
}
return v
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"MustBool",
"(",
"key",
"string",
",",
"defaults",
"...",
"bool",
")",
"bool",
"{",
"ck",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"s",
":=",
"parseSecureCookie",
"(",
"c",
".",
"secret",
",",
"ck",
".",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"s",
")",
"\n",
"if",
"len",
"(",
"defaults",
")",
">",
"0",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"defaults",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
]
| // MustBool gets data bool type | [
"MustBool",
"gets",
"data",
"bool",
"type"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L766-L780 |
8,798 | lunny/tango | cookie.go | NewSecureCookie | func NewSecureCookie(secret, name string, val string, age ...int64) *http.Cookie {
var buf bytes.Buffer
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
encoder.Write([]byte(val))
encoder.Close()
cookie := secCookieValue(secret, buf.Bytes())
return NewCookie(name, cookie, age...)
} | go | func NewSecureCookie(secret, name string, val string, age ...int64) *http.Cookie {
var buf bytes.Buffer
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
encoder.Write([]byte(val))
encoder.Close()
cookie := secCookieValue(secret, buf.Bytes())
return NewCookie(name, cookie, age...)
} | [
"func",
"NewSecureCookie",
"(",
"secret",
",",
"name",
"string",
",",
"val",
"string",
",",
"age",
"...",
"int64",
")",
"*",
"http",
".",
"Cookie",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"encoder",
":=",
"base64",
".",
"NewEncoder",
"(",
"base64",
".",
"StdEncoding",
",",
"&",
"buf",
")",
"\n",
"encoder",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"val",
")",
")",
"\n",
"encoder",
".",
"Close",
"(",
")",
"\n\n",
"cookie",
":=",
"secCookieValue",
"(",
"secret",
",",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"return",
"NewCookie",
"(",
"name",
",",
"cookie",
",",
"age",
"...",
")",
"\n",
"}"
]
| // NewSecureCookie generates a new secure cookie | [
"NewSecureCookie",
"generates",
"a",
"new",
"secure",
"cookie"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L789-L797 |
8,799 | lunny/tango | cookie.go | Expire | func (c *secureCookies) Expire(key string, expire time.Time) {
ck := c.Get(key)
if ck != nil {
ck.Expires = expire
ck.Value = secCookieValue(c.secret, []byte(ck.Value))
c.Set(ck)
}
} | go | func (c *secureCookies) Expire(key string, expire time.Time) {
ck := c.Get(key)
if ck != nil {
ck.Expires = expire
ck.Value = secCookieValue(c.secret, []byte(ck.Value))
c.Set(ck)
}
} | [
"func",
"(",
"c",
"*",
"secureCookies",
")",
"Expire",
"(",
"key",
"string",
",",
"expire",
"time",
".",
"Time",
")",
"{",
"ck",
":=",
"c",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"ck",
"!=",
"nil",
"{",
"ck",
".",
"Expires",
"=",
"expire",
"\n",
"ck",
".",
"Value",
"=",
"secCookieValue",
"(",
"c",
".",
"secret",
",",
"[",
"]",
"byte",
"(",
"ck",
".",
"Value",
")",
")",
"\n",
"c",
".",
"Set",
"(",
"ck",
")",
"\n",
"}",
"\n",
"}"
]
| // Expire sets key expire time | [
"Expire",
"sets",
"key",
"expire",
"time"
]
| eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1 | https://github.com/lunny/tango/blob/eff25c79c1b7824c5a21d3e6a44bc6bf8f955df1/cookie.go#L800-L807 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.