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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
16,700 | hekmon/transmissionrpc | controller.go | New | func New(host, user, password string, conf *AdvancedConfig) (c *Client, err error) {
// Config
if conf != nil {
// Check custom config
if conf.Port == 0 {
conf.Port = defaultPort
}
if conf.RPCURI == "" {
conf.RPCURI = defaultRPCPath
}
if conf.HTTPTimeout == 0 {
conf.HTTPTimeout = defaultTimeout
}
if conf.UserAgent == "" {
conf.UserAgent = defaultUserAgent
}
} else {
// Spawn default config
conf = &AdvancedConfig{
// HTTPS false by default
Port: defaultPort,
RPCURI: defaultRPCPath,
HTTPTimeout: defaultTimeout,
UserAgent: defaultUserAgent,
}
}
// Build & validate URL
var scheme string
if conf.HTTPS {
scheme = "https"
} else {
scheme = "http"
}
remoteURL, err := url.Parse(fmt.Sprintf("%s://%s:%d%s", scheme, host, conf.Port, conf.RPCURI))
if err != nil {
err = fmt.Errorf("can't build a valid URL: %v", err)
return
}
// Initialize & return ready to use client
c = &Client{
url: remoteURL.String(),
user: user,
password: password,
userAgent: conf.UserAgent,
rnd: rand.New(rand.NewSource(time.Now().Unix())),
httpC: &http.Client{
Timeout: conf.HTTPTimeout,
},
}
return
} | go | func New(host, user, password string, conf *AdvancedConfig) (c *Client, err error) {
// Config
if conf != nil {
// Check custom config
if conf.Port == 0 {
conf.Port = defaultPort
}
if conf.RPCURI == "" {
conf.RPCURI = defaultRPCPath
}
if conf.HTTPTimeout == 0 {
conf.HTTPTimeout = defaultTimeout
}
if conf.UserAgent == "" {
conf.UserAgent = defaultUserAgent
}
} else {
// Spawn default config
conf = &AdvancedConfig{
// HTTPS false by default
Port: defaultPort,
RPCURI: defaultRPCPath,
HTTPTimeout: defaultTimeout,
UserAgent: defaultUserAgent,
}
}
// Build & validate URL
var scheme string
if conf.HTTPS {
scheme = "https"
} else {
scheme = "http"
}
remoteURL, err := url.Parse(fmt.Sprintf("%s://%s:%d%s", scheme, host, conf.Port, conf.RPCURI))
if err != nil {
err = fmt.Errorf("can't build a valid URL: %v", err)
return
}
// Initialize & return ready to use client
c = &Client{
url: remoteURL.String(),
user: user,
password: password,
userAgent: conf.UserAgent,
rnd: rand.New(rand.NewSource(time.Now().Unix())),
httpC: &http.Client{
Timeout: conf.HTTPTimeout,
},
}
return
} | [
"func",
"New",
"(",
"host",
",",
"user",
",",
"password",
"string",
",",
"conf",
"*",
"AdvancedConfig",
")",
"(",
"c",
"*",
"Client",
",",
"err",
"error",
")",
"{",
"// Config",
"if",
"conf",
"!=",
"nil",
"{",
"// Check custom config",
"if",
"conf",
".... | // New returns an initialized and ready to use Controller | [
"New",
"returns",
"an",
"initialized",
"and",
"ready",
"to",
"use",
"Controller"
] | 4352aea9f1b8457261dc9b03e8d32ced8fa1a471 | https://github.com/hekmon/transmissionrpc/blob/4352aea9f1b8457261dc9b03e8d32ced8fa1a471/controller.go#L46-L96 |
16,701 | hekmon/transmissionrpc | session_arguments.go | GetSpeed | func (u *Units) GetSpeed() (speed cunits.Bits) {
return cunits.ImportInByte(float64(u.SpeedBytes))
} | go | func (u *Units) GetSpeed() (speed cunits.Bits) {
return cunits.ImportInByte(float64(u.SpeedBytes))
} | [
"func",
"(",
"u",
"*",
"Units",
")",
"GetSpeed",
"(",
")",
"(",
"speed",
"cunits",
".",
"Bits",
")",
"{",
"return",
"cunits",
".",
"ImportInByte",
"(",
"float64",
"(",
"u",
".",
"SpeedBytes",
")",
")",
"\n",
"}"
] | // GetSpeed returns the speed in a handy format | [
"GetSpeed",
"returns",
"the",
"speed",
"in",
"a",
"handy",
"format"
] | 4352aea9f1b8457261dc9b03e8d32ced8fa1a471 | https://github.com/hekmon/transmissionrpc/blob/4352aea9f1b8457261dc9b03e8d32ced8fa1a471/session_arguments.go#L152-L154 |
16,702 | hekmon/transmissionrpc | session_arguments.go | GetSize | func (u *Units) GetSize() (size cunits.Bits) {
return cunits.ImportInByte(float64(u.SizeBytes))
} | go | func (u *Units) GetSize() (size cunits.Bits) {
return cunits.ImportInByte(float64(u.SizeBytes))
} | [
"func",
"(",
"u",
"*",
"Units",
")",
"GetSize",
"(",
")",
"(",
"size",
"cunits",
".",
"Bits",
")",
"{",
"return",
"cunits",
".",
"ImportInByte",
"(",
"float64",
"(",
"u",
".",
"SizeBytes",
")",
")",
"\n",
"}"
] | // GetSize returns the size in a handy format | [
"GetSize",
"returns",
"the",
"size",
"in",
"a",
"handy",
"format"
] | 4352aea9f1b8457261dc9b03e8d32ced8fa1a471 | https://github.com/hekmon/transmissionrpc/blob/4352aea9f1b8457261dc9b03e8d32ced8fa1a471/session_arguments.go#L157-L159 |
16,703 | hekmon/transmissionrpc | session_arguments.go | GetMemory | func (u *Units) GetMemory() (memory cunits.Bits) {
return cunits.ImportInByte(float64(u.MemoryBytes))
} | go | func (u *Units) GetMemory() (memory cunits.Bits) {
return cunits.ImportInByte(float64(u.MemoryBytes))
} | [
"func",
"(",
"u",
"*",
"Units",
")",
"GetMemory",
"(",
")",
"(",
"memory",
"cunits",
".",
"Bits",
")",
"{",
"return",
"cunits",
".",
"ImportInByte",
"(",
"float64",
"(",
"u",
".",
"MemoryBytes",
")",
")",
"\n",
"}"
] | // GetMemory returns the memory in a handy format | [
"GetMemory",
"returns",
"the",
"memory",
"in",
"a",
"handy",
"format"
] | 4352aea9f1b8457261dc9b03e8d32ced8fa1a471 | https://github.com/hekmon/transmissionrpc/blob/4352aea9f1b8457261dc9b03e8d32ced8fa1a471/session_arguments.go#L162-L164 |
16,704 | hekmon/transmissionrpc | session_stats.go | GetDownloaded | func (cs *CumulativeStats) GetDownloaded() (downloaded cunits.Bits) {
return cunits.ImportInByte(float64(cs.DownloadedBytes))
} | go | func (cs *CumulativeStats) GetDownloaded() (downloaded cunits.Bits) {
return cunits.ImportInByte(float64(cs.DownloadedBytes))
} | [
"func",
"(",
"cs",
"*",
"CumulativeStats",
")",
"GetDownloaded",
"(",
")",
"(",
"downloaded",
"cunits",
".",
"Bits",
")",
"{",
"return",
"cunits",
".",
"ImportInByte",
"(",
"float64",
"(",
"cs",
".",
"DownloadedBytes",
")",
")",
"\n",
"}"
] | // GetDownloaded returns cumulative stats downloaded size in a handy format | [
"GetDownloaded",
"returns",
"cumulative",
"stats",
"downloaded",
"size",
"in",
"a",
"handy",
"format"
] | 4352aea9f1b8457261dc9b03e8d32ced8fa1a471 | https://github.com/hekmon/transmissionrpc/blob/4352aea9f1b8457261dc9b03e8d32ced8fa1a471/session_stats.go#L46-L48 |
16,705 | hekmon/transmissionrpc | session_stats.go | GetUploaded | func (cs *CumulativeStats) GetUploaded() (uploaded cunits.Bits) {
return cunits.ImportInByte(float64(cs.UploadedBytes))
} | go | func (cs *CumulativeStats) GetUploaded() (uploaded cunits.Bits) {
return cunits.ImportInByte(float64(cs.UploadedBytes))
} | [
"func",
"(",
"cs",
"*",
"CumulativeStats",
")",
"GetUploaded",
"(",
")",
"(",
"uploaded",
"cunits",
".",
"Bits",
")",
"{",
"return",
"cunits",
".",
"ImportInByte",
"(",
"float64",
"(",
"cs",
".",
"UploadedBytes",
")",
")",
"\n",
"}"
] | // GetUploaded returns cumulative stats uploaded size in a handy format | [
"GetUploaded",
"returns",
"cumulative",
"stats",
"uploaded",
"size",
"in",
"a",
"handy",
"format"
] | 4352aea9f1b8457261dc9b03e8d32ced8fa1a471 | https://github.com/hekmon/transmissionrpc/blob/4352aea9f1b8457261dc9b03e8d32ced8fa1a471/session_stats.go#L51-L53 |
16,706 | alphazero/Go-Redis | future.go | send | func send(c chan result, v interface{}, e Error) {
c <- result{v, e}
} | go | func send(c chan result, v interface{}, e Error) {
c <- result{v, e}
} | [
"func",
"send",
"(",
"c",
"chan",
"result",
",",
"v",
"interface",
"{",
"}",
",",
"e",
"Error",
")",
"{",
"c",
"<-",
"result",
"{",
"v",
",",
"e",
"}",
"\n",
"}"
] | // creates a result struct using the provided references
// and sends it on the specified channel. | [
"creates",
"a",
"result",
"struct",
"using",
"the",
"provided",
"references",
"and",
"sends",
"it",
"on",
"the",
"specified",
"channel",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/future.go#L40-L42 |
16,707 | alphazero/Go-Redis | synchclient.go | NewSynchClient | func NewSynchClient() (c Client, err Error) {
spec := DefaultSpec()
c, err = NewSynchClientWithSpec(spec)
if err != nil {
log.Println("NewSynchClientWithSpec raised error: ", err)
}
if c == nil {
log.Println("NewSynchClientWithSpec returned nil Client.")
err = newSystemError("NewSynchClientWithSpec returned nil Client")
}
return
} | go | func NewSynchClient() (c Client, err Error) {
spec := DefaultSpec()
c, err = NewSynchClientWithSpec(spec)
if err != nil {
log.Println("NewSynchClientWithSpec raised error: ", err)
}
if c == nil {
log.Println("NewSynchClientWithSpec returned nil Client.")
err = newSystemError("NewSynchClientWithSpec returned nil Client")
}
return
} | [
"func",
"NewSynchClient",
"(",
")",
"(",
"c",
"Client",
",",
"err",
"Error",
")",
"{",
"spec",
":=",
"DefaultSpec",
"(",
")",
"\n",
"c",
",",
"err",
"=",
"NewSynchClientWithSpec",
"(",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"... | // Create a new syncClient and connects to the Redis server using the
// default ConnectionSpec.
// | [
"Create",
"a",
"new",
"syncClient",
"and",
"connects",
"to",
"the",
"Redis",
"server",
"using",
"the",
"default",
"ConnectionSpec",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L36-L47 |
16,708 | alphazero/Go-Redis | synchclient.go | NewSynchClientWithSpec | func NewSynchClientWithSpec(spec *ConnectionSpec) (c Client, err Error) {
_c := new(syncClient)
_c.conn, err = NewSyncConnection(spec)
if err != nil {
return nil, withError(err)
}
// _c.conn = conn
return _c, nil
} | go | func NewSynchClientWithSpec(spec *ConnectionSpec) (c Client, err Error) {
_c := new(syncClient)
_c.conn, err = NewSyncConnection(spec)
if err != nil {
return nil, withError(err)
}
// _c.conn = conn
return _c, nil
} | [
"func",
"NewSynchClientWithSpec",
"(",
"spec",
"*",
"ConnectionSpec",
")",
"(",
"c",
"Client",
",",
"err",
"Error",
")",
"{",
"_c",
":=",
"new",
"(",
"syncClient",
")",
"\n",
"_c",
".",
"conn",
",",
"err",
"=",
"NewSyncConnection",
"(",
"spec",
")",
"\... | // Create a new syncClient and connects to the Redis server using the
// specified ConnectionSpec.
// | [
"Create",
"a",
"new",
"syncClient",
"and",
"connects",
"to",
"the",
"Redis",
"server",
"using",
"the",
"specified",
"ConnectionSpec",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L52-L60 |
16,709 | alphazero/Go-Redis | synchclient.go | Get | func (c *syncClient) Get(arg0 string) (result []byte, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&GET, [][]byte{arg0bytes})
if err == nil {
result = resp.GetBulkData()
}
return result, err
} | go | func (c *syncClient) Get(arg0 string) (result []byte, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&GET, [][]byte{arg0bytes})
if err == nil {
result = resp.GetBulkData()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Get",
"(",
"arg0",
"string",
")",
"(",
"result",
"[",
"]",
"byte",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n\n",
"var",
"resp",
"Response",
"\n",
"resp",
"... | // Redis GET command. | [
"Redis",
"GET",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L73-L83 |
16,710 | alphazero/Go-Redis | synchclient.go | Set | func (c *syncClient) Set(arg0 string, arg1 []byte) (err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
_, err = c.conn.ServiceRequest(&SET, [][]byte{arg0bytes, arg1bytes})
return
} | go | func (c *syncClient) Set(arg0 string, arg1 []byte) (err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
_, err = c.conn.ServiceRequest(&SET, [][]byte{arg0bytes, arg1bytes})
return
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Set",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"byte",
")",
"(",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
"arg1",
"\n\n",
"_",
",",
... | // Redis SET command. | [
"Redis",
"SET",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L98-L104 |
16,711 | alphazero/Go-Redis | synchclient.go | Mget | func (c *syncClient) Mget(arg0 string, arg1 []string) (result [][]byte, err Error) {
args := appendAndConvert(arg0, arg1...)
var resp Response
resp, err = c.conn.ServiceRequest(&MGET, args)
if err == nil {
result = resp.GetMultiBulkData()
}
return result, err
} | go | func (c *syncClient) Mget(arg0 string, arg1 []string) (result [][]byte, err Error) {
args := appendAndConvert(arg0, arg1...)
var resp Response
resp, err = c.conn.ServiceRequest(&MGET, args)
if err == nil {
result = resp.GetMultiBulkData()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Mget",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"string",
")",
"(",
"result",
"[",
"]",
"[",
"]",
"byte",
",",
"err",
"Error",
")",
"{",
"args",
":=",
"appendAndConvert",
"(",
"arg0",
",",
"arg1",
"... | // Redis MGET command. | [
"Redis",
"MGET",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L244-L252 |
16,712 | alphazero/Go-Redis | synchclient.go | Decrby | func (c *syncClient) Decrby(arg0 string, arg1 int64) (result int64, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
var resp Response
resp, err = c.conn.ServiceRequest(&DECRBY, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.GetNumberValue()
}
return result, err
} | go | func (c *syncClient) Decrby(arg0 string, arg1 int64) (result int64, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
var resp Response
resp, err = c.conn.ServiceRequest(&DECRBY, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.GetNumberValue()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Decrby",
"(",
"arg0",
"string",
",",
"arg1",
"int64",
")",
"(",
"result",
"int64",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
"[",
"]",
... | // Redis DECRBY command. | [
"Redis",
"DECRBY",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L295-L306 |
16,713 | alphazero/Go-Redis | synchclient.go | Rpush | func (c *syncClient) Rpush(arg0 string, arg1 []byte) (err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
_, err = c.conn.ServiceRequest(&RPUSH, [][]byte{arg0bytes, arg1bytes})
return
} | go | func (c *syncClient) Rpush(arg0 string, arg1 []byte) (err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
_, err = c.conn.ServiceRequest(&RPUSH, [][]byte{arg0bytes, arg1bytes})
return
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Rpush",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"byte",
")",
"(",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
"arg1",
"\n\n",
"_",
",",... | // Redis RPUSH command. | [
"Redis",
"RPUSH",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L385-L391 |
16,714 | alphazero/Go-Redis | synchclient.go | Lpop | func (c *syncClient) Lpop(arg0 string) (result []byte, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&LPOP, [][]byte{arg0bytes})
if err == nil {
result = resp.GetBulkData()
}
return result, err
} | go | func (c *syncClient) Lpop(arg0 string) (result []byte, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&LPOP, [][]byte{arg0bytes})
if err == nil {
result = resp.GetBulkData()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Lpop",
"(",
"arg0",
"string",
")",
"(",
"result",
"[",
"]",
"byte",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n\n",
"var",
"resp",
"Response",
"\n",
"resp",
... | // Redis LPOP command. | [
"Redis",
"LPOP",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L480-L490 |
16,715 | alphazero/Go-Redis | synchclient.go | Rpop | func (c *syncClient) Rpop(arg0 string) (result []byte, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&RPOP, [][]byte{arg0bytes})
if err == nil {
result = resp.GetBulkData()
}
return result, err
} | go | func (c *syncClient) Rpop(arg0 string) (result []byte, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&RPOP, [][]byte{arg0bytes})
if err == nil {
result = resp.GetBulkData()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Rpop",
"(",
"arg0",
"string",
")",
"(",
"result",
"[",
"]",
"byte",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n\n",
"var",
"resp",
"Response",
"\n",
"resp",
... | // Redis RPOP command. | [
"Redis",
"RPOP",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L507-L517 |
16,716 | alphazero/Go-Redis | synchclient.go | Rpoplpush | func (c *syncClient) Rpoplpush(arg0 string, arg1 string) (result []byte, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(arg1)
var resp Response
resp, err = c.conn.ServiceRequest(&RPOPLPUSH, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.GetBulkData()
}
return result, err
} | go | func (c *syncClient) Rpoplpush(arg0 string, arg1 string) (result []byte, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(arg1)
var resp Response
resp, err = c.conn.ServiceRequest(&RPOPLPUSH, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.GetBulkData()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Rpoplpush",
"(",
"arg0",
"string",
",",
"arg1",
"string",
")",
"(",
"result",
"[",
"]",
"byte",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":="... | // Redis RPOPLPUSH command. | [
"Redis",
"RPOPLPUSH",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L534-L545 |
16,717 | alphazero/Go-Redis | synchclient.go | Sadd | func (c *syncClient) Sadd(arg0 string, arg1 []byte) (result bool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
var resp Response
resp, err = c.conn.ServiceRequest(&SADD, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.GetBooleanValue()
}
return result, err
} | go | func (c *syncClient) Sadd(arg0 string, arg1 []byte) (result bool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
var resp Response
resp, err = c.conn.ServiceRequest(&SADD, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.GetBooleanValue()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Sadd",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"byte",
")",
"(",
"result",
"bool",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
"ar... | // Redis SADD command. | [
"Redis",
"SADD",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L563-L574 |
16,718 | alphazero/Go-Redis | synchclient.go | Scard | func (c *syncClient) Scard(arg0 string) (result int64, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&SCARD, [][]byte{arg0bytes})
if err == nil {
result = resp.GetNumberValue()
}
return result, err
} | go | func (c *syncClient) Scard(arg0 string) (result int64, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&SCARD, [][]byte{arg0bytes})
if err == nil {
result = resp.GetNumberValue()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Scard",
"(",
"arg0",
"string",
")",
"(",
"result",
"int64",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n\n",
"var",
"resp",
"Response",
"\n",
"resp",
",",
"err"... | // Redis SCARD command. | [
"Redis",
"SCARD",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L620-L630 |
16,719 | alphazero/Go-Redis | synchclient.go | Sinterstore | func (c *syncClient) Sinterstore(arg0 string, arg1 []string) (err Error) {
_, err = c.conn.ServiceRequest(&SINTERSTORE, appendAndConvert(arg0, arg1...))
return
} | go | func (c *syncClient) Sinterstore(arg0 string, arg1 []string) (err Error) {
_, err = c.conn.ServiceRequest(&SINTERSTORE, appendAndConvert(arg0, arg1...))
return
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Sinterstore",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"string",
")",
"(",
"err",
"Error",
")",
"{",
"_",
",",
"err",
"=",
"c",
".",
"conn",
".",
"ServiceRequest",
"(",
"&",
"SINTERSTORE",
",",
"appen... | // Redis SINTERSTORE command. | [
"Redis",
"SINTERSTORE",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L673-L676 |
16,720 | alphazero/Go-Redis | synchclient.go | Sdiffstore | func (c *syncClient) Sdiffstore(arg0 string, arg1 []string) (err Error) {
_, err = c.conn.ServiceRequest(&SDIFFSTORE, appendAndConvert(arg0, arg1...))
return
} | go | func (c *syncClient) Sdiffstore(arg0 string, arg1 []string) (err Error) {
_, err = c.conn.ServiceRequest(&SDIFFSTORE, appendAndConvert(arg0, arg1...))
return
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Sdiffstore",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"string",
")",
"(",
"err",
"Error",
")",
"{",
"_",
",",
"err",
"=",
"c",
".",
"conn",
".",
"ServiceRequest",
"(",
"&",
"SDIFFSTORE",
",",
"appendA... | // Redis SDIFFSTORE command. | [
"Redis",
"SDIFFSTORE",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L708-L711 |
16,721 | alphazero/Go-Redis | synchclient.go | Hgetall | func (c *syncClient) Hgetall(arg0 string) (result [][]byte, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&HGETALL, [][]byte{arg0bytes})
if err == nil {
result = resp.GetMultiBulkData()
}
return result, err
} | go | func (c *syncClient) Hgetall(arg0 string) (result [][]byte, err Error) {
arg0bytes := []byte(arg0)
var resp Response
resp, err = c.conn.ServiceRequest(&HGETALL, [][]byte{arg0bytes})
if err == nil {
result = resp.GetMultiBulkData()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Hgetall",
"(",
"arg0",
"string",
")",
"(",
"result",
"[",
"]",
"[",
"]",
"byte",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n\n",
"var",
"resp",
"Response",
"... | // Redis HGETALL command. | [
"Redis",
"HGETALL",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L879-L889 |
16,722 | alphazero/Go-Redis | synchclient.go | Move | func (c *syncClient) Move(arg0 string, arg1 int64) (result bool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
var resp Response
resp, err = c.conn.ServiceRequest(&MOVE, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.GetBooleanValue()
}
return result, err
} | go | func (c *syncClient) Move(arg0 string, arg1 int64) (result bool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
var resp Response
resp, err = c.conn.ServiceRequest(&MOVE, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.GetBooleanValue()
}
return result, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Move",
"(",
"arg0",
"string",
",",
"arg1",
"int64",
")",
"(",
"result",
"bool",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
"[",
"]",
"b... | // Redis MOVE command. | [
"Redis",
"MOVE",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L904-L915 |
16,723 | alphazero/Go-Redis | synchclient.go | Publish | func (c *syncClient) Publish(arg0 string, arg1 []byte) (rcvCnt int64, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
var resp Response
resp, err = c.conn.ServiceRequest(&PUBLISH, [][]byte{arg0bytes, arg1bytes})
if err == nil {
rcvCnt = resp.GetNumberValue()
}
return rcvCnt, err
} | go | func (c *syncClient) Publish(arg0 string, arg1 []byte) (rcvCnt int64, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
var resp Response
resp, err = c.conn.ServiceRequest(&PUBLISH, [][]byte{arg0bytes, arg1bytes})
if err == nil {
rcvCnt = resp.GetNumberValue()
}
return rcvCnt, err
} | [
"func",
"(",
"c",
"*",
"syncClient",
")",
"Publish",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"byte",
")",
"(",
"rcvCnt",
"int64",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
... | // Redis PUBLISH command. | [
"Redis",
"PUBLISH",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/synchclient.go#L935-L945 |
16,724 | alphazero/Go-Redis | specification.go | GetKeyType | func GetKeyType(typename string) (keytype KeyType) {
switch {
case typename == "none":
keytype = RT_NONE
case typename == "string":
keytype = RT_STRING
case typename == "list":
keytype = RT_LIST
case typename == "set":
keytype = RT_SET
case typename == "zset":
keytype = RT_ZSET
default:
panic("BUG - unknown type: " + string(keytype))
}
return
} | go | func GetKeyType(typename string) (keytype KeyType) {
switch {
case typename == "none":
keytype = RT_NONE
case typename == "string":
keytype = RT_STRING
case typename == "list":
keytype = RT_LIST
case typename == "set":
keytype = RT_SET
case typename == "zset":
keytype = RT_ZSET
default:
panic("BUG - unknown type: " + string(keytype))
}
return
} | [
"func",
"GetKeyType",
"(",
"typename",
"string",
")",
"(",
"keytype",
"KeyType",
")",
"{",
"switch",
"{",
"case",
"typename",
"==",
"\"",
"\"",
":",
"keytype",
"=",
"RT_NONE",
"\n",
"case",
"typename",
"==",
"\"",
"\"",
":",
"keytype",
"=",
"RT_STRING",
... | // Returns KeyType by name
// | [
"Returns",
"KeyType",
"by",
"name"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/specification.go#L47-L63 |
16,725 | alphazero/Go-Redis | specification.go | anyClientRedisErrSpec | func anyClientRedisErrSpec(spec *MethodSpec, method string) *MethodSpec {
// Commands that can return ERR given random input and state
switch method {
// Redis-Spec: Background save may be running already and can raise -ERR
case "Bgsave":
spec.NoRedisErr = false
}
return spec
} | go | func anyClientRedisErrSpec(spec *MethodSpec, method string) *MethodSpec {
// Commands that can return ERR given random input and state
switch method {
// Redis-Spec: Background save may be running already and can raise -ERR
case "Bgsave":
spec.NoRedisErr = false
}
return spec
} | [
"func",
"anyClientRedisErrSpec",
"(",
"spec",
"*",
"MethodSpec",
",",
"method",
"string",
")",
"*",
"MethodSpec",
"{",
"// Commands that can return ERR given random input and state",
"switch",
"method",
"{",
"// Redis-Spec: Background save may be running already and can raise -ERR"... | // spec.NoRedisErr
// Specs MethodSpec.NoRedisErr - client type invariant | [
"spec",
".",
"NoRedisErr",
"Specs",
"MethodSpec",
".",
"NoRedisErr",
"-",
"client",
"type",
"invariant"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/specification.go#L246-L255 |
16,726 | alphazero/Go-Redis | specification.go | anyClientNilResultValueSpec | func anyClientNilResultValueSpec(spec *MethodSpec, method string) *MethodSpec {
// Commands that can return nil/zero-value given random input and state
switch method {
// Redis-Spec: DB may be empty and AllKeys can return nil result
// REVU: check if this is actually conformant
case "AllKeys":
spec.NoNilResultValue = false
}
return spec
} | go | func anyClientNilResultValueSpec(spec *MethodSpec, method string) *MethodSpec {
// Commands that can return nil/zero-value given random input and state
switch method {
// Redis-Spec: DB may be empty and AllKeys can return nil result
// REVU: check if this is actually conformant
case "AllKeys":
spec.NoNilResultValue = false
}
return spec
} | [
"func",
"anyClientNilResultValueSpec",
"(",
"spec",
"*",
"MethodSpec",
",",
"method",
"string",
")",
"*",
"MethodSpec",
"{",
"// Commands that can return nil/zero-value given random input and state",
"switch",
"method",
"{",
"// Redis-Spec: DB may be empty and AllKeys can return ni... | // spec.NoNilResultValue
// Specs MethodSpec.NoNilResultValue - client type invariant | [
"spec",
".",
"NoNilResultValue",
"Specs",
"MethodSpec",
".",
"NoNilResultValue",
"-",
"client",
"type",
"invariant"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/specification.go#L259-L269 |
16,727 | alphazero/Go-Redis | connection.go | DefaultSpec | func DefaultSpec() *ConnectionSpec {
return &ConnectionSpec{
DefaultRedisHost,
DefaultRedisPort,
DefaultRedisPassword,
DefaultRedisDB,
DefaultTCPReadBuffSize,
DefaultTCPWriteBuffSize,
DefaultTCPReadTimeoutNSecs,
DefaultTCPWriteTimeoutNSecs,
DefaultTCPKeepalive,
DefaultTCPLinger,
DefaultReqChanSize,
DefaultRespChanSize,
DefaultHeartbeatSecs,
DefaultProtocol,
}
} | go | func DefaultSpec() *ConnectionSpec {
return &ConnectionSpec{
DefaultRedisHost,
DefaultRedisPort,
DefaultRedisPassword,
DefaultRedisDB,
DefaultTCPReadBuffSize,
DefaultTCPWriteBuffSize,
DefaultTCPReadTimeoutNSecs,
DefaultTCPWriteTimeoutNSecs,
DefaultTCPKeepalive,
DefaultTCPLinger,
DefaultReqChanSize,
DefaultRespChanSize,
DefaultHeartbeatSecs,
DefaultProtocol,
}
} | [
"func",
"DefaultSpec",
"(",
")",
"*",
"ConnectionSpec",
"{",
"return",
"&",
"ConnectionSpec",
"{",
"DefaultRedisHost",
",",
"DefaultRedisPort",
",",
"DefaultRedisPassword",
",",
"DefaultRedisDB",
",",
"DefaultTCPReadBuffSize",
",",
"DefaultTCPWriteBuffSize",
",",
"Defau... | // Creates a ConnectionSpec using default settings.
// using the DefaultXXX consts of redis package. | [
"Creates",
"a",
"ConnectionSpec",
"using",
"default",
"settings",
".",
"using",
"the",
"DefaultXXX",
"consts",
"of",
"redis",
"package",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L97-L114 |
16,728 | alphazero/Go-Redis | connection.go | Db | func (spec *ConnectionSpec) Db(db int) *ConnectionSpec {
spec.db = db
return spec
} | go | func (spec *ConnectionSpec) Db(db int) *ConnectionSpec {
spec.db = db
return spec
} | [
"func",
"(",
"spec",
"*",
"ConnectionSpec",
")",
"Db",
"(",
"db",
"int",
")",
"*",
"ConnectionSpec",
"{",
"spec",
".",
"db",
"=",
"db",
"\n",
"return",
"spec",
"\n",
"}"
] | // Sets the db for connection spec and returns the reference
// Note that you should not this after you have already connected. | [
"Sets",
"the",
"db",
"for",
"connection",
"spec",
"and",
"returns",
"the",
"reference",
"Note",
"that",
"you",
"should",
"not",
"this",
"after",
"you",
"have",
"already",
"connected",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L118-L121 |
16,729 | alphazero/Go-Redis | connection.go | Host | func (spec *ConnectionSpec) Host(host string) *ConnectionSpec {
spec.host = host
return spec
} | go | func (spec *ConnectionSpec) Host(host string) *ConnectionSpec {
spec.host = host
return spec
} | [
"func",
"(",
"spec",
"*",
"ConnectionSpec",
")",
"Host",
"(",
"host",
"string",
")",
"*",
"ConnectionSpec",
"{",
"spec",
".",
"host",
"=",
"host",
"\n",
"return",
"spec",
"\n",
"}"
] | // Sets the host for connection spec and returns the reference
// Note that you should not this after you have already connected. | [
"Sets",
"the",
"host",
"for",
"connection",
"spec",
"and",
"returns",
"the",
"reference",
"Note",
"that",
"you",
"should",
"not",
"this",
"after",
"you",
"have",
"already",
"connected",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L125-L128 |
16,730 | alphazero/Go-Redis | connection.go | Port | func (spec *ConnectionSpec) Port(port int) *ConnectionSpec {
spec.port = port
return spec
} | go | func (spec *ConnectionSpec) Port(port int) *ConnectionSpec {
spec.port = port
return spec
} | [
"func",
"(",
"spec",
"*",
"ConnectionSpec",
")",
"Port",
"(",
"port",
"int",
")",
"*",
"ConnectionSpec",
"{",
"spec",
".",
"port",
"=",
"port",
"\n",
"return",
"spec",
"\n",
"}"
] | // Sets the port for connection spec and returns the reference
// Note that you should not this after you have already connected. | [
"Sets",
"the",
"port",
"for",
"connection",
"spec",
"and",
"returns",
"the",
"reference",
"Note",
"that",
"you",
"should",
"not",
"this",
"after",
"you",
"have",
"already",
"connected",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L132-L135 |
16,731 | alphazero/Go-Redis | connection.go | Password | func (spec *ConnectionSpec) Password(password string) *ConnectionSpec {
spec.password = password
return spec
} | go | func (spec *ConnectionSpec) Password(password string) *ConnectionSpec {
spec.password = password
return spec
} | [
"func",
"(",
"spec",
"*",
"ConnectionSpec",
")",
"Password",
"(",
"password",
"string",
")",
"*",
"ConnectionSpec",
"{",
"spec",
".",
"password",
"=",
"password",
"\n",
"return",
"spec",
"\n",
"}"
] | // Sets the password for connection spec and returns the reference
// Note that you should not this after you have already connected. | [
"Sets",
"the",
"password",
"for",
"connection",
"spec",
"and",
"returns",
"the",
"reference",
"Note",
"that",
"you",
"should",
"not",
"this",
"after",
"you",
"have",
"already",
"connected",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L139-L142 |
16,732 | alphazero/Go-Redis | connection.go | String | func (c *connHdl) String() string {
return fmt.Sprintf("conn<redis-server@%s:%d [db %d]>", c.spec.host, c.spec.port, c.spec.db)
} | go | func (c *connHdl) String() string {
return fmt.Sprintf("conn<redis-server@%s:%d [db %d]>", c.spec.host, c.spec.port, c.spec.db)
} | [
"func",
"(",
"c",
"*",
"connHdl",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"spec",
".",
"host",
",",
"c",
".",
"spec",
".",
"port",
",",
"c",
".",
"spec",
".",
"db",
")",
"\n",
... | // Returns minimal info string for logging, etc | [
"Returns",
"minimal",
"info",
"string",
"for",
"logging",
"etc"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L218-L220 |
16,733 | alphazero/Go-Redis | connection.go | NewSyncConnection | func NewSyncConnection(spec *ConnectionSpec) (c SyncConnection, err Error) {
defer func() {
if e := recover(); e != nil {
connerr := e.(error)
err = newSystemErrorWithCause("NewSyncConnection", connerr)
}
}()
connHdl := newConnHdl(spec)
connHdl.connect()
c = connHdl
return
} | go | func NewSyncConnection(spec *ConnectionSpec) (c SyncConnection, err Error) {
defer func() {
if e := recover(); e != nil {
connerr := e.(error)
err = newSystemErrorWithCause("NewSyncConnection", connerr)
}
}()
connHdl := newConnHdl(spec)
connHdl.connect()
c = connHdl
return
} | [
"func",
"NewSyncConnection",
"(",
"spec",
"*",
"ConnectionSpec",
")",
"(",
"c",
"SyncConnection",
",",
"err",
"Error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"e",
":=",
"recover",
"(",
")",
";",
"e",
"!=",
"nil",
"{",
"connerr",
":=",
"e",
... | // Creates a new SyncConnection using the provided ConnectionSpec.
// Note that this function will also connect to the specified redis server. | [
"Creates",
"a",
"new",
"SyncConnection",
"using",
"the",
"provided",
"ConnectionSpec",
".",
"Note",
"that",
"this",
"function",
"will",
"also",
"connect",
"to",
"the",
"specified",
"redis",
"server",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L320-L332 |
16,734 | alphazero/Go-Redis | connection.go | ServiceRequest | func (c *connHdl) ServiceRequest(cmd *Command, args [][]byte) (resp Response, err Error) {
loginfo := "connHdl.ServiceRequest"
defer func() {
if re := recover(); re != nil {
// REVU - needs to be logged - TODO
err = newSystemErrorWithCause("ServiceRequest", re.(error))
}
}()
if !c.connected {
panic(fmt.Errorf("Connection %s is alredy closed", c.String()))
}
if cmd == &QUIT {
c.disconnect()
return
}
buff := CreateRequestBytes(cmd, args)
sendRequest(c.conn, buff) // panics
// REVU - this demands resp to be non-nil even in case of io errors
// TODO - look into this
resp, e := GetResponse(c.reader, cmd)
if e != nil {
panic(fmt.Errorf("%s(%s) - failed to get response", loginfo, cmd.Code))
}
// handle Redis server ERR - don't panic
if resp.IsError() {
redismsg := fmt.Sprintf(" [%s]: %s", cmd.Code, resp.GetMessage())
err = newRedisError(redismsg)
}
return
} | go | func (c *connHdl) ServiceRequest(cmd *Command, args [][]byte) (resp Response, err Error) {
loginfo := "connHdl.ServiceRequest"
defer func() {
if re := recover(); re != nil {
// REVU - needs to be logged - TODO
err = newSystemErrorWithCause("ServiceRequest", re.(error))
}
}()
if !c.connected {
panic(fmt.Errorf("Connection %s is alredy closed", c.String()))
}
if cmd == &QUIT {
c.disconnect()
return
}
buff := CreateRequestBytes(cmd, args)
sendRequest(c.conn, buff) // panics
// REVU - this demands resp to be non-nil even in case of io errors
// TODO - look into this
resp, e := GetResponse(c.reader, cmd)
if e != nil {
panic(fmt.Errorf("%s(%s) - failed to get response", loginfo, cmd.Code))
}
// handle Redis server ERR - don't panic
if resp.IsError() {
redismsg := fmt.Sprintf(" [%s]: %s", cmd.Code, resp.GetMessage())
err = newRedisError(redismsg)
}
return
} | [
"func",
"(",
"c",
"*",
"connHdl",
")",
"ServiceRequest",
"(",
"cmd",
"*",
"Command",
",",
"args",
"[",
"]",
"[",
"]",
"byte",
")",
"(",
"resp",
"Response",
",",
"err",
"Error",
")",
"{",
"loginfo",
":=",
"\"",
"\"",
"\n\n",
"defer",
"func",
"(",
... | // Implementation of SyncConnection.ServiceRequest. | [
"Implementation",
"of",
"SyncConnection",
".",
"ServiceRequest",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L335-L371 |
16,735 | alphazero/Go-Redis | connection.go | newAsyncConnHdl | func newAsyncConnHdl(spec *ConnectionSpec) *asyncConnHdl {
c := new(asyncConnHdl)
// connection base
connHdl := newConnHdl(spec) // panics
c.super = connHdl
// conn management
c.managerCtl = make(workerCtl)
c.feedback = make(chan workerStatus)
c.shutdown = make(chan bool, 1)
// request processing
c.writer = bufio.NewWriterSize(connHdl.conn, spec.wBufSize)
c.reqProcCtl = make(workerCtl)
c.pendingReqs = make(chan asyncReqPtr, spec.reqChanCap) // REVU for PubSub
// fault processing
c.faults = make(chan asyncReqPtr, spec.reqChanCap) // REVU - not sure about sizing
// response processing
c.rspProcCtl = make(workerCtl)
switch spec.protocol {
case REDIS_DB:
c.heartbeatCtl = make(workerCtl)
c.pendingResps = make(chan asyncReqPtr, spec.rspChanCap)
case REDIS_PUBSUB:
c.subscriptions = make(map[string]*Subscription)
}
// REVU - this is state - TODO move to startup
c.isShutdown = false
return c
} | go | func newAsyncConnHdl(spec *ConnectionSpec) *asyncConnHdl {
c := new(asyncConnHdl)
// connection base
connHdl := newConnHdl(spec) // panics
c.super = connHdl
// conn management
c.managerCtl = make(workerCtl)
c.feedback = make(chan workerStatus)
c.shutdown = make(chan bool, 1)
// request processing
c.writer = bufio.NewWriterSize(connHdl.conn, spec.wBufSize)
c.reqProcCtl = make(workerCtl)
c.pendingReqs = make(chan asyncReqPtr, spec.reqChanCap) // REVU for PubSub
// fault processing
c.faults = make(chan asyncReqPtr, spec.reqChanCap) // REVU - not sure about sizing
// response processing
c.rspProcCtl = make(workerCtl)
switch spec.protocol {
case REDIS_DB:
c.heartbeatCtl = make(workerCtl)
c.pendingResps = make(chan asyncReqPtr, spec.rspChanCap)
case REDIS_PUBSUB:
c.subscriptions = make(map[string]*Subscription)
}
// REVU - this is state - TODO move to startup
c.isShutdown = false
return c
} | [
"func",
"newAsyncConnHdl",
"(",
"spec",
"*",
"ConnectionSpec",
")",
"*",
"asyncConnHdl",
"{",
"c",
":=",
"new",
"(",
"asyncConnHdl",
")",
"\n\n",
"// connection base",
"connHdl",
":=",
"newConnHdl",
"(",
"spec",
")",
"// panics",
"\n",
"c",
".",
"super",
"="... | // Creates a new asyncConnHdl with a new connHdl as its delegated 'super'.
// Note it does not start the processing goroutines for the channels.
//
// REVU - PubSub could be checked here | [
"Creates",
"a",
"new",
"asyncConnHdl",
"with",
"a",
"new",
"connHdl",
"as",
"its",
"delegated",
"super",
".",
"Note",
"it",
"does",
"not",
"start",
"the",
"processing",
"goroutines",
"for",
"the",
"channels",
".",
"REVU",
"-",
"PubSub",
"could",
"be",
"che... | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L483-L519 |
16,736 | alphazero/Go-Redis | connection.go | startup | func (c *asyncConnHdl) startup() {
protocol := c.spec().protocol
go c.worker(manager, "manager", managementTask, c.managerCtl, nil)
c.managerCtl <- start
// heartbeat only on REDIS_DB protocol
if protocol == REDIS_DB {
go c.worker(heartbeatworker, "heartbeat", heartbeatTask, c.heartbeatCtl, c.feedback)
c.heartbeatCtl <- start
}
go c.worker(requesthandler, "request-processor", reqProcessingTask, c.reqProcCtl, c.feedback)
c.reqProcCtl <- start
var rspProcTask workerTask
switch protocol {
case REDIS_DB:
rspProcTask = dbRspProcessingTask
case REDIS_PUBSUB:
rspProcTask = msgProcessingTask
// cmd := SUBSCRIBE
// c.pendingResps <- &asyncRequestInfo{0, 0, &cmd, nil, nil, nil}
}
go c.worker(responsehandler, "response-processor", rspProcTask, c.rspProcCtl, c.feedback)
c.rspProcCtl <- start
// REVU - pretty please TODO do the customized log
// log.Printf("<INFO> %s - READY", c)
} | go | func (c *asyncConnHdl) startup() {
protocol := c.spec().protocol
go c.worker(manager, "manager", managementTask, c.managerCtl, nil)
c.managerCtl <- start
// heartbeat only on REDIS_DB protocol
if protocol == REDIS_DB {
go c.worker(heartbeatworker, "heartbeat", heartbeatTask, c.heartbeatCtl, c.feedback)
c.heartbeatCtl <- start
}
go c.worker(requesthandler, "request-processor", reqProcessingTask, c.reqProcCtl, c.feedback)
c.reqProcCtl <- start
var rspProcTask workerTask
switch protocol {
case REDIS_DB:
rspProcTask = dbRspProcessingTask
case REDIS_PUBSUB:
rspProcTask = msgProcessingTask
// cmd := SUBSCRIBE
// c.pendingResps <- &asyncRequestInfo{0, 0, &cmd, nil, nil, nil}
}
go c.worker(responsehandler, "response-processor", rspProcTask, c.rspProcCtl, c.feedback)
c.rspProcCtl <- start
// REVU - pretty please TODO do the customized log
// log.Printf("<INFO> %s - READY", c)
} | [
"func",
"(",
"c",
"*",
"asyncConnHdl",
")",
"startup",
"(",
")",
"{",
"protocol",
":=",
"c",
".",
"spec",
"(",
")",
".",
"protocol",
"\n\n",
"go",
"c",
".",
"worker",
"(",
"manager",
",",
"\"",
"\"",
",",
"managementTask",
",",
"c",
".",
"managerCt... | // responsible for managing the various moving parts of the asyncConnHdl | [
"responsible",
"for",
"managing",
"the",
"various",
"moving",
"parts",
"of",
"the",
"asyncConnHdl"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L681-L711 |
16,737 | alphazero/Go-Redis | connection.go | reqProcessingTask | func reqProcessingTask(c *asyncConnHdl, ctl workerCtl) (ic *interrupt_code, ts *taskStatus) {
var err error
var errmsg string
bytecnt := 0
blen := 0
bufsize := c.spec().wBufSize
var sig interrupt_code
select {
case req := <-c.pendingReqs:
blen, err := c.processAsyncRequest(req)
if err != nil {
errmsg = fmt.Sprintf("processAsyncRequest error in initial phase")
goto proc_error
}
bytecnt += blen
case sig := <-ctl:
return &sig, &ok_status
}
for bytecnt < bufsize {
select {
case req := <-c.pendingReqs:
blen, err = c.processAsyncRequest(req)
if err != nil {
errmsg = fmt.Sprintf("processAsyncRequest error in batch phase")
goto proc_error
}
if blen > 0 {
bytecnt += blen
} else {
bytecnt = 0
}
case sig = <-ctl:
ic = &sig
goto done
default:
goto done
}
}
done:
c.writer.Flush()
return ic, &ok_status
proc_error:
log.Println(errmsg, err)
return nil, &taskStatus{snderr, err}
} | go | func reqProcessingTask(c *asyncConnHdl, ctl workerCtl) (ic *interrupt_code, ts *taskStatus) {
var err error
var errmsg string
bytecnt := 0
blen := 0
bufsize := c.spec().wBufSize
var sig interrupt_code
select {
case req := <-c.pendingReqs:
blen, err := c.processAsyncRequest(req)
if err != nil {
errmsg = fmt.Sprintf("processAsyncRequest error in initial phase")
goto proc_error
}
bytecnt += blen
case sig := <-ctl:
return &sig, &ok_status
}
for bytecnt < bufsize {
select {
case req := <-c.pendingReqs:
blen, err = c.processAsyncRequest(req)
if err != nil {
errmsg = fmt.Sprintf("processAsyncRequest error in batch phase")
goto proc_error
}
if blen > 0 {
bytecnt += blen
} else {
bytecnt = 0
}
case sig = <-ctl:
ic = &sig
goto done
default:
goto done
}
}
done:
c.writer.Flush()
return ic, &ok_status
proc_error:
log.Println(errmsg, err)
return nil, &taskStatus{snderr, err}
} | [
"func",
"reqProcessingTask",
"(",
"c",
"*",
"asyncConnHdl",
",",
"ctl",
"workerCtl",
")",
"(",
"ic",
"*",
"interrupt_code",
",",
"ts",
"*",
"taskStatus",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"errmsg",
"string",
"\n\n",
"bytecnt",
":=",
"0",
"\n"... | // Pending further tests, this addresses bug in earlier version
// and can be interrupted | [
"Pending",
"further",
"tests",
"this",
"addresses",
"bug",
"in",
"earlier",
"version",
"and",
"can",
"be",
"interrupted"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L958-L1010 |
16,738 | alphazero/Go-Redis | connection.go | nextId | func (c *asyncConnHdl) nextId() (id int64) {
id = c.nextid
c.nextid++
return
} | go | func (c *asyncConnHdl) nextId() (id int64) {
id = c.nextid
c.nextid++
return
} | [
"func",
"(",
"c",
"*",
"asyncConnHdl",
")",
"nextId",
"(",
")",
"(",
"id",
"int64",
")",
"{",
"id",
"=",
"c",
".",
"nextid",
"\n",
"c",
".",
"nextid",
"++",
"\n",
"return",
"\n",
"}"
] | // request id needs to be unique in context of associated connection
// only one goroutine calls this so no need to provide concurrency guards | [
"request",
"id",
"needs",
"to",
"be",
"unique",
"in",
"context",
"of",
"associated",
"connection",
"only",
"one",
"goroutine",
"calls",
"this",
"so",
"no",
"need",
"to",
"provide",
"concurrency",
"guards"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/connection.go#L1050-L1054 |
16,739 | alphazero/Go-Redis | bench/asyncbench.go | benchTask | func benchTask(taskspec taskSpec, iterations int, workers int, printReport bool) (delta time.Duration, err error) {
// channel to signal completion
signal := make(chan int, workers)
// spec and initialize an AsyncClient
// will flush your db13 as noted in README ..
spec := redis.DefaultSpec().Db(13).Password("go-redis")
client, e := redis.NewAsynchClientWithSpec(spec)
if e != nil {
log.Println("Error creating client for worker: ", e)
return -1, e
}
defer client.Quit()
// panics
setup(client)
t0 := time.Now()
for i := 0; i < workers; i++ {
id := fmt.Sprintf("%d", i)
go taskspec.task(id, signal, client, iterations)
}
// wait for completion
for i := 0; i < workers; i++ {
<-signal
}
delta = time.Now().Sub(t0)
if printReport {
report(taskspec.name, workers, delta, iterations*workers)
}
return
} | go | func benchTask(taskspec taskSpec, iterations int, workers int, printReport bool) (delta time.Duration, err error) {
// channel to signal completion
signal := make(chan int, workers)
// spec and initialize an AsyncClient
// will flush your db13 as noted in README ..
spec := redis.DefaultSpec().Db(13).Password("go-redis")
client, e := redis.NewAsynchClientWithSpec(spec)
if e != nil {
log.Println("Error creating client for worker: ", e)
return -1, e
}
defer client.Quit()
// panics
setup(client)
t0 := time.Now()
for i := 0; i < workers; i++ {
id := fmt.Sprintf("%d", i)
go taskspec.task(id, signal, client, iterations)
}
// wait for completion
for i := 0; i < workers; i++ {
<-signal
}
delta = time.Now().Sub(t0)
if printReport {
report(taskspec.name, workers, delta, iterations*workers)
}
return
} | [
"func",
"benchTask",
"(",
"taskspec",
"taskSpec",
",",
"iterations",
"int",
",",
"workers",
"int",
",",
"printReport",
"bool",
")",
"(",
"delta",
"time",
".",
"Duration",
",",
"err",
"error",
")",
"{",
"// channel to signal completion",
"signal",
":=",
"make",... | // Use a single redis.AsyncClient with specified number
// of workers to bench concurrent load on the async client | [
"Use",
"a",
"single",
"redis",
".",
"AsyncClient",
"with",
"specified",
"number",
"of",
"workers",
"to",
"bench",
"concurrent",
"load",
"on",
"the",
"async",
"client"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/bench/asyncbench.go#L70-L105 |
16,740 | alphazero/Go-Redis | asynchclient.go | NewAsynchClientWithSpec | func NewAsynchClientWithSpec(spec *ConnectionSpec) (client AsyncClient, err Error) {
c := new(asyncClient)
c.conn, err = NewAsynchConnection(spec)
if err != nil {
if debug() {
log.Println("NewAsyncConnection() raised error: ", err)
}
return nil, err
}
return c, nil
} | go | func NewAsynchClientWithSpec(spec *ConnectionSpec) (client AsyncClient, err Error) {
c := new(asyncClient)
c.conn, err = NewAsynchConnection(spec)
if err != nil {
if debug() {
log.Println("NewAsyncConnection() raised error: ", err)
}
return nil, err
}
return c, nil
} | [
"func",
"NewAsynchClientWithSpec",
"(",
"spec",
"*",
"ConnectionSpec",
")",
"(",
"client",
"AsyncClient",
",",
"err",
"Error",
")",
"{",
"c",
":=",
"new",
"(",
"asyncClient",
")",
"\n",
"c",
".",
"conn",
",",
"err",
"=",
"NewAsynchConnection",
"(",
"spec",... | // Create a new asynClient and connects to the Redis server using the
// specified ConnectionSpec.
// | [
"Create",
"a",
"new",
"asynClient",
"and",
"connects",
"to",
"the",
"Redis",
"server",
"using",
"the",
"specified",
"ConnectionSpec",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/asynchclient.go#L42-L52 |
16,741 | alphazero/Go-Redis | asynchclient.go | Getset | func (c *asyncClient) Getset(arg0 string, arg1 []byte) (result FutureBytes, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&GETSET, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.future.(FutureBytes)
}
return result, err
} | go | func (c *asyncClient) Getset(arg0 string, arg1 []byte) (result FutureBytes, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := arg1
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&GETSET, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.future.(FutureBytes)
}
return result, err
} | [
"func",
"(",
"c",
"*",
"asyncClient",
")",
"Getset",
"(",
"arg0",
"string",
",",
"arg1",
"[",
"]",
"byte",
")",
"(",
"result",
"FutureBytes",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
"... | // Redis GETSET command. | [
"Redis",
"GETSET",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/asynchclient.go#L207-L218 |
16,742 | alphazero/Go-Redis | asynchclient.go | Incr | func (c *asyncClient) Incr(arg0 string) (result FutureInt64, err Error) {
arg0bytes := []byte(arg0)
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&INCR, [][]byte{arg0bytes})
if err == nil {
result = resp.future.(FutureInt64)
}
return result, err
} | go | func (c *asyncClient) Incr(arg0 string) (result FutureInt64, err Error) {
arg0bytes := []byte(arg0)
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&INCR, [][]byte{arg0bytes})
if err == nil {
result = resp.future.(FutureInt64)
}
return result, err
} | [
"func",
"(",
"c",
"*",
"asyncClient",
")",
"Incr",
"(",
"arg0",
"string",
")",
"(",
"result",
"FutureInt64",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n\n",
"var",
"resp",
"*",
"PendingResponse",
"\n",
"r... | // Redis INCR command. | [
"Redis",
"INCR",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/asynchclient.go#L237-L247 |
16,743 | alphazero/Go-Redis | asynchclient.go | Incrby | func (c *asyncClient) Incrby(arg0 string, arg1 int64) (result FutureInt64, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&INCRBY, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.future.(FutureInt64)
}
return result, err
} | go | func (c *asyncClient) Incrby(arg0 string, arg1 int64) (result FutureInt64, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&INCRBY, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.future.(FutureInt64)
}
return result, err
} | [
"func",
"(",
"c",
"*",
"asyncClient",
")",
"Incrby",
"(",
"arg0",
"string",
",",
"arg1",
"int64",
")",
"(",
"result",
"FutureInt64",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
"[",
... | // Redis INCRBY command. | [
"Redis",
"INCRBY",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/asynchclient.go#L250-L261 |
16,744 | alphazero/Go-Redis | asynchclient.go | Renamenx | func (c *asyncClient) Renamenx(arg0 string, arg1 string) (result FutureBool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(arg1)
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&RENAMENX, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.future.(FutureBool)
}
return result, err
} | go | func (c *asyncClient) Renamenx(arg0 string, arg1 string) (result FutureBool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(arg1)
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&RENAMENX, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.future.(FutureBool)
}
return result, err
} | [
"func",
"(",
"c",
"*",
"asyncClient",
")",
"Renamenx",
"(",
"arg0",
"string",
",",
"arg1",
"string",
")",
"(",
"result",
"FutureBool",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
"[",... | // Redis RENAMENX command. | [
"Redis",
"RENAMENX",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/asynchclient.go#L315-L326 |
16,745 | alphazero/Go-Redis | asynchclient.go | Expire | func (c *asyncClient) Expire(arg0 string, arg1 int64) (result FutureBool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&EXPIRE, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.future.(FutureBool)
}
return result, err
} | go | func (c *asyncClient) Expire(arg0 string, arg1 int64) (result FutureBool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
var resp *PendingResponse
resp, err = c.conn.QueueRequest(&EXPIRE, [][]byte{arg0bytes, arg1bytes})
if err == nil {
result = resp.future.(FutureBool)
}
return result, err
} | [
"func",
"(",
"c",
"*",
"asyncClient",
")",
"Expire",
"(",
"arg0",
"string",
",",
"arg1",
"int64",
")",
"(",
"result",
"FutureBool",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1bytes",
":=",
"[",
... | // Redis EXPIRE command. | [
"Redis",
"EXPIRE",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/asynchclient.go#L340-L351 |
16,746 | alphazero/Go-Redis | asynchclient.go | Ltrim | func (c *asyncClient) Ltrim(arg0 string, arg1 int64, arg2 int64) (stat FutureBool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
arg2bytes := []byte(fmt.Sprintf("%d", arg2))
resp, err := c.conn.QueueRequest(<RIM, [][]byte{arg0bytes, arg1bytes, arg2bytes})
if err == nil {
stat = resp.future.(FutureBool)
}
return
} | go | func (c *asyncClient) Ltrim(arg0 string, arg1 int64, arg2 int64) (stat FutureBool, err Error) {
arg0bytes := []byte(arg0)
arg1bytes := []byte(fmt.Sprintf("%d", arg1))
arg2bytes := []byte(fmt.Sprintf("%d", arg2))
resp, err := c.conn.QueueRequest(<RIM, [][]byte{arg0bytes, arg1bytes, arg2bytes})
if err == nil {
stat = resp.future.(FutureBool)
}
return
} | [
"func",
"(",
"c",
"*",
"asyncClient",
")",
"Ltrim",
"(",
"arg0",
"string",
",",
"arg1",
"int64",
",",
"arg2",
"int64",
")",
"(",
"stat",
"FutureBool",
",",
"err",
"Error",
")",
"{",
"arg0bytes",
":=",
"[",
"]",
"byte",
"(",
"arg0",
")",
"\n",
"arg1... | // Redis LTRIM command. | [
"Redis",
"LTRIM",
"command",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/asynchclient.go#L450-L461 |
16,747 | alphazero/Go-Redis | protocol.go | CreateFuture | func CreateFuture(cmd *Command) (future interface{}) {
switch cmd.RespType {
case BOOLEAN:
future = newFutureBool()
case BULK:
future = newFutureBytes()
case MULTI_BULK:
future = newFutureBytesArray()
case NUMBER:
future = newFutureInt64()
case STATUS:
future = newFutureBool()
case STRING:
future = newFutureString()
case VIRTUAL:
// REVU - treating virtual futures as FutureBools (always true)
future = newFutureBool()
}
return
} | go | func CreateFuture(cmd *Command) (future interface{}) {
switch cmd.RespType {
case BOOLEAN:
future = newFutureBool()
case BULK:
future = newFutureBytes()
case MULTI_BULK:
future = newFutureBytesArray()
case NUMBER:
future = newFutureInt64()
case STATUS:
future = newFutureBool()
case STRING:
future = newFutureString()
case VIRTUAL:
// REVU - treating virtual futures as FutureBools (always true)
future = newFutureBool()
}
return
} | [
"func",
"CreateFuture",
"(",
"cmd",
"*",
"Command",
")",
"(",
"future",
"interface",
"{",
"}",
")",
"{",
"switch",
"cmd",
".",
"RespType",
"{",
"case",
"BOOLEAN",
":",
"future",
"=",
"newFutureBool",
"(",
")",
"\n",
"case",
"BULK",
":",
"future",
"=",
... | // Creates a specific Future type for the given Redis command
// and returns it as a generic reference. | [
"Creates",
"a",
"specific",
"Future",
"type",
"for",
"the",
"given",
"Redis",
"command",
"and",
"returns",
"it",
"as",
"a",
"generic",
"reference",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/protocol.go#L92-L111 |
16,748 | alphazero/Go-Redis | protocol.go | SetFutureResult | func SetFutureResult(future interface{}, cmd *Command, r Response) {
if r.IsError() {
future.(FutureResult).onError(newRedisError(r.GetMessage()))
} else {
switch cmd.RespType {
case BOOLEAN:
future.(FutureBool).set(r.GetBooleanValue())
case BULK:
future.(FutureBytes).set(r.GetBulkData())
case MULTI_BULK:
future.(FutureBytesArray).set(r.GetMultiBulkData())
case NUMBER:
future.(FutureInt64).set(r.GetNumberValue())
case STATUS:
future.(FutureBool).set(true)
case STRING:
future.(FutureString).set(r.GetStringValue())
case VIRTUAL:
// REVU - OK to treat virtual commands as FutureBool
future.(FutureBool).set(true)
}
}
} | go | func SetFutureResult(future interface{}, cmd *Command, r Response) {
if r.IsError() {
future.(FutureResult).onError(newRedisError(r.GetMessage()))
} else {
switch cmd.RespType {
case BOOLEAN:
future.(FutureBool).set(r.GetBooleanValue())
case BULK:
future.(FutureBytes).set(r.GetBulkData())
case MULTI_BULK:
future.(FutureBytesArray).set(r.GetMultiBulkData())
case NUMBER:
future.(FutureInt64).set(r.GetNumberValue())
case STATUS:
future.(FutureBool).set(true)
case STRING:
future.(FutureString).set(r.GetStringValue())
case VIRTUAL:
// REVU - OK to treat virtual commands as FutureBool
future.(FutureBool).set(true)
}
}
} | [
"func",
"SetFutureResult",
"(",
"future",
"interface",
"{",
"}",
",",
"cmd",
"*",
"Command",
",",
"r",
"Response",
")",
"{",
"if",
"r",
".",
"IsError",
"(",
")",
"{",
"future",
".",
"(",
"FutureResult",
")",
".",
"onError",
"(",
"newRedisError",
"(",
... | // Sets the type specific result value from the response for the future reference
// based on the command type. | [
"Sets",
"the",
"type",
"specific",
"result",
"value",
"from",
"the",
"response",
"for",
"the",
"future",
"reference",
"based",
"on",
"the",
"command",
"type",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/protocol.go#L115-L137 |
16,749 | alphazero/Go-Redis | compliance/compliance.go | main | func main() {
flag.Parse()
specfname, e := getSpecFileName("compliance.prop")
if e != nil {
log.Println("error -", e)
}
rmspec, e1 := readCommandsFromSpecFile(specfname)
if e1 != nil {
log.Println("error -", e1)
return
}
var rctype clientType
fmt.Println()
fmt.Println("/////////////////////////////////////")
fmt.Println("/// Go-Redis client compliance ///")
fmt.Println("/////////////////////////////////////\n")
rctype = sync
analyzeAndReport(rctype, rmspec)
rctype = async
analyzeAndReport(rctype, rmspec)
} | go | func main() {
flag.Parse()
specfname, e := getSpecFileName("compliance.prop")
if e != nil {
log.Println("error -", e)
}
rmspec, e1 := readCommandsFromSpecFile(specfname)
if e1 != nil {
log.Println("error -", e1)
return
}
var rctype clientType
fmt.Println()
fmt.Println("/////////////////////////////////////")
fmt.Println("/// Go-Redis client compliance ///")
fmt.Println("/////////////////////////////////////\n")
rctype = sync
analyzeAndReport(rctype, rmspec)
rctype = async
analyzeAndReport(rctype, rmspec)
} | [
"func",
"main",
"(",
")",
"{",
"flag",
".",
"Parse",
"(",
")",
"\n\n",
"specfname",
",",
"e",
":=",
"getSpecFileName",
"(",
"\"",
"\"",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
... | // Checks Redis client interfaces' methods against a
// a list of canonical Redis methods obtained from a
// spec file and reports the missing methods | [
"Checks",
"Redis",
"client",
"interfaces",
"methods",
"against",
"a",
"a",
"list",
"of",
"canonical",
"Redis",
"methods",
"obtained",
"from",
"a",
"spec",
"file",
"and",
"reports",
"the",
"missing",
"methods"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/compliance/compliance.go#L42-L67 |
16,750 | alphazero/Go-Redis | compliance/compliance.go | analyzeAndReport | func analyzeAndReport(rctype clientType, rmspec []string) {
defined, e2 := getDefinedMethods(rctype)
if e2 != nil {
log.Println("error -", e2)
return
}
reportCompliance(rctype, defined, rmspec)
} | go | func analyzeAndReport(rctype clientType, rmspec []string) {
defined, e2 := getDefinedMethods(rctype)
if e2 != nil {
log.Println("error -", e2)
return
}
reportCompliance(rctype, defined, rmspec)
} | [
"func",
"analyzeAndReport",
"(",
"rctype",
"clientType",
",",
"rmspec",
"[",
"]",
"string",
")",
"{",
"defined",
",",
"e2",
":=",
"getDefinedMethods",
"(",
"rctype",
")",
"\n",
"if",
"e2",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
... | // Get the defined methods for the specified client type
// and report compliance | [
"Get",
"the",
"defined",
"methods",
"for",
"the",
"specified",
"client",
"type",
"and",
"report",
"compliance"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/compliance/compliance.go#L71-L78 |
16,751 | alphazero/Go-Redis | compliance/compliance.go | reportCompliance | func reportCompliance(rctype clientType, mmap map[string]string, specms []string) {
fmt.Printf("=== compliance report [%s] =========================\n", rctype)
var nccnt = 0
for _, method := range specms {
if mmap[method] == "" {
nccnt++
fmt.Printf("not defined - [%d]: %s\n", nccnt, method)
}
}
if nccnt == 0 {
fmt.Printf("client is compliant")
}
} | go | func reportCompliance(rctype clientType, mmap map[string]string, specms []string) {
fmt.Printf("=== compliance report [%s] =========================\n", rctype)
var nccnt = 0
for _, method := range specms {
if mmap[method] == "" {
nccnt++
fmt.Printf("not defined - [%d]: %s\n", nccnt, method)
}
}
if nccnt == 0 {
fmt.Printf("client is compliant")
}
} | [
"func",
"reportCompliance",
"(",
"rctype",
"clientType",
",",
"mmap",
"map",
"[",
"string",
"]",
"string",
",",
"specms",
"[",
"]",
"string",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"rctype",
")",
"\n",
"var",
"nccnt",
"=",
"0",
... | // check method name map against spec'd method names
// and report undefined methods | [
"check",
"method",
"name",
"map",
"against",
"spec",
"d",
"method",
"names",
"and",
"report",
"undefined",
"methods"
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/compliance/compliance.go#L82-L94 |
16,752 | alphazero/Go-Redis | compliance/compliance.go | getSpecFileName | func getSpecFileName(csmetafile string) (string, error) {
var fname string
buff, e := ioutil.ReadFile(csmetafile)
if e != nil {
return fname, e
}
fname = string(buff)
return fname[:len(fname)-1], nil
} | go | func getSpecFileName(csmetafile string) (string, error) {
var fname string
buff, e := ioutil.ReadFile(csmetafile)
if e != nil {
return fname, e
}
fname = string(buff)
return fname[:len(fname)-1], nil
} | [
"func",
"getSpecFileName",
"(",
"csmetafile",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"fname",
"string",
"\n",
"buff",
",",
"e",
":=",
"ioutil",
".",
"ReadFile",
"(",
"csmetafile",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
... | // Reads the spec file to use for the check
// csmetafile is the name of the expected prop file and
// should contain just the name of another file. | [
"Reads",
"the",
"spec",
"file",
"to",
"use",
"for",
"the",
"check",
"csmetafile",
"is",
"the",
"name",
"of",
"the",
"expected",
"prop",
"file",
"and",
"should",
"contain",
"just",
"the",
"name",
"of",
"another",
"file",
"."
] | a0637b1543645181061469efea75f57ad2e3f23a | https://github.com/alphazero/Go-Redis/blob/a0637b1543645181061469efea75f57ad2e3f23a/compliance/compliance.go#L156-L164 |
16,753 | linki/instrumented_http | client.go | RoundTrip | func (it *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
statusCode := BogusStatusCode
// Remember the current time.
now := time.Now()
// Make the request using the next RoundTripper.
resp, err := it.next.RoundTrip(req)
if resp != nil {
statusCode = resp.StatusCode
}
// Observe the time it took to make the request.
RequestDurationSeconds.WithLabelValues(
req.URL.Scheme,
req.URL.Host,
it.cbs.PathProcessor(req.URL.Path),
it.cbs.QueryProcessor(req.URL.RawQuery),
req.Method,
it.cbs.CodeProcessor(statusCode),
).Observe(time.Since(now).Seconds())
// return the response and error reported from the next RoundTripper.
return resp, err
} | go | func (it *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
statusCode := BogusStatusCode
// Remember the current time.
now := time.Now()
// Make the request using the next RoundTripper.
resp, err := it.next.RoundTrip(req)
if resp != nil {
statusCode = resp.StatusCode
}
// Observe the time it took to make the request.
RequestDurationSeconds.WithLabelValues(
req.URL.Scheme,
req.URL.Host,
it.cbs.PathProcessor(req.URL.Path),
it.cbs.QueryProcessor(req.URL.RawQuery),
req.Method,
it.cbs.CodeProcessor(statusCode),
).Observe(time.Since(now).Seconds())
// return the response and error reported from the next RoundTripper.
return resp, err
} | [
"func",
"(",
"it",
"*",
"Transport",
")",
"RoundTrip",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"statusCode",
":=",
"BogusStatusCode",
"\n\n",
"// Remember the current time.",
"now",
":=",
"ti... | // RoundTrip implements http.RoundTripper. It forwards the request to the
// next RoundTripper and measures the time it took in Prometheus summary. | [
"RoundTrip",
"implements",
"http",
".",
"RoundTripper",
".",
"It",
"forwards",
"the",
"request",
"to",
"the",
"next",
"RoundTripper",
"and",
"measures",
"the",
"time",
"it",
"took",
"in",
"Prometheus",
"summary",
"."
] | ff7c0aeddedba068c35f6d07eaab3df955cba6d7 | https://github.com/linki/instrumented_http/blob/ff7c0aeddedba068c35f6d07eaab3df955cba6d7/client.go#L78-L102 |
16,754 | linki/instrumented_http | client.go | NewTransport | func NewTransport(next http.RoundTripper, cbs *Callbacks) http.RoundTripper {
// If next RoundTripper is not defined we'll use http.DefaultTransport.
if next == nil {
next = http.DefaultTransport
}
// If cbs is not defined we'll initilialize it with defaults.
if cbs == nil {
cbs = &Callbacks{}
}
// By default, path and query will be ignored.
if cbs.PathProcessor == nil {
cbs.PathProcessor = EliminatingProcessor
}
if cbs.QueryProcessor == nil {
cbs.QueryProcessor = EliminatingProcessor
}
// By default, status code is set as is.
if cbs.CodeProcessor == nil {
cbs.CodeProcessor = IntToStringProcessor
}
return &Transport{next: next, cbs: cbs}
} | go | func NewTransport(next http.RoundTripper, cbs *Callbacks) http.RoundTripper {
// If next RoundTripper is not defined we'll use http.DefaultTransport.
if next == nil {
next = http.DefaultTransport
}
// If cbs is not defined we'll initilialize it with defaults.
if cbs == nil {
cbs = &Callbacks{}
}
// By default, path and query will be ignored.
if cbs.PathProcessor == nil {
cbs.PathProcessor = EliminatingProcessor
}
if cbs.QueryProcessor == nil {
cbs.QueryProcessor = EliminatingProcessor
}
// By default, status code is set as is.
if cbs.CodeProcessor == nil {
cbs.CodeProcessor = IntToStringProcessor
}
return &Transport{next: next, cbs: cbs}
} | [
"func",
"NewTransport",
"(",
"next",
"http",
".",
"RoundTripper",
",",
"cbs",
"*",
"Callbacks",
")",
"http",
".",
"RoundTripper",
"{",
"// If next RoundTripper is not defined we'll use http.DefaultTransport.",
"if",
"next",
"==",
"nil",
"{",
"next",
"=",
"http",
"."... | // NewTransport takes a http.RoundTripper, wraps it with instrumentation and
// returns it as a new http.RoundTripper. Optionally, It can receive a
// collection of callbacks that process request path and query into a suitable
// label value. | [
"NewTransport",
"takes",
"a",
"http",
".",
"RoundTripper",
"wraps",
"it",
"with",
"instrumentation",
"and",
"returns",
"it",
"as",
"a",
"new",
"http",
".",
"RoundTripper",
".",
"Optionally",
"It",
"can",
"receive",
"a",
"collection",
"of",
"callbacks",
"that",... | ff7c0aeddedba068c35f6d07eaab3df955cba6d7 | https://github.com/linki/instrumented_http/blob/ff7c0aeddedba068c35f6d07eaab3df955cba6d7/client.go#L123-L146 |
16,755 | theplant/cldr | calendar.go | Format | func (c Calendar) Format(datetime time.Time, pattern string) (string, error) {
parsed, err := c.parseDateTimeFormat(pattern)
if err != nil {
return "", err
}
return c.formatDateTime(datetime, parsed)
} | go | func (c Calendar) Format(datetime time.Time, pattern string) (string, error) {
parsed, err := c.parseDateTimeFormat(pattern)
if err != nil {
return "", err
}
return c.formatDateTime(datetime, parsed)
} | [
"func",
"(",
"c",
"Calendar",
")",
"Format",
"(",
"datetime",
"time",
".",
"Time",
",",
"pattern",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"parsed",
",",
"err",
":=",
"c",
".",
"parseDateTimeFormat",
"(",
"pattern",
")",
"\n",
"if",
"er... | // Format takes a time struct and a format and returns a formatted
// string. Callers should use a DateFormat, TimeFormat, or DateTimeFormat
// constant. | [
"Format",
"takes",
"a",
"time",
"struct",
"and",
"a",
"format",
"and",
"returns",
"a",
"formatted",
"string",
".",
"Callers",
"should",
"use",
"a",
"DateFormat",
"TimeFormat",
"or",
"DateTimeFormat",
"constant",
"."
] | 9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2 | https://github.com/theplant/cldr/blob/9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2/calendar.go#L139-L146 |
16,756 | theplant/cldr | calendar.go | formatDateTime | func (c Calendar) formatDateTime(datetime time.Time, pattern []*datetimePatternComponent) (string, error) {
formatted := ""
for _, component := range pattern {
if component.componentType == datetimePatternComponentLiteral {
formatted += component.pattern
} else {
f, err := c.formatDateTimeComponent(datetime, component.pattern)
if err != nil {
return "", err
}
formatted += f
}
}
return strings.Trim(formatted, " ,"), nil
} | go | func (c Calendar) formatDateTime(datetime time.Time, pattern []*datetimePatternComponent) (string, error) {
formatted := ""
for _, component := range pattern {
if component.componentType == datetimePatternComponentLiteral {
formatted += component.pattern
} else {
f, err := c.formatDateTimeComponent(datetime, component.pattern)
if err != nil {
return "", err
}
formatted += f
}
}
return strings.Trim(formatted, " ,"), nil
} | [
"func",
"(",
"c",
"Calendar",
")",
"formatDateTime",
"(",
"datetime",
"time",
".",
"Time",
",",
"pattern",
"[",
"]",
"*",
"datetimePatternComponent",
")",
"(",
"string",
",",
"error",
")",
"{",
"formatted",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"com... | // formatDateTime takes a time.Time and a sequence of parsed pattern components
// and returns an internationalized string representation. | [
"formatDateTime",
"takes",
"a",
"time",
".",
"Time",
"and",
"a",
"sequence",
"of",
"parsed",
"pattern",
"components",
"and",
"returns",
"an",
"internationalized",
"string",
"representation",
"."
] | 9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2 | https://github.com/theplant/cldr/blob/9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2/calendar.go#L150-L165 |
16,757 | theplant/cldr | calendar.go | formatDateTimeComponent | func (c Calendar) formatDateTimeComponent(datetime time.Time, pattern string) (string, error) {
switch pattern[0:1] {
case string(datetimeFormatUnitEra):
return c.formatDateTimeComponentEra(datetime, len(pattern))
case string(datetimeFormatUnitYear):
return c.formatDateTimeComponentYear(datetime, len(pattern))
case string(datetimeFormatUnitMonth):
return c.formatDateTimeComponentMonth(datetime, len(pattern))
case string(datetimeFormatUnitDayOfWeek):
return c.formatDateTimeComponentDayOfWeek(datetime, len(pattern))
case string(datetimeFormatUnitDay):
return c.formatDateTimeComponentDay(datetime, len(pattern))
case string(datetimeFormatUnitHour12):
return c.formatDateTimeComponentHour12(datetime, len(pattern))
case string(datetimeFormatUnitHour24):
return c.formatDateTimeComponentHour24(datetime, len(pattern))
case string(datetimeFormatUnitMinute):
return c.formatDateTimeComponentMinute(datetime, len(pattern))
case string(datetimeFormatUnitSecond):
return c.formatDateTimeComponentSecond(datetime, len(pattern))
case string(datetimeFormatUnitPeriod):
return c.formatDateTimeComponentPeriod(datetime, len(pattern))
case string(datetimeForamtUnitQuarter):
return c.formatDateTimeComponentQuarter(datetime, len(pattern))
case string(datetimeFormatUnitTimeZone1):
fallthrough
case string(datetimeFormatUnitTimeZone2):
return c.formatDateTimeComponentTimeZone(datetime, len(pattern))
}
return "", errors.New("unknown datetime format unit: " + pattern[0:1])
} | go | func (c Calendar) formatDateTimeComponent(datetime time.Time, pattern string) (string, error) {
switch pattern[0:1] {
case string(datetimeFormatUnitEra):
return c.formatDateTimeComponentEra(datetime, len(pattern))
case string(datetimeFormatUnitYear):
return c.formatDateTimeComponentYear(datetime, len(pattern))
case string(datetimeFormatUnitMonth):
return c.formatDateTimeComponentMonth(datetime, len(pattern))
case string(datetimeFormatUnitDayOfWeek):
return c.formatDateTimeComponentDayOfWeek(datetime, len(pattern))
case string(datetimeFormatUnitDay):
return c.formatDateTimeComponentDay(datetime, len(pattern))
case string(datetimeFormatUnitHour12):
return c.formatDateTimeComponentHour12(datetime, len(pattern))
case string(datetimeFormatUnitHour24):
return c.formatDateTimeComponentHour24(datetime, len(pattern))
case string(datetimeFormatUnitMinute):
return c.formatDateTimeComponentMinute(datetime, len(pattern))
case string(datetimeFormatUnitSecond):
return c.formatDateTimeComponentSecond(datetime, len(pattern))
case string(datetimeFormatUnitPeriod):
return c.formatDateTimeComponentPeriod(datetime, len(pattern))
case string(datetimeForamtUnitQuarter):
return c.formatDateTimeComponentQuarter(datetime, len(pattern))
case string(datetimeFormatUnitTimeZone1):
fallthrough
case string(datetimeFormatUnitTimeZone2):
return c.formatDateTimeComponentTimeZone(datetime, len(pattern))
}
return "", errors.New("unknown datetime format unit: " + pattern[0:1])
} | [
"func",
"(",
"c",
"Calendar",
")",
"formatDateTimeComponent",
"(",
"datetime",
"time",
".",
"Time",
",",
"pattern",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"switch",
"pattern",
"[",
"0",
":",
"1",
"]",
"{",
"case",
"string",
"(",
"datetim... | // formatDateTimeComponent renders a single component of a datetime format
// pattern. | [
"formatDateTimeComponent",
"renders",
"a",
"single",
"component",
"of",
"a",
"datetime",
"format",
"pattern",
"."
] | 9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2 | https://github.com/theplant/cldr/blob/9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2/calendar.go#L169-L200 |
16,758 | theplant/cldr | calendar.go | formatDateTimeComponentMonthWide | func (c Calendar) formatDateTimeComponentMonthWide(month int) string {
switch month {
case 1:
return c.FormatNames.Months.Wide.Jan
case 2:
return c.FormatNames.Months.Wide.Feb
case 3:
return c.FormatNames.Months.Wide.Mar
case 4:
return c.FormatNames.Months.Wide.Apr
case 5:
return c.FormatNames.Months.Wide.May
case 6:
return c.FormatNames.Months.Wide.Jun
case 7:
return c.FormatNames.Months.Wide.Jul
case 8:
return c.FormatNames.Months.Wide.Aug
case 9:
return c.FormatNames.Months.Wide.Sep
case 10:
return c.FormatNames.Months.Wide.Oct
case 11:
return c.FormatNames.Months.Wide.Nov
case 12:
return c.FormatNames.Months.Wide.Dec
}
return ""
} | go | func (c Calendar) formatDateTimeComponentMonthWide(month int) string {
switch month {
case 1:
return c.FormatNames.Months.Wide.Jan
case 2:
return c.FormatNames.Months.Wide.Feb
case 3:
return c.FormatNames.Months.Wide.Mar
case 4:
return c.FormatNames.Months.Wide.Apr
case 5:
return c.FormatNames.Months.Wide.May
case 6:
return c.FormatNames.Months.Wide.Jun
case 7:
return c.FormatNames.Months.Wide.Jul
case 8:
return c.FormatNames.Months.Wide.Aug
case 9:
return c.FormatNames.Months.Wide.Sep
case 10:
return c.FormatNames.Months.Wide.Oct
case 11:
return c.FormatNames.Months.Wide.Nov
case 12:
return c.FormatNames.Months.Wide.Dec
}
return ""
} | [
"func",
"(",
"c",
"Calendar",
")",
"formatDateTimeComponentMonthWide",
"(",
"month",
"int",
")",
"string",
"{",
"switch",
"month",
"{",
"case",
"1",
":",
"return",
"c",
".",
"FormatNames",
".",
"Months",
".",
"Wide",
".",
"Jan",
"\n",
"case",
"2",
":",
... | // formatDateTimeComponentMonthWide renders a full text month component. | [
"formatDateTimeComponentMonthWide",
"renders",
"a",
"full",
"text",
"month",
"component",
"."
] | 9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2 | https://github.com/theplant/cldr/blob/9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2/calendar.go#L310-L339 |
16,759 | theplant/cldr | calendar.go | formatDateTimeComponentMonthNarrow | func (c Calendar) formatDateTimeComponentMonthNarrow(month int) string {
switch month {
case 1:
return c.FormatNames.Months.Narrow.Jan
case 2:
return c.FormatNames.Months.Narrow.Feb
case 3:
return c.FormatNames.Months.Narrow.Mar
case 4:
return c.FormatNames.Months.Narrow.Apr
case 5:
return c.FormatNames.Months.Narrow.May
case 6:
return c.FormatNames.Months.Narrow.Jun
case 7:
return c.FormatNames.Months.Narrow.Jul
case 8:
return c.FormatNames.Months.Narrow.Aug
case 9:
return c.FormatNames.Months.Narrow.Sep
case 10:
return c.FormatNames.Months.Narrow.Oct
case 11:
return c.FormatNames.Months.Narrow.Nov
case 12:
return c.FormatNames.Months.Narrow.Dec
}
return ""
} | go | func (c Calendar) formatDateTimeComponentMonthNarrow(month int) string {
switch month {
case 1:
return c.FormatNames.Months.Narrow.Jan
case 2:
return c.FormatNames.Months.Narrow.Feb
case 3:
return c.FormatNames.Months.Narrow.Mar
case 4:
return c.FormatNames.Months.Narrow.Apr
case 5:
return c.FormatNames.Months.Narrow.May
case 6:
return c.FormatNames.Months.Narrow.Jun
case 7:
return c.FormatNames.Months.Narrow.Jul
case 8:
return c.FormatNames.Months.Narrow.Aug
case 9:
return c.FormatNames.Months.Narrow.Sep
case 10:
return c.FormatNames.Months.Narrow.Oct
case 11:
return c.FormatNames.Months.Narrow.Nov
case 12:
return c.FormatNames.Months.Narrow.Dec
}
return ""
} | [
"func",
"(",
"c",
"Calendar",
")",
"formatDateTimeComponentMonthNarrow",
"(",
"month",
"int",
")",
"string",
"{",
"switch",
"month",
"{",
"case",
"1",
":",
"return",
"c",
".",
"FormatNames",
".",
"Months",
".",
"Narrow",
".",
"Jan",
"\n",
"case",
"2",
":... | // formatDateTimeComponentMonthNarrow renders a super-short month compontent -
// not guaranteed to be unique for different months. | [
"formatDateTimeComponentMonthNarrow",
"renders",
"a",
"super",
"-",
"short",
"month",
"compontent",
"-",
"not",
"guaranteed",
"to",
"be",
"unique",
"for",
"different",
"months",
"."
] | 9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2 | https://github.com/theplant/cldr/blob/9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2/calendar.go#L343-L372 |
16,760 | theplant/cldr | calendar.go | formatDateTimeComponentDayOfWeekNarrow | func (c Calendar) formatDateTimeComponentDayOfWeekNarrow(dayOfWeek time.Weekday) string {
switch dayOfWeek {
case time.Sunday:
return c.FormatNames.Days.Narrow.Sun
case time.Monday:
return c.FormatNames.Days.Narrow.Mon
case time.Tuesday:
return c.FormatNames.Days.Narrow.Tue
case time.Wednesday:
return c.FormatNames.Days.Narrow.Wed
case time.Thursday:
return c.FormatNames.Days.Narrow.Thu
case time.Friday:
return c.FormatNames.Days.Narrow.Fri
case time.Saturday:
return c.FormatNames.Days.Narrow.Sat
}
return ""
} | go | func (c Calendar) formatDateTimeComponentDayOfWeekNarrow(dayOfWeek time.Weekday) string {
switch dayOfWeek {
case time.Sunday:
return c.FormatNames.Days.Narrow.Sun
case time.Monday:
return c.FormatNames.Days.Narrow.Mon
case time.Tuesday:
return c.FormatNames.Days.Narrow.Tue
case time.Wednesday:
return c.FormatNames.Days.Narrow.Wed
case time.Thursday:
return c.FormatNames.Days.Narrow.Thu
case time.Friday:
return c.FormatNames.Days.Narrow.Fri
case time.Saturday:
return c.FormatNames.Days.Narrow.Sat
}
return ""
} | [
"func",
"(",
"c",
"Calendar",
")",
"formatDateTimeComponentDayOfWeekNarrow",
"(",
"dayOfWeek",
"time",
".",
"Weekday",
")",
"string",
"{",
"switch",
"dayOfWeek",
"{",
"case",
"time",
".",
"Sunday",
":",
"return",
"c",
".",
"FormatNames",
".",
"Days",
".",
"N... | // formatDateTimeComponentDayOfWeekNarrow renders a super-short day-of-week
// compontent - not guaranteed to be unique for different days. | [
"formatDateTimeComponentDayOfWeekNarrow",
"renders",
"a",
"super",
"-",
"short",
"day",
"-",
"of",
"-",
"week",
"compontent",
"-",
"not",
"guaranteed",
"to",
"be",
"unique",
"for",
"different",
"days",
"."
] | 9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2 | https://github.com/theplant/cldr/blob/9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2/calendar.go#L463-L482 |
16,761 | theplant/cldr | number.go | chunkString | func chunkString(str string, size int) []string {
if str == "" {
return []string{}
}
if size == 0 {
return []string{str}
}
chunks := make([]string, int64(math.Ceil(float64(len(str))/float64(size))))
for len(str) < len(chunks)*size {
str = " " + str
}
for i := 0; i < len(chunks); i++ {
start := i * size
stop := int64(math.Min(float64(start+size), float64(len(str))))
chunks[i] = str[start:stop]
}
chunks[0] = strings.TrimLeft(chunks[0], " ")
return chunks
} | go | func chunkString(str string, size int) []string {
if str == "" {
return []string{}
}
if size == 0 {
return []string{str}
}
chunks := make([]string, int64(math.Ceil(float64(len(str))/float64(size))))
for len(str) < len(chunks)*size {
str = " " + str
}
for i := 0; i < len(chunks); i++ {
start := i * size
stop := int64(math.Min(float64(start+size), float64(len(str))))
chunks[i] = str[start:stop]
}
chunks[0] = strings.TrimLeft(chunks[0], " ")
return chunks
} | [
"func",
"chunkString",
"(",
"str",
"string",
",",
"size",
"int",
")",
"[",
"]",
"string",
"{",
"if",
"str",
"==",
"\"",
"\"",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"size",
"==",
"0",
"{",
"return",
"[",
"]",
"str... | // chunkString takes a string and chunks it into size-sized pieces in a slice.
// If the length of the string is not divisible by the size, then the first
// chunk in the slice will be padded to compensate. | [
"chunkString",
"takes",
"a",
"string",
"and",
"chunks",
"it",
"into",
"size",
"-",
"sized",
"pieces",
"in",
"a",
"slice",
".",
"If",
"the",
"length",
"of",
"the",
"string",
"is",
"not",
"divisible",
"by",
"the",
"size",
"then",
"the",
"first",
"chunk",
... | 9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2 | https://github.com/theplant/cldr/blob/9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2/number.go#L242-L266 |
16,762 | theplant/cldr | locale.go | GetLocale | func GetLocale(locale string) (*Locale, bool) {
l, ok := locales[locale]
return l, ok
} | go | func GetLocale(locale string) (*Locale, bool) {
l, ok := locales[locale]
return l, ok
} | [
"func",
"GetLocale",
"(",
"locale",
"string",
")",
"(",
"*",
"Locale",
",",
"bool",
")",
"{",
"l",
",",
"ok",
":=",
"locales",
"[",
"locale",
"]",
"\n",
"return",
"l",
",",
"ok",
"\n",
"}"
] | // GetLocale returns a pointer to an existing locale object and a boolean whether the locale exists. | [
"GetLocale",
"returns",
"a",
"pointer",
"to",
"an",
"existing",
"locale",
"object",
"and",
"a",
"boolean",
"whether",
"the",
"locale",
"exists",
"."
] | 9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2 | https://github.com/theplant/cldr/blob/9f76f7ce4ee8058b01f92739cf0d0cceaeda3cb2/locale.go#L109-L112 |
16,763 | mitchellh/iochan | iochan.go | DelimReader | func DelimReader(r io.Reader, delim byte) <-chan string {
ch := make(chan string)
go func() {
buf := bufio.NewReader(r)
for {
line, err := buf.ReadString(delim)
if line != "" {
ch <- line
}
if err != nil {
break
}
}
close(ch)
}()
return ch
} | go | func DelimReader(r io.Reader, delim byte) <-chan string {
ch := make(chan string)
go func() {
buf := bufio.NewReader(r)
for {
line, err := buf.ReadString(delim)
if line != "" {
ch <- line
}
if err != nil {
break
}
}
close(ch)
}()
return ch
} | [
"func",
"DelimReader",
"(",
"r",
"io",
".",
"Reader",
",",
"delim",
"byte",
")",
"<-",
"chan",
"string",
"{",
"ch",
":=",
"make",
"(",
"chan",
"string",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"buf",
":=",
"bufio",
".",
"NewReader",
"(",
"r",
"... | // DelimReader takes an io.Reader and produces the contents of the reader
// on the returned channel. The contents on the channel will be returned
// on boundaries specified by the delim parameter, and will include this
// delimiter.
//
// If an error occurs while reading from the reader, the reading will end.
//
// In the case of an EOF or error, the channel will be closed.
//
// This must only be called once for any individual reader. The behavior is
// unknown and will be unexpected if this is called multiple times with the
// same reader. | [
"DelimReader",
"takes",
"an",
"io",
".",
"Reader",
"and",
"produces",
"the",
"contents",
"of",
"the",
"reader",
"on",
"the",
"returned",
"channel",
".",
"The",
"contents",
"on",
"the",
"channel",
"will",
"be",
"returned",
"on",
"boundaries",
"specified",
"by... | b6e3aadd28864e14dae41ff5c7261455b1242d24 | https://github.com/mitchellh/iochan/blob/b6e3aadd28864e14dae41ff5c7261455b1242d24/iochan.go#L20-L41 |
16,764 | mattetti/filebuffer | filebuffer.go | Bytes | func (f *Buffer) Bytes() []byte {
if f.isClosed || f.Index >= int64(f.Buff.Len()) {
return []byte{}
}
return f.Buff.Bytes()[f.Index:]
} | go | func (f *Buffer) Bytes() []byte {
if f.isClosed || f.Index >= int64(f.Buff.Len()) {
return []byte{}
}
return f.Buff.Bytes()[f.Index:]
} | [
"func",
"(",
"f",
"*",
"Buffer",
")",
"Bytes",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"f",
".",
"isClosed",
"||",
"f",
".",
"Index",
">=",
"int64",
"(",
"f",
".",
"Buff",
".",
"Len",
"(",
")",
")",
"{",
"return",
"[",
"]",
"byte",
"{",
"}",... | // Bytes returns the bytes available until the end of the buffer. | [
"Bytes",
"returns",
"the",
"bytes",
"available",
"until",
"the",
"end",
"of",
"the",
"buffer",
"."
] | 3a1e8e5a6548ea21cce597660d0c0dcc8c77a520 | https://github.com/mattetti/filebuffer/blob/3a1e8e5a6548ea21cce597660d0c0dcc8c77a520/filebuffer.go#L35-L40 |
16,765 | fgrosse/zaptest | logger.go | Write | func (o testOutput) Write(p []byte) (int, error) {
msg := strings.TrimSpace(string(p))
o.Log(msg)
return len(p), nil
} | go | func (o testOutput) Write(p []byte) (int, error) {
msg := strings.TrimSpace(string(p))
o.Log(msg)
return len(p), nil
} | [
"func",
"(",
"o",
"testOutput",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"msg",
":=",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"p",
")",
")",
"\n",
"o",
".",
"Log",
"(",
"msg",
")",
"\n",
"ret... | // Write logs all messages as logs via o. | [
"Write",
"logs",
"all",
"messages",
"as",
"logs",
"via",
"o",
"."
] | c15df62b6d517f1bc693998900e3e2cd28319b7f | https://github.com/fgrosse/zaptest/blob/c15df62b6d517f1bc693998900e3e2cd28319b7f/logger.go#L79-L83 |
16,766 | tucnak/store | store.go | Register | func Register(extension string, m MarshalFunc, um UnmarshalFunc) {
formats[extension] = format{m, um}
} | go | func Register(extension string, m MarshalFunc, um UnmarshalFunc) {
formats[extension] = format{m, um}
} | [
"func",
"Register",
"(",
"extension",
"string",
",",
"m",
"MarshalFunc",
",",
"um",
"UnmarshalFunc",
")",
"{",
"formats",
"[",
"extension",
"]",
"=",
"format",
"{",
"m",
",",
"um",
"}",
"\n",
"}"
] | // Register is the way you register configuration formats, by mapping some
// file name extension to corresponding marshal and unmarshal functions.
// Once registered, the format given would be compatible with Load and Save. | [
"Register",
"is",
"the",
"way",
"you",
"register",
"configuration",
"formats",
"by",
"mapping",
"some",
"file",
"name",
"extension",
"to",
"corresponding",
"marshal",
"and",
"unmarshal",
"functions",
".",
"Once",
"registered",
"the",
"format",
"given",
"would",
... | b02ecdcc6dfb2cbc3a16da35ec1499618f64e1b6 | https://github.com/tucnak/store/blob/b02ecdcc6dfb2cbc3a16da35ec1499618f64e1b6/store.go#L62-L64 |
16,767 | tucnak/store | store.go | LoadWith | func LoadWith(path string, v interface{}, um UnmarshalFunc) error {
if applicationName == "" {
panic("store: application name not defined")
}
globalPath := buildPlatformPath(path)
data, err := ioutil.ReadFile(globalPath)
if err != nil {
// There is a chance that file we are looking for
// just doesn't exist. In this case we are supposed
// to create an empty configuration file, based on v.
empty := reflect.New(reflect.TypeOf(v))
if innerErr := Save(path, &empty); innerErr != nil {
// Smth going on with the file system... returning error.
return err
}
v = empty
return nil
}
if err := um(data, v); err != nil {
return fmt.Errorf("store: failed to unmarshal %s: %v", path, err)
}
return nil
} | go | func LoadWith(path string, v interface{}, um UnmarshalFunc) error {
if applicationName == "" {
panic("store: application name not defined")
}
globalPath := buildPlatformPath(path)
data, err := ioutil.ReadFile(globalPath)
if err != nil {
// There is a chance that file we are looking for
// just doesn't exist. In this case we are supposed
// to create an empty configuration file, based on v.
empty := reflect.New(reflect.TypeOf(v))
if innerErr := Save(path, &empty); innerErr != nil {
// Smth going on with the file system... returning error.
return err
}
v = empty
return nil
}
if err := um(data, v); err != nil {
return fmt.Errorf("store: failed to unmarshal %s: %v", path, err)
}
return nil
} | [
"func",
"LoadWith",
"(",
"path",
"string",
",",
"v",
"interface",
"{",
"}",
",",
"um",
"UnmarshalFunc",
")",
"error",
"{",
"if",
"applicationName",
"==",
"\"",
"\"",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"globalPath",
":=",
"buildPlatf... | // LoadWith loads the configuration using any unmarshaler at all. | [
"LoadWith",
"loads",
"the",
"configuration",
"using",
"any",
"unmarshaler",
"at",
"all",
"."
] | b02ecdcc6dfb2cbc3a16da35ec1499618f64e1b6 | https://github.com/tucnak/store/blob/b02ecdcc6dfb2cbc3a16da35ec1499618f64e1b6/store.go#L109-L138 |
16,768 | tucnak/store | store.go | SaveWith | func SaveWith(path string, v interface{}, m MarshalFunc) error {
if applicationName == "" {
panic("store: application name not defined")
}
var b bytes.Buffer
if data, err := m(v); err == nil {
b.Write(data)
} else {
return fmt.Errorf("store: failed to marshal %s: %v", path, err)
}
b.WriteRune('\n')
globalPath := buildPlatformPath(path)
if err := os.MkdirAll(filepath.Dir(globalPath), os.ModePerm); err != nil {
return err
}
if err := ioutil.WriteFile(globalPath, b.Bytes(), os.ModePerm); err != nil {
return err
}
return nil
} | go | func SaveWith(path string, v interface{}, m MarshalFunc) error {
if applicationName == "" {
panic("store: application name not defined")
}
var b bytes.Buffer
if data, err := m(v); err == nil {
b.Write(data)
} else {
return fmt.Errorf("store: failed to marshal %s: %v", path, err)
}
b.WriteRune('\n')
globalPath := buildPlatformPath(path)
if err := os.MkdirAll(filepath.Dir(globalPath), os.ModePerm); err != nil {
return err
}
if err := ioutil.WriteFile(globalPath, b.Bytes(), os.ModePerm); err != nil {
return err
}
return nil
} | [
"func",
"SaveWith",
"(",
"path",
"string",
",",
"v",
"interface",
"{",
"}",
",",
"m",
"MarshalFunc",
")",
"error",
"{",
"if",
"applicationName",
"==",
"\"",
"\"",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"b",
"bytes",
".",
"Buf... | // SaveWith saves the configuration using any marshaler at all. | [
"SaveWith",
"saves",
"the",
"configuration",
"using",
"any",
"marshaler",
"at",
"all",
"."
] | b02ecdcc6dfb2cbc3a16da35ec1499618f64e1b6 | https://github.com/tucnak/store/blob/b02ecdcc6dfb2cbc3a16da35ec1499618f64e1b6/store.go#L141-L166 |
16,769 | tucnak/store | store.go | buildPlatformPath | func buildPlatformPath(path string) string {
if runtime.GOOS == "windows" {
return fmt.Sprintf("%s\\%s\\%s", os.Getenv("APPDATA"),
applicationName,
path)
}
var unixConfigDir string
if xdg := os.Getenv("XDG_CONFIG_HOME"); xdg != "" {
unixConfigDir = xdg
} else {
unixConfigDir = os.Getenv("HOME") + "/.config"
}
return fmt.Sprintf("%s/%s/%s", unixConfigDir,
applicationName,
path)
} | go | func buildPlatformPath(path string) string {
if runtime.GOOS == "windows" {
return fmt.Sprintf("%s\\%s\\%s", os.Getenv("APPDATA"),
applicationName,
path)
}
var unixConfigDir string
if xdg := os.Getenv("XDG_CONFIG_HOME"); xdg != "" {
unixConfigDir = xdg
} else {
unixConfigDir = os.Getenv("HOME") + "/.config"
}
return fmt.Sprintf("%s/%s/%s", unixConfigDir,
applicationName,
path)
} | [
"func",
"buildPlatformPath",
"(",
"path",
"string",
")",
"string",
"{",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\\",
"\\\\",
"\"",
",",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
",",
"app... | // buildPlatformPath builds a platform-dependent path for relative path given. | [
"buildPlatformPath",
"builds",
"a",
"platform",
"-",
"dependent",
"path",
"for",
"relative",
"path",
"given",
"."
] | b02ecdcc6dfb2cbc3a16da35ec1499618f64e1b6 | https://github.com/tucnak/store/blob/b02ecdcc6dfb2cbc3a16da35ec1499618f64e1b6/store.go#L179-L196 |
16,770 | creack/goselect | select.go | Select | func Select(n int, r, w, e *FDSet, timeout time.Duration) error {
var timeval *syscall.Timeval
if timeout >= 0 {
t := syscall.NsecToTimeval(timeout.Nanoseconds())
timeval = &t
}
return sysSelect(n, r, w, e, timeval)
} | go | func Select(n int, r, w, e *FDSet, timeout time.Duration) error {
var timeval *syscall.Timeval
if timeout >= 0 {
t := syscall.NsecToTimeval(timeout.Nanoseconds())
timeval = &t
}
return sysSelect(n, r, w, e, timeval)
} | [
"func",
"Select",
"(",
"n",
"int",
",",
"r",
",",
"w",
",",
"e",
"*",
"FDSet",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"var",
"timeval",
"*",
"syscall",
".",
"Timeval",
"\n",
"if",
"timeout",
">=",
"0",
"{",
"t",
":=",
"syscal... | // Select wraps syscall.Select with Go types | [
"Select",
"wraps",
"syscall",
".",
"Select",
"with",
"Go",
"types"
] | c98c4e62c41618cf78d3ff759af0d4dbaa677748 | https://github.com/creack/goselect/blob/c98c4e62c41618cf78d3ff759af0d4dbaa677748/select.go#L9-L17 |
16,771 | creack/goselect | select.go | RetrySelect | func RetrySelect(n int, r, w, e *FDSet, timeout time.Duration, retries int, retryDelay time.Duration) (err error) {
for i := 0; i < retries; i++ {
if err = Select(n, r, w, e, timeout); err != syscall.EINTR {
return err
}
time.Sleep(retryDelay)
}
return err
} | go | func RetrySelect(n int, r, w, e *FDSet, timeout time.Duration, retries int, retryDelay time.Duration) (err error) {
for i := 0; i < retries; i++ {
if err = Select(n, r, w, e, timeout); err != syscall.EINTR {
return err
}
time.Sleep(retryDelay)
}
return err
} | [
"func",
"RetrySelect",
"(",
"n",
"int",
",",
"r",
",",
"w",
",",
"e",
"*",
"FDSet",
",",
"timeout",
"time",
".",
"Duration",
",",
"retries",
"int",
",",
"retryDelay",
"time",
".",
"Duration",
")",
"(",
"err",
"error",
")",
"{",
"for",
"i",
":=",
... | // RetrySelect wraps syscall.Select with Go types, and retries a number of times, with a given retryDelay. | [
"RetrySelect",
"wraps",
"syscall",
".",
"Select",
"with",
"Go",
"types",
"and",
"retries",
"a",
"number",
"of",
"times",
"with",
"a",
"given",
"retryDelay",
"."
] | c98c4e62c41618cf78d3ff759af0d4dbaa677748 | https://github.com/creack/goselect/blob/c98c4e62c41618cf78d3ff759af0d4dbaa677748/select.go#L20-L28 |
16,772 | kris-nova/lolgopher | writer.go | writeRaw | func (w *Writer) writeRaw(s string) (int, error) {
c, err := w.getColorer()
if err != nil {
return -1, err
}
nWritten := 0
for _, r := range s {
c.rainbow(freq, float64(w.origin)+float64(w.lineIdx)/spread)
_, err := w.Output.Write(c.format())
if err != nil {
return nWritten, err
}
n, err := w.Output.Write([]byte(string(r)))
if err != nil {
return nWritten, err
}
_, err = w.Output.Write(c.reset())
if err != nil {
return nWritten, err
}
nWritten += n
w.lineIdx++
}
return nWritten, nil
} | go | func (w *Writer) writeRaw(s string) (int, error) {
c, err := w.getColorer()
if err != nil {
return -1, err
}
nWritten := 0
for _, r := range s {
c.rainbow(freq, float64(w.origin)+float64(w.lineIdx)/spread)
_, err := w.Output.Write(c.format())
if err != nil {
return nWritten, err
}
n, err := w.Output.Write([]byte(string(r)))
if err != nil {
return nWritten, err
}
_, err = w.Output.Write(c.reset())
if err != nil {
return nWritten, err
}
nWritten += n
w.lineIdx++
}
return nWritten, nil
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"writeRaw",
"(",
"s",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"w",
".",
"getColorer",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",... | // writeRaw will write a lol'd s to the underlying writer. It does no line
// detection. | [
"writeRaw",
"will",
"write",
"a",
"lol",
"d",
"s",
"to",
"the",
"underlying",
"writer",
".",
"It",
"does",
"no",
"line",
"detection",
"."
] | 313b3abb0d9bb53e3c43230132061a7a9cb100fc | https://github.com/kris-nova/lolgopher/blob/313b3abb0d9bb53e3c43230132061a7a9cb100fc/writer.go#L36-L60 |
16,773 | kris-nova/lolgopher | writer.go | Write | func (w *Writer) Write(p []byte) (int, error) {
nWritten := 0
ss := strings.Split(string(p), "\n")
for i, s := range ss {
// TODO: strip out pre-existing ANSI codes and expand tabs. Would be
// great to expand tabs in a context aware way (line linux expand
// command).
n, err := w.writeRaw(s)
if err != nil {
return nWritten, err
}
nWritten += n
// Increment the origin (line count) for each newline. There is a
// newline for every item in this array except the last one.
if i != len(ss)-1 {
n, err := w.Output.Write([]byte("\n"))
if err != nil {
return nWritten, err
}
nWritten += n
w.origin++
w.lineIdx = 0
}
}
return nWritten, nil
} | go | func (w *Writer) Write(p []byte) (int, error) {
nWritten := 0
ss := strings.Split(string(p), "\n")
for i, s := range ss {
// TODO: strip out pre-existing ANSI codes and expand tabs. Would be
// great to expand tabs in a context aware way (line linux expand
// command).
n, err := w.writeRaw(s)
if err != nil {
return nWritten, err
}
nWritten += n
// Increment the origin (line count) for each newline. There is a
// newline for every item in this array except the last one.
if i != len(ss)-1 {
n, err := w.Output.Write([]byte("\n"))
if err != nil {
return nWritten, err
}
nWritten += n
w.origin++
w.lineIdx = 0
}
}
return nWritten, nil
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"nWritten",
":=",
"0",
"\n",
"ss",
":=",
"strings",
".",
"Split",
"(",
"string",
"(",
"p",
")",
",",
"\"",
"\\n",
"\"",
")",
... | // Write will write a byte slice to the Writer | [
"Write",
"will",
"write",
"a",
"byte",
"slice",
"to",
"the",
"Writer"
] | 313b3abb0d9bb53e3c43230132061a7a9cb100fc | https://github.com/kris-nova/lolgopher/blob/313b3abb0d9bb53e3c43230132061a7a9cb100fc/writer.go#L77-L104 |
16,774 | kris-nova/lolgopher | writer.go | NewLolWriter | func NewLolWriter() io.Writer {
colorMode := ColorMode256
if noColor {
colorMode = ColorMode0
}
return &Writer{
Output: stdout,
ColorMode: colorMode,
}
} | go | func NewLolWriter() io.Writer {
colorMode := ColorMode256
if noColor {
colorMode = ColorMode0
}
return &Writer{
Output: stdout,
ColorMode: colorMode,
}
} | [
"func",
"NewLolWriter",
"(",
")",
"io",
".",
"Writer",
"{",
"colorMode",
":=",
"ColorMode256",
"\n",
"if",
"noColor",
"{",
"colorMode",
"=",
"ColorMode0",
"\n",
"}",
"\n",
"return",
"&",
"Writer",
"{",
"Output",
":",
"stdout",
",",
"ColorMode",
":",
"col... | // NewLolWriter will return a new io.Writer with a default ColorMode of 256 | [
"NewLolWriter",
"will",
"return",
"a",
"new",
"io",
".",
"Writer",
"with",
"a",
"default",
"ColorMode",
"of",
"256"
] | 313b3abb0d9bb53e3c43230132061a7a9cb100fc | https://github.com/kris-nova/lolgopher/blob/313b3abb0d9bb53e3c43230132061a7a9cb100fc/writer.go#L107-L116 |
16,775 | kris-nova/lolgopher | writer.go | NewTruecolorLolWriter | func NewTruecolorLolWriter() io.Writer {
colorMode := ColorModeTrueColor
if noColor {
colorMode = ColorMode0
}
return &Writer{
Output: stdout,
ColorMode: colorMode,
}
} | go | func NewTruecolorLolWriter() io.Writer {
colorMode := ColorModeTrueColor
if noColor {
colorMode = ColorMode0
}
return &Writer{
Output: stdout,
ColorMode: colorMode,
}
} | [
"func",
"NewTruecolorLolWriter",
"(",
")",
"io",
".",
"Writer",
"{",
"colorMode",
":=",
"ColorModeTrueColor",
"\n",
"if",
"noColor",
"{",
"colorMode",
"=",
"ColorMode0",
"\n",
"}",
"\n",
"return",
"&",
"Writer",
"{",
"Output",
":",
"stdout",
",",
"ColorMode"... | // NewTruecolorLolWriter will return a new io.Writer with a default ColorMode of truecolor | [
"NewTruecolorLolWriter",
"will",
"return",
"a",
"new",
"io",
".",
"Writer",
"with",
"a",
"default",
"ColorMode",
"of",
"truecolor"
] | 313b3abb0d9bb53e3c43230132061a7a9cb100fc | https://github.com/kris-nova/lolgopher/blob/313b3abb0d9bb53e3c43230132061a7a9cb100fc/writer.go#L119-L128 |
16,776 | kelseyhightower/memkv | store.go | New | func New() Store {
s := Store{m: make(map[string]KVPair)}
s.FuncMap = map[string]interface{}{
"exists": s.Exists,
"ls": s.List,
"lsdir": s.ListDir,
"get": s.Get,
"gets": s.GetAll,
"getv": s.GetValue,
"getvs": s.GetAllValues,
}
return s
} | go | func New() Store {
s := Store{m: make(map[string]KVPair)}
s.FuncMap = map[string]interface{}{
"exists": s.Exists,
"ls": s.List,
"lsdir": s.ListDir,
"get": s.Get,
"gets": s.GetAll,
"getv": s.GetValue,
"getvs": s.GetAllValues,
}
return s
} | [
"func",
"New",
"(",
")",
"Store",
"{",
"s",
":=",
"Store",
"{",
"m",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"KVPair",
")",
"}",
"\n",
"s",
".",
"FuncMap",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"s",... | // New creates and initializes a new Store. | [
"New",
"creates",
"and",
"initializes",
"a",
"new",
"Store",
"."
] | 892bfd468afa0fa476556e7bd7734a087cda08b3 | https://github.com/kelseyhightower/memkv/blob/892bfd468afa0fa476556e7bd7734a087cda08b3/store.go#L37-L49 |
16,777 | kelseyhightower/memkv | store.go | Del | func (s Store) Del(key string) {
s.Lock()
delete(s.m, key)
s.Unlock()
} | go | func (s Store) Del(key string) {
s.Lock()
delete(s.m, key)
s.Unlock()
} | [
"func",
"(",
"s",
"Store",
")",
"Del",
"(",
"key",
"string",
")",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"s",
".",
"m",
",",
"key",
")",
"\n",
"s",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // Delete deletes the KVPair associated with key. | [
"Delete",
"deletes",
"the",
"KVPair",
"associated",
"with",
"key",
"."
] | 892bfd468afa0fa476556e7bd7734a087cda08b3 | https://github.com/kelseyhightower/memkv/blob/892bfd468afa0fa476556e7bd7734a087cda08b3/store.go#L52-L56 |
16,778 | kelseyhightower/memkv | store.go | Exists | func (s Store) Exists(key string) bool {
_, err := s.Get(key)
if err != nil {
return false
}
return true
} | go | func (s Store) Exists(key string) bool {
_, err := s.Get(key)
if err != nil {
return false
}
return true
} | [
"func",
"(",
"s",
"Store",
")",
"Exists",
"(",
"key",
"string",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"s",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Exists checks for the existence of key in the store. | [
"Exists",
"checks",
"for",
"the",
"existence",
"of",
"key",
"in",
"the",
"store",
"."
] | 892bfd468afa0fa476556e7bd7734a087cda08b3 | https://github.com/kelseyhightower/memkv/blob/892bfd468afa0fa476556e7bd7734a087cda08b3/store.go#L59-L65 |
16,779 | kelseyhightower/memkv | store.go | GetValue | func (s Store) GetValue(key string, v ...string) (string, error) {
kv, err := s.Get(key)
if err != nil {
if len(v) > 0 {
// Take default
return v[0], nil
}
return "", err
}
return kv.Value, nil
} | go | func (s Store) GetValue(key string, v ...string) (string, error) {
kv, err := s.Get(key)
if err != nil {
if len(v) > 0 {
// Take default
return v[0], nil
}
return "", err
}
return kv.Value, nil
} | [
"func",
"(",
"s",
"Store",
")",
"GetValue",
"(",
"key",
"string",
",",
"v",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"kv",
",",
"err",
":=",
"s",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len... | // GetValue gets the value associated with key. If there are no values
// associated with key, GetValue returns "", ErrNotExist. | [
"GetValue",
"gets",
"the",
"value",
"associated",
"with",
"key",
".",
"If",
"there",
"are",
"no",
"values",
"associated",
"with",
"key",
"GetValue",
"returns",
"ErrNotExist",
"."
] | 892bfd468afa0fa476556e7bd7734a087cda08b3 | https://github.com/kelseyhightower/memkv/blob/892bfd468afa0fa476556e7bd7734a087cda08b3/store.go#L81-L91 |
16,780 | kelseyhightower/memkv | store.go | GetAll | func (s Store) GetAll(pattern string) (KVPairs, error) {
ks := make(KVPairs, 0)
s.RLock()
defer s.RUnlock()
for _, kv := range s.m {
m, err := path.Match(pattern, kv.Key)
if err != nil {
return nil, err
}
if m {
ks = append(ks, kv)
}
}
if len(ks) == 0 {
return ks, nil
}
sort.Sort(ks)
return ks, nil
} | go | func (s Store) GetAll(pattern string) (KVPairs, error) {
ks := make(KVPairs, 0)
s.RLock()
defer s.RUnlock()
for _, kv := range s.m {
m, err := path.Match(pattern, kv.Key)
if err != nil {
return nil, err
}
if m {
ks = append(ks, kv)
}
}
if len(ks) == 0 {
return ks, nil
}
sort.Sort(ks)
return ks, nil
} | [
"func",
"(",
"s",
"Store",
")",
"GetAll",
"(",
"pattern",
"string",
")",
"(",
"KVPairs",
",",
"error",
")",
"{",
"ks",
":=",
"make",
"(",
"KVPairs",
",",
"0",
")",
"\n",
"s",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"RUnlock",
"(",
")",... | // GetAll returns a KVPair for all nodes with keys matching pattern.
// The syntax of patterns is the same as in path.Match. | [
"GetAll",
"returns",
"a",
"KVPair",
"for",
"all",
"nodes",
"with",
"keys",
"matching",
"pattern",
".",
"The",
"syntax",
"of",
"patterns",
"is",
"the",
"same",
"as",
"in",
"path",
".",
"Match",
"."
] | 892bfd468afa0fa476556e7bd7734a087cda08b3 | https://github.com/kelseyhightower/memkv/blob/892bfd468afa0fa476556e7bd7734a087cda08b3/store.go#L95-L113 |
16,781 | kelseyhightower/memkv | store.go | Set | func (s Store) Set(key string, value string) {
s.Lock()
s.m[key] = KVPair{key, value}
s.Unlock()
} | go | func (s Store) Set(key string, value string) {
s.Lock()
s.m[key] = KVPair{key, value}
s.Unlock()
} | [
"func",
"(",
"s",
"Store",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"string",
")",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"m",
"[",
"key",
"]",
"=",
"KVPair",
"{",
"key",
",",
"value",
"}",
"\n",
"s",
".",
"Unlock",
"(",
")... | // Set sets the KVPair entry associated with key to value. | [
"Set",
"sets",
"the",
"KVPair",
"entry",
"associated",
"with",
"key",
"to",
"value",
"."
] | 892bfd468afa0fa476556e7bd7734a087cda08b3 | https://github.com/kelseyhightower/memkv/blob/892bfd468afa0fa476556e7bd7734a087cda08b3/store.go#L176-L180 |
16,782 | appscode/go-hetzner | client.go | NewRequest | func (c *Client) NewRequest(method, path string, request interface{}) (*http.Request, error) {
var u *url.URL
var err error
if c.BaseURL != "" {
u, err = url.Parse(c.BaseURL)
if err != nil {
return nil, err
}
}
qv, err := query.Values(request)
if err != nil {
return nil, err
}
qs := encode(qv)
if qs != "" && method == http.MethodGet || method == http.MethodDelete {
if strings.Contains(path, "?") {
path += "&" + qs
} else {
path += "?" + qs
}
}
if path != "" {
rel, err := url.Parse(path)
if err != nil {
return nil, err
}
if u != nil {
u = u.ResolveReference(rel)
} else {
u = rel
}
}
if u == nil {
return nil, errors.New("No URL is provided.")
}
req, err := http.NewRequest(method, u.String(), bytes.NewBufferString(qs))
if err != nil {
return nil, err
}
req.Header.Add("Accept", "application/json")
req.Header.Add("User-Agent", c.UserAgent)
for k, v := range c.headers {
req.Header.Add(k, v)
}
if method == http.MethodPost || method == http.MethodPut {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Content-Length", strconv.Itoa(len(qs)))
}
if c.Debug {
dump, err := httputil.DumpRequestOut(req, true)
if err == nil {
fmt.Println(string(dump))
}
}
return req, nil
} | go | func (c *Client) NewRequest(method, path string, request interface{}) (*http.Request, error) {
var u *url.URL
var err error
if c.BaseURL != "" {
u, err = url.Parse(c.BaseURL)
if err != nil {
return nil, err
}
}
qv, err := query.Values(request)
if err != nil {
return nil, err
}
qs := encode(qv)
if qs != "" && method == http.MethodGet || method == http.MethodDelete {
if strings.Contains(path, "?") {
path += "&" + qs
} else {
path += "?" + qs
}
}
if path != "" {
rel, err := url.Parse(path)
if err != nil {
return nil, err
}
if u != nil {
u = u.ResolveReference(rel)
} else {
u = rel
}
}
if u == nil {
return nil, errors.New("No URL is provided.")
}
req, err := http.NewRequest(method, u.String(), bytes.NewBufferString(qs))
if err != nil {
return nil, err
}
req.Header.Add("Accept", "application/json")
req.Header.Add("User-Agent", c.UserAgent)
for k, v := range c.headers {
req.Header.Add(k, v)
}
if method == http.MethodPost || method == http.MethodPut {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Content-Length", strconv.Itoa(len(qs)))
}
if c.Debug {
dump, err := httputil.DumpRequestOut(req, true)
if err == nil {
fmt.Println(string(dump))
}
}
return req, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"NewRequest",
"(",
"method",
",",
"path",
"string",
",",
"request",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"var",
"u",
"*",
"url",
".",
"URL",
"\n",
"var",
"err"... | // NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL
// of the Client. If specified, the value pointed to by request is www-form-urlencoded and included in as the request body. | [
"NewRequest",
"creates",
"an",
"API",
"request",
".",
"A",
"relative",
"URL",
"can",
"be",
"provided",
"in",
"urlStr",
"which",
"will",
"be",
"resolved",
"to",
"the",
"BaseURL",
"of",
"the",
"Client",
".",
"If",
"specified",
"the",
"value",
"pointed",
"to"... | c038e08b19b1c760484d443de8958880e35bd879 | https://github.com/appscode/go-hetzner/blob/c038e08b19b1c760484d443de8958880e35bd879/client.go#L96-L155 |
16,783 | appscode/go-hetzner | client.go | checkResponse | func checkResponse(r *http.Response) error {
if c := r.StatusCode; c >= 200 && c <= 299 {
return nil
}
apiErr := &APIError{Response: r}
data, err := ioutil.ReadAll(r.Body)
if err == nil && len(data) > 0 {
type E struct {
Error *APIError `json:"error"`
}
e := E{}
if err = json.Unmarshal(data, &e); err == nil {
e.Error.Response = r
apiErr = e.Error
}
}
return apiErr
} | go | func checkResponse(r *http.Response) error {
if c := r.StatusCode; c >= 200 && c <= 299 {
return nil
}
apiErr := &APIError{Response: r}
data, err := ioutil.ReadAll(r.Body)
if err == nil && len(data) > 0 {
type E struct {
Error *APIError `json:"error"`
}
e := E{}
if err = json.Unmarshal(data, &e); err == nil {
e.Error.Response = r
apiErr = e.Error
}
}
return apiErr
} | [
"func",
"checkResponse",
"(",
"r",
"*",
"http",
".",
"Response",
")",
"error",
"{",
"if",
"c",
":=",
"r",
".",
"StatusCode",
";",
"c",
">=",
"200",
"&&",
"c",
"<=",
"299",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"apiErr",
":=",
"&",
"APIError",
... | // CheckResponse checks the API response for errors, and returns them if present. A response is considered an
// error if it has a status code outside the 200 range. API error responses are expected to have either no response
// body, or a JSON response body that maps to APIError. | [
"CheckResponse",
"checks",
"the",
"API",
"response",
"for",
"errors",
"and",
"returns",
"them",
"if",
"present",
".",
"A",
"response",
"is",
"considered",
"an",
"error",
"if",
"it",
"has",
"a",
"status",
"code",
"outside",
"the",
"200",
"range",
".",
"API"... | c038e08b19b1c760484d443de8958880e35bd879 | https://github.com/appscode/go-hetzner/blob/c038e08b19b1c760484d443de8958880e35bd879/client.go#L231-L249 |
16,784 | beego/mux | params.go | Params | func Params(r *http.Request) map[string]string {
v := r.Context().Value(routeParamsID)
if v == nil {
return map[string]string{}
}
if v, ok := v.(map[string]string); ok {
return v
}
return map[string]string{}
} | go | func Params(r *http.Request) map[string]string {
v := r.Context().Value(routeParamsID)
if v == nil {
return map[string]string{}
}
if v, ok := v.(map[string]string); ok {
return v
}
return map[string]string{}
} | [
"func",
"Params",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"v",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"routeParamsID",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"map",
"[",
... | // Params return the router params | [
"Params",
"return",
"the",
"router",
"params"
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/params.go#L15-L24 |
16,785 | beego/mux | params.go | Param | func Param(r *http.Request, key string) string {
p := Params(r)
if v, ok := p[key]; ok {
return v
}
return ""
} | go | func Param(r *http.Request, key string) string {
p := Params(r)
if v, ok := p[key]; ok {
return v
}
return ""
} | [
"func",
"Param",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"key",
"string",
")",
"string",
"{",
"p",
":=",
"Params",
"(",
"r",
")",
"\n",
"if",
"v",
",",
"ok",
":=",
"p",
"[",
"key",
"]",
";",
"ok",
"{",
"return",
"v",
"\n",
"}",
"\n",
"r... | // Param return the router param based on the key | [
"Param",
"return",
"the",
"router",
"param",
"based",
"on",
"the",
"key"
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/params.go#L27-L33 |
16,786 | beego/mux | mux.go | Get | func (m *Mux) Get(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodGet, pattern, handler)
} | go | func (m *Mux) Get(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodGet, pattern, handler)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Get",
"(",
"pattern",
"string",
",",
"handler",
"http",
".",
"HandlerFunc",
")",
"{",
"m",
".",
"Handle",
"(",
"http",
".",
"MethodGet",
",",
"pattern",
",",
"handler",
")",
"\n",
"}"
] | // Get registers a new GET route for a path with matching handler in the Mux. | [
"Get",
"registers",
"a",
"new",
"GET",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"Mux",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L23-L25 |
16,787 | beego/mux | mux.go | Head | func (m *Mux) Head(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodHead, pattern, handler)
} | go | func (m *Mux) Head(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodHead, pattern, handler)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Head",
"(",
"pattern",
"string",
",",
"handler",
"http",
".",
"HandlerFunc",
")",
"{",
"m",
".",
"Handle",
"(",
"http",
".",
"MethodHead",
",",
"pattern",
",",
"handler",
")",
"\n",
"}"
] | // Head registers a new HEAD route for a path with matching handler in the Mux. | [
"Head",
"registers",
"a",
"new",
"HEAD",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"Mux",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L28-L30 |
16,788 | beego/mux | mux.go | Post | func (m *Mux) Post(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodPost, pattern, handler)
} | go | func (m *Mux) Post(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodPost, pattern, handler)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Post",
"(",
"pattern",
"string",
",",
"handler",
"http",
".",
"HandlerFunc",
")",
"{",
"m",
".",
"Handle",
"(",
"http",
".",
"MethodPost",
",",
"pattern",
",",
"handler",
")",
"\n",
"}"
] | // Post registers a new POST route for a path with matching handler in the Mux. | [
"Post",
"registers",
"a",
"new",
"POST",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"Mux",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L33-L35 |
16,789 | beego/mux | mux.go | Put | func (m *Mux) Put(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodPut, pattern, handler)
} | go | func (m *Mux) Put(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodPut, pattern, handler)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Put",
"(",
"pattern",
"string",
",",
"handler",
"http",
".",
"HandlerFunc",
")",
"{",
"m",
".",
"Handle",
"(",
"http",
".",
"MethodPut",
",",
"pattern",
",",
"handler",
")",
"\n",
"}"
] | // Put registers a new PUT route for a path with matching handler in the Mux. | [
"Put",
"registers",
"a",
"new",
"PUT",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"Mux",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L38-L40 |
16,790 | beego/mux | mux.go | Patch | func (m *Mux) Patch(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodPatch, pattern, handler)
} | go | func (m *Mux) Patch(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodPatch, pattern, handler)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Patch",
"(",
"pattern",
"string",
",",
"handler",
"http",
".",
"HandlerFunc",
")",
"{",
"m",
".",
"Handle",
"(",
"http",
".",
"MethodPatch",
",",
"pattern",
",",
"handler",
")",
"\n",
"}"
] | // Patch registers a new PATCH route for a path with matching handler in the Mux. | [
"Patch",
"registers",
"a",
"new",
"PATCH",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"Mux",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L43-L45 |
16,791 | beego/mux | mux.go | Delete | func (m *Mux) Delete(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodDelete, pattern, handler)
} | go | func (m *Mux) Delete(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodDelete, pattern, handler)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Delete",
"(",
"pattern",
"string",
",",
"handler",
"http",
".",
"HandlerFunc",
")",
"{",
"m",
".",
"Handle",
"(",
"http",
".",
"MethodDelete",
",",
"pattern",
",",
"handler",
")",
"\n",
"}"
] | // Delete registers a new DELETE route for a path with matching handler in the Mux. | [
"Delete",
"registers",
"a",
"new",
"DELETE",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"Mux",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L48-L50 |
16,792 | beego/mux | mux.go | Options | func (m *Mux) Options(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodOptions, pattern, handler)
} | go | func (m *Mux) Options(pattern string, handler http.HandlerFunc) {
m.Handle(http.MethodOptions, pattern, handler)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Options",
"(",
"pattern",
"string",
",",
"handler",
"http",
".",
"HandlerFunc",
")",
"{",
"m",
".",
"Handle",
"(",
"http",
".",
"MethodOptions",
",",
"pattern",
",",
"handler",
")",
"\n",
"}"
] | // Options registers a new OPTIONS route for a path with matching handler in the Mux. | [
"Options",
"registers",
"a",
"new",
"OPTIONS",
"route",
"for",
"a",
"path",
"with",
"matching",
"handler",
"in",
"the",
"Mux",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L53-L55 |
16,793 | beego/mux | mux.go | Handle | func (m *Mux) Handle(method, pattern string, handler http.HandlerFunc) {
if method == "" {
panic(fmt.Errorf("invalid method"))
}
m.trie.Parse(pattern).Handle(strings.ToUpper(method), handler)
} | go | func (m *Mux) Handle(method, pattern string, handler http.HandlerFunc) {
if method == "" {
panic(fmt.Errorf("invalid method"))
}
m.trie.Parse(pattern).Handle(strings.ToUpper(method), handler)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Handle",
"(",
"method",
",",
"pattern",
"string",
",",
"handler",
"http",
".",
"HandlerFunc",
")",
"{",
"if",
"method",
"==",
"\"",
"\"",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
")",
"\n"... | // Handle registers a new handler with method and path in the Mux.
// For GET, POST, PUT, PATCH and DELETE requests the respective shortcut
// functions can be used. | [
"Handle",
"registers",
"a",
"new",
"handler",
"with",
"method",
"and",
"path",
"in",
"the",
"Mux",
".",
"For",
"GET",
"POST",
"PUT",
"PATCH",
"and",
"DELETE",
"requests",
"the",
"respective",
"shortcut",
"functions",
"can",
"be",
"used",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L66-L71 |
16,794 | beego/mux | mux.go | Handler | func (m *Mux) Handler(method, path string, handler http.Handler) {
m.Handle(method, path, func(w http.ResponseWriter, req *http.Request) {
handler.ServeHTTP(w, req)
})
} | go | func (m *Mux) Handler(method, path string, handler http.Handler) {
m.Handle(method, path, func(w http.ResponseWriter, req *http.Request) {
handler.ServeHTTP(w, req)
})
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"Handler",
"(",
"method",
",",
"path",
"string",
",",
"handler",
"http",
".",
"Handler",
")",
"{",
"m",
".",
"Handle",
"(",
"method",
",",
"path",
",",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
... | // Handler is an adapter which allows the usage of an http.Handler as a
// request handle. | [
"Handler",
"is",
"an",
"adapter",
"which",
"allows",
"the",
"usage",
"of",
"an",
"http",
".",
"Handler",
"as",
"a",
"request",
"handle",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L75-L79 |
16,795 | beego/mux | mux.go | ServeHTTP | func (m *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var handler http.HandlerFunc
path := req.URL.Path
method := req.Method
match, err := m.trie.Match(path)
if err != nil {
http.Error(w, fmt.Sprintf(`"Access %s: %s"`, path, err), http.StatusNotImplemented)
return
}
if match.Node == nil {
// Redirect for slash url
// Router /a/b Access PATH /a/b/ Redirect to /a/b
// Router /a/b/ Access PATH /a/b Redirect to /a/b/
if match.Path != "" {
req.URL.Path = match.Path
code := http.StatusMovedPermanently
if method != "GET" {
code = http.StatusTemporaryRedirect
}
http.Redirect(w, req, req.URL.String(), code)
return
}
if m.defaultHandler == nil {
http.Error(w, fmt.Sprintf(`"%s" not implemented`, path), http.StatusNotFound)
return
}
handler = m.defaultHandler
} else {
var ok bool
if handler, ok = match.Node.GetHandler(method).(http.HandlerFunc); !ok {
// OPTIONS preflight
if method == http.MethodOptions {
w.Header().Set("Access-Control-Allow-Methods", strings.Join(match.Node.GetAllow(), ", "))
w.WriteHeader(http.StatusNoContent)
return
}
if m.defaultHandler == nil {
w.Header().Set("Access-Control-Allow-Methods", strings.Join(match.Node.GetAllow(), ", "))
http.Error(w, fmt.Sprintf(`"%s" not allowed in "%s"`, method, path), 405)
return
}
handler = m.defaultHandler
}
}
if match.Params != nil {
ctx := context.WithValue(req.Context(), routeParamsID, match.Params)
req = req.WithContext(ctx)
}
handler(w, req)
} | go | func (m *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var handler http.HandlerFunc
path := req.URL.Path
method := req.Method
match, err := m.trie.Match(path)
if err != nil {
http.Error(w, fmt.Sprintf(`"Access %s: %s"`, path, err), http.StatusNotImplemented)
return
}
if match.Node == nil {
// Redirect for slash url
// Router /a/b Access PATH /a/b/ Redirect to /a/b
// Router /a/b/ Access PATH /a/b Redirect to /a/b/
if match.Path != "" {
req.URL.Path = match.Path
code := http.StatusMovedPermanently
if method != "GET" {
code = http.StatusTemporaryRedirect
}
http.Redirect(w, req, req.URL.String(), code)
return
}
if m.defaultHandler == nil {
http.Error(w, fmt.Sprintf(`"%s" not implemented`, path), http.StatusNotFound)
return
}
handler = m.defaultHandler
} else {
var ok bool
if handler, ok = match.Node.GetHandler(method).(http.HandlerFunc); !ok {
// OPTIONS preflight
if method == http.MethodOptions {
w.Header().Set("Access-Control-Allow-Methods", strings.Join(match.Node.GetAllow(), ", "))
w.WriteHeader(http.StatusNoContent)
return
}
if m.defaultHandler == nil {
w.Header().Set("Access-Control-Allow-Methods", strings.Join(match.Node.GetAllow(), ", "))
http.Error(w, fmt.Sprintf(`"%s" not allowed in "%s"`, method, path), 405)
return
}
handler = m.defaultHandler
}
}
if match.Params != nil {
ctx := context.WithValue(req.Context(), routeParamsID, match.Params)
req = req.WithContext(ctx)
}
handler(w, req)
} | [
"func",
"(",
"m",
"*",
"Mux",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"handler",
"http",
".",
"HandlerFunc",
"\n",
"path",
":=",
"req",
".",
"URL",
".",
"Path",
"\n",
"met... | // ServeHTTP implemented http.Handler interface | [
"ServeHTTP",
"implemented",
"http",
".",
"Handler",
"interface"
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/mux.go#L82-L132 |
16,796 | beego/mux | tree.go | getChild | func (n *Node) getChild(key string) *Node {
if strings.Contains(key, "::") {
key = strings.Replace(key, "::", ":", -1)
}
if v, ok := n.children[key]; ok {
return v
}
for _, c := range n.segChildren {
if c.segment == key {
return c
}
}
for _, c := range n.optionChildren {
if c.segment == key {
return c
}
}
for _, c := range n.varyChildren {
if c.segment == key {
return c
}
}
return nil
} | go | func (n *Node) getChild(key string) *Node {
if strings.Contains(key, "::") {
key = strings.Replace(key, "::", ":", -1)
}
if v, ok := n.children[key]; ok {
return v
}
for _, c := range n.segChildren {
if c.segment == key {
return c
}
}
for _, c := range n.optionChildren {
if c.segment == key {
return c
}
}
for _, c := range n.varyChildren {
if c.segment == key {
return c
}
}
return nil
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"getChild",
"(",
"key",
"string",
")",
"*",
"Node",
"{",
"if",
"strings",
".",
"Contains",
"(",
"key",
",",
"\"",
"\"",
")",
"{",
"key",
"=",
"strings",
".",
"Replace",
"(",
"key",
",",
"\"",
"\"",
",",
"\"",... | // getChild return the static key | [
"getChild",
"return",
"the",
"static",
"key"
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L279-L302 |
16,797 | beego/mux | tree.go | Name | func (n *Node) Name(name string) *Node {
if n.getRootNode().namedRoutes == nil {
n.getRootNode().namedRoutes = map[string]*Node{name: n}
} else {
if _, ok := n.getRootNode().namedRoutes[name]; ok {
panic(fmt.Errorf("mux: route already has name %q, can't set", name))
}
n.getRootNode().namedRoutes[name] = n
}
return n
} | go | func (n *Node) Name(name string) *Node {
if n.getRootNode().namedRoutes == nil {
n.getRootNode().namedRoutes = map[string]*Node{name: n}
} else {
if _, ok := n.getRootNode().namedRoutes[name]; ok {
panic(fmt.Errorf("mux: route already has name %q, can't set", name))
}
n.getRootNode().namedRoutes[name] = n
}
return n
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"Name",
"(",
"name",
"string",
")",
"*",
"Node",
"{",
"if",
"n",
".",
"getRootNode",
"(",
")",
".",
"namedRoutes",
"==",
"nil",
"{",
"n",
".",
"getRootNode",
"(",
")",
".",
"namedRoutes",
"=",
"map",
"[",
"stri... | // Name sets the name for the route, used to build URLs. | [
"Name",
"sets",
"the",
"name",
"for",
"the",
"route",
"used",
"to",
"build",
"URLs",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L305-L315 |
16,798 | beego/mux | tree.go | GetName | func (n *Node) GetName(name string) *Node {
if n.getRootNode().namedRoutes != nil {
return n.getRootNode().namedRoutes[name]
}
return nil
} | go | func (n *Node) GetName(name string) *Node {
if n.getRootNode().namedRoutes != nil {
return n.getRootNode().namedRoutes[name]
}
return nil
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"GetName",
"(",
"name",
"string",
")",
"*",
"Node",
"{",
"if",
"n",
".",
"getRootNode",
"(",
")",
".",
"namedRoutes",
"!=",
"nil",
"{",
"return",
"n",
".",
"getRootNode",
"(",
")",
".",
"namedRoutes",
"[",
"name"... | // GetName returns the name for the route, if any. | [
"GetName",
"returns",
"the",
"name",
"for",
"the",
"route",
"if",
"any",
"."
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L318-L323 |
16,799 | beego/mux | tree.go | getRootNode | func (n *Node) getRootNode() *Node {
if n.parent == nil {
return n
}
return n.parent.getRootNode()
} | go | func (n *Node) getRootNode() *Node {
if n.parent == nil {
return n
}
return n.parent.getRootNode()
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"getRootNode",
"(",
")",
"*",
"Node",
"{",
"if",
"n",
".",
"parent",
"==",
"nil",
"{",
"return",
"n",
"\n",
"}",
"\n",
"return",
"n",
".",
"parent",
".",
"getRootNode",
"(",
")",
"\n",
"}"
] | // getRootNode will return the Node whose parent is nil | [
"getRootNode",
"will",
"return",
"the",
"Node",
"whose",
"parent",
"is",
"nil"
] | 6660b4b5accbb383fac89498e57d3250d5e907ac | https://github.com/beego/mux/blob/6660b4b5accbb383fac89498e57d3250d5e907ac/tree.go#L326-L331 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.