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
|
---|---|---|---|---|---|---|---|---|---|---|---|
15,900 |
hillu/go-yara
|
rule.go
|
Identifier
|
func (s *String) Identifier() string {
return C.GoString(C.string_identifier(s.cptr))
}
|
go
|
func (s *String) Identifier() string {
return C.GoString(C.string_identifier(s.cptr))
}
|
[
"func",
"(",
"s",
"*",
"String",
")",
"Identifier",
"(",
")",
"string",
"{",
"return",
"C",
".",
"GoString",
"(",
"C",
".",
"string_identifier",
"(",
"s",
".",
"cptr",
")",
")",
"\n",
"}"
] |
// Identifier returns the string's name
|
[
"Identifier",
"returns",
"the",
"string",
"s",
"name"
] |
62cc1506ae60c3f5fd56e992776dddd08d74891f
|
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rule.go#L182-L184
|
15,901 |
hillu/go-yara
|
rule.go
|
Matches
|
func (s *String) Matches() (matches []Match) {
var size C.int
C.string_matches(s.cptr, nil, &size)
ptrs := make([]*C.YR_MATCH, int(size))
if size == 0 {
return
}
C.string_matches(s.cptr, &ptrs[0], &size)
for _, ptr := range ptrs {
matches = append(matches, Match{ptr})
}
return
}
|
go
|
func (s *String) Matches() (matches []Match) {
var size C.int
C.string_matches(s.cptr, nil, &size)
ptrs := make([]*C.YR_MATCH, int(size))
if size == 0 {
return
}
C.string_matches(s.cptr, &ptrs[0], &size)
for _, ptr := range ptrs {
matches = append(matches, Match{ptr})
}
return
}
|
[
"func",
"(",
"s",
"*",
"String",
")",
"Matches",
"(",
")",
"(",
"matches",
"[",
"]",
"Match",
")",
"{",
"var",
"size",
"C",
".",
"int",
"\n",
"C",
".",
"string_matches",
"(",
"s",
".",
"cptr",
",",
"nil",
",",
"&",
"size",
")",
"\n",
"ptrs",
":=",
"make",
"(",
"[",
"]",
"*",
"C",
".",
"YR_MATCH",
",",
"int",
"(",
"size",
")",
")",
"\n",
"if",
"size",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"C",
".",
"string_matches",
"(",
"s",
".",
"cptr",
",",
"&",
"ptrs",
"[",
"0",
"]",
",",
"&",
"size",
")",
"\n",
"for",
"_",
",",
"ptr",
":=",
"range",
"ptrs",
"{",
"matches",
"=",
"append",
"(",
"matches",
",",
"Match",
"{",
"ptr",
"}",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Matches returns all matches that have been recorded for the string.
|
[
"Matches",
"returns",
"all",
"matches",
"that",
"have",
"been",
"recorded",
"for",
"the",
"string",
"."
] |
62cc1506ae60c3f5fd56e992776dddd08d74891f
|
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rule.go#L190-L202
|
15,902 |
oschwald/maxminddb-golang
|
reader.go
|
FromBytes
|
func FromBytes(buffer []byte) (*Reader, error) {
metadataStart := bytes.LastIndex(buffer, metadataStartMarker)
if metadataStart == -1 {
return nil, newInvalidDatabaseError("error opening database: invalid MaxMind DB file")
}
metadataStart += len(metadataStartMarker)
metadataDecoder := decoder{buffer[metadataStart:]}
var metadata Metadata
rvMetdata := reflect.ValueOf(&metadata)
_, err := metadataDecoder.decode(0, rvMetdata, 0)
if err != nil {
return nil, err
}
searchTreeSize := metadata.NodeCount * metadata.RecordSize / 4
dataSectionStart := searchTreeSize + dataSectionSeparatorSize
dataSectionEnd := uint(metadataStart - len(metadataStartMarker))
if dataSectionStart > dataSectionEnd {
return nil, newInvalidDatabaseError("the MaxMind DB contains invalid metadata")
}
d := decoder{
buffer[searchTreeSize+dataSectionSeparatorSize : metadataStart-len(metadataStartMarker)],
}
reader := &Reader{
buffer: buffer,
decoder: d,
Metadata: metadata,
ipv4Start: 0,
}
reader.ipv4Start, err = reader.startNode()
return reader, err
}
|
go
|
func FromBytes(buffer []byte) (*Reader, error) {
metadataStart := bytes.LastIndex(buffer, metadataStartMarker)
if metadataStart == -1 {
return nil, newInvalidDatabaseError("error opening database: invalid MaxMind DB file")
}
metadataStart += len(metadataStartMarker)
metadataDecoder := decoder{buffer[metadataStart:]}
var metadata Metadata
rvMetdata := reflect.ValueOf(&metadata)
_, err := metadataDecoder.decode(0, rvMetdata, 0)
if err != nil {
return nil, err
}
searchTreeSize := metadata.NodeCount * metadata.RecordSize / 4
dataSectionStart := searchTreeSize + dataSectionSeparatorSize
dataSectionEnd := uint(metadataStart - len(metadataStartMarker))
if dataSectionStart > dataSectionEnd {
return nil, newInvalidDatabaseError("the MaxMind DB contains invalid metadata")
}
d := decoder{
buffer[searchTreeSize+dataSectionSeparatorSize : metadataStart-len(metadataStartMarker)],
}
reader := &Reader{
buffer: buffer,
decoder: d,
Metadata: metadata,
ipv4Start: 0,
}
reader.ipv4Start, err = reader.startNode()
return reader, err
}
|
[
"func",
"FromBytes",
"(",
"buffer",
"[",
"]",
"byte",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"metadataStart",
":=",
"bytes",
".",
"LastIndex",
"(",
"buffer",
",",
"metadataStartMarker",
")",
"\n\n",
"if",
"metadataStart",
"==",
"-",
"1",
"{",
"return",
"nil",
",",
"newInvalidDatabaseError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"metadataStart",
"+=",
"len",
"(",
"metadataStartMarker",
")",
"\n",
"metadataDecoder",
":=",
"decoder",
"{",
"buffer",
"[",
"metadataStart",
":",
"]",
"}",
"\n\n",
"var",
"metadata",
"Metadata",
"\n\n",
"rvMetdata",
":=",
"reflect",
".",
"ValueOf",
"(",
"&",
"metadata",
")",
"\n",
"_",
",",
"err",
":=",
"metadataDecoder",
".",
"decode",
"(",
"0",
",",
"rvMetdata",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"searchTreeSize",
":=",
"metadata",
".",
"NodeCount",
"*",
"metadata",
".",
"RecordSize",
"/",
"4",
"\n",
"dataSectionStart",
":=",
"searchTreeSize",
"+",
"dataSectionSeparatorSize",
"\n",
"dataSectionEnd",
":=",
"uint",
"(",
"metadataStart",
"-",
"len",
"(",
"metadataStartMarker",
")",
")",
"\n",
"if",
"dataSectionStart",
">",
"dataSectionEnd",
"{",
"return",
"nil",
",",
"newInvalidDatabaseError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"d",
":=",
"decoder",
"{",
"buffer",
"[",
"searchTreeSize",
"+",
"dataSectionSeparatorSize",
":",
"metadataStart",
"-",
"len",
"(",
"metadataStartMarker",
")",
"]",
",",
"}",
"\n\n",
"reader",
":=",
"&",
"Reader",
"{",
"buffer",
":",
"buffer",
",",
"decoder",
":",
"d",
",",
"Metadata",
":",
"metadata",
",",
"ipv4Start",
":",
"0",
",",
"}",
"\n\n",
"reader",
".",
"ipv4Start",
",",
"err",
"=",
"reader",
".",
"startNode",
"(",
")",
"\n\n",
"return",
"reader",
",",
"err",
"\n",
"}"
] |
// FromBytes takes a byte slice corresponding to a MaxMind DB file and returns
// a Reader structure or an error.
|
[
"FromBytes",
"takes",
"a",
"byte",
"slice",
"corresponding",
"to",
"a",
"MaxMind",
"DB",
"file",
"and",
"returns",
"a",
"Reader",
"structure",
"or",
"an",
"error",
"."
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/reader.go#L49-L87
|
15,903 |
oschwald/maxminddb-golang
|
reader.go
|
Lookup
|
func (r *Reader) Lookup(ipAddress net.IP, result interface{}) error {
if r.buffer == nil {
return errors.New("cannot call Lookup on a closed database")
}
pointer, err := r.lookupPointer(ipAddress)
if pointer == 0 || err != nil {
return err
}
return r.retrieveData(pointer, result)
}
|
go
|
func (r *Reader) Lookup(ipAddress net.IP, result interface{}) error {
if r.buffer == nil {
return errors.New("cannot call Lookup on a closed database")
}
pointer, err := r.lookupPointer(ipAddress)
if pointer == 0 || err != nil {
return err
}
return r.retrieveData(pointer, result)
}
|
[
"func",
"(",
"r",
"*",
"Reader",
")",
"Lookup",
"(",
"ipAddress",
"net",
".",
"IP",
",",
"result",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"r",
".",
"buffer",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pointer",
",",
"err",
":=",
"r",
".",
"lookupPointer",
"(",
"ipAddress",
")",
"\n",
"if",
"pointer",
"==",
"0",
"||",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"r",
".",
"retrieveData",
"(",
"pointer",
",",
"result",
")",
"\n",
"}"
] |
// Lookup takes an IP address as a net.IP structure and a pointer to the
// result value to Decode into.
|
[
"Lookup",
"takes",
"an",
"IP",
"address",
"as",
"a",
"net",
".",
"IP",
"structure",
"and",
"a",
"pointer",
"to",
"the",
"result",
"value",
"to",
"Decode",
"into",
"."
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/reader.go#L109-L118
|
15,904 |
oschwald/maxminddb-golang
|
reader.go
|
LookupOffset
|
func (r *Reader) LookupOffset(ipAddress net.IP) (uintptr, error) {
if r.buffer == nil {
return 0, errors.New("cannot call LookupOffset on a closed database")
}
pointer, err := r.lookupPointer(ipAddress)
if pointer == 0 || err != nil {
return NotFound, err
}
return r.resolveDataPointer(pointer)
}
|
go
|
func (r *Reader) LookupOffset(ipAddress net.IP) (uintptr, error) {
if r.buffer == nil {
return 0, errors.New("cannot call LookupOffset on a closed database")
}
pointer, err := r.lookupPointer(ipAddress)
if pointer == 0 || err != nil {
return NotFound, err
}
return r.resolveDataPointer(pointer)
}
|
[
"func",
"(",
"r",
"*",
"Reader",
")",
"LookupOffset",
"(",
"ipAddress",
"net",
".",
"IP",
")",
"(",
"uintptr",
",",
"error",
")",
"{",
"if",
"r",
".",
"buffer",
"==",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pointer",
",",
"err",
":=",
"r",
".",
"lookupPointer",
"(",
"ipAddress",
")",
"\n",
"if",
"pointer",
"==",
"0",
"||",
"err",
"!=",
"nil",
"{",
"return",
"NotFound",
",",
"err",
"\n",
"}",
"\n",
"return",
"r",
".",
"resolveDataPointer",
"(",
"pointer",
")",
"\n",
"}"
] |
// LookupOffset maps an argument net.IP to a corresponding record offset in the
// database. NotFound is returned if no such record is found, and a record may
// otherwise be extracted by passing the returned offset to Decode. LookupOffset
// is an advanced API, which exists to provide clients with a means to cache
// previously-decoded records.
|
[
"LookupOffset",
"maps",
"an",
"argument",
"net",
".",
"IP",
"to",
"a",
"corresponding",
"record",
"offset",
"in",
"the",
"database",
".",
"NotFound",
"is",
"returned",
"if",
"no",
"such",
"record",
"is",
"found",
"and",
"a",
"record",
"may",
"otherwise",
"be",
"extracted",
"by",
"passing",
"the",
"returned",
"offset",
"to",
"Decode",
".",
"LookupOffset",
"is",
"an",
"advanced",
"API",
"which",
"exists",
"to",
"provide",
"clients",
"with",
"a",
"means",
"to",
"cache",
"previously",
"-",
"decoded",
"records",
"."
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/reader.go#L125-L134
|
15,905 |
oschwald/maxminddb-golang
|
traverse.go
|
Networks
|
func (r *Reader) Networks() *Networks {
s := 4
if r.Metadata.IPVersion == 6 {
s = 16
}
return &Networks{
reader: r,
nodes: []netNode{
{
ip: make(net.IP, s),
},
},
}
}
|
go
|
func (r *Reader) Networks() *Networks {
s := 4
if r.Metadata.IPVersion == 6 {
s = 16
}
return &Networks{
reader: r,
nodes: []netNode{
{
ip: make(net.IP, s),
},
},
}
}
|
[
"func",
"(",
"r",
"*",
"Reader",
")",
"Networks",
"(",
")",
"*",
"Networks",
"{",
"s",
":=",
"4",
"\n",
"if",
"r",
".",
"Metadata",
".",
"IPVersion",
"==",
"6",
"{",
"s",
"=",
"16",
"\n",
"}",
"\n",
"return",
"&",
"Networks",
"{",
"reader",
":",
"r",
",",
"nodes",
":",
"[",
"]",
"netNode",
"{",
"{",
"ip",
":",
"make",
"(",
"net",
".",
"IP",
",",
"s",
")",
",",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] |
// Networks returns an iterator that can be used to traverse all networks in
// the database.
//
// Please note that a MaxMind DB may map IPv4 networks into several locations
// in in an IPv6 database. This iterator will iterate over all of these
// locations separately.
|
[
"Networks",
"returns",
"an",
"iterator",
"that",
"can",
"be",
"used",
"to",
"traverse",
"all",
"networks",
"in",
"the",
"database",
".",
"Please",
"note",
"that",
"a",
"MaxMind",
"DB",
"may",
"map",
"IPv4",
"networks",
"into",
"several",
"locations",
"in",
"in",
"an",
"IPv6",
"database",
".",
"This",
"iterator",
"will",
"iterate",
"over",
"all",
"of",
"these",
"locations",
"separately",
"."
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/traverse.go#L26-L39
|
15,906 |
oschwald/maxminddb-golang
|
traverse.go
|
Next
|
func (n *Networks) Next() bool {
for len(n.nodes) > 0 {
node := n.nodes[len(n.nodes)-1]
n.nodes = n.nodes[:len(n.nodes)-1]
for {
if node.pointer < n.reader.Metadata.NodeCount {
ipRight := make(net.IP, len(node.ip))
copy(ipRight, node.ip)
if len(ipRight) <= int(node.bit>>3) {
n.err = newInvalidDatabaseError(
"invalid search tree at %v/%v", ipRight, node.bit)
return false
}
ipRight[node.bit>>3] |= 1 << (7 - (node.bit % 8))
rightPointer, err := n.reader.readNode(node.pointer, 1)
if err != nil {
n.err = err
return false
}
node.bit++
n.nodes = append(n.nodes, netNode{
pointer: rightPointer,
ip: ipRight,
bit: node.bit,
})
node.pointer, err = n.reader.readNode(node.pointer, 0)
if err != nil {
n.err = err
return false
}
} else if node.pointer > n.reader.Metadata.NodeCount {
n.lastNode = node
return true
} else {
break
}
}
}
return false
}
|
go
|
func (n *Networks) Next() bool {
for len(n.nodes) > 0 {
node := n.nodes[len(n.nodes)-1]
n.nodes = n.nodes[:len(n.nodes)-1]
for {
if node.pointer < n.reader.Metadata.NodeCount {
ipRight := make(net.IP, len(node.ip))
copy(ipRight, node.ip)
if len(ipRight) <= int(node.bit>>3) {
n.err = newInvalidDatabaseError(
"invalid search tree at %v/%v", ipRight, node.bit)
return false
}
ipRight[node.bit>>3] |= 1 << (7 - (node.bit % 8))
rightPointer, err := n.reader.readNode(node.pointer, 1)
if err != nil {
n.err = err
return false
}
node.bit++
n.nodes = append(n.nodes, netNode{
pointer: rightPointer,
ip: ipRight,
bit: node.bit,
})
node.pointer, err = n.reader.readNode(node.pointer, 0)
if err != nil {
n.err = err
return false
}
} else if node.pointer > n.reader.Metadata.NodeCount {
n.lastNode = node
return true
} else {
break
}
}
}
return false
}
|
[
"func",
"(",
"n",
"*",
"Networks",
")",
"Next",
"(",
")",
"bool",
"{",
"for",
"len",
"(",
"n",
".",
"nodes",
")",
">",
"0",
"{",
"node",
":=",
"n",
".",
"nodes",
"[",
"len",
"(",
"n",
".",
"nodes",
")",
"-",
"1",
"]",
"\n",
"n",
".",
"nodes",
"=",
"n",
".",
"nodes",
"[",
":",
"len",
"(",
"n",
".",
"nodes",
")",
"-",
"1",
"]",
"\n\n",
"for",
"{",
"if",
"node",
".",
"pointer",
"<",
"n",
".",
"reader",
".",
"Metadata",
".",
"NodeCount",
"{",
"ipRight",
":=",
"make",
"(",
"net",
".",
"IP",
",",
"len",
"(",
"node",
".",
"ip",
")",
")",
"\n",
"copy",
"(",
"ipRight",
",",
"node",
".",
"ip",
")",
"\n",
"if",
"len",
"(",
"ipRight",
")",
"<=",
"int",
"(",
"node",
".",
"bit",
">>",
"3",
")",
"{",
"n",
".",
"err",
"=",
"newInvalidDatabaseError",
"(",
"\"",
"\"",
",",
"ipRight",
",",
"node",
".",
"bit",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"ipRight",
"[",
"node",
".",
"bit",
">>",
"3",
"]",
"|=",
"1",
"<<",
"(",
"7",
"-",
"(",
"node",
".",
"bit",
"%",
"8",
")",
")",
"\n\n",
"rightPointer",
",",
"err",
":=",
"n",
".",
"reader",
".",
"readNode",
"(",
"node",
".",
"pointer",
",",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"n",
".",
"err",
"=",
"err",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"node",
".",
"bit",
"++",
"\n",
"n",
".",
"nodes",
"=",
"append",
"(",
"n",
".",
"nodes",
",",
"netNode",
"{",
"pointer",
":",
"rightPointer",
",",
"ip",
":",
"ipRight",
",",
"bit",
":",
"node",
".",
"bit",
",",
"}",
")",
"\n\n",
"node",
".",
"pointer",
",",
"err",
"=",
"n",
".",
"reader",
".",
"readNode",
"(",
"node",
".",
"pointer",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"n",
".",
"err",
"=",
"err",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"}",
"else",
"if",
"node",
".",
"pointer",
">",
"n",
".",
"reader",
".",
"Metadata",
".",
"NodeCount",
"{",
"n",
".",
"lastNode",
"=",
"node",
"\n",
"return",
"true",
"\n",
"}",
"else",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// Next prepares the next network for reading with the Network method. It
// returns true if there is another network to be processed and false if there
// are no more networks or if there is an error.
|
[
"Next",
"prepares",
"the",
"next",
"network",
"for",
"reading",
"with",
"the",
"Network",
"method",
".",
"It",
"returns",
"true",
"if",
"there",
"is",
"another",
"network",
"to",
"be",
"processed",
"and",
"false",
"if",
"there",
"are",
"no",
"more",
"networks",
"or",
"if",
"there",
"is",
"an",
"error",
"."
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/traverse.go#L44-L89
|
15,907 |
oschwald/maxminddb-golang
|
traverse.go
|
Network
|
func (n *Networks) Network(result interface{}) (*net.IPNet, error) {
if err := n.reader.retrieveData(n.lastNode.pointer, result); err != nil {
return nil, err
}
return &net.IPNet{
IP: n.lastNode.ip,
Mask: net.CIDRMask(int(n.lastNode.bit), len(n.lastNode.ip)*8),
}, nil
}
|
go
|
func (n *Networks) Network(result interface{}) (*net.IPNet, error) {
if err := n.reader.retrieveData(n.lastNode.pointer, result); err != nil {
return nil, err
}
return &net.IPNet{
IP: n.lastNode.ip,
Mask: net.CIDRMask(int(n.lastNode.bit), len(n.lastNode.ip)*8),
}, nil
}
|
[
"func",
"(",
"n",
"*",
"Networks",
")",
"Network",
"(",
"result",
"interface",
"{",
"}",
")",
"(",
"*",
"net",
".",
"IPNet",
",",
"error",
")",
"{",
"if",
"err",
":=",
"n",
".",
"reader",
".",
"retrieveData",
"(",
"n",
".",
"lastNode",
".",
"pointer",
",",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"n",
".",
"lastNode",
".",
"ip",
",",
"Mask",
":",
"net",
".",
"CIDRMask",
"(",
"int",
"(",
"n",
".",
"lastNode",
".",
"bit",
")",
",",
"len",
"(",
"n",
".",
"lastNode",
".",
"ip",
")",
"*",
"8",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// Network returns the current network or an error if there is a problem
// decoding the data for the network. It takes a pointer to a result value to
// decode the network's data into.
|
[
"Network",
"returns",
"the",
"current",
"network",
"or",
"an",
"error",
"if",
"there",
"is",
"a",
"problem",
"decoding",
"the",
"data",
"for",
"the",
"network",
".",
"It",
"takes",
"a",
"pointer",
"to",
"a",
"result",
"value",
"to",
"decode",
"the",
"network",
"s",
"data",
"into",
"."
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/traverse.go#L94-L103
|
15,908 |
oschwald/maxminddb-golang
|
decoder.go
|
nextValueOffset
|
func (d *decoder) nextValueOffset(offset uint, numberToSkip uint) (uint, error) {
if numberToSkip == 0 {
return offset, nil
}
typeNum, size, offset, err := d.decodeCtrlData(offset)
if err != nil {
return 0, err
}
switch typeNum {
case _Pointer:
_, offset, err = d.decodePointer(size, offset)
if err != nil {
return 0, err
}
case _Map:
numberToSkip += 2 * size
case _Slice:
numberToSkip += size
case _Bool:
default:
offset += size
}
return d.nextValueOffset(offset, numberToSkip-1)
}
|
go
|
func (d *decoder) nextValueOffset(offset uint, numberToSkip uint) (uint, error) {
if numberToSkip == 0 {
return offset, nil
}
typeNum, size, offset, err := d.decodeCtrlData(offset)
if err != nil {
return 0, err
}
switch typeNum {
case _Pointer:
_, offset, err = d.decodePointer(size, offset)
if err != nil {
return 0, err
}
case _Map:
numberToSkip += 2 * size
case _Slice:
numberToSkip += size
case _Bool:
default:
offset += size
}
return d.nextValueOffset(offset, numberToSkip-1)
}
|
[
"func",
"(",
"d",
"*",
"decoder",
")",
"nextValueOffset",
"(",
"offset",
"uint",
",",
"numberToSkip",
"uint",
")",
"(",
"uint",
",",
"error",
")",
"{",
"if",
"numberToSkip",
"==",
"0",
"{",
"return",
"offset",
",",
"nil",
"\n",
"}",
"\n",
"typeNum",
",",
"size",
",",
"offset",
",",
"err",
":=",
"d",
".",
"decodeCtrlData",
"(",
"offset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"switch",
"typeNum",
"{",
"case",
"_Pointer",
":",
"_",
",",
"offset",
",",
"err",
"=",
"d",
".",
"decodePointer",
"(",
"size",
",",
"offset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"case",
"_Map",
":",
"numberToSkip",
"+=",
"2",
"*",
"size",
"\n",
"case",
"_Slice",
":",
"numberToSkip",
"+=",
"size",
"\n",
"case",
"_Bool",
":",
"default",
":",
"offset",
"+=",
"size",
"\n",
"}",
"\n",
"return",
"d",
".",
"nextValueOffset",
"(",
"offset",
",",
"numberToSkip",
"-",
"1",
")",
"\n",
"}"
] |
// This function is used to skip ahead to the next value without decoding
// the one at the offset passed in. The size bits have different meanings for
// different data types
|
[
"This",
"function",
"is",
"used",
"to",
"skip",
"ahead",
"to",
"the",
"next",
"value",
"without",
"decoding",
"the",
"one",
"at",
"the",
"offset",
"passed",
"in",
".",
"The",
"size",
"bits",
"have",
"different",
"meanings",
"for",
"different",
"data",
"types"
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/decoder.go#L698-L721
|
15,909 |
oschwald/maxminddb-golang
|
verifier.go
|
Verify
|
func (r *Reader) Verify() error {
v := verifier{r}
if err := v.verifyMetadata(); err != nil {
return err
}
return v.verifyDatabase()
}
|
go
|
func (r *Reader) Verify() error {
v := verifier{r}
if err := v.verifyMetadata(); err != nil {
return err
}
return v.verifyDatabase()
}
|
[
"func",
"(",
"r",
"*",
"Reader",
")",
"Verify",
"(",
")",
"error",
"{",
"v",
":=",
"verifier",
"{",
"r",
"}",
"\n",
"if",
"err",
":=",
"v",
".",
"verifyMetadata",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"v",
".",
"verifyDatabase",
"(",
")",
"\n",
"}"
] |
// Verify checks that the database is valid. It validates the search tree,
// the data section, and the metadata section. This verifier is stricter than
// the specification and may return errors on databases that are readable.
|
[
"Verify",
"checks",
"that",
"the",
"database",
"is",
"valid",
".",
"It",
"validates",
"the",
"search",
"tree",
"the",
"data",
"section",
"and",
"the",
"metadata",
"section",
".",
"This",
"verifier",
"is",
"stricter",
"than",
"the",
"specification",
"and",
"may",
"return",
"errors",
"on",
"databases",
"that",
"are",
"readable",
"."
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/verifier.go#L12-L19
|
15,910 |
oschwald/maxminddb-golang
|
reader_other.go
|
Close
|
func (r *Reader) Close() error {
var err error
if r.hasMappedFile {
runtime.SetFinalizer(r, nil)
r.hasMappedFile = false
err = munmap(r.buffer)
}
r.buffer = nil
return err
}
|
go
|
func (r *Reader) Close() error {
var err error
if r.hasMappedFile {
runtime.SetFinalizer(r, nil)
r.hasMappedFile = false
err = munmap(r.buffer)
}
r.buffer = nil
return err
}
|
[
"func",
"(",
"r",
"*",
"Reader",
")",
"Close",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"r",
".",
"hasMappedFile",
"{",
"runtime",
".",
"SetFinalizer",
"(",
"r",
",",
"nil",
")",
"\n",
"r",
".",
"hasMappedFile",
"=",
"false",
"\n",
"err",
"=",
"munmap",
"(",
"r",
".",
"buffer",
")",
"\n",
"}",
"\n",
"r",
".",
"buffer",
"=",
"nil",
"\n",
"return",
"err",
"\n",
"}"
] |
// Close unmaps the database file from virtual memory and returns the
// resources to the system. If called on a Reader opened using FromBytes
// or Open on Google App Engine, this method does nothing.
|
[
"Close",
"unmaps",
"the",
"database",
"file",
"from",
"virtual",
"memory",
"and",
"returns",
"the",
"resources",
"to",
"the",
"system",
".",
"If",
"called",
"on",
"a",
"Reader",
"opened",
"using",
"FromBytes",
"or",
"Open",
"on",
"Google",
"App",
"Engine",
"this",
"method",
"does",
"nothing",
"."
] |
45a75c13cdc3299446986746fd39a493aec870c7
|
https://github.com/oschwald/maxminddb-golang/blob/45a75c13cdc3299446986746fd39a493aec870c7/reader_other.go#L54-L63
|
15,911 |
cloudfoundry/bosh-agent
|
integration/utils/tar.go
|
TarballDirectory
|
func TarballDirectory(dirname, rootdir, tarname string) (string, error) {
f, err := os.OpenFile(tarname, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
if err != nil {
return "", err
}
h := sha1.New()
gw := gzip.NewWriter(io.MultiWriter(f, h))
tw := tar.NewWriter(gw)
w := TarWalker{
tw: tw,
root: rootdir,
}
if err := filepath.Walk(dirname, w.Walk); err != nil {
return "", err
}
if err := tw.Close(); err != nil {
return "", err
}
if err := gw.Close(); err != nil {
return "", err
}
if err := f.Close(); err != nil {
return "", err
}
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
|
go
|
func TarballDirectory(dirname, rootdir, tarname string) (string, error) {
f, err := os.OpenFile(tarname, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
if err != nil {
return "", err
}
h := sha1.New()
gw := gzip.NewWriter(io.MultiWriter(f, h))
tw := tar.NewWriter(gw)
w := TarWalker{
tw: tw,
root: rootdir,
}
if err := filepath.Walk(dirname, w.Walk); err != nil {
return "", err
}
if err := tw.Close(); err != nil {
return "", err
}
if err := gw.Close(); err != nil {
return "", err
}
if err := f.Close(); err != nil {
return "", err
}
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
|
[
"func",
"TarballDirectory",
"(",
"dirname",
",",
"rootdir",
",",
"tarname",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"tarname",
",",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_TRUNC",
"|",
"os",
".",
"O_WRONLY",
",",
"0666",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"h",
":=",
"sha1",
".",
"New",
"(",
")",
"\n",
"gw",
":=",
"gzip",
".",
"NewWriter",
"(",
"io",
".",
"MultiWriter",
"(",
"f",
",",
"h",
")",
")",
"\n",
"tw",
":=",
"tar",
".",
"NewWriter",
"(",
"gw",
")",
"\n\n",
"w",
":=",
"TarWalker",
"{",
"tw",
":",
"tw",
",",
"root",
":",
"rootdir",
",",
"}",
"\n",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"dirname",
",",
"w",
".",
"Walk",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tw",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"gw",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"f",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"h",
".",
"Sum",
"(",
"nil",
")",
")",
",",
"nil",
"\n",
"}"
] |
// TarballDirectory - rootdir is equivalent to tar -C 'rootdir'
|
[
"TarballDirectory",
"-",
"rootdir",
"is",
"equivalent",
"to",
"tar",
"-",
"C",
"rootdir"
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/integration/utils/tar.go#L58-L86
|
15,912 |
cloudfoundry/bosh-agent
|
settings/service.go
|
GetSettings
|
func (s *settingsService) GetSettings() Settings {
s.settingsMutex.Lock()
settingsCopy := s.settings
if s.settings.Networks != nil {
settingsCopy.Networks = make(map[string]Network)
}
for networkName, network := range s.settings.Networks {
settingsCopy.Networks[networkName] = network
}
s.settingsMutex.Unlock()
for networkName, network := range settingsCopy.Networks {
if !network.IsDHCP() {
continue
}
resolvedNetwork, err := s.resolveNetwork(network)
if err != nil {
break
}
settingsCopy.Networks[networkName] = resolvedNetwork
}
return settingsCopy
}
|
go
|
func (s *settingsService) GetSettings() Settings {
s.settingsMutex.Lock()
settingsCopy := s.settings
if s.settings.Networks != nil {
settingsCopy.Networks = make(map[string]Network)
}
for networkName, network := range s.settings.Networks {
settingsCopy.Networks[networkName] = network
}
s.settingsMutex.Unlock()
for networkName, network := range settingsCopy.Networks {
if !network.IsDHCP() {
continue
}
resolvedNetwork, err := s.resolveNetwork(network)
if err != nil {
break
}
settingsCopy.Networks[networkName] = resolvedNetwork
}
return settingsCopy
}
|
[
"func",
"(",
"s",
"*",
"settingsService",
")",
"GetSettings",
"(",
")",
"Settings",
"{",
"s",
".",
"settingsMutex",
".",
"Lock",
"(",
")",
"\n\n",
"settingsCopy",
":=",
"s",
".",
"settings",
"\n\n",
"if",
"s",
".",
"settings",
".",
"Networks",
"!=",
"nil",
"{",
"settingsCopy",
".",
"Networks",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Network",
")",
"\n",
"}",
"\n\n",
"for",
"networkName",
",",
"network",
":=",
"range",
"s",
".",
"settings",
".",
"Networks",
"{",
"settingsCopy",
".",
"Networks",
"[",
"networkName",
"]",
"=",
"network",
"\n",
"}",
"\n",
"s",
".",
"settingsMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"networkName",
",",
"network",
":=",
"range",
"settingsCopy",
".",
"Networks",
"{",
"if",
"!",
"network",
".",
"IsDHCP",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"resolvedNetwork",
",",
"err",
":=",
"s",
".",
"resolveNetwork",
"(",
"network",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"settingsCopy",
".",
"Networks",
"[",
"networkName",
"]",
"=",
"resolvedNetwork",
"\n",
"}",
"\n",
"return",
"settingsCopy",
"\n",
"}"
] |
// GetSettings returns setting even if it fails to resolve IPs for dynamic networks.
|
[
"GetSettings",
"returns",
"setting",
"even",
"if",
"it",
"fails",
"to",
"resolve",
"IPs",
"for",
"dynamic",
"networks",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/settings/service.go#L207-L234
|
15,913 |
cloudfoundry/bosh-agent
|
agentclient/http/mocks/mocks.go
|
NewMockAgentClientFactory
|
func NewMockAgentClientFactory(ctrl *gomock.Controller) *MockAgentClientFactory {
mock := &MockAgentClientFactory{ctrl: ctrl}
mock.recorder = &MockAgentClientFactoryMockRecorder{mock}
return mock
}
|
go
|
func NewMockAgentClientFactory(ctrl *gomock.Controller) *MockAgentClientFactory {
mock := &MockAgentClientFactory{ctrl: ctrl}
mock.recorder = &MockAgentClientFactoryMockRecorder{mock}
return mock
}
|
[
"func",
"NewMockAgentClientFactory",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockAgentClientFactory",
"{",
"mock",
":=",
"&",
"MockAgentClientFactory",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockAgentClientFactoryMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] |
// NewMockAgentClientFactory creates a new mock instance
|
[
"NewMockAgentClientFactory",
"creates",
"a",
"new",
"mock",
"instance"
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/agentclient/http/mocks/mocks.go#L25-L29
|
15,914 |
cloudfoundry/bosh-agent
|
agentclient/http/mocks/mocks.go
|
NewAgentClient
|
func (m *MockAgentClientFactory) NewAgentClient(directorID, mbusURL, caCert string) (agentclient.AgentClient, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NewAgentClient", directorID, mbusURL, caCert)
ret0, _ := ret[0].(agentclient.AgentClient)
ret1, _ := ret[1].(error)
return ret0, ret1
}
|
go
|
func (m *MockAgentClientFactory) NewAgentClient(directorID, mbusURL, caCert string) (agentclient.AgentClient, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NewAgentClient", directorID, mbusURL, caCert)
ret0, _ := ret[0].(agentclient.AgentClient)
ret1, _ := ret[1].(error)
return ret0, ret1
}
|
[
"func",
"(",
"m",
"*",
"MockAgentClientFactory",
")",
"NewAgentClient",
"(",
"directorID",
",",
"mbusURL",
",",
"caCert",
"string",
")",
"(",
"agentclient",
".",
"AgentClient",
",",
"error",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"directorID",
",",
"mbusURL",
",",
"caCert",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"agentclient",
".",
"AgentClient",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] |
// NewAgentClient mocks base method
|
[
"NewAgentClient",
"mocks",
"base",
"method"
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/agentclient/http/mocks/mocks.go#L37-L43
|
15,915 |
cloudfoundry/bosh-agent
|
agentclient/http/mocks/mocks.go
|
NewAgentClient
|
func (mr *MockAgentClientFactoryMockRecorder) NewAgentClient(directorID, mbusURL, caCert interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAgentClient", reflect.TypeOf((*MockAgentClientFactory)(nil).NewAgentClient), directorID, mbusURL, caCert)
}
|
go
|
func (mr *MockAgentClientFactoryMockRecorder) NewAgentClient(directorID, mbusURL, caCert interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAgentClient", reflect.TypeOf((*MockAgentClientFactory)(nil).NewAgentClient), directorID, mbusURL, caCert)
}
|
[
"func",
"(",
"mr",
"*",
"MockAgentClientFactoryMockRecorder",
")",
"NewAgentClient",
"(",
"directorID",
",",
"mbusURL",
",",
"caCert",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockAgentClientFactory",
")",
"(",
"nil",
")",
".",
"NewAgentClient",
")",
",",
"directorID",
",",
"mbusURL",
",",
"caCert",
")",
"\n",
"}"
] |
// NewAgentClient indicates an expected call of NewAgentClient
|
[
"NewAgentClient",
"indicates",
"an",
"expected",
"call",
"of",
"NewAgentClient"
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/agentclient/http/mocks/mocks.go#L46-L49
|
15,916 |
cloudfoundry/bosh-agent
|
agent/applier/applyspec/v1_apply_spec.go
|
Jobs
|
func (s V1ApplySpec) Jobs() []models.Job {
jobsWithSource := []models.Job{}
if s.RenderedTemplatesArchiveSpec != nil {
for _, j := range s.JobSpec.JobTemplateSpecsAsJobs() {
j.Source = s.RenderedTemplatesArchiveSpec.AsSource(j)
j.Packages = s.Packages()
jobsWithSource = append(jobsWithSource, j)
}
}
return jobsWithSource
}
|
go
|
func (s V1ApplySpec) Jobs() []models.Job {
jobsWithSource := []models.Job{}
if s.RenderedTemplatesArchiveSpec != nil {
for _, j := range s.JobSpec.JobTemplateSpecsAsJobs() {
j.Source = s.RenderedTemplatesArchiveSpec.AsSource(j)
j.Packages = s.Packages()
jobsWithSource = append(jobsWithSource, j)
}
}
return jobsWithSource
}
|
[
"func",
"(",
"s",
"V1ApplySpec",
")",
"Jobs",
"(",
")",
"[",
"]",
"models",
".",
"Job",
"{",
"jobsWithSource",
":=",
"[",
"]",
"models",
".",
"Job",
"{",
"}",
"\n\n",
"if",
"s",
".",
"RenderedTemplatesArchiveSpec",
"!=",
"nil",
"{",
"for",
"_",
",",
"j",
":=",
"range",
"s",
".",
"JobSpec",
".",
"JobTemplateSpecsAsJobs",
"(",
")",
"{",
"j",
".",
"Source",
"=",
"s",
".",
"RenderedTemplatesArchiveSpec",
".",
"AsSource",
"(",
"j",
")",
"\n",
"j",
".",
"Packages",
"=",
"s",
".",
"Packages",
"(",
")",
"\n",
"jobsWithSource",
"=",
"append",
"(",
"jobsWithSource",
",",
"j",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"jobsWithSource",
"\n",
"}"
] |
// Jobs returns a list of pre-rendered job templates
// extracted from a single tarball provided by BOSH director.
|
[
"Jobs",
"returns",
"a",
"list",
"of",
"pre",
"-",
"rendered",
"job",
"templates",
"extracted",
"from",
"a",
"single",
"tarball",
"provided",
"by",
"BOSH",
"director",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/agent/applier/applyspec/v1_apply_spec.go#L56-L68
|
15,917 |
cloudfoundry/bosh-agent
|
platform/net/custom_network.go
|
toInterfaceAddresses
|
func toInterfaceAddresses(networks []customNetwork) (addresses []boship.InterfaceAddress) {
for _, network := range networks {
addresses = append(addresses, network.ToInterfaceAddress())
}
return
}
|
go
|
func toInterfaceAddresses(networks []customNetwork) (addresses []boship.InterfaceAddress) {
for _, network := range networks {
addresses = append(addresses, network.ToInterfaceAddress())
}
return
}
|
[
"func",
"toInterfaceAddresses",
"(",
"networks",
"[",
"]",
"customNetwork",
")",
"(",
"addresses",
"[",
"]",
"boship",
".",
"InterfaceAddress",
")",
"{",
"for",
"_",
",",
"network",
":=",
"range",
"networks",
"{",
"addresses",
"=",
"append",
"(",
"addresses",
",",
"network",
".",
"ToInterfaceAddress",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// toInterfaceAddresses bulk converts customNetworks to InterfaceAddresses
|
[
"toInterfaceAddresses",
"bulk",
"converts",
"customNetworks",
"to",
"InterfaceAddresses"
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/platform/net/custom_network.go#L31-L36
|
15,918 |
cloudfoundry/bosh-agent
|
jobsupervisor/monitor/monitor.go
|
condMonitor
|
func condMonitor(freq time.Duration, cond *sync.Cond) (*Monitor, error) {
m := &Monitor{
tick: time.NewTicker(freq),
inited: true,
cond: cond,
}
m.state.Set(stateRunning)
if err := m.monitorLoop(); err != nil {
return nil, err
}
return m, nil
}
|
go
|
func condMonitor(freq time.Duration, cond *sync.Cond) (*Monitor, error) {
m := &Monitor{
tick: time.NewTicker(freq),
inited: true,
cond: cond,
}
m.state.Set(stateRunning)
if err := m.monitorLoop(); err != nil {
return nil, err
}
return m, nil
}
|
[
"func",
"condMonitor",
"(",
"freq",
"time",
".",
"Duration",
",",
"cond",
"*",
"sync",
".",
"Cond",
")",
"(",
"*",
"Monitor",
",",
"error",
")",
"{",
"m",
":=",
"&",
"Monitor",
"{",
"tick",
":",
"time",
".",
"NewTicker",
"(",
"freq",
")",
",",
"inited",
":",
"true",
",",
"cond",
":",
"cond",
",",
"}",
"\n",
"m",
".",
"state",
".",
"Set",
"(",
"stateRunning",
")",
"\n",
"if",
"err",
":=",
"m",
".",
"monitorLoop",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// condMonitor, returns a Monitor that broadcasts on cond on each update.
|
[
"condMonitor",
"returns",
"a",
"Monitor",
"that",
"broadcasts",
"on",
"cond",
"on",
"each",
"update",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/monitor/monitor.go#L91-L102
|
15,919 |
cloudfoundry/bosh-agent
|
platform/syscall_windows.go
|
createProfile
|
func createProfile(sid, username string) (string, error) {
const S_OK = 0x00000000
if err := procCreateProfile.Find(); err != nil {
return "", err
}
psid, err := syscall.UTF16PtrFromString(sid)
if err != nil {
return "", err
}
pusername, err := syscall.UTF16PtrFromString(username)
if err != nil {
return "", err
}
var pathbuf [260]uint16
r1, _, e1 := syscall.Syscall6(procCreateProfile.Addr(), 4,
uintptr(unsafe.Pointer(psid)), // _In_ LPCWSTR pszUserSid
uintptr(unsafe.Pointer(pusername)), // _In_ LPCWSTR pszUserName
uintptr(unsafe.Pointer(&pathbuf[0])), // _Out_ LPWSTR pszProfilePath
uintptr(len(pathbuf)), // _In_ DWORD cchProfilePath
0, // unused
0, // unused
)
if r1 != S_OK {
if e1 == 0 {
return "", os.NewSyscallError("CreateProfile", syscall.EINVAL)
}
return "", os.NewSyscallError("CreateProfile", e1)
}
profilePath := syscall.UTF16ToString(pathbuf[0:])
return profilePath, nil
}
|
go
|
func createProfile(sid, username string) (string, error) {
const S_OK = 0x00000000
if err := procCreateProfile.Find(); err != nil {
return "", err
}
psid, err := syscall.UTF16PtrFromString(sid)
if err != nil {
return "", err
}
pusername, err := syscall.UTF16PtrFromString(username)
if err != nil {
return "", err
}
var pathbuf [260]uint16
r1, _, e1 := syscall.Syscall6(procCreateProfile.Addr(), 4,
uintptr(unsafe.Pointer(psid)), // _In_ LPCWSTR pszUserSid
uintptr(unsafe.Pointer(pusername)), // _In_ LPCWSTR pszUserName
uintptr(unsafe.Pointer(&pathbuf[0])), // _Out_ LPWSTR pszProfilePath
uintptr(len(pathbuf)), // _In_ DWORD cchProfilePath
0, // unused
0, // unused
)
if r1 != S_OK {
if e1 == 0 {
return "", os.NewSyscallError("CreateProfile", syscall.EINVAL)
}
return "", os.NewSyscallError("CreateProfile", e1)
}
profilePath := syscall.UTF16ToString(pathbuf[0:])
return profilePath, nil
}
|
[
"func",
"createProfile",
"(",
"sid",
",",
"username",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"const",
"S_OK",
"=",
"0x00000000",
"\n",
"if",
"err",
":=",
"procCreateProfile",
".",
"Find",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"psid",
",",
"err",
":=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"sid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"pusername",
",",
"err",
":=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"var",
"pathbuf",
"[",
"260",
"]",
"uint16",
"\n",
"r1",
",",
"_",
",",
"e1",
":=",
"syscall",
".",
"Syscall6",
"(",
"procCreateProfile",
".",
"Addr",
"(",
")",
",",
"4",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"psid",
")",
")",
",",
"// _In_ LPCWSTR pszUserSid",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"pusername",
")",
")",
",",
"// _In_ LPCWSTR pszUserName",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"pathbuf",
"[",
"0",
"]",
")",
")",
",",
"// _Out_ LPWSTR pszProfilePath",
"uintptr",
"(",
"len",
"(",
"pathbuf",
")",
")",
",",
"// _In_ DWORD cchProfilePath",
"0",
",",
"// unused",
"0",
",",
"// unused",
")",
"\n",
"if",
"r1",
"!=",
"S_OK",
"{",
"if",
"e1",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"syscall",
".",
"EINVAL",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"e1",
")",
"\n",
"}",
"\n",
"profilePath",
":=",
"syscall",
".",
"UTF16ToString",
"(",
"pathbuf",
"[",
"0",
":",
"]",
")",
"\n",
"return",
"profilePath",
",",
"nil",
"\n",
"}"
] |
// createProfile, creates the profile and home directory of the user identified
// by Security Identifier sid.
|
[
"createProfile",
"creates",
"the",
"profile",
"and",
"home",
"directory",
"of",
"the",
"user",
"identified",
"by",
"Security",
"Identifier",
"sid",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/platform/syscall_windows.go#L35-L65
|
15,920 |
cloudfoundry/bosh-agent
|
platform/syscall_windows.go
|
deleteProfile
|
func deleteProfile(sid string) error {
if err := procDeleteProfile.Find(); err != nil {
return err
}
psid, err := syscall.UTF16PtrFromString(sid)
if err != nil {
return err
}
r1, _, e1 := syscall.Syscall(procDeleteProfile.Addr(), 3,
uintptr(unsafe.Pointer(psid)), // _In_ LPCTSTR lpSidString,
0, // _In_opt_ LPCTSTR lpProfilePath,
0, // _In_opt_ LPCTSTR lpComputerName
)
if r1 == 0 {
if e1 == 0 {
return os.NewSyscallError("DeleteProfile", syscall.EINVAL)
}
return os.NewSyscallError("DeleteProfile", e1)
}
return nil
}
|
go
|
func deleteProfile(sid string) error {
if err := procDeleteProfile.Find(); err != nil {
return err
}
psid, err := syscall.UTF16PtrFromString(sid)
if err != nil {
return err
}
r1, _, e1 := syscall.Syscall(procDeleteProfile.Addr(), 3,
uintptr(unsafe.Pointer(psid)), // _In_ LPCTSTR lpSidString,
0, // _In_opt_ LPCTSTR lpProfilePath,
0, // _In_opt_ LPCTSTR lpComputerName
)
if r1 == 0 {
if e1 == 0 {
return os.NewSyscallError("DeleteProfile", syscall.EINVAL)
}
return os.NewSyscallError("DeleteProfile", e1)
}
return nil
}
|
[
"func",
"deleteProfile",
"(",
"sid",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"procDeleteProfile",
".",
"Find",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"psid",
",",
"err",
":=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"sid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"r1",
",",
"_",
",",
"e1",
":=",
"syscall",
".",
"Syscall",
"(",
"procDeleteProfile",
".",
"Addr",
"(",
")",
",",
"3",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"psid",
")",
")",
",",
"// _In_ LPCTSTR lpSidString,",
"0",
",",
"// _In_opt_ LPCTSTR lpProfilePath,",
"0",
",",
"// _In_opt_ LPCTSTR lpComputerName",
")",
"\n",
"if",
"r1",
"==",
"0",
"{",
"if",
"e1",
"==",
"0",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"syscall",
".",
"EINVAL",
")",
"\n",
"}",
"\n",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"e1",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// deleteProfile, deletes the profile and home directory of the user identified
// by Security Identifier sid.
|
[
"deleteProfile",
"deletes",
"the",
"profile",
"and",
"home",
"directory",
"of",
"the",
"user",
"identified",
"by",
"Security",
"Identifier",
"sid",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/platform/syscall_windows.go#L69-L89
|
15,921 |
cloudfoundry/bosh-agent
|
platform/syscall_windows.go
|
generatePassword
|
func generatePassword() (string, error) {
const Length = 14
in := make([]byte, ascii85.MaxEncodedLen(Length))
if _, err := io.ReadFull(rand.Reader, in); err != nil {
return "", err
}
out := make([]byte, ascii85.MaxEncodedLen(len(in)))
if n := ascii85.Encode(out, in); n < Length {
return "", errors.New("short password")
}
// replace forward slashes as NET USER does not like them
var char byte // replacement char
for _, c := range out {
if c != '/' {
char = c
break
}
}
for i, c := range out {
if c == '/' {
out[i] = char
}
}
return string(out[:Length]), nil
}
|
go
|
func generatePassword() (string, error) {
const Length = 14
in := make([]byte, ascii85.MaxEncodedLen(Length))
if _, err := io.ReadFull(rand.Reader, in); err != nil {
return "", err
}
out := make([]byte, ascii85.MaxEncodedLen(len(in)))
if n := ascii85.Encode(out, in); n < Length {
return "", errors.New("short password")
}
// replace forward slashes as NET USER does not like them
var char byte // replacement char
for _, c := range out {
if c != '/' {
char = c
break
}
}
for i, c := range out {
if c == '/' {
out[i] = char
}
}
return string(out[:Length]), nil
}
|
[
"func",
"generatePassword",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"const",
"Length",
"=",
"14",
"\n\n",
"in",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"ascii85",
".",
"MaxEncodedLen",
"(",
"Length",
")",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"rand",
".",
"Reader",
",",
"in",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"out",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"ascii85",
".",
"MaxEncodedLen",
"(",
"len",
"(",
"in",
")",
")",
")",
"\n",
"if",
"n",
":=",
"ascii85",
".",
"Encode",
"(",
"out",
",",
"in",
")",
";",
"n",
"<",
"Length",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// replace forward slashes as NET USER does not like them",
"var",
"char",
"byte",
"// replacement char",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"out",
"{",
"if",
"c",
"!=",
"'/'",
"{",
"char",
"=",
"c",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"out",
"{",
"if",
"c",
"==",
"'/'",
"{",
"out",
"[",
"i",
"]",
"=",
"char",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"string",
"(",
"out",
"[",
":",
"Length",
"]",
")",
",",
"nil",
"\n",
"}"
] |
// generatePassword, returns a 14 char ascii85 encoded password.
//
// DO NOT CALL THIS DIRECTLY, use randomPassword instead as it
// returns a valid Windows password.
|
[
"generatePassword",
"returns",
"a",
"14",
"char",
"ascii85",
"encoded",
"password",
".",
"DO",
"NOT",
"CALL",
"THIS",
"DIRECTLY",
"use",
"randomPassword",
"instead",
"as",
"it",
"returns",
"a",
"valid",
"Windows",
"password",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/platform/syscall_windows.go#L193-L220
|
15,922 |
cloudfoundry/bosh-agent
|
platform/syscall_windows.go
|
randomPassword
|
func randomPassword() (string, error) {
limit := 100
for ; limit >= 0; limit-- {
s, err := generatePassword()
if err != nil {
return "", err
}
if validPassword(s) {
return s, nil
}
}
return "", errors.New("failed to generate valid Windows password")
}
|
go
|
func randomPassword() (string, error) {
limit := 100
for ; limit >= 0; limit-- {
s, err := generatePassword()
if err != nil {
return "", err
}
if validPassword(s) {
return s, nil
}
}
return "", errors.New("failed to generate valid Windows password")
}
|
[
"func",
"randomPassword",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"limit",
":=",
"100",
"\n",
"for",
";",
"limit",
">=",
"0",
";",
"limit",
"--",
"{",
"s",
",",
"err",
":=",
"generatePassword",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"validPassword",
"(",
"s",
")",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// randomPassword, returns a ascii85 encoded 14 char password
// if the password is longer than 14 chars NET.exe will ask
// for confirmation due to backwards compatibility issues with
// Windows prior to Windows 2000.
|
[
"randomPassword",
"returns",
"a",
"ascii85",
"encoded",
"14",
"char",
"password",
"if",
"the",
"password",
"is",
"longer",
"than",
"14",
"chars",
"NET",
".",
"exe",
"will",
"ask",
"for",
"confirmation",
"due",
"to",
"backwards",
"compatibility",
"issues",
"with",
"Windows",
"prior",
"to",
"Windows",
"2000",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/platform/syscall_windows.go#L226-L238
|
15,923 |
cloudfoundry/bosh-agent
|
jobsupervisor/pipe/syslog/syslog.go
|
Dial
|
func Dial(network, raddr string, priority Priority, tag string) (*Writer, error) {
hostname, _ := os.Hostname()
return DialHostname(network, raddr, priority, tag, hostname)
}
|
go
|
func Dial(network, raddr string, priority Priority, tag string) (*Writer, error) {
hostname, _ := os.Hostname()
return DialHostname(network, raddr, priority, tag, hostname)
}
|
[
"func",
"Dial",
"(",
"network",
",",
"raddr",
"string",
",",
"priority",
"Priority",
",",
"tag",
"string",
")",
"(",
"*",
"Writer",
",",
"error",
")",
"{",
"hostname",
",",
"_",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"return",
"DialHostname",
"(",
"network",
",",
"raddr",
",",
"priority",
",",
"tag",
",",
"hostname",
")",
"\n",
"}"
] |
// Dial establishes a connection to a log daemon by connecting to
// address raddr on the specified network. Each write to the returned
// writer sends a log message with the given facility, severity and
// tag.
|
[
"Dial",
"establishes",
"a",
"connection",
"to",
"a",
"log",
"daemon",
"by",
"connecting",
"to",
"address",
"raddr",
"on",
"the",
"specified",
"network",
".",
"Each",
"write",
"to",
"the",
"returned",
"writer",
"sends",
"a",
"log",
"message",
"with",
"the",
"given",
"facility",
"severity",
"and",
"tag",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/pipe/syslog/syslog.go#L95-L98
|
15,924 |
cloudfoundry/bosh-agent
|
jobsupervisor/pipe/syslog/syslog.go
|
Err
|
func (w *Writer) Err(m string) error {
_, err := w.writeAndRetry(LOG_ERR, m)
return err
}
|
go
|
func (w *Writer) Err(m string) error {
_, err := w.writeAndRetry(LOG_ERR, m)
return err
}
|
[
"func",
"(",
"w",
"*",
"Writer",
")",
"Err",
"(",
"m",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"w",
".",
"writeAndRetry",
"(",
"LOG_ERR",
",",
"m",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Err logs a message with severity LOG_ERR, ignoring the severity
// passed to New.
|
[
"Err",
"logs",
"a",
"message",
"with",
"severity",
"LOG_ERR",
"ignoring",
"the",
"severity",
"passed",
"to",
"New",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/pipe/syslog/syslog.go#L188-L191
|
15,925 |
cloudfoundry/bosh-agent
|
jobsupervisor/pipe/syslog/syslog.go
|
Warning
|
func (w *Writer) Warning(m string) error {
_, err := w.writeAndRetry(LOG_WARNING, m)
return err
}
|
go
|
func (w *Writer) Warning(m string) error {
_, err := w.writeAndRetry(LOG_WARNING, m)
return err
}
|
[
"func",
"(",
"w",
"*",
"Writer",
")",
"Warning",
"(",
"m",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"w",
".",
"writeAndRetry",
"(",
"LOG_WARNING",
",",
"m",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Warning logs a message with severity LOG_WARNING, ignoring the
// severity passed to New.
|
[
"Warning",
"logs",
"a",
"message",
"with",
"severity",
"LOG_WARNING",
"ignoring",
"the",
"severity",
"passed",
"to",
"New",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/pipe/syslog/syslog.go#L195-L198
|
15,926 |
cloudfoundry/bosh-agent
|
jobsupervisor/pipe/syslog/syslog.go
|
Notice
|
func (w *Writer) Notice(m string) error {
_, err := w.writeAndRetry(LOG_NOTICE, m)
return err
}
|
go
|
func (w *Writer) Notice(m string) error {
_, err := w.writeAndRetry(LOG_NOTICE, m)
return err
}
|
[
"func",
"(",
"w",
"*",
"Writer",
")",
"Notice",
"(",
"m",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"w",
".",
"writeAndRetry",
"(",
"LOG_NOTICE",
",",
"m",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Notice logs a message with severity LOG_NOTICE, ignoring the
// severity passed to New.
|
[
"Notice",
"logs",
"a",
"message",
"with",
"severity",
"LOG_NOTICE",
"ignoring",
"the",
"severity",
"passed",
"to",
"New",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/pipe/syslog/syslog.go#L202-L205
|
15,927 |
cloudfoundry/bosh-agent
|
jobsupervisor/pipe/syslog/syslog.go
|
itoa
|
func itoa(dst []byte, n int) []byte {
var a [20]byte
i := len(a)
us := uintptr(n)
for us >= 10 {
i--
q := us / 10
a[i] = byte(us - q*10 + '0')
us = q
}
i--
a[i] = byte(us + '0')
return append(dst, a[i:]...)
}
|
go
|
func itoa(dst []byte, n int) []byte {
var a [20]byte
i := len(a)
us := uintptr(n)
for us >= 10 {
i--
q := us / 10
a[i] = byte(us - q*10 + '0')
us = q
}
i--
a[i] = byte(us + '0')
return append(dst, a[i:]...)
}
|
[
"func",
"itoa",
"(",
"dst",
"[",
"]",
"byte",
",",
"n",
"int",
")",
"[",
"]",
"byte",
"{",
"var",
"a",
"[",
"20",
"]",
"byte",
"\n",
"i",
":=",
"len",
"(",
"a",
")",
"\n",
"us",
":=",
"uintptr",
"(",
"n",
")",
"\n",
"for",
"us",
">=",
"10",
"{",
"i",
"--",
"\n",
"q",
":=",
"us",
"/",
"10",
"\n",
"a",
"[",
"i",
"]",
"=",
"byte",
"(",
"us",
"-",
"q",
"*",
"10",
"+",
"'0'",
")",
"\n",
"us",
"=",
"q",
"\n",
"}",
"\n",
"i",
"--",
"\n",
"a",
"[",
"i",
"]",
"=",
"byte",
"(",
"us",
"+",
"'0'",
")",
"\n",
"return",
"append",
"(",
"dst",
",",
"a",
"[",
"i",
":",
"]",
"...",
")",
"\n",
"}"
] |
// itoa, cheap integer to fixed-width decimal ASCII.
|
[
"itoa",
"cheap",
"integer",
"to",
"fixed",
"-",
"width",
"decimal",
"ASCII",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/pipe/syslog/syslog.go#L251-L264
|
15,928 |
cloudfoundry/bosh-agent
|
jobsupervisor/monit/http_client.go
|
NewHTTPClient
|
func NewHTTPClient(
host, username, password string,
shortClient HTTPClient,
longClient HTTPClient,
logger boshlog.Logger,
) Client {
return httpClient{
host: host,
username: username,
password: password,
startClient: shortClient,
stopClient: longClient,
unmonitorClient: longClient,
statusClient: shortClient,
logger: logger,
}
}
|
go
|
func NewHTTPClient(
host, username, password string,
shortClient HTTPClient,
longClient HTTPClient,
logger boshlog.Logger,
) Client {
return httpClient{
host: host,
username: username,
password: password,
startClient: shortClient,
stopClient: longClient,
unmonitorClient: longClient,
statusClient: shortClient,
logger: logger,
}
}
|
[
"func",
"NewHTTPClient",
"(",
"host",
",",
"username",
",",
"password",
"string",
",",
"shortClient",
"HTTPClient",
",",
"longClient",
"HTTPClient",
",",
"logger",
"boshlog",
".",
"Logger",
",",
")",
"Client",
"{",
"return",
"httpClient",
"{",
"host",
":",
"host",
",",
"username",
":",
"username",
",",
"password",
":",
"password",
",",
"startClient",
":",
"shortClient",
",",
"stopClient",
":",
"longClient",
",",
"unmonitorClient",
":",
"longClient",
",",
"statusClient",
":",
"shortClient",
",",
"logger",
":",
"logger",
",",
"}",
"\n",
"}"
] |
// NewHTTPClient creates a new monit client
//
// status & start use the shortClient
// unmonitor & stop use the longClient
|
[
"NewHTTPClient",
"creates",
"a",
"new",
"monit",
"client",
"status",
"&",
"start",
"use",
"the",
"shortClient",
"unmonitor",
"&",
"stop",
"use",
"the",
"longClient"
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/monit/http_client.go#L38-L54
|
15,929 |
cloudfoundry/bosh-agent
|
jobsupervisor/pipe/main.go
|
Environ
|
func Environ() []string {
e := os.Environ()
for i, n := 0, 0; i < len(e); i++ {
if !strings.HasPrefix(e[i], EnvPrefix) {
e[n] = e[i]
n++
}
}
return e
}
|
go
|
func Environ() []string {
e := os.Environ()
for i, n := 0, 0; i < len(e); i++ {
if !strings.HasPrefix(e[i], EnvPrefix) {
e[n] = e[i]
n++
}
}
return e
}
|
[
"func",
"Environ",
"(",
")",
"[",
"]",
"string",
"{",
"e",
":=",
"os",
".",
"Environ",
"(",
")",
"\n",
"for",
"i",
",",
"n",
":=",
"0",
",",
"0",
";",
"i",
"<",
"len",
"(",
"e",
")",
";",
"i",
"++",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"e",
"[",
"i",
"]",
",",
"EnvPrefix",
")",
"{",
"e",
"[",
"n",
"]",
"=",
"e",
"[",
"i",
"]",
"\n",
"n",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"e",
"\n",
"}"
] |
// Environ strips program specific variables from the environment.
|
[
"Environ",
"strips",
"program",
"specific",
"variables",
"from",
"the",
"environment",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/pipe/main.go#L280-L289
|
15,930 |
cloudfoundry/bosh-agent
|
agent/applier/applyspec/concrete_v1_service.go
|
Get
|
func (s concreteV1Service) Get() (V1ApplySpec, error) {
var spec V1ApplySpec
if !s.fs.FileExists(s.specFilePath) {
return spec, nil
}
contents, err := s.fs.ReadFile(s.specFilePath)
if err != nil {
return spec, bosherr.WrapError(err, "Reading json spec file")
}
err = json.Unmarshal([]byte(contents), &spec)
if err != nil {
return spec, bosherr.WrapError(err, "Unmarshalling json spec file")
}
return spec, nil
}
|
go
|
func (s concreteV1Service) Get() (V1ApplySpec, error) {
var spec V1ApplySpec
if !s.fs.FileExists(s.specFilePath) {
return spec, nil
}
contents, err := s.fs.ReadFile(s.specFilePath)
if err != nil {
return spec, bosherr.WrapError(err, "Reading json spec file")
}
err = json.Unmarshal([]byte(contents), &spec)
if err != nil {
return spec, bosherr.WrapError(err, "Unmarshalling json spec file")
}
return spec, nil
}
|
[
"func",
"(",
"s",
"concreteV1Service",
")",
"Get",
"(",
")",
"(",
"V1ApplySpec",
",",
"error",
")",
"{",
"var",
"spec",
"V1ApplySpec",
"\n\n",
"if",
"!",
"s",
".",
"fs",
".",
"FileExists",
"(",
"s",
".",
"specFilePath",
")",
"{",
"return",
"spec",
",",
"nil",
"\n",
"}",
"\n\n",
"contents",
",",
"err",
":=",
"s",
".",
"fs",
".",
"ReadFile",
"(",
"s",
".",
"specFilePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"spec",
",",
"bosherr",
".",
"WrapError",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"contents",
")",
",",
"&",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"spec",
",",
"bosherr",
".",
"WrapError",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"spec",
",",
"nil",
"\n",
"}"
] |
// Get reads and marshals the file contents.
|
[
"Get",
"reads",
"and",
"marshals",
"the",
"file",
"contents",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/agent/applier/applyspec/concrete_v1_service.go#L21-L39
|
15,931 |
cloudfoundry/bosh-agent
|
agent/applier/applyspec/concrete_v1_service.go
|
Set
|
func (s concreteV1Service) Set(spec V1ApplySpec) error {
specBytes, err := json.Marshal(spec)
if err != nil {
return bosherr.WrapError(err, "Marshalling apply spec")
}
err = s.fs.WriteFile(s.specFilePath, specBytes)
if err != nil {
return bosherr.WrapError(err, "Writing spec to disk")
}
return nil
}
|
go
|
func (s concreteV1Service) Set(spec V1ApplySpec) error {
specBytes, err := json.Marshal(spec)
if err != nil {
return bosherr.WrapError(err, "Marshalling apply spec")
}
err = s.fs.WriteFile(s.specFilePath, specBytes)
if err != nil {
return bosherr.WrapError(err, "Writing spec to disk")
}
return nil
}
|
[
"func",
"(",
"s",
"concreteV1Service",
")",
"Set",
"(",
"spec",
"V1ApplySpec",
")",
"error",
"{",
"specBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"bosherr",
".",
"WrapError",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"s",
".",
"fs",
".",
"WriteFile",
"(",
"s",
".",
"specFilePath",
",",
"specBytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"bosherr",
".",
"WrapError",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Set unmarshals and writes to the file.
|
[
"Set",
"unmarshals",
"and",
"writes",
"to",
"the",
"file",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/agent/applier/applyspec/concrete_v1_service.go#L42-L54
|
15,932 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
Connect
|
func Connect(match func(description string) bool) (*Mgr, error) {
m, err := mgr.Connect()
if err != nil {
return nil, err
}
if match == nil {
match = func(_ string) bool { return true }
}
return &Mgr{m: m, match: match}, nil
}
|
go
|
func Connect(match func(description string) bool) (*Mgr, error) {
m, err := mgr.Connect()
if err != nil {
return nil, err
}
if match == nil {
match = func(_ string) bool { return true }
}
return &Mgr{m: m, match: match}, nil
}
|
[
"func",
"Connect",
"(",
"match",
"func",
"(",
"description",
"string",
")",
"bool",
")",
"(",
"*",
"Mgr",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"mgr",
".",
"Connect",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"match",
"==",
"nil",
"{",
"match",
"=",
"func",
"(",
"_",
"string",
")",
"bool",
"{",
"return",
"true",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Mgr",
"{",
"m",
":",
"m",
",",
"match",
":",
"match",
"}",
",",
"nil",
"\n",
"}"
] |
// Connect returns a new Mgr that will monitor all services with descriptions
// matched by match. If match is nil all services are matched.
|
[
"Connect",
"returns",
"a",
"new",
"Mgr",
"that",
"will",
"monitor",
"all",
"services",
"with",
"descriptions",
"matched",
"by",
"match",
".",
"If",
"match",
"is",
"nil",
"all",
"services",
"are",
"matched",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L26-L35
|
15,933 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
serviceDescription
|
func serviceDescription(s *mgr.Service) (string, error) {
var p *windows.SERVICE_DESCRIPTION
n := uint32(1024)
for {
b := make([]byte, n)
p = (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0]))
err := windows.QueryServiceConfig2(s.Handle,
windows.SERVICE_CONFIG_DESCRIPTION, &b[0], n, &n)
if err == nil {
break
}
if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
return "", err
}
if n <= uint32(len(b)) {
return "", err
}
}
return toString(p.Description), nil
}
|
go
|
func serviceDescription(s *mgr.Service) (string, error) {
var p *windows.SERVICE_DESCRIPTION
n := uint32(1024)
for {
b := make([]byte, n)
p = (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0]))
err := windows.QueryServiceConfig2(s.Handle,
windows.SERVICE_CONFIG_DESCRIPTION, &b[0], n, &n)
if err == nil {
break
}
if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
return "", err
}
if n <= uint32(len(b)) {
return "", err
}
}
return toString(p.Description), nil
}
|
[
"func",
"serviceDescription",
"(",
"s",
"*",
"mgr",
".",
"Service",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"p",
"*",
"windows",
".",
"SERVICE_DESCRIPTION",
"\n",
"n",
":=",
"uint32",
"(",
"1024",
")",
"\n",
"for",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"p",
"=",
"(",
"*",
"windows",
".",
"SERVICE_DESCRIPTION",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"b",
"[",
"0",
"]",
")",
")",
"\n",
"err",
":=",
"windows",
".",
"QueryServiceConfig2",
"(",
"s",
".",
"Handle",
",",
"windows",
".",
"SERVICE_CONFIG_DESCRIPTION",
",",
"&",
"b",
"[",
"0",
"]",
",",
"n",
",",
"&",
"n",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"if",
"err",
".",
"(",
"syscall",
".",
"Errno",
")",
"!=",
"syscall",
".",
"ERROR_INSUFFICIENT_BUFFER",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"n",
"<=",
"uint32",
"(",
"len",
"(",
"b",
")",
")",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"toString",
"(",
"p",
".",
"Description",
")",
",",
"nil",
"\n",
"}"
] |
// serviceDescription, returns the description of service s.
|
[
"serviceDescription",
"returns",
"the",
"description",
"of",
"service",
"s",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L50-L69
|
15,934 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
services
|
func (m *Mgr) services() ([]*mgr.Service, error) {
names, err := m.m.ListServices()
if err != nil {
return nil, fmt.Errorf("winsvc: listing services: %s", err)
}
var svcs []*mgr.Service
for _, name := range names {
s, err := m.m.OpenService(name)
if err != nil {
continue // ignore - likely access denied
}
desc, err := serviceDescription(s)
if err != nil {
s.Close()
continue // ignore - likely access denied
}
if m.match(desc) {
svcs = append(svcs, s)
} else {
s.Close()
}
}
return svcs, nil
}
|
go
|
func (m *Mgr) services() ([]*mgr.Service, error) {
names, err := m.m.ListServices()
if err != nil {
return nil, fmt.Errorf("winsvc: listing services: %s", err)
}
var svcs []*mgr.Service
for _, name := range names {
s, err := m.m.OpenService(name)
if err != nil {
continue // ignore - likely access denied
}
desc, err := serviceDescription(s)
if err != nil {
s.Close()
continue // ignore - likely access denied
}
if m.match(desc) {
svcs = append(svcs, s)
} else {
s.Close()
}
}
return svcs, nil
}
|
[
"func",
"(",
"m",
"*",
"Mgr",
")",
"services",
"(",
")",
"(",
"[",
"]",
"*",
"mgr",
".",
"Service",
",",
"error",
")",
"{",
"names",
",",
"err",
":=",
"m",
".",
"m",
".",
"ListServices",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"var",
"svcs",
"[",
"]",
"*",
"mgr",
".",
"Service",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"s",
",",
"err",
":=",
"m",
".",
"m",
".",
"OpenService",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"// ignore - likely access denied",
"\n",
"}",
"\n",
"desc",
",",
"err",
":=",
"serviceDescription",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"Close",
"(",
")",
"\n",
"continue",
"// ignore - likely access denied",
"\n",
"}",
"\n",
"if",
"m",
".",
"match",
"(",
"desc",
")",
"{",
"svcs",
"=",
"append",
"(",
"svcs",
",",
"s",
")",
"\n",
"}",
"else",
"{",
"s",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"svcs",
",",
"nil",
"\n",
"}"
] |
// services, returns all of the services that match the Mgr's match function.
|
[
"services",
"returns",
"all",
"of",
"the",
"services",
"that",
"match",
"the",
"Mgr",
"s",
"match",
"function",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L72-L95
|
15,935 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
iter
|
func (m *Mgr) iter(fn func(*mgr.Service) error) (first error) {
svcs, err := m.services()
if err != nil {
return err
}
var mu sync.Mutex
var wg sync.WaitGroup
wg.Add(len(svcs))
for _, s := range svcs {
go func(s *mgr.Service) {
defer wg.Done()
defer s.Close()
if err := fn(s); err != nil {
mu.Lock()
if first == nil {
first = err
}
mu.Unlock()
}
}(s)
}
wg.Wait()
return
}
|
go
|
func (m *Mgr) iter(fn func(*mgr.Service) error) (first error) {
svcs, err := m.services()
if err != nil {
return err
}
var mu sync.Mutex
var wg sync.WaitGroup
wg.Add(len(svcs))
for _, s := range svcs {
go func(s *mgr.Service) {
defer wg.Done()
defer s.Close()
if err := fn(s); err != nil {
mu.Lock()
if first == nil {
first = err
}
mu.Unlock()
}
}(s)
}
wg.Wait()
return
}
|
[
"func",
"(",
"m",
"*",
"Mgr",
")",
"iter",
"(",
"fn",
"func",
"(",
"*",
"mgr",
".",
"Service",
")",
"error",
")",
"(",
"first",
"error",
")",
"{",
"svcs",
",",
"err",
":=",
"m",
".",
"services",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"mu",
"sync",
".",
"Mutex",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"wg",
".",
"Add",
"(",
"len",
"(",
"svcs",
")",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"svcs",
"{",
"go",
"func",
"(",
"s",
"*",
"mgr",
".",
"Service",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"defer",
"s",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
":=",
"fn",
"(",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"first",
"==",
"nil",
"{",
"first",
"=",
"err",
"\n",
"}",
"\n",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
"s",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// iter, calls function fn concurrently on each service matched by Mgr.
// The service is closed for fn and the first error, if any, is returned.
//
// fn must be safe for concurrent use and must not block indefinitely.
|
[
"iter",
"calls",
"function",
"fn",
"concurrently",
"on",
"each",
"service",
"matched",
"by",
"Mgr",
".",
"The",
"service",
"is",
"closed",
"for",
"fn",
"and",
"the",
"first",
"error",
"if",
"any",
"is",
"returned",
".",
"fn",
"must",
"be",
"safe",
"for",
"concurrent",
"use",
"and",
"must",
"not",
"block",
"indefinitely",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L101-L124
|
15,936 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
querySvc
|
func querySvc(s *mgr.Service) (svc.Status, error) {
status, err := s.Query()
if err != nil {
err = &ServiceError{"querying status of service", s.Name, err}
}
return status, err
}
|
go
|
func querySvc(s *mgr.Service) (svc.Status, error) {
status, err := s.Query()
if err != nil {
err = &ServiceError{"querying status of service", s.Name, err}
}
return status, err
}
|
[
"func",
"querySvc",
"(",
"s",
"*",
"mgr",
".",
"Service",
")",
"(",
"svc",
".",
"Status",
",",
"error",
")",
"{",
"status",
",",
"err",
":=",
"s",
".",
"Query",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"&",
"ServiceError",
"{",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"err",
"}",
"\n",
"}",
"\n",
"return",
"status",
",",
"err",
"\n",
"}"
] |
// querySvc, queries the service status of service s. This is really here to
// return a formated error message.
|
[
"querySvc",
"queries",
"the",
"service",
"status",
"of",
"service",
"s",
".",
"This",
"is",
"really",
"here",
"to",
"return",
"a",
"formated",
"error",
"message",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L155-L161
|
15,937 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
calculateWaitHint
|
func calculateWaitHint(status svc.Status) (waitHint, interval time.Duration) {
//
// This is all a little confusing, so I included the definition of WaitHint
// and Microsoft's guidelines on how to use below:
//
//
// Definition of WaitHint:
//
// The estimated time required for a pending start, stop, pause, or
// continue operation, in milliseconds. Before the specified amount
// of time has elapsed, the service should make its next call to the
// SetServiceStatus function with either an incremented dwCheckPoint
// value or a change in dwCurrentState. If the amount of time specified
// by dwWaitHint passes, and dwCheckPoint has not been incremented or
// dwCurrentState has not changed, the service control manager or service
// control program can assume that an error has occurred and the service
// should be stopped. However, if the service shares a process with other
// services, the service control manager cannot terminate the service
// application because it would have to terminate the other services
// sharing the process as well.
//
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms685996(v=vs.85).aspx
//
//
// Using the wait hint to check for state transition:
//
// Do not wait longer than the wait hint. A good interval is
// one-tenth of the wait hint but not less than 1 second
// and not more than 10 seconds.
//
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms686315(v=vs.85).aspx
//
waitHint = time.Duration(status.WaitHint) * time.Millisecond
if waitHint == 0 {
waitHint = time.Second * 10
}
interval = waitHint / 10
switch {
case interval < time.Second:
interval = time.Second
case interval > time.Second*10:
interval = time.Second * 10
}
return
}
|
go
|
func calculateWaitHint(status svc.Status) (waitHint, interval time.Duration) {
//
// This is all a little confusing, so I included the definition of WaitHint
// and Microsoft's guidelines on how to use below:
//
//
// Definition of WaitHint:
//
// The estimated time required for a pending start, stop, pause, or
// continue operation, in milliseconds. Before the specified amount
// of time has elapsed, the service should make its next call to the
// SetServiceStatus function with either an incremented dwCheckPoint
// value or a change in dwCurrentState. If the amount of time specified
// by dwWaitHint passes, and dwCheckPoint has not been incremented or
// dwCurrentState has not changed, the service control manager or service
// control program can assume that an error has occurred and the service
// should be stopped. However, if the service shares a process with other
// services, the service control manager cannot terminate the service
// application because it would have to terminate the other services
// sharing the process as well.
//
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms685996(v=vs.85).aspx
//
//
// Using the wait hint to check for state transition:
//
// Do not wait longer than the wait hint. A good interval is
// one-tenth of the wait hint but not less than 1 second
// and not more than 10 seconds.
//
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms686315(v=vs.85).aspx
//
waitHint = time.Duration(status.WaitHint) * time.Millisecond
if waitHint == 0 {
waitHint = time.Second * 10
}
interval = waitHint / 10
switch {
case interval < time.Second:
interval = time.Second
case interval > time.Second*10:
interval = time.Second * 10
}
return
}
|
[
"func",
"calculateWaitHint",
"(",
"status",
"svc",
".",
"Status",
")",
"(",
"waitHint",
",",
"interval",
"time",
".",
"Duration",
")",
"{",
"//",
"// This is all a little confusing, so I included the definition of WaitHint",
"// and Microsoft's guidelines on how to use below:",
"//",
"//",
"// Definition of WaitHint:",
"//",
"// The estimated time required for a pending start, stop, pause, or",
"// continue operation, in milliseconds. Before the specified amount",
"// of time has elapsed, the service should make its next call to the",
"// SetServiceStatus function with either an incremented dwCheckPoint",
"// value or a change in dwCurrentState. If the amount of time specified",
"// by dwWaitHint passes, and dwCheckPoint has not been incremented or",
"// dwCurrentState has not changed, the service control manager or service",
"// control program can assume that an error has occurred and the service",
"// should be stopped. However, if the service shares a process with other",
"// services, the service control manager cannot terminate the service",
"// application because it would have to terminate the other services",
"// sharing the process as well.",
"//",
"// https://msdn.microsoft.com/en-us/library/windows/desktop/ms685996(v=vs.85).aspx",
"//",
"//",
"// Using the wait hint to check for state transition:",
"//",
"// Do not wait longer than the wait hint. A good interval is",
"// one-tenth of the wait hint but not less than 1 second",
"// and not more than 10 seconds.",
"//",
"// https://msdn.microsoft.com/en-us/library/windows/desktop/ms686315(v=vs.85).aspx",
"//",
"waitHint",
"=",
"time",
".",
"Duration",
"(",
"status",
".",
"WaitHint",
")",
"*",
"time",
".",
"Millisecond",
"\n",
"if",
"waitHint",
"==",
"0",
"{",
"waitHint",
"=",
"time",
".",
"Second",
"*",
"10",
"\n",
"}",
"\n",
"interval",
"=",
"waitHint",
"/",
"10",
"\n",
"switch",
"{",
"case",
"interval",
"<",
"time",
".",
"Second",
":",
"interval",
"=",
"time",
".",
"Second",
"\n",
"case",
"interval",
">",
"time",
".",
"Second",
"*",
"10",
":",
"interval",
"=",
"time",
".",
"Second",
"*",
"10",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// calculateWaitHint, converts a service's WaitHint into a time duration and
// calculates the interval the caller should wait for before rechecking the
// service's status.
//
// If no WaitHint is provided the default of 10 seconds is returned. As per
// Microsoft's recommendations he returned interval will be between 1 and 10
// seconds.
|
[
"calculateWaitHint",
"converts",
"a",
"service",
"s",
"WaitHint",
"into",
"a",
"time",
"duration",
"and",
"calculates",
"the",
"interval",
"the",
"caller",
"should",
"wait",
"for",
"before",
"rechecking",
"the",
"service",
"s",
"status",
".",
"If",
"no",
"WaitHint",
"is",
"provided",
"the",
"default",
"of",
"10",
"seconds",
"is",
"returned",
".",
"As",
"per",
"Microsoft",
"s",
"recommendations",
"he",
"returned",
"interval",
"will",
"be",
"between",
"1",
"and",
"10",
"seconds",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L170-L214
|
15,938 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
waitPending
|
func waitPending(s *mgr.Service, pendingState svc.State) (svc.Status, error) {
// Arbitrary timeout to prevent misbehaving
// services from triggering an infinite loop.
const Timeout = time.Minute * 20
if pendingState != svc.StartPending && pendingState != svc.StopPending {
// This is a programming error and really should be a panic.
return svc.Status{}, errors.New("winsvc: invalid pending state: " +
svcStateString(pendingState))
}
status, err := querySvc(s)
if err != nil {
return status, err
}
start := time.Now()
for status.State == pendingState {
waitHint, interval := calculateWaitHint(status)
time.Sleep(interval) // sleep before rechecking status
status, err = querySvc(s)
if err != nil {
return status, err
}
if status.State != pendingState {
break
}
switch {
// Exceeded our timeout
case time.Since(start) > Timeout:
err := &TransitionError{
Msg: "timeout waiting for state transition",
Name: s.Name,
Status: status,
WaitHint: waitHint,
Duration: time.Since(start),
}
return status, err
}
}
if status.State == pendingState {
err := &TransitionError{
Msg: "failed to transition out of state",
Name: s.Name,
Status: status,
Duration: time.Since(start),
}
return status, err
}
return status, nil
}
|
go
|
func waitPending(s *mgr.Service, pendingState svc.State) (svc.Status, error) {
// Arbitrary timeout to prevent misbehaving
// services from triggering an infinite loop.
const Timeout = time.Minute * 20
if pendingState != svc.StartPending && pendingState != svc.StopPending {
// This is a programming error and really should be a panic.
return svc.Status{}, errors.New("winsvc: invalid pending state: " +
svcStateString(pendingState))
}
status, err := querySvc(s)
if err != nil {
return status, err
}
start := time.Now()
for status.State == pendingState {
waitHint, interval := calculateWaitHint(status)
time.Sleep(interval) // sleep before rechecking status
status, err = querySvc(s)
if err != nil {
return status, err
}
if status.State != pendingState {
break
}
switch {
// Exceeded our timeout
case time.Since(start) > Timeout:
err := &TransitionError{
Msg: "timeout waiting for state transition",
Name: s.Name,
Status: status,
WaitHint: waitHint,
Duration: time.Since(start),
}
return status, err
}
}
if status.State == pendingState {
err := &TransitionError{
Msg: "failed to transition out of state",
Name: s.Name,
Status: status,
Duration: time.Since(start),
}
return status, err
}
return status, nil
}
|
[
"func",
"waitPending",
"(",
"s",
"*",
"mgr",
".",
"Service",
",",
"pendingState",
"svc",
".",
"State",
")",
"(",
"svc",
".",
"Status",
",",
"error",
")",
"{",
"// Arbitrary timeout to prevent misbehaving",
"// services from triggering an infinite loop.",
"const",
"Timeout",
"=",
"time",
".",
"Minute",
"*",
"20",
"\n\n",
"if",
"pendingState",
"!=",
"svc",
".",
"StartPending",
"&&",
"pendingState",
"!=",
"svc",
".",
"StopPending",
"{",
"// This is a programming error and really should be a panic.",
"return",
"svc",
".",
"Status",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"svcStateString",
"(",
"pendingState",
")",
")",
"\n",
"}",
"\n\n",
"status",
",",
"err",
":=",
"querySvc",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"status",
",",
"err",
"\n",
"}",
"\n\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"for",
"status",
".",
"State",
"==",
"pendingState",
"{",
"waitHint",
",",
"interval",
":=",
"calculateWaitHint",
"(",
"status",
")",
"\n",
"time",
".",
"Sleep",
"(",
"interval",
")",
"// sleep before rechecking status",
"\n\n",
"status",
",",
"err",
"=",
"querySvc",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"status",
",",
"err",
"\n",
"}",
"\n",
"if",
"status",
".",
"State",
"!=",
"pendingState",
"{",
"break",
"\n",
"}",
"\n\n",
"switch",
"{",
"// Exceeded our timeout",
"case",
"time",
".",
"Since",
"(",
"start",
")",
">",
"Timeout",
":",
"err",
":=",
"&",
"TransitionError",
"{",
"Msg",
":",
"\"",
"\"",
",",
"Name",
":",
"s",
".",
"Name",
",",
"Status",
":",
"status",
",",
"WaitHint",
":",
"waitHint",
",",
"Duration",
":",
"time",
".",
"Since",
"(",
"start",
")",
",",
"}",
"\n",
"return",
"status",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"status",
".",
"State",
"==",
"pendingState",
"{",
"err",
":=",
"&",
"TransitionError",
"{",
"Msg",
":",
"\"",
"\"",
",",
"Name",
":",
"s",
".",
"Name",
",",
"Status",
":",
"status",
",",
"Duration",
":",
"time",
".",
"Since",
"(",
"start",
")",
",",
"}",
"\n",
"return",
"status",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"status",
",",
"nil",
"\n",
"}"
] |
// waitPending, waits for service s to transition out of pendingState, which
// must be either StartPending or StopPending. A two minute time limit is
// enforced for the state transition.
//
// See calculateWaitHint for an explanation of how the service's WaitHint is
// used to check progress.
|
[
"waitPending",
"waits",
"for",
"service",
"s",
"to",
"transition",
"out",
"of",
"pendingState",
"which",
"must",
"be",
"either",
"StartPending",
"or",
"StopPending",
".",
"A",
"two",
"minute",
"time",
"limit",
"is",
"enforced",
"for",
"the",
"state",
"transition",
".",
"See",
"calculateWaitHint",
"for",
"an",
"explanation",
"of",
"how",
"the",
"service",
"s",
"WaitHint",
"is",
"used",
"to",
"check",
"progress",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L222-L277
|
15,939 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
Status
|
func (m *Mgr) Status() ([]ServiceStatus, error) {
svcs, err := m.services()
if err != nil {
return nil, err
}
defer closeServices(svcs)
sts := make([]ServiceStatus, len(svcs))
for i, s := range svcs {
status, err := querySvc(s)
if err != nil {
return nil, err
}
sts[i] = ServiceStatus{Name: s.Name, State: status.State}
}
return sts, nil
}
|
go
|
func (m *Mgr) Status() ([]ServiceStatus, error) {
svcs, err := m.services()
if err != nil {
return nil, err
}
defer closeServices(svcs)
sts := make([]ServiceStatus, len(svcs))
for i, s := range svcs {
status, err := querySvc(s)
if err != nil {
return nil, err
}
sts[i] = ServiceStatus{Name: s.Name, State: status.State}
}
return sts, nil
}
|
[
"func",
"(",
"m",
"*",
"Mgr",
")",
"Status",
"(",
")",
"(",
"[",
"]",
"ServiceStatus",
",",
"error",
")",
"{",
"svcs",
",",
"err",
":=",
"m",
".",
"services",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"closeServices",
"(",
"svcs",
")",
"\n\n",
"sts",
":=",
"make",
"(",
"[",
"]",
"ServiceStatus",
",",
"len",
"(",
"svcs",
")",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"svcs",
"{",
"status",
",",
"err",
":=",
"querySvc",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"sts",
"[",
"i",
"]",
"=",
"ServiceStatus",
"{",
"Name",
":",
"s",
".",
"Name",
",",
"State",
":",
"status",
".",
"State",
"}",
"\n",
"}",
"\n",
"return",
"sts",
",",
"nil",
"\n",
"}"
] |
// Status returns the name and status for all of the services monitored.
|
[
"Status",
"returns",
"the",
"name",
"and",
"status",
"for",
"all",
"of",
"the",
"services",
"monitored",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L516-L532
|
15,940 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
Unmonitor
|
func (m *Mgr) Unmonitor() error {
return m.iter(func(s *mgr.Service) error {
return SetStartType(s, mgr.StartDisabled)
})
}
|
go
|
func (m *Mgr) Unmonitor() error {
return m.iter(func(s *mgr.Service) error {
return SetStartType(s, mgr.StartDisabled)
})
}
|
[
"func",
"(",
"m",
"*",
"Mgr",
")",
"Unmonitor",
"(",
")",
"error",
"{",
"return",
"m",
".",
"iter",
"(",
"func",
"(",
"s",
"*",
"mgr",
".",
"Service",
")",
"error",
"{",
"return",
"SetStartType",
"(",
"s",
",",
"mgr",
".",
"StartDisabled",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// Unmonitor disable start for all the Mgr m's services.
|
[
"Unmonitor",
"disable",
"start",
"for",
"all",
"the",
"Mgr",
"m",
"s",
"services",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L548-L552
|
15,941 |
cloudfoundry/bosh-agent
|
jobsupervisor/winsvc/winsvc.go
|
DisableAgentAutoStart
|
func (m *Mgr) DisableAgentAutoStart() error {
const name = "bosh-agent"
s, err := m.m.OpenService("bosh-agent")
if err != nil {
return &ServiceError{"opening service", name, err}
}
defer s.Close()
return SetStartType(s, mgr.StartManual)
}
|
go
|
func (m *Mgr) DisableAgentAutoStart() error {
const name = "bosh-agent"
s, err := m.m.OpenService("bosh-agent")
if err != nil {
return &ServiceError{"opening service", name, err}
}
defer s.Close()
return SetStartType(s, mgr.StartManual)
}
|
[
"func",
"(",
"m",
"*",
"Mgr",
")",
"DisableAgentAutoStart",
"(",
")",
"error",
"{",
"const",
"name",
"=",
"\"",
"\"",
"\n",
"s",
",",
"err",
":=",
"m",
".",
"m",
".",
"OpenService",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"ServiceError",
"{",
"\"",
"\"",
",",
"name",
",",
"err",
"}",
"\n",
"}",
"\n",
"defer",
"s",
".",
"Close",
"(",
")",
"\n",
"return",
"SetStartType",
"(",
"s",
",",
"mgr",
".",
"StartManual",
")",
"\n",
"}"
] |
// DisableAgentAutoStart sets the start type of the bosh-agent to manual.
|
[
"DisableAgentAutoStart",
"sets",
"the",
"start",
"type",
"of",
"the",
"bosh",
"-",
"agent",
"to",
"manual",
"."
] |
dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2
|
https://github.com/cloudfoundry/bosh-agent/blob/dd4b686c8ed5909cf80ea3f5c9fdb6d6f6f1e9c2/jobsupervisor/winsvc/winsvc.go#L555-L563
|
15,942 |
eapache/channels
|
shared_buffer.go
|
NewChannel
|
func (buf *SharedBuffer) NewChannel() SimpleChannel {
ch := &sharedBufferChannel{
in: make(chan interface{}),
out: make(chan interface{}),
buf: queue.New(),
}
buf.in <- ch
return ch
}
|
go
|
func (buf *SharedBuffer) NewChannel() SimpleChannel {
ch := &sharedBufferChannel{
in: make(chan interface{}),
out: make(chan interface{}),
buf: queue.New(),
}
buf.in <- ch
return ch
}
|
[
"func",
"(",
"buf",
"*",
"SharedBuffer",
")",
"NewChannel",
"(",
")",
"SimpleChannel",
"{",
"ch",
":=",
"&",
"sharedBufferChannel",
"{",
"in",
":",
"make",
"(",
"chan",
"interface",
"{",
"}",
")",
",",
"out",
":",
"make",
"(",
"chan",
"interface",
"{",
"}",
")",
",",
"buf",
":",
"queue",
".",
"New",
"(",
")",
",",
"}",
"\n",
"buf",
".",
"in",
"<-",
"ch",
"\n",
"return",
"ch",
"\n",
"}"
] |
//NewChannel spawns and returns a new channel sharing the underlying buffer.
|
[
"NewChannel",
"spawns",
"and",
"returns",
"a",
"new",
"channel",
"sharing",
"the",
"underlying",
"buffer",
"."
] |
47238d5aae8c0fefd518ef2bee46290909cf8263
|
https://github.com/eapache/channels/blob/47238d5aae8c0fefd518ef2bee46290909cf8263/shared_buffer.go#L67-L75
|
15,943 |
eapache/channels
|
ring_channel.go
|
ringBuffer
|
func (ch *RingChannel) ringBuffer() {
var input, output chan interface{}
var next interface{}
input = ch.input
for input != nil || output != nil {
select {
// Prefer to write if possible, which is surprisingly effective in reducing
// dropped elements due to overflow. The naive read/write select chooses randomly
// when both channels are ready, which produces unnecessary drops 50% of the time.
case output <- next:
ch.buffer.Remove()
default:
select {
case elem, open := <-input:
if open {
ch.buffer.Add(elem)
if ch.size != Infinity && ch.buffer.Length() > int(ch.size) {
ch.buffer.Remove()
}
} else {
input = nil
}
case output <- next:
ch.buffer.Remove()
case ch.length <- ch.buffer.Length():
}
}
if ch.buffer.Length() > 0 {
output = ch.output
next = ch.buffer.Peek()
} else {
output = nil
next = nil
}
}
close(ch.output)
close(ch.length)
}
|
go
|
func (ch *RingChannel) ringBuffer() {
var input, output chan interface{}
var next interface{}
input = ch.input
for input != nil || output != nil {
select {
// Prefer to write if possible, which is surprisingly effective in reducing
// dropped elements due to overflow. The naive read/write select chooses randomly
// when both channels are ready, which produces unnecessary drops 50% of the time.
case output <- next:
ch.buffer.Remove()
default:
select {
case elem, open := <-input:
if open {
ch.buffer.Add(elem)
if ch.size != Infinity && ch.buffer.Length() > int(ch.size) {
ch.buffer.Remove()
}
} else {
input = nil
}
case output <- next:
ch.buffer.Remove()
case ch.length <- ch.buffer.Length():
}
}
if ch.buffer.Length() > 0 {
output = ch.output
next = ch.buffer.Peek()
} else {
output = nil
next = nil
}
}
close(ch.output)
close(ch.length)
}
|
[
"func",
"(",
"ch",
"*",
"RingChannel",
")",
"ringBuffer",
"(",
")",
"{",
"var",
"input",
",",
"output",
"chan",
"interface",
"{",
"}",
"\n",
"var",
"next",
"interface",
"{",
"}",
"\n",
"input",
"=",
"ch",
".",
"input",
"\n\n",
"for",
"input",
"!=",
"nil",
"||",
"output",
"!=",
"nil",
"{",
"select",
"{",
"// Prefer to write if possible, which is surprisingly effective in reducing",
"// dropped elements due to overflow. The naive read/write select chooses randomly",
"// when both channels are ready, which produces unnecessary drops 50% of the time.",
"case",
"output",
"<-",
"next",
":",
"ch",
".",
"buffer",
".",
"Remove",
"(",
")",
"\n",
"default",
":",
"select",
"{",
"case",
"elem",
",",
"open",
":=",
"<-",
"input",
":",
"if",
"open",
"{",
"ch",
".",
"buffer",
".",
"Add",
"(",
"elem",
")",
"\n",
"if",
"ch",
".",
"size",
"!=",
"Infinity",
"&&",
"ch",
".",
"buffer",
".",
"Length",
"(",
")",
">",
"int",
"(",
"ch",
".",
"size",
")",
"{",
"ch",
".",
"buffer",
".",
"Remove",
"(",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"input",
"=",
"nil",
"\n",
"}",
"\n",
"case",
"output",
"<-",
"next",
":",
"ch",
".",
"buffer",
".",
"Remove",
"(",
")",
"\n",
"case",
"ch",
".",
"length",
"<-",
"ch",
".",
"buffer",
".",
"Length",
"(",
")",
":",
"}",
"\n",
"}",
"\n\n",
"if",
"ch",
".",
"buffer",
".",
"Length",
"(",
")",
">",
"0",
"{",
"output",
"=",
"ch",
".",
"output",
"\n",
"next",
"=",
"ch",
".",
"buffer",
".",
"Peek",
"(",
")",
"\n",
"}",
"else",
"{",
"output",
"=",
"nil",
"\n",
"next",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"close",
"(",
"ch",
".",
"output",
")",
"\n",
"close",
"(",
"ch",
".",
"length",
")",
"\n",
"}"
] |
// for all buffered cases
|
[
"for",
"all",
"buffered",
"cases"
] |
47238d5aae8c0fefd518ef2bee46290909cf8263
|
https://github.com/eapache/channels/blob/47238d5aae8c0fefd518ef2bee46290909cf8263/ring_channel.go#L74-L114
|
15,944 |
yosssi/gcss
|
compile.go
|
Compile
|
func Compile(dst io.Writer, src io.Reader) (int, error) {
data, err := ioutil.ReadAll(src)
if err != nil {
return 0, err
}
bc, berrc := compileBytes(data)
bf := new(bytes.Buffer)
BufWriteLoop:
for {
select {
case b, ok := <-bc:
if !ok {
break BufWriteLoop
}
bf.Write(b)
case err := <-berrc:
return 0, err
}
}
return dst.Write(bf.Bytes())
}
|
go
|
func Compile(dst io.Writer, src io.Reader) (int, error) {
data, err := ioutil.ReadAll(src)
if err != nil {
return 0, err
}
bc, berrc := compileBytes(data)
bf := new(bytes.Buffer)
BufWriteLoop:
for {
select {
case b, ok := <-bc:
if !ok {
break BufWriteLoop
}
bf.Write(b)
case err := <-berrc:
return 0, err
}
}
return dst.Write(bf.Bytes())
}
|
[
"func",
"Compile",
"(",
"dst",
"io",
".",
"Writer",
",",
"src",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"src",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"bc",
",",
"berrc",
":=",
"compileBytes",
"(",
"data",
")",
"\n\n",
"bf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"BufWriteLoop",
":",
"for",
"{",
"select",
"{",
"case",
"b",
",",
"ok",
":=",
"<-",
"bc",
":",
"if",
"!",
"ok",
"{",
"break",
"BufWriteLoop",
"\n",
"}",
"\n\n",
"bf",
".",
"Write",
"(",
"b",
")",
"\n",
"case",
"err",
":=",
"<-",
"berrc",
":",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"dst",
".",
"Write",
"(",
"bf",
".",
"Bytes",
"(",
")",
")",
"\n",
"}"
] |
// Compile compiles GCSS data which is read from src and
// Writes the result CSS data to the dst.
|
[
"Compile",
"compiles",
"GCSS",
"data",
"which",
"is",
"read",
"from",
"src",
"and",
"Writes",
"the",
"result",
"CSS",
"data",
"to",
"the",
"dst",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/compile.go#L24-L50
|
15,945 |
yosssi/gcss
|
compile.go
|
CompileFile
|
func CompileFile(path string) (string, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
cssPath := cssFilePath(path)
bc, berrc := compileBytes(data)
done, werrc := write(cssPath, bc, berrc)
select {
case <-done:
case err := <-werrc:
return "", err
}
return cssPath, nil
}
|
go
|
func CompileFile(path string) (string, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
cssPath := cssFilePath(path)
bc, berrc := compileBytes(data)
done, werrc := write(cssPath, bc, berrc)
select {
case <-done:
case err := <-werrc:
return "", err
}
return cssPath, nil
}
|
[
"func",
"CompileFile",
"(",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"cssPath",
":=",
"cssFilePath",
"(",
"path",
")",
"\n\n",
"bc",
",",
"berrc",
":=",
"compileBytes",
"(",
"data",
")",
"\n\n",
"done",
",",
"werrc",
":=",
"write",
"(",
"cssPath",
",",
"bc",
",",
"berrc",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"done",
":",
"case",
"err",
":=",
"<-",
"werrc",
":",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"cssPath",
",",
"nil",
"\n",
"}"
] |
// CompileFile parses the GCSS file specified by the path parameter,
// generates a CSS file and returns the path of the generated CSS file
// and an error when it occurs.
|
[
"CompileFile",
"parses",
"the",
"GCSS",
"file",
"specified",
"by",
"the",
"path",
"parameter",
"generates",
"a",
"CSS",
"file",
"and",
"returns",
"the",
"path",
"of",
"the",
"generated",
"CSS",
"file",
"and",
"an",
"error",
"when",
"it",
"occurs",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/compile.go#L55-L75
|
15,946 |
yosssi/gcss
|
compile.go
|
convertExt
|
func convertExt(path string, ext string) string {
return strings.TrimSuffix(path, filepath.Ext(path)) + ext
}
|
go
|
func convertExt(path string, ext string) string {
return strings.TrimSuffix(path, filepath.Ext(path)) + ext
}
|
[
"func",
"convertExt",
"(",
"path",
"string",
",",
"ext",
"string",
")",
"string",
"{",
"return",
"strings",
".",
"TrimSuffix",
"(",
"path",
",",
"filepath",
".",
"Ext",
"(",
"path",
")",
")",
"+",
"ext",
"\n",
"}"
] |
// convertExt converts path's extension into ext.
|
[
"convertExt",
"converts",
"path",
"s",
"extension",
"into",
"ext",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/compile.go#L128-L130
|
15,947 |
yosssi/gcss
|
variable.go
|
WriteTo
|
func (v *variable) WriteTo(w io.Writer) (int64, error) {
n, err := w.Write([]byte(v.value))
return int64(n), err
}
|
go
|
func (v *variable) WriteTo(w io.Writer) (int64, error) {
n, err := w.Write([]byte(v.value))
return int64(n), err
}
|
[
"func",
"(",
"v",
"*",
"variable",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"v",
".",
"value",
")",
")",
"\n\n",
"return",
"int64",
"(",
"n",
")",
",",
"err",
"\n",
"}"
] |
// WriteTo writes the variable to the writer.
|
[
"WriteTo",
"writes",
"the",
"variable",
"to",
"the",
"writer",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/variable.go#L17-L21
|
15,948 |
yosssi/gcss
|
variable.go
|
variableNV
|
func variableNV(ln *line) (string, string, error) {
s := strings.TrimSpace(ln.s)
if !strings.HasPrefix(s, dollarMark) {
return "", "", fmt.Errorf("variable must start with %q [line: %d]", dollarMark, ln.no)
}
nv := strings.SplitN(s, space, 2)
if len(nv) < 2 {
return "", "", fmt.Errorf("variable's name and value should be divided by a space [line: %d]", ln.no)
}
if !strings.HasSuffix(nv[0], colon) {
return "", "", fmt.Errorf("variable's name should end with a colon [line: %d]", ln.no)
}
return strings.TrimSuffix(strings.TrimPrefix(nv[0], dollarMark), colon), nv[1], nil
}
|
go
|
func variableNV(ln *line) (string, string, error) {
s := strings.TrimSpace(ln.s)
if !strings.HasPrefix(s, dollarMark) {
return "", "", fmt.Errorf("variable must start with %q [line: %d]", dollarMark, ln.no)
}
nv := strings.SplitN(s, space, 2)
if len(nv) < 2 {
return "", "", fmt.Errorf("variable's name and value should be divided by a space [line: %d]", ln.no)
}
if !strings.HasSuffix(nv[0], colon) {
return "", "", fmt.Errorf("variable's name should end with a colon [line: %d]", ln.no)
}
return strings.TrimSuffix(strings.TrimPrefix(nv[0], dollarMark), colon), nv[1], nil
}
|
[
"func",
"variableNV",
"(",
"ln",
"*",
"line",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"s",
":=",
"strings",
".",
"TrimSpace",
"(",
"ln",
".",
"s",
")",
"\n\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"s",
",",
"dollarMark",
")",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dollarMark",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"nv",
":=",
"strings",
".",
"SplitN",
"(",
"s",
",",
"space",
",",
"2",
")",
"\n\n",
"if",
"len",
"(",
"nv",
")",
"<",
"2",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"nv",
"[",
"0",
"]",
",",
"colon",
")",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"TrimSuffix",
"(",
"strings",
".",
"TrimPrefix",
"(",
"nv",
"[",
"0",
"]",
",",
"dollarMark",
")",
",",
"colon",
")",
",",
"nv",
"[",
"1",
"]",
",",
"nil",
"\n",
"}"
] |
// variableNV extracts a variable name and value
// from the line.
|
[
"variableNV",
"extracts",
"a",
"variable",
"name",
"and",
"value",
"from",
"the",
"line",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/variable.go#L25-L43
|
15,949 |
yosssi/gcss
|
variable.go
|
newVariable
|
func newVariable(ln *line, parent element) (*variable, error) {
name, value, err := variableNV(ln)
if err != nil {
return nil, err
}
if strings.HasSuffix(value, semicolon) {
return nil, fmt.Errorf("variable must not end with %q", semicolon)
}
return &variable{
elementBase: newElementBase(ln, parent),
name: name,
value: value,
}, nil
}
|
go
|
func newVariable(ln *line, parent element) (*variable, error) {
name, value, err := variableNV(ln)
if err != nil {
return nil, err
}
if strings.HasSuffix(value, semicolon) {
return nil, fmt.Errorf("variable must not end with %q", semicolon)
}
return &variable{
elementBase: newElementBase(ln, parent),
name: name,
value: value,
}, nil
}
|
[
"func",
"newVariable",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"(",
"*",
"variable",
",",
"error",
")",
"{",
"name",
",",
"value",
",",
"err",
":=",
"variableNV",
"(",
"ln",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"value",
",",
"semicolon",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"semicolon",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"variable",
"{",
"elementBase",
":",
"newElementBase",
"(",
"ln",
",",
"parent",
")",
",",
"name",
":",
"name",
",",
"value",
":",
"value",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// newVariable creates and returns a variable.
|
[
"newVariable",
"creates",
"and",
"returns",
"a",
"variable",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/variable.go#L46-L62
|
15,950 |
yosssi/gcss
|
mixin_declaration.go
|
mixinNP
|
func mixinNP(ln *line, isDeclaration bool) (string, []string, error) {
s := strings.TrimSpace(ln.s)
if !strings.HasPrefix(s, dollarMark) {
return "", nil, fmt.Errorf("mixin must start with %q [line: %d]", dollarMark, ln.no)
}
s = strings.TrimPrefix(s, dollarMark)
np := strings.Split(s, openParenthesis)
if len(np) != 2 {
return "", nil, fmt.Errorf("mixin's format is invalid [line: %d]", ln.no)
}
paramsS := strings.TrimSpace(np[1])
if !strings.HasSuffix(paramsS, closeParenthesis) {
return "", nil, fmt.Errorf("mixin must end with %q [line: %d]", closeParenthesis, ln.no)
}
paramsS = strings.TrimSuffix(paramsS, closeParenthesis)
if strings.Index(paramsS, closeParenthesis) != -1 {
return "", nil, fmt.Errorf("mixin's format is invalid [line: %d]", ln.no)
}
var params []string
if paramsS != "" {
params = strings.Split(paramsS, comma)
}
for i, p := range params {
p = strings.TrimSpace(p)
if isDeclaration {
if !strings.HasPrefix(p, dollarMark) {
return "", nil, fmt.Errorf("mixin's parameter must start with %q [line: %d]", dollarMark, ln.no)
}
p = strings.TrimPrefix(p, dollarMark)
}
params[i] = p
}
return np[0], params, nil
}
|
go
|
func mixinNP(ln *line, isDeclaration bool) (string, []string, error) {
s := strings.TrimSpace(ln.s)
if !strings.HasPrefix(s, dollarMark) {
return "", nil, fmt.Errorf("mixin must start with %q [line: %d]", dollarMark, ln.no)
}
s = strings.TrimPrefix(s, dollarMark)
np := strings.Split(s, openParenthesis)
if len(np) != 2 {
return "", nil, fmt.Errorf("mixin's format is invalid [line: %d]", ln.no)
}
paramsS := strings.TrimSpace(np[1])
if !strings.HasSuffix(paramsS, closeParenthesis) {
return "", nil, fmt.Errorf("mixin must end with %q [line: %d]", closeParenthesis, ln.no)
}
paramsS = strings.TrimSuffix(paramsS, closeParenthesis)
if strings.Index(paramsS, closeParenthesis) != -1 {
return "", nil, fmt.Errorf("mixin's format is invalid [line: %d]", ln.no)
}
var params []string
if paramsS != "" {
params = strings.Split(paramsS, comma)
}
for i, p := range params {
p = strings.TrimSpace(p)
if isDeclaration {
if !strings.HasPrefix(p, dollarMark) {
return "", nil, fmt.Errorf("mixin's parameter must start with %q [line: %d]", dollarMark, ln.no)
}
p = strings.TrimPrefix(p, dollarMark)
}
params[i] = p
}
return np[0], params, nil
}
|
[
"func",
"mixinNP",
"(",
"ln",
"*",
"line",
",",
"isDeclaration",
"bool",
")",
"(",
"string",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"s",
":=",
"strings",
".",
"TrimSpace",
"(",
"ln",
".",
"s",
")",
"\n\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"s",
",",
"dollarMark",
")",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dollarMark",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"s",
"=",
"strings",
".",
"TrimPrefix",
"(",
"s",
",",
"dollarMark",
")",
"\n\n",
"np",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"openParenthesis",
")",
"\n\n",
"if",
"len",
"(",
"np",
")",
"!=",
"2",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"paramsS",
":=",
"strings",
".",
"TrimSpace",
"(",
"np",
"[",
"1",
"]",
")",
"\n\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"paramsS",
",",
"closeParenthesis",
")",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"closeParenthesis",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"paramsS",
"=",
"strings",
".",
"TrimSuffix",
"(",
"paramsS",
",",
"closeParenthesis",
")",
"\n\n",
"if",
"strings",
".",
"Index",
"(",
"paramsS",
",",
"closeParenthesis",
")",
"!=",
"-",
"1",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"var",
"params",
"[",
"]",
"string",
"\n\n",
"if",
"paramsS",
"!=",
"\"",
"\"",
"{",
"params",
"=",
"strings",
".",
"Split",
"(",
"paramsS",
",",
"comma",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"p",
":=",
"range",
"params",
"{",
"p",
"=",
"strings",
".",
"TrimSpace",
"(",
"p",
")",
"\n\n",
"if",
"isDeclaration",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"p",
",",
"dollarMark",
")",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dollarMark",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"p",
"=",
"strings",
".",
"TrimPrefix",
"(",
"p",
",",
"dollarMark",
")",
"\n",
"}",
"\n\n",
"params",
"[",
"i",
"]",
"=",
"p",
"\n",
"}",
"\n\n",
"return",
"np",
"[",
"0",
"]",
",",
"params",
",",
"nil",
"\n",
"}"
] |
// mixinNP extracts a mixin name and parameters from the line.
|
[
"mixinNP",
"extracts",
"a",
"mixin",
"name",
"and",
"parameters",
"from",
"the",
"line",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/mixin_declaration.go#L22-L70
|
15,951 |
yosssi/gcss
|
mixin_declaration.go
|
newMixinDeclaration
|
func newMixinDeclaration(ln *line, parent element) (*mixinDeclaration, error) {
name, paramNames, err := mixinNP(ln, true)
if err != nil {
return nil, err
}
return &mixinDeclaration{
elementBase: newElementBase(ln, parent),
name: name,
paramNames: paramNames,
}, nil
}
|
go
|
func newMixinDeclaration(ln *line, parent element) (*mixinDeclaration, error) {
name, paramNames, err := mixinNP(ln, true)
if err != nil {
return nil, err
}
return &mixinDeclaration{
elementBase: newElementBase(ln, parent),
name: name,
paramNames: paramNames,
}, nil
}
|
[
"func",
"newMixinDeclaration",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"(",
"*",
"mixinDeclaration",
",",
"error",
")",
"{",
"name",
",",
"paramNames",
",",
"err",
":=",
"mixinNP",
"(",
"ln",
",",
"true",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"mixinDeclaration",
"{",
"elementBase",
":",
"newElementBase",
"(",
"ln",
",",
"parent",
")",
",",
"name",
":",
"name",
",",
"paramNames",
":",
"paramNames",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// newMixinDeclaration creates and returns a mixin declaration.
|
[
"newMixinDeclaration",
"creates",
"and",
"returns",
"a",
"mixin",
"declaration",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/mixin_declaration.go#L73-L85
|
15,952 |
yosssi/gcss
|
element.go
|
newElement
|
func newElement(ln *line, parent element) (element, error) {
var e element
var err error
switch {
case ln.isComment():
e = newComment(ln, parent)
case ln.isAtRule():
e = newAtRule(ln, parent)
case ln.isMixinDeclaration():
// error can be ignored becuase the line is checked beforehand
// by calling `ln.isMixinDeclaration()`.
e, _ = newMixinDeclaration(ln, parent)
case ln.isMixinInvocation():
// error can be ignored becuase the line is checked beforehand
// by calling `ln.isMixinInvocation()`.
e, _ = newMixinInvocation(ln, parent)
case ln.isVariable():
e, err = newVariable(ln, parent)
case ln.isDeclaration():
e, err = newDeclaration(ln, parent)
default:
e, err = newSelector(ln, parent)
}
return e, err
}
|
go
|
func newElement(ln *line, parent element) (element, error) {
var e element
var err error
switch {
case ln.isComment():
e = newComment(ln, parent)
case ln.isAtRule():
e = newAtRule(ln, parent)
case ln.isMixinDeclaration():
// error can be ignored becuase the line is checked beforehand
// by calling `ln.isMixinDeclaration()`.
e, _ = newMixinDeclaration(ln, parent)
case ln.isMixinInvocation():
// error can be ignored becuase the line is checked beforehand
// by calling `ln.isMixinInvocation()`.
e, _ = newMixinInvocation(ln, parent)
case ln.isVariable():
e, err = newVariable(ln, parent)
case ln.isDeclaration():
e, err = newDeclaration(ln, parent)
default:
e, err = newSelector(ln, parent)
}
return e, err
}
|
[
"func",
"newElement",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"(",
"element",
",",
"error",
")",
"{",
"var",
"e",
"element",
"\n",
"var",
"err",
"error",
"\n\n",
"switch",
"{",
"case",
"ln",
".",
"isComment",
"(",
")",
":",
"e",
"=",
"newComment",
"(",
"ln",
",",
"parent",
")",
"\n",
"case",
"ln",
".",
"isAtRule",
"(",
")",
":",
"e",
"=",
"newAtRule",
"(",
"ln",
",",
"parent",
")",
"\n",
"case",
"ln",
".",
"isMixinDeclaration",
"(",
")",
":",
"// error can be ignored becuase the line is checked beforehand",
"// by calling `ln.isMixinDeclaration()`.",
"e",
",",
"_",
"=",
"newMixinDeclaration",
"(",
"ln",
",",
"parent",
")",
"\n",
"case",
"ln",
".",
"isMixinInvocation",
"(",
")",
":",
"// error can be ignored becuase the line is checked beforehand",
"// by calling `ln.isMixinInvocation()`.",
"e",
",",
"_",
"=",
"newMixinInvocation",
"(",
"ln",
",",
"parent",
")",
"\n",
"case",
"ln",
".",
"isVariable",
"(",
")",
":",
"e",
",",
"err",
"=",
"newVariable",
"(",
"ln",
",",
"parent",
")",
"\n",
"case",
"ln",
".",
"isDeclaration",
"(",
")",
":",
"e",
",",
"err",
"=",
"newDeclaration",
"(",
"ln",
",",
"parent",
")",
"\n",
"default",
":",
"e",
",",
"err",
"=",
"newSelector",
"(",
"ln",
",",
"parent",
")",
"\n",
"}",
"\n\n",
"return",
"e",
",",
"err",
"\n",
"}"
] |
// newElement creates and returns an element.
|
[
"newElement",
"creates",
"and",
"returns",
"an",
"element",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/element.go#L15-L41
|
15,953 |
yosssi/gcss
|
declaration.go
|
WriteTo
|
func (dec *declaration) WriteTo(w io.Writer) (int64, error) {
return dec.writeTo(w, nil)
}
|
go
|
func (dec *declaration) WriteTo(w io.Writer) (int64, error) {
return dec.writeTo(w, nil)
}
|
[
"func",
"(",
"dec",
"*",
"declaration",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"return",
"dec",
".",
"writeTo",
"(",
"w",
",",
"nil",
")",
"\n",
"}"
] |
// WriteTo writes the declaration to the writer.
|
[
"WriteTo",
"writes",
"the",
"declaration",
"to",
"the",
"writer",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/declaration.go#L18-L20
|
15,954 |
yosssi/gcss
|
declaration.go
|
writeTo
|
func (dec *declaration) writeTo(w io.Writer, params map[string]string) (int64, error) {
bf := new(bytes.Buffer)
bf.WriteString(dec.property)
bf.WriteString(colon)
for i, v := range strings.Split(dec.value, space) {
if i > 0 {
bf.WriteString(space)
}
for j, w := range strings.Split(v, comma) {
if j > 0 {
bf.WriteString(comma)
}
if strings.HasPrefix(w, dollarMark) {
// Writing to the bytes.Buffer never returns an error.
dec.writeParamTo(bf, strings.TrimPrefix(w, dollarMark), params)
} else {
bf.WriteString(w)
}
}
}
bf.WriteString(semicolon)
n, err := w.Write(bf.Bytes())
return int64(n), err
}
|
go
|
func (dec *declaration) writeTo(w io.Writer, params map[string]string) (int64, error) {
bf := new(bytes.Buffer)
bf.WriteString(dec.property)
bf.WriteString(colon)
for i, v := range strings.Split(dec.value, space) {
if i > 0 {
bf.WriteString(space)
}
for j, w := range strings.Split(v, comma) {
if j > 0 {
bf.WriteString(comma)
}
if strings.HasPrefix(w, dollarMark) {
// Writing to the bytes.Buffer never returns an error.
dec.writeParamTo(bf, strings.TrimPrefix(w, dollarMark), params)
} else {
bf.WriteString(w)
}
}
}
bf.WriteString(semicolon)
n, err := w.Write(bf.Bytes())
return int64(n), err
}
|
[
"func",
"(",
"dec",
"*",
"declaration",
")",
"writeTo",
"(",
"w",
"io",
".",
"Writer",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"bf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"bf",
".",
"WriteString",
"(",
"dec",
".",
"property",
")",
"\n",
"bf",
".",
"WriteString",
"(",
"colon",
")",
"\n\n",
"for",
"i",
",",
"v",
":=",
"range",
"strings",
".",
"Split",
"(",
"dec",
".",
"value",
",",
"space",
")",
"{",
"if",
"i",
">",
"0",
"{",
"bf",
".",
"WriteString",
"(",
"space",
")",
"\n",
"}",
"\n\n",
"for",
"j",
",",
"w",
":=",
"range",
"strings",
".",
"Split",
"(",
"v",
",",
"comma",
")",
"{",
"if",
"j",
">",
"0",
"{",
"bf",
".",
"WriteString",
"(",
"comma",
")",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"w",
",",
"dollarMark",
")",
"{",
"// Writing to the bytes.Buffer never returns an error.",
"dec",
".",
"writeParamTo",
"(",
"bf",
",",
"strings",
".",
"TrimPrefix",
"(",
"w",
",",
"dollarMark",
")",
",",
"params",
")",
"\n",
"}",
"else",
"{",
"bf",
".",
"WriteString",
"(",
"w",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"bf",
".",
"WriteString",
"(",
"semicolon",
")",
"\n\n",
"n",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"bf",
".",
"Bytes",
"(",
")",
")",
"\n\n",
"return",
"int64",
"(",
"n",
")",
",",
"err",
"\n",
"}"
] |
// writeTo writes the declaration to the writer.
|
[
"writeTo",
"writes",
"the",
"declaration",
"to",
"the",
"writer",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/declaration.go#L23-L53
|
15,955 |
yosssi/gcss
|
declaration.go
|
writeParamTo
|
func (dec *declaration) writeParamTo(w io.Writer, name string, params map[string]string) (int64, error) {
if s, ok := params[name]; ok {
if strings.HasPrefix(s, dollarMark) {
if v, ok := dec.Context().vars[strings.TrimPrefix(s, dollarMark)]; ok {
return v.WriteTo(w)
}
return 0, nil
}
n, err := w.Write([]byte(s))
return int64(n), err
}
if v, ok := dec.Context().vars[name]; ok {
return v.WriteTo(w)
}
return 0, nil
}
|
go
|
func (dec *declaration) writeParamTo(w io.Writer, name string, params map[string]string) (int64, error) {
if s, ok := params[name]; ok {
if strings.HasPrefix(s, dollarMark) {
if v, ok := dec.Context().vars[strings.TrimPrefix(s, dollarMark)]; ok {
return v.WriteTo(w)
}
return 0, nil
}
n, err := w.Write([]byte(s))
return int64(n), err
}
if v, ok := dec.Context().vars[name]; ok {
return v.WriteTo(w)
}
return 0, nil
}
|
[
"func",
"(",
"dec",
"*",
"declaration",
")",
"writeParamTo",
"(",
"w",
"io",
".",
"Writer",
",",
"name",
"string",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"s",
",",
"ok",
":=",
"params",
"[",
"name",
"]",
";",
"ok",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"s",
",",
"dollarMark",
")",
"{",
"if",
"v",
",",
"ok",
":=",
"dec",
".",
"Context",
"(",
")",
".",
"vars",
"[",
"strings",
".",
"TrimPrefix",
"(",
"s",
",",
"dollarMark",
")",
"]",
";",
"ok",
"{",
"return",
"v",
".",
"WriteTo",
"(",
"w",
")",
"\n",
"}",
"\n",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"n",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"s",
")",
")",
"\n",
"return",
"int64",
"(",
"n",
")",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"v",
",",
"ok",
":=",
"dec",
".",
"Context",
"(",
")",
".",
"vars",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"v",
".",
"WriteTo",
"(",
"w",
")",
"\n",
"}",
"\n\n",
"return",
"0",
",",
"nil",
"\n",
"}"
] |
// writeParam writes the param to the writer.
|
[
"writeParam",
"writes",
"the",
"param",
"to",
"the",
"writer",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/declaration.go#L56-L74
|
15,956 |
yosssi/gcss
|
declaration.go
|
declarationPV
|
func declarationPV(ln *line) (string, string, error) {
pv := strings.SplitN(strings.TrimSpace(ln.s), space, 2)
if len(pv) < 2 {
return "", "", fmt.Errorf("declaration's property and value should be divided by a space [line: %d]", ln.no)
}
if !strings.HasSuffix(pv[0], colon) {
return "", "", fmt.Errorf("property should end with a colon [line: %d]", ln.no)
}
return strings.TrimSuffix(pv[0], colon), pv[1], nil
}
|
go
|
func declarationPV(ln *line) (string, string, error) {
pv := strings.SplitN(strings.TrimSpace(ln.s), space, 2)
if len(pv) < 2 {
return "", "", fmt.Errorf("declaration's property and value should be divided by a space [line: %d]", ln.no)
}
if !strings.HasSuffix(pv[0], colon) {
return "", "", fmt.Errorf("property should end with a colon [line: %d]", ln.no)
}
return strings.TrimSuffix(pv[0], colon), pv[1], nil
}
|
[
"func",
"declarationPV",
"(",
"ln",
"*",
"line",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"pv",
":=",
"strings",
".",
"SplitN",
"(",
"strings",
".",
"TrimSpace",
"(",
"ln",
".",
"s",
")",
",",
"space",
",",
"2",
")",
"\n\n",
"if",
"len",
"(",
"pv",
")",
"<",
"2",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"pv",
"[",
"0",
"]",
",",
"colon",
")",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"TrimSuffix",
"(",
"pv",
"[",
"0",
"]",
",",
"colon",
")",
",",
"pv",
"[",
"1",
"]",
",",
"nil",
"\n",
"}"
] |
// declarationPV extracts a declaration property and value
// from the line.
|
[
"declarationPV",
"extracts",
"a",
"declaration",
"property",
"and",
"value",
"from",
"the",
"line",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/declaration.go#L78-L90
|
15,957 |
yosssi/gcss
|
declaration.go
|
newDeclaration
|
func newDeclaration(ln *line, parent element) (*declaration, error) {
property, value, err := declarationPV(ln)
if err != nil {
return nil, err
}
if strings.HasSuffix(value, semicolon) {
return nil, fmt.Errorf("declaration must not end with %q [line: %d]", semicolon, ln.no)
}
return &declaration{
elementBase: newElementBase(ln, parent),
property: property,
value: value,
}, nil
}
|
go
|
func newDeclaration(ln *line, parent element) (*declaration, error) {
property, value, err := declarationPV(ln)
if err != nil {
return nil, err
}
if strings.HasSuffix(value, semicolon) {
return nil, fmt.Errorf("declaration must not end with %q [line: %d]", semicolon, ln.no)
}
return &declaration{
elementBase: newElementBase(ln, parent),
property: property,
value: value,
}, nil
}
|
[
"func",
"newDeclaration",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"(",
"*",
"declaration",
",",
"error",
")",
"{",
"property",
",",
"value",
",",
"err",
":=",
"declarationPV",
"(",
"ln",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"value",
",",
"semicolon",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"semicolon",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"declaration",
"{",
"elementBase",
":",
"newElementBase",
"(",
"ln",
",",
"parent",
")",
",",
"property",
":",
"property",
",",
"value",
":",
"value",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// newDeclaration creates and returns a declaration.
|
[
"newDeclaration",
"creates",
"and",
"returns",
"a",
"declaration",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/declaration.go#L93-L109
|
15,958 |
yosssi/gcss
|
element_base.go
|
AppendChild
|
func (eBase *elementBase) AppendChild(child element) {
switch c := child.(type) {
case *mixinInvocation:
eBase.mixins = append(eBase.mixins, c)
case *declaration:
eBase.decs = append(eBase.decs, c)
case *selector:
eBase.sels = append(eBase.sels, c)
}
}
|
go
|
func (eBase *elementBase) AppendChild(child element) {
switch c := child.(type) {
case *mixinInvocation:
eBase.mixins = append(eBase.mixins, c)
case *declaration:
eBase.decs = append(eBase.decs, c)
case *selector:
eBase.sels = append(eBase.sels, c)
}
}
|
[
"func",
"(",
"eBase",
"*",
"elementBase",
")",
"AppendChild",
"(",
"child",
"element",
")",
"{",
"switch",
"c",
":=",
"child",
".",
"(",
"type",
")",
"{",
"case",
"*",
"mixinInvocation",
":",
"eBase",
".",
"mixins",
"=",
"append",
"(",
"eBase",
".",
"mixins",
",",
"c",
")",
"\n",
"case",
"*",
"declaration",
":",
"eBase",
".",
"decs",
"=",
"append",
"(",
"eBase",
".",
"decs",
",",
"c",
")",
"\n",
"case",
"*",
"selector",
":",
"eBase",
".",
"sels",
"=",
"append",
"(",
"eBase",
".",
"sels",
",",
"c",
")",
"\n",
"}",
"\n",
"}"
] |
// AppendChild appends a child element to the element.
|
[
"AppendChild",
"appends",
"a",
"child",
"element",
"to",
"the",
"element",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/element_base.go#L19-L28
|
15,959 |
yosssi/gcss
|
element_base.go
|
Context
|
func (eBase *elementBase) Context() *context {
if eBase.parent != nil {
return eBase.parent.Context()
}
return eBase.ctx
}
|
go
|
func (eBase *elementBase) Context() *context {
if eBase.parent != nil {
return eBase.parent.Context()
}
return eBase.ctx
}
|
[
"func",
"(",
"eBase",
"*",
"elementBase",
")",
"Context",
"(",
")",
"*",
"context",
"{",
"if",
"eBase",
".",
"parent",
"!=",
"nil",
"{",
"return",
"eBase",
".",
"parent",
".",
"Context",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"eBase",
".",
"ctx",
"\n",
"}"
] |
// Context returns the top element's context.
|
[
"Context",
"returns",
"the",
"top",
"element",
"s",
"context",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/element_base.go#L41-L47
|
15,960 |
yosssi/gcss
|
element_base.go
|
hasMixinDecs
|
func (eBase *elementBase) hasMixinDecs() bool {
for _, mi := range eBase.mixins {
if decs, _ := mi.decsParams(); len(decs) > 0 {
return true
}
}
return false
}
|
go
|
func (eBase *elementBase) hasMixinDecs() bool {
for _, mi := range eBase.mixins {
if decs, _ := mi.decsParams(); len(decs) > 0 {
return true
}
}
return false
}
|
[
"func",
"(",
"eBase",
"*",
"elementBase",
")",
"hasMixinDecs",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"mi",
":=",
"range",
"eBase",
".",
"mixins",
"{",
"if",
"decs",
",",
"_",
":=",
"mi",
".",
"decsParams",
"(",
")",
";",
"len",
"(",
"decs",
")",
">",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// hasMixinDecs returns true if the element has a mixin
// which has declarations.
|
[
"hasMixinDecs",
"returns",
"true",
"if",
"the",
"element",
"has",
"a",
"mixin",
"which",
"has",
"declarations",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/element_base.go#L51-L59
|
15,961 |
yosssi/gcss
|
element_base.go
|
hasMixinSels
|
func (eBase *elementBase) hasMixinSels() bool {
for _, mi := range eBase.mixins {
if sels, _ := mi.selsParams(); len(sels) > 0 {
return true
}
}
return false
}
|
go
|
func (eBase *elementBase) hasMixinSels() bool {
for _, mi := range eBase.mixins {
if sels, _ := mi.selsParams(); len(sels) > 0 {
return true
}
}
return false
}
|
[
"func",
"(",
"eBase",
"*",
"elementBase",
")",
"hasMixinSels",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"mi",
":=",
"range",
"eBase",
".",
"mixins",
"{",
"if",
"sels",
",",
"_",
":=",
"mi",
".",
"selsParams",
"(",
")",
";",
"len",
"(",
"sels",
")",
">",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// hasMixinSels returns true if the element has a mixin
// which has selectors.
|
[
"hasMixinSels",
"returns",
"true",
"if",
"the",
"element",
"has",
"a",
"mixin",
"which",
"has",
"selectors",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/element_base.go#L63-L71
|
15,962 |
yosssi/gcss
|
element_base.go
|
writeDecsTo
|
func (eBase *elementBase) writeDecsTo(w io.Writer, params map[string]string) (int64, error) {
bf := new(bytes.Buffer)
// Write the declarations.
for _, dec := range eBase.decs {
// Writing to the bytes.Buffer never returns an error.
dec.writeTo(bf, params)
}
// Write the mixin's declarations.
for _, mi := range eBase.mixins {
decs, prms := mi.decsParams()
for _, dec := range decs {
// Writing to the bytes.Buffer never returns an error.
dec.writeTo(bf, prms)
}
}
n, err := w.Write(bf.Bytes())
return int64(n), err
}
|
go
|
func (eBase *elementBase) writeDecsTo(w io.Writer, params map[string]string) (int64, error) {
bf := new(bytes.Buffer)
// Write the declarations.
for _, dec := range eBase.decs {
// Writing to the bytes.Buffer never returns an error.
dec.writeTo(bf, params)
}
// Write the mixin's declarations.
for _, mi := range eBase.mixins {
decs, prms := mi.decsParams()
for _, dec := range decs {
// Writing to the bytes.Buffer never returns an error.
dec.writeTo(bf, prms)
}
}
n, err := w.Write(bf.Bytes())
return int64(n), err
}
|
[
"func",
"(",
"eBase",
"*",
"elementBase",
")",
"writeDecsTo",
"(",
"w",
"io",
".",
"Writer",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"bf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"// Write the declarations.",
"for",
"_",
",",
"dec",
":=",
"range",
"eBase",
".",
"decs",
"{",
"// Writing to the bytes.Buffer never returns an error.",
"dec",
".",
"writeTo",
"(",
"bf",
",",
"params",
")",
"\n",
"}",
"\n\n",
"// Write the mixin's declarations.",
"for",
"_",
",",
"mi",
":=",
"range",
"eBase",
".",
"mixins",
"{",
"decs",
",",
"prms",
":=",
"mi",
".",
"decsParams",
"(",
")",
"\n\n",
"for",
"_",
",",
"dec",
":=",
"range",
"decs",
"{",
"// Writing to the bytes.Buffer never returns an error.",
"dec",
".",
"writeTo",
"(",
"bf",
",",
"prms",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"n",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"bf",
".",
"Bytes",
"(",
")",
")",
"\n\n",
"return",
"int64",
"(",
"n",
")",
",",
"err",
"\n",
"}"
] |
// writeDecsTo writes the element's declarations to w.
|
[
"writeDecsTo",
"writes",
"the",
"element",
"s",
"declarations",
"to",
"w",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/element_base.go#L74-L96
|
15,963 |
yosssi/gcss
|
element_base.go
|
newElementBase
|
func newElementBase(ln *line, parent element) elementBase {
return elementBase{
ln: ln,
parent: parent,
}
}
|
go
|
func newElementBase(ln *line, parent element) elementBase {
return elementBase{
ln: ln,
parent: parent,
}
}
|
[
"func",
"newElementBase",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"elementBase",
"{",
"return",
"elementBase",
"{",
"ln",
":",
"ln",
",",
"parent",
":",
"parent",
",",
"}",
"\n",
"}"
] |
// newElementBase creates and returns an element base.
|
[
"newElementBase",
"creates",
"and",
"returns",
"an",
"element",
"base",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/element_base.go#L99-L104
|
15,964 |
yosssi/gcss
|
cmd/gcss/main.go
|
writeTo
|
func writeTo(w io.Writer, s string) {
w.Write([]byte(s + "\n"))
}
|
go
|
func writeTo(w io.Writer, s string) {
w.Write([]byte(s + "\n"))
}
|
[
"func",
"writeTo",
"(",
"w",
"io",
".",
"Writer",
",",
"s",
"string",
")",
"{",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"s",
"+",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"}"
] |
// writeTo writes s to w.
|
[
"writeTo",
"writes",
"s",
"to",
"w",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/cmd/gcss/main.go#L56-L58
|
15,965 |
yosssi/gcss
|
write.go
|
write
|
func write(path string, bc <-chan []byte, berrc <-chan error) (<-chan struct{}, <-chan error) {
done := make(chan struct{})
errc := make(chan error)
go func() {
f, err := os.Create(path)
if err != nil {
errc <- err
return
}
defer f.Close()
w := newBufWriter(f)
for {
select {
case b, ok := <-bc:
if !ok {
if err := w.Flush(); err != nil {
errc <- err
return
}
done <- struct{}{}
return
}
if _, err := w.Write(b); err != nil {
errc <- err
return
}
case err := <-berrc:
errc <- err
return
}
}
}()
return done, errc
}
|
go
|
func write(path string, bc <-chan []byte, berrc <-chan error) (<-chan struct{}, <-chan error) {
done := make(chan struct{})
errc := make(chan error)
go func() {
f, err := os.Create(path)
if err != nil {
errc <- err
return
}
defer f.Close()
w := newBufWriter(f)
for {
select {
case b, ok := <-bc:
if !ok {
if err := w.Flush(); err != nil {
errc <- err
return
}
done <- struct{}{}
return
}
if _, err := w.Write(b); err != nil {
errc <- err
return
}
case err := <-berrc:
errc <- err
return
}
}
}()
return done, errc
}
|
[
"func",
"write",
"(",
"path",
"string",
",",
"bc",
"<-",
"chan",
"[",
"]",
"byte",
",",
"berrc",
"<-",
"chan",
"error",
")",
"(",
"<-",
"chan",
"struct",
"{",
"}",
",",
"<-",
"chan",
"error",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"errc",
":=",
"make",
"(",
"chan",
"error",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"path",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"errc",
"<-",
"err",
"\n",
"return",
"\n",
"}",
"\n\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"w",
":=",
"newBufWriter",
"(",
"f",
")",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"b",
",",
"ok",
":=",
"<-",
"bc",
":",
"if",
"!",
"ok",
"{",
"if",
"err",
":=",
"w",
".",
"Flush",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"errc",
"<-",
"err",
"\n",
"return",
"\n",
"}",
"\n\n",
"done",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"return",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"errc",
"<-",
"err",
"\n",
"return",
"\n",
"}",
"\n",
"case",
"err",
":=",
"<-",
"berrc",
":",
"errc",
"<-",
"err",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"done",
",",
"errc",
"\n",
"}"
] |
// write writes the input byte data to the CSS file.
|
[
"write",
"writes",
"the",
"input",
"byte",
"data",
"to",
"the",
"CSS",
"file",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/write.go#L20-L62
|
15,966 |
yosssi/gcss
|
mixin_invocation.go
|
decsParams
|
func (mi *mixinInvocation) decsParams() ([]*declaration, map[string]string) {
md, ok := mi.Context().mixins[mi.name]
if !ok {
return nil, nil
}
params := make(map[string]string)
l := len(mi.paramValues)
for i, name := range md.paramNames {
if i < l {
params[name] = mi.paramValues[i]
}
}
return md.decs, params
}
|
go
|
func (mi *mixinInvocation) decsParams() ([]*declaration, map[string]string) {
md, ok := mi.Context().mixins[mi.name]
if !ok {
return nil, nil
}
params := make(map[string]string)
l := len(mi.paramValues)
for i, name := range md.paramNames {
if i < l {
params[name] = mi.paramValues[i]
}
}
return md.decs, params
}
|
[
"func",
"(",
"mi",
"*",
"mixinInvocation",
")",
"decsParams",
"(",
")",
"(",
"[",
"]",
"*",
"declaration",
",",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"md",
",",
"ok",
":=",
"mi",
".",
"Context",
"(",
")",
".",
"mixins",
"[",
"mi",
".",
"name",
"]",
"\n\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"params",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n\n",
"l",
":=",
"len",
"(",
"mi",
".",
"paramValues",
")",
"\n\n",
"for",
"i",
",",
"name",
":=",
"range",
"md",
".",
"paramNames",
"{",
"if",
"i",
"<",
"l",
"{",
"params",
"[",
"name",
"]",
"=",
"mi",
".",
"paramValues",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"md",
".",
"decs",
",",
"params",
"\n",
"}"
] |
// decsParams returns the mixin's declarations and params.
|
[
"decsParams",
"returns",
"the",
"mixin",
"s",
"declarations",
"and",
"params",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/mixin_invocation.go#L18-L36
|
15,967 |
yosssi/gcss
|
mixin_invocation.go
|
selsParams
|
func (mi *mixinInvocation) selsParams() ([]*selector, map[string]string) {
md, ok := mi.Context().mixins[mi.name]
if !ok {
return nil, nil
}
params := make(map[string]string)
l := len(mi.paramValues)
for i, name := range md.paramNames {
if i < l {
params[name] = mi.paramValues[i]
}
}
return md.sels, params
}
|
go
|
func (mi *mixinInvocation) selsParams() ([]*selector, map[string]string) {
md, ok := mi.Context().mixins[mi.name]
if !ok {
return nil, nil
}
params := make(map[string]string)
l := len(mi.paramValues)
for i, name := range md.paramNames {
if i < l {
params[name] = mi.paramValues[i]
}
}
return md.sels, params
}
|
[
"func",
"(",
"mi",
"*",
"mixinInvocation",
")",
"selsParams",
"(",
")",
"(",
"[",
"]",
"*",
"selector",
",",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"md",
",",
"ok",
":=",
"mi",
".",
"Context",
"(",
")",
".",
"mixins",
"[",
"mi",
".",
"name",
"]",
"\n\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"params",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n\n",
"l",
":=",
"len",
"(",
"mi",
".",
"paramValues",
")",
"\n\n",
"for",
"i",
",",
"name",
":=",
"range",
"md",
".",
"paramNames",
"{",
"if",
"i",
"<",
"l",
"{",
"params",
"[",
"name",
"]",
"=",
"mi",
".",
"paramValues",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"md",
".",
"sels",
",",
"params",
"\n",
"}"
] |
// selsParams returns the mixin's selectors and params.
|
[
"selsParams",
"returns",
"the",
"mixin",
"s",
"selectors",
"and",
"params",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/mixin_invocation.go#L39-L57
|
15,968 |
yosssi/gcss
|
mixin_invocation.go
|
newMixinInvocation
|
func newMixinInvocation(ln *line, parent element) (*mixinInvocation, error) {
name, paramValues, err := mixinNP(ln, false)
if err != nil {
return nil, err
}
return &mixinInvocation{
elementBase: newElementBase(ln, parent),
name: name,
paramValues: paramValues,
}, nil
}
|
go
|
func newMixinInvocation(ln *line, parent element) (*mixinInvocation, error) {
name, paramValues, err := mixinNP(ln, false)
if err != nil {
return nil, err
}
return &mixinInvocation{
elementBase: newElementBase(ln, parent),
name: name,
paramValues: paramValues,
}, nil
}
|
[
"func",
"newMixinInvocation",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"(",
"*",
"mixinInvocation",
",",
"error",
")",
"{",
"name",
",",
"paramValues",
",",
"err",
":=",
"mixinNP",
"(",
"ln",
",",
"false",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"mixinInvocation",
"{",
"elementBase",
":",
"newElementBase",
"(",
"ln",
",",
"parent",
")",
",",
"name",
":",
"name",
",",
"paramValues",
":",
"paramValues",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// newMixinInvocation creates and returns a mixin invocation.
|
[
"newMixinInvocation",
"creates",
"and",
"returns",
"a",
"mixin",
"invocation",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/mixin_invocation.go#L60-L72
|
15,969 |
yosssi/gcss
|
line.go
|
childOf
|
func (ln *line) childOf(parent element) (bool, error) {
var ok bool
var err error
switch pIndent := parent.Base().ln.indent; {
case ln.indent == pIndent+1:
ok = true
case ln.indent > pIndent+1:
err = fmt.Errorf("indent is invalid [line: %d]", ln.no)
}
return ok, err
}
|
go
|
func (ln *line) childOf(parent element) (bool, error) {
var ok bool
var err error
switch pIndent := parent.Base().ln.indent; {
case ln.indent == pIndent+1:
ok = true
case ln.indent > pIndent+1:
err = fmt.Errorf("indent is invalid [line: %d]", ln.no)
}
return ok, err
}
|
[
"func",
"(",
"ln",
"*",
"line",
")",
"childOf",
"(",
"parent",
"element",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"ok",
"bool",
"\n",
"var",
"err",
"error",
"\n\n",
"switch",
"pIndent",
":=",
"parent",
".",
"Base",
"(",
")",
".",
"ln",
".",
"indent",
";",
"{",
"case",
"ln",
".",
"indent",
"==",
"pIndent",
"+",
"1",
":",
"ok",
"=",
"true",
"\n",
"case",
"ln",
".",
"indent",
">",
"pIndent",
"+",
"1",
":",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"return",
"ok",
",",
"err",
"\n",
"}"
] |
// childOf returns true if the line is a child of the parent.
|
[
"childOf",
"returns",
"true",
"if",
"the",
"line",
"is",
"a",
"child",
"of",
"the",
"parent",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L30-L42
|
15,970 |
yosssi/gcss
|
line.go
|
isDeclaration
|
func (ln *line) isDeclaration() bool {
_, _, err := declarationPV(ln)
return err == nil
}
|
go
|
func (ln *line) isDeclaration() bool {
_, _, err := declarationPV(ln)
return err == nil
}
|
[
"func",
"(",
"ln",
"*",
"line",
")",
"isDeclaration",
"(",
")",
"bool",
"{",
"_",
",",
"_",
",",
"err",
":=",
"declarationPV",
"(",
"ln",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] |
// isDeclaration returns true if the line is a declaration.
|
[
"isDeclaration",
"returns",
"true",
"if",
"the",
"line",
"is",
"a",
"declaration",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L45-L48
|
15,971 |
yosssi/gcss
|
line.go
|
isAtRule
|
func (ln *line) isAtRule() bool {
return strings.HasPrefix(strings.TrimSpace(ln.s), atMark)
}
|
go
|
func (ln *line) isAtRule() bool {
return strings.HasPrefix(strings.TrimSpace(ln.s), atMark)
}
|
[
"func",
"(",
"ln",
"*",
"line",
")",
"isAtRule",
"(",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"strings",
".",
"TrimSpace",
"(",
"ln",
".",
"s",
")",
",",
"atMark",
")",
"\n",
"}"
] |
// isAtRule returns true if the line is an at-rule.
|
[
"isAtRule",
"returns",
"true",
"if",
"the",
"line",
"is",
"an",
"at",
"-",
"rule",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L51-L53
|
15,972 |
yosssi/gcss
|
line.go
|
isVariable
|
func (ln *line) isVariable() bool {
if !ln.isTopIndent() {
return false
}
_, _, err := variableNV(ln)
return err == nil
}
|
go
|
func (ln *line) isVariable() bool {
if !ln.isTopIndent() {
return false
}
_, _, err := variableNV(ln)
return err == nil
}
|
[
"func",
"(",
"ln",
"*",
"line",
")",
"isVariable",
"(",
")",
"bool",
"{",
"if",
"!",
"ln",
".",
"isTopIndent",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
":=",
"variableNV",
"(",
"ln",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] |
// isVariable returns true if the line is a variable.
|
[
"isVariable",
"returns",
"true",
"if",
"the",
"line",
"is",
"a",
"variable",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L56-L64
|
15,973 |
yosssi/gcss
|
line.go
|
isMixinDeclaration
|
func (ln *line) isMixinDeclaration() bool {
if !ln.isTopIndent() {
return false
}
_, _, err := mixinNP(ln, true)
return err == nil
}
|
go
|
func (ln *line) isMixinDeclaration() bool {
if !ln.isTopIndent() {
return false
}
_, _, err := mixinNP(ln, true)
return err == nil
}
|
[
"func",
"(",
"ln",
"*",
"line",
")",
"isMixinDeclaration",
"(",
")",
"bool",
"{",
"if",
"!",
"ln",
".",
"isTopIndent",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
":=",
"mixinNP",
"(",
"ln",
",",
"true",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] |
// isMixinDeclaration returns true if the line is a mixin declaration.
|
[
"isMixinDeclaration",
"returns",
"true",
"if",
"the",
"line",
"is",
"a",
"mixin",
"declaration",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L67-L75
|
15,974 |
yosssi/gcss
|
line.go
|
isMixinInvocation
|
func (ln *line) isMixinInvocation() bool {
if ln.isTopIndent() {
return false
}
_, _, err := mixinNP(ln, false)
return err == nil
}
|
go
|
func (ln *line) isMixinInvocation() bool {
if ln.isTopIndent() {
return false
}
_, _, err := mixinNP(ln, false)
return err == nil
}
|
[
"func",
"(",
"ln",
"*",
"line",
")",
"isMixinInvocation",
"(",
")",
"bool",
"{",
"if",
"ln",
".",
"isTopIndent",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
":=",
"mixinNP",
"(",
"ln",
",",
"false",
")",
"\n\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] |
// isMixinInvocation returns true if the line is a mixin invocation.
|
[
"isMixinInvocation",
"returns",
"true",
"if",
"the",
"line",
"is",
"a",
"mixin",
"invocation",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L78-L86
|
15,975 |
yosssi/gcss
|
line.go
|
isComment
|
func (ln *line) isComment() bool {
return strings.HasPrefix(strings.TrimSpace(ln.s), doubleSlash)
}
|
go
|
func (ln *line) isComment() bool {
return strings.HasPrefix(strings.TrimSpace(ln.s), doubleSlash)
}
|
[
"func",
"(",
"ln",
"*",
"line",
")",
"isComment",
"(",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"strings",
".",
"TrimSpace",
"(",
"ln",
".",
"s",
")",
",",
"doubleSlash",
")",
"\n",
"}"
] |
// isComment returns true if the line is a comment.
|
[
"isComment",
"returns",
"true",
"if",
"the",
"line",
"is",
"a",
"comment",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L89-L91
|
15,976 |
yosssi/gcss
|
line.go
|
newLine
|
func newLine(no int, s string) *line {
return &line{
no: no,
s: s,
indent: indent(s),
}
}
|
go
|
func newLine(no int, s string) *line {
return &line{
no: no,
s: s,
indent: indent(s),
}
}
|
[
"func",
"newLine",
"(",
"no",
"int",
",",
"s",
"string",
")",
"*",
"line",
"{",
"return",
"&",
"line",
"{",
"no",
":",
"no",
",",
"s",
":",
"s",
",",
"indent",
":",
"indent",
"(",
"s",
")",
",",
"}",
"\n",
"}"
] |
// newLine creates and returns a line.
|
[
"newLine",
"creates",
"and",
"returns",
"a",
"line",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L94-L100
|
15,977 |
yosssi/gcss
|
line.go
|
indent
|
func indent(s string) int {
var i int
for _, b := range s {
if b != unicodeSpace {
break
}
i++
}
return i / 2
}
|
go
|
func indent(s string) int {
var i int
for _, b := range s {
if b != unicodeSpace {
break
}
i++
}
return i / 2
}
|
[
"func",
"indent",
"(",
"s",
"string",
")",
"int",
"{",
"var",
"i",
"int",
"\n\n",
"for",
"_",
",",
"b",
":=",
"range",
"s",
"{",
"if",
"b",
"!=",
"unicodeSpace",
"{",
"break",
"\n",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"return",
"i",
"/",
"2",
"\n",
"}"
] |
// indent returns the string's indent.
|
[
"indent",
"returns",
"the",
"string",
"s",
"indent",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/line.go#L103-L114
|
15,978 |
yosssi/gcss
|
at_rule.go
|
WriteTo
|
func (ar *atRule) WriteTo(w io.Writer) (int64, error) {
bf := new(bytes.Buffer)
bf.WriteString(strings.TrimSpace(ar.ln.s))
if len(ar.sels) == 0 && len(ar.decs) == 0 && !ar.hasMixinDecs() && !ar.hasMixinSels() {
bf.WriteString(semicolon)
n, err := w.Write(bf.Bytes())
return int64(n), err
}
bf.WriteString(openBrace)
// Writing to the bytes.Buffer never returns an error.
ar.writeDecsTo(bf, nil)
for _, sel := range ar.sels {
// Writing to the bytes.Buffer never returns an error.
sel.WriteTo(bf)
}
// Write the mixin's selectors.
for _, mi := range ar.mixins {
sels, prms := mi.selsParams()
for _, sl := range sels {
sl.parent = ar
// Writing to the bytes.Buffer never returns an error.
sl.writeTo(bf, prms)
}
}
bf.WriteString(closeBrace)
n, err := w.Write(bf.Bytes())
return int64(n), err
}
|
go
|
func (ar *atRule) WriteTo(w io.Writer) (int64, error) {
bf := new(bytes.Buffer)
bf.WriteString(strings.TrimSpace(ar.ln.s))
if len(ar.sels) == 0 && len(ar.decs) == 0 && !ar.hasMixinDecs() && !ar.hasMixinSels() {
bf.WriteString(semicolon)
n, err := w.Write(bf.Bytes())
return int64(n), err
}
bf.WriteString(openBrace)
// Writing to the bytes.Buffer never returns an error.
ar.writeDecsTo(bf, nil)
for _, sel := range ar.sels {
// Writing to the bytes.Buffer never returns an error.
sel.WriteTo(bf)
}
// Write the mixin's selectors.
for _, mi := range ar.mixins {
sels, prms := mi.selsParams()
for _, sl := range sels {
sl.parent = ar
// Writing to the bytes.Buffer never returns an error.
sl.writeTo(bf, prms)
}
}
bf.WriteString(closeBrace)
n, err := w.Write(bf.Bytes())
return int64(n), err
}
|
[
"func",
"(",
"ar",
"*",
"atRule",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"bf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"bf",
".",
"WriteString",
"(",
"strings",
".",
"TrimSpace",
"(",
"ar",
".",
"ln",
".",
"s",
")",
")",
"\n\n",
"if",
"len",
"(",
"ar",
".",
"sels",
")",
"==",
"0",
"&&",
"len",
"(",
"ar",
".",
"decs",
")",
"==",
"0",
"&&",
"!",
"ar",
".",
"hasMixinDecs",
"(",
")",
"&&",
"!",
"ar",
".",
"hasMixinSels",
"(",
")",
"{",
"bf",
".",
"WriteString",
"(",
"semicolon",
")",
"\n",
"n",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"bf",
".",
"Bytes",
"(",
")",
")",
"\n",
"return",
"int64",
"(",
"n",
")",
",",
"err",
"\n",
"}",
"\n\n",
"bf",
".",
"WriteString",
"(",
"openBrace",
")",
"\n\n",
"// Writing to the bytes.Buffer never returns an error.",
"ar",
".",
"writeDecsTo",
"(",
"bf",
",",
"nil",
")",
"\n\n",
"for",
"_",
",",
"sel",
":=",
"range",
"ar",
".",
"sels",
"{",
"// Writing to the bytes.Buffer never returns an error.",
"sel",
".",
"WriteTo",
"(",
"bf",
")",
"\n",
"}",
"\n\n",
"// Write the mixin's selectors.",
"for",
"_",
",",
"mi",
":=",
"range",
"ar",
".",
"mixins",
"{",
"sels",
",",
"prms",
":=",
"mi",
".",
"selsParams",
"(",
")",
"\n\n",
"for",
"_",
",",
"sl",
":=",
"range",
"sels",
"{",
"sl",
".",
"parent",
"=",
"ar",
"\n",
"// Writing to the bytes.Buffer never returns an error.",
"sl",
".",
"writeTo",
"(",
"bf",
",",
"prms",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"bf",
".",
"WriteString",
"(",
"closeBrace",
")",
"\n\n",
"n",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"bf",
".",
"Bytes",
"(",
")",
")",
"\n\n",
"return",
"int64",
"(",
"n",
")",
",",
"err",
"\n",
"}"
] |
// WriteTo writes the at-rule to the writer.
|
[
"WriteTo",
"writes",
"the",
"at",
"-",
"rule",
"to",
"the",
"writer",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/at_rule.go#L15-L52
|
15,979 |
yosssi/gcss
|
at_rule.go
|
newAtRule
|
func newAtRule(ln *line, parent element) *atRule {
return &atRule{
elementBase: newElementBase(ln, parent),
}
}
|
go
|
func newAtRule(ln *line, parent element) *atRule {
return &atRule{
elementBase: newElementBase(ln, parent),
}
}
|
[
"func",
"newAtRule",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"*",
"atRule",
"{",
"return",
"&",
"atRule",
"{",
"elementBase",
":",
"newElementBase",
"(",
"ln",
",",
"parent",
")",
",",
"}",
"\n",
"}"
] |
// newAtRule creates and returns a at-rule.
|
[
"newAtRule",
"creates",
"and",
"returns",
"a",
"at",
"-",
"rule",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/at_rule.go#L55-L59
|
15,980 |
yosssi/gcss
|
selector.go
|
WriteTo
|
func (sel *selector) WriteTo(w io.Writer) (int64, error) {
return sel.writeTo(w, nil)
}
|
go
|
func (sel *selector) WriteTo(w io.Writer) (int64, error) {
return sel.writeTo(w, nil)
}
|
[
"func",
"(",
"sel",
"*",
"selector",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"return",
"sel",
".",
"writeTo",
"(",
"w",
",",
"nil",
")",
"\n",
"}"
] |
// WriteTo writes the selector to the writer.
|
[
"WriteTo",
"writes",
"the",
"selector",
"to",
"the",
"writer",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/selector.go#L17-L19
|
15,981 |
yosssi/gcss
|
selector.go
|
writeTo
|
func (sel *selector) writeTo(w io.Writer, params map[string]string) (int64, error) {
bf := new(bytes.Buffer)
// Write the declarations.
if len(sel.decs) > 0 || sel.hasMixinDecs() {
bf.WriteString(sel.names())
bf.WriteString(openBrace)
// Writing to the bytes.Buffer never returns an error.
sel.writeDecsTo(bf, params)
bf.WriteString(closeBrace)
}
// Write the child selectors.
for _, childSel := range sel.sels {
// Writing to the bytes.Buffer never returns an error.
childSel.writeTo(bf, params)
}
// Write the mixin's selectors.
for _, mi := range sel.mixins {
sels, prms := mi.selsParams()
for _, sl := range sels {
sl.parent = sel
// Writing to the bytes.Buffer never returns an error.
sl.writeTo(bf, prms)
}
}
n, err := w.Write(bf.Bytes())
return int64(n), err
}
|
go
|
func (sel *selector) writeTo(w io.Writer, params map[string]string) (int64, error) {
bf := new(bytes.Buffer)
// Write the declarations.
if len(sel.decs) > 0 || sel.hasMixinDecs() {
bf.WriteString(sel.names())
bf.WriteString(openBrace)
// Writing to the bytes.Buffer never returns an error.
sel.writeDecsTo(bf, params)
bf.WriteString(closeBrace)
}
// Write the child selectors.
for _, childSel := range sel.sels {
// Writing to the bytes.Buffer never returns an error.
childSel.writeTo(bf, params)
}
// Write the mixin's selectors.
for _, mi := range sel.mixins {
sels, prms := mi.selsParams()
for _, sl := range sels {
sl.parent = sel
// Writing to the bytes.Buffer never returns an error.
sl.writeTo(bf, prms)
}
}
n, err := w.Write(bf.Bytes())
return int64(n), err
}
|
[
"func",
"(",
"sel",
"*",
"selector",
")",
"writeTo",
"(",
"w",
"io",
".",
"Writer",
",",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"bf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"// Write the declarations.",
"if",
"len",
"(",
"sel",
".",
"decs",
")",
">",
"0",
"||",
"sel",
".",
"hasMixinDecs",
"(",
")",
"{",
"bf",
".",
"WriteString",
"(",
"sel",
".",
"names",
"(",
")",
")",
"\n",
"bf",
".",
"WriteString",
"(",
"openBrace",
")",
"\n\n",
"// Writing to the bytes.Buffer never returns an error.",
"sel",
".",
"writeDecsTo",
"(",
"bf",
",",
"params",
")",
"\n\n",
"bf",
".",
"WriteString",
"(",
"closeBrace",
")",
"\n",
"}",
"\n\n",
"// Write the child selectors.",
"for",
"_",
",",
"childSel",
":=",
"range",
"sel",
".",
"sels",
"{",
"// Writing to the bytes.Buffer never returns an error.",
"childSel",
".",
"writeTo",
"(",
"bf",
",",
"params",
")",
"\n",
"}",
"\n\n",
"// Write the mixin's selectors.",
"for",
"_",
",",
"mi",
":=",
"range",
"sel",
".",
"mixins",
"{",
"sels",
",",
"prms",
":=",
"mi",
".",
"selsParams",
"(",
")",
"\n\n",
"for",
"_",
",",
"sl",
":=",
"range",
"sels",
"{",
"sl",
".",
"parent",
"=",
"sel",
"\n",
"// Writing to the bytes.Buffer never returns an error.",
"sl",
".",
"writeTo",
"(",
"bf",
",",
"prms",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"n",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"bf",
".",
"Bytes",
"(",
")",
")",
"\n\n",
"return",
"int64",
"(",
"n",
")",
",",
"err",
"\n",
"}"
] |
// writeTo writes the selector to the writer.
|
[
"writeTo",
"writes",
"the",
"selector",
"to",
"the",
"writer",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/selector.go#L22-L56
|
15,982 |
yosssi/gcss
|
selector.go
|
names
|
func (sel *selector) names() string {
bf := new(bytes.Buffer)
switch parent := sel.parent.(type) {
case nil, *atRule:
for _, name := range strings.Split(sel.name, comma) {
if bf.Len() > 0 {
bf.WriteString(comma)
}
bf.WriteString(strings.TrimSpace(name))
}
case *selector:
for _, parentS := range strings.Split(parent.names(), comma) {
for _, s := range strings.Split(sel.name, comma) {
if bf.Len() > 0 {
bf.WriteString(comma)
}
s = strings.TrimSpace(s)
if strings.Index(s, ampersand) != -1 {
bf.WriteString(strings.Replace(s, ampersand, parentS, -1))
} else {
bf.WriteString(parentS)
bf.WriteString(space)
bf.WriteString(s)
}
}
}
}
return bf.String()
}
|
go
|
func (sel *selector) names() string {
bf := new(bytes.Buffer)
switch parent := sel.parent.(type) {
case nil, *atRule:
for _, name := range strings.Split(sel.name, comma) {
if bf.Len() > 0 {
bf.WriteString(comma)
}
bf.WriteString(strings.TrimSpace(name))
}
case *selector:
for _, parentS := range strings.Split(parent.names(), comma) {
for _, s := range strings.Split(sel.name, comma) {
if bf.Len() > 0 {
bf.WriteString(comma)
}
s = strings.TrimSpace(s)
if strings.Index(s, ampersand) != -1 {
bf.WriteString(strings.Replace(s, ampersand, parentS, -1))
} else {
bf.WriteString(parentS)
bf.WriteString(space)
bf.WriteString(s)
}
}
}
}
return bf.String()
}
|
[
"func",
"(",
"sel",
"*",
"selector",
")",
"names",
"(",
")",
"string",
"{",
"bf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"switch",
"parent",
":=",
"sel",
".",
"parent",
".",
"(",
"type",
")",
"{",
"case",
"nil",
",",
"*",
"atRule",
":",
"for",
"_",
",",
"name",
":=",
"range",
"strings",
".",
"Split",
"(",
"sel",
".",
"name",
",",
"comma",
")",
"{",
"if",
"bf",
".",
"Len",
"(",
")",
">",
"0",
"{",
"bf",
".",
"WriteString",
"(",
"comma",
")",
"\n",
"}",
"\n\n",
"bf",
".",
"WriteString",
"(",
"strings",
".",
"TrimSpace",
"(",
"name",
")",
")",
"\n",
"}",
"\n",
"case",
"*",
"selector",
":",
"for",
"_",
",",
"parentS",
":=",
"range",
"strings",
".",
"Split",
"(",
"parent",
".",
"names",
"(",
")",
",",
"comma",
")",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"strings",
".",
"Split",
"(",
"sel",
".",
"name",
",",
"comma",
")",
"{",
"if",
"bf",
".",
"Len",
"(",
")",
">",
"0",
"{",
"bf",
".",
"WriteString",
"(",
"comma",
")",
"\n",
"}",
"\n\n",
"s",
"=",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"\n\n",
"if",
"strings",
".",
"Index",
"(",
"s",
",",
"ampersand",
")",
"!=",
"-",
"1",
"{",
"bf",
".",
"WriteString",
"(",
"strings",
".",
"Replace",
"(",
"s",
",",
"ampersand",
",",
"parentS",
",",
"-",
"1",
")",
")",
"\n",
"}",
"else",
"{",
"bf",
".",
"WriteString",
"(",
"parentS",
")",
"\n",
"bf",
".",
"WriteString",
"(",
"space",
")",
"\n",
"bf",
".",
"WriteString",
"(",
"s",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"bf",
".",
"String",
"(",
")",
"\n",
"}"
] |
// names returns the selector names.
|
[
"names",
"returns",
"the",
"selector",
"names",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/selector.go#L59-L92
|
15,983 |
yosssi/gcss
|
selector.go
|
newSelector
|
func newSelector(ln *line, parent element) (*selector, error) {
name := strings.TrimSpace(ln.s)
if strings.HasSuffix(name, openBrace) {
return nil, fmt.Errorf("selector must not end with %q [line: %d]", openBrace, ln.no)
}
if strings.HasSuffix(name, closeBrace) {
return nil, fmt.Errorf("selector must not end with %q [line: %d]", closeBrace, ln.no)
}
return &selector{
elementBase: newElementBase(ln, parent),
name: name,
}, nil
}
|
go
|
func newSelector(ln *line, parent element) (*selector, error) {
name := strings.TrimSpace(ln.s)
if strings.HasSuffix(name, openBrace) {
return nil, fmt.Errorf("selector must not end with %q [line: %d]", openBrace, ln.no)
}
if strings.HasSuffix(name, closeBrace) {
return nil, fmt.Errorf("selector must not end with %q [line: %d]", closeBrace, ln.no)
}
return &selector{
elementBase: newElementBase(ln, parent),
name: name,
}, nil
}
|
[
"func",
"newSelector",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"(",
"*",
"selector",
",",
"error",
")",
"{",
"name",
":=",
"strings",
".",
"TrimSpace",
"(",
"ln",
".",
"s",
")",
"\n\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"name",
",",
"openBrace",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"openBrace",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"name",
",",
"closeBrace",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"closeBrace",
",",
"ln",
".",
"no",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"selector",
"{",
"elementBase",
":",
"newElementBase",
"(",
"ln",
",",
"parent",
")",
",",
"name",
":",
"name",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// newSelector creates and returns a selector.
|
[
"newSelector",
"creates",
"and",
"returns",
"a",
"selector",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/selector.go#L95-L110
|
15,984 |
yosssi/gcss
|
context.go
|
newContext
|
func newContext() *context {
return &context{
vars: make(map[string]*variable),
mixins: make(map[string]*mixinDeclaration),
}
}
|
go
|
func newContext() *context {
return &context{
vars: make(map[string]*variable),
mixins: make(map[string]*mixinDeclaration),
}
}
|
[
"func",
"newContext",
"(",
")",
"*",
"context",
"{",
"return",
"&",
"context",
"{",
"vars",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"variable",
")",
",",
"mixins",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"mixinDeclaration",
")",
",",
"}",
"\n",
"}"
] |
// newContext creates and returns a context.
|
[
"newContext",
"creates",
"and",
"returns",
"a",
"context",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/context.go#L10-L15
|
15,985 |
yosssi/gcss
|
comment.go
|
newComment
|
func newComment(ln *line, parent element) *comment {
return &comment{
elementBase: newElementBase(ln, parent),
}
}
|
go
|
func newComment(ln *line, parent element) *comment {
return &comment{
elementBase: newElementBase(ln, parent),
}
}
|
[
"func",
"newComment",
"(",
"ln",
"*",
"line",
",",
"parent",
"element",
")",
"*",
"comment",
"{",
"return",
"&",
"comment",
"{",
"elementBase",
":",
"newElementBase",
"(",
"ln",
",",
"parent",
")",
",",
"}",
"\n",
"}"
] |
// newComment creates and returns a comment.
|
[
"newComment",
"creates",
"and",
"returns",
"a",
"comment",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/comment.go#L16-L20
|
15,986 |
yosssi/gcss
|
parse.go
|
appendChildren
|
func appendChildren(parent element, lines []string, i *int, l int) error {
for *i < l {
// Fetch a line.
ln := newLine(*i+1, lines[*i])
// Ignore the empty line.
if ln.isEmpty() {
*i++
return nil
}
ok, err := ln.childOf(parent)
if err != nil {
return err
}
if !ok {
return nil
}
child, err := newElement(ln, parent)
if err != nil {
return err
}
parent.AppendChild(child)
*i++
if err := appendChildren(child, lines, i, l); err != nil {
return err
}
}
return nil
}
|
go
|
func appendChildren(parent element, lines []string, i *int, l int) error {
for *i < l {
// Fetch a line.
ln := newLine(*i+1, lines[*i])
// Ignore the empty line.
if ln.isEmpty() {
*i++
return nil
}
ok, err := ln.childOf(parent)
if err != nil {
return err
}
if !ok {
return nil
}
child, err := newElement(ln, parent)
if err != nil {
return err
}
parent.AppendChild(child)
*i++
if err := appendChildren(child, lines, i, l); err != nil {
return err
}
}
return nil
}
|
[
"func",
"appendChildren",
"(",
"parent",
"element",
",",
"lines",
"[",
"]",
"string",
",",
"i",
"*",
"int",
",",
"l",
"int",
")",
"error",
"{",
"for",
"*",
"i",
"<",
"l",
"{",
"// Fetch a line.",
"ln",
":=",
"newLine",
"(",
"*",
"i",
"+",
"1",
",",
"lines",
"[",
"*",
"i",
"]",
")",
"\n\n",
"// Ignore the empty line.",
"if",
"ln",
".",
"isEmpty",
"(",
")",
"{",
"*",
"i",
"++",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"ok",
",",
"err",
":=",
"ln",
".",
"childOf",
"(",
"parent",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"child",
",",
"err",
":=",
"newElement",
"(",
"ln",
",",
"parent",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"parent",
".",
"AppendChild",
"(",
"child",
")",
"\n\n",
"*",
"i",
"++",
"\n\n",
"if",
"err",
":=",
"appendChildren",
"(",
"child",
",",
"lines",
",",
"i",
",",
"l",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// appendChildren parses the lines and appends the child elements
// to the parent element.
|
[
"appendChildren",
"parses",
"the",
"lines",
"and",
"appends",
"the",
"child",
"elements",
"to",
"the",
"parent",
"element",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/parse.go#L72-L109
|
15,987 |
yosssi/gcss
|
parse.go
|
formatLF
|
func formatLF(s string) string {
return strings.Replace(strings.Replace(s, crlf, lf, -1), cr, lf, -1)
}
|
go
|
func formatLF(s string) string {
return strings.Replace(strings.Replace(s, crlf, lf, -1), cr, lf, -1)
}
|
[
"func",
"formatLF",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"strings",
".",
"Replace",
"(",
"strings",
".",
"Replace",
"(",
"s",
",",
"crlf",
",",
"lf",
",",
"-",
"1",
")",
",",
"cr",
",",
"lf",
",",
"-",
"1",
")",
"\n",
"}"
] |
// formatLF replaces the line feed codes with LF and
// returns the result string.
|
[
"formatLF",
"replaces",
"the",
"line",
"feed",
"codes",
"with",
"LF",
"and",
"returns",
"the",
"result",
"string",
"."
] |
39677598ea4f3ec1da5568173b4d43611f307edb
|
https://github.com/yosssi/gcss/blob/39677598ea4f3ec1da5568173b4d43611f307edb/parse.go#L113-L115
|
15,988 |
osamingo/jsonrpc
|
unmarshal.go
|
Unmarshal
|
func Unmarshal(params *fastjson.RawMessage, dst interface{}) *Error {
if params == nil {
return ErrInvalidParams()
}
if err := fastjson.Unmarshal(*params, dst); err != nil {
return ErrInvalidParams()
}
return nil
}
|
go
|
func Unmarshal(params *fastjson.RawMessage, dst interface{}) *Error {
if params == nil {
return ErrInvalidParams()
}
if err := fastjson.Unmarshal(*params, dst); err != nil {
return ErrInvalidParams()
}
return nil
}
|
[
"func",
"Unmarshal",
"(",
"params",
"*",
"fastjson",
".",
"RawMessage",
",",
"dst",
"interface",
"{",
"}",
")",
"*",
"Error",
"{",
"if",
"params",
"==",
"nil",
"{",
"return",
"ErrInvalidParams",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"fastjson",
".",
"Unmarshal",
"(",
"*",
"params",
",",
"dst",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ErrInvalidParams",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Unmarshal decodes JSON-RPC params.
|
[
"Unmarshal",
"decodes",
"JSON",
"-",
"RPC",
"params",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/unmarshal.go#L6-L14
|
15,989 |
osamingo/jsonrpc
|
context.go
|
RequestID
|
func RequestID(c context.Context) *fastjson.RawMessage {
return c.Value(requestIDKey{}).(*fastjson.RawMessage)
}
|
go
|
func RequestID(c context.Context) *fastjson.RawMessage {
return c.Value(requestIDKey{}).(*fastjson.RawMessage)
}
|
[
"func",
"RequestID",
"(",
"c",
"context",
".",
"Context",
")",
"*",
"fastjson",
".",
"RawMessage",
"{",
"return",
"c",
".",
"Value",
"(",
"requestIDKey",
"{",
"}",
")",
".",
"(",
"*",
"fastjson",
".",
"RawMessage",
")",
"\n",
"}"
] |
// RequestID takes request id from context.
|
[
"RequestID",
"takes",
"request",
"id",
"from",
"context",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/context.go#L12-L14
|
15,990 |
osamingo/jsonrpc
|
context.go
|
WithRequestID
|
func WithRequestID(c context.Context, id *fastjson.RawMessage) context.Context {
return context.WithValue(c, requestIDKey{}, id)
}
|
go
|
func WithRequestID(c context.Context, id *fastjson.RawMessage) context.Context {
return context.WithValue(c, requestIDKey{}, id)
}
|
[
"func",
"WithRequestID",
"(",
"c",
"context",
".",
"Context",
",",
"id",
"*",
"fastjson",
".",
"RawMessage",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"c",
",",
"requestIDKey",
"{",
"}",
",",
"id",
")",
"\n",
"}"
] |
// WithRequestID adds request id to context.
|
[
"WithRequestID",
"adds",
"request",
"id",
"to",
"context",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/context.go#L17-L19
|
15,991 |
osamingo/jsonrpc
|
handler.go
|
ServeHTTP
|
func (mr *MethodRepository) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rs, batch, err := ParseRequest(r)
if err != nil {
err := SendResponse(w, []*Response{
{
Version: Version,
Error: err,
},
}, false)
if err != nil {
fmt.Fprint(w, "Failed to encode error objects")
w.WriteHeader(http.StatusInternalServerError)
}
return
}
resp := make([]*Response, len(rs))
for i := range rs {
resp[i] = mr.InvokeMethod(r.Context(), rs[i])
}
if err := SendResponse(w, resp, batch); err != nil {
fmt.Fprint(w, "Failed to encode result objects")
w.WriteHeader(http.StatusInternalServerError)
}
}
|
go
|
func (mr *MethodRepository) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rs, batch, err := ParseRequest(r)
if err != nil {
err := SendResponse(w, []*Response{
{
Version: Version,
Error: err,
},
}, false)
if err != nil {
fmt.Fprint(w, "Failed to encode error objects")
w.WriteHeader(http.StatusInternalServerError)
}
return
}
resp := make([]*Response, len(rs))
for i := range rs {
resp[i] = mr.InvokeMethod(r.Context(), rs[i])
}
if err := SendResponse(w, resp, batch); err != nil {
fmt.Fprint(w, "Failed to encode result objects")
w.WriteHeader(http.StatusInternalServerError)
}
}
|
[
"func",
"(",
"mr",
"*",
"MethodRepository",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"rs",
",",
"batch",
",",
"err",
":=",
"ParseRequest",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
":=",
"SendResponse",
"(",
"w",
",",
"[",
"]",
"*",
"Response",
"{",
"{",
"Version",
":",
"Version",
",",
"Error",
":",
"err",
",",
"}",
",",
"}",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprint",
"(",
"w",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"resp",
":=",
"make",
"(",
"[",
"]",
"*",
"Response",
",",
"len",
"(",
"rs",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"rs",
"{",
"resp",
"[",
"i",
"]",
"=",
"mr",
".",
"InvokeMethod",
"(",
"r",
".",
"Context",
"(",
")",
",",
"rs",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"SendResponse",
"(",
"w",
",",
"resp",
",",
"batch",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprint",
"(",
"w",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}",
"\n",
"}"
] |
// ServeHTTP provides basic JSON-RPC handling.
|
[
"ServeHTTP",
"provides",
"basic",
"JSON",
"-",
"RPC",
"handling",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/handler.go#L17-L43
|
15,992 |
osamingo/jsonrpc
|
handler.go
|
InvokeMethod
|
func (mr *MethodRepository) InvokeMethod(c context.Context, r *Request) *Response {
var h Handler
res := NewResponse(r)
h, res.Error = mr.TakeMethod(r)
if res.Error != nil {
return res
}
res.Result, res.Error = h.ServeJSONRPC(WithRequestID(c, r.ID), r.Params)
if res.Error != nil {
res.Result = nil
}
return res
}
|
go
|
func (mr *MethodRepository) InvokeMethod(c context.Context, r *Request) *Response {
var h Handler
res := NewResponse(r)
h, res.Error = mr.TakeMethod(r)
if res.Error != nil {
return res
}
res.Result, res.Error = h.ServeJSONRPC(WithRequestID(c, r.ID), r.Params)
if res.Error != nil {
res.Result = nil
}
return res
}
|
[
"func",
"(",
"mr",
"*",
"MethodRepository",
")",
"InvokeMethod",
"(",
"c",
"context",
".",
"Context",
",",
"r",
"*",
"Request",
")",
"*",
"Response",
"{",
"var",
"h",
"Handler",
"\n",
"res",
":=",
"NewResponse",
"(",
"r",
")",
"\n",
"h",
",",
"res",
".",
"Error",
"=",
"mr",
".",
"TakeMethod",
"(",
"r",
")",
"\n",
"if",
"res",
".",
"Error",
"!=",
"nil",
"{",
"return",
"res",
"\n",
"}",
"\n",
"res",
".",
"Result",
",",
"res",
".",
"Error",
"=",
"h",
".",
"ServeJSONRPC",
"(",
"WithRequestID",
"(",
"c",
",",
"r",
".",
"ID",
")",
",",
"r",
".",
"Params",
")",
"\n",
"if",
"res",
".",
"Error",
"!=",
"nil",
"{",
"res",
".",
"Result",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] |
// InvokeMethod invokes JSON-RPC method.
|
[
"InvokeMethod",
"invokes",
"JSON",
"-",
"RPC",
"method",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/handler.go#L46-L58
|
15,993 |
osamingo/jsonrpc
|
method.go
|
TakeMethod
|
func (mr *MethodRepository) TakeMethod(r *Request) (Handler, *Error) {
if r.Method == "" || r.Version != Version {
return nil, ErrInvalidParams()
}
mr.m.RLock()
md, ok := mr.r[r.Method]
mr.m.RUnlock()
if !ok {
return nil, ErrMethodNotFound()
}
return md.Handler, nil
}
|
go
|
func (mr *MethodRepository) TakeMethod(r *Request) (Handler, *Error) {
if r.Method == "" || r.Version != Version {
return nil, ErrInvalidParams()
}
mr.m.RLock()
md, ok := mr.r[r.Method]
mr.m.RUnlock()
if !ok {
return nil, ErrMethodNotFound()
}
return md.Handler, nil
}
|
[
"func",
"(",
"mr",
"*",
"MethodRepository",
")",
"TakeMethod",
"(",
"r",
"*",
"Request",
")",
"(",
"Handler",
",",
"*",
"Error",
")",
"{",
"if",
"r",
".",
"Method",
"==",
"\"",
"\"",
"||",
"r",
".",
"Version",
"!=",
"Version",
"{",
"return",
"nil",
",",
"ErrInvalidParams",
"(",
")",
"\n",
"}",
"\n\n",
"mr",
".",
"m",
".",
"RLock",
"(",
")",
"\n",
"md",
",",
"ok",
":=",
"mr",
".",
"r",
"[",
"r",
".",
"Method",
"]",
"\n",
"mr",
".",
"m",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrMethodNotFound",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"md",
".",
"Handler",
",",
"nil",
"\n",
"}"
] |
// TakeMethod takes jsonrpc.Func in MethodRepository.
|
[
"TakeMethod",
"takes",
"jsonrpc",
".",
"Func",
"in",
"MethodRepository",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/method.go#L31-L44
|
15,994 |
osamingo/jsonrpc
|
method.go
|
RegisterMethod
|
func (mr *MethodRepository) RegisterMethod(method string, h Handler, params, result interface{}) error {
if method == "" || h == nil {
return errors.New("jsonrpc: method name and function should not be empty")
}
mr.m.Lock()
mr.r[method] = Metadata{
Handler: h,
Params: params,
Result: result,
}
mr.m.Unlock()
return nil
}
|
go
|
func (mr *MethodRepository) RegisterMethod(method string, h Handler, params, result interface{}) error {
if method == "" || h == nil {
return errors.New("jsonrpc: method name and function should not be empty")
}
mr.m.Lock()
mr.r[method] = Metadata{
Handler: h,
Params: params,
Result: result,
}
mr.m.Unlock()
return nil
}
|
[
"func",
"(",
"mr",
"*",
"MethodRepository",
")",
"RegisterMethod",
"(",
"method",
"string",
",",
"h",
"Handler",
",",
"params",
",",
"result",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"method",
"==",
"\"",
"\"",
"||",
"h",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"mr",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"mr",
".",
"r",
"[",
"method",
"]",
"=",
"Metadata",
"{",
"Handler",
":",
"h",
",",
"Params",
":",
"params",
",",
"Result",
":",
"result",
",",
"}",
"\n",
"mr",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RegisterMethod registers jsonrpc.Func to MethodRepository.
|
[
"RegisterMethod",
"registers",
"jsonrpc",
".",
"Func",
"to",
"MethodRepository",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/method.go#L47-L59
|
15,995 |
osamingo/jsonrpc
|
method.go
|
Methods
|
func (mr *MethodRepository) Methods() map[string]Metadata {
mr.m.RLock()
ml := make(map[string]Metadata, len(mr.r))
for k, md := range mr.r {
ml[k] = md
}
mr.m.RUnlock()
return ml
}
|
go
|
func (mr *MethodRepository) Methods() map[string]Metadata {
mr.m.RLock()
ml := make(map[string]Metadata, len(mr.r))
for k, md := range mr.r {
ml[k] = md
}
mr.m.RUnlock()
return ml
}
|
[
"func",
"(",
"mr",
"*",
"MethodRepository",
")",
"Methods",
"(",
")",
"map",
"[",
"string",
"]",
"Metadata",
"{",
"mr",
".",
"m",
".",
"RLock",
"(",
")",
"\n",
"ml",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Metadata",
",",
"len",
"(",
"mr",
".",
"r",
")",
")",
"\n",
"for",
"k",
",",
"md",
":=",
"range",
"mr",
".",
"r",
"{",
"ml",
"[",
"k",
"]",
"=",
"md",
"\n",
"}",
"\n",
"mr",
".",
"m",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"ml",
"\n",
"}"
] |
// Methods returns registered methods.
|
[
"Methods",
"returns",
"registered",
"methods",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/method.go#L62-L70
|
15,996 |
osamingo/jsonrpc
|
jsonrpc.go
|
ParseRequest
|
func ParseRequest(r *http.Request) ([]*Request, bool, *Error) {
var rerr *Error
if !strings.HasPrefix(r.Header.Get(contentTypeKey), contentTypeValue) {
return nil, false, ErrInvalidRequest()
}
buf := bytes.NewBuffer(make([]byte, 0, r.ContentLength))
if _, err := buf.ReadFrom(r.Body); err != nil {
return nil, false, ErrInvalidRequest()
}
defer func(r *http.Request) {
err := r.Body.Close()
if err != nil {
rerr = ErrInternal()
}
}(r)
if buf.Len() == 0 {
return nil, false, ErrInvalidRequest()
}
f, _, err := buf.ReadRune()
if err != nil {
return nil, false, ErrInvalidRequest()
}
if err := buf.UnreadRune(); err != nil {
return nil, false, ErrInvalidRequest()
}
var rs []*Request
if f != batchRequestKey {
var req *Request
if err := fastjson.NewDecoder(buf).Decode(&req); err != nil {
return nil, false, ErrParse()
}
return append(rs, req), false, nil
}
if err := fastjson.NewDecoder(buf).Decode(&rs); err != nil {
return nil, false, ErrParse()
}
return rs, true, rerr
}
|
go
|
func ParseRequest(r *http.Request) ([]*Request, bool, *Error) {
var rerr *Error
if !strings.HasPrefix(r.Header.Get(contentTypeKey), contentTypeValue) {
return nil, false, ErrInvalidRequest()
}
buf := bytes.NewBuffer(make([]byte, 0, r.ContentLength))
if _, err := buf.ReadFrom(r.Body); err != nil {
return nil, false, ErrInvalidRequest()
}
defer func(r *http.Request) {
err := r.Body.Close()
if err != nil {
rerr = ErrInternal()
}
}(r)
if buf.Len() == 0 {
return nil, false, ErrInvalidRequest()
}
f, _, err := buf.ReadRune()
if err != nil {
return nil, false, ErrInvalidRequest()
}
if err := buf.UnreadRune(); err != nil {
return nil, false, ErrInvalidRequest()
}
var rs []*Request
if f != batchRequestKey {
var req *Request
if err := fastjson.NewDecoder(buf).Decode(&req); err != nil {
return nil, false, ErrParse()
}
return append(rs, req), false, nil
}
if err := fastjson.NewDecoder(buf).Decode(&rs); err != nil {
return nil, false, ErrParse()
}
return rs, true, rerr
}
|
[
"func",
"ParseRequest",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"[",
"]",
"*",
"Request",
",",
"bool",
",",
"*",
"Error",
")",
"{",
"var",
"rerr",
"*",
"Error",
"\n\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"r",
".",
"Header",
".",
"Get",
"(",
"contentTypeKey",
")",
",",
"contentTypeValue",
")",
"{",
"return",
"nil",
",",
"false",
",",
"ErrInvalidRequest",
"(",
")",
"\n",
"}",
"\n\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"r",
".",
"ContentLength",
")",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"buf",
".",
"ReadFrom",
"(",
"r",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"ErrInvalidRequest",
"(",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"err",
":=",
"r",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"rerr",
"=",
"ErrInternal",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
"r",
")",
"\n\n",
"if",
"buf",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"false",
",",
"ErrInvalidRequest",
"(",
")",
"\n",
"}",
"\n\n",
"f",
",",
"_",
",",
"err",
":=",
"buf",
".",
"ReadRune",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"ErrInvalidRequest",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"buf",
".",
"UnreadRune",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"ErrInvalidRequest",
"(",
")",
"\n",
"}",
"\n\n",
"var",
"rs",
"[",
"]",
"*",
"Request",
"\n",
"if",
"f",
"!=",
"batchRequestKey",
"{",
"var",
"req",
"*",
"Request",
"\n",
"if",
"err",
":=",
"fastjson",
".",
"NewDecoder",
"(",
"buf",
")",
".",
"Decode",
"(",
"&",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"ErrParse",
"(",
")",
"\n",
"}",
"\n",
"return",
"append",
"(",
"rs",
",",
"req",
")",
",",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"fastjson",
".",
"NewDecoder",
"(",
"buf",
")",
".",
"Decode",
"(",
"&",
"rs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"ErrParse",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"rs",
",",
"true",
",",
"rerr",
"\n",
"}"
] |
// ParseRequest parses a HTTP request to JSON-RPC request.
|
[
"ParseRequest",
"parses",
"a",
"HTTP",
"request",
"to",
"JSON",
"-",
"RPC",
"request",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/jsonrpc.go#L39-L84
|
15,997 |
osamingo/jsonrpc
|
jsonrpc.go
|
NewResponse
|
func NewResponse(r *Request) *Response {
return &Response{
Version: r.Version,
ID: r.ID,
}
}
|
go
|
func NewResponse(r *Request) *Response {
return &Response{
Version: r.Version,
ID: r.ID,
}
}
|
[
"func",
"NewResponse",
"(",
"r",
"*",
"Request",
")",
"*",
"Response",
"{",
"return",
"&",
"Response",
"{",
"Version",
":",
"r",
".",
"Version",
",",
"ID",
":",
"r",
".",
"ID",
",",
"}",
"\n",
"}"
] |
// NewResponse generates a JSON-RPC response.
|
[
"NewResponse",
"generates",
"a",
"JSON",
"-",
"RPC",
"response",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/jsonrpc.go#L87-L92
|
15,998 |
osamingo/jsonrpc
|
jsonrpc.go
|
SendResponse
|
func SendResponse(w http.ResponseWriter, resp []*Response, batch bool) error {
w.Header().Set(contentTypeKey, contentTypeValue)
if batch || len(resp) > 1 {
return fastjson.NewEncoder(w).Encode(resp)
} else if len(resp) == 1 {
return fastjson.NewEncoder(w).Encode(resp[0])
}
return nil
}
|
go
|
func SendResponse(w http.ResponseWriter, resp []*Response, batch bool) error {
w.Header().Set(contentTypeKey, contentTypeValue)
if batch || len(resp) > 1 {
return fastjson.NewEncoder(w).Encode(resp)
} else if len(resp) == 1 {
return fastjson.NewEncoder(w).Encode(resp[0])
}
return nil
}
|
[
"func",
"SendResponse",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"resp",
"[",
"]",
"*",
"Response",
",",
"batch",
"bool",
")",
"error",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"contentTypeKey",
",",
"contentTypeValue",
")",
"\n",
"if",
"batch",
"||",
"len",
"(",
"resp",
")",
">",
"1",
"{",
"return",
"fastjson",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"resp",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"resp",
")",
"==",
"1",
"{",
"return",
"fastjson",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"resp",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// SendResponse writes JSON-RPC response.
|
[
"SendResponse",
"writes",
"JSON",
"-",
"RPC",
"response",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/jsonrpc.go#L95-L103
|
15,999 |
osamingo/jsonrpc
|
debug.go
|
ServeDebug
|
func (mr *MethodRepository) ServeDebug(w http.ResponseWriter, r *http.Request) { // nolint: unparam
ms := mr.Methods()
if len(ms) == 0 {
w.WriteHeader(http.StatusNotFound)
return
}
l := make([]*MethodReference, 0, len(ms))
for k, md := range ms {
l = append(l, makeMethodReference(k, md))
}
w.Header().Set(contentTypeKey, contentTypeValue)
if err := fastjson.NewEncoder(w).Encode(l); err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
}
|
go
|
func (mr *MethodRepository) ServeDebug(w http.ResponseWriter, r *http.Request) { // nolint: unparam
ms := mr.Methods()
if len(ms) == 0 {
w.WriteHeader(http.StatusNotFound)
return
}
l := make([]*MethodReference, 0, len(ms))
for k, md := range ms {
l = append(l, makeMethodReference(k, md))
}
w.Header().Set(contentTypeKey, contentTypeValue)
if err := fastjson.NewEncoder(w).Encode(l); err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
}
|
[
"func",
"(",
"mr",
"*",
"MethodRepository",
")",
"ServeDebug",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// nolint: unparam",
"ms",
":=",
"mr",
".",
"Methods",
"(",
")",
"\n",
"if",
"len",
"(",
"ms",
")",
"==",
"0",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusNotFound",
")",
"\n",
"return",
"\n",
"}",
"\n",
"l",
":=",
"make",
"(",
"[",
"]",
"*",
"MethodReference",
",",
"0",
",",
"len",
"(",
"ms",
")",
")",
"\n",
"for",
"k",
",",
"md",
":=",
"range",
"ms",
"{",
"l",
"=",
"append",
"(",
"l",
",",
"makeMethodReference",
"(",
"k",
",",
"md",
")",
")",
"\n",
"}",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"contentTypeKey",
",",
"contentTypeValue",
")",
"\n",
"if",
"err",
":=",
"fastjson",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"l",
")",
";",
"err",
"!=",
"nil",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
] |
// ServeDebug views registered method list.
|
[
"ServeDebug",
"views",
"registered",
"method",
"list",
"."
] |
4eab63bf79a0c3a9eba01903b194548650395676
|
https://github.com/osamingo/jsonrpc/blob/4eab63bf79a0c3a9eba01903b194548650395676/debug.go#L20-L35
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.