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
|
---|---|---|---|---|---|---|---|---|---|---|---|
16,400 |
fhs/gompd
|
mpd/client.go
|
SetVolume
|
func (c *Client) SetVolume(volume int) error {
return c.Command("setvol %d", volume).OK()
}
|
go
|
func (c *Client) SetVolume(volume int) error {
return c.Command("setvol %d", volume).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"SetVolume",
"(",
"volume",
"int",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"volume",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// SetVolume sets the volume to volume. The range of volume is 0-100.
|
[
"SetVolume",
"sets",
"the",
"volume",
"to",
"volume",
".",
"The",
"range",
"of",
"volume",
"is",
"0",
"-",
"100",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L374-L376
|
16,401 |
fhs/gompd
|
mpd/client.go
|
PlaylistInfo
|
func (c *Client) PlaylistInfo(start, end int) ([]Attrs, error) {
var cmd *Command
switch {
case start < 0 && end < 0:
// Request all playlist items.
cmd = c.Command("playlistinfo")
case start >= 0 && end >= 0:
// Request this range of playlist items.
cmd = c.Command("playlistinfo %d:%d", start, end)
case start >= 0 && end < 0:
// Request the single playlist item at this position.
cmd = c.Command("playlistinfo %d", start)
case start < 0 && end >= 0:
return nil, errors.New("negative start index")
default:
panic("unreachable")
}
return cmd.AttrsList("file")
}
|
go
|
func (c *Client) PlaylistInfo(start, end int) ([]Attrs, error) {
var cmd *Command
switch {
case start < 0 && end < 0:
// Request all playlist items.
cmd = c.Command("playlistinfo")
case start >= 0 && end >= 0:
// Request this range of playlist items.
cmd = c.Command("playlistinfo %d:%d", start, end)
case start >= 0 && end < 0:
// Request the single playlist item at this position.
cmd = c.Command("playlistinfo %d", start)
case start < 0 && end >= 0:
return nil, errors.New("negative start index")
default:
panic("unreachable")
}
return cmd.AttrsList("file")
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistInfo",
"(",
"start",
",",
"end",
"int",
")",
"(",
"[",
"]",
"Attrs",
",",
"error",
")",
"{",
"var",
"cmd",
"*",
"Command",
"\n",
"switch",
"{",
"case",
"start",
"<",
"0",
"&&",
"end",
"<",
"0",
":",
"// Request all playlist items.",
"cmd",
"=",
"c",
".",
"Command",
"(",
"\"",
"\"",
")",
"\n",
"case",
"start",
">=",
"0",
"&&",
"end",
">=",
"0",
":",
"// Request this range of playlist items.",
"cmd",
"=",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"start",
",",
"end",
")",
"\n",
"case",
"start",
">=",
"0",
"&&",
"end",
"<",
"0",
":",
"// Request the single playlist item at this position.",
"cmd",
"=",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"start",
")",
"\n",
"case",
"start",
"<",
"0",
"&&",
"end",
">=",
"0",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"cmd",
".",
"AttrsList",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
//
// Playlist related functions
//
// PlaylistInfo returns attributes for songs in the current playlist. If
// both start and end are negative, it does this for all songs in
// playlist. If end is negative but start is positive, it does it for the
// song at position start. If both start and end are positive, it does it
// for positions in range [start, end).
|
[
"Playlist",
"related",
"functions",
"PlaylistInfo",
"returns",
"attributes",
"for",
"songs",
"in",
"the",
"current",
"playlist",
".",
"If",
"both",
"start",
"and",
"end",
"are",
"negative",
"it",
"does",
"this",
"for",
"all",
"songs",
"in",
"playlist",
".",
"If",
"end",
"is",
"negative",
"but",
"start",
"is",
"positive",
"it",
"does",
"it",
"for",
"the",
"song",
"at",
"position",
"start",
".",
"If",
"both",
"start",
"and",
"end",
"are",
"positive",
"it",
"does",
"it",
"for",
"positions",
"in",
"range",
"[",
"start",
"end",
")",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L419-L437
|
16,402 |
fhs/gompd
|
mpd/client.go
|
SetPriority
|
func (c *Client) SetPriority(priority, start, end int) error {
switch {
case start < 0 && end < 0:
return errors.New("negative start and end index")
case start >= 0 && end >= 0:
// Update the prio for this range of playlist items.
return c.Command("prio %d %d:%d", priority, start, end).OK()
case start >= 0 && end < 0:
// Update the prio for a single playlist item at this position.
return c.Command("prio %d %d", priority, start).OK()
case start < 0 && end >= 0:
return errors.New("negative start index")
default:
panic("unreachable")
}
}
|
go
|
func (c *Client) SetPriority(priority, start, end int) error {
switch {
case start < 0 && end < 0:
return errors.New("negative start and end index")
case start >= 0 && end >= 0:
// Update the prio for this range of playlist items.
return c.Command("prio %d %d:%d", priority, start, end).OK()
case start >= 0 && end < 0:
// Update the prio for a single playlist item at this position.
return c.Command("prio %d %d", priority, start).OK()
case start < 0 && end >= 0:
return errors.New("negative start index")
default:
panic("unreachable")
}
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"SetPriority",
"(",
"priority",
",",
"start",
",",
"end",
"int",
")",
"error",
"{",
"switch",
"{",
"case",
"start",
"<",
"0",
"&&",
"end",
"<",
"0",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"start",
">=",
"0",
"&&",
"end",
">=",
"0",
":",
"// Update the prio for this range of playlist items.",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"priority",
",",
"start",
",",
"end",
")",
".",
"OK",
"(",
")",
"\n",
"case",
"start",
">=",
"0",
"&&",
"end",
"<",
"0",
":",
"// Update the prio for a single playlist item at this position.",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"priority",
",",
"start",
")",
".",
"OK",
"(",
")",
"\n",
"case",
"start",
"<",
"0",
"&&",
"end",
">=",
"0",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] |
// SetPriority set the priority of the specified songs. If end is negative but
// start is non-negative, it does it for the song at position start. If both
// start and end are non-negative, it does it for positions in range
// [start, end).
|
[
"SetPriority",
"set",
"the",
"priority",
"of",
"the",
"specified",
"songs",
".",
"If",
"end",
"is",
"negative",
"but",
"start",
"is",
"non",
"-",
"negative",
"it",
"does",
"it",
"for",
"the",
"song",
"at",
"position",
"start",
".",
"If",
"both",
"start",
"and",
"end",
"are",
"non",
"-",
"negative",
"it",
"does",
"it",
"for",
"positions",
"in",
"range",
"[",
"start",
"end",
")",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L443-L458
|
16,403 |
fhs/gompd
|
mpd/client.go
|
SetPriorityID
|
func (c *Client) SetPriorityID(priority, id int) error {
return c.Command("prioid %d %d", priority, id).OK()
}
|
go
|
func (c *Client) SetPriorityID(priority, id int) error {
return c.Command("prioid %d %d", priority, id).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"SetPriorityID",
"(",
"priority",
",",
"id",
"int",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"priority",
",",
"id",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// SetPriorityID sets the prio of the song with the given id.
|
[
"SetPriorityID",
"sets",
"the",
"prio",
"of",
"the",
"song",
"with",
"the",
"given",
"id",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L461-L463
|
16,404 |
fhs/gompd
|
mpd/client.go
|
Delete
|
func (c *Client) Delete(start, end int) error {
if start < 0 {
return errors.New("negative start index")
}
if end < 0 {
return c.Command("delete %d", start).OK()
}
return c.Command("delete %d:%d", start, end).OK()
}
|
go
|
func (c *Client) Delete(start, end int) error {
if start < 0 {
return errors.New("negative start index")
}
if end < 0 {
return c.Command("delete %d", start).OK()
}
return c.Command("delete %d:%d", start, end).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Delete",
"(",
"start",
",",
"end",
"int",
")",
"error",
"{",
"if",
"start",
"<",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"end",
"<",
"0",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"start",
")",
".",
"OK",
"(",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"start",
",",
"end",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// Delete deletes songs from playlist. If both start and end are positive,
// it deletes those at positions in range [start, end). If end is negative,
// it deletes the song at position start.
|
[
"Delete",
"deletes",
"songs",
"from",
"playlist",
".",
"If",
"both",
"start",
"and",
"end",
"are",
"positive",
"it",
"deletes",
"those",
"at",
"positions",
"in",
"range",
"[",
"start",
"end",
")",
".",
"If",
"end",
"is",
"negative",
"it",
"deletes",
"the",
"song",
"at",
"position",
"start",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L468-L476
|
16,405 |
fhs/gompd
|
mpd/client.go
|
Move
|
func (c *Client) Move(start, end, position int) error {
if start < 0 {
return errors.New("negative start index")
}
if end < 0 {
return c.Command("move %d %d", start, position).OK()
}
return c.Command("move %d:%d %d", start, end, position).OK()
}
|
go
|
func (c *Client) Move(start, end, position int) error {
if start < 0 {
return errors.New("negative start index")
}
if end < 0 {
return c.Command("move %d %d", start, position).OK()
}
return c.Command("move %d:%d %d", start, end, position).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Move",
"(",
"start",
",",
"end",
",",
"position",
"int",
")",
"error",
"{",
"if",
"start",
"<",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"end",
"<",
"0",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"start",
",",
"position",
")",
".",
"OK",
"(",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"start",
",",
"end",
",",
"position",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// Move moves the songs between the positions start and end to the new position
// position. If end is negative, only the song at position start is moved.
|
[
"Move",
"moves",
"the",
"songs",
"between",
"the",
"positions",
"start",
"and",
"end",
"to",
"the",
"new",
"position",
"position",
".",
"If",
"end",
"is",
"negative",
"only",
"the",
"song",
"at",
"position",
"start",
"is",
"moved",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L485-L493
|
16,406 |
fhs/gompd
|
mpd/client.go
|
MoveID
|
func (c *Client) MoveID(songid, position int) error {
return c.Command("moveid %d %d", songid, position).OK()
}
|
go
|
func (c *Client) MoveID(songid, position int) error {
return c.Command("moveid %d %d", songid, position).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"MoveID",
"(",
"songid",
",",
"position",
"int",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"songid",
",",
"position",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// MoveID moves songid to position on the plyalist.
|
[
"MoveID",
"moves",
"songid",
"to",
"position",
"on",
"the",
"plyalist",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L496-L498
|
16,407 |
fhs/gompd
|
mpd/client.go
|
Search
|
func (c *Client) Search(args ...string) ([]Attrs, error) {
return c.Command("search " + quoteArgs(args)).AttrsList("file")
}
|
go
|
func (c *Client) Search(args ...string) ([]Attrs, error) {
return c.Command("search " + quoteArgs(args)).AttrsList("file")
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Search",
"(",
"args",
"...",
"string",
")",
"(",
"[",
"]",
"Attrs",
",",
"error",
")",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
"+",
"quoteArgs",
"(",
"args",
")",
")",
".",
"AttrsList",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// Search behaves exactly the same as Find, but the searches are not case sensitive.
|
[
"Search",
"behaves",
"exactly",
"the",
"same",
"as",
"Find",
"but",
"the",
"searches",
"are",
"not",
"case",
"sensitive",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L662-L664
|
16,408 |
fhs/gompd
|
mpd/client.go
|
EnableOutput
|
func (c *Client) EnableOutput(id int) error {
return c.Command("enableoutput %d", id).OK()
}
|
go
|
func (c *Client) EnableOutput(id int) error {
return c.Command("enableoutput %d", id).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"EnableOutput",
"(",
"id",
"int",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"id",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// EnableOutput enables the audio output with the given id.
|
[
"EnableOutput",
"enables",
"the",
"audio",
"output",
"with",
"the",
"given",
"id",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L704-L706
|
16,409 |
fhs/gompd
|
mpd/client.go
|
DisableOutput
|
func (c *Client) DisableOutput(id int) error {
return c.Command("disableoutput %d", id).OK()
}
|
go
|
func (c *Client) DisableOutput(id int) error {
return c.Command("disableoutput %d", id).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"DisableOutput",
"(",
"id",
"int",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"id",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// DisableOutput disables the audio output with the given id.
|
[
"DisableOutput",
"disables",
"the",
"audio",
"output",
"with",
"the",
"given",
"id",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L709-L711
|
16,410 |
fhs/gompd
|
mpd/client.go
|
PlaylistContents
|
func (c *Client) PlaylistContents(name string) ([]Attrs, error) {
return c.Command("listplaylistinfo %s", name).AttrsList("file")
}
|
go
|
func (c *Client) PlaylistContents(name string) ([]Attrs, error) {
return c.Command("listplaylistinfo %s", name).AttrsList("file")
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistContents",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"Attrs",
",",
"error",
")",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
")",
".",
"AttrsList",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// PlaylistContents returns a list of attributes for songs in the specified
// stored playlist.
|
[
"PlaylistContents",
"returns",
"a",
"list",
"of",
"attributes",
"for",
"songs",
"in",
"the",
"specified",
"stored",
"playlist",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L722-L724
|
16,411 |
fhs/gompd
|
mpd/client.go
|
PlaylistLoad
|
func (c *Client) PlaylistLoad(name string, start, end int) error {
if start < 0 || end < 0 {
return c.Command("load %s", name).OK()
}
return c.Command("load %s %d:%d", name, start, end).OK()
}
|
go
|
func (c *Client) PlaylistLoad(name string, start, end int) error {
if start < 0 || end < 0 {
return c.Command("load %s", name).OK()
}
return c.Command("load %s %d:%d", name, start, end).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistLoad",
"(",
"name",
"string",
",",
"start",
",",
"end",
"int",
")",
"error",
"{",
"if",
"start",
"<",
"0",
"||",
"end",
"<",
"0",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
")",
".",
"OK",
"(",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
",",
"start",
",",
"end",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// PlaylistLoad loads the specfied playlist into the current queue.
// If start and end are non-negative, only songs in this range are loaded.
|
[
"PlaylistLoad",
"loads",
"the",
"specfied",
"playlist",
"into",
"the",
"current",
"queue",
".",
"If",
"start",
"and",
"end",
"are",
"non",
"-",
"negative",
"only",
"songs",
"in",
"this",
"range",
"are",
"loaded",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L728-L733
|
16,412 |
fhs/gompd
|
mpd/client.go
|
PlaylistAdd
|
func (c *Client) PlaylistAdd(name string, uri string) error {
return c.Command("playlistadd %s %s", name, uri).OK()
}
|
go
|
func (c *Client) PlaylistAdd(name string, uri string) error {
return c.Command("playlistadd %s %s", name, uri).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistAdd",
"(",
"name",
"string",
",",
"uri",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
",",
"uri",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// PlaylistAdd adds a song identified by uri to a stored playlist identified
// by name.
|
[
"PlaylistAdd",
"adds",
"a",
"song",
"identified",
"by",
"uri",
"to",
"a",
"stored",
"playlist",
"identified",
"by",
"name",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L737-L739
|
16,413 |
fhs/gompd
|
mpd/client.go
|
PlaylistClear
|
func (c *Client) PlaylistClear(name string) error {
return c.Command("playlistclear %s", name).OK()
}
|
go
|
func (c *Client) PlaylistClear(name string) error {
return c.Command("playlistclear %s", name).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistClear",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// PlaylistClear clears the specified playlist.
|
[
"PlaylistClear",
"clears",
"the",
"specified",
"playlist",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L742-L744
|
16,414 |
fhs/gompd
|
mpd/client.go
|
PlaylistMove
|
func (c *Client) PlaylistMove(name string, id, pos int) error {
return c.Command("playlistmove %s %d %d", name, id, pos).OK()
}
|
go
|
func (c *Client) PlaylistMove(name string, id, pos int) error {
return c.Command("playlistmove %s %d %d", name, id, pos).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistMove",
"(",
"name",
"string",
",",
"id",
",",
"pos",
"int",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
",",
"id",
",",
"pos",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// PlaylistMove moves a song identified by id in a playlist identified by name
// to the position pos.
|
[
"PlaylistMove",
"moves",
"a",
"song",
"identified",
"by",
"id",
"in",
"a",
"playlist",
"identified",
"by",
"name",
"to",
"the",
"position",
"pos",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L753-L755
|
16,415 |
fhs/gompd
|
mpd/client.go
|
PlaylistRename
|
func (c *Client) PlaylistRename(name, newName string) error {
return c.Command("rename %s %s", name, newName).OK()
}
|
go
|
func (c *Client) PlaylistRename(name, newName string) error {
return c.Command("rename %s %s", name, newName).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistRename",
"(",
"name",
",",
"newName",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
",",
"newName",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// PlaylistRename renames the playlist identified by name to newName.
|
[
"PlaylistRename",
"renames",
"the",
"playlist",
"identified",
"by",
"name",
"to",
"newName",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L758-L760
|
16,416 |
fhs/gompd
|
mpd/client.go
|
PlaylistRemove
|
func (c *Client) PlaylistRemove(name string) error {
return c.Command("rm %s", name).OK()
}
|
go
|
func (c *Client) PlaylistRemove(name string) error {
return c.Command("rm %s", name).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistRemove",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// PlaylistRemove removes the playlist identified by name from the playlist
// directory.
|
[
"PlaylistRemove",
"removes",
"the",
"playlist",
"identified",
"by",
"name",
"from",
"the",
"playlist",
"directory",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L764-L766
|
16,417 |
fhs/gompd
|
mpd/client.go
|
PlaylistSave
|
func (c *Client) PlaylistSave(name string) error {
return c.Command("save %s", name).OK()
}
|
go
|
func (c *Client) PlaylistSave(name string) error {
return c.Command("save %s", name).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PlaylistSave",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"name",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// PlaylistSave saves the current playlist as name in the playlist directory.
|
[
"PlaylistSave",
"saves",
"the",
"current",
"playlist",
"as",
"name",
"in",
"the",
"playlist",
"directory",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L769-L771
|
16,418 |
fhs/gompd
|
mpd/client.go
|
StickerFind
|
func (c *Client) StickerFind(uri string, name string) ([]string, []Sticker, error) {
attrs, err := c.Command("sticker find song %s %s", uri, name).AttrsList("file")
if err != nil {
return nil, nil, err
}
files := make([]string, len(attrs))
stks := make([]Sticker, len(attrs))
for i, attr := range attrs {
if _, ok := attr["file"]; !ok {
return nil, nil, textproto.ProtocolError("file attribute not found")
}
if _, ok := attr["sticker"]; !ok {
return nil, nil, textproto.ProtocolError("sticker attribute not found")
}
files[i] = attr["file"]
stk, err := parseSticker(attr["sticker"])
if err != nil {
return nil, nil, err
}
stks[i] = *stk
}
return files, stks, nil
}
|
go
|
func (c *Client) StickerFind(uri string, name string) ([]string, []Sticker, error) {
attrs, err := c.Command("sticker find song %s %s", uri, name).AttrsList("file")
if err != nil {
return nil, nil, err
}
files := make([]string, len(attrs))
stks := make([]Sticker, len(attrs))
for i, attr := range attrs {
if _, ok := attr["file"]; !ok {
return nil, nil, textproto.ProtocolError("file attribute not found")
}
if _, ok := attr["sticker"]; !ok {
return nil, nil, textproto.ProtocolError("sticker attribute not found")
}
files[i] = attr["file"]
stk, err := parseSticker(attr["sticker"])
if err != nil {
return nil, nil, err
}
stks[i] = *stk
}
return files, stks, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"StickerFind",
"(",
"uri",
"string",
",",
"name",
"string",
")",
"(",
"[",
"]",
"string",
",",
"[",
"]",
"Sticker",
",",
"error",
")",
"{",
"attrs",
",",
"err",
":=",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"uri",
",",
"name",
")",
".",
"AttrsList",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"files",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"attrs",
")",
")",
"\n",
"stks",
":=",
"make",
"(",
"[",
"]",
"Sticker",
",",
"len",
"(",
"attrs",
")",
")",
"\n",
"for",
"i",
",",
"attr",
":=",
"range",
"attrs",
"{",
"if",
"_",
",",
"ok",
":=",
"attr",
"[",
"\"",
"\"",
"]",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
",",
"textproto",
".",
"ProtocolError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"attr",
"[",
"\"",
"\"",
"]",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
",",
"textproto",
".",
"ProtocolError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"files",
"[",
"i",
"]",
"=",
"attr",
"[",
"\"",
"\"",
"]",
"\n",
"stk",
",",
"err",
":=",
"parseSticker",
"(",
"attr",
"[",
"\"",
"\"",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"stks",
"[",
"i",
"]",
"=",
"*",
"stk",
"\n",
"}",
"\n",
"return",
"files",
",",
"stks",
",",
"nil",
"\n",
"}"
] |
// StickerFind finds songs inside directory with URI which have a sticker with given name.
// It returns a slice of URIs of matching songs and a slice of corresponding stickers.
|
[
"StickerFind",
"finds",
"songs",
"inside",
"directory",
"with",
"URI",
"which",
"have",
"a",
"sticker",
"with",
"given",
"name",
".",
"It",
"returns",
"a",
"slice",
"of",
"URIs",
"of",
"matching",
"songs",
"and",
"a",
"slice",
"of",
"corresponding",
"stickers",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L806-L828
|
16,419 |
fhs/gompd
|
mpd/client.go
|
StickerGet
|
func (c *Client) StickerGet(uri string, name string) (*Sticker, error) {
attrs, err := c.Command("sticker get song %s %s", uri, name).Attrs()
if err != nil {
return nil, err
}
attr, ok := attrs["sticker"]
if !ok {
return nil, textproto.ProtocolError("sticker not found")
}
stk, err := parseSticker(attr)
if stk == nil {
return nil, err
}
return stk, nil
}
|
go
|
func (c *Client) StickerGet(uri string, name string) (*Sticker, error) {
attrs, err := c.Command("sticker get song %s %s", uri, name).Attrs()
if err != nil {
return nil, err
}
attr, ok := attrs["sticker"]
if !ok {
return nil, textproto.ProtocolError("sticker not found")
}
stk, err := parseSticker(attr)
if stk == nil {
return nil, err
}
return stk, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"StickerGet",
"(",
"uri",
"string",
",",
"name",
"string",
")",
"(",
"*",
"Sticker",
",",
"error",
")",
"{",
"attrs",
",",
"err",
":=",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"uri",
",",
"name",
")",
".",
"Attrs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"attr",
",",
"ok",
":=",
"attrs",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"textproto",
".",
"ProtocolError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"stk",
",",
"err",
":=",
"parseSticker",
"(",
"attr",
")",
"\n",
"if",
"stk",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"stk",
",",
"nil",
"\n",
"}"
] |
// StickerGet gets sticker value for the song with given URI.
|
[
"StickerGet",
"gets",
"sticker",
"value",
"for",
"the",
"song",
"with",
"given",
"URI",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L831-L845
|
16,420 |
fhs/gompd
|
mpd/client.go
|
StickerList
|
func (c *Client) StickerList(uri string) ([]Sticker, error) {
attrs, err := c.Command("sticker list song %s", uri).AttrsList("sticker")
if err != nil {
return nil, err
}
stks := make([]Sticker, len(attrs))
for i, attr := range attrs {
s, ok := attr["sticker"]
if !ok {
return nil, textproto.ProtocolError("sticker attribute not found")
}
stk, err := parseSticker(s)
if err != nil {
return nil, err
}
stks[i] = *stk
}
return stks, nil
}
|
go
|
func (c *Client) StickerList(uri string) ([]Sticker, error) {
attrs, err := c.Command("sticker list song %s", uri).AttrsList("sticker")
if err != nil {
return nil, err
}
stks := make([]Sticker, len(attrs))
for i, attr := range attrs {
s, ok := attr["sticker"]
if !ok {
return nil, textproto.ProtocolError("sticker attribute not found")
}
stk, err := parseSticker(s)
if err != nil {
return nil, err
}
stks[i] = *stk
}
return stks, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"StickerList",
"(",
"uri",
"string",
")",
"(",
"[",
"]",
"Sticker",
",",
"error",
")",
"{",
"attrs",
",",
"err",
":=",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"uri",
")",
".",
"AttrsList",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"stks",
":=",
"make",
"(",
"[",
"]",
"Sticker",
",",
"len",
"(",
"attrs",
")",
")",
"\n",
"for",
"i",
",",
"attr",
":=",
"range",
"attrs",
"{",
"s",
",",
"ok",
":=",
"attr",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"textproto",
".",
"ProtocolError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"stk",
",",
"err",
":=",
"parseSticker",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"stks",
"[",
"i",
"]",
"=",
"*",
"stk",
"\n",
"}",
"\n",
"return",
"stks",
",",
"nil",
"\n",
"}"
] |
// StickerList returns a slice of stickers for the song with given URI.
|
[
"StickerList",
"returns",
"a",
"slice",
"of",
"stickers",
"for",
"the",
"song",
"with",
"given",
"URI",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L848-L866
|
16,421 |
fhs/gompd
|
mpd/client.go
|
StickerSet
|
func (c *Client) StickerSet(uri string, name string, value string) error {
return c.Command("sticker set song %s %s %s", uri, name, value).OK()
}
|
go
|
func (c *Client) StickerSet(uri string, name string, value string) error {
return c.Command("sticker set song %s %s %s", uri, name, value).OK()
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"StickerSet",
"(",
"uri",
"string",
",",
"name",
"string",
",",
"value",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Command",
"(",
"\"",
"\"",
",",
"uri",
",",
"name",
",",
"value",
")",
".",
"OK",
"(",
")",
"\n",
"}"
] |
// StickerSet sets sticker value for the song with given URI.
|
[
"StickerSet",
"sets",
"sticker",
"value",
"for",
"the",
"song",
"with",
"given",
"URI",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/client.go#L869-L871
|
16,422 |
fhs/gompd
|
mpd/commandlist.go
|
Value
|
func (pa *PromisedAttrs) Value() (Attrs, error) {
if !pa.computed {
return nil, errors.New("value has not been computed yet")
}
return pa.attrs, nil
}
|
go
|
func (pa *PromisedAttrs) Value() (Attrs, error) {
if !pa.computed {
return nil, errors.New("value has not been computed yet")
}
return pa.attrs, nil
}
|
[
"func",
"(",
"pa",
"*",
"PromisedAttrs",
")",
"Value",
"(",
")",
"(",
"Attrs",
",",
"error",
")",
"{",
"if",
"!",
"pa",
".",
"computed",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"pa",
".",
"attrs",
",",
"nil",
"\n",
"}"
] |
// Value is a convenience method for ensuring that a promise
// has been computed, returning the Attrs.
|
[
"Value",
"is",
"a",
"convenience",
"method",
"for",
"ensuring",
"that",
"a",
"promise",
"has",
"been",
"computed",
"returning",
"the",
"Attrs",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L51-L56
|
16,423 |
fhs/gompd
|
mpd/commandlist.go
|
Value
|
func (pi *PromisedID) Value() (int, error) {
if *pi == -1 {
return -1, errors.New("value has not been computed yet")
}
return (int)(*pi), nil
}
|
go
|
func (pi *PromisedID) Value() (int, error) {
if *pi == -1 {
return -1, errors.New("value has not been computed yet")
}
return (int)(*pi), nil
}
|
[
"func",
"(",
"pi",
"*",
"PromisedID",
")",
"Value",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"*",
"pi",
"==",
"-",
"1",
"{",
"return",
"-",
"1",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"(",
"int",
")",
"(",
"*",
"pi",
")",
",",
"nil",
"\n",
"}"
] |
// Value is a convenience method for ensuring that a promise
// has been computed, returning the ID.
|
[
"Value",
"is",
"a",
"convenience",
"method",
"for",
"ensuring",
"that",
"a",
"promise",
"has",
"been",
"computed",
"returning",
"the",
"ID",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L60-L65
|
16,424 |
fhs/gompd
|
mpd/commandlist.go
|
CurrentSong
|
func (cl *CommandList) CurrentSong() *PromisedAttrs {
pa := newPromisedAttrs()
cl.cmdQ.PushBack(&command{"currentsong", pa, cmdAttrReturn})
return pa
}
|
go
|
func (cl *CommandList) CurrentSong() *PromisedAttrs {
pa := newPromisedAttrs()
cl.cmdQ.PushBack(&command{"currentsong", pa, cmdAttrReturn})
return pa
}
|
[
"func",
"(",
"cl",
"*",
"CommandList",
")",
"CurrentSong",
"(",
")",
"*",
"PromisedAttrs",
"{",
"pa",
":=",
"newPromisedAttrs",
"(",
")",
"\n",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"\"",
"\"",
",",
"pa",
",",
"cmdAttrReturn",
"}",
")",
"\n",
"return",
"pa",
"\n",
"}"
] |
// CurrentSong returns information about the current song in the playlist.
|
[
"CurrentSong",
"returns",
"information",
"about",
"the",
"current",
"song",
"in",
"the",
"playlist",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L79-L83
|
16,425 |
fhs/gompd
|
mpd/commandlist.go
|
PlayID
|
func (cl *CommandList) PlayID(id int) {
if id < 0 {
cl.cmdQ.PushBack(&command{"playid", nil, cmdNoReturn})
} else {
cl.cmdQ.PushBack(&command{fmt.Sprintf("playid %d", id), nil, cmdNoReturn})
}
}
|
go
|
func (cl *CommandList) PlayID(id int) {
if id < 0 {
cl.cmdQ.PushBack(&command{"playid", nil, cmdNoReturn})
} else {
cl.cmdQ.PushBack(&command{fmt.Sprintf("playid %d", id), nil, cmdNoReturn})
}
}
|
[
"func",
"(",
"cl",
"*",
"CommandList",
")",
"PlayID",
"(",
"id",
"int",
")",
"{",
"if",
"id",
"<",
"0",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"\"",
"\"",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}",
"else",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"id",
")",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// PlayID plays the song identified by id. If id is negative, start playing
// at the currect position in playlist.
|
[
"PlayID",
"plays",
"the",
"song",
"identified",
"by",
"id",
".",
"If",
"id",
"is",
"negative",
"start",
"playing",
"at",
"the",
"currect",
"position",
"in",
"playlist",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L122-L128
|
16,426 |
fhs/gompd
|
mpd/commandlist.go
|
SetVolume
|
func (cl *CommandList) SetVolume(volume int) {
cl.cmdQ.PushBack(&command{fmt.Sprintf("setvol %d", volume), nil, cmdNoReturn})
}
|
go
|
func (cl *CommandList) SetVolume(volume int) {
cl.cmdQ.PushBack(&command{fmt.Sprintf("setvol %d", volume), nil, cmdNoReturn})
}
|
[
"func",
"(",
"cl",
"*",
"CommandList",
")",
"SetVolume",
"(",
"volume",
"int",
")",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"volume",
")",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}"
] |
// SetVolume sets the MPD volume level.
|
[
"SetVolume",
"sets",
"the",
"MPD",
"volume",
"level",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L152-L154
|
16,427 |
fhs/gompd
|
mpd/commandlist.go
|
SetPriority
|
func (cl *CommandList) SetPriority(priority, start, end int) error {
if start < 0 {
return errors.New("negative start index")
}
if end < 0 {
cl.cmdQ.PushBack(&command{fmt.Sprintf("prio %d %d", priority, start), nil, cmdNoReturn})
} else {
cl.cmdQ.PushBack(&command{fmt.Sprintf("prio %d %d:%d", priority, start, end), nil, cmdNoReturn})
}
return nil
}
|
go
|
func (cl *CommandList) SetPriority(priority, start, end int) error {
if start < 0 {
return errors.New("negative start index")
}
if end < 0 {
cl.cmdQ.PushBack(&command{fmt.Sprintf("prio %d %d", priority, start), nil, cmdNoReturn})
} else {
cl.cmdQ.PushBack(&command{fmt.Sprintf("prio %d %d:%d", priority, start, end), nil, cmdNoReturn})
}
return nil
}
|
[
"func",
"(",
"cl",
"*",
"CommandList",
")",
"SetPriority",
"(",
"priority",
",",
"start",
",",
"end",
"int",
")",
"error",
"{",
"if",
"start",
"<",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"end",
"<",
"0",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"priority",
",",
"start",
")",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}",
"else",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"priority",
",",
"start",
",",
"end",
")",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
//
// Playlist related functions
//
// SetPriority sets the priority for songs in the playlist. If both start and
// end are non-negative, it updates those at positions in range [start, end).
// If end is negative, it updates the song at position start.
|
[
"Playlist",
"related",
"functions",
"SetPriority",
"sets",
"the",
"priority",
"for",
"songs",
"in",
"the",
"playlist",
".",
"If",
"both",
"start",
"and",
"end",
"are",
"non",
"-",
"negative",
"it",
"updates",
"those",
"at",
"positions",
"in",
"range",
"[",
"start",
"end",
")",
".",
"If",
"end",
"is",
"negative",
"it",
"updates",
"the",
"song",
"at",
"position",
"start",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L199-L209
|
16,428 |
fhs/gompd
|
mpd/commandlist.go
|
SetPriorityID
|
func (cl *CommandList) SetPriorityID(priority, id int) {
cl.cmdQ.PushBack(&command{fmt.Sprintf("prioid %d %d", priority, id), nil, cmdNoReturn})
}
|
go
|
func (cl *CommandList) SetPriorityID(priority, id int) {
cl.cmdQ.PushBack(&command{fmt.Sprintf("prioid %d %d", priority, id), nil, cmdNoReturn})
}
|
[
"func",
"(",
"cl",
"*",
"CommandList",
")",
"SetPriorityID",
"(",
"priority",
",",
"id",
"int",
")",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"priority",
",",
"id",
")",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}"
] |
// SetPriorityID sets the priority for the song identified by id.
|
[
"SetPriorityID",
"sets",
"the",
"priority",
"for",
"the",
"song",
"identified",
"by",
"id",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L212-L214
|
16,429 |
fhs/gompd
|
mpd/commandlist.go
|
MoveID
|
func (cl *CommandList) MoveID(songid, position int) {
cl.cmdQ.PushBack(&command{fmt.Sprintf("moveid %d %d", songid, position), nil, cmdNoReturn})
}
|
go
|
func (cl *CommandList) MoveID(songid, position int) {
cl.cmdQ.PushBack(&command{fmt.Sprintf("moveid %d %d", songid, position), nil, cmdNoReturn})
}
|
[
"func",
"(",
"cl",
"*",
"CommandList",
")",
"MoveID",
"(",
"songid",
",",
"position",
"int",
")",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"songid",
",",
"position",
")",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}"
] |
// MoveID moves songid to position on the playlist.
|
[
"MoveID",
"moves",
"songid",
"to",
"position",
"on",
"the",
"playlist",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L251-L253
|
16,430 |
fhs/gompd
|
mpd/commandlist.go
|
PlaylistLoad
|
func (cl *CommandList) PlaylistLoad(name string, start, end int) {
if start < 0 || end < 0 {
cl.cmdQ.PushBack(&command{fmt.Sprintf("load %s", quote(name)), nil, cmdNoReturn})
} else {
cl.cmdQ.PushBack(&command{fmt.Sprintf("load %s %d:%d", quote(name), start, end), nil, cmdNoReturn})
}
}
|
go
|
func (cl *CommandList) PlaylistLoad(name string, start, end int) {
if start < 0 || end < 0 {
cl.cmdQ.PushBack(&command{fmt.Sprintf("load %s", quote(name)), nil, cmdNoReturn})
} else {
cl.cmdQ.PushBack(&command{fmt.Sprintf("load %s %d:%d", quote(name), start, end), nil, cmdNoReturn})
}
}
|
[
"func",
"(",
"cl",
"*",
"CommandList",
")",
"PlaylistLoad",
"(",
"name",
"string",
",",
"start",
",",
"end",
"int",
")",
"{",
"if",
"start",
"<",
"0",
"||",
"end",
"<",
"0",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"quote",
"(",
"name",
")",
")",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}",
"else",
"{",
"cl",
".",
"cmdQ",
".",
"PushBack",
"(",
"&",
"command",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"quote",
"(",
"name",
")",
",",
"start",
",",
"end",
")",
",",
"nil",
",",
"cmdNoReturn",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// Stored playlists related commands.
// PlaylistLoad loads the specfied playlist into the current queue.
// If start and end are non-negative, only songs in this range are loaded.
|
[
"Stored",
"playlists",
"related",
"commands",
".",
"PlaylistLoad",
"loads",
"the",
"specfied",
"playlist",
"into",
"the",
"current",
"queue",
".",
"If",
"start",
"and",
"end",
"are",
"non",
"-",
"negative",
"only",
"songs",
"in",
"this",
"range",
"are",
"loaded",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L302-L308
|
16,431 |
fhs/gompd
|
mpd/commandlist.go
|
End
|
func (cl *CommandList) End() error {
// Tell MPD to start an OK command list:
beginID, beginErr := cl.client.cmd("command_list_ok_begin")
if beginErr != nil {
return beginErr
}
cl.client.text.StartResponse(beginID)
cl.client.text.EndResponse(beginID)
// Ensure the queue is cleared regardless.
defer cl.cmdQ.Init()
// Issue all of the queued up commands in the list:
for e := cl.cmdQ.Front(); e != nil; e = e.Next() {
cmdID, cmdErr := cl.client.cmd(e.Value.(*command).cmd)
if cmdErr != nil {
return cmdErr
}
cl.client.text.StartResponse(cmdID)
cl.client.text.EndResponse(cmdID)
}
// Tell MPD to end the command list and do the operations.
endID, endErr := cl.client.cmd("command_list_end")
if endErr != nil {
return endErr
}
cl.client.text.StartResponse(endID)
defer cl.client.text.EndResponse(endID)
// Get the responses back and check for errors:
for e := cl.cmdQ.Front(); e != nil; e = e.Next() {
switch e.Value.(*command).typeOf {
case cmdNoReturn:
if err := cl.client.readOKLine("list_OK"); err != nil {
return err
}
case cmdAttrReturn:
a, aErr := cl.client.readAttrs("list_OK")
if aErr != nil {
return aErr
}
pa := e.Value.(*command).promise.(*PromisedAttrs)
pa.attrs = a
pa.computed = true
case cmdIDReturn:
a, aErr := cl.client.readAttrs("list_OK")
if aErr != nil {
return aErr
}
rid, ridErr := strconv.Atoi(a["Id"])
if ridErr != nil {
return ridErr
}
*(e.Value.(*command).promise.(*PromisedID)) = PromisedID(rid)
}
}
// Finalize the command list with the last OK:
return cl.client.readOKLine("OK")
}
|
go
|
func (cl *CommandList) End() error {
// Tell MPD to start an OK command list:
beginID, beginErr := cl.client.cmd("command_list_ok_begin")
if beginErr != nil {
return beginErr
}
cl.client.text.StartResponse(beginID)
cl.client.text.EndResponse(beginID)
// Ensure the queue is cleared regardless.
defer cl.cmdQ.Init()
// Issue all of the queued up commands in the list:
for e := cl.cmdQ.Front(); e != nil; e = e.Next() {
cmdID, cmdErr := cl.client.cmd(e.Value.(*command).cmd)
if cmdErr != nil {
return cmdErr
}
cl.client.text.StartResponse(cmdID)
cl.client.text.EndResponse(cmdID)
}
// Tell MPD to end the command list and do the operations.
endID, endErr := cl.client.cmd("command_list_end")
if endErr != nil {
return endErr
}
cl.client.text.StartResponse(endID)
defer cl.client.text.EndResponse(endID)
// Get the responses back and check for errors:
for e := cl.cmdQ.Front(); e != nil; e = e.Next() {
switch e.Value.(*command).typeOf {
case cmdNoReturn:
if err := cl.client.readOKLine("list_OK"); err != nil {
return err
}
case cmdAttrReturn:
a, aErr := cl.client.readAttrs("list_OK")
if aErr != nil {
return aErr
}
pa := e.Value.(*command).promise.(*PromisedAttrs)
pa.attrs = a
pa.computed = true
case cmdIDReturn:
a, aErr := cl.client.readAttrs("list_OK")
if aErr != nil {
return aErr
}
rid, ridErr := strconv.Atoi(a["Id"])
if ridErr != nil {
return ridErr
}
*(e.Value.(*command).promise.(*PromisedID)) = PromisedID(rid)
}
}
// Finalize the command list with the last OK:
return cl.client.readOKLine("OK")
}
|
[
"func",
"(",
"cl",
"*",
"CommandList",
")",
"End",
"(",
")",
"error",
"{",
"// Tell MPD to start an OK command list:",
"beginID",
",",
"beginErr",
":=",
"cl",
".",
"client",
".",
"cmd",
"(",
"\"",
"\"",
")",
"\n",
"if",
"beginErr",
"!=",
"nil",
"{",
"return",
"beginErr",
"\n",
"}",
"\n",
"cl",
".",
"client",
".",
"text",
".",
"StartResponse",
"(",
"beginID",
")",
"\n",
"cl",
".",
"client",
".",
"text",
".",
"EndResponse",
"(",
"beginID",
")",
"\n\n",
"// Ensure the queue is cleared regardless.",
"defer",
"cl",
".",
"cmdQ",
".",
"Init",
"(",
")",
"\n\n",
"// Issue all of the queued up commands in the list:",
"for",
"e",
":=",
"cl",
".",
"cmdQ",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"cmdID",
",",
"cmdErr",
":=",
"cl",
".",
"client",
".",
"cmd",
"(",
"e",
".",
"Value",
".",
"(",
"*",
"command",
")",
".",
"cmd",
")",
"\n",
"if",
"cmdErr",
"!=",
"nil",
"{",
"return",
"cmdErr",
"\n",
"}",
"\n",
"cl",
".",
"client",
".",
"text",
".",
"StartResponse",
"(",
"cmdID",
")",
"\n",
"cl",
".",
"client",
".",
"text",
".",
"EndResponse",
"(",
"cmdID",
")",
"\n",
"}",
"\n\n",
"// Tell MPD to end the command list and do the operations.",
"endID",
",",
"endErr",
":=",
"cl",
".",
"client",
".",
"cmd",
"(",
"\"",
"\"",
")",
"\n",
"if",
"endErr",
"!=",
"nil",
"{",
"return",
"endErr",
"\n",
"}",
"\n",
"cl",
".",
"client",
".",
"text",
".",
"StartResponse",
"(",
"endID",
")",
"\n",
"defer",
"cl",
".",
"client",
".",
"text",
".",
"EndResponse",
"(",
"endID",
")",
"\n\n",
"// Get the responses back and check for errors:",
"for",
"e",
":=",
"cl",
".",
"cmdQ",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"switch",
"e",
".",
"Value",
".",
"(",
"*",
"command",
")",
".",
"typeOf",
"{",
"case",
"cmdNoReturn",
":",
"if",
"err",
":=",
"cl",
".",
"client",
".",
"readOKLine",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"case",
"cmdAttrReturn",
":",
"a",
",",
"aErr",
":=",
"cl",
".",
"client",
".",
"readAttrs",
"(",
"\"",
"\"",
")",
"\n",
"if",
"aErr",
"!=",
"nil",
"{",
"return",
"aErr",
"\n",
"}",
"\n",
"pa",
":=",
"e",
".",
"Value",
".",
"(",
"*",
"command",
")",
".",
"promise",
".",
"(",
"*",
"PromisedAttrs",
")",
"\n",
"pa",
".",
"attrs",
"=",
"a",
"\n",
"pa",
".",
"computed",
"=",
"true",
"\n\n",
"case",
"cmdIDReturn",
":",
"a",
",",
"aErr",
":=",
"cl",
".",
"client",
".",
"readAttrs",
"(",
"\"",
"\"",
")",
"\n",
"if",
"aErr",
"!=",
"nil",
"{",
"return",
"aErr",
"\n",
"}",
"\n",
"rid",
",",
"ridErr",
":=",
"strconv",
".",
"Atoi",
"(",
"a",
"[",
"\"",
"\"",
"]",
")",
"\n",
"if",
"ridErr",
"!=",
"nil",
"{",
"return",
"ridErr",
"\n",
"}",
"\n",
"*",
"(",
"e",
".",
"Value",
".",
"(",
"*",
"command",
")",
".",
"promise",
".",
"(",
"*",
"PromisedID",
")",
")",
"=",
"PromisedID",
"(",
"rid",
")",
"\n\n",
"}",
"\n",
"}",
"\n\n",
"// Finalize the command list with the last OK:",
"return",
"cl",
".",
"client",
".",
"readOKLine",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// End executes the command list.
|
[
"End",
"executes",
"the",
"command",
"list",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/commandlist.go#L349-L414
|
16,432 |
fhs/gompd
|
mpd/response.go
|
Command
|
func (c *Client) Command(format string, args ...interface{}) *Command {
for i := range args {
switch s := args[i].(type) {
case Quoted: // ignore
case string:
args[i] = quote(s)
}
}
return &Command{
client: c,
cmd: fmt.Sprintf(format, args...),
}
}
|
go
|
func (c *Client) Command(format string, args ...interface{}) *Command {
for i := range args {
switch s := args[i].(type) {
case Quoted: // ignore
case string:
args[i] = quote(s)
}
}
return &Command{
client: c,
cmd: fmt.Sprintf(format, args...),
}
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Command",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Command",
"{",
"for",
"i",
":=",
"range",
"args",
"{",
"switch",
"s",
":=",
"args",
"[",
"i",
"]",
".",
"(",
"type",
")",
"{",
"case",
"Quoted",
":",
"// ignore",
"case",
"string",
":",
"args",
"[",
"i",
"]",
"=",
"quote",
"(",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Command",
"{",
"client",
":",
"c",
",",
"cmd",
":",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
",",
"}",
"\n",
"}"
] |
// Command returns a command that can be sent to MPD sever.
// It enables low-level access to MPD protocol and should be avoided if
// the user is not familiar with MPD protocol.
//
// Strings in args are automatically quoted so that spaces are preserved.
// Pass strings as Quoted type if this is not desired.
|
[
"Command",
"returns",
"a",
"command",
"that",
"can",
"be",
"sent",
"to",
"MPD",
"sever",
".",
"It",
"enables",
"low",
"-",
"level",
"access",
"to",
"MPD",
"protocol",
"and",
"should",
"be",
"avoided",
"if",
"the",
"user",
"is",
"not",
"familiar",
"with",
"MPD",
"protocol",
".",
"Strings",
"in",
"args",
"are",
"automatically",
"quoted",
"so",
"that",
"spaces",
"are",
"preserved",
".",
"Pass",
"strings",
"as",
"Quoted",
"type",
"if",
"this",
"is",
"not",
"desired",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/response.go#L18-L30
|
16,433 |
fhs/gompd
|
mpd/response.go
|
OK
|
func (cmd *Command) OK() error {
id, err := cmd.client.cmd(cmd.cmd)
if err != nil {
return err
}
cmd.client.text.StartResponse(id)
defer cmd.client.text.EndResponse(id)
return cmd.client.readOKLine("OK")
}
|
go
|
func (cmd *Command) OK() error {
id, err := cmd.client.cmd(cmd.cmd)
if err != nil {
return err
}
cmd.client.text.StartResponse(id)
defer cmd.client.text.EndResponse(id)
return cmd.client.readOKLine("OK")
}
|
[
"func",
"(",
"cmd",
"*",
"Command",
")",
"OK",
"(",
")",
"error",
"{",
"id",
",",
"err",
":=",
"cmd",
".",
"client",
".",
"cmd",
"(",
"cmd",
".",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"cmd",
".",
"client",
".",
"text",
".",
"StartResponse",
"(",
"id",
")",
"\n",
"defer",
"cmd",
".",
"client",
".",
"text",
".",
"EndResponse",
"(",
"id",
")",
"\n",
"return",
"cmd",
".",
"client",
".",
"readOKLine",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// OK sends command to server and checks for error.
|
[
"OK",
"sends",
"command",
"to",
"server",
"and",
"checks",
"for",
"error",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/response.go#L44-L52
|
16,434 |
fhs/gompd
|
mpd/response.go
|
Attrs
|
func (cmd *Command) Attrs() (Attrs, error) {
id, err := cmd.client.cmd(cmd.cmd)
if err != nil {
return nil, err
}
cmd.client.text.StartResponse(id)
defer cmd.client.text.EndResponse(id)
return cmd.client.readAttrs("OK")
}
|
go
|
func (cmd *Command) Attrs() (Attrs, error) {
id, err := cmd.client.cmd(cmd.cmd)
if err != nil {
return nil, err
}
cmd.client.text.StartResponse(id)
defer cmd.client.text.EndResponse(id)
return cmd.client.readAttrs("OK")
}
|
[
"func",
"(",
"cmd",
"*",
"Command",
")",
"Attrs",
"(",
")",
"(",
"Attrs",
",",
"error",
")",
"{",
"id",
",",
"err",
":=",
"cmd",
".",
"client",
".",
"cmd",
"(",
"cmd",
".",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cmd",
".",
"client",
".",
"text",
".",
"StartResponse",
"(",
"id",
")",
"\n",
"defer",
"cmd",
".",
"client",
".",
"text",
".",
"EndResponse",
"(",
"id",
")",
"\n",
"return",
"cmd",
".",
"client",
".",
"readAttrs",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// Attrs sends command to server and reads attributes returned in response.
|
[
"Attrs",
"sends",
"command",
"to",
"server",
"and",
"reads",
"attributes",
"returned",
"in",
"response",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/response.go#L55-L63
|
16,435 |
fhs/gompd
|
mpd/response.go
|
AttrsList
|
func (cmd *Command) AttrsList(startKey string) ([]Attrs, error) {
id, err := cmd.client.cmd(cmd.cmd)
if err != nil {
return nil, err
}
cmd.client.text.StartResponse(id)
defer cmd.client.text.EndResponse(id)
return cmd.client.readAttrsList(startKey)
}
|
go
|
func (cmd *Command) AttrsList(startKey string) ([]Attrs, error) {
id, err := cmd.client.cmd(cmd.cmd)
if err != nil {
return nil, err
}
cmd.client.text.StartResponse(id)
defer cmd.client.text.EndResponse(id)
return cmd.client.readAttrsList(startKey)
}
|
[
"func",
"(",
"cmd",
"*",
"Command",
")",
"AttrsList",
"(",
"startKey",
"string",
")",
"(",
"[",
"]",
"Attrs",
",",
"error",
")",
"{",
"id",
",",
"err",
":=",
"cmd",
".",
"client",
".",
"cmd",
"(",
"cmd",
".",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cmd",
".",
"client",
".",
"text",
".",
"StartResponse",
"(",
"id",
")",
"\n",
"defer",
"cmd",
".",
"client",
".",
"text",
".",
"EndResponse",
"(",
"id",
")",
"\n",
"return",
"cmd",
".",
"client",
".",
"readAttrsList",
"(",
"startKey",
")",
"\n",
"}"
] |
// AttrsList sends command to server and reads a list of attributes returned in response.
// Each attribute group starts with key startKey.
|
[
"AttrsList",
"sends",
"command",
"to",
"server",
"and",
"reads",
"a",
"list",
"of",
"attributes",
"returned",
"in",
"response",
".",
"Each",
"attribute",
"group",
"starts",
"with",
"key",
"startKey",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/response.go#L67-L75
|
16,436 |
fhs/gompd
|
mpd/response.go
|
Strings
|
func (cmd *Command) Strings(key string) ([]string, error) {
id, err := cmd.client.cmd(cmd.cmd)
if err != nil {
return nil, err
}
cmd.client.text.StartResponse(id)
defer cmd.client.text.EndResponse(id)
return cmd.client.readList(key)
}
|
go
|
func (cmd *Command) Strings(key string) ([]string, error) {
id, err := cmd.client.cmd(cmd.cmd)
if err != nil {
return nil, err
}
cmd.client.text.StartResponse(id)
defer cmd.client.text.EndResponse(id)
return cmd.client.readList(key)
}
|
[
"func",
"(",
"cmd",
"*",
"Command",
")",
"Strings",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"id",
",",
"err",
":=",
"cmd",
".",
"client",
".",
"cmd",
"(",
"cmd",
".",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cmd",
".",
"client",
".",
"text",
".",
"StartResponse",
"(",
"id",
")",
"\n",
"defer",
"cmd",
".",
"client",
".",
"text",
".",
"EndResponse",
"(",
"id",
")",
"\n",
"return",
"cmd",
".",
"client",
".",
"readList",
"(",
"key",
")",
"\n",
"}"
] |
// Strings sends command to server and reads a list of strings returned in response.
// Each string have the key key.
|
[
"Strings",
"sends",
"command",
"to",
"server",
"and",
"reads",
"a",
"list",
"of",
"strings",
"returned",
"in",
"response",
".",
"Each",
"string",
"have",
"the",
"key",
"key",
"."
] |
e9f7b69903c5ed916cfc447488363d709ecd5492
|
https://github.com/fhs/gompd/blob/e9f7b69903c5ed916cfc447488363d709ecd5492/mpd/response.go#L79-L87
|
16,437 |
Unleash/unleash-client-go
|
debuglistener.go
|
OnCount
|
func (l DebugListener) OnCount(name string, enabled bool) {
fmt.Printf("Counted '%s' as enabled? %v\n", name, enabled)
}
|
go
|
func (l DebugListener) OnCount(name string, enabled bool) {
fmt.Printf("Counted '%s' as enabled? %v\n", name, enabled)
}
|
[
"func",
"(",
"l",
"DebugListener",
")",
"OnCount",
"(",
"name",
"string",
",",
"enabled",
"bool",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"name",
",",
"enabled",
")",
"\n",
"}"
] |
// OnCount prints to the console when the feature is queried.
|
[
"OnCount",
"prints",
"to",
"the",
"console",
"when",
"the",
"feature",
"is",
"queried",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/debuglistener.go#L28-L30
|
16,438 |
Unleash/unleash-client-go
|
config.go
|
WithRefreshInterval
|
func WithRefreshInterval(refreshInterval time.Duration) ConfigOption {
return func(o *configOption) {
o.refreshInterval = refreshInterval
}
}
|
go
|
func WithRefreshInterval(refreshInterval time.Duration) ConfigOption {
return func(o *configOption) {
o.refreshInterval = refreshInterval
}
}
|
[
"func",
"WithRefreshInterval",
"(",
"refreshInterval",
"time",
".",
"Duration",
")",
"ConfigOption",
"{",
"return",
"func",
"(",
"o",
"*",
"configOption",
")",
"{",
"o",
".",
"refreshInterval",
"=",
"refreshInterval",
"\n",
"}",
"\n",
"}"
] |
// WithRefreshInterval specifies the time interval with which the client should sync the
// feature toggles from the unleash server.
|
[
"WithRefreshInterval",
"specifies",
"the",
"time",
"interval",
"with",
"which",
"the",
"client",
"should",
"sync",
"the",
"feature",
"toggles",
"from",
"the",
"unleash",
"server",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/config.go#L64-L68
|
16,439 |
Unleash/unleash-client-go
|
config.go
|
WithMetricsInterval
|
func WithMetricsInterval(metricsInterval time.Duration) ConfigOption {
return func(o *configOption) {
o.metricsInterval = metricsInterval
}
}
|
go
|
func WithMetricsInterval(metricsInterval time.Duration) ConfigOption {
return func(o *configOption) {
o.metricsInterval = metricsInterval
}
}
|
[
"func",
"WithMetricsInterval",
"(",
"metricsInterval",
"time",
".",
"Duration",
")",
"ConfigOption",
"{",
"return",
"func",
"(",
"o",
"*",
"configOption",
")",
"{",
"o",
".",
"metricsInterval",
"=",
"metricsInterval",
"\n",
"}",
"\n",
"}"
] |
// WithMetricsInterval specifies the times interval woth which the client should upload
// the metrics data to the unleash server.
|
[
"WithMetricsInterval",
"specifies",
"the",
"times",
"interval",
"woth",
"which",
"the",
"client",
"should",
"upload",
"the",
"metrics",
"data",
"to",
"the",
"unleash",
"server",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/config.go#L72-L76
|
16,440 |
Unleash/unleash-client-go
|
config.go
|
WithHttpClient
|
func WithHttpClient(client *http.Client) ConfigOption {
return func(o *configOption) {
o.httpClient = client
}
}
|
go
|
func WithHttpClient(client *http.Client) ConfigOption {
return func(o *configOption) {
o.httpClient = client
}
}
|
[
"func",
"WithHttpClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"ConfigOption",
"{",
"return",
"func",
"(",
"o",
"*",
"configOption",
")",
"{",
"o",
".",
"httpClient",
"=",
"client",
"\n",
"}",
"\n",
"}"
] |
// WithHttpClient specifies which HttpClient the client should use for making requests to the server.
|
[
"WithHttpClient",
"specifies",
"which",
"HttpClient",
"the",
"client",
"should",
"use",
"for",
"making",
"requests",
"to",
"the",
"server",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/config.go#L110-L114
|
16,441 |
Unleash/unleash-client-go
|
config.go
|
WithCustomHeaders
|
func WithCustomHeaders(headers http.Header) ConfigOption {
return func(o *configOption) {
o.customHeaders = headers
}
}
|
go
|
func WithCustomHeaders(headers http.Header) ConfigOption {
return func(o *configOption) {
o.customHeaders = headers
}
}
|
[
"func",
"WithCustomHeaders",
"(",
"headers",
"http",
".",
"Header",
")",
"ConfigOption",
"{",
"return",
"func",
"(",
"o",
"*",
"configOption",
")",
"{",
"o",
".",
"customHeaders",
"=",
"headers",
"\n",
"}",
"\n",
"}"
] |
// WithCustomHeaders specifies any custom headers that should be sent along with requests to the
// server.
|
[
"WithCustomHeaders",
"specifies",
"any",
"custom",
"headers",
"that",
"should",
"be",
"sent",
"along",
"with",
"requests",
"to",
"the",
"server",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/config.go#L118-L122
|
16,442 |
Unleash/unleash-client-go
|
config.go
|
WithContext
|
func WithContext(ctx context.Context) FeatureOption {
return func(opts *featureOption) {
opts.ctx = &ctx
}
}
|
go
|
func WithContext(ctx context.Context) FeatureOption {
return func(opts *featureOption) {
opts.ctx = &ctx
}
}
|
[
"func",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"FeatureOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"featureOption",
")",
"{",
"opts",
".",
"ctx",
"=",
"&",
"ctx",
"\n",
"}",
"\n",
"}"
] |
// WithContext allows the user to provide a context that will be passed into the active strategy
// for determining if a specified feature should be enabled or not.
|
[
"WithContext",
"allows",
"the",
"user",
"to",
"provide",
"a",
"context",
"that",
"will",
"be",
"passed",
"into",
"the",
"active",
"strategy",
"for",
"determining",
"if",
"a",
"specified",
"feature",
"should",
"be",
"enabled",
"or",
"not",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/config.go#L142-L146
|
16,443 |
Unleash/unleash-client-go
|
unleash.go
|
IsEnabled
|
func IsEnabled(feature string, options ...FeatureOption) bool {
return defaultClient.IsEnabled(feature, options...)
}
|
go
|
func IsEnabled(feature string, options ...FeatureOption) bool {
return defaultClient.IsEnabled(feature, options...)
}
|
[
"func",
"IsEnabled",
"(",
"feature",
"string",
",",
"options",
"...",
"FeatureOption",
")",
"bool",
"{",
"return",
"defaultClient",
".",
"IsEnabled",
"(",
"feature",
",",
"options",
"...",
")",
"\n",
"}"
] |
// IsEnabled queries the default client whether or not the specified feature is enabled or not.
|
[
"IsEnabled",
"queries",
"the",
"default",
"client",
"whether",
"or",
"not",
"the",
"specified",
"feature",
"is",
"enabled",
"or",
"not",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/unleash.go#L37-L39
|
16,444 |
Unleash/unleash-client-go
|
client.go
|
IsEnabled
|
func (uc Client) IsEnabled(feature string, options ...FeatureOption) (enabled bool) {
defer func() {
uc.metrics.count(feature, enabled)
}()
f := uc.repository.getToggle(feature)
var opts featureOption
for _, o := range options {
o(&opts)
}
if f == nil {
if opts.fallback != nil {
return *opts.fallback
}
return false
}
if !f.Enabled {
return false
}
for _, s := range f.Strategies {
foundStrategy := uc.getStrategy(s.Name)
if foundStrategy == nil {
// TODO: warnOnce missingStrategy
continue
}
if foundStrategy.IsEnabled(s.Parameters, opts.ctx) {
return true
}
}
return false
}
|
go
|
func (uc Client) IsEnabled(feature string, options ...FeatureOption) (enabled bool) {
defer func() {
uc.metrics.count(feature, enabled)
}()
f := uc.repository.getToggle(feature)
var opts featureOption
for _, o := range options {
o(&opts)
}
if f == nil {
if opts.fallback != nil {
return *opts.fallback
}
return false
}
if !f.Enabled {
return false
}
for _, s := range f.Strategies {
foundStrategy := uc.getStrategy(s.Name)
if foundStrategy == nil {
// TODO: warnOnce missingStrategy
continue
}
if foundStrategy.IsEnabled(s.Parameters, opts.ctx) {
return true
}
}
return false
}
|
[
"func",
"(",
"uc",
"Client",
")",
"IsEnabled",
"(",
"feature",
"string",
",",
"options",
"...",
"FeatureOption",
")",
"(",
"enabled",
"bool",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"uc",
".",
"metrics",
".",
"count",
"(",
"feature",
",",
"enabled",
")",
"\n",
"}",
"(",
")",
"\n\n",
"f",
":=",
"uc",
".",
"repository",
".",
"getToggle",
"(",
"feature",
")",
"\n\n",
"var",
"opts",
"featureOption",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"options",
"{",
"o",
"(",
"&",
"opts",
")",
"\n",
"}",
"\n\n",
"if",
"f",
"==",
"nil",
"{",
"if",
"opts",
".",
"fallback",
"!=",
"nil",
"{",
"return",
"*",
"opts",
".",
"fallback",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"!",
"f",
".",
"Enabled",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"s",
":=",
"range",
"f",
".",
"Strategies",
"{",
"foundStrategy",
":=",
"uc",
".",
"getStrategy",
"(",
"s",
".",
"Name",
")",
"\n",
"if",
"foundStrategy",
"==",
"nil",
"{",
"// TODO: warnOnce missingStrategy",
"continue",
"\n",
"}",
"\n",
"if",
"foundStrategy",
".",
"IsEnabled",
"(",
"s",
".",
"Parameters",
",",
"opts",
".",
"ctx",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsEnabled queries whether or not the specified feature is enabled or not.
|
[
"IsEnabled",
"queries",
"whether",
"or",
"not",
"the",
"specified",
"feature",
"is",
"enabled",
"or",
"not",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/client.go#L217-L251
|
16,445 |
Unleash/unleash-client-go
|
client.go
|
Close
|
func (uc *Client) Close() error {
uc.repository.Close()
uc.metrics.Close()
uc.closed <- true
return nil
}
|
go
|
func (uc *Client) Close() error {
uc.repository.Close()
uc.metrics.Close()
uc.closed <- true
return nil
}
|
[
"func",
"(",
"uc",
"*",
"Client",
")",
"Close",
"(",
")",
"error",
"{",
"uc",
".",
"repository",
".",
"Close",
"(",
")",
"\n",
"uc",
".",
"metrics",
".",
"Close",
"(",
")",
"\n",
"uc",
".",
"closed",
"<-",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close stops the client from syncing data from the server.
|
[
"Close",
"stops",
"the",
"client",
"from",
"syncing",
"data",
"from",
"the",
"server",
"."
] |
9febc6ff26f48b744f0ad7b94adffb197b2f300c
|
https://github.com/Unleash/unleash-client-go/blob/9febc6ff26f48b744f0ad7b94adffb197b2f300c/client.go#L254-L259
|
16,446 |
tidwall/match
|
match.go
|
Allowable
|
func Allowable(pattern string) (min, max string) {
if pattern == "" || pattern[0] == '*' {
return "", ""
}
minb := make([]byte, 0, len(pattern))
maxb := make([]byte, 0, len(pattern))
var wild bool
for i := 0; i < len(pattern); i++ {
if pattern[i] == '*' {
wild = true
break
}
if pattern[i] == '?' {
minb = append(minb, 0)
maxb = append(maxb, maxRuneBytes...)
} else {
minb = append(minb, pattern[i])
maxb = append(maxb, pattern[i])
}
}
if wild {
r, n := utf8.DecodeLastRune(maxb)
if r != utf8.RuneError {
if r < utf8.MaxRune {
r++
if r > 0x7f {
b := make([]byte, 4)
nn := utf8.EncodeRune(b, r)
maxb = append(maxb[:len(maxb)-n], b[:nn]...)
} else {
maxb = append(maxb[:len(maxb)-n], byte(r))
}
}
}
}
return string(minb), string(maxb)
}
|
go
|
func Allowable(pattern string) (min, max string) {
if pattern == "" || pattern[0] == '*' {
return "", ""
}
minb := make([]byte, 0, len(pattern))
maxb := make([]byte, 0, len(pattern))
var wild bool
for i := 0; i < len(pattern); i++ {
if pattern[i] == '*' {
wild = true
break
}
if pattern[i] == '?' {
minb = append(minb, 0)
maxb = append(maxb, maxRuneBytes...)
} else {
minb = append(minb, pattern[i])
maxb = append(maxb, pattern[i])
}
}
if wild {
r, n := utf8.DecodeLastRune(maxb)
if r != utf8.RuneError {
if r < utf8.MaxRune {
r++
if r > 0x7f {
b := make([]byte, 4)
nn := utf8.EncodeRune(b, r)
maxb = append(maxb[:len(maxb)-n], b[:nn]...)
} else {
maxb = append(maxb[:len(maxb)-n], byte(r))
}
}
}
}
return string(minb), string(maxb)
}
|
[
"func",
"Allowable",
"(",
"pattern",
"string",
")",
"(",
"min",
",",
"max",
"string",
")",
"{",
"if",
"pattern",
"==",
"\"",
"\"",
"||",
"pattern",
"[",
"0",
"]",
"==",
"'*'",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
"\n",
"}",
"\n\n",
"minb",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"pattern",
")",
")",
"\n",
"maxb",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"pattern",
")",
")",
"\n",
"var",
"wild",
"bool",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"pattern",
")",
";",
"i",
"++",
"{",
"if",
"pattern",
"[",
"i",
"]",
"==",
"'*'",
"{",
"wild",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"pattern",
"[",
"i",
"]",
"==",
"'?'",
"{",
"minb",
"=",
"append",
"(",
"minb",
",",
"0",
")",
"\n",
"maxb",
"=",
"append",
"(",
"maxb",
",",
"maxRuneBytes",
"...",
")",
"\n",
"}",
"else",
"{",
"minb",
"=",
"append",
"(",
"minb",
",",
"pattern",
"[",
"i",
"]",
")",
"\n",
"maxb",
"=",
"append",
"(",
"maxb",
",",
"pattern",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"wild",
"{",
"r",
",",
"n",
":=",
"utf8",
".",
"DecodeLastRune",
"(",
"maxb",
")",
"\n",
"if",
"r",
"!=",
"utf8",
".",
"RuneError",
"{",
"if",
"r",
"<",
"utf8",
".",
"MaxRune",
"{",
"r",
"++",
"\n",
"if",
"r",
">",
"0x7f",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",
"nn",
":=",
"utf8",
".",
"EncodeRune",
"(",
"b",
",",
"r",
")",
"\n",
"maxb",
"=",
"append",
"(",
"maxb",
"[",
":",
"len",
"(",
"maxb",
")",
"-",
"n",
"]",
",",
"b",
"[",
":",
"nn",
"]",
"...",
")",
"\n",
"}",
"else",
"{",
"maxb",
"=",
"append",
"(",
"maxb",
"[",
":",
"len",
"(",
"maxb",
")",
"-",
"n",
"]",
",",
"byte",
"(",
"r",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"string",
"(",
"minb",
")",
",",
"string",
"(",
"maxb",
")",
"\n",
"}"
] |
// Allowable parses the pattern and determines the minimum and maximum allowable
// values that the pattern can represent.
// When the max cannot be determined, 'true' will be returned
// for infinite.
|
[
"Allowable",
"parses",
"the",
"pattern",
"and",
"determines",
"the",
"minimum",
"and",
"maximum",
"allowable",
"values",
"that",
"the",
"pattern",
"can",
"represent",
".",
"When",
"the",
"max",
"cannot",
"be",
"determined",
"true",
"will",
"be",
"returned",
"for",
"infinite",
"."
] |
33827db735fff6510490d69a8622612558a557ed
|
https://github.com/tidwall/match/blob/33827db735fff6510490d69a8622612558a557ed/match.go#L134-L171
|
16,447 |
tidwall/match
|
match.go
|
IsPattern
|
func IsPattern(str string) bool {
for i := 0; i < len(str); i++ {
if str[i] == '*' || str[i] == '?' {
return true
}
}
return false
}
|
go
|
func IsPattern(str string) bool {
for i := 0; i < len(str); i++ {
if str[i] == '*' || str[i] == '?' {
return true
}
}
return false
}
|
[
"func",
"IsPattern",
"(",
"str",
"string",
")",
"bool",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"str",
")",
";",
"i",
"++",
"{",
"if",
"str",
"[",
"i",
"]",
"==",
"'*'",
"||",
"str",
"[",
"i",
"]",
"==",
"'?'",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsPattern returns true if the string is a pattern.
|
[
"IsPattern",
"returns",
"true",
"if",
"the",
"string",
"is",
"a",
"pattern",
"."
] |
33827db735fff6510490d69a8622612558a557ed
|
https://github.com/tidwall/match/blob/33827db735fff6510490d69a8622612558a557ed/match.go#L174-L181
|
16,448 |
socketplane/libovsdb
|
notation.go
|
MarshalJSON
|
func (o Operation) MarshalJSON() ([]byte, error) {
type OpAlias Operation
switch o.Op {
case "select":
where := o.Where
if where == nil {
where = make([]interface{}, 0, 0)
}
return json.Marshal(&struct {
Where []interface{} `json:"where"`
OpAlias
}{
Where: where,
OpAlias: (OpAlias)(o),
})
default:
return json.Marshal(&struct {
OpAlias
}{
OpAlias: (OpAlias)(o),
})
}
}
|
go
|
func (o Operation) MarshalJSON() ([]byte, error) {
type OpAlias Operation
switch o.Op {
case "select":
where := o.Where
if where == nil {
where = make([]interface{}, 0, 0)
}
return json.Marshal(&struct {
Where []interface{} `json:"where"`
OpAlias
}{
Where: where,
OpAlias: (OpAlias)(o),
})
default:
return json.Marshal(&struct {
OpAlias
}{
OpAlias: (OpAlias)(o),
})
}
}
|
[
"func",
"(",
"o",
"Operation",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"type",
"OpAlias",
"Operation",
"\n",
"switch",
"o",
".",
"Op",
"{",
"case",
"\"",
"\"",
":",
"where",
":=",
"o",
".",
"Where",
"\n",
"if",
"where",
"==",
"nil",
"{",
"where",
"=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
",",
"0",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"Where",
"[",
"]",
"interface",
"{",
"}",
"`json:\"where\"`",
"\n",
"OpAlias",
"\n",
"}",
"{",
"Where",
":",
"where",
",",
"OpAlias",
":",
"(",
"OpAlias",
")",
"(",
"o",
")",
",",
"}",
")",
"\n",
"default",
":",
"return",
"json",
".",
"Marshal",
"(",
"&",
"struct",
"{",
"OpAlias",
"\n",
"}",
"{",
"OpAlias",
":",
"(",
"OpAlias",
")",
"(",
"o",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// MarshalJSON marshalls 'Operation' to a byte array
// For 'select' operations, we dont omit the 'Where' field
// to allow selecting all rows of a table
|
[
"MarshalJSON",
"marshalls",
"Operation",
"to",
"a",
"byte",
"array",
"For",
"select",
"operations",
"we",
"dont",
"omit",
"the",
"Where",
"field",
"to",
"allow",
"selecting",
"all",
"rows",
"of",
"a",
"table"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/notation.go#L22-L44
|
16,449 |
socketplane/libovsdb
|
map.go
|
MarshalJSON
|
func (o OvsMap) MarshalJSON() ([]byte, error) {
var ovsMap, innerMap []interface{}
ovsMap = append(ovsMap, "map")
for key, val := range o.GoMap {
var mapSeg []interface{}
mapSeg = append(mapSeg, key)
mapSeg = append(mapSeg, val)
innerMap = append(innerMap, mapSeg)
}
ovsMap = append(ovsMap, innerMap)
return json.Marshal(ovsMap)
}
|
go
|
func (o OvsMap) MarshalJSON() ([]byte, error) {
var ovsMap, innerMap []interface{}
ovsMap = append(ovsMap, "map")
for key, val := range o.GoMap {
var mapSeg []interface{}
mapSeg = append(mapSeg, key)
mapSeg = append(mapSeg, val)
innerMap = append(innerMap, mapSeg)
}
ovsMap = append(ovsMap, innerMap)
return json.Marshal(ovsMap)
}
|
[
"func",
"(",
"o",
"OvsMap",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"ovsMap",
",",
"innerMap",
"[",
"]",
"interface",
"{",
"}",
"\n",
"ovsMap",
"=",
"append",
"(",
"ovsMap",
",",
"\"",
"\"",
")",
"\n",
"for",
"key",
",",
"val",
":=",
"range",
"o",
".",
"GoMap",
"{",
"var",
"mapSeg",
"[",
"]",
"interface",
"{",
"}",
"\n",
"mapSeg",
"=",
"append",
"(",
"mapSeg",
",",
"key",
")",
"\n",
"mapSeg",
"=",
"append",
"(",
"mapSeg",
",",
"val",
")",
"\n",
"innerMap",
"=",
"append",
"(",
"innerMap",
",",
"mapSeg",
")",
"\n",
"}",
"\n",
"ovsMap",
"=",
"append",
"(",
"ovsMap",
",",
"innerMap",
")",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"ovsMap",
")",
"\n",
"}"
] |
// MarshalJSON marshalls an OVSDB style Map to a byte array
|
[
"MarshalJSON",
"marshalls",
"an",
"OVSDB",
"style",
"Map",
"to",
"a",
"byte",
"array"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/map.go#L21-L32
|
16,450 |
socketplane/libovsdb
|
map.go
|
UnmarshalJSON
|
func (o *OvsMap) UnmarshalJSON(b []byte) (err error) {
var oMap []interface{}
o.GoMap = make(map[interface{}]interface{})
if err := json.Unmarshal(b, &oMap); err == nil && len(oMap) > 1 {
innerSlice := oMap[1].([]interface{})
for _, val := range innerSlice {
f := val.([]interface{})
o.GoMap[f[0]] = f[1]
}
}
return err
}
|
go
|
func (o *OvsMap) UnmarshalJSON(b []byte) (err error) {
var oMap []interface{}
o.GoMap = make(map[interface{}]interface{})
if err := json.Unmarshal(b, &oMap); err == nil && len(oMap) > 1 {
innerSlice := oMap[1].([]interface{})
for _, val := range innerSlice {
f := val.([]interface{})
o.GoMap[f[0]] = f[1]
}
}
return err
}
|
[
"func",
"(",
"o",
"*",
"OvsMap",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"var",
"oMap",
"[",
"]",
"interface",
"{",
"}",
"\n",
"o",
".",
"GoMap",
"=",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"oMap",
")",
";",
"err",
"==",
"nil",
"&&",
"len",
"(",
"oMap",
")",
">",
"1",
"{",
"innerSlice",
":=",
"oMap",
"[",
"1",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"innerSlice",
"{",
"f",
":=",
"val",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"o",
".",
"GoMap",
"[",
"f",
"[",
"0",
"]",
"]",
"=",
"f",
"[",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// UnmarshalJSON unmarshalls an OVSDB style Map from a byte array
|
[
"UnmarshalJSON",
"unmarshalls",
"an",
"OVSDB",
"style",
"Map",
"from",
"a",
"byte",
"array"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/map.go#L35-L46
|
16,451 |
socketplane/libovsdb
|
map.go
|
NewOvsMap
|
func NewOvsMap(goMap interface{}) (*OvsMap, error) {
v := reflect.ValueOf(goMap)
if v.Kind() != reflect.Map {
return nil, errors.New("OvsMap supports only Go Map types")
}
genMap := make(map[interface{}]interface{})
keys := v.MapKeys()
for _, key := range keys {
genMap[key.Interface()] = v.MapIndex(key).Interface()
}
return &OvsMap{genMap}, nil
}
|
go
|
func NewOvsMap(goMap interface{}) (*OvsMap, error) {
v := reflect.ValueOf(goMap)
if v.Kind() != reflect.Map {
return nil, errors.New("OvsMap supports only Go Map types")
}
genMap := make(map[interface{}]interface{})
keys := v.MapKeys()
for _, key := range keys {
genMap[key.Interface()] = v.MapIndex(key).Interface()
}
return &OvsMap{genMap}, nil
}
|
[
"func",
"NewOvsMap",
"(",
"goMap",
"interface",
"{",
"}",
")",
"(",
"*",
"OvsMap",
",",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"goMap",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Map",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"genMap",
":=",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"keys",
":=",
"v",
".",
"MapKeys",
"(",
")",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"genMap",
"[",
"key",
".",
"Interface",
"(",
")",
"]",
"=",
"v",
".",
"MapIndex",
"(",
"key",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"return",
"&",
"OvsMap",
"{",
"genMap",
"}",
",",
"nil",
"\n",
"}"
] |
// NewOvsMap will return an OVSDB style map from a provided Golang Map
|
[
"NewOvsMap",
"will",
"return",
"an",
"OVSDB",
"style",
"map",
"from",
"a",
"provided",
"Golang",
"Map"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/map.go#L49-L61
|
16,452 |
socketplane/libovsdb
|
set.go
|
NewOvsSet
|
func NewOvsSet(goSlice interface{}) (*OvsSet, error) {
v := reflect.ValueOf(goSlice)
if v.Kind() != reflect.Slice {
return nil, errors.New("OvsSet supports only Go Slice types")
}
var ovsSet []interface{}
for i := 0; i < v.Len(); i++ {
ovsSet = append(ovsSet, v.Index(i).Interface())
}
return &OvsSet{ovsSet}, nil
}
|
go
|
func NewOvsSet(goSlice interface{}) (*OvsSet, error) {
v := reflect.ValueOf(goSlice)
if v.Kind() != reflect.Slice {
return nil, errors.New("OvsSet supports only Go Slice types")
}
var ovsSet []interface{}
for i := 0; i < v.Len(); i++ {
ovsSet = append(ovsSet, v.Index(i).Interface())
}
return &OvsSet{ovsSet}, nil
}
|
[
"func",
"NewOvsSet",
"(",
"goSlice",
"interface",
"{",
"}",
")",
"(",
"*",
"OvsSet",
",",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"goSlice",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Slice",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"ovsSet",
"[",
"]",
"interface",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"v",
".",
"Len",
"(",
")",
";",
"i",
"++",
"{",
"ovsSet",
"=",
"append",
"(",
"ovsSet",
",",
"v",
".",
"Index",
"(",
"i",
")",
".",
"Interface",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"OvsSet",
"{",
"ovsSet",
"}",
",",
"nil",
"\n",
"}"
] |
// NewOvsSet creates a new OVSDB style set from a Go slice
|
[
"NewOvsSet",
"creates",
"a",
"new",
"OVSDB",
"style",
"set",
"from",
"a",
"Go",
"slice"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/set.go#L21-L32
|
16,453 |
socketplane/libovsdb
|
set.go
|
MarshalJSON
|
func (o OvsSet) MarshalJSON() ([]byte, error) {
var oSet []interface{}
oSet = append(oSet, "set")
oSet = append(oSet, o.GoSet)
return json.Marshal(oSet)
}
|
go
|
func (o OvsSet) MarshalJSON() ([]byte, error) {
var oSet []interface{}
oSet = append(oSet, "set")
oSet = append(oSet, o.GoSet)
return json.Marshal(oSet)
}
|
[
"func",
"(",
"o",
"OvsSet",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"oSet",
"[",
"]",
"interface",
"{",
"}",
"\n",
"oSet",
"=",
"append",
"(",
"oSet",
",",
"\"",
"\"",
")",
"\n",
"oSet",
"=",
"append",
"(",
"oSet",
",",
"o",
".",
"GoSet",
")",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"oSet",
")",
"\n",
"}"
] |
// MarshalJSON wil marshal an OVSDB style set in to a JSON byte array
|
[
"MarshalJSON",
"wil",
"marshal",
"an",
"OVSDB",
"style",
"set",
"in",
"to",
"a",
"JSON",
"byte",
"array"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/set.go#L35-L40
|
16,454 |
socketplane/libovsdb
|
set.go
|
UnmarshalJSON
|
func (o *OvsSet) UnmarshalJSON(b []byte) (err error) {
var oSet []interface{}
if err = json.Unmarshal(b, &oSet); err == nil && len(oSet) > 1 {
innerSet := oSet[1].([]interface{})
for _, val := range innerSet {
goVal, err := ovsSliceToGoNotation(val)
if err == nil {
o.GoSet = append(o.GoSet, goVal)
}
}
}
return err
}
|
go
|
func (o *OvsSet) UnmarshalJSON(b []byte) (err error) {
var oSet []interface{}
if err = json.Unmarshal(b, &oSet); err == nil && len(oSet) > 1 {
innerSet := oSet[1].([]interface{})
for _, val := range innerSet {
goVal, err := ovsSliceToGoNotation(val)
if err == nil {
o.GoSet = append(o.GoSet, goVal)
}
}
}
return err
}
|
[
"func",
"(",
"o",
"*",
"OvsSet",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"var",
"oSet",
"[",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"oSet",
")",
";",
"err",
"==",
"nil",
"&&",
"len",
"(",
"oSet",
")",
">",
"1",
"{",
"innerSet",
":=",
"oSet",
"[",
"1",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"innerSet",
"{",
"goVal",
",",
"err",
":=",
"ovsSliceToGoNotation",
"(",
"val",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"o",
".",
"GoSet",
"=",
"append",
"(",
"o",
".",
"GoSet",
",",
"goVal",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// UnmarshalJSON will unmarshal a JSON byte array to an OVSDB style set
|
[
"UnmarshalJSON",
"will",
"unmarshal",
"a",
"JSON",
"byte",
"array",
"to",
"an",
"OVSDB",
"style",
"set"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/set.go#L43-L55
|
16,455 |
socketplane/libovsdb
|
row.go
|
UnmarshalJSON
|
func (r *Row) UnmarshalJSON(b []byte) (err error) {
r.Fields = make(map[string]interface{})
var raw map[string]interface{}
err = json.Unmarshal(b, &raw)
for key, val := range raw {
val, err = ovsSliceToGoNotation(val)
if err != nil {
return err
}
r.Fields[key] = val
}
return err
}
|
go
|
func (r *Row) UnmarshalJSON(b []byte) (err error) {
r.Fields = make(map[string]interface{})
var raw map[string]interface{}
err = json.Unmarshal(b, &raw)
for key, val := range raw {
val, err = ovsSliceToGoNotation(val)
if err != nil {
return err
}
r.Fields[key] = val
}
return err
}
|
[
"func",
"(",
"r",
"*",
"Row",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"r",
".",
"Fields",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"var",
"raw",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"raw",
")",
"\n",
"for",
"key",
",",
"val",
":=",
"range",
"raw",
"{",
"val",
",",
"err",
"=",
"ovsSliceToGoNotation",
"(",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"r",
".",
"Fields",
"[",
"key",
"]",
"=",
"val",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// UnmarshalJSON unmarshalls a byte array to an OVSDB Row
|
[
"UnmarshalJSON",
"unmarshalls",
"a",
"byte",
"array",
"to",
"an",
"OVSDB",
"Row"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/row.go#L11-L23
|
16,456 |
socketplane/libovsdb
|
schema.go
|
Print
|
func (schema DatabaseSchema) Print(w io.Writer) {
fmt.Fprintf(w, "%s, (%s)\n", schema.Name, schema.Version)
for table, tableSchema := range schema.Tables {
fmt.Fprintf(w, "\t %s\n", table)
for column, columnSchema := range tableSchema.Columns {
fmt.Fprintf(w, "\t\t %s => %v\n", column, columnSchema)
}
}
}
|
go
|
func (schema DatabaseSchema) Print(w io.Writer) {
fmt.Fprintf(w, "%s, (%s)\n", schema.Name, schema.Version)
for table, tableSchema := range schema.Tables {
fmt.Fprintf(w, "\t %s\n", table)
for column, columnSchema := range tableSchema.Columns {
fmt.Fprintf(w, "\t\t %s => %v\n", column, columnSchema)
}
}
}
|
[
"func",
"(",
"schema",
"DatabaseSchema",
")",
"Print",
"(",
"w",
"io",
".",
"Writer",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\n",
"\"",
",",
"schema",
".",
"Name",
",",
"schema",
".",
"Version",
")",
"\n",
"for",
"table",
",",
"tableSchema",
":=",
"range",
"schema",
".",
"Tables",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"table",
")",
"\n",
"for",
"column",
",",
"columnSchema",
":=",
"range",
"tableSchema",
".",
"Columns",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"\"",
"\\t",
"\\t",
"\\n",
"\"",
",",
"column",
",",
"columnSchema",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Print will print the contents of the DatabaseSchema
|
[
"Print",
"will",
"print",
"the",
"contents",
"of",
"the",
"DatabaseSchema"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/schema.go#L30-L38
|
16,457 |
socketplane/libovsdb
|
schema.go
|
validateOperations
|
func (schema DatabaseSchema) validateOperations(operations ...Operation) bool {
for _, op := range operations {
table, ok := schema.Tables[op.Table]
if ok {
for column := range op.Row {
if _, ok := table.Columns[column]; !ok {
return false
}
}
for _, row := range op.Rows {
for column := range row {
if _, ok := table.Columns[column]; !ok {
return false
}
}
}
for _, column := range op.Columns {
if _, ok := table.Columns[column]; !ok {
return false
}
}
} else {
return false
}
}
return true
}
|
go
|
func (schema DatabaseSchema) validateOperations(operations ...Operation) bool {
for _, op := range operations {
table, ok := schema.Tables[op.Table]
if ok {
for column := range op.Row {
if _, ok := table.Columns[column]; !ok {
return false
}
}
for _, row := range op.Rows {
for column := range row {
if _, ok := table.Columns[column]; !ok {
return false
}
}
}
for _, column := range op.Columns {
if _, ok := table.Columns[column]; !ok {
return false
}
}
} else {
return false
}
}
return true
}
|
[
"func",
"(",
"schema",
"DatabaseSchema",
")",
"validateOperations",
"(",
"operations",
"...",
"Operation",
")",
"bool",
"{",
"for",
"_",
",",
"op",
":=",
"range",
"operations",
"{",
"table",
",",
"ok",
":=",
"schema",
".",
"Tables",
"[",
"op",
".",
"Table",
"]",
"\n",
"if",
"ok",
"{",
"for",
"column",
":=",
"range",
"op",
".",
"Row",
"{",
"if",
"_",
",",
"ok",
":=",
"table",
".",
"Columns",
"[",
"column",
"]",
";",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"op",
".",
"Rows",
"{",
"for",
"column",
":=",
"range",
"row",
"{",
"if",
"_",
",",
"ok",
":=",
"table",
".",
"Columns",
"[",
"column",
"]",
";",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"column",
":=",
"range",
"op",
".",
"Columns",
"{",
"if",
"_",
",",
"ok",
":=",
"table",
".",
"Columns",
"[",
"column",
"]",
";",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// Basic validation for operations against Database Schema
|
[
"Basic",
"validation",
"for",
"operations",
"against",
"Database",
"Schema"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/schema.go#L41-L67
|
16,458 |
socketplane/libovsdb
|
rpc.go
|
NewTransactArgs
|
func NewTransactArgs(database string, operations ...Operation) []interface{} {
dbSlice := make([]interface{}, 1)
dbSlice[0] = database
opsSlice := make([]interface{}, len(operations))
for i, d := range operations {
opsSlice[i] = d
}
ops := append(dbSlice, opsSlice...)
return ops
}
|
go
|
func NewTransactArgs(database string, operations ...Operation) []interface{} {
dbSlice := make([]interface{}, 1)
dbSlice[0] = database
opsSlice := make([]interface{}, len(operations))
for i, d := range operations {
opsSlice[i] = d
}
ops := append(dbSlice, opsSlice...)
return ops
}
|
[
"func",
"NewTransactArgs",
"(",
"database",
"string",
",",
"operations",
"...",
"Operation",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"dbSlice",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"1",
")",
"\n",
"dbSlice",
"[",
"0",
"]",
"=",
"database",
"\n\n",
"opsSlice",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"operations",
")",
")",
"\n",
"for",
"i",
",",
"d",
":=",
"range",
"operations",
"{",
"opsSlice",
"[",
"i",
"]",
"=",
"d",
"\n",
"}",
"\n\n",
"ops",
":=",
"append",
"(",
"dbSlice",
",",
"opsSlice",
"...",
")",
"\n",
"return",
"ops",
"\n",
"}"
] |
// NewTransactArgs creates a new set of arguments for a transact RPC
|
[
"NewTransactArgs",
"creates",
"a",
"new",
"set",
"of",
"arguments",
"for",
"a",
"transact",
"RPC"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/rpc.go#L9-L20
|
16,459 |
socketplane/libovsdb
|
rpc.go
|
NewMonitorArgs
|
func NewMonitorArgs(database string, value interface{}, requests map[string]MonitorRequest) []interface{} {
return []interface{}{database, value, requests}
}
|
go
|
func NewMonitorArgs(database string, value interface{}, requests map[string]MonitorRequest) []interface{} {
return []interface{}{database, value, requests}
}
|
[
"func",
"NewMonitorArgs",
"(",
"database",
"string",
",",
"value",
"interface",
"{",
"}",
",",
"requests",
"map",
"[",
"string",
"]",
"MonitorRequest",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"return",
"[",
"]",
"interface",
"{",
"}",
"{",
"database",
",",
"value",
",",
"requests",
"}",
"\n",
"}"
] |
// NewMonitorArgs creates a new set of arguments for a monitor RPC
|
[
"NewMonitorArgs",
"creates",
"a",
"new",
"set",
"of",
"arguments",
"for",
"a",
"monitor",
"RPC"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/rpc.go#L28-L30
|
16,460 |
socketplane/libovsdb
|
uuid.go
|
MarshalJSON
|
func (u UUID) MarshalJSON() ([]byte, error) {
var uuidSlice []string
err := u.validateUUID()
if err == nil {
uuidSlice = []string{"uuid", u.GoUUID}
} else {
uuidSlice = []string{"named-uuid", u.GoUUID}
}
return json.Marshal(uuidSlice)
}
|
go
|
func (u UUID) MarshalJSON() ([]byte, error) {
var uuidSlice []string
err := u.validateUUID()
if err == nil {
uuidSlice = []string{"uuid", u.GoUUID}
} else {
uuidSlice = []string{"named-uuid", u.GoUUID}
}
return json.Marshal(uuidSlice)
}
|
[
"func",
"(",
"u",
"UUID",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"uuidSlice",
"[",
"]",
"string",
"\n",
"err",
":=",
"u",
".",
"validateUUID",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"uuidSlice",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"u",
".",
"GoUUID",
"}",
"\n",
"}",
"else",
"{",
"uuidSlice",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"u",
".",
"GoUUID",
"}",
"\n",
"}",
"\n\n",
"return",
"json",
".",
"Marshal",
"(",
"uuidSlice",
")",
"\n",
"}"
] |
// MarshalJSON will marshal an OVSDB style UUID to a JSON encoded byte array
|
[
"MarshalJSON",
"will",
"marshal",
"an",
"OVSDB",
"style",
"UUID",
"to",
"a",
"JSON",
"encoded",
"byte",
"array"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/uuid.go#L15-L25
|
16,461 |
socketplane/libovsdb
|
uuid.go
|
UnmarshalJSON
|
func (u *UUID) UnmarshalJSON(b []byte) (err error) {
var ovsUUID []string
if err := json.Unmarshal(b, &ovsUUID); err == nil {
u.GoUUID = ovsUUID[1]
}
return err
}
|
go
|
func (u *UUID) UnmarshalJSON(b []byte) (err error) {
var ovsUUID []string
if err := json.Unmarshal(b, &ovsUUID); err == nil {
u.GoUUID = ovsUUID[1]
}
return err
}
|
[
"func",
"(",
"u",
"*",
"UUID",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"var",
"ovsUUID",
"[",
"]",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"ovsUUID",
")",
";",
"err",
"==",
"nil",
"{",
"u",
".",
"GoUUID",
"=",
"ovsUUID",
"[",
"1",
"]",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// UnmarshalJSON will unmarshal a JSON encoded byte array to a OVSDB style UUID
|
[
"UnmarshalJSON",
"will",
"unmarshal",
"a",
"JSON",
"encoded",
"byte",
"array",
"to",
"a",
"OVSDB",
"style",
"UUID"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/uuid.go#L28-L34
|
16,462 |
socketplane/libovsdb
|
client.go
|
ConnectUsingProtocol
|
func ConnectUsingProtocol(protocol string, target string) (*OvsdbClient, error) {
conn, err := net.Dial(protocol, target)
if err != nil {
return nil, err
}
c := rpc2.NewClientWithCodec(jsonrpc.NewJSONCodec(conn))
c.Handle("echo", echo)
c.Handle("update", update)
go c.Run()
go handleDisconnectNotification(c)
ovs := newOvsdbClient(c)
// Process Async Notifications
dbs, err := ovs.ListDbs()
if err == nil {
for _, db := range dbs {
schema, err := ovs.GetSchema(db)
if err == nil {
ovs.Schema[db] = *schema
} else {
return nil, err
}
}
}
return ovs, nil
}
|
go
|
func ConnectUsingProtocol(protocol string, target string) (*OvsdbClient, error) {
conn, err := net.Dial(protocol, target)
if err != nil {
return nil, err
}
c := rpc2.NewClientWithCodec(jsonrpc.NewJSONCodec(conn))
c.Handle("echo", echo)
c.Handle("update", update)
go c.Run()
go handleDisconnectNotification(c)
ovs := newOvsdbClient(c)
// Process Async Notifications
dbs, err := ovs.ListDbs()
if err == nil {
for _, db := range dbs {
schema, err := ovs.GetSchema(db)
if err == nil {
ovs.Schema[db] = *schema
} else {
return nil, err
}
}
}
return ovs, nil
}
|
[
"func",
"ConnectUsingProtocol",
"(",
"protocol",
"string",
",",
"target",
"string",
")",
"(",
"*",
"OvsdbClient",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"net",
".",
"Dial",
"(",
"protocol",
",",
"target",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"c",
":=",
"rpc2",
".",
"NewClientWithCodec",
"(",
"jsonrpc",
".",
"NewJSONCodec",
"(",
"conn",
")",
")",
"\n",
"c",
".",
"Handle",
"(",
"\"",
"\"",
",",
"echo",
")",
"\n",
"c",
".",
"Handle",
"(",
"\"",
"\"",
",",
"update",
")",
"\n",
"go",
"c",
".",
"Run",
"(",
")",
"\n",
"go",
"handleDisconnectNotification",
"(",
"c",
")",
"\n\n",
"ovs",
":=",
"newOvsdbClient",
"(",
"c",
")",
"\n\n",
"// Process Async Notifications",
"dbs",
",",
"err",
":=",
"ovs",
".",
"ListDbs",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"for",
"_",
",",
"db",
":=",
"range",
"dbs",
"{",
"schema",
",",
"err",
":=",
"ovs",
".",
"GetSchema",
"(",
"db",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"ovs",
".",
"Schema",
"[",
"db",
"]",
"=",
"*",
"schema",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ovs",
",",
"nil",
"\n",
"}"
] |
// ConnectUsingProtocol creates an OVSDB connection and returns and OvsdbClient
|
[
"ConnectUsingProtocol",
"creates",
"an",
"OVSDB",
"connection",
"and",
"returns",
"and",
"OvsdbClient"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/client.go#L53-L81
|
16,463 |
socketplane/libovsdb
|
client.go
|
Connect
|
func Connect(ipAddr string, port int) (*OvsdbClient, error) {
if ipAddr == "" {
ipAddr = DefaultAddress
}
if port <= 0 {
port = DefaultPort
}
target := fmt.Sprintf("%s:%d", ipAddr, port)
return ConnectUsingProtocol("tcp", target)
}
|
go
|
func Connect(ipAddr string, port int) (*OvsdbClient, error) {
if ipAddr == "" {
ipAddr = DefaultAddress
}
if port <= 0 {
port = DefaultPort
}
target := fmt.Sprintf("%s:%d", ipAddr, port)
return ConnectUsingProtocol("tcp", target)
}
|
[
"func",
"Connect",
"(",
"ipAddr",
"string",
",",
"port",
"int",
")",
"(",
"*",
"OvsdbClient",
",",
"error",
")",
"{",
"if",
"ipAddr",
"==",
"\"",
"\"",
"{",
"ipAddr",
"=",
"DefaultAddress",
"\n",
"}",
"\n\n",
"if",
"port",
"<=",
"0",
"{",
"port",
"=",
"DefaultPort",
"\n",
"}",
"\n\n",
"target",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ipAddr",
",",
"port",
")",
"\n",
"return",
"ConnectUsingProtocol",
"(",
"\"",
"\"",
",",
"target",
")",
"\n",
"}"
] |
// Connect creates an OVSDB connection and returns and OvsdbClient
|
[
"Connect",
"creates",
"an",
"OVSDB",
"connection",
"and",
"returns",
"and",
"OvsdbClient"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/client.go#L84-L95
|
16,464 |
socketplane/libovsdb
|
client.go
|
ConnectWithUnixSocket
|
func ConnectWithUnixSocket(socketFile string) (*OvsdbClient, error) {
if _, err := os.Stat(socketFile); os.IsNotExist(err) {
return nil, errors.New("Invalid socket file")
}
return ConnectUsingProtocol("unix", socketFile)
}
|
go
|
func ConnectWithUnixSocket(socketFile string) (*OvsdbClient, error) {
if _, err := os.Stat(socketFile); os.IsNotExist(err) {
return nil, errors.New("Invalid socket file")
}
return ConnectUsingProtocol("unix", socketFile)
}
|
[
"func",
"ConnectWithUnixSocket",
"(",
"socketFile",
"string",
")",
"(",
"*",
"OvsdbClient",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"socketFile",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"ConnectUsingProtocol",
"(",
"\"",
"\"",
",",
"socketFile",
")",
"\n",
"}"
] |
// ConnectWithUnixSocket makes a OVSDB Connection via a Unix Socket
|
[
"ConnectWithUnixSocket",
"makes",
"a",
"OVSDB",
"Connection",
"via",
"a",
"Unix",
"Socket"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/client.go#L98-L105
|
16,465 |
socketplane/libovsdb
|
client.go
|
Register
|
func (ovs *OvsdbClient) Register(handler NotificationHandler) {
ovs.handlersMutex.Lock()
defer ovs.handlersMutex.Unlock()
ovs.handlers = append(ovs.handlers, handler)
}
|
go
|
func (ovs *OvsdbClient) Register(handler NotificationHandler) {
ovs.handlersMutex.Lock()
defer ovs.handlersMutex.Unlock()
ovs.handlers = append(ovs.handlers, handler)
}
|
[
"func",
"(",
"ovs",
"*",
"OvsdbClient",
")",
"Register",
"(",
"handler",
"NotificationHandler",
")",
"{",
"ovs",
".",
"handlersMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ovs",
".",
"handlersMutex",
".",
"Unlock",
"(",
")",
"\n",
"ovs",
".",
"handlers",
"=",
"append",
"(",
"ovs",
".",
"handlers",
",",
"handler",
")",
"\n",
"}"
] |
// Register registers the supplied NotificationHandler to recieve OVSDB Notifications
|
[
"Register",
"registers",
"the",
"supplied",
"NotificationHandler",
"to",
"recieve",
"OVSDB",
"Notifications"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/client.go#L108-L112
|
16,466 |
socketplane/libovsdb
|
client.go
|
getHandlerIndex
|
func getHandlerIndex(handler NotificationHandler, handlers []NotificationHandler) (int, error) {
for i, h := range handlers {
if reflect.DeepEqual(h, handler) {
return i, nil
}
}
return -1, errors.New("Handler not found")
}
|
go
|
func getHandlerIndex(handler NotificationHandler, handlers []NotificationHandler) (int, error) {
for i, h := range handlers {
if reflect.DeepEqual(h, handler) {
return i, nil
}
}
return -1, errors.New("Handler not found")
}
|
[
"func",
"getHandlerIndex",
"(",
"handler",
"NotificationHandler",
",",
"handlers",
"[",
"]",
"NotificationHandler",
")",
"(",
"int",
",",
"error",
")",
"{",
"for",
"i",
",",
"h",
":=",
"range",
"handlers",
"{",
"if",
"reflect",
".",
"DeepEqual",
"(",
"h",
",",
"handler",
")",
"{",
"return",
"i",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
//Get Handler by index
|
[
"Get",
"Handler",
"by",
"index"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/client.go#L115-L122
|
16,467 |
socketplane/libovsdb
|
client.go
|
Unregister
|
func (ovs *OvsdbClient) Unregister(handler NotificationHandler) error {
ovs.handlersMutex.Lock()
defer ovs.handlersMutex.Unlock()
i, err := getHandlerIndex(handler, ovs.handlers)
if err != nil {
return err
}
ovs.handlers = append(ovs.handlers[:i], ovs.handlers[i+1:]...)
return nil
}
|
go
|
func (ovs *OvsdbClient) Unregister(handler NotificationHandler) error {
ovs.handlersMutex.Lock()
defer ovs.handlersMutex.Unlock()
i, err := getHandlerIndex(handler, ovs.handlers)
if err != nil {
return err
}
ovs.handlers = append(ovs.handlers[:i], ovs.handlers[i+1:]...)
return nil
}
|
[
"func",
"(",
"ovs",
"*",
"OvsdbClient",
")",
"Unregister",
"(",
"handler",
"NotificationHandler",
")",
"error",
"{",
"ovs",
".",
"handlersMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ovs",
".",
"handlersMutex",
".",
"Unlock",
"(",
")",
"\n",
"i",
",",
"err",
":=",
"getHandlerIndex",
"(",
"handler",
",",
"ovs",
".",
"handlers",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ovs",
".",
"handlers",
"=",
"append",
"(",
"ovs",
".",
"handlers",
"[",
":",
"i",
"]",
",",
"ovs",
".",
"handlers",
"[",
"i",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Unregister the supplied NotificationHandler to not recieve OVSDB Notifications anymore
|
[
"Unregister",
"the",
"supplied",
"NotificationHandler",
"to",
"not",
"recieve",
"OVSDB",
"Notifications",
"anymore"
] |
4de3618546deba09d8875d719752db32bd4652c0
|
https://github.com/socketplane/libovsdb/blob/4de3618546deba09d8875d719752db32bd4652c0/client.go#L125-L134
|
16,468 |
tyler-sommer/stick
|
twig/escape.go
|
Init
|
func (e *AutoEscapeExtension) Init(env *stick.Env) error {
env.Visitors = append(env.Visitors, &autoEscapeVisitor{})
env.Filters["escape"] = func(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
ct := "html"
if len(args) > 0 {
ct = stick.CoerceString(args[0])
}
if sval, ok := val.(stick.SafeValue); ok {
if sval.IsSafe(ct) {
return val
}
}
escfn, ok := e.Escapers[ct]
if !ok {
// TODO: Communicate error, no escaper for the specified content type.
return val
}
return stick.NewSafeValue(escfn(stick.CoerceString(val)), ct)
}
return nil
}
|
go
|
func (e *AutoEscapeExtension) Init(env *stick.Env) error {
env.Visitors = append(env.Visitors, &autoEscapeVisitor{})
env.Filters["escape"] = func(ctx stick.Context, val stick.Value, args ...stick.Value) stick.Value {
ct := "html"
if len(args) > 0 {
ct = stick.CoerceString(args[0])
}
if sval, ok := val.(stick.SafeValue); ok {
if sval.IsSafe(ct) {
return val
}
}
escfn, ok := e.Escapers[ct]
if !ok {
// TODO: Communicate error, no escaper for the specified content type.
return val
}
return stick.NewSafeValue(escfn(stick.CoerceString(val)), ct)
}
return nil
}
|
[
"func",
"(",
"e",
"*",
"AutoEscapeExtension",
")",
"Init",
"(",
"env",
"*",
"stick",
".",
"Env",
")",
"error",
"{",
"env",
".",
"Visitors",
"=",
"append",
"(",
"env",
".",
"Visitors",
",",
"&",
"autoEscapeVisitor",
"{",
"}",
")",
"\n",
"env",
".",
"Filters",
"[",
"\"",
"\"",
"]",
"=",
"func",
"(",
"ctx",
"stick",
".",
"Context",
",",
"val",
"stick",
".",
"Value",
",",
"args",
"...",
"stick",
".",
"Value",
")",
"stick",
".",
"Value",
"{",
"ct",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"ct",
"=",
"stick",
".",
"CoerceString",
"(",
"args",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"if",
"sval",
",",
"ok",
":=",
"val",
".",
"(",
"stick",
".",
"SafeValue",
")",
";",
"ok",
"{",
"if",
"sval",
".",
"IsSafe",
"(",
"ct",
")",
"{",
"return",
"val",
"\n",
"}",
"\n",
"}",
"\n\n",
"escfn",
",",
"ok",
":=",
"e",
".",
"Escapers",
"[",
"ct",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// TODO: Communicate error, no escaper for the specified content type.",
"return",
"val",
"\n",
"}",
"\n\n",
"return",
"stick",
".",
"NewSafeValue",
"(",
"escfn",
"(",
"stick",
".",
"CoerceString",
"(",
"val",
")",
")",
",",
"ct",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Init registers the escape functionality with the given Env.
|
[
"Init",
"registers",
"the",
"escape",
"functionality",
"with",
"the",
"given",
"Env",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/escape.go#L21-L44
|
16,469 |
tyler-sommer/stick
|
twig/escape.go
|
NewAutoEscapeExtension
|
func NewAutoEscapeExtension() *AutoEscapeExtension {
return &AutoEscapeExtension{
Escapers: map[string]Escaper{
"html": escape.HTML,
"html_attr": escape.HTMLAttribute,
"js": escape.JS,
"css": escape.CSS,
"url": escape.URLQueryParam,
},
}
}
|
go
|
func NewAutoEscapeExtension() *AutoEscapeExtension {
return &AutoEscapeExtension{
Escapers: map[string]Escaper{
"html": escape.HTML,
"html_attr": escape.HTMLAttribute,
"js": escape.JS,
"css": escape.CSS,
"url": escape.URLQueryParam,
},
}
}
|
[
"func",
"NewAutoEscapeExtension",
"(",
")",
"*",
"AutoEscapeExtension",
"{",
"return",
"&",
"AutoEscapeExtension",
"{",
"Escapers",
":",
"map",
"[",
"string",
"]",
"Escaper",
"{",
"\"",
"\"",
":",
"escape",
".",
"HTML",
",",
"\"",
"\"",
":",
"escape",
".",
"HTMLAttribute",
",",
"\"",
"\"",
":",
"escape",
".",
"JS",
",",
"\"",
"\"",
":",
"escape",
".",
"CSS",
",",
"\"",
"\"",
":",
"escape",
".",
"URLQueryParam",
",",
"}",
",",
"}",
"\n",
"}"
] |
// NewAutoEscapeExtension returns an AutoEscapeExtension with Twig equivalent
// Escapers, by default.
|
[
"NewAutoEscapeExtension",
"returns",
"an",
"AutoEscapeExtension",
"with",
"Twig",
"equivalent",
"Escapers",
"by",
"default",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/escape.go#L48-L58
|
16,470 |
tyler-sommer/stick
|
twig/escape.go
|
push
|
func (v *autoEscapeVisitor) push(name string) {
v.stack = append(v.stack, name)
}
|
go
|
func (v *autoEscapeVisitor) push(name string) {
v.stack = append(v.stack, name)
}
|
[
"func",
"(",
"v",
"*",
"autoEscapeVisitor",
")",
"push",
"(",
"name",
"string",
")",
"{",
"v",
".",
"stack",
"=",
"append",
"(",
"v",
".",
"stack",
",",
"name",
")",
"\n",
"}"
] |
// push adds the given name on top of the stack.
|
[
"push",
"adds",
"the",
"given",
"name",
"on",
"top",
"of",
"the",
"stack",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/escape.go#L67-L69
|
16,471 |
tyler-sommer/stick
|
twig/escape.go
|
pop
|
func (v *autoEscapeVisitor) pop() {
v.stack = v.stack[0 : len(v.stack)-1]
}
|
go
|
func (v *autoEscapeVisitor) pop() {
v.stack = v.stack[0 : len(v.stack)-1]
}
|
[
"func",
"(",
"v",
"*",
"autoEscapeVisitor",
")",
"pop",
"(",
")",
"{",
"v",
".",
"stack",
"=",
"v",
".",
"stack",
"[",
"0",
":",
"len",
"(",
"v",
".",
"stack",
")",
"-",
"1",
"]",
"\n",
"}"
] |
// pop removes the top-most name on the stack.
|
[
"pop",
"removes",
"the",
"top",
"-",
"most",
"name",
"on",
"the",
"stack",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/escape.go#L72-L74
|
16,472 |
tyler-sommer/stick
|
exec.go
|
newState
|
func newState(name string, out io.Writer, ctx map[string]Value, env *Env) *state {
return &state{
out: out,
node: nil,
name: name,
meta: &metadata{make(map[string]string)},
blocks: make([]map[string]*parse.BlockNode, 0),
macros: make(map[string]*parse.MacroNode),
env: env,
scope: &scopeStack{[]map[string]Value{ctx}},
}
}
|
go
|
func newState(name string, out io.Writer, ctx map[string]Value, env *Env) *state {
return &state{
out: out,
node: nil,
name: name,
meta: &metadata{make(map[string]string)},
blocks: make([]map[string]*parse.BlockNode, 0),
macros: make(map[string]*parse.MacroNode),
env: env,
scope: &scopeStack{[]map[string]Value{ctx}},
}
}
|
[
"func",
"newState",
"(",
"name",
"string",
",",
"out",
"io",
".",
"Writer",
",",
"ctx",
"map",
"[",
"string",
"]",
"Value",
",",
"env",
"*",
"Env",
")",
"*",
"state",
"{",
"return",
"&",
"state",
"{",
"out",
":",
"out",
",",
"node",
":",
"nil",
",",
"name",
":",
"name",
",",
"meta",
":",
"&",
"metadata",
"{",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"}",
",",
"blocks",
":",
"make",
"(",
"[",
"]",
"map",
"[",
"string",
"]",
"*",
"parse",
".",
"BlockNode",
",",
"0",
")",
",",
"macros",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"parse",
".",
"MacroNode",
")",
",",
"env",
":",
"env",
",",
"scope",
":",
"&",
"scopeStack",
"{",
"[",
"]",
"map",
"[",
"string",
"]",
"Value",
"{",
"ctx",
"}",
"}",
",",
"}",
"\n",
"}"
] |
// newState creates a new template execution state, ready for use.
|
[
"newState",
"creates",
"a",
"new",
"template",
"execution",
"state",
"ready",
"for",
"use",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L34-L48
|
16,473 |
tyler-sommer/stick
|
exec.go
|
push
|
func (s *scopeStack) push() {
s.scopes = append(s.scopes, make(map[string]Value))
}
|
go
|
func (s *scopeStack) push() {
s.scopes = append(s.scopes, make(map[string]Value))
}
|
[
"func",
"(",
"s",
"*",
"scopeStack",
")",
"push",
"(",
")",
"{",
"s",
".",
"scopes",
"=",
"append",
"(",
"s",
".",
"scopes",
",",
"make",
"(",
"map",
"[",
"string",
"]",
"Value",
")",
")",
"\n",
"}"
] |
// push adds a scope on top of the stack.
|
[
"push",
"adds",
"a",
"scope",
"on",
"top",
"of",
"the",
"stack",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L105-L107
|
16,474 |
tyler-sommer/stick
|
exec.go
|
pop
|
func (s *scopeStack) pop() {
s.scopes = s.scopes[0 : len(s.scopes)-1]
}
|
go
|
func (s *scopeStack) pop() {
s.scopes = s.scopes[0 : len(s.scopes)-1]
}
|
[
"func",
"(",
"s",
"*",
"scopeStack",
")",
"pop",
"(",
")",
"{",
"s",
".",
"scopes",
"=",
"s",
".",
"scopes",
"[",
"0",
":",
"len",
"(",
"s",
".",
"scopes",
")",
"-",
"1",
"]",
"\n",
"}"
] |
// pop removes the top-most scope.
|
[
"pop",
"removes",
"the",
"top",
"-",
"most",
"scope",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L110-L112
|
16,475 |
tyler-sommer/stick
|
exec.go
|
All
|
func (s *scopeStack) All() map[string]Value {
res := make(map[string]Value)
for _, scope := range s.scopes {
for k, v := range scope {
res[k] = v
}
}
return res
}
|
go
|
func (s *scopeStack) All() map[string]Value {
res := make(map[string]Value)
for _, scope := range s.scopes {
for k, v := range scope {
res[k] = v
}
}
return res
}
|
[
"func",
"(",
"s",
"*",
"scopeStack",
")",
"All",
"(",
")",
"map",
"[",
"string",
"]",
"Value",
"{",
"res",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Value",
")",
"\n",
"for",
"_",
",",
"scope",
":=",
"range",
"s",
".",
"scopes",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"scope",
"{",
"res",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] |
// All returns a flat map of the current scope.
|
[
"All",
"returns",
"a",
"flat",
"map",
"of",
"the",
"current",
"scope",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L115-L123
|
16,476 |
tyler-sommer/stick
|
exec.go
|
getBlock
|
func (s *state) getBlock(name string) *parse.BlockNode {
for _, blocks := range s.blocks {
if block, ok := blocks[name]; ok {
return block
}
}
return nil
}
|
go
|
func (s *state) getBlock(name string) *parse.BlockNode {
for _, blocks := range s.blocks {
if block, ok := blocks[name]; ok {
return block
}
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"state",
")",
"getBlock",
"(",
"name",
"string",
")",
"*",
"parse",
".",
"BlockNode",
"{",
"for",
"_",
",",
"blocks",
":=",
"range",
"s",
".",
"blocks",
"{",
"if",
"block",
",",
"ok",
":=",
"blocks",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"block",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Method getBlock iterates through each set of blocks, returning the first
// block with the given name.
|
[
"Method",
"getBlock",
"iterates",
"through",
"each",
"set",
"of",
"blocks",
"returning",
"the",
"first",
"block",
"with",
"the",
"given",
"name",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L176-L184
|
16,477 |
tyler-sommer/stick
|
exec.go
|
walkChild
|
func (s *state) walkChild(node parse.Node) error {
switch node := node.(type) {
case *parse.BodyNode:
for _, c := range node.All() {
err := s.walkChild(c)
if err != nil {
return err
}
}
case *parse.UseNode:
return s.walkUseNode(node)
}
return nil
}
|
go
|
func (s *state) walkChild(node parse.Node) error {
switch node := node.(type) {
case *parse.BodyNode:
for _, c := range node.All() {
err := s.walkChild(c)
if err != nil {
return err
}
}
case *parse.UseNode:
return s.walkUseNode(node)
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"state",
")",
"walkChild",
"(",
"node",
"parse",
".",
"Node",
")",
"error",
"{",
"switch",
"node",
":=",
"node",
".",
"(",
"type",
")",
"{",
"case",
"*",
"parse",
".",
"BodyNode",
":",
"for",
"_",
",",
"c",
":=",
"range",
"node",
".",
"All",
"(",
")",
"{",
"err",
":=",
"s",
".",
"walkChild",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"*",
"parse",
".",
"UseNode",
":",
"return",
"s",
".",
"walkUseNode",
"(",
"node",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// walkChild only executes a subset of nodes, intended to be used on child templates.
|
[
"walkChild",
"only",
"executes",
"a",
"subset",
"of",
"nodes",
"intended",
"to",
"be",
"used",
"on",
"child",
"templates",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L299-L312
|
16,478 |
tyler-sommer/stick
|
exec.go
|
walkIncludeNode
|
func (s *state) walkIncludeNode(node *parse.IncludeNode) (tpl string, ctx map[string]Value, err error) {
ctx = make(map[string]Value)
v, err := s.evalExpr(node.Tpl)
if err != nil {
return "", nil, err
}
tpl = CoerceString(v)
var with Value
if n := node.With; n != nil {
with, err = s.evalExpr(n)
// TODO: Assert "with" is a hash?
if err != nil {
return "", nil, err
}
}
if !node.Only {
ctx = s.scope.All()
}
if with != nil {
if with, ok := with.(map[string]Value); ok {
for k, v := range with {
ctx[k] = v
}
}
}
return tpl, ctx, err
}
|
go
|
func (s *state) walkIncludeNode(node *parse.IncludeNode) (tpl string, ctx map[string]Value, err error) {
ctx = make(map[string]Value)
v, err := s.evalExpr(node.Tpl)
if err != nil {
return "", nil, err
}
tpl = CoerceString(v)
var with Value
if n := node.With; n != nil {
with, err = s.evalExpr(n)
// TODO: Assert "with" is a hash?
if err != nil {
return "", nil, err
}
}
if !node.Only {
ctx = s.scope.All()
}
if with != nil {
if with, ok := with.(map[string]Value); ok {
for k, v := range with {
ctx[k] = v
}
}
}
return tpl, ctx, err
}
|
[
"func",
"(",
"s",
"*",
"state",
")",
"walkIncludeNode",
"(",
"node",
"*",
"parse",
".",
"IncludeNode",
")",
"(",
"tpl",
"string",
",",
"ctx",
"map",
"[",
"string",
"]",
"Value",
",",
"err",
"error",
")",
"{",
"ctx",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Value",
")",
"\n",
"v",
",",
"err",
":=",
"s",
".",
"evalExpr",
"(",
"node",
".",
"Tpl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tpl",
"=",
"CoerceString",
"(",
"v",
")",
"\n",
"var",
"with",
"Value",
"\n",
"if",
"n",
":=",
"node",
".",
"With",
";",
"n",
"!=",
"nil",
"{",
"with",
",",
"err",
"=",
"s",
".",
"evalExpr",
"(",
"n",
")",
"\n",
"// TODO: Assert \"with\" is a hash?",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"node",
".",
"Only",
"{",
"ctx",
"=",
"s",
".",
"scope",
".",
"All",
"(",
")",
"\n",
"}",
"\n",
"if",
"with",
"!=",
"nil",
"{",
"if",
"with",
",",
"ok",
":=",
"with",
".",
"(",
"map",
"[",
"string",
"]",
"Value",
")",
";",
"ok",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"with",
"{",
"ctx",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"tpl",
",",
"ctx",
",",
"err",
"\n",
"}"
] |
// Method walkInclude determines the necessary parameters for including or embedding a template.
|
[
"Method",
"walkInclude",
"determines",
"the",
"necessary",
"parameters",
"for",
"including",
"or",
"embedding",
"a",
"template",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L347-L373
|
16,479 |
tyler-sommer/stick
|
exec.go
|
execute
|
func execute(name string, out io.Writer, ctx map[string]Value, env *Env) error {
if ctx == nil {
ctx = make(map[string]Value)
}
s := newState(name, out, ctx, env)
tree, err := s.env.load(name)
if err != nil {
return err
}
s.blocks = append(s.blocks, tree.Blocks())
err = s.walk(tree.Root())
if err != nil {
return err
}
return nil
}
|
go
|
func execute(name string, out io.Writer, ctx map[string]Value, env *Env) error {
if ctx == nil {
ctx = make(map[string]Value)
}
s := newState(name, out, ctx, env)
tree, err := s.env.load(name)
if err != nil {
return err
}
s.blocks = append(s.blocks, tree.Blocks())
err = s.walk(tree.Root())
if err != nil {
return err
}
return nil
}
|
[
"func",
"execute",
"(",
"name",
"string",
",",
"out",
"io",
".",
"Writer",
",",
"ctx",
"map",
"[",
"string",
"]",
"Value",
",",
"env",
"*",
"Env",
")",
"error",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"ctx",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Value",
")",
"\n",
"}",
"\n",
"s",
":=",
"newState",
"(",
"name",
",",
"out",
",",
"ctx",
",",
"env",
")",
"\n",
"tree",
",",
"err",
":=",
"s",
".",
"env",
".",
"load",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"blocks",
"=",
"append",
"(",
"s",
".",
"blocks",
",",
"tree",
".",
"Blocks",
"(",
")",
")",
"\n",
"err",
"=",
"s",
".",
"walk",
"(",
"tree",
".",
"Root",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// execute kicks off execution of the given template.
|
[
"execute",
"kicks",
"off",
"execution",
"of",
"the",
"given",
"template",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L801-L816
|
16,480 |
tyler-sommer/stick
|
exec.go
|
load
|
func (env *Env) load(name string) (*parse.Tree, error) {
tpl, err := env.Loader.Load(name)
if err != nil {
return nil, err
}
tree := parse.NewNamedTree(name, tpl.Contents())
tree.Visitors = append(tree.Visitors, env.Visitors...)
err = tree.Parse()
if err != nil {
return nil, err
}
return tree, nil
}
|
go
|
func (env *Env) load(name string) (*parse.Tree, error) {
tpl, err := env.Loader.Load(name)
if err != nil {
return nil, err
}
tree := parse.NewNamedTree(name, tpl.Contents())
tree.Visitors = append(tree.Visitors, env.Visitors...)
err = tree.Parse()
if err != nil {
return nil, err
}
return tree, nil
}
|
[
"func",
"(",
"env",
"*",
"Env",
")",
"load",
"(",
"name",
"string",
")",
"(",
"*",
"parse",
".",
"Tree",
",",
"error",
")",
"{",
"tpl",
",",
"err",
":=",
"env",
".",
"Loader",
".",
"Load",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tree",
":=",
"parse",
".",
"NewNamedTree",
"(",
"name",
",",
"tpl",
".",
"Contents",
"(",
")",
")",
"\n",
"tree",
".",
"Visitors",
"=",
"append",
"(",
"tree",
".",
"Visitors",
",",
"env",
".",
"Visitors",
"...",
")",
"\n",
"err",
"=",
"tree",
".",
"Parse",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"tree",
",",
"nil",
"\n",
"}"
] |
// Method load attempts to load and parse the given template.
|
[
"Method",
"load",
"attempts",
"to",
"load",
"and",
"parse",
"the",
"given",
"template",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/exec.go#L819-L831
|
16,481 |
tyler-sommer/stick
|
twig/escape/escape.go
|
HTML
|
func HTML(in string) string {
var out = &bytes.Buffer{}
for _, c := range in {
if c == 34 {
// "
out.WriteString(""")
} else if c == 38 {
// &
out.WriteString("&")
} else if c == 39 {
// '
out.WriteString("'")
} else if c == 60 {
// <
out.WriteString("<")
} else if c == 62 {
// >
out.WriteString(">")
} else {
// UTF-8
out.WriteRune(c)
}
}
return out.String()
}
|
go
|
func HTML(in string) string {
var out = &bytes.Buffer{}
for _, c := range in {
if c == 34 {
// "
out.WriteString(""")
} else if c == 38 {
// &
out.WriteString("&")
} else if c == 39 {
// '
out.WriteString("'")
} else if c == 60 {
// <
out.WriteString("<")
} else if c == 62 {
// >
out.WriteString(">")
} else {
// UTF-8
out.WriteRune(c)
}
}
return out.String()
}
|
[
"func",
"HTML",
"(",
"in",
"string",
")",
"string",
"{",
"var",
"out",
"=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"in",
"{",
"if",
"c",
"==",
"34",
"{",
"// \"",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
"==",
"38",
"{",
"// &",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
"==",
"39",
"{",
"// '",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
"==",
"60",
"{",
"// <",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
"==",
"62",
"{",
"// >",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"// UTF-8",
"out",
".",
"WriteRune",
"(",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"out",
".",
"String",
"(",
")",
"\n",
"}"
] |
// HTML provides a Twig-compatible HTML escape function.
|
[
"HTML",
"provides",
"a",
"Twig",
"-",
"compatible",
"HTML",
"escape",
"function",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/escape/escape.go#L10-L34
|
16,482 |
tyler-sommer/stick
|
twig/escape/escape.go
|
HTMLAttribute
|
func HTMLAttribute(in string) string {
var out = &bytes.Buffer{}
for _, c := range in {
if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c >= 44 && c <= 46) || c == 95 {
// a-zA-Z0-9,.-_
out.WriteRune(c)
} else if c == 34 {
// "
out.WriteString(""")
} else if c == 38 {
// &
out.WriteString("&")
} else if c == 60 {
// <
out.WriteString("<")
} else if c == 62 {
// >
out.WriteString(">")
} else if c <= 31 && c != 9 && c != 10 && c != 13 {
// Non-whitespace
out.WriteString("�")
} else {
// UTF-8
fmt.Fprintf(out, "&#%d;", c)
}
}
return out.String()
}
|
go
|
func HTMLAttribute(in string) string {
var out = &bytes.Buffer{}
for _, c := range in {
if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c >= 44 && c <= 46) || c == 95 {
// a-zA-Z0-9,.-_
out.WriteRune(c)
} else if c == 34 {
// "
out.WriteString(""")
} else if c == 38 {
// &
out.WriteString("&")
} else if c == 60 {
// <
out.WriteString("<")
} else if c == 62 {
// >
out.WriteString(">")
} else if c <= 31 && c != 9 && c != 10 && c != 13 {
// Non-whitespace
out.WriteString("�")
} else {
// UTF-8
fmt.Fprintf(out, "&#%d;", c)
}
}
return out.String()
}
|
[
"func",
"HTMLAttribute",
"(",
"in",
"string",
")",
"string",
"{",
"var",
"out",
"=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"in",
"{",
"if",
"(",
"c",
">=",
"65",
"&&",
"c",
"<=",
"90",
")",
"||",
"(",
"c",
">=",
"97",
"&&",
"c",
"<=",
"122",
")",
"||",
"(",
"c",
">=",
"48",
"&&",
"c",
"<=",
"57",
")",
"||",
"(",
"c",
">=",
"44",
"&&",
"c",
"<=",
"46",
")",
"||",
"c",
"==",
"95",
"{",
"// a-zA-Z0-9,.-_",
"out",
".",
"WriteRune",
"(",
"c",
")",
"\n",
"}",
"else",
"if",
"c",
"==",
"34",
"{",
"// \"",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
"==",
"38",
"{",
"// &",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
"==",
"60",
"{",
"// <",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
"==",
"62",
"{",
"// >",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
"<=",
"31",
"&&",
"c",
"!=",
"9",
"&&",
"c",
"!=",
"10",
"&&",
"c",
"!=",
"13",
"{",
"// Non-whitespace",
"out",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"// UTF-8",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\"",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"out",
".",
"String",
"(",
")",
"\n",
"}"
] |
// HTMLAttribute provides a Twig-compatible escaper for HTML attributes.
|
[
"HTMLAttribute",
"provides",
"a",
"Twig",
"-",
"compatible",
"escaper",
"for",
"HTML",
"attributes",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/escape/escape.go#L37-L64
|
16,483 |
tyler-sommer/stick
|
twig/escape/escape.go
|
JS
|
func JS(in string) string {
var out = &bytes.Buffer{}
for _, c := range in {
if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 44 || c == 46 || c == 95 {
// a-zA-Z0-9,._
out.WriteRune(c)
} else {
// UTF-8
fmt.Fprintf(out, "\\u%04X", c)
}
}
return out.String()
}
|
go
|
func JS(in string) string {
var out = &bytes.Buffer{}
for _, c := range in {
if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 44 || c == 46 || c == 95 {
// a-zA-Z0-9,._
out.WriteRune(c)
} else {
// UTF-8
fmt.Fprintf(out, "\\u%04X", c)
}
}
return out.String()
}
|
[
"func",
"JS",
"(",
"in",
"string",
")",
"string",
"{",
"var",
"out",
"=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"in",
"{",
"if",
"(",
"c",
">=",
"65",
"&&",
"c",
"<=",
"90",
")",
"||",
"(",
"c",
">=",
"97",
"&&",
"c",
"<=",
"122",
")",
"||",
"(",
"c",
">=",
"48",
"&&",
"c",
"<=",
"57",
")",
"||",
"c",
"==",
"44",
"||",
"c",
"==",
"46",
"||",
"c",
"==",
"95",
"{",
"// a-zA-Z0-9,._",
"out",
".",
"WriteRune",
"(",
"c",
")",
"\n",
"}",
"else",
"{",
"// UTF-8",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\\\",
"\"",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"out",
".",
"String",
"(",
")",
"\n",
"}"
] |
// JS provides a Twig-compatible javascript escaper.
|
[
"JS",
"provides",
"a",
"Twig",
"-",
"compatible",
"javascript",
"escaper",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/escape/escape.go#L67-L79
|
16,484 |
tyler-sommer/stick
|
twig/escape/escape.go
|
URLQueryParam
|
func URLQueryParam(in string) string {
var out = &bytes.Buffer{}
var c byte
for i := 0; i < len(in); i++ {
c = in[i]
if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 45 || c == 46 || c == 126 || c == 95 {
// a-zA-Z0-9-._~
out.WriteByte(c)
} else {
// UTF-8
fmt.Fprintf(out, "%%%02X", c)
}
}
return out.String()
}
|
go
|
func URLQueryParam(in string) string {
var out = &bytes.Buffer{}
var c byte
for i := 0; i < len(in); i++ {
c = in[i]
if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 45 || c == 46 || c == 126 || c == 95 {
// a-zA-Z0-9-._~
out.WriteByte(c)
} else {
// UTF-8
fmt.Fprintf(out, "%%%02X", c)
}
}
return out.String()
}
|
[
"func",
"URLQueryParam",
"(",
"in",
"string",
")",
"string",
"{",
"var",
"out",
"=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"var",
"c",
"byte",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"in",
")",
";",
"i",
"++",
"{",
"c",
"=",
"in",
"[",
"i",
"]",
"\n",
"if",
"(",
"c",
">=",
"65",
"&&",
"c",
"<=",
"90",
")",
"||",
"(",
"c",
">=",
"97",
"&&",
"c",
"<=",
"122",
")",
"||",
"(",
"c",
">=",
"48",
"&&",
"c",
"<=",
"57",
")",
"||",
"c",
"==",
"45",
"||",
"c",
"==",
"46",
"||",
"c",
"==",
"126",
"||",
"c",
"==",
"95",
"{",
"// a-zA-Z0-9-._~",
"out",
".",
"WriteByte",
"(",
"c",
")",
"\n",
"}",
"else",
"{",
"// UTF-8",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\"",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"out",
".",
"String",
"(",
")",
"\n",
"}"
] |
// URLQueryParam provides Twig-compatible query string escaper.
|
[
"URLQueryParam",
"provides",
"Twig",
"-",
"compatible",
"query",
"string",
"escaper",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/twig/escape/escape.go#L97-L111
|
16,485 |
tyler-sommer/stick
|
parse/parse_tag.go
|
parseTag
|
func (t *Tree) parseTag() (Node, error) {
name, err := t.expect(tokenName)
if err != nil {
return nil, err
}
switch name.value {
case "extends":
return parseExtends(t, name.Pos)
case "block":
return parseBlock(t, name.Pos)
case "if", "elseif":
return parseIf(t, name.Pos)
case "for":
return parseFor(t, name.Pos)
case "include":
return parseInclude(t, name.Pos)
case "embed":
return parseEmbed(t, name.Pos)
case "use":
return parseUse(t, name.Pos)
case "set":
return parseSet(t, name.Pos)
case "do":
return parseDo(t, name.Pos)
case "filter":
return parseFilter(t, name.Pos)
case "macro":
return parseMacro(t, name.Pos)
case "import":
return parseImport(t, name.Pos)
case "from":
return parseFrom(t, name.Pos)
default:
return nil, newUnexpectedTokenError(name)
}
}
|
go
|
func (t *Tree) parseTag() (Node, error) {
name, err := t.expect(tokenName)
if err != nil {
return nil, err
}
switch name.value {
case "extends":
return parseExtends(t, name.Pos)
case "block":
return parseBlock(t, name.Pos)
case "if", "elseif":
return parseIf(t, name.Pos)
case "for":
return parseFor(t, name.Pos)
case "include":
return parseInclude(t, name.Pos)
case "embed":
return parseEmbed(t, name.Pos)
case "use":
return parseUse(t, name.Pos)
case "set":
return parseSet(t, name.Pos)
case "do":
return parseDo(t, name.Pos)
case "filter":
return parseFilter(t, name.Pos)
case "macro":
return parseMacro(t, name.Pos)
case "import":
return parseImport(t, name.Pos)
case "from":
return parseFrom(t, name.Pos)
default:
return nil, newUnexpectedTokenError(name)
}
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"parseTag",
"(",
")",
"(",
"Node",
",",
"error",
")",
"{",
"name",
",",
"err",
":=",
"t",
".",
"expect",
"(",
"tokenName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"switch",
"name",
".",
"value",
"{",
"case",
"\"",
"\"",
":",
"return",
"parseExtends",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseBlock",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"parseIf",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseFor",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseInclude",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseEmbed",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseUse",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseSet",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseDo",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseFilter",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseMacro",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseImport",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseFrom",
"(",
"t",
",",
"name",
".",
"Pos",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"newUnexpectedTokenError",
"(",
"name",
")",
"\n",
"}",
"\n",
"}"
] |
// parseTag parses the opening of a tag "{%", then delegates to a more specific parser function
// based on the tag's name.
|
[
"parseTag",
"parses",
"the",
"opening",
"of",
"a",
"tag",
"{",
"%",
"then",
"delegates",
"to",
"a",
"more",
"specific",
"parser",
"function",
"based",
"on",
"the",
"tag",
"s",
"name",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse_tag.go#L11-L46
|
16,486 |
tyler-sommer/stick
|
parse/parse_tag.go
|
parseUntilEndTag
|
func (t *Tree) parseUntilEndTag(name string, start Pos) (*BodyNode, error) {
tok := t.peek()
if tok.tokenType == tokenEOF {
return nil, newUnclosedTagError(name, start)
}
n, err := t.parseUntilTag(start, "end"+name)
if err != nil {
return nil, err
}
_, err = t.expect(tokenTagClose)
if err != nil {
return nil, err
}
return n, nil
}
|
go
|
func (t *Tree) parseUntilEndTag(name string, start Pos) (*BodyNode, error) {
tok := t.peek()
if tok.tokenType == tokenEOF {
return nil, newUnclosedTagError(name, start)
}
n, err := t.parseUntilTag(start, "end"+name)
if err != nil {
return nil, err
}
_, err = t.expect(tokenTagClose)
if err != nil {
return nil, err
}
return n, nil
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"parseUntilEndTag",
"(",
"name",
"string",
",",
"start",
"Pos",
")",
"(",
"*",
"BodyNode",
",",
"error",
")",
"{",
"tok",
":=",
"t",
".",
"peek",
"(",
")",
"\n",
"if",
"tok",
".",
"tokenType",
"==",
"tokenEOF",
"{",
"return",
"nil",
",",
"newUnclosedTagError",
"(",
"name",
",",
"start",
")",
"\n",
"}",
"\n\n",
"n",
",",
"err",
":=",
"t",
".",
"parseUntilTag",
"(",
"start",
",",
"\"",
"\"",
"+",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"t",
".",
"expect",
"(",
"tokenTagClose",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] |
// parseUntilEndTag parses until it reaches the specified tag's "end", returning a specific error otherwise.
|
[
"parseUntilEndTag",
"parses",
"until",
"it",
"reaches",
"the",
"specified",
"tag",
"s",
"end",
"returning",
"a",
"specific",
"error",
"otherwise",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse_tag.go#L49-L64
|
16,487 |
tyler-sommer/stick
|
parse/parse_tag.go
|
parseUntilTag
|
func (t *Tree) parseUntilTag(start Pos, names ...string) (*BodyNode, error) {
n := NewBodyNode(start)
for {
switch tok := t.peek(); tok.tokenType {
case tokenEOF:
return n, newUnexpectedEOFError(tok)
case tokenTagOpen:
t.next()
tok, err := t.expect(tokenName)
if err != nil {
return n, err
}
if contains(names, tok.value) {
return n, nil
}
t.backup3()
o, err := t.parse()
if err != nil {
return n, err
}
n.Append(o)
default:
o, err := t.parse()
if err != nil {
return n, err
}
n.Append(o)
}
}
}
|
go
|
func (t *Tree) parseUntilTag(start Pos, names ...string) (*BodyNode, error) {
n := NewBodyNode(start)
for {
switch tok := t.peek(); tok.tokenType {
case tokenEOF:
return n, newUnexpectedEOFError(tok)
case tokenTagOpen:
t.next()
tok, err := t.expect(tokenName)
if err != nil {
return n, err
}
if contains(names, tok.value) {
return n, nil
}
t.backup3()
o, err := t.parse()
if err != nil {
return n, err
}
n.Append(o)
default:
o, err := t.parse()
if err != nil {
return n, err
}
n.Append(o)
}
}
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"parseUntilTag",
"(",
"start",
"Pos",
",",
"names",
"...",
"string",
")",
"(",
"*",
"BodyNode",
",",
"error",
")",
"{",
"n",
":=",
"NewBodyNode",
"(",
"start",
")",
"\n",
"for",
"{",
"switch",
"tok",
":=",
"t",
".",
"peek",
"(",
")",
";",
"tok",
".",
"tokenType",
"{",
"case",
"tokenEOF",
":",
"return",
"n",
",",
"newUnexpectedEOFError",
"(",
"tok",
")",
"\n\n",
"case",
"tokenTagOpen",
":",
"t",
".",
"next",
"(",
")",
"\n",
"tok",
",",
"err",
":=",
"t",
".",
"expect",
"(",
"tokenName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"if",
"contains",
"(",
"names",
",",
"tok",
".",
"value",
")",
"{",
"return",
"n",
",",
"nil",
"\n",
"}",
"\n",
"t",
".",
"backup3",
"(",
")",
"\n",
"o",
",",
"err",
":=",
"t",
".",
"parse",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"n",
".",
"Append",
"(",
"o",
")",
"\n\n",
"default",
":",
"o",
",",
"err",
":=",
"t",
".",
"parse",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"n",
".",
"Append",
"(",
"o",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// parseUntilTag parses until it reaches the specified tag node, returning a parse error otherwise.
|
[
"parseUntilTag",
"parses",
"until",
"it",
"reaches",
"the",
"specified",
"tag",
"node",
"returning",
"a",
"parse",
"error",
"otherwise",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse_tag.go#L76-L107
|
16,488 |
tyler-sommer/stick
|
parse/parse_tag.go
|
parseInclude
|
func parseInclude(t *Tree, start Pos) (Node, error) {
expr, with, only, err := parseIncludeOrEmbed(t)
if err != nil {
return nil, err
}
return NewIncludeNode(expr, with, only, start), nil
}
|
go
|
func parseInclude(t *Tree, start Pos) (Node, error) {
expr, with, only, err := parseIncludeOrEmbed(t)
if err != nil {
return nil, err
}
return NewIncludeNode(expr, with, only, start), nil
}
|
[
"func",
"parseInclude",
"(",
"t",
"*",
"Tree",
",",
"start",
"Pos",
")",
"(",
"Node",
",",
"error",
")",
"{",
"expr",
",",
"with",
",",
"only",
",",
"err",
":=",
"parseIncludeOrEmbed",
"(",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NewIncludeNode",
"(",
"expr",
",",
"with",
",",
"only",
",",
"start",
")",
",",
"nil",
"\n",
"}"
] |
// parseInclude parses an include statement.
|
[
"parseInclude",
"parses",
"an",
"include",
"statement",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse_tag.go#L322-L328
|
16,489 |
tyler-sommer/stick
|
parse/parse_tag.go
|
parseEmbed
|
func parseEmbed(t *Tree, start Pos) (Node, error) {
expr, with, only, err := parseIncludeOrEmbed(t)
if err != nil {
return nil, err
}
t.pushBlockStack()
for {
tok := t.nextNonSpace()
if tok.tokenType == tokenEOF {
return nil, newUnclosedTagError("embed", start)
} else if tok.tokenType == tokenTagOpen {
tok, err := t.expect(tokenName)
if err != nil {
return nil, err
}
if tok.value == "endembed" {
t.next()
_, err := t.expect(tokenTagClose)
if err != nil {
return nil, err
}
break
} else if tok.value == "block" {
n, err := parseBlock(t, start)
if err != nil {
return nil, err
}
if _, ok := n.(*BlockNode); !ok {
return nil, newUnexpectedTokenError(tok)
}
} else {
return nil, newUnexpectedValueError(tok, "endembed or block")
}
}
}
blockRefs := t.popBlockStack()
return NewEmbedNode(expr, with, only, blockRefs, start), nil
}
|
go
|
func parseEmbed(t *Tree, start Pos) (Node, error) {
expr, with, only, err := parseIncludeOrEmbed(t)
if err != nil {
return nil, err
}
t.pushBlockStack()
for {
tok := t.nextNonSpace()
if tok.tokenType == tokenEOF {
return nil, newUnclosedTagError("embed", start)
} else if tok.tokenType == tokenTagOpen {
tok, err := t.expect(tokenName)
if err != nil {
return nil, err
}
if tok.value == "endembed" {
t.next()
_, err := t.expect(tokenTagClose)
if err != nil {
return nil, err
}
break
} else if tok.value == "block" {
n, err := parseBlock(t, start)
if err != nil {
return nil, err
}
if _, ok := n.(*BlockNode); !ok {
return nil, newUnexpectedTokenError(tok)
}
} else {
return nil, newUnexpectedValueError(tok, "endembed or block")
}
}
}
blockRefs := t.popBlockStack()
return NewEmbedNode(expr, with, only, blockRefs, start), nil
}
|
[
"func",
"parseEmbed",
"(",
"t",
"*",
"Tree",
",",
"start",
"Pos",
")",
"(",
"Node",
",",
"error",
")",
"{",
"expr",
",",
"with",
",",
"only",
",",
"err",
":=",
"parseIncludeOrEmbed",
"(",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"t",
".",
"pushBlockStack",
"(",
")",
"\n",
"for",
"{",
"tok",
":=",
"t",
".",
"nextNonSpace",
"(",
")",
"\n",
"if",
"tok",
".",
"tokenType",
"==",
"tokenEOF",
"{",
"return",
"nil",
",",
"newUnclosedTagError",
"(",
"\"",
"\"",
",",
"start",
")",
"\n",
"}",
"else",
"if",
"tok",
".",
"tokenType",
"==",
"tokenTagOpen",
"{",
"tok",
",",
"err",
":=",
"t",
".",
"expect",
"(",
"tokenName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"tok",
".",
"value",
"==",
"\"",
"\"",
"{",
"t",
".",
"next",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"t",
".",
"expect",
"(",
"tokenTagClose",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"else",
"if",
"tok",
".",
"value",
"==",
"\"",
"\"",
"{",
"n",
",",
"err",
":=",
"parseBlock",
"(",
"t",
",",
"start",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"n",
".",
"(",
"*",
"BlockNode",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"newUnexpectedTokenError",
"(",
"tok",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"newUnexpectedValueError",
"(",
"tok",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"blockRefs",
":=",
"t",
".",
"popBlockStack",
"(",
")",
"\n",
"return",
"NewEmbedNode",
"(",
"expr",
",",
"with",
",",
"only",
",",
"blockRefs",
",",
"start",
")",
",",
"nil",
"\n",
"}"
] |
// parseEmbed parses an embed statement and body.
|
[
"parseEmbed",
"parses",
"an",
"embed",
"statement",
"and",
"body",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse_tag.go#L331-L368
|
16,490 |
tyler-sommer/stick
|
parse/parse.go
|
NewNamedTree
|
func NewNamedTree(name string, input io.Reader) *Tree {
return &Tree{
lex: newLexer(input),
root: NewModuleNode(name),
blocks: []map[string]*BlockNode{make(map[string]*BlockNode)},
macros: make(map[string]*MacroNode),
unread: make([]token, 0),
read: make([]token, 0),
Name: name,
Visitors: make([]NodeVisitor, 0),
}
}
|
go
|
func NewNamedTree(name string, input io.Reader) *Tree {
return &Tree{
lex: newLexer(input),
root: NewModuleNode(name),
blocks: []map[string]*BlockNode{make(map[string]*BlockNode)},
macros: make(map[string]*MacroNode),
unread: make([]token, 0),
read: make([]token, 0),
Name: name,
Visitors: make([]NodeVisitor, 0),
}
}
|
[
"func",
"NewNamedTree",
"(",
"name",
"string",
",",
"input",
"io",
".",
"Reader",
")",
"*",
"Tree",
"{",
"return",
"&",
"Tree",
"{",
"lex",
":",
"newLexer",
"(",
"input",
")",
",",
"root",
":",
"NewModuleNode",
"(",
"name",
")",
",",
"blocks",
":",
"[",
"]",
"map",
"[",
"string",
"]",
"*",
"BlockNode",
"{",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"BlockNode",
")",
"}",
",",
"macros",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"MacroNode",
")",
",",
"unread",
":",
"make",
"(",
"[",
"]",
"token",
",",
"0",
")",
",",
"read",
":",
"make",
"(",
"[",
"]",
"token",
",",
"0",
")",
",",
"Name",
":",
"name",
",",
"Visitors",
":",
"make",
"(",
"[",
"]",
"NodeVisitor",
",",
"0",
")",
",",
"}",
"\n",
"}"
] |
// NewNamedTree is an alternative constructor which creates a Tree with a name
|
[
"NewNamedTree",
"is",
"an",
"alternative",
"constructor",
"which",
"creates",
"a",
"Tree",
"with",
"a",
"name"
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L38-L52
|
16,491 |
tyler-sommer/stick
|
parse/parse.go
|
Blocks
|
func (t *Tree) Blocks() map[string]*BlockNode {
return t.blocks[len(t.blocks)-1]
}
|
go
|
func (t *Tree) Blocks() map[string]*BlockNode {
return t.blocks[len(t.blocks)-1]
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"Blocks",
"(",
")",
"map",
"[",
"string",
"]",
"*",
"BlockNode",
"{",
"return",
"t",
".",
"blocks",
"[",
"len",
"(",
"t",
".",
"blocks",
")",
"-",
"1",
"]",
"\n",
"}"
] |
// Blocks returns a map of blocks in this tree.
|
[
"Blocks",
"returns",
"a",
"map",
"of",
"blocks",
"in",
"this",
"tree",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L60-L62
|
16,492 |
tyler-sommer/stick
|
parse/parse.go
|
peek
|
func (t *Tree) peek() token {
tok := t.next()
t.backup()
return tok
}
|
go
|
func (t *Tree) peek() token {
tok := t.next()
t.backup()
return tok
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"peek",
"(",
")",
"token",
"{",
"tok",
":=",
"t",
".",
"next",
"(",
")",
"\n",
"t",
".",
"backup",
"(",
")",
"\n\n",
"return",
"tok",
"\n",
"}"
] |
// peek returns the next unread token without advancing the internal cursor.
|
[
"peek",
"returns",
"the",
"next",
"unread",
"token",
"without",
"advancing",
"the",
"internal",
"cursor",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L91-L96
|
16,493 |
tyler-sommer/stick
|
parse/parse.go
|
peekNonSpace
|
func (t *Tree) peekNonSpace() token {
var next token
for {
next = t.next()
if next.tokenType != tokenWhitespace {
t.backup()
return next
}
}
}
|
go
|
func (t *Tree) peekNonSpace() token {
var next token
for {
next = t.next()
if next.tokenType != tokenWhitespace {
t.backup()
return next
}
}
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"peekNonSpace",
"(",
")",
"token",
"{",
"var",
"next",
"token",
"\n",
"for",
"{",
"next",
"=",
"t",
".",
"next",
"(",
")",
"\n",
"if",
"next",
".",
"tokenType",
"!=",
"tokenWhitespace",
"{",
"t",
".",
"backup",
"(",
")",
"\n",
"return",
"next",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// peek returns the next unread, non-space token without advancing the internal cursor.
|
[
"peek",
"returns",
"the",
"next",
"unread",
"non",
"-",
"space",
"token",
"without",
"advancing",
"the",
"internal",
"cursor",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L99-L108
|
16,494 |
tyler-sommer/stick
|
parse/parse.go
|
backup
|
func (t *Tree) backup() {
var tok token
tok, t.read = t.read[len(t.read)-1], t.read[:len(t.read)-1]
t.unread = append(t.unread, tok)
}
|
go
|
func (t *Tree) backup() {
var tok token
tok, t.read = t.read[len(t.read)-1], t.read[:len(t.read)-1]
t.unread = append(t.unread, tok)
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"backup",
"(",
")",
"{",
"var",
"tok",
"token",
"\n",
"tok",
",",
"t",
".",
"read",
"=",
"t",
".",
"read",
"[",
"len",
"(",
"t",
".",
"read",
")",
"-",
"1",
"]",
",",
"t",
".",
"read",
"[",
":",
"len",
"(",
"t",
".",
"read",
")",
"-",
"1",
"]",
"\n",
"t",
".",
"unread",
"=",
"append",
"(",
"t",
".",
"unread",
",",
"tok",
")",
"\n",
"}"
] |
// backup pushes the last read token back onto the unread stack and reduces the internal cursor by one.
|
[
"backup",
"pushes",
"the",
"last",
"read",
"token",
"back",
"onto",
"the",
"unread",
"stack",
"and",
"reduces",
"the",
"internal",
"cursor",
"by",
"one",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L111-L115
|
16,495 |
tyler-sommer/stick
|
parse/parse.go
|
next
|
func (t *Tree) next() token {
var tok token
if len(t.unread) > 0 {
tok, t.unread = t.unread[len(t.unread)-1], t.unread[:len(t.unread)-1]
} else {
tok = t.lex.nextToken()
}
t.read = append(t.read, tok)
return tok
}
|
go
|
func (t *Tree) next() token {
var tok token
if len(t.unread) > 0 {
tok, t.unread = t.unread[len(t.unread)-1], t.unread[:len(t.unread)-1]
} else {
tok = t.lex.nextToken()
}
t.read = append(t.read, tok)
return tok
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"next",
"(",
")",
"token",
"{",
"var",
"tok",
"token",
"\n",
"if",
"len",
"(",
"t",
".",
"unread",
")",
">",
"0",
"{",
"tok",
",",
"t",
".",
"unread",
"=",
"t",
".",
"unread",
"[",
"len",
"(",
"t",
".",
"unread",
")",
"-",
"1",
"]",
",",
"t",
".",
"unread",
"[",
":",
"len",
"(",
"t",
".",
"unread",
")",
"-",
"1",
"]",
"\n",
"}",
"else",
"{",
"tok",
"=",
"t",
".",
"lex",
".",
"nextToken",
"(",
")",
"\n",
"}",
"\n\n",
"t",
".",
"read",
"=",
"append",
"(",
"t",
".",
"read",
",",
"tok",
")",
"\n\n",
"return",
"tok",
"\n",
"}"
] |
// next returns the next unread token and advances the internal cursor by one.
|
[
"next",
"returns",
"the",
"next",
"unread",
"token",
"and",
"advances",
"the",
"internal",
"cursor",
"by",
"one",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L129-L140
|
16,496 |
tyler-sommer/stick
|
parse/parse.go
|
nextNonSpace
|
func (t *Tree) nextNonSpace() token {
var next token
for {
next = t.next()
if next.tokenType != tokenWhitespace || next.tokenType == tokenEOF {
return next
}
}
}
|
go
|
func (t *Tree) nextNonSpace() token {
var next token
for {
next = t.next()
if next.tokenType != tokenWhitespace || next.tokenType == tokenEOF {
return next
}
}
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"nextNonSpace",
"(",
")",
"token",
"{",
"var",
"next",
"token",
"\n",
"for",
"{",
"next",
"=",
"t",
".",
"next",
"(",
")",
"\n",
"if",
"next",
".",
"tokenType",
"!=",
"tokenWhitespace",
"||",
"next",
".",
"tokenType",
"==",
"tokenEOF",
"{",
"return",
"next",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// nextNonSpace returns the next non-whitespace token.
|
[
"nextNonSpace",
"returns",
"the",
"next",
"non",
"-",
"whitespace",
"token",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L143-L151
|
16,497 |
tyler-sommer/stick
|
parse/parse.go
|
expect
|
func (t *Tree) expect(typs ...tokenType) (token, error) {
tok := t.nextNonSpace()
for _, typ := range typs {
if tok.tokenType == typ {
return tok, nil
}
}
return tok, newUnexpectedTokenError(tok, typs...)
}
|
go
|
func (t *Tree) expect(typs ...tokenType) (token, error) {
tok := t.nextNonSpace()
for _, typ := range typs {
if tok.tokenType == typ {
return tok, nil
}
}
return tok, newUnexpectedTokenError(tok, typs...)
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"expect",
"(",
"typs",
"...",
"tokenType",
")",
"(",
"token",
",",
"error",
")",
"{",
"tok",
":=",
"t",
".",
"nextNonSpace",
"(",
")",
"\n",
"for",
"_",
",",
"typ",
":=",
"range",
"typs",
"{",
"if",
"tok",
".",
"tokenType",
"==",
"typ",
"{",
"return",
"tok",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"tok",
",",
"newUnexpectedTokenError",
"(",
"tok",
",",
"typs",
"...",
")",
"\n",
"}"
] |
// expect returns the next non-space token. Additionally, if the token is not of one of the expected types,
// an UnexpectedTokenError is returned.
|
[
"expect",
"returns",
"the",
"next",
"non",
"-",
"space",
"token",
".",
"Additionally",
"if",
"the",
"token",
"is",
"not",
"of",
"one",
"of",
"the",
"expected",
"types",
"an",
"UnexpectedTokenError",
"is",
"returned",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L155-L164
|
16,498 |
tyler-sommer/stick
|
parse/parse.go
|
expectValue
|
func (t *Tree) expectValue(typ tokenType, val string) (token, error) {
tok, err := t.expect(typ)
if err != nil {
return tok, err
}
if tok.value != val {
return tok, newUnexpectedValueError(tok, val)
}
return tok, nil
}
|
go
|
func (t *Tree) expectValue(typ tokenType, val string) (token, error) {
tok, err := t.expect(typ)
if err != nil {
return tok, err
}
if tok.value != val {
return tok, newUnexpectedValueError(tok, val)
}
return tok, nil
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"expectValue",
"(",
"typ",
"tokenType",
",",
"val",
"string",
")",
"(",
"token",
",",
"error",
")",
"{",
"tok",
",",
"err",
":=",
"t",
".",
"expect",
"(",
"typ",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"tok",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"tok",
".",
"value",
"!=",
"val",
"{",
"return",
"tok",
",",
"newUnexpectedValueError",
"(",
"tok",
",",
"val",
")",
"\n",
"}",
"\n\n",
"return",
"tok",
",",
"nil",
"\n",
"}"
] |
// expectValue returns the next non-space token, with additional checks on the value of the token.
// If the token is not of the expected type, an UnexpectedTokenError is returned. If the token is not the
// expected value, an UnexpectedValueError is returned.
|
[
"expectValue",
"returns",
"the",
"next",
"non",
"-",
"space",
"token",
"with",
"additional",
"checks",
"on",
"the",
"value",
"of",
"the",
"token",
".",
"If",
"the",
"token",
"is",
"not",
"of",
"the",
"expected",
"type",
"an",
"UnexpectedTokenError",
"is",
"returned",
".",
"If",
"the",
"token",
"is",
"not",
"the",
"expected",
"value",
"an",
"UnexpectedValueError",
"is",
"returned",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L169-L180
|
16,499 |
tyler-sommer/stick
|
parse/parse.go
|
enter
|
func (t *Tree) enter(n Node) {
for _, v := range t.Visitors {
v.Enter(n)
}
}
|
go
|
func (t *Tree) enter(n Node) {
for _, v := range t.Visitors {
v.Enter(n)
}
}
|
[
"func",
"(",
"t",
"*",
"Tree",
")",
"enter",
"(",
"n",
"Node",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"t",
".",
"Visitors",
"{",
"v",
".",
"Enter",
"(",
"n",
")",
"\n",
"}",
"\n",
"}"
] |
// Enter is called when the given Node is entered.
|
[
"Enter",
"is",
"called",
"when",
"the",
"given",
"Node",
"is",
"entered",
"."
] |
4dce83bd3cb062197fb3325aa010310717985af1
|
https://github.com/tyler-sommer/stick/blob/4dce83bd3cb062197fb3325aa010310717985af1/parse/parse.go#L183-L187
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.