id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
14,200 |
kidoman/embd
|
leddriver.go
|
NewLEDDriver
|
func NewLEDDriver(ledMap LEDMap, lf ledFactory) LEDDriver {
return &ledDriver{
ledMap: ledMap,
lf: lf,
initializedLEDs: map[string]LED{},
}
}
|
go
|
func NewLEDDriver(ledMap LEDMap, lf ledFactory) LEDDriver {
return &ledDriver{
ledMap: ledMap,
lf: lf,
initializedLEDs: map[string]LED{},
}
}
|
[
"func",
"NewLEDDriver",
"(",
"ledMap",
"LEDMap",
",",
"lf",
"ledFactory",
")",
"LEDDriver",
"{",
"return",
"&",
"ledDriver",
"{",
"ledMap",
":",
"ledMap",
",",
"lf",
":",
"lf",
",",
"initializedLEDs",
":",
"map",
"[",
"string",
"]",
"LED",
"{",
"}",
",",
"}",
"\n",
"}"
] |
// NewLEDDriver returns a LEDDriver interface which allows control
// over the LED subsystem.
|
[
"NewLEDDriver",
"returns",
"a",
"LEDDriver",
"interface",
"which",
"allows",
"control",
"over",
"the",
"LED",
"subsystem",
"."
] |
d3d8c0c5c68dc6caccebb7d720f36e64bafd0a62
|
https://github.com/kidoman/embd/blob/d3d8c0c5c68dc6caccebb7d720f36e64bafd0a62/leddriver.go#L26-L33
|
14,201 |
campoy/embedmd
|
embedmd/command.go
|
nextSlash
|
func nextSlash(s string) int {
for sep := 0; ; sep++ {
i := strings.IndexByte(s[sep:], '/')
if i < 0 {
return -1
}
sep += i
if sep == 0 || s[sep-1] != '\\' {
return sep
}
}
}
|
go
|
func nextSlash(s string) int {
for sep := 0; ; sep++ {
i := strings.IndexByte(s[sep:], '/')
if i < 0 {
return -1
}
sep += i
if sep == 0 || s[sep-1] != '\\' {
return sep
}
}
}
|
[
"func",
"nextSlash",
"(",
"s",
"string",
")",
"int",
"{",
"for",
"sep",
":=",
"0",
";",
";",
"sep",
"++",
"{",
"i",
":=",
"strings",
".",
"IndexByte",
"(",
"s",
"[",
"sep",
":",
"]",
",",
"'/'",
")",
"\n",
"if",
"i",
"<",
"0",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"sep",
"+=",
"i",
"\n",
"if",
"sep",
"==",
"0",
"||",
"s",
"[",
"sep",
"-",
"1",
"]",
"!=",
"'\\\\'",
"{",
"return",
"sep",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// nextSlash will find the index of the next unescaped slash in a string.
|
[
"nextSlash",
"will",
"find",
"the",
"index",
"of",
"the",
"next",
"unescaped",
"slash",
"in",
"a",
"string",
"."
] |
97c13d6e41602fc6e397eb51c45f38069371a969
|
https://github.com/campoy/embedmd/blob/97c13d6e41602fc6e397eb51c45f38069371a969/embedmd/command.go#L90-L101
|
14,202 |
campoy/embedmd
|
embedmd/embedmd.go
|
Process
|
func Process(out io.Writer, in io.Reader, opts ...Option) error {
e := embedder{Fetcher: fetcher{}}
for _, opt := range opts {
opt.f(&e)
}
return process(out, in, e.runCommand)
}
|
go
|
func Process(out io.Writer, in io.Reader, opts ...Option) error {
e := embedder{Fetcher: fetcher{}}
for _, opt := range opts {
opt.f(&e)
}
return process(out, in, e.runCommand)
}
|
[
"func",
"Process",
"(",
"out",
"io",
".",
"Writer",
",",
"in",
"io",
".",
"Reader",
",",
"opts",
"...",
"Option",
")",
"error",
"{",
"e",
":=",
"embedder",
"{",
"Fetcher",
":",
"fetcher",
"{",
"}",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
".",
"f",
"(",
"&",
"e",
")",
"\n",
"}",
"\n",
"return",
"process",
"(",
"out",
",",
"in",
",",
"e",
".",
"runCommand",
")",
"\n",
"}"
] |
// Process reads markdown from the given io.Reader searching for an embedmd
// command. When a command is found, it is executed and the output is written
// into the given io.Writer with the rest of standard markdown.
|
[
"Process",
"reads",
"markdown",
"from",
"the",
"given",
"io",
".",
"Reader",
"searching",
"for",
"an",
"embedmd",
"command",
".",
"When",
"a",
"command",
"is",
"found",
"it",
"is",
"executed",
"and",
"the",
"output",
"is",
"written",
"into",
"the",
"given",
"io",
".",
"Writer",
"with",
"the",
"rest",
"of",
"standard",
"markdown",
"."
] |
97c13d6e41602fc6e397eb51c45f38069371a969
|
https://github.com/campoy/embedmd/blob/97c13d6e41602fc6e397eb51c45f38069371a969/embedmd/embedmd.go#L64-L70
|
14,203 |
campoy/embedmd
|
embedmd/embedmd.go
|
WithBaseDir
|
func WithBaseDir(path string) Option {
return Option{func(e *embedder) { e.baseDir = path }}
}
|
go
|
func WithBaseDir(path string) Option {
return Option{func(e *embedder) { e.baseDir = path }}
}
|
[
"func",
"WithBaseDir",
"(",
"path",
"string",
")",
"Option",
"{",
"return",
"Option",
"{",
"func",
"(",
"e",
"*",
"embedder",
")",
"{",
"e",
".",
"baseDir",
"=",
"path",
"}",
"}",
"\n",
"}"
] |
// WithBaseDir indicates that the given path should be used to resolve relative
// paths.
|
[
"WithBaseDir",
"indicates",
"that",
"the",
"given",
"path",
"should",
"be",
"used",
"to",
"resolve",
"relative",
"paths",
"."
] |
97c13d6e41602fc6e397eb51c45f38069371a969
|
https://github.com/campoy/embedmd/blob/97c13d6e41602fc6e397eb51c45f38069371a969/embedmd/embedmd.go#L77-L79
|
14,204 |
campoy/embedmd
|
embedmd/embedmd.go
|
WithFetcher
|
func WithFetcher(c Fetcher) Option {
return Option{func(e *embedder) { e.Fetcher = c }}
}
|
go
|
func WithFetcher(c Fetcher) Option {
return Option{func(e *embedder) { e.Fetcher = c }}
}
|
[
"func",
"WithFetcher",
"(",
"c",
"Fetcher",
")",
"Option",
"{",
"return",
"Option",
"{",
"func",
"(",
"e",
"*",
"embedder",
")",
"{",
"e",
".",
"Fetcher",
"=",
"c",
"}",
"}",
"\n",
"}"
] |
// WithFetcher provides a custom Fetcher to be used whenever a path or url needs
// to be fetched.
|
[
"WithFetcher",
"provides",
"a",
"custom",
"Fetcher",
"to",
"be",
"used",
"whenever",
"a",
"path",
"or",
"url",
"needs",
"to",
"be",
"fetched",
"."
] |
97c13d6e41602fc6e397eb51c45f38069371a969
|
https://github.com/campoy/embedmd/blob/97c13d6e41602fc6e397eb51c45f38069371a969/embedmd/embedmd.go#L83-L85
|
14,205 |
jszwec/csvutil
|
encoder.go
|
EncodeHeader
|
func (e *Encoder) EncodeHeader(v interface{}) error {
typ, err := valueType(v)
if err != nil {
return err
}
return e.encodeHeader(typ)
}
|
go
|
func (e *Encoder) EncodeHeader(v interface{}) error {
typ, err := valueType(v)
if err != nil {
return err
}
return e.encodeHeader(typ)
}
|
[
"func",
"(",
"e",
"*",
"Encoder",
")",
"EncodeHeader",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"typ",
",",
"err",
":=",
"valueType",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"e",
".",
"encodeHeader",
"(",
"typ",
")",
"\n",
"}"
] |
// EncodeHeader writes the CSV header of the provided struct value to the output
// stream. The provided argument v must be a struct value.
//
// The first Encode method call will not write header if EncodeHeader was called
// before it. This method can be called in cases when a data set could be
// empty, but header is desired.
//
// EncodeHeader is like Header function, but it works with the Encoder and writes
// directly to the output stream. Look at Header documentation for the exact
// header encoding rules.
|
[
"EncodeHeader",
"writes",
"the",
"CSV",
"header",
"of",
"the",
"provided",
"struct",
"value",
"to",
"the",
"output",
"stream",
".",
"The",
"provided",
"argument",
"v",
"must",
"be",
"a",
"struct",
"value",
".",
"The",
"first",
"Encode",
"method",
"call",
"will",
"not",
"write",
"header",
"if",
"EncodeHeader",
"was",
"called",
"before",
"it",
".",
"This",
"method",
"can",
"be",
"called",
"in",
"cases",
"when",
"a",
"data",
"set",
"could",
"be",
"empty",
"but",
"header",
"is",
"desired",
".",
"EncodeHeader",
"is",
"like",
"Header",
"function",
"but",
"it",
"works",
"with",
"the",
"Encoder",
"and",
"writes",
"directly",
"to",
"the",
"output",
"stream",
".",
"Look",
"at",
"Header",
"documentation",
"for",
"the",
"exact",
"header",
"encoding",
"rules",
"."
] |
0115205d1ccaac20f9c7e4cdc987adf657c9fbf2
|
https://github.com/jszwec/csvutil/blob/0115205d1ccaac20f9c7e4cdc987adf657c9fbf2/encoder.go#L139-L145
|
14,206 |
jszwec/csvutil
|
decoder.go
|
NewDecoder
|
func NewDecoder(r Reader, header ...string) (dec *Decoder, err error) {
if len(header) == 0 {
header, err = r.Read()
if err != nil {
return nil, err
}
}
h := make([]string, len(header))
copy(h, header)
header = h
m := make(map[string]int, len(header))
for i, h := range header {
m[h] = i
}
return &Decoder{
r: r,
header: header,
hmap: m,
unused: make([]int, 0, len(header)),
}, nil
}
|
go
|
func NewDecoder(r Reader, header ...string) (dec *Decoder, err error) {
if len(header) == 0 {
header, err = r.Read()
if err != nil {
return nil, err
}
}
h := make([]string, len(header))
copy(h, header)
header = h
m := make(map[string]int, len(header))
for i, h := range header {
m[h] = i
}
return &Decoder{
r: r,
header: header,
hmap: m,
unused: make([]int, 0, len(header)),
}, nil
}
|
[
"func",
"NewDecoder",
"(",
"r",
"Reader",
",",
"header",
"...",
"string",
")",
"(",
"dec",
"*",
"Decoder",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"header",
")",
"==",
"0",
"{",
"header",
",",
"err",
"=",
"r",
".",
"Read",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"h",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"header",
")",
")",
"\n",
"copy",
"(",
"h",
",",
"header",
")",
"\n",
"header",
"=",
"h",
"\n\n",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"len",
"(",
"header",
")",
")",
"\n",
"for",
"i",
",",
"h",
":=",
"range",
"header",
"{",
"m",
"[",
"h",
"]",
"=",
"i",
"\n",
"}",
"\n\n",
"return",
"&",
"Decoder",
"{",
"r",
":",
"r",
",",
"header",
":",
"header",
",",
"hmap",
":",
"m",
",",
"unused",
":",
"make",
"(",
"[",
"]",
"int",
",",
"0",
",",
"len",
"(",
"header",
")",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewDecoder returns a new decoder that reads from r.
//
// Decoder will match struct fields according to the given header.
//
// If header is empty NewDecoder will read one line and treat it as a header.
//
// Records coming from r must be of the same length as the header.
//
// NewDecoder may return io.EOF if there is no data in r and no header was
// provided by the caller.
|
[
"NewDecoder",
"returns",
"a",
"new",
"decoder",
"that",
"reads",
"from",
"r",
".",
"Decoder",
"will",
"match",
"struct",
"fields",
"according",
"to",
"the",
"given",
"header",
".",
"If",
"header",
"is",
"empty",
"NewDecoder",
"will",
"read",
"one",
"line",
"and",
"treat",
"it",
"as",
"a",
"header",
".",
"Records",
"coming",
"from",
"r",
"must",
"be",
"of",
"the",
"same",
"length",
"as",
"the",
"header",
".",
"NewDecoder",
"may",
"return",
"io",
".",
"EOF",
"if",
"there",
"is",
"no",
"data",
"in",
"r",
"and",
"no",
"header",
"was",
"provided",
"by",
"the",
"caller",
"."
] |
0115205d1ccaac20f9c7e4cdc987adf657c9fbf2
|
https://github.com/jszwec/csvutil/blob/0115205d1ccaac20f9c7e4cdc987adf657c9fbf2/decoder.go#L61-L84
|
14,207 |
jszwec/csvutil
|
decoder.go
|
Header
|
func (d *Decoder) Header() []string {
header := make([]string, len(d.header))
copy(header, d.header)
return header
}
|
go
|
func (d *Decoder) Header() []string {
header := make([]string, len(d.header))
copy(header, d.header)
return header
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"Header",
"(",
")",
"[",
"]",
"string",
"{",
"header",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"d",
".",
"header",
")",
")",
"\n",
"copy",
"(",
"header",
",",
"d",
".",
"header",
")",
"\n",
"return",
"header",
"\n",
"}"
] |
// Header returns the first line that came from the reader, or returns the
// defined header by the caller.
|
[
"Header",
"returns",
"the",
"first",
"line",
"that",
"came",
"from",
"the",
"reader",
"or",
"returns",
"the",
"defined",
"header",
"by",
"the",
"caller",
"."
] |
0115205d1ccaac20f9c7e4cdc987adf657c9fbf2
|
https://github.com/jszwec/csvutil/blob/0115205d1ccaac20f9c7e4cdc987adf657c9fbf2/decoder.go#L155-L159
|
14,208 |
jszwec/csvutil
|
decoder.go
|
Unused
|
func (d *Decoder) Unused() []int {
if len(d.unused) == 0 {
return nil
}
indices := make([]int, len(d.unused))
copy(indices, d.unused)
return indices
}
|
go
|
func (d *Decoder) Unused() []int {
if len(d.unused) == 0 {
return nil
}
indices := make([]int, len(d.unused))
copy(indices, d.unused)
return indices
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"Unused",
"(",
")",
"[",
"]",
"int",
"{",
"if",
"len",
"(",
"d",
".",
"unused",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"indices",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"len",
"(",
"d",
".",
"unused",
")",
")",
"\n",
"copy",
"(",
"indices",
",",
"d",
".",
"unused",
")",
"\n",
"return",
"indices",
"\n",
"}"
] |
// Unused returns a list of column indexes that were not used during decoding
// due to lack of matching struct field.
|
[
"Unused",
"returns",
"a",
"list",
"of",
"column",
"indexes",
"that",
"were",
"not",
"used",
"during",
"decoding",
"due",
"to",
"lack",
"of",
"matching",
"struct",
"field",
"."
] |
0115205d1ccaac20f9c7e4cdc987adf657c9fbf2
|
https://github.com/jszwec/csvutil/blob/0115205d1ccaac20f9c7e4cdc987adf657c9fbf2/decoder.go#L163-L171
|
14,209 |
akutz/memconn
|
memconn_listener.go
|
Close
|
func (l *Listener) Close() error {
l.once.Do(func() {
close(l.done)
<-l.rmvd
})
return nil
}
|
go
|
func (l *Listener) Close() error {
l.once.Do(func() {
close(l.done)
<-l.rmvd
})
return nil
}
|
[
"func",
"(",
"l",
"*",
"Listener",
")",
"Close",
"(",
")",
"error",
"{",
"l",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"l",
".",
"done",
")",
"\n",
"<-",
"l",
".",
"rmvd",
"\n",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close implements the net.Listener Close method.
|
[
"Close",
"implements",
"the",
"net",
".",
"Listener",
"Close",
"method",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_listener.go#L94-L100
|
14,210 |
akutz/memconn
|
memconn_pipe.go
|
set
|
func (d *pipeDeadline) set(t time.Time) {
d.mu.Lock()
defer d.mu.Unlock()
if d.timer != nil && !d.timer.Stop() {
<-d.cancel // Wait for the timer callback to finish and close cancel
}
d.timer = nil
// Time is zero, then there is no deadline.
closed := isClosedChan(d.cancel)
if t.IsZero() {
if closed {
d.cancel = make(chan struct{})
}
return
}
// Time in the future, setup a timer to cancel in the future.
if dur := time.Until(t); dur > 0 {
if closed {
d.cancel = make(chan struct{})
}
d.timer = time.AfterFunc(dur, func() {
close(d.cancel)
})
return
}
// Time in the past, so close immediately.
if !closed {
close(d.cancel)
}
}
|
go
|
func (d *pipeDeadline) set(t time.Time) {
d.mu.Lock()
defer d.mu.Unlock()
if d.timer != nil && !d.timer.Stop() {
<-d.cancel // Wait for the timer callback to finish and close cancel
}
d.timer = nil
// Time is zero, then there is no deadline.
closed := isClosedChan(d.cancel)
if t.IsZero() {
if closed {
d.cancel = make(chan struct{})
}
return
}
// Time in the future, setup a timer to cancel in the future.
if dur := time.Until(t); dur > 0 {
if closed {
d.cancel = make(chan struct{})
}
d.timer = time.AfterFunc(dur, func() {
close(d.cancel)
})
return
}
// Time in the past, so close immediately.
if !closed {
close(d.cancel)
}
}
|
[
"func",
"(",
"d",
"*",
"pipeDeadline",
")",
"set",
"(",
"t",
"time",
".",
"Time",
")",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"d",
".",
"timer",
"!=",
"nil",
"&&",
"!",
"d",
".",
"timer",
".",
"Stop",
"(",
")",
"{",
"<-",
"d",
".",
"cancel",
"// Wait for the timer callback to finish and close cancel",
"\n",
"}",
"\n",
"d",
".",
"timer",
"=",
"nil",
"\n\n",
"// Time is zero, then there is no deadline.",
"closed",
":=",
"isClosedChan",
"(",
"d",
".",
"cancel",
")",
"\n",
"if",
"t",
".",
"IsZero",
"(",
")",
"{",
"if",
"closed",
"{",
"d",
".",
"cancel",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Time in the future, setup a timer to cancel in the future.",
"if",
"dur",
":=",
"time",
".",
"Until",
"(",
"t",
")",
";",
"dur",
">",
"0",
"{",
"if",
"closed",
"{",
"d",
".",
"cancel",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"}",
"\n",
"d",
".",
"timer",
"=",
"time",
".",
"AfterFunc",
"(",
"dur",
",",
"func",
"(",
")",
"{",
"close",
"(",
"d",
".",
"cancel",
")",
"\n",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Time in the past, so close immediately.",
"if",
"!",
"closed",
"{",
"close",
"(",
"d",
".",
"cancel",
")",
"\n",
"}",
"\n",
"}"
] |
// set sets the point in time when the deadline will time out.
// A timeout event is signaled by closing the channel returned by waiter.
// Once a timeout has occurred, the deadline can be refreshed by specifying a
// t value in the future.
//
// A zero value for t prevents timeout.
|
[
"set",
"sets",
"the",
"point",
"in",
"time",
"when",
"the",
"deadline",
"will",
"time",
"out",
".",
"A",
"timeout",
"event",
"is",
"signaled",
"by",
"closing",
"the",
"channel",
"returned",
"by",
"waiter",
".",
"Once",
"a",
"timeout",
"has",
"occurred",
"the",
"deadline",
"can",
"be",
"refreshed",
"by",
"specifying",
"a",
"t",
"value",
"in",
"the",
"future",
".",
"A",
"zero",
"value",
"for",
"t",
"prevents",
"timeout",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_pipe.go#L52-L85
|
14,211 |
akutz/memconn
|
memconn_pipe.go
|
wait
|
func (d *pipeDeadline) wait() chan struct{} {
d.mu.Lock()
defer d.mu.Unlock()
return d.cancel
}
|
go
|
func (d *pipeDeadline) wait() chan struct{} {
d.mu.Lock()
defer d.mu.Unlock()
return d.cancel
}
|
[
"func",
"(",
"d",
"*",
"pipeDeadline",
")",
"wait",
"(",
")",
"chan",
"struct",
"{",
"}",
"{",
"d",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"d",
".",
"cancel",
"\n",
"}"
] |
// wait returns a channel that is closed when the deadline is exceeded.
|
[
"wait",
"returns",
"a",
"channel",
"that",
"is",
"closed",
"when",
"the",
"deadline",
"is",
"exceeded",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_pipe.go#L88-L92
|
14,212 |
akutz/memconn
|
memconn_pipe.go
|
Pipe
|
func Pipe() (net.Conn, net.Conn) {
cb1 := make(chan []byte)
cb2 := make(chan []byte)
cn1 := make(chan int)
cn2 := make(chan int)
done1 := make(chan struct{})
done2 := make(chan struct{})
p1 := &pipe{
rdRx: cb1, rdTx: cn1,
wrTx: cb2, wrRx: cn2,
localDone: done1, remoteDone: done2,
readDeadline: makePipeDeadline(),
writeDeadline: makePipeDeadline(),
}
p2 := &pipe{
rdRx: cb2, rdTx: cn2,
wrTx: cb1, wrRx: cn1,
localDone: done2, remoteDone: done1,
readDeadline: makePipeDeadline(),
writeDeadline: makePipeDeadline(),
}
return p1, p2
}
|
go
|
func Pipe() (net.Conn, net.Conn) {
cb1 := make(chan []byte)
cb2 := make(chan []byte)
cn1 := make(chan int)
cn2 := make(chan int)
done1 := make(chan struct{})
done2 := make(chan struct{})
p1 := &pipe{
rdRx: cb1, rdTx: cn1,
wrTx: cb2, wrRx: cn2,
localDone: done1, remoteDone: done2,
readDeadline: makePipeDeadline(),
writeDeadline: makePipeDeadline(),
}
p2 := &pipe{
rdRx: cb2, rdTx: cn2,
wrTx: cb1, wrRx: cn1,
localDone: done2, remoteDone: done1,
readDeadline: makePipeDeadline(),
writeDeadline: makePipeDeadline(),
}
return p1, p2
}
|
[
"func",
"Pipe",
"(",
")",
"(",
"net",
".",
"Conn",
",",
"net",
".",
"Conn",
")",
"{",
"cb1",
":=",
"make",
"(",
"chan",
"[",
"]",
"byte",
")",
"\n",
"cb2",
":=",
"make",
"(",
"chan",
"[",
"]",
"byte",
")",
"\n",
"cn1",
":=",
"make",
"(",
"chan",
"int",
")",
"\n",
"cn2",
":=",
"make",
"(",
"chan",
"int",
")",
"\n",
"done1",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"done2",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n\n",
"p1",
":=",
"&",
"pipe",
"{",
"rdRx",
":",
"cb1",
",",
"rdTx",
":",
"cn1",
",",
"wrTx",
":",
"cb2",
",",
"wrRx",
":",
"cn2",
",",
"localDone",
":",
"done1",
",",
"remoteDone",
":",
"done2",
",",
"readDeadline",
":",
"makePipeDeadline",
"(",
")",
",",
"writeDeadline",
":",
"makePipeDeadline",
"(",
")",
",",
"}",
"\n",
"p2",
":=",
"&",
"pipe",
"{",
"rdRx",
":",
"cb2",
",",
"rdTx",
":",
"cn2",
",",
"wrTx",
":",
"cb1",
",",
"wrRx",
":",
"cn1",
",",
"localDone",
":",
"done2",
",",
"remoteDone",
":",
"done1",
",",
"readDeadline",
":",
"makePipeDeadline",
"(",
")",
",",
"writeDeadline",
":",
"makePipeDeadline",
"(",
")",
",",
"}",
"\n",
"return",
"p1",
",",
"p2",
"\n",
"}"
] |
// Pipe creates a synchronous, in-memory, full duplex
// network connection; both ends implement the Conn interface.
// Reads on one end are matched with writes on the other,
// copying data directly between the two; there is no internal
// buffering.
|
[
"Pipe",
"creates",
"a",
"synchronous",
"in",
"-",
"memory",
"full",
"duplex",
"network",
"connection",
";",
"both",
"ends",
"implement",
"the",
"Conn",
"interface",
".",
"Reads",
"on",
"one",
"end",
"are",
"matched",
"with",
"writes",
"on",
"the",
"other",
"copying",
"data",
"directly",
"between",
"the",
"two",
";",
"there",
"is",
"no",
"internal",
"buffering",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_pipe.go#L140-L163
|
14,213 |
akutz/memconn
|
memconn_conn.go
|
BufferSize
|
func (c *Conn) BufferSize() int {
if c.laddr.Buffered() {
c.buf.configMu.RLock()
defer c.buf.configMu.RUnlock()
return c.buf.max
}
return 0
}
|
go
|
func (c *Conn) BufferSize() int {
if c.laddr.Buffered() {
c.buf.configMu.RLock()
defer c.buf.configMu.RUnlock()
return c.buf.max
}
return 0
}
|
[
"func",
"(",
"c",
"*",
"Conn",
")",
"BufferSize",
"(",
")",
"int",
"{",
"if",
"c",
".",
"laddr",
".",
"Buffered",
"(",
")",
"{",
"c",
".",
"buf",
".",
"configMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"buf",
".",
"configMu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
".",
"buf",
".",
"max",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] |
// BufferSize gets the number of bytes allowed to be queued for
// asynchrnous Write operations.
//
// Please note that this function will always return zero for unbuffered
// connections.
//
// Please see the function SetBufferSize for more information.
|
[
"BufferSize",
"gets",
"the",
"number",
"of",
"bytes",
"allowed",
"to",
"be",
"queued",
"for",
"asynchrnous",
"Write",
"operations",
".",
"Please",
"note",
"that",
"this",
"function",
"will",
"always",
"return",
"zero",
"for",
"unbuffered",
"connections",
".",
"Please",
"see",
"the",
"function",
"SetBufferSize",
"for",
"more",
"information",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_conn.go#L136-L143
|
14,214 |
akutz/memconn
|
memconn_conn.go
|
CloseTimeout
|
func (c *Conn) CloseTimeout() time.Duration {
if c.laddr.Buffered() {
c.buf.configMu.RLock()
defer c.buf.configMu.RUnlock()
return c.buf.closeTimeout
}
return 0
}
|
go
|
func (c *Conn) CloseTimeout() time.Duration {
if c.laddr.Buffered() {
c.buf.configMu.RLock()
defer c.buf.configMu.RUnlock()
return c.buf.closeTimeout
}
return 0
}
|
[
"func",
"(",
"c",
"*",
"Conn",
")",
"CloseTimeout",
"(",
")",
"time",
".",
"Duration",
"{",
"if",
"c",
".",
"laddr",
".",
"Buffered",
"(",
")",
"{",
"c",
".",
"buf",
".",
"configMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"buf",
".",
"configMu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
".",
"buf",
".",
"closeTimeout",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] |
// CloseTimeout gets the time.Duration value used when closing buffered
// connections.
//
// Please note that this function will always return zero for
// unbuffered connections.
//
// Please see the function SetCloseTimeout for more information.
|
[
"CloseTimeout",
"gets",
"the",
"time",
".",
"Duration",
"value",
"used",
"when",
"closing",
"buffered",
"connections",
".",
"Please",
"note",
"that",
"this",
"function",
"will",
"always",
"return",
"zero",
"for",
"unbuffered",
"connections",
".",
"Please",
"see",
"the",
"function",
"SetCloseTimeout",
"for",
"more",
"information",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_conn.go#L172-L179
|
14,215 |
akutz/memconn
|
memconn_conn.go
|
SetCloseTimeout
|
func (c *Conn) SetCloseTimeout(d time.Duration) {
if c.laddr.Buffered() {
c.buf.configMu.Lock()
defer c.buf.configMu.Unlock()
c.buf.closeTimeout = d
}
}
|
go
|
func (c *Conn) SetCloseTimeout(d time.Duration) {
if c.laddr.Buffered() {
c.buf.configMu.Lock()
defer c.buf.configMu.Unlock()
c.buf.closeTimeout = d
}
}
|
[
"func",
"(",
"c",
"*",
"Conn",
")",
"SetCloseTimeout",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"if",
"c",
".",
"laddr",
".",
"Buffered",
"(",
")",
"{",
"c",
".",
"buf",
".",
"configMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"buf",
".",
"configMu",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"buf",
".",
"closeTimeout",
"=",
"d",
"\n",
"}",
"\n",
"}"
] |
// SetCloseTimeout sets a time.Duration value used by the Close function
// to determine the amount of time to wait for pending, buffered Writes
// to complete before closing the connection.
//
// The default timeout value is 10 seconds. A zero value does not
// mean there is no timeout, rather it means the timeout is immediate.
//
// Please note that setting this value has no effect on unbuffered
// connections.
|
[
"SetCloseTimeout",
"sets",
"a",
"time",
".",
"Duration",
"value",
"used",
"by",
"the",
"Close",
"function",
"to",
"determine",
"the",
"amount",
"of",
"time",
"to",
"wait",
"for",
"pending",
"buffered",
"Writes",
"to",
"complete",
"before",
"closing",
"the",
"connection",
".",
"The",
"default",
"timeout",
"value",
"is",
"10",
"seconds",
".",
"A",
"zero",
"value",
"does",
"not",
"mean",
"there",
"is",
"no",
"timeout",
"rather",
"it",
"means",
"the",
"timeout",
"is",
"immediate",
".",
"Please",
"note",
"that",
"setting",
"this",
"value",
"has",
"no",
"effect",
"on",
"unbuffered",
"connections",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_conn.go#L190-L196
|
14,216 |
akutz/memconn
|
memconn_conn.go
|
Close
|
func (c *Conn) Close() error {
c.pipe.once.Do(func() {
// Buffered connections will attempt to wait until all
// pending Writes are completed or until the specified
// timeout value has elapsed.
if c.laddr.Buffered() {
// Set up a channel that is closed when the specified
// timer elapses.
timeout := c.CloseTimeout()
timeoutDone := make(chan struct{})
if timeout == 0 {
close(timeoutDone)
} else {
time.AfterFunc(timeout, func() { close(timeoutDone) })
}
// Set up a channel that is closed when there is
// no more buffered data.
writesDone := make(chan struct{})
go func() {
c.buf.dataMu.Lock()
defer c.buf.dataMu.Unlock()
for len(c.buf.dataN) > 0 {
c.buf.dataMu.Unlock()
c.buf.dataMu.Lock()
}
close(writesDone)
}()
// Wait to close the connection.
select {
case <-writesDone:
case <-timeoutDone:
}
}
close(c.pipe.localDone)
})
return nil
}
|
go
|
func (c *Conn) Close() error {
c.pipe.once.Do(func() {
// Buffered connections will attempt to wait until all
// pending Writes are completed or until the specified
// timeout value has elapsed.
if c.laddr.Buffered() {
// Set up a channel that is closed when the specified
// timer elapses.
timeout := c.CloseTimeout()
timeoutDone := make(chan struct{})
if timeout == 0 {
close(timeoutDone)
} else {
time.AfterFunc(timeout, func() { close(timeoutDone) })
}
// Set up a channel that is closed when there is
// no more buffered data.
writesDone := make(chan struct{})
go func() {
c.buf.dataMu.Lock()
defer c.buf.dataMu.Unlock()
for len(c.buf.dataN) > 0 {
c.buf.dataMu.Unlock()
c.buf.dataMu.Lock()
}
close(writesDone)
}()
// Wait to close the connection.
select {
case <-writesDone:
case <-timeoutDone:
}
}
close(c.pipe.localDone)
})
return nil
}
|
[
"func",
"(",
"c",
"*",
"Conn",
")",
"Close",
"(",
")",
"error",
"{",
"c",
".",
"pipe",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"// Buffered connections will attempt to wait until all",
"// pending Writes are completed or until the specified",
"// timeout value has elapsed.",
"if",
"c",
".",
"laddr",
".",
"Buffered",
"(",
")",
"{",
"// Set up a channel that is closed when the specified",
"// timer elapses.",
"timeout",
":=",
"c",
".",
"CloseTimeout",
"(",
")",
"\n",
"timeoutDone",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"if",
"timeout",
"==",
"0",
"{",
"close",
"(",
"timeoutDone",
")",
"\n",
"}",
"else",
"{",
"time",
".",
"AfterFunc",
"(",
"timeout",
",",
"func",
"(",
")",
"{",
"close",
"(",
"timeoutDone",
")",
"}",
")",
"\n",
"}",
"\n\n",
"// Set up a channel that is closed when there is",
"// no more buffered data.",
"writesDone",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"c",
".",
"buf",
".",
"dataMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"buf",
".",
"dataMu",
".",
"Unlock",
"(",
")",
"\n",
"for",
"len",
"(",
"c",
".",
"buf",
".",
"dataN",
")",
">",
"0",
"{",
"c",
".",
"buf",
".",
"dataMu",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"buf",
".",
"dataMu",
".",
"Lock",
"(",
")",
"\n",
"}",
"\n",
"close",
"(",
"writesDone",
")",
"\n",
"}",
"(",
")",
"\n\n",
"// Wait to close the connection.",
"select",
"{",
"case",
"<-",
"writesDone",
":",
"case",
"<-",
"timeoutDone",
":",
"}",
"\n",
"}",
"\n\n",
"close",
"(",
"c",
".",
"pipe",
".",
"localDone",
")",
"\n",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close implements the net.Conn Close method.
|
[
"Close",
"implements",
"the",
"net",
".",
"Conn",
"Close",
"method",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_conn.go#L209-L250
|
14,217 |
akutz/memconn
|
memconn_conn.go
|
writeAsync
|
func (c *Conn) writeAsync(b []byte) (int, error) {
// Prevent concurrent writes.
c.buf.writeMu.Lock()
defer c.buf.writeMu.Unlock()
// Get the max buffer size to determine if the buffer's capacity
// should be grown.
c.buf.configMu.RLock()
max := c.buf.max
c.buf.configMu.RUnlock()
// If the provided data is too large for the buffer then force
// a synchrnous write.
if max > 0 && len(b) > max {
return c.writeSync(b)
}
// Lock access to the buffer. This prevents concurrent writes to
// the buffer. Occasionally the lock is released temporarily to
// check if the buffer's length allows this write operation to
// proceed.
c.buf.dataMu.Lock()
// If the max buffer size is non-zero and larger than the
// capacity of the buffer, then grow the buffer capacity.
if max > 0 && max > c.buf.data.Cap() {
c.buf.data.Grow(max)
}
// Wait until there is room in the buffer to proceed.
for max > 0 && c.buf.data.Len()+len(b) > c.buf.data.Cap() {
c.buf.dataMu.Unlock()
c.buf.dataMu.Lock()
}
defer c.buf.dataMu.Unlock()
// Write the data to the buffer.
n, err := c.buf.data.Write(b)
if err != nil {
return n, err
} else if n < len(b) {
return n, fmt.Errorf("trunc write: exp=%d act=%d", len(b), n)
}
// Record the number of bytes written in a FIFO list.
c.buf.dataN = append(c.buf.dataN, n)
// Start a goroutine that reads n bytes from the buffer where n
// is the first element in the FIFO list from above. The read
// below may not actually correspond to the write from above;
// that's okay. The important thing is the order of the reads,
// and that's achieved using the circular buffer and FIFO list
// of bytes written.
go func() {
// The read operation must also obtain a lock, preventing
// concurrent access to the buffer.
c.buf.dataMu.Lock()
// Get the number of bytes to read.
n := c.buf.dataN[0]
c.buf.dataN = c.buf.dataN[1:]
// Read the bytes from the buffer into a temporary buffer.
b := make([]byte, n)
if nr, err := c.buf.data.Read(b); err != nil {
go func() { c.buf.errs <- err }()
c.buf.dataMu.Unlock()
return
} else if nr < n {
go func() {
c.buf.errs <- fmt.Errorf("trunc read: exp=%d act=%d", n, nr)
}()
c.buf.dataMu.Unlock()
return
}
// Ensure access to the buffer is restored.
defer c.buf.dataMu.Unlock()
// Write the temporary buffer into the underlying connection.
if nw, err := c.writeSync(b); err != nil {
go func() { c.buf.errs <- err }()
return
} else if nw < n {
go func() {
c.buf.errs <- fmt.Errorf("trunc write: exp=%d act=%d", n, nw)
}()
return
}
}()
return n, nil
}
|
go
|
func (c *Conn) writeAsync(b []byte) (int, error) {
// Prevent concurrent writes.
c.buf.writeMu.Lock()
defer c.buf.writeMu.Unlock()
// Get the max buffer size to determine if the buffer's capacity
// should be grown.
c.buf.configMu.RLock()
max := c.buf.max
c.buf.configMu.RUnlock()
// If the provided data is too large for the buffer then force
// a synchrnous write.
if max > 0 && len(b) > max {
return c.writeSync(b)
}
// Lock access to the buffer. This prevents concurrent writes to
// the buffer. Occasionally the lock is released temporarily to
// check if the buffer's length allows this write operation to
// proceed.
c.buf.dataMu.Lock()
// If the max buffer size is non-zero and larger than the
// capacity of the buffer, then grow the buffer capacity.
if max > 0 && max > c.buf.data.Cap() {
c.buf.data.Grow(max)
}
// Wait until there is room in the buffer to proceed.
for max > 0 && c.buf.data.Len()+len(b) > c.buf.data.Cap() {
c.buf.dataMu.Unlock()
c.buf.dataMu.Lock()
}
defer c.buf.dataMu.Unlock()
// Write the data to the buffer.
n, err := c.buf.data.Write(b)
if err != nil {
return n, err
} else if n < len(b) {
return n, fmt.Errorf("trunc write: exp=%d act=%d", len(b), n)
}
// Record the number of bytes written in a FIFO list.
c.buf.dataN = append(c.buf.dataN, n)
// Start a goroutine that reads n bytes from the buffer where n
// is the first element in the FIFO list from above. The read
// below may not actually correspond to the write from above;
// that's okay. The important thing is the order of the reads,
// and that's achieved using the circular buffer and FIFO list
// of bytes written.
go func() {
// The read operation must also obtain a lock, preventing
// concurrent access to the buffer.
c.buf.dataMu.Lock()
// Get the number of bytes to read.
n := c.buf.dataN[0]
c.buf.dataN = c.buf.dataN[1:]
// Read the bytes from the buffer into a temporary buffer.
b := make([]byte, n)
if nr, err := c.buf.data.Read(b); err != nil {
go func() { c.buf.errs <- err }()
c.buf.dataMu.Unlock()
return
} else if nr < n {
go func() {
c.buf.errs <- fmt.Errorf("trunc read: exp=%d act=%d", n, nr)
}()
c.buf.dataMu.Unlock()
return
}
// Ensure access to the buffer is restored.
defer c.buf.dataMu.Unlock()
// Write the temporary buffer into the underlying connection.
if nw, err := c.writeSync(b); err != nil {
go func() { c.buf.errs <- err }()
return
} else if nw < n {
go func() {
c.buf.errs <- fmt.Errorf("trunc write: exp=%d act=%d", n, nw)
}()
return
}
}()
return n, nil
}
|
[
"func",
"(",
"c",
"*",
"Conn",
")",
"writeAsync",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Prevent concurrent writes.",
"c",
".",
"buf",
".",
"writeMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"buf",
".",
"writeMu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Get the max buffer size to determine if the buffer's capacity",
"// should be grown.",
"c",
".",
"buf",
".",
"configMu",
".",
"RLock",
"(",
")",
"\n",
"max",
":=",
"c",
".",
"buf",
".",
"max",
"\n",
"c",
".",
"buf",
".",
"configMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"// If the provided data is too large for the buffer then force",
"// a synchrnous write.",
"if",
"max",
">",
"0",
"&&",
"len",
"(",
"b",
")",
">",
"max",
"{",
"return",
"c",
".",
"writeSync",
"(",
"b",
")",
"\n",
"}",
"\n\n",
"// Lock access to the buffer. This prevents concurrent writes to",
"// the buffer. Occasionally the lock is released temporarily to",
"// check if the buffer's length allows this write operation to",
"// proceed.",
"c",
".",
"buf",
".",
"dataMu",
".",
"Lock",
"(",
")",
"\n\n",
"// If the max buffer size is non-zero and larger than the",
"// capacity of the buffer, then grow the buffer capacity.",
"if",
"max",
">",
"0",
"&&",
"max",
">",
"c",
".",
"buf",
".",
"data",
".",
"Cap",
"(",
")",
"{",
"c",
".",
"buf",
".",
"data",
".",
"Grow",
"(",
"max",
")",
"\n",
"}",
"\n\n",
"// Wait until there is room in the buffer to proceed.",
"for",
"max",
">",
"0",
"&&",
"c",
".",
"buf",
".",
"data",
".",
"Len",
"(",
")",
"+",
"len",
"(",
"b",
")",
">",
"c",
".",
"buf",
".",
"data",
".",
"Cap",
"(",
")",
"{",
"c",
".",
"buf",
".",
"dataMu",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"buf",
".",
"dataMu",
".",
"Lock",
"(",
")",
"\n",
"}",
"\n",
"defer",
"c",
".",
"buf",
".",
"dataMu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Write the data to the buffer.",
"n",
",",
"err",
":=",
"c",
".",
"buf",
".",
"data",
".",
"Write",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"else",
"if",
"n",
"<",
"len",
"(",
"b",
")",
"{",
"return",
"n",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"b",
")",
",",
"n",
")",
"\n",
"}",
"\n\n",
"// Record the number of bytes written in a FIFO list.",
"c",
".",
"buf",
".",
"dataN",
"=",
"append",
"(",
"c",
".",
"buf",
".",
"dataN",
",",
"n",
")",
"\n\n",
"// Start a goroutine that reads n bytes from the buffer where n",
"// is the first element in the FIFO list from above. The read",
"// below may not actually correspond to the write from above;",
"// that's okay. The important thing is the order of the reads,",
"// and that's achieved using the circular buffer and FIFO list",
"// of bytes written.",
"go",
"func",
"(",
")",
"{",
"// The read operation must also obtain a lock, preventing",
"// concurrent access to the buffer.",
"c",
".",
"buf",
".",
"dataMu",
".",
"Lock",
"(",
")",
"\n\n",
"// Get the number of bytes to read.",
"n",
":=",
"c",
".",
"buf",
".",
"dataN",
"[",
"0",
"]",
"\n",
"c",
".",
"buf",
".",
"dataN",
"=",
"c",
".",
"buf",
".",
"dataN",
"[",
"1",
":",
"]",
"\n\n",
"// Read the bytes from the buffer into a temporary buffer.",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"if",
"nr",
",",
"err",
":=",
"c",
".",
"buf",
".",
"data",
".",
"Read",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"go",
"func",
"(",
")",
"{",
"c",
".",
"buf",
".",
"errs",
"<-",
"err",
"}",
"(",
")",
"\n",
"c",
".",
"buf",
".",
"dataMu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"else",
"if",
"nr",
"<",
"n",
"{",
"go",
"func",
"(",
")",
"{",
"c",
".",
"buf",
".",
"errs",
"<-",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
",",
"nr",
")",
"\n",
"}",
"(",
")",
"\n",
"c",
".",
"buf",
".",
"dataMu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Ensure access to the buffer is restored.",
"defer",
"c",
".",
"buf",
".",
"dataMu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Write the temporary buffer into the underlying connection.",
"if",
"nw",
",",
"err",
":=",
"c",
".",
"writeSync",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"go",
"func",
"(",
")",
"{",
"c",
".",
"buf",
".",
"errs",
"<-",
"err",
"}",
"(",
")",
"\n",
"return",
"\n",
"}",
"else",
"if",
"nw",
"<",
"n",
"{",
"go",
"func",
"(",
")",
"{",
"c",
".",
"buf",
".",
"errs",
"<-",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
",",
"nw",
")",
"\n",
"}",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] |
// writeAsync performs the Write operation in a goroutine. This
// behavior means the Write operation is not blocking, but also means
// that when Write operations fail the associated error is not returned
// from this function.
|
[
"writeAsync",
"performs",
"the",
"Write",
"operation",
"in",
"a",
"goroutine",
".",
"This",
"behavior",
"means",
"the",
"Write",
"operation",
"is",
"not",
"blocking",
"but",
"also",
"means",
"that",
"when",
"Write",
"operations",
"fail",
"the",
"associated",
"error",
"is",
"not",
"returned",
"from",
"this",
"function",
"."
] |
e0a19f53d865bbc181e3ed1204978510b315f7e2
|
https://github.com/akutz/memconn/blob/e0a19f53d865bbc181e3ed1204978510b315f7e2/memconn_conn.go#L317-L409
|
14,218 |
gregjones/httpcache
|
diskcache/diskcache.go
|
New
|
func New(basePath string) *Cache {
return &Cache{
d: diskv.New(diskv.Options{
BasePath: basePath,
CacheSizeMax: 100 * 1024 * 1024, // 100MB
}),
}
}
|
go
|
func New(basePath string) *Cache {
return &Cache{
d: diskv.New(diskv.Options{
BasePath: basePath,
CacheSizeMax: 100 * 1024 * 1024, // 100MB
}),
}
}
|
[
"func",
"New",
"(",
"basePath",
"string",
")",
"*",
"Cache",
"{",
"return",
"&",
"Cache",
"{",
"d",
":",
"diskv",
".",
"New",
"(",
"diskv",
".",
"Options",
"{",
"BasePath",
":",
"basePath",
",",
"CacheSizeMax",
":",
"100",
"*",
"1024",
"*",
"1024",
",",
"// 100MB",
"}",
")",
",",
"}",
"\n",
"}"
] |
// New returns a new Cache that will store files in basePath
|
[
"New",
"returns",
"a",
"new",
"Cache",
"that",
"will",
"store",
"files",
"in",
"basePath"
] |
3befbb6ad0cc97d4c25d851e9528915809e1a22f
|
https://github.com/gregjones/httpcache/blob/3befbb6ad0cc97d4c25d851e9528915809e1a22f/diskcache/diskcache.go#L48-L55
|
14,219 |
gregjones/httpcache
|
httpcache.go
|
cacheKey
|
func cacheKey(req *http.Request) string {
if req.Method == http.MethodGet {
return req.URL.String()
} else {
return req.Method + " " + req.URL.String()
}
}
|
go
|
func cacheKey(req *http.Request) string {
if req.Method == http.MethodGet {
return req.URL.String()
} else {
return req.Method + " " + req.URL.String()
}
}
|
[
"func",
"cacheKey",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"if",
"req",
".",
"Method",
"==",
"http",
".",
"MethodGet",
"{",
"return",
"req",
".",
"URL",
".",
"String",
"(",
")",
"\n",
"}",
"else",
"{",
"return",
"req",
".",
"Method",
"+",
"\"",
"\"",
"+",
"req",
".",
"URL",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// cacheKey returns the cache key for req.
|
[
"cacheKey",
"returns",
"the",
"cache",
"key",
"for",
"req",
"."
] |
3befbb6ad0cc97d4c25d851e9528915809e1a22f
|
https://github.com/gregjones/httpcache/blob/3befbb6ad0cc97d4c25d851e9528915809e1a22f/httpcache.go#L42-L48
|
14,220 |
gregjones/httpcache
|
httpcache.go
|
CachedResponse
|
func CachedResponse(c Cache, req *http.Request) (resp *http.Response, err error) {
cachedVal, ok := c.Get(cacheKey(req))
if !ok {
return
}
b := bytes.NewBuffer(cachedVal)
return http.ReadResponse(bufio.NewReader(b), req)
}
|
go
|
func CachedResponse(c Cache, req *http.Request) (resp *http.Response, err error) {
cachedVal, ok := c.Get(cacheKey(req))
if !ok {
return
}
b := bytes.NewBuffer(cachedVal)
return http.ReadResponse(bufio.NewReader(b), req)
}
|
[
"func",
"CachedResponse",
"(",
"c",
"Cache",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"resp",
"*",
"http",
".",
"Response",
",",
"err",
"error",
")",
"{",
"cachedVal",
",",
"ok",
":=",
"c",
".",
"Get",
"(",
"cacheKey",
"(",
"req",
")",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n\n",
"b",
":=",
"bytes",
".",
"NewBuffer",
"(",
"cachedVal",
")",
"\n",
"return",
"http",
".",
"ReadResponse",
"(",
"bufio",
".",
"NewReader",
"(",
"b",
")",
",",
"req",
")",
"\n",
"}"
] |
// CachedResponse returns the cached http.Response for req if present, and nil
// otherwise.
|
[
"CachedResponse",
"returns",
"the",
"cached",
"http",
".",
"Response",
"for",
"req",
"if",
"present",
"and",
"nil",
"otherwise",
"."
] |
3befbb6ad0cc97d4c25d851e9528915809e1a22f
|
https://github.com/gregjones/httpcache/blob/3befbb6ad0cc97d4c25d851e9528915809e1a22f/httpcache.go#L52-L60
|
14,221 |
gregjones/httpcache
|
httpcache.go
|
Set
|
func (c *MemoryCache) Set(key string, resp []byte) {
c.mu.Lock()
c.items[key] = resp
c.mu.Unlock()
}
|
go
|
func (c *MemoryCache) Set(key string, resp []byte) {
c.mu.Lock()
c.items[key] = resp
c.mu.Unlock()
}
|
[
"func",
"(",
"c",
"*",
"MemoryCache",
")",
"Set",
"(",
"key",
"string",
",",
"resp",
"[",
"]",
"byte",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"items",
"[",
"key",
"]",
"=",
"resp",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// Set saves response resp to the cache with key
|
[
"Set",
"saves",
"response",
"resp",
"to",
"the",
"cache",
"with",
"key"
] |
3befbb6ad0cc97d4c25d851e9528915809e1a22f
|
https://github.com/gregjones/httpcache/blob/3befbb6ad0cc97d4c25d851e9528915809e1a22f/httpcache.go#L77-L81
|
14,222 |
gregjones/httpcache
|
httpcache.go
|
Delete
|
func (c *MemoryCache) Delete(key string) {
c.mu.Lock()
delete(c.items, key)
c.mu.Unlock()
}
|
go
|
func (c *MemoryCache) Delete(key string) {
c.mu.Lock()
delete(c.items, key)
c.mu.Unlock()
}
|
[
"func",
"(",
"c",
"*",
"MemoryCache",
")",
"Delete",
"(",
"key",
"string",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"c",
".",
"items",
",",
"key",
")",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// Delete removes key from the cache
|
[
"Delete",
"removes",
"key",
"from",
"the",
"cache"
] |
3befbb6ad0cc97d4c25d851e9528915809e1a22f
|
https://github.com/gregjones/httpcache/blob/3befbb6ad0cc97d4c25d851e9528915809e1a22f/httpcache.go#L84-L88
|
14,223 |
gregjones/httpcache
|
httpcache.go
|
varyMatches
|
func varyMatches(cachedResp *http.Response, req *http.Request) bool {
for _, header := range headerAllCommaSepValues(cachedResp.Header, "vary") {
header = http.CanonicalHeaderKey(header)
if header != "" && req.Header.Get(header) != cachedResp.Header.Get("X-Varied-"+header) {
return false
}
}
return true
}
|
go
|
func varyMatches(cachedResp *http.Response, req *http.Request) bool {
for _, header := range headerAllCommaSepValues(cachedResp.Header, "vary") {
header = http.CanonicalHeaderKey(header)
if header != "" && req.Header.Get(header) != cachedResp.Header.Get("X-Varied-"+header) {
return false
}
}
return true
}
|
[
"func",
"varyMatches",
"(",
"cachedResp",
"*",
"http",
".",
"Response",
",",
"req",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"for",
"_",
",",
"header",
":=",
"range",
"headerAllCommaSepValues",
"(",
"cachedResp",
".",
"Header",
",",
"\"",
"\"",
")",
"{",
"header",
"=",
"http",
".",
"CanonicalHeaderKey",
"(",
"header",
")",
"\n",
"if",
"header",
"!=",
"\"",
"\"",
"&&",
"req",
".",
"Header",
".",
"Get",
"(",
"header",
")",
"!=",
"cachedResp",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
"+",
"header",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// varyMatches will return false unless all of the cached values for the headers listed in Vary
// match the new request
|
[
"varyMatches",
"will",
"return",
"false",
"unless",
"all",
"of",
"the",
"cached",
"values",
"for",
"the",
"headers",
"listed",
"in",
"Vary",
"match",
"the",
"new",
"request"
] |
3befbb6ad0cc97d4c25d851e9528915809e1a22f
|
https://github.com/gregjones/httpcache/blob/3befbb6ad0cc97d4c25d851e9528915809e1a22f/httpcache.go#L121-L129
|
14,224 |
gregjones/httpcache
|
httpcache.go
|
Date
|
func Date(respHeaders http.Header) (date time.Time, err error) {
dateHeader := respHeaders.Get("date")
if dateHeader == "" {
err = ErrNoDateHeader
return
}
return time.Parse(time.RFC1123, dateHeader)
}
|
go
|
func Date(respHeaders http.Header) (date time.Time, err error) {
dateHeader := respHeaders.Get("date")
if dateHeader == "" {
err = ErrNoDateHeader
return
}
return time.Parse(time.RFC1123, dateHeader)
}
|
[
"func",
"Date",
"(",
"respHeaders",
"http",
".",
"Header",
")",
"(",
"date",
"time",
".",
"Time",
",",
"err",
"error",
")",
"{",
"dateHeader",
":=",
"respHeaders",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"dateHeader",
"==",
"\"",
"\"",
"{",
"err",
"=",
"ErrNoDateHeader",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123",
",",
"dateHeader",
")",
"\n",
"}"
] |
// Date parses and returns the value of the Date header.
|
[
"Date",
"parses",
"and",
"returns",
"the",
"value",
"of",
"the",
"Date",
"header",
"."
] |
3befbb6ad0cc97d4c25d851e9528915809e1a22f
|
https://github.com/gregjones/httpcache/blob/3befbb6ad0cc97d4c25d851e9528915809e1a22f/httpcache.go#L260-L268
|
14,225 |
gregjones/httpcache
|
leveldbcache/leveldbcache.go
|
New
|
func New(path string) (*Cache, error) {
cache := &Cache{}
var err error
cache.db, err = leveldb.OpenFile(path, nil)
if err != nil {
return nil, err
}
return cache, nil
}
|
go
|
func New(path string) (*Cache, error) {
cache := &Cache{}
var err error
cache.db, err = leveldb.OpenFile(path, nil)
if err != nil {
return nil, err
}
return cache, nil
}
|
[
"func",
"New",
"(",
"path",
"string",
")",
"(",
"*",
"Cache",
",",
"error",
")",
"{",
"cache",
":=",
"&",
"Cache",
"{",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"cache",
".",
"db",
",",
"err",
"=",
"leveldb",
".",
"OpenFile",
"(",
"path",
",",
"nil",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"cache",
",",
"nil",
"\n",
"}"
] |
// New returns a new Cache that will store leveldb in path
|
[
"New",
"returns",
"a",
"new",
"Cache",
"that",
"will",
"store",
"leveldb",
"in",
"path"
] |
3befbb6ad0cc97d4c25d851e9528915809e1a22f
|
https://github.com/gregjones/httpcache/blob/3befbb6ad0cc97d4c25d851e9528915809e1a22f/leveldbcache/leveldbcache.go#L35-L45
|
14,226 |
mattn/go-colorable
|
colorable_windows.go
|
doTitleSequence
|
func doTitleSequence(er *bytes.Reader) error {
var c byte
var err error
c, err = er.ReadByte()
if err != nil {
return err
}
if c != '0' && c != '2' {
return nil
}
c, err = er.ReadByte()
if err != nil {
return err
}
if c != ';' {
return nil
}
title := make([]byte, 0, 80)
for {
c, err = er.ReadByte()
if err != nil {
return err
}
if c == 0x07 || c == '\n' {
break
}
title = append(title, c)
}
if len(title) > 0 {
title8, err := syscall.UTF16PtrFromString(string(title))
if err == nil {
procSetConsoleTitle.Call(uintptr(unsafe.Pointer(title8)))
}
}
return nil
}
|
go
|
func doTitleSequence(er *bytes.Reader) error {
var c byte
var err error
c, err = er.ReadByte()
if err != nil {
return err
}
if c != '0' && c != '2' {
return nil
}
c, err = er.ReadByte()
if err != nil {
return err
}
if c != ';' {
return nil
}
title := make([]byte, 0, 80)
for {
c, err = er.ReadByte()
if err != nil {
return err
}
if c == 0x07 || c == '\n' {
break
}
title = append(title, c)
}
if len(title) > 0 {
title8, err := syscall.UTF16PtrFromString(string(title))
if err == nil {
procSetConsoleTitle.Call(uintptr(unsafe.Pointer(title8)))
}
}
return nil
}
|
[
"func",
"doTitleSequence",
"(",
"er",
"*",
"bytes",
".",
"Reader",
")",
"error",
"{",
"var",
"c",
"byte",
"\n",
"var",
"err",
"error",
"\n\n",
"c",
",",
"err",
"=",
"er",
".",
"ReadByte",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"c",
"!=",
"'0'",
"&&",
"c",
"!=",
"'2'",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"c",
",",
"err",
"=",
"er",
".",
"ReadByte",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"c",
"!=",
"';'",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"title",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"80",
")",
"\n",
"for",
"{",
"c",
",",
"err",
"=",
"er",
".",
"ReadByte",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"c",
"==",
"0x07",
"||",
"c",
"==",
"'\\n'",
"{",
"break",
"\n",
"}",
"\n",
"title",
"=",
"append",
"(",
"title",
",",
"c",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"title",
")",
">",
"0",
"{",
"title8",
",",
"err",
":=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"string",
"(",
"title",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"procSetConsoleTitle",
".",
"Call",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"title8",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// `\033]0;TITLESTR\007`
|
[
"\\",
"033",
"]",
"0",
";",
"TITLESTR",
"\\",
"007"
] |
3a70a971f94a22f2fa562ffcc7a0eb45f5daf045
|
https://github.com/mattn/go-colorable/blob/3a70a971f94a22f2fa562ffcc7a0eb45f5daf045/colorable_windows.go#L379-L415
|
14,227 |
kylelemons/go-gypsy
|
yaml/parser.go
|
Parse
|
func Parse(r io.Reader) (node Node, err error) {
lb := &lineBuffer{
Reader: bufio.NewReader(r),
}
defer func() {
if r := recover(); r != nil {
switch r := r.(type) {
case error:
err = r
case string:
err = errors.New(r)
default:
err = fmt.Errorf("%v", r)
}
}
}()
node = parseNode(lb, 0, nil)
return
}
|
go
|
func Parse(r io.Reader) (node Node, err error) {
lb := &lineBuffer{
Reader: bufio.NewReader(r),
}
defer func() {
if r := recover(); r != nil {
switch r := r.(type) {
case error:
err = r
case string:
err = errors.New(r)
default:
err = fmt.Errorf("%v", r)
}
}
}()
node = parseNode(lb, 0, nil)
return
}
|
[
"func",
"Parse",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"node",
"Node",
",",
"err",
"error",
")",
"{",
"lb",
":=",
"&",
"lineBuffer",
"{",
"Reader",
":",
"bufio",
".",
"NewReader",
"(",
"r",
")",
",",
"}",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"switch",
"r",
":=",
"r",
".",
"(",
"type",
")",
"{",
"case",
"error",
":",
"err",
"=",
"r",
"\n",
"case",
"string",
":",
"err",
"=",
"errors",
".",
"New",
"(",
"r",
")",
"\n",
"default",
":",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"node",
"=",
"parseNode",
"(",
"lb",
",",
"0",
",",
"nil",
")",
"\n",
"return",
"\n",
"}"
] |
// Parse returns a root-level Node parsed from the lines read from r. In
// general, this will be done for you by one of the File constructors.
|
[
"Parse",
"returns",
"a",
"root",
"-",
"level",
"Node",
"parsed",
"from",
"the",
"lines",
"read",
"from",
"r",
".",
"In",
"general",
"this",
"will",
"be",
"done",
"for",
"you",
"by",
"one",
"of",
"the",
"File",
"constructors",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/parser.go#L28-L48
|
14,228 |
kylelemons/go-gypsy
|
yaml/config.go
|
ReadFile
|
func ReadFile(filename string) (*File, error) {
fin, err := os.Open(filename)
if err != nil {
return nil, err
}
defer fin.Close()
f := new(File)
f.Root, err = Parse(fin)
if err != nil {
return nil, err
}
return f, nil
}
|
go
|
func ReadFile(filename string) (*File, error) {
fin, err := os.Open(filename)
if err != nil {
return nil, err
}
defer fin.Close()
f := new(File)
f.Root, err = Parse(fin)
if err != nil {
return nil, err
}
return f, nil
}
|
[
"func",
"ReadFile",
"(",
"filename",
"string",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"fin",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"fin",
".",
"Close",
"(",
")",
"\n\n",
"f",
":=",
"new",
"(",
"File",
")",
"\n",
"f",
".",
"Root",
",",
"err",
"=",
"Parse",
"(",
"fin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"f",
",",
"nil",
"\n",
"}"
] |
// ReadFile reads a YAML configuration file from the given filename.
|
[
"ReadFile",
"reads",
"a",
"YAML",
"configuration",
"file",
"from",
"the",
"given",
"filename",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/config.go#L34-L48
|
14,229 |
kylelemons/go-gypsy
|
yaml/config.go
|
Config
|
func Config(yamlconf string) *File {
var err error
buf := bytes.NewBufferString(yamlconf)
f := new(File)
f.Root, err = Parse(buf)
if err != nil {
panic(err)
}
return f
}
|
go
|
func Config(yamlconf string) *File {
var err error
buf := bytes.NewBufferString(yamlconf)
f := new(File)
f.Root, err = Parse(buf)
if err != nil {
panic(err)
}
return f
}
|
[
"func",
"Config",
"(",
"yamlconf",
"string",
")",
"*",
"File",
"{",
"var",
"err",
"error",
"\n",
"buf",
":=",
"bytes",
".",
"NewBufferString",
"(",
"yamlconf",
")",
"\n\n",
"f",
":=",
"new",
"(",
"File",
")",
"\n",
"f",
".",
"Root",
",",
"err",
"=",
"Parse",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"f",
"\n",
"}"
] |
// Config reads a YAML configuration from a static string. If an error is
// found, it will panic. This is a utility function and is intended for use in
// initializers.
|
[
"Config",
"reads",
"a",
"YAML",
"configuration",
"from",
"a",
"static",
"string",
".",
"If",
"an",
"error",
"is",
"found",
"it",
"will",
"panic",
".",
"This",
"is",
"a",
"utility",
"function",
"and",
"is",
"intended",
"for",
"use",
"in",
"initializers",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/config.go#L53-L64
|
14,230 |
kylelemons/go-gypsy
|
yaml/config.go
|
ConfigFile
|
func ConfigFile(filename string) *File {
f, err := ReadFile(filename)
if err != nil {
panic(err)
}
return f
}
|
go
|
func ConfigFile(filename string) *File {
f, err := ReadFile(filename)
if err != nil {
panic(err)
}
return f
}
|
[
"func",
"ConfigFile",
"(",
"filename",
"string",
")",
"*",
"File",
"{",
"f",
",",
"err",
":=",
"ReadFile",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
] |
// ConfigFile reads a YAML configuration file from the given filename and
// panics if an error is found. This is a utility function and is intended for
// use in initializers.
|
[
"ConfigFile",
"reads",
"a",
"YAML",
"configuration",
"file",
"from",
"the",
"given",
"filename",
"and",
"panics",
"if",
"an",
"error",
"is",
"found",
".",
"This",
"is",
"a",
"utility",
"function",
"and",
"is",
"intended",
"for",
"use",
"in",
"initializers",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/config.go#L69-L75
|
14,231 |
kylelemons/go-gypsy
|
yaml/config.go
|
Get
|
func (f *File) Get(spec string) (string, error) {
node, err := Child(f.Root, spec)
if err != nil {
return "", err
}
if node == nil {
return "", &NodeNotFound{
Full: spec,
Spec: spec,
}
}
scalar, ok := node.(Scalar)
if !ok {
return "", &NodeTypeMismatch{
Full: spec,
Spec: spec,
Token: "$",
Expected: "yaml.Scalar",
Node: node,
}
}
return scalar.String(), nil
}
|
go
|
func (f *File) Get(spec string) (string, error) {
node, err := Child(f.Root, spec)
if err != nil {
return "", err
}
if node == nil {
return "", &NodeNotFound{
Full: spec,
Spec: spec,
}
}
scalar, ok := node.(Scalar)
if !ok {
return "", &NodeTypeMismatch{
Full: spec,
Spec: spec,
Token: "$",
Expected: "yaml.Scalar",
Node: node,
}
}
return scalar.String(), nil
}
|
[
"func",
"(",
"f",
"*",
"File",
")",
"Get",
"(",
"spec",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"node",
",",
"err",
":=",
"Child",
"(",
"f",
".",
"Root",
",",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"node",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"&",
"NodeNotFound",
"{",
"Full",
":",
"spec",
",",
"Spec",
":",
"spec",
",",
"}",
"\n",
"}",
"\n\n",
"scalar",
",",
"ok",
":=",
"node",
".",
"(",
"Scalar",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"&",
"NodeTypeMismatch",
"{",
"Full",
":",
"spec",
",",
"Spec",
":",
"spec",
",",
"Token",
":",
"\"",
"\"",
",",
"Expected",
":",
"\"",
"\"",
",",
"Node",
":",
"node",
",",
"}",
"\n",
"}",
"\n",
"return",
"scalar",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// Get retrieves a scalar from the file specified by a string of the same
// format as that expected by Child. If the final node is not a Scalar, Get
// will return an error.
|
[
"Get",
"retrieves",
"a",
"scalar",
"from",
"the",
"file",
"specified",
"by",
"a",
"string",
"of",
"the",
"same",
"format",
"as",
"that",
"expected",
"by",
"Child",
".",
"If",
"the",
"final",
"node",
"is",
"not",
"a",
"Scalar",
"Get",
"will",
"return",
"an",
"error",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/config.go#L80-L104
|
14,232 |
kylelemons/go-gypsy
|
yaml/config.go
|
Count
|
func (f *File) Count(spec string) (int, error) {
node, err := Child(f.Root, spec)
if err != nil {
return -1, err
}
if node == nil {
return -1, &NodeNotFound{
Full: spec,
Spec: spec,
}
}
lst, ok := node.(List)
if !ok {
return -1, &NodeTypeMismatch{
Full: spec,
Spec: spec,
Token: "$",
Expected: "yaml.List",
Node: node,
}
}
return lst.Len(), nil
}
|
go
|
func (f *File) Count(spec string) (int, error) {
node, err := Child(f.Root, spec)
if err != nil {
return -1, err
}
if node == nil {
return -1, &NodeNotFound{
Full: spec,
Spec: spec,
}
}
lst, ok := node.(List)
if !ok {
return -1, &NodeTypeMismatch{
Full: spec,
Spec: spec,
Token: "$",
Expected: "yaml.List",
Node: node,
}
}
return lst.Len(), nil
}
|
[
"func",
"(",
"f",
"*",
"File",
")",
"Count",
"(",
"spec",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"node",
",",
"err",
":=",
"Child",
"(",
"f",
".",
"Root",
",",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"node",
"==",
"nil",
"{",
"return",
"-",
"1",
",",
"&",
"NodeNotFound",
"{",
"Full",
":",
"spec",
",",
"Spec",
":",
"spec",
",",
"}",
"\n",
"}",
"\n\n",
"lst",
",",
"ok",
":=",
"node",
".",
"(",
"List",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"-",
"1",
",",
"&",
"NodeTypeMismatch",
"{",
"Full",
":",
"spec",
",",
"Spec",
":",
"spec",
",",
"Token",
":",
"\"",
"\"",
",",
"Expected",
":",
"\"",
"\"",
",",
"Node",
":",
"node",
",",
"}",
"\n",
"}",
"\n",
"return",
"lst",
".",
"Len",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// Count retrieves a the number of elements in the specified list from the file
// using the same format as that expected by Child. If the final node is not a
// List, Count will return an error.
|
[
"Count",
"retrieves",
"a",
"the",
"number",
"of",
"elements",
"in",
"the",
"specified",
"list",
"from",
"the",
"file",
"using",
"the",
"same",
"format",
"as",
"that",
"expected",
"by",
"Child",
".",
"If",
"the",
"final",
"node",
"is",
"not",
"a",
"List",
"Count",
"will",
"return",
"an",
"error",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/config.go#L137-L161
|
14,233 |
kylelemons/go-gypsy
|
yaml/config.go
|
Require
|
func (f *File) Require(spec string) string {
str, err := f.Get(spec)
if err != nil {
panic(err)
}
return str
}
|
go
|
func (f *File) Require(spec string) string {
str, err := f.Get(spec)
if err != nil {
panic(err)
}
return str
}
|
[
"func",
"(",
"f",
"*",
"File",
")",
"Require",
"(",
"spec",
"string",
")",
"string",
"{",
"str",
",",
"err",
":=",
"f",
".",
"Get",
"(",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"str",
"\n",
"}"
] |
// Require retrieves a scalar from the file specified by a string of the same
// format as that expected by Child. If the final node is not a Scalar, String
// will panic. This is a convenience function for use in initializers.
|
[
"Require",
"retrieves",
"a",
"scalar",
"from",
"the",
"file",
"specified",
"by",
"a",
"string",
"of",
"the",
"same",
"format",
"as",
"that",
"expected",
"by",
"Child",
".",
"If",
"the",
"final",
"node",
"is",
"not",
"a",
"Scalar",
"String",
"will",
"panic",
".",
"This",
"is",
"a",
"convenience",
"function",
"for",
"use",
"in",
"initializers",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/config.go#L166-L172
|
14,234 |
kylelemons/go-gypsy
|
yaml/types.go
|
Item
|
func (node List) Item(idx int) Node {
if idx >= 0 && idx < len(node) {
return node[idx]
}
return nil
}
|
go
|
func (node List) Item(idx int) Node {
if idx >= 0 && idx < len(node) {
return node[idx]
}
return nil
}
|
[
"func",
"(",
"node",
"List",
")",
"Item",
"(",
"idx",
"int",
")",
"Node",
"{",
"if",
"idx",
">=",
"0",
"&&",
"idx",
"<",
"len",
"(",
"node",
")",
"{",
"return",
"node",
"[",
"idx",
"]",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Get the idx'th item from the List.
|
[
"Get",
"the",
"idx",
"th",
"item",
"from",
"the",
"List",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/types.go#L85-L90
|
14,235 |
kylelemons/go-gypsy
|
yaml/types.go
|
Render
|
func Render(node Node) string {
buf := bytes.NewBuffer(nil)
node.write(buf, 0, 0)
return buf.String()
}
|
go
|
func Render(node Node) string {
buf := bytes.NewBuffer(nil)
node.write(buf, 0, 0)
return buf.String()
}
|
[
"func",
"Render",
"(",
"node",
"Node",
")",
"string",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"node",
".",
"write",
"(",
"buf",
",",
"0",
",",
"0",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] |
// Render returns a string of the node as a YAML document. Note that
// Scalars will have a newline appended if they are rendered directly.
|
[
"Render",
"returns",
"a",
"string",
"of",
"the",
"node",
"as",
"a",
"YAML",
"document",
".",
"Note",
"that",
"Scalars",
"will",
"have",
"a",
"newline",
"appended",
"if",
"they",
"are",
"rendered",
"directly",
"."
] |
08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8
|
https://github.com/kylelemons/go-gypsy/blob/08cad365cd28a7fba23bb1e57aa43c5e18ad8bb8/yaml/types.go#L116-L120
|
14,236 |
zenazn/goji
|
example/main.go
|
NotFound
|
func NotFound(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Umm... have you tried turning it off and on again?", 404)
}
|
go
|
func NotFound(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Umm... have you tried turning it off and on again?", 404)
}
|
[
"func",
"NotFound",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"\"",
"\"",
",",
"404",
")",
"\n",
"}"
] |
// NotFound is a 404 handler.
|
[
"NotFound",
"is",
"a",
"404",
"handler",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/example/main.go#L175-L177
|
14,237 |
zenazn/goji
|
default.go
|
Insert
|
func Insert(middleware, before web.MiddlewareType) error {
return DefaultMux.Insert(middleware, before)
}
|
go
|
func Insert(middleware, before web.MiddlewareType) error {
return DefaultMux.Insert(middleware, before)
}
|
[
"func",
"Insert",
"(",
"middleware",
",",
"before",
"web",
".",
"MiddlewareType",
")",
"error",
"{",
"return",
"DefaultMux",
".",
"Insert",
"(",
"middleware",
",",
"before",
")",
"\n",
"}"
] |
// Insert the given middleware into the default Mux's middleware stack. See the
// documentation for web.Mux.Insert for more information.
|
[
"Insert",
"the",
"given",
"middleware",
"into",
"the",
"default",
"Mux",
"s",
"middleware",
"stack",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
".",
"Insert",
"for",
"more",
"information",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L28-L30
|
14,238 |
zenazn/goji
|
default.go
|
Handle
|
func Handle(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Handle(pattern, handler)
}
|
go
|
func Handle(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Handle(pattern, handler)
}
|
[
"func",
"Handle",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Handle",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Handle adds a route to the default Mux. See the documentation for web.Mux for
// more information about what types this function accepts.
|
[
"Handle",
"adds",
"a",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L40-L42
|
14,239 |
zenazn/goji
|
default.go
|
Connect
|
func Connect(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Connect(pattern, handler)
}
|
go
|
func Connect(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Connect(pattern, handler)
}
|
[
"func",
"Connect",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Connect",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Connect adds a CONNECT route to the default Mux. See the documentation for
// web.Mux for more information about what types this function accepts.
|
[
"Connect",
"adds",
"a",
"CONNECT",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L46-L48
|
14,240 |
zenazn/goji
|
default.go
|
Delete
|
func Delete(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Delete(pattern, handler)
}
|
go
|
func Delete(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Delete(pattern, handler)
}
|
[
"func",
"Delete",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Delete",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Delete adds a DELETE route to the default Mux. See the documentation for
// web.Mux for more information about what types this function accepts.
|
[
"Delete",
"adds",
"a",
"DELETE",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L52-L54
|
14,241 |
zenazn/goji
|
default.go
|
Get
|
func Get(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Get(pattern, handler)
}
|
go
|
func Get(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Get(pattern, handler)
}
|
[
"func",
"Get",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Get",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Get adds a GET route to the default Mux. See the documentation for web.Mux for
// more information about what types this function accepts.
|
[
"Get",
"adds",
"a",
"GET",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L58-L60
|
14,242 |
zenazn/goji
|
default.go
|
Head
|
func Head(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Head(pattern, handler)
}
|
go
|
func Head(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Head(pattern, handler)
}
|
[
"func",
"Head",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Head",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Head adds a HEAD route to the default Mux. See the documentation for web.Mux
// for more information about what types this function accepts.
|
[
"Head",
"adds",
"a",
"HEAD",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L64-L66
|
14,243 |
zenazn/goji
|
default.go
|
Options
|
func Options(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Options(pattern, handler)
}
|
go
|
func Options(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Options(pattern, handler)
}
|
[
"func",
"Options",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Options",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Options adds a OPTIONS route to the default Mux. See the documentation for
// web.Mux for more information about what types this function accepts.
|
[
"Options",
"adds",
"a",
"OPTIONS",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L70-L72
|
14,244 |
zenazn/goji
|
default.go
|
Patch
|
func Patch(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Patch(pattern, handler)
}
|
go
|
func Patch(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Patch(pattern, handler)
}
|
[
"func",
"Patch",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Patch",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Patch adds a PATCH route to the default Mux. See the documentation for web.Mux
// for more information about what types this function accepts.
|
[
"Patch",
"adds",
"a",
"PATCH",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L76-L78
|
14,245 |
zenazn/goji
|
default.go
|
Post
|
func Post(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Post(pattern, handler)
}
|
go
|
func Post(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Post(pattern, handler)
}
|
[
"func",
"Post",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Post",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Post adds a POST route to the default Mux. See the documentation for web.Mux
// for more information about what types this function accepts.
|
[
"Post",
"adds",
"a",
"POST",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L82-L84
|
14,246 |
zenazn/goji
|
default.go
|
Put
|
func Put(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Put(pattern, handler)
}
|
go
|
func Put(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Put(pattern, handler)
}
|
[
"func",
"Put",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Put",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Put adds a PUT route to the default Mux. See the documentation for web.Mux for
// more information about what types this function accepts.
|
[
"Put",
"adds",
"a",
"PUT",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L88-L90
|
14,247 |
zenazn/goji
|
default.go
|
Trace
|
func Trace(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Trace(pattern, handler)
}
|
go
|
func Trace(pattern web.PatternType, handler web.HandlerType) {
DefaultMux.Trace(pattern, handler)
}
|
[
"func",
"Trace",
"(",
"pattern",
"web",
".",
"PatternType",
",",
"handler",
"web",
".",
"HandlerType",
")",
"{",
"DefaultMux",
".",
"Trace",
"(",
"pattern",
",",
"handler",
")",
"\n",
"}"
] |
// Trace adds a TRACE route to the default Mux. See the documentation for
// web.Mux for more information about what types this function accepts.
|
[
"Trace",
"adds",
"a",
"TRACE",
"route",
"to",
"the",
"default",
"Mux",
".",
"See",
"the",
"documentation",
"for",
"web",
".",
"Mux",
"for",
"more",
"information",
"about",
"what",
"types",
"this",
"function",
"accepts",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/default.go#L94-L96
|
14,248 |
zenazn/goji
|
web/middleware/request_id.go
|
GetReqID
|
func GetReqID(c web.C) string {
if c.Env == nil {
return ""
}
v, ok := c.Env[RequestIDKey]
if !ok {
return ""
}
if reqID, ok := v.(string); ok {
return reqID
}
return ""
}
|
go
|
func GetReqID(c web.C) string {
if c.Env == nil {
return ""
}
v, ok := c.Env[RequestIDKey]
if !ok {
return ""
}
if reqID, ok := v.(string); ok {
return reqID
}
return ""
}
|
[
"func",
"GetReqID",
"(",
"c",
"web",
".",
"C",
")",
"string",
"{",
"if",
"c",
".",
"Env",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"v",
",",
"ok",
":=",
"c",
".",
"Env",
"[",
"RequestIDKey",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"reqID",
",",
"ok",
":=",
"v",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"reqID",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] |
// GetReqID returns a request ID from the given context if one is present.
// Returns the empty string if a request ID cannot be found.
|
[
"GetReqID",
"returns",
"a",
"request",
"ID",
"from",
"the",
"given",
"context",
"if",
"one",
"is",
"present",
".",
"Returns",
"the",
"empty",
"string",
"if",
"a",
"request",
"ID",
"cannot",
"be",
"found",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/middleware/request_id.go#L76-L88
|
14,249 |
zenazn/goji
|
web/middleware/options.go
|
AutomaticOptions
|
func AutomaticOptions(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if r.Method == "OPTIONS" {
w = &autoOptionsProxy{c: c, w: w}
}
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
|
go
|
func AutomaticOptions(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if r.Method == "OPTIONS" {
w = &autoOptionsProxy{c: c, w: w}
}
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
|
[
"func",
"AutomaticOptions",
"(",
"c",
"*",
"web",
".",
"C",
",",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"fn",
":=",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"r",
".",
"Method",
"==",
"\"",
"\"",
"{",
"w",
"=",
"&",
"autoOptionsProxy",
"{",
"c",
":",
"c",
",",
"w",
":",
"w",
"}",
"\n",
"}",
"\n\n",
"h",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"}",
"\n\n",
"return",
"http",
".",
"HandlerFunc",
"(",
"fn",
")",
"\n",
"}"
] |
// AutomaticOptions automatically return an appropriate "Allow" header when the
// request method is OPTIONS and the request would have otherwise been 404'd.
|
[
"AutomaticOptions",
"automatically",
"return",
"an",
"appropriate",
"Allow",
"header",
"when",
"the",
"request",
"method",
"is",
"OPTIONS",
"and",
"the",
"request",
"would",
"have",
"otherwise",
"been",
"404",
"d",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/middleware/options.go#L64-L74
|
14,250 |
zenazn/goji
|
web/web.go
|
ServeHTTPC
|
func (h HandlerFunc) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
h(c, w, r)
}
|
go
|
func (h HandlerFunc) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
h(c, w, r)
}
|
[
"func",
"(",
"h",
"HandlerFunc",
")",
"ServeHTTPC",
"(",
"c",
"C",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"h",
"(",
"c",
",",
"w",
",",
"r",
")",
"\n",
"}"
] |
// ServeHTTPC implements Handler.
|
[
"ServeHTTPC",
"implements",
"Handler",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/web.go#L53-L55
|
14,251 |
zenazn/goji
|
web/middleware/urlquery.go
|
URLQuery
|
func URLQuery(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if c.Env == nil {
c.Env = make(map[interface{}]interface{})
}
c.Env[URLQueryKey] = r.URL.Query()
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
|
go
|
func URLQuery(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if c.Env == nil {
c.Env = make(map[interface{}]interface{})
}
c.Env[URLQueryKey] = r.URL.Query()
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
|
[
"func",
"URLQuery",
"(",
"c",
"*",
"web",
".",
"C",
",",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"fn",
":=",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"c",
".",
"Env",
"==",
"nil",
"{",
"c",
".",
"Env",
"=",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"c",
".",
"Env",
"[",
"URLQueryKey",
"]",
"=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
"\n\n",
"h",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"}",
"\n\n",
"return",
"http",
".",
"HandlerFunc",
"(",
"fn",
")",
"\n",
"}"
] |
// URLQuery is a middleware to parse the URL Query parameters just once,
// and store the resulting url.Values in the context.
|
[
"URLQuery",
"is",
"a",
"middleware",
"to",
"parse",
"the",
"URL",
"Query",
"parameters",
"just",
"once",
"and",
"store",
"the",
"resulting",
"url",
".",
"Values",
"in",
"the",
"context",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/middleware/urlquery.go#L13-L24
|
14,252 |
zenazn/goji
|
web/middleware/envinit.go
|
EnvInit
|
func EnvInit(c *web.C, h http.Handler) http.Handler {
return envInit{c, h}
}
|
go
|
func EnvInit(c *web.C, h http.Handler) http.Handler {
return envInit{c, h}
}
|
[
"func",
"EnvInit",
"(",
"c",
"*",
"web",
".",
"C",
",",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"envInit",
"{",
"c",
",",
"h",
"}",
"\n",
"}"
] |
// EnvInit is a middleware that allocates an environment map if it is nil. While
// it's impossible in general to ensure that Env is never nil in a middleware
// stack, in most common cases placing this middleware at the top of the stack
// will eliminate the need for repetative nil checks.
|
[
"EnvInit",
"is",
"a",
"middleware",
"that",
"allocates",
"an",
"environment",
"map",
"if",
"it",
"is",
"nil",
".",
"While",
"it",
"s",
"impossible",
"in",
"general",
"to",
"ensure",
"that",
"Env",
"is",
"never",
"nil",
"in",
"a",
"middleware",
"stack",
"in",
"most",
"common",
"cases",
"placing",
"this",
"middleware",
"at",
"the",
"top",
"of",
"the",
"stack",
"will",
"eliminate",
"the",
"need",
"for",
"repetative",
"nil",
"checks",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/middleware/envinit.go#L25-L27
|
14,253 |
zenazn/goji
|
example/middleware.go
|
SuperSecure
|
func SuperSecure(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
auth := r.Header.Get("Authorization")
if !strings.HasPrefix(auth, "Basic ") {
pleaseAuth(w)
return
}
password, err := base64.StdEncoding.DecodeString(auth[6:])
if err != nil || string(password) != Password {
pleaseAuth(w)
return
}
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
|
go
|
func SuperSecure(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
auth := r.Header.Get("Authorization")
if !strings.HasPrefix(auth, "Basic ") {
pleaseAuth(w)
return
}
password, err := base64.StdEncoding.DecodeString(auth[6:])
if err != nil || string(password) != Password {
pleaseAuth(w)
return
}
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
|
[
"func",
"SuperSecure",
"(",
"c",
"*",
"web",
".",
"C",
",",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"fn",
":=",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"auth",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"auth",
",",
"\"",
"\"",
")",
"{",
"pleaseAuth",
"(",
"w",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"password",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"auth",
"[",
"6",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"string",
"(",
"password",
")",
"!=",
"Password",
"{",
"pleaseAuth",
"(",
"w",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"h",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"}",
"\n",
"return",
"http",
".",
"HandlerFunc",
"(",
"fn",
")",
"\n",
"}"
] |
// SuperSecure is HTTP Basic Auth middleware for super-secret admin page. Shhhh!
|
[
"SuperSecure",
"is",
"HTTP",
"Basic",
"Auth",
"middleware",
"for",
"super",
"-",
"secret",
"admin",
"page",
".",
"Shhhh!"
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/example/middleware.go#L24-L41
|
14,254 |
zenazn/goji
|
bind/bind.go
|
Sniff
|
func Sniff() string {
if bind := os.Getenv("GOJI_BIND"); bind != "" {
return bind
} else if usingEinhorn() {
return "einhorn@0"
} else if usingSystemd() {
return "fd@3"
} else if port := os.Getenv("PORT"); port != "" {
return ":" + port
}
return ""
}
|
go
|
func Sniff() string {
if bind := os.Getenv("GOJI_BIND"); bind != "" {
return bind
} else if usingEinhorn() {
return "einhorn@0"
} else if usingSystemd() {
return "fd@3"
} else if port := os.Getenv("PORT"); port != "" {
return ":" + port
}
return ""
}
|
[
"func",
"Sniff",
"(",
")",
"string",
"{",
"if",
"bind",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
";",
"bind",
"!=",
"\"",
"\"",
"{",
"return",
"bind",
"\n",
"}",
"else",
"if",
"usingEinhorn",
"(",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"else",
"if",
"usingSystemd",
"(",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"else",
"if",
"port",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
";",
"port",
"!=",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"+",
"port",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] |
// Sniff attempts to select a sensible default bind string by examining its
// environment. It examines the GOJI_BIND environment variable, Einhorn,
// systemd, and the PORT environment variable, in that order, selecting the
// first plausible option. It returns the empty string if no sensible default
// could be extracted from the environment.
|
[
"Sniff",
"attempts",
"to",
"select",
"a",
"sensible",
"default",
"bind",
"string",
"by",
"examining",
"its",
"environment",
".",
"It",
"examines",
"the",
"GOJI_BIND",
"environment",
"variable",
"Einhorn",
"systemd",
"and",
"the",
"PORT",
"environment",
"variable",
"in",
"that",
"order",
"selecting",
"the",
"first",
"plausible",
"option",
".",
"It",
"returns",
"the",
"empty",
"string",
"if",
"no",
"sensible",
"default",
"could",
"be",
"extracted",
"from",
"the",
"environment",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/bind/bind.go#L86-L97
|
14,255 |
zenazn/goji
|
bind/bind.go
|
Socket
|
func Socket(bind string) net.Listener {
l, err := listenTo(bind)
if err != nil {
log.Fatal(err)
}
return l
}
|
go
|
func Socket(bind string) net.Listener {
l, err := listenTo(bind)
if err != nil {
log.Fatal(err)
}
return l
}
|
[
"func",
"Socket",
"(",
"bind",
"string",
")",
"net",
".",
"Listener",
"{",
"l",
",",
"err",
":=",
"listenTo",
"(",
"bind",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"l",
"\n",
"}"
] |
// Socket parses and binds to the specified address. If Socket encounters an
// error while parsing or binding to the given socket it will exit by calling
// log.Fatal.
|
[
"Socket",
"parses",
"and",
"binds",
"to",
"the",
"specified",
"address",
".",
"If",
"Socket",
"encounters",
"an",
"error",
"while",
"parsing",
"or",
"binding",
"to",
"the",
"given",
"socket",
"it",
"will",
"exit",
"by",
"calling",
"log",
".",
"Fatal",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/bind/bind.go#L128-L134
|
14,256 |
zenazn/goji
|
web/mutil/writer_proxy.go
|
WrapWriter
|
func WrapWriter(w http.ResponseWriter) WriterProxy {
_, cn := w.(http.CloseNotifier)
_, fl := w.(http.Flusher)
_, hj := w.(http.Hijacker)
_, rf := w.(io.ReaderFrom)
bw := basicWriter{ResponseWriter: w}
if cn && fl && hj && rf {
return &fancyWriter{bw}
}
if fl {
return &flushWriter{bw}
}
return &bw
}
|
go
|
func WrapWriter(w http.ResponseWriter) WriterProxy {
_, cn := w.(http.CloseNotifier)
_, fl := w.(http.Flusher)
_, hj := w.(http.Hijacker)
_, rf := w.(io.ReaderFrom)
bw := basicWriter{ResponseWriter: w}
if cn && fl && hj && rf {
return &fancyWriter{bw}
}
if fl {
return &flushWriter{bw}
}
return &bw
}
|
[
"func",
"WrapWriter",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"WriterProxy",
"{",
"_",
",",
"cn",
":=",
"w",
".",
"(",
"http",
".",
"CloseNotifier",
")",
"\n",
"_",
",",
"fl",
":=",
"w",
".",
"(",
"http",
".",
"Flusher",
")",
"\n",
"_",
",",
"hj",
":=",
"w",
".",
"(",
"http",
".",
"Hijacker",
")",
"\n",
"_",
",",
"rf",
":=",
"w",
".",
"(",
"io",
".",
"ReaderFrom",
")",
"\n\n",
"bw",
":=",
"basicWriter",
"{",
"ResponseWriter",
":",
"w",
"}",
"\n",
"if",
"cn",
"&&",
"fl",
"&&",
"hj",
"&&",
"rf",
"{",
"return",
"&",
"fancyWriter",
"{",
"bw",
"}",
"\n",
"}",
"\n",
"if",
"fl",
"{",
"return",
"&",
"flushWriter",
"{",
"bw",
"}",
"\n",
"}",
"\n",
"return",
"&",
"bw",
"\n",
"}"
] |
// WrapWriter wraps an http.ResponseWriter, returning a proxy that allows you to
// hook into various parts of the response process.
|
[
"WrapWriter",
"wraps",
"an",
"http",
".",
"ResponseWriter",
"returning",
"a",
"proxy",
"that",
"allows",
"you",
"to",
"hook",
"into",
"various",
"parts",
"of",
"the",
"response",
"process",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mutil/writer_proxy.go#L32-L46
|
14,257 |
zenazn/goji
|
graceful/listener/listener.go
|
Accept
|
func (t *T) Accept() (net.Conn, error) {
c, err := t.l.Accept()
if err != nil {
return nil, err
}
connID := atomic.AddUint64(&t.connCount, 1)
shard := &t.shards[int(connID)%len(t.shards)]
wc := &conn{
Conn: c,
shard: shard,
mode: t.mode,
}
if err = wc.init(); err != nil {
return nil, err
}
return wc, nil
}
|
go
|
func (t *T) Accept() (net.Conn, error) {
c, err := t.l.Accept()
if err != nil {
return nil, err
}
connID := atomic.AddUint64(&t.connCount, 1)
shard := &t.shards[int(connID)%len(t.shards)]
wc := &conn{
Conn: c,
shard: shard,
mode: t.mode,
}
if err = wc.init(); err != nil {
return nil, err
}
return wc, nil
}
|
[
"func",
"(",
"t",
"*",
"T",
")",
"Accept",
"(",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"t",
".",
"l",
".",
"Accept",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"connID",
":=",
"atomic",
".",
"AddUint64",
"(",
"&",
"t",
".",
"connCount",
",",
"1",
")",
"\n",
"shard",
":=",
"&",
"t",
".",
"shards",
"[",
"int",
"(",
"connID",
")",
"%",
"len",
"(",
"t",
".",
"shards",
")",
"]",
"\n",
"wc",
":=",
"&",
"conn",
"{",
"Conn",
":",
"c",
",",
"shard",
":",
"shard",
",",
"mode",
":",
"t",
".",
"mode",
",",
"}",
"\n\n",
"if",
"err",
"=",
"wc",
".",
"init",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"wc",
",",
"nil",
"\n",
"}"
] |
// Accept waits for and returns the next connection to the listener. The
// returned net.Conn's idleness is tracked, and idle connections can be closed
// from the associated T.
|
[
"Accept",
"waits",
"for",
"and",
"returns",
"the",
"next",
"connection",
"to",
"the",
"listener",
".",
"The",
"returned",
"net",
".",
"Conn",
"s",
"idleness",
"is",
"tracked",
"and",
"idle",
"connections",
"can",
"be",
"closed",
"from",
"the",
"associated",
"T",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/graceful/listener/listener.go#L74-L92
|
14,258 |
zenazn/goji
|
graceful/listener/listener.go
|
CloseIdle
|
func (t *T) CloseIdle() error {
for i := range t.shards {
t.shards[i].closeConns(false, false)
}
// Not sure if returning errors is actually useful here :/
return nil
}
|
go
|
func (t *T) CloseIdle() error {
for i := range t.shards {
t.shards[i].closeConns(false, false)
}
// Not sure if returning errors is actually useful here :/
return nil
}
|
[
"func",
"(",
"t",
"*",
"T",
")",
"CloseIdle",
"(",
")",
"error",
"{",
"for",
"i",
":=",
"range",
"t",
".",
"shards",
"{",
"t",
".",
"shards",
"[",
"i",
"]",
".",
"closeConns",
"(",
"false",
",",
"false",
")",
"\n",
"}",
"\n",
"// Not sure if returning errors is actually useful here :/",
"return",
"nil",
"\n",
"}"
] |
// CloseIdle closes all connections that are currently marked as being idle. It,
// however, makes no attempt to wait for in-use connections to die, or to close
// connections which become idle in the future. Call this function if you're
// interested in shedding useless connections, but otherwise wish to continue
// serving requests.
|
[
"CloseIdle",
"closes",
"all",
"connections",
"that",
"are",
"currently",
"marked",
"as",
"being",
"idle",
".",
"It",
"however",
"makes",
"no",
"attempt",
"to",
"wait",
"for",
"in",
"-",
"use",
"connections",
"to",
"die",
"or",
"to",
"close",
"connections",
"which",
"become",
"idle",
"in",
"the",
"future",
".",
"Call",
"this",
"function",
"if",
"you",
"re",
"interested",
"in",
"shedding",
"useless",
"connections",
"but",
"otherwise",
"wish",
"to",
"continue",
"serving",
"requests",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/graceful/listener/listener.go#L109-L115
|
14,259 |
zenazn/goji
|
graceful/listener/listener.go
|
Drain
|
func (t *T) Drain() error {
for i := range t.shards {
t.shards[i].closeConns(false, true)
}
for i := range t.shards {
t.shards[i].wait()
}
return nil
}
|
go
|
func (t *T) Drain() error {
for i := range t.shards {
t.shards[i].closeConns(false, true)
}
for i := range t.shards {
t.shards[i].wait()
}
return nil
}
|
[
"func",
"(",
"t",
"*",
"T",
")",
"Drain",
"(",
")",
"error",
"{",
"for",
"i",
":=",
"range",
"t",
".",
"shards",
"{",
"t",
".",
"shards",
"[",
"i",
"]",
".",
"closeConns",
"(",
"false",
",",
"true",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"t",
".",
"shards",
"{",
"t",
".",
"shards",
"[",
"i",
"]",
".",
"wait",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Drain immediately closes all idle connections, prevents new connections from
// being accepted, and waits for all outstanding connections to finish.
//
// Once a listener has been drained, there is no way to re-enable it. You
// probably want to Close the listener before draining it, otherwise new
// connections will be accepted and immediately closed.
|
[
"Drain",
"immediately",
"closes",
"all",
"idle",
"connections",
"prevents",
"new",
"connections",
"from",
"being",
"accepted",
"and",
"waits",
"for",
"all",
"outstanding",
"connections",
"to",
"finish",
".",
"Once",
"a",
"listener",
"has",
"been",
"drained",
"there",
"is",
"no",
"way",
"to",
"re",
"-",
"enable",
"it",
".",
"You",
"probably",
"want",
"to",
"Close",
"the",
"listener",
"before",
"draining",
"it",
"otherwise",
"new",
"connections",
"will",
"be",
"accepted",
"and",
"immediately",
"closed",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/graceful/listener/listener.go#L123-L131
|
14,260 |
zenazn/goji
|
graceful/listener/listener.go
|
Disown
|
func Disown(c net.Conn) error {
if cn, ok := c.(*conn); ok {
return cn.disown()
}
return errNotManaged
}
|
go
|
func Disown(c net.Conn) error {
if cn, ok := c.(*conn); ok {
return cn.disown()
}
return errNotManaged
}
|
[
"func",
"Disown",
"(",
"c",
"net",
".",
"Conn",
")",
"error",
"{",
"if",
"cn",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"conn",
")",
";",
"ok",
"{",
"return",
"cn",
".",
"disown",
"(",
")",
"\n",
"}",
"\n",
"return",
"errNotManaged",
"\n",
"}"
] |
// Disown causes a connection to no longer be tracked by the listener. The
// passed connection must have been returned by a call to Accept from this
// listener.
|
[
"Disown",
"causes",
"a",
"connection",
"to",
"no",
"longer",
"be",
"tracked",
"by",
"the",
"listener",
".",
"The",
"passed",
"connection",
"must",
"have",
"been",
"returned",
"by",
"a",
"call",
"to",
"Accept",
"from",
"this",
"listener",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/graceful/listener/listener.go#L151-L156
|
14,261 |
zenazn/goji
|
graceful/listener/listener.go
|
MarkIdle
|
func MarkIdle(c net.Conn) error {
if cn, ok := c.(*conn); ok {
cn.markIdle()
return nil
}
return errNotManaged
}
|
go
|
func MarkIdle(c net.Conn) error {
if cn, ok := c.(*conn); ok {
cn.markIdle()
return nil
}
return errNotManaged
}
|
[
"func",
"MarkIdle",
"(",
"c",
"net",
".",
"Conn",
")",
"error",
"{",
"if",
"cn",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"conn",
")",
";",
"ok",
"{",
"cn",
".",
"markIdle",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errNotManaged",
"\n",
"}"
] |
// MarkIdle marks the given connection as being idle, and therefore eligible for
// closing at any time. The passed connection must have been returned by a call
// to Accept from this listener.
|
[
"MarkIdle",
"marks",
"the",
"given",
"connection",
"as",
"being",
"idle",
"and",
"therefore",
"eligible",
"for",
"closing",
"at",
"any",
"time",
".",
"The",
"passed",
"connection",
"must",
"have",
"been",
"returned",
"by",
"a",
"call",
"to",
"Accept",
"from",
"this",
"listener",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/graceful/listener/listener.go#L161-L167
|
14,262 |
zenazn/goji
|
graceful/listener/listener.go
|
MarkInUse
|
func MarkInUse(c net.Conn) error {
if cn, ok := c.(*conn); ok {
cn.markInUse()
return nil
}
return errNotManaged
}
|
go
|
func MarkInUse(c net.Conn) error {
if cn, ok := c.(*conn); ok {
cn.markInUse()
return nil
}
return errNotManaged
}
|
[
"func",
"MarkInUse",
"(",
"c",
"net",
".",
"Conn",
")",
"error",
"{",
"if",
"cn",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"conn",
")",
";",
"ok",
"{",
"cn",
".",
"markInUse",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errNotManaged",
"\n",
"}"
] |
// MarkInUse marks this connection as being in use, removing it from the set of
// connections which are eligible for closing. The passed connection must have
// been returned by a call to Accept from this listener.
|
[
"MarkInUse",
"marks",
"this",
"connection",
"as",
"being",
"in",
"use",
"removing",
"it",
"from",
"the",
"set",
"of",
"connections",
"which",
"are",
"eligible",
"for",
"closing",
".",
"The",
"passed",
"connection",
"must",
"have",
"been",
"returned",
"by",
"a",
"call",
"to",
"Accept",
"from",
"this",
"listener",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/graceful/listener/listener.go#L172-L178
|
14,263 |
zenazn/goji
|
graceful/graceful.go
|
peacefulError
|
func peacefulError(err error) error {
if atomic.LoadInt32(&closing) == 0 {
return err
}
// Unfortunately Go doesn't really give us a better way to select errors
// than this, so *shrug*.
if oe, ok := err.(*net.OpError); ok {
switch oe.Op {
// backward compatibility: older golang returns AcceptEx on Windows.
// Current golang returns "accept" consistently. It's platform independent.
// See https://github.com/golang/go/commit/b0f4ee533a875c258ac1030ee382f0ffe2de304b
case "AcceptEx":
fallthrough
case "accept":
if oe.Err.Error() == errClosing {
return nil
}
}
}
return err
}
|
go
|
func peacefulError(err error) error {
if atomic.LoadInt32(&closing) == 0 {
return err
}
// Unfortunately Go doesn't really give us a better way to select errors
// than this, so *shrug*.
if oe, ok := err.(*net.OpError); ok {
switch oe.Op {
// backward compatibility: older golang returns AcceptEx on Windows.
// Current golang returns "accept" consistently. It's platform independent.
// See https://github.com/golang/go/commit/b0f4ee533a875c258ac1030ee382f0ffe2de304b
case "AcceptEx":
fallthrough
case "accept":
if oe.Err.Error() == errClosing {
return nil
}
}
}
return err
}
|
[
"func",
"peacefulError",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"atomic",
".",
"LoadInt32",
"(",
"&",
"closing",
")",
"==",
"0",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Unfortunately Go doesn't really give us a better way to select errors",
"// than this, so *shrug*.",
"if",
"oe",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"net",
".",
"OpError",
")",
";",
"ok",
"{",
"switch",
"oe",
".",
"Op",
"{",
"// backward compatibility: older golang returns AcceptEx on Windows.",
"// Current golang returns \"accept\" consistently. It's platform independent.",
"// See https://github.com/golang/go/commit/b0f4ee533a875c258ac1030ee382f0ffe2de304b",
"case",
"\"",
"\"",
":",
"fallthrough",
"\n",
"case",
"\"",
"\"",
":",
"if",
"oe",
".",
"Err",
".",
"Error",
"(",
")",
"==",
"errClosing",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// During graceful shutdown, calls to Accept will start returning errors. This
// is inconvenient, since we know these sorts of errors are peaceful, so we
// silently swallow them.
|
[
"During",
"graceful",
"shutdown",
"calls",
"to",
"Accept",
"will",
"start",
"returning",
"errors",
".",
"This",
"is",
"inconvenient",
"since",
"we",
"know",
"these",
"sorts",
"of",
"errors",
"are",
"peaceful",
"so",
"we",
"silently",
"swallow",
"them",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/graceful/graceful.go#L45-L65
|
14,264 |
zenazn/goji
|
example/models.go
|
Write
|
func (g Greet) Write(w io.Writer) {
fmt.Fprintf(w, "%s\n@%s at %s\n---\n", g.Message, g.User,
g.Time.Format(time.UnixDate))
}
|
go
|
func (g Greet) Write(w io.Writer) {
fmt.Fprintf(w, "%s\n@%s at %s\n---\n", g.Message, g.User,
g.Time.Format(time.UnixDate))
}
|
[
"func",
"(",
"g",
"Greet",
")",
"Write",
"(",
"w",
"io",
".",
"Writer",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"g",
".",
"Message",
",",
"g",
".",
"User",
",",
"g",
".",
"Time",
".",
"Format",
"(",
"time",
".",
"UnixDate",
")",
")",
"\n",
"}"
] |
// Write out a representation of the greet
|
[
"Write",
"out",
"a",
"representation",
"of",
"the",
"greet"
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/example/models.go#L28-L31
|
14,265 |
zenazn/goji
|
example/models.go
|
Write
|
func (u User) Write(w io.Writer, handle string) {
fmt.Fprintf(w, "%s (@%s)\n%s\n", u.Name, handle, u.Bio)
}
|
go
|
func (u User) Write(w io.Writer, handle string) {
fmt.Fprintf(w, "%s (@%s)\n%s\n", u.Name, handle, u.Bio)
}
|
[
"func",
"(",
"u",
"User",
")",
"Write",
"(",
"w",
"io",
".",
"Writer",
",",
"handle",
"string",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"u",
".",
"Name",
",",
"handle",
",",
"u",
".",
"Bio",
")",
"\n",
"}"
] |
// Write out the user
|
[
"Write",
"out",
"the",
"user"
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/example/models.go#L47-L49
|
14,266 |
zenazn/goji
|
web/mux.go
|
New
|
func New() *Mux {
mux := Mux{
ms: mStack{
stack: make([]mLayer, 0),
pool: makeCPool(),
},
rt: router{
routes: make([]route, 0),
notFound: parseHandler(http.NotFound),
},
}
mux.ms.router = &mux.rt
return &mux
}
|
go
|
func New() *Mux {
mux := Mux{
ms: mStack{
stack: make([]mLayer, 0),
pool: makeCPool(),
},
rt: router{
routes: make([]route, 0),
notFound: parseHandler(http.NotFound),
},
}
mux.ms.router = &mux.rt
return &mux
}
|
[
"func",
"New",
"(",
")",
"*",
"Mux",
"{",
"mux",
":=",
"Mux",
"{",
"ms",
":",
"mStack",
"{",
"stack",
":",
"make",
"(",
"[",
"]",
"mLayer",
",",
"0",
")",
",",
"pool",
":",
"makeCPool",
"(",
")",
",",
"}",
",",
"rt",
":",
"router",
"{",
"routes",
":",
"make",
"(",
"[",
"]",
"route",
",",
"0",
")",
",",
"notFound",
":",
"parseHandler",
"(",
"http",
".",
"NotFound",
")",
",",
"}",
",",
"}",
"\n",
"mux",
".",
"ms",
".",
"router",
"=",
"&",
"mux",
".",
"rt",
"\n",
"return",
"&",
"mux",
"\n",
"}"
] |
// New creates a new Mux without any routes or middleware.
|
[
"New",
"creates",
"a",
"new",
"Mux",
"without",
"any",
"routes",
"or",
"middleware",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L27-L40
|
14,267 |
zenazn/goji
|
web/mux.go
|
ServeHTTPC
|
func (m *Mux) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
stack := m.ms.alloc()
stack.ServeHTTPC(c, w, r)
m.ms.release(stack)
}
|
go
|
func (m *Mux) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
stack := m.ms.alloc()
stack.ServeHTTPC(c, w, r)
m.ms.release(stack)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"ServeHTTPC",
"(",
"c",
"C",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"stack",
":=",
"m",
".",
"ms",
".",
"alloc",
"(",
")",
"\n",
"stack",
".",
"ServeHTTPC",
"(",
"c",
",",
"w",
",",
"r",
")",
"\n",
"m",
".",
"ms",
".",
"release",
"(",
"stack",
")",
"\n",
"}"
] |
// ServeHTTPC creates a context dependent request with the given Mux. Satisfies
// the Handler interface.
|
[
"ServeHTTPC",
"creates",
"a",
"context",
"dependent",
"request",
"with",
"the",
"given",
"Mux",
".",
"Satisfies",
"the",
"Handler",
"interface",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L51-L55
|
14,268 |
zenazn/goji
|
web/mux.go
|
Connect
|
func (m *Mux) Connect(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mCONNECT, handler)
}
|
go
|
func (m *Mux) Connect(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mCONNECT, handler)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"Connect",
"(",
"pattern",
"PatternType",
",",
"handler",
"HandlerType",
")",
"{",
"m",
".",
"rt",
".",
"handleUntyped",
"(",
"pattern",
",",
"mCONNECT",
",",
"handler",
")",
"\n",
"}"
] |
// Connect dispatches to the given handler when the pattern matches and the HTTP
// method is CONNECT.
|
[
"Connect",
"dispatches",
"to",
"the",
"given",
"handler",
"when",
"the",
"pattern",
"matches",
"and",
"the",
"HTTP",
"method",
"is",
"CONNECT",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L140-L142
|
14,269 |
zenazn/goji
|
web/mux.go
|
Delete
|
func (m *Mux) Delete(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mDELETE, handler)
}
|
go
|
func (m *Mux) Delete(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mDELETE, handler)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"Delete",
"(",
"pattern",
"PatternType",
",",
"handler",
"HandlerType",
")",
"{",
"m",
".",
"rt",
".",
"handleUntyped",
"(",
"pattern",
",",
"mDELETE",
",",
"handler",
")",
"\n",
"}"
] |
// Delete dispatches to the given handler when the pattern matches and the HTTP
// method is DELETE.
|
[
"Delete",
"dispatches",
"to",
"the",
"given",
"handler",
"when",
"the",
"pattern",
"matches",
"and",
"the",
"HTTP",
"method",
"is",
"DELETE",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L146-L148
|
14,270 |
zenazn/goji
|
web/mux.go
|
Head
|
func (m *Mux) Head(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mHEAD, handler)
}
|
go
|
func (m *Mux) Head(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mHEAD, handler)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"Head",
"(",
"pattern",
"PatternType",
",",
"handler",
"HandlerType",
")",
"{",
"m",
".",
"rt",
".",
"handleUntyped",
"(",
"pattern",
",",
"mHEAD",
",",
"handler",
")",
"\n",
"}"
] |
// Head dispatches to the given handler when the pattern matches and the HTTP
// method is HEAD.
|
[
"Head",
"dispatches",
"to",
"the",
"given",
"handler",
"when",
"the",
"pattern",
"matches",
"and",
"the",
"HTTP",
"method",
"is",
"HEAD",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L163-L165
|
14,271 |
zenazn/goji
|
web/mux.go
|
Options
|
func (m *Mux) Options(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mOPTIONS, handler)
}
|
go
|
func (m *Mux) Options(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mOPTIONS, handler)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"Options",
"(",
"pattern",
"PatternType",
",",
"handler",
"HandlerType",
")",
"{",
"m",
".",
"rt",
".",
"handleUntyped",
"(",
"pattern",
",",
"mOPTIONS",
",",
"handler",
")",
"\n",
"}"
] |
// Options dispatches to the given handler when the pattern matches and the HTTP
// method is OPTIONS.
|
[
"Options",
"dispatches",
"to",
"the",
"given",
"handler",
"when",
"the",
"pattern",
"matches",
"and",
"the",
"HTTP",
"method",
"is",
"OPTIONS",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L169-L171
|
14,272 |
zenazn/goji
|
web/mux.go
|
Patch
|
func (m *Mux) Patch(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPATCH, handler)
}
|
go
|
func (m *Mux) Patch(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPATCH, handler)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"Patch",
"(",
"pattern",
"PatternType",
",",
"handler",
"HandlerType",
")",
"{",
"m",
".",
"rt",
".",
"handleUntyped",
"(",
"pattern",
",",
"mPATCH",
",",
"handler",
")",
"\n",
"}"
] |
// Patch dispatches to the given handler when the pattern matches and the HTTP
// method is PATCH.
|
[
"Patch",
"dispatches",
"to",
"the",
"given",
"handler",
"when",
"the",
"pattern",
"matches",
"and",
"the",
"HTTP",
"method",
"is",
"PATCH",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L175-L177
|
14,273 |
zenazn/goji
|
web/mux.go
|
Post
|
func (m *Mux) Post(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPOST, handler)
}
|
go
|
func (m *Mux) Post(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPOST, handler)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"Post",
"(",
"pattern",
"PatternType",
",",
"handler",
"HandlerType",
")",
"{",
"m",
".",
"rt",
".",
"handleUntyped",
"(",
"pattern",
",",
"mPOST",
",",
"handler",
")",
"\n",
"}"
] |
// Post dispatches to the given handler when the pattern matches and the HTTP
// method is POST.
|
[
"Post",
"dispatches",
"to",
"the",
"given",
"handler",
"when",
"the",
"pattern",
"matches",
"and",
"the",
"HTTP",
"method",
"is",
"POST",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L181-L183
|
14,274 |
zenazn/goji
|
web/mux.go
|
Put
|
func (m *Mux) Put(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPUT, handler)
}
|
go
|
func (m *Mux) Put(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mPUT, handler)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"Put",
"(",
"pattern",
"PatternType",
",",
"handler",
"HandlerType",
")",
"{",
"m",
".",
"rt",
".",
"handleUntyped",
"(",
"pattern",
",",
"mPUT",
",",
"handler",
")",
"\n",
"}"
] |
// Put dispatches to the given handler when the pattern matches and the HTTP
// method is PUT.
|
[
"Put",
"dispatches",
"to",
"the",
"given",
"handler",
"when",
"the",
"pattern",
"matches",
"and",
"the",
"HTTP",
"method",
"is",
"PUT",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L187-L189
|
14,275 |
zenazn/goji
|
web/mux.go
|
Trace
|
func (m *Mux) Trace(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mTRACE, handler)
}
|
go
|
func (m *Mux) Trace(pattern PatternType, handler HandlerType) {
m.rt.handleUntyped(pattern, mTRACE, handler)
}
|
[
"func",
"(",
"m",
"*",
"Mux",
")",
"Trace",
"(",
"pattern",
"PatternType",
",",
"handler",
"HandlerType",
")",
"{",
"m",
".",
"rt",
".",
"handleUntyped",
"(",
"pattern",
",",
"mTRACE",
",",
"handler",
")",
"\n",
"}"
] |
// Trace dispatches to the given handler when the pattern matches and the HTTP
// method is TRACE.
|
[
"Trace",
"dispatches",
"to",
"the",
"given",
"handler",
"when",
"the",
"pattern",
"matches",
"and",
"the",
"HTTP",
"method",
"is",
"TRACE",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/web/mux.go#L193-L195
|
14,276 |
zenazn/goji
|
serve.go
|
ServeTLS
|
func ServeTLS(config *tls.Config) {
if !flag.Parsed() {
flag.Parse()
}
ServeListener(tls.NewListener(bind.Default(), config))
}
|
go
|
func ServeTLS(config *tls.Config) {
if !flag.Parsed() {
flag.Parse()
}
ServeListener(tls.NewListener(bind.Default(), config))
}
|
[
"func",
"ServeTLS",
"(",
"config",
"*",
"tls",
".",
"Config",
")",
"{",
"if",
"!",
"flag",
".",
"Parsed",
"(",
")",
"{",
"flag",
".",
"Parse",
"(",
")",
"\n",
"}",
"\n\n",
"ServeListener",
"(",
"tls",
".",
"NewListener",
"(",
"bind",
".",
"Default",
"(",
")",
",",
"config",
")",
")",
"\n",
"}"
] |
// Like Serve, but enables TLS using the given config.
|
[
"Like",
"Serve",
"but",
"enables",
"TLS",
"using",
"the",
"given",
"config",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/serve.go#L35-L41
|
14,277 |
zenazn/goji
|
serve.go
|
ServeListener
|
func ServeListener(listener net.Listener) {
DefaultMux.Compile()
// Install our handler at the root of the standard net/http default mux.
// This allows packages like expvar to continue working as expected.
http.Handle("/", DefaultMux)
log.Println("Starting Goji on", listener.Addr())
graceful.HandleSignals()
bind.Ready()
graceful.PreHook(func() { log.Printf("Goji received signal, gracefully stopping") })
graceful.PostHook(func() { log.Printf("Goji stopped") })
err := graceful.Serve(listener, http.DefaultServeMux)
if err != nil {
log.Fatal(err)
}
graceful.Wait()
}
|
go
|
func ServeListener(listener net.Listener) {
DefaultMux.Compile()
// Install our handler at the root of the standard net/http default mux.
// This allows packages like expvar to continue working as expected.
http.Handle("/", DefaultMux)
log.Println("Starting Goji on", listener.Addr())
graceful.HandleSignals()
bind.Ready()
graceful.PreHook(func() { log.Printf("Goji received signal, gracefully stopping") })
graceful.PostHook(func() { log.Printf("Goji stopped") })
err := graceful.Serve(listener, http.DefaultServeMux)
if err != nil {
log.Fatal(err)
}
graceful.Wait()
}
|
[
"func",
"ServeListener",
"(",
"listener",
"net",
".",
"Listener",
")",
"{",
"DefaultMux",
".",
"Compile",
"(",
")",
"\n",
"// Install our handler at the root of the standard net/http default mux.",
"// This allows packages like expvar to continue working as expected.",
"http",
".",
"Handle",
"(",
"\"",
"\"",
",",
"DefaultMux",
")",
"\n\n",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"listener",
".",
"Addr",
"(",
")",
")",
"\n\n",
"graceful",
".",
"HandleSignals",
"(",
")",
"\n",
"bind",
".",
"Ready",
"(",
")",
"\n",
"graceful",
".",
"PreHook",
"(",
"func",
"(",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"}",
")",
"\n",
"graceful",
".",
"PostHook",
"(",
"func",
"(",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"}",
")",
"\n\n",
"err",
":=",
"graceful",
".",
"Serve",
"(",
"listener",
",",
"http",
".",
"DefaultServeMux",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"graceful",
".",
"Wait",
"(",
")",
"\n",
"}"
] |
// Like Serve, but runs Goji on top of an arbitrary net.Listener.
|
[
"Like",
"Serve",
"but",
"runs",
"Goji",
"on",
"top",
"of",
"an",
"arbitrary",
"net",
".",
"Listener",
"."
] |
84fcf9f2a841e8e9124cfadbdf0f45132a9b821e
|
https://github.com/zenazn/goji/blob/84fcf9f2a841e8e9124cfadbdf0f45132a9b821e/serve.go#L44-L64
|
14,278 |
go-ozzo/ozzo-routing
|
fault/panic.go
|
getCallStack
|
func getCallStack(skip int) string {
buf := new(bytes.Buffer)
for i := skip; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
fmt.Fprintf(buf, "\n%s:%d", file, line)
}
return buf.String()
}
|
go
|
func getCallStack(skip int) string {
buf := new(bytes.Buffer)
for i := skip; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
fmt.Fprintf(buf, "\n%s:%d", file, line)
}
return buf.String()
}
|
[
"func",
"getCallStack",
"(",
"skip",
"int",
")",
"string",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"for",
"i",
":=",
"skip",
";",
";",
"i",
"++",
"{",
"_",
",",
"file",
",",
"line",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"i",
")",
"\n",
"if",
"!",
"ok",
"{",
"break",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"buf",
",",
"\"",
"\\n",
"\"",
",",
"file",
",",
"line",
")",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] |
// getCallStack returns the current call stack information as a string.
// The skip parameter specifies how many top frames should be skipped.
|
[
"getCallStack",
"returns",
"the",
"current",
"call",
"stack",
"information",
"as",
"a",
"string",
".",
"The",
"skip",
"parameter",
"specifies",
"how",
"many",
"top",
"frames",
"should",
"be",
"skipped",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/fault/panic.go#L46-L56
|
14,279 |
go-ozzo/ozzo-routing
|
group.go
|
newRouteGroup
|
func newRouteGroup(prefix string, router *Router, handlers []Handler) *RouteGroup {
return &RouteGroup{
prefix: prefix,
router: router,
handlers: handlers,
}
}
|
go
|
func newRouteGroup(prefix string, router *Router, handlers []Handler) *RouteGroup {
return &RouteGroup{
prefix: prefix,
router: router,
handlers: handlers,
}
}
|
[
"func",
"newRouteGroup",
"(",
"prefix",
"string",
",",
"router",
"*",
"Router",
",",
"handlers",
"[",
"]",
"Handler",
")",
"*",
"RouteGroup",
"{",
"return",
"&",
"RouteGroup",
"{",
"prefix",
":",
"prefix",
",",
"router",
":",
"router",
",",
"handlers",
":",
"handlers",
",",
"}",
"\n",
"}"
] |
// newRouteGroup creates a new RouteGroup with the given path prefix, router, and handlers.
|
[
"newRouteGroup",
"creates",
"a",
"new",
"RouteGroup",
"with",
"the",
"given",
"path",
"prefix",
"router",
"and",
"handlers",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/group.go#L17-L23
|
14,280 |
go-ozzo/ozzo-routing
|
group.go
|
Delete
|
func (rg *RouteGroup) Delete(path string, handlers ...Handler) *Route {
return rg.add("DELETE", path, handlers)
}
|
go
|
func (rg *RouteGroup) Delete(path string, handlers ...Handler) *Route {
return rg.add("DELETE", path, handlers)
}
|
[
"func",
"(",
"rg",
"*",
"RouteGroup",
")",
"Delete",
"(",
"path",
"string",
",",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"rg",
".",
"add",
"(",
"\"",
"\"",
",",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Delete adds a DELETE route to the router with the given route path and handlers.
|
[
"Delete",
"adds",
"a",
"DELETE",
"route",
"to",
"the",
"router",
"with",
"the",
"given",
"route",
"path",
"and",
"handlers",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/group.go#L46-L48
|
14,281 |
go-ozzo/ozzo-routing
|
group.go
|
combineHandlers
|
func combineHandlers(h1 []Handler, h2 []Handler) []Handler {
hh := make([]Handler, len(h1)+len(h2))
copy(hh, h1)
copy(hh[len(h1):], h2)
return hh
}
|
go
|
func combineHandlers(h1 []Handler, h2 []Handler) []Handler {
hh := make([]Handler, len(h1)+len(h2))
copy(hh, h1)
copy(hh[len(h1):], h2)
return hh
}
|
[
"func",
"combineHandlers",
"(",
"h1",
"[",
"]",
"Handler",
",",
"h2",
"[",
"]",
"Handler",
")",
"[",
"]",
"Handler",
"{",
"hh",
":=",
"make",
"(",
"[",
"]",
"Handler",
",",
"len",
"(",
"h1",
")",
"+",
"len",
"(",
"h2",
")",
")",
"\n",
"copy",
"(",
"hh",
",",
"h1",
")",
"\n",
"copy",
"(",
"hh",
"[",
"len",
"(",
"h1",
")",
":",
"]",
",",
"h2",
")",
"\n",
"return",
"hh",
"\n",
"}"
] |
// combineHandlers merges two lists of handlers into a new list.
|
[
"combineHandlers",
"merges",
"two",
"lists",
"of",
"handlers",
"into",
"a",
"new",
"list",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/group.go#L125-L130
|
14,282 |
go-ozzo/ozzo-routing
|
cors/handler.go
|
Handler
|
func Handler(opts Options) routing.Handler {
opts.init()
return func(c *routing.Context) (err error) {
origin := c.Request.Header.Get(headerOrigin)
if origin == "" {
// the request is outside the scope of CORS
return
}
if c.Request.Method == "OPTIONS" {
// a preflight request
method := c.Request.Header.Get(headerRequestMethod)
if method == "" {
// the request is outside the scope of CORS
return
}
headers := c.Request.Header.Get(headerRequestHeaders)
opts.setPreflightHeaders(origin, method, headers, c.Response.Header())
c.Abort()
return
}
opts.setActualHeaders(origin, c.Response.Header())
return
}
}
|
go
|
func Handler(opts Options) routing.Handler {
opts.init()
return func(c *routing.Context) (err error) {
origin := c.Request.Header.Get(headerOrigin)
if origin == "" {
// the request is outside the scope of CORS
return
}
if c.Request.Method == "OPTIONS" {
// a preflight request
method := c.Request.Header.Get(headerRequestMethod)
if method == "" {
// the request is outside the scope of CORS
return
}
headers := c.Request.Header.Get(headerRequestHeaders)
opts.setPreflightHeaders(origin, method, headers, c.Response.Header())
c.Abort()
return
}
opts.setActualHeaders(origin, c.Response.Header())
return
}
}
|
[
"func",
"Handler",
"(",
"opts",
"Options",
")",
"routing",
".",
"Handler",
"{",
"opts",
".",
"init",
"(",
")",
"\n\n",
"return",
"func",
"(",
"c",
"*",
"routing",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"origin",
":=",
"c",
".",
"Request",
".",
"Header",
".",
"Get",
"(",
"headerOrigin",
")",
"\n",
"if",
"origin",
"==",
"\"",
"\"",
"{",
"// the request is outside the scope of CORS",
"return",
"\n",
"}",
"\n",
"if",
"c",
".",
"Request",
".",
"Method",
"==",
"\"",
"\"",
"{",
"// a preflight request",
"method",
":=",
"c",
".",
"Request",
".",
"Header",
".",
"Get",
"(",
"headerRequestMethod",
")",
"\n",
"if",
"method",
"==",
"\"",
"\"",
"{",
"// the request is outside the scope of CORS",
"return",
"\n",
"}",
"\n",
"headers",
":=",
"c",
".",
"Request",
".",
"Header",
".",
"Get",
"(",
"headerRequestHeaders",
")",
"\n",
"opts",
".",
"setPreflightHeaders",
"(",
"origin",
",",
"method",
",",
"headers",
",",
"c",
".",
"Response",
".",
"Header",
"(",
")",
")",
"\n",
"c",
".",
"Abort",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"opts",
".",
"setActualHeaders",
"(",
"origin",
",",
"c",
".",
"Response",
".",
"Header",
"(",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
] |
// Handler creates a routing handler that adds appropriate CORS headers according to the specified options and the request.
|
[
"Handler",
"creates",
"a",
"routing",
"handler",
"that",
"adds",
"appropriate",
"CORS",
"headers",
"according",
"to",
"the",
"specified",
"options",
"and",
"the",
"request",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/cors/handler.go#L59-L84
|
14,283 |
go-ozzo/ozzo-routing
|
route.go
|
Tag
|
func (r *Route) Tag(value interface{}) *Route {
if len(r.routes) > 0 {
// this route is a composite one (a path with multiple methods)
for _, route := range r.routes {
route.Tag(value)
}
return r
}
if r.tags == nil {
r.tags = []interface{}{}
}
r.tags = append(r.tags, value)
return r
}
|
go
|
func (r *Route) Tag(value interface{}) *Route {
if len(r.routes) > 0 {
// this route is a composite one (a path with multiple methods)
for _, route := range r.routes {
route.Tag(value)
}
return r
}
if r.tags == nil {
r.tags = []interface{}{}
}
r.tags = append(r.tags, value)
return r
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Tag",
"(",
"value",
"interface",
"{",
"}",
")",
"*",
"Route",
"{",
"if",
"len",
"(",
"r",
".",
"routes",
")",
">",
"0",
"{",
"// this route is a composite one (a path with multiple methods)",
"for",
"_",
",",
"route",
":=",
"range",
"r",
".",
"routes",
"{",
"route",
".",
"Tag",
"(",
"value",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}",
"\n",
"if",
"r",
".",
"tags",
"==",
"nil",
"{",
"r",
".",
"tags",
"=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"r",
".",
"tags",
"=",
"append",
"(",
"r",
".",
"tags",
",",
"value",
")",
"\n",
"return",
"r",
"\n",
"}"
] |
// Tag associates some custom data with the route.
|
[
"Tag",
"associates",
"some",
"custom",
"data",
"with",
"the",
"route",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L31-L44
|
14,284 |
go-ozzo/ozzo-routing
|
route.go
|
Get
|
func (r *Route) Get(handlers ...Handler) *Route {
return r.group.add("GET", r.path, handlers)
}
|
go
|
func (r *Route) Get(handlers ...Handler) *Route {
return r.group.add("GET", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Get",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Get adds the route to the router using the GET HTTP method.
|
[
"Get",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"GET",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L62-L64
|
14,285 |
go-ozzo/ozzo-routing
|
route.go
|
Post
|
func (r *Route) Post(handlers ...Handler) *Route {
return r.group.add("POST", r.path, handlers)
}
|
go
|
func (r *Route) Post(handlers ...Handler) *Route {
return r.group.add("POST", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Post",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Post adds the route to the router using the POST HTTP method.
|
[
"Post",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"POST",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L67-L69
|
14,286 |
go-ozzo/ozzo-routing
|
route.go
|
Put
|
func (r *Route) Put(handlers ...Handler) *Route {
return r.group.add("PUT", r.path, handlers)
}
|
go
|
func (r *Route) Put(handlers ...Handler) *Route {
return r.group.add("PUT", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Put",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Put adds the route to the router using the PUT HTTP method.
|
[
"Put",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"PUT",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L72-L74
|
14,287 |
go-ozzo/ozzo-routing
|
route.go
|
Patch
|
func (r *Route) Patch(handlers ...Handler) *Route {
return r.group.add("PATCH", r.path, handlers)
}
|
go
|
func (r *Route) Patch(handlers ...Handler) *Route {
return r.group.add("PATCH", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Patch",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Patch adds the route to the router using the PATCH HTTP method.
|
[
"Patch",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"PATCH",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L77-L79
|
14,288 |
go-ozzo/ozzo-routing
|
route.go
|
Delete
|
func (r *Route) Delete(handlers ...Handler) *Route {
return r.group.add("DELETE", r.path, handlers)
}
|
go
|
func (r *Route) Delete(handlers ...Handler) *Route {
return r.group.add("DELETE", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Delete",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Delete adds the route to the router using the DELETE HTTP method.
|
[
"Delete",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"DELETE",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L82-L84
|
14,289 |
go-ozzo/ozzo-routing
|
route.go
|
Connect
|
func (r *Route) Connect(handlers ...Handler) *Route {
return r.group.add("CONNECT", r.path, handlers)
}
|
go
|
func (r *Route) Connect(handlers ...Handler) *Route {
return r.group.add("CONNECT", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Connect",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Connect adds the route to the router using the CONNECT HTTP method.
|
[
"Connect",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"CONNECT",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L87-L89
|
14,290 |
go-ozzo/ozzo-routing
|
route.go
|
Head
|
func (r *Route) Head(handlers ...Handler) *Route {
return r.group.add("HEAD", r.path, handlers)
}
|
go
|
func (r *Route) Head(handlers ...Handler) *Route {
return r.group.add("HEAD", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Head",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Head adds the route to the router using the HEAD HTTP method.
|
[
"Head",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"HEAD",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L92-L94
|
14,291 |
go-ozzo/ozzo-routing
|
route.go
|
Options
|
func (r *Route) Options(handlers ...Handler) *Route {
return r.group.add("OPTIONS", r.path, handlers)
}
|
go
|
func (r *Route) Options(handlers ...Handler) *Route {
return r.group.add("OPTIONS", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Options",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Options adds the route to the router using the OPTIONS HTTP method.
|
[
"Options",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"OPTIONS",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L97-L99
|
14,292 |
go-ozzo/ozzo-routing
|
route.go
|
Trace
|
func (r *Route) Trace(handlers ...Handler) *Route {
return r.group.add("TRACE", r.path, handlers)
}
|
go
|
func (r *Route) Trace(handlers ...Handler) *Route {
return r.group.add("TRACE", r.path, handlers)
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"Trace",
"(",
"handlers",
"...",
"Handler",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"group",
".",
"add",
"(",
"\"",
"\"",
",",
"r",
".",
"path",
",",
"handlers",
")",
"\n",
"}"
] |
// Trace adds the route to the router using the TRACE HTTP method.
|
[
"Trace",
"adds",
"the",
"route",
"to",
"the",
"router",
"using",
"the",
"TRACE",
"HTTP",
"method",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L102-L104
|
14,293 |
go-ozzo/ozzo-routing
|
route.go
|
URL
|
func (r *Route) URL(pairs ...interface{}) (s string) {
s = r.template
for i := 0; i < len(pairs); i++ {
name := fmt.Sprintf("<%v>", pairs[i])
value := ""
if i < len(pairs)-1 {
value = url.QueryEscape(fmt.Sprint(pairs[i+1]))
}
s = strings.Replace(s, name, value, -1)
}
return
}
|
go
|
func (r *Route) URL(pairs ...interface{}) (s string) {
s = r.template
for i := 0; i < len(pairs); i++ {
name := fmt.Sprintf("<%v>", pairs[i])
value := ""
if i < len(pairs)-1 {
value = url.QueryEscape(fmt.Sprint(pairs[i+1]))
}
s = strings.Replace(s, name, value, -1)
}
return
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"URL",
"(",
"pairs",
"...",
"interface",
"{",
"}",
")",
"(",
"s",
"string",
")",
"{",
"s",
"=",
"r",
".",
"template",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"pairs",
")",
";",
"i",
"++",
"{",
"name",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pairs",
"[",
"i",
"]",
")",
"\n",
"value",
":=",
"\"",
"\"",
"\n",
"if",
"i",
"<",
"len",
"(",
"pairs",
")",
"-",
"1",
"{",
"value",
"=",
"url",
".",
"QueryEscape",
"(",
"fmt",
".",
"Sprint",
"(",
"pairs",
"[",
"i",
"+",
"1",
"]",
")",
")",
"\n",
"}",
"\n",
"s",
"=",
"strings",
".",
"Replace",
"(",
"s",
",",
"name",
",",
"value",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// URL creates a URL using the current route and the given parameters.
// The parameters should be given in the sequence of name1, value1, name2, value2, and so on.
// If a parameter in the route is not provided a value, the parameter token will remain in the resulting URL.
// The method will perform URL encoding for all given parameter values.
|
[
"URL",
"creates",
"a",
"URL",
"using",
"the",
"current",
"route",
"and",
"the",
"given",
"parameters",
".",
"The",
"parameters",
"should",
"be",
"given",
"in",
"the",
"sequence",
"of",
"name1",
"value1",
"name2",
"value2",
"and",
"so",
"on",
".",
"If",
"a",
"parameter",
"in",
"the",
"route",
"is",
"not",
"provided",
"a",
"value",
"the",
"parameter",
"token",
"will",
"remain",
"in",
"the",
"resulting",
"URL",
".",
"The",
"method",
"will",
"perform",
"URL",
"encoding",
"for",
"all",
"given",
"parameter",
"values",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L116-L127
|
14,294 |
go-ozzo/ozzo-routing
|
route.go
|
String
|
func (r *Route) String() string {
return r.method + " " + r.group.prefix + r.path
}
|
go
|
func (r *Route) String() string {
return r.method + " " + r.group.prefix + r.path
}
|
[
"func",
"(",
"r",
"*",
"Route",
")",
"String",
"(",
")",
"string",
"{",
"return",
"r",
".",
"method",
"+",
"\"",
"\"",
"+",
"r",
".",
"group",
".",
"prefix",
"+",
"r",
".",
"path",
"\n",
"}"
] |
// String returns the string representation of the route.
|
[
"String",
"returns",
"the",
"string",
"representation",
"of",
"the",
"route",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/route.go#L130-L132
|
14,295 |
go-ozzo/ozzo-routing
|
context.go
|
NewContext
|
func NewContext(res http.ResponseWriter, req *http.Request, handlers ...Handler) *Context {
c := &Context{handlers: handlers}
c.init(res, req)
return c
}
|
go
|
func NewContext(res http.ResponseWriter, req *http.Request, handlers ...Handler) *Context {
c := &Context{handlers: handlers}
c.init(res, req)
return c
}
|
[
"func",
"NewContext",
"(",
"res",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
",",
"handlers",
"...",
"Handler",
")",
"*",
"Context",
"{",
"c",
":=",
"&",
"Context",
"{",
"handlers",
":",
"handlers",
"}",
"\n",
"c",
".",
"init",
"(",
"res",
",",
"req",
")",
"\n",
"return",
"c",
"\n",
"}"
] |
// NewContext creates a new Context object with the given response, request, and the handlers.
// This method is primarily provided for writing unit tests for handlers.
|
[
"NewContext",
"creates",
"a",
"new",
"Context",
"object",
"with",
"the",
"given",
"response",
"request",
"and",
"the",
"handlers",
".",
"This",
"method",
"is",
"primarily",
"provided",
"for",
"writing",
"unit",
"tests",
"for",
"handlers",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/context.go#L26-L30
|
14,296 |
go-ozzo/ozzo-routing
|
context.go
|
Param
|
func (c *Context) Param(name string) string {
for i, n := range c.pnames {
if n == name {
return c.pvalues[i]
}
}
return ""
}
|
go
|
func (c *Context) Param(name string) string {
for i, n := range c.pnames {
if n == name {
return c.pvalues[i]
}
}
return ""
}
|
[
"func",
"(",
"c",
"*",
"Context",
")",
"Param",
"(",
"name",
"string",
")",
"string",
"{",
"for",
"i",
",",
"n",
":=",
"range",
"c",
".",
"pnames",
"{",
"if",
"n",
"==",
"name",
"{",
"return",
"c",
".",
"pvalues",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] |
// Param returns the named parameter value that is found in the URL path matching the current route.
// If the named parameter cannot be found, an empty string will be returned.
|
[
"Param",
"returns",
"the",
"named",
"parameter",
"value",
"that",
"is",
"found",
"in",
"the",
"URL",
"path",
"matching",
"the",
"current",
"route",
".",
"If",
"the",
"named",
"parameter",
"cannot",
"be",
"found",
"an",
"empty",
"string",
"will",
"be",
"returned",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/context.go#L39-L46
|
14,297 |
go-ozzo/ozzo-routing
|
context.go
|
SetParam
|
func (c *Context) SetParam(name, value string) {
for i, n := range c.pnames {
if n == name {
c.pvalues[i] = value
return
}
}
c.pnames = append(c.pnames, name)
c.pvalues = append(c.pvalues, value)
}
|
go
|
func (c *Context) SetParam(name, value string) {
for i, n := range c.pnames {
if n == name {
c.pvalues[i] = value
return
}
}
c.pnames = append(c.pnames, name)
c.pvalues = append(c.pvalues, value)
}
|
[
"func",
"(",
"c",
"*",
"Context",
")",
"SetParam",
"(",
"name",
",",
"value",
"string",
")",
"{",
"for",
"i",
",",
"n",
":=",
"range",
"c",
".",
"pnames",
"{",
"if",
"n",
"==",
"name",
"{",
"c",
".",
"pvalues",
"[",
"i",
"]",
"=",
"value",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"c",
".",
"pnames",
"=",
"append",
"(",
"c",
".",
"pnames",
",",
"name",
")",
"\n",
"c",
".",
"pvalues",
"=",
"append",
"(",
"c",
".",
"pvalues",
",",
"value",
")",
"\n",
"}"
] |
// SetParam sets the named parameter value.
// This method is primarily provided for writing unit tests.
|
[
"SetParam",
"sets",
"the",
"named",
"parameter",
"value",
".",
"This",
"method",
"is",
"primarily",
"provided",
"for",
"writing",
"unit",
"tests",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/context.go#L50-L59
|
14,298 |
go-ozzo/ozzo-routing
|
context.go
|
Set
|
func (c *Context) Set(name string, value interface{}) {
if c.data == nil {
c.data = make(map[string]interface{})
}
c.data[name] = value
}
|
go
|
func (c *Context) Set(name string, value interface{}) {
if c.data == nil {
c.data = make(map[string]interface{})
}
c.data[name] = value
}
|
[
"func",
"(",
"c",
"*",
"Context",
")",
"Set",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"c",
".",
"data",
"==",
"nil",
"{",
"c",
".",
"data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"c",
".",
"data",
"[",
"name",
"]",
"=",
"value",
"\n",
"}"
] |
// Set stores the named data item in the context so that it can be retrieved later.
|
[
"Set",
"stores",
"the",
"named",
"data",
"item",
"in",
"the",
"context",
"so",
"that",
"it",
"can",
"be",
"retrieved",
"later",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/context.go#L68-L73
|
14,299 |
go-ozzo/ozzo-routing
|
context.go
|
Query
|
func (c *Context) Query(name string, defaultValue ...string) string {
if vs, _ := c.Request.URL.Query()[name]; len(vs) > 0 {
return vs[0]
}
if len(defaultValue) > 0 {
return defaultValue[0]
}
return ""
}
|
go
|
func (c *Context) Query(name string, defaultValue ...string) string {
if vs, _ := c.Request.URL.Query()[name]; len(vs) > 0 {
return vs[0]
}
if len(defaultValue) > 0 {
return defaultValue[0]
}
return ""
}
|
[
"func",
"(",
"c",
"*",
"Context",
")",
"Query",
"(",
"name",
"string",
",",
"defaultValue",
"...",
"string",
")",
"string",
"{",
"if",
"vs",
",",
"_",
":=",
"c",
".",
"Request",
".",
"URL",
".",
"Query",
"(",
")",
"[",
"name",
"]",
";",
"len",
"(",
"vs",
")",
">",
"0",
"{",
"return",
"vs",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"defaultValue",
")",
">",
"0",
"{",
"return",
"defaultValue",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] |
// Query returns the first value for the named component of the URL query parameters.
// If key is not present, it returns the specified default value or an empty string.
|
[
"Query",
"returns",
"the",
"first",
"value",
"for",
"the",
"named",
"component",
"of",
"the",
"URL",
"query",
"parameters",
".",
"If",
"key",
"is",
"not",
"present",
"it",
"returns",
"the",
"specified",
"default",
"value",
"or",
"an",
"empty",
"string",
"."
] |
9dcabc145f0d565b5219e2fd72c3da04876980b7
|
https://github.com/go-ozzo/ozzo-routing/blob/9dcabc145f0d565b5219e2fd72c3da04876980b7/context.go#L77-L85
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.