id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
151,100 | brutella/dnssd | service.go | addrsForInterface | func addrsForInterface(iface *net.Interface) ([]net.IP, []net.IP) {
var v4, v6, v6local []net.IP
addrs, _ := iface.Addrs()
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
v4 = append(v4, ipnet.IP)
} else {
switch ip := ipnet.IP.To16(); ip != nil {
case ip.IsGlobalUnicast():
v6 = append(v6, ipnet.IP)
case ip.IsLinkLocalUnicast():
v6local = append(v6local, ipnet.IP)
}
}
}
}
if len(v6) == 0 {
v6 = v6local
}
return v4, v6
} | go | func addrsForInterface(iface *net.Interface) ([]net.IP, []net.IP) {
var v4, v6, v6local []net.IP
addrs, _ := iface.Addrs()
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
v4 = append(v4, ipnet.IP)
} else {
switch ip := ipnet.IP.To16(); ip != nil {
case ip.IsGlobalUnicast():
v6 = append(v6, ipnet.IP)
case ip.IsLinkLocalUnicast():
v6local = append(v6local, ipnet.IP)
}
}
}
}
if len(v6) == 0 {
v6 = v6local
}
return v4, v6
} | [
"func",
"addrsForInterface",
"(",
"iface",
"*",
"net",
".",
"Interface",
")",
"(",
"[",
"]",
"net",
".",
"IP",
",",
"[",
"]",
"net",
".",
"IP",
")",
"{",
"var",
"v4",
",",
"v6",
",",
"v6local",
"[",
"]",
"net",
".",
"IP",
"\n\n",
"addrs",
",",
... | // addrsForInterface returns ipv4 and ipv6 addresses for a specific interface. | [
"addrsForInterface",
"returns",
"ipv4",
"and",
"ipv6",
"addresses",
"for",
"a",
"specific",
"interface",
"."
] | 61d1bc6e53ace5b3d9ecb46ffd0b3158c00ae9d0 | https://github.com/brutella/dnssd/blob/61d1bc6e53ace5b3d9ecb46ffd0b3158c00ae9d0/service.go#L267-L289 |
151,101 | brutella/dnssd | resolve.go | LookupInstance | func LookupInstance(ctx context.Context, instance string) (Service, error) {
var srv Service
conn, err := NewMDNSConn()
if err != nil {
return srv, err
}
return lookupInstance(ctx, instance, conn)
} | go | func LookupInstance(ctx context.Context, instance string) (Service, error) {
var srv Service
conn, err := NewMDNSConn()
if err != nil {
return srv, err
}
return lookupInstance(ctx, instance, conn)
} | [
"func",
"LookupInstance",
"(",
"ctx",
"context",
".",
"Context",
",",
"instance",
"string",
")",
"(",
"Service",
",",
"error",
")",
"{",
"var",
"srv",
"Service",
"\n\n",
"conn",
",",
"err",
":=",
"NewMDNSConn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",... | // LookupInstance resolves a service by its service instance name. | [
"LookupInstance",
"resolves",
"a",
"service",
"by",
"its",
"service",
"instance",
"name",
"."
] | 61d1bc6e53ace5b3d9ecb46ffd0b3158c00ae9d0 | https://github.com/brutella/dnssd/blob/61d1bc6e53ace5b3d9ecb46ffd0b3158c00ae9d0/resolve.go#L9-L18 |
151,102 | AkihiroSuda/go-netfilter-queue | netfilter.go | SetVerdict | func (p *NFPacket) SetVerdict(v Verdict) {
p.verdictChannel <- VerdictContainer{Verdict: v, Packet: nil}
} | go | func (p *NFPacket) SetVerdict(v Verdict) {
p.verdictChannel <- VerdictContainer{Verdict: v, Packet: nil}
} | [
"func",
"(",
"p",
"*",
"NFPacket",
")",
"SetVerdict",
"(",
"v",
"Verdict",
")",
"{",
"p",
".",
"verdictChannel",
"<-",
"VerdictContainer",
"{",
"Verdict",
":",
"v",
",",
"Packet",
":",
"nil",
"}",
"\n",
"}"
] | //Set the verdict for the packet | [
"Set",
"the",
"verdict",
"for",
"the",
"packet"
] | 5b02f804b4f292cd337dc6e4f211ca1ce7627db8 | https://github.com/AkihiroSuda/go-netfilter-queue/blob/5b02f804b4f292cd337dc6e4f211ca1ce7627db8/netfilter.go#L63-L65 |
151,103 | AkihiroSuda/go-netfilter-queue | netfilter.go | SetVerdictWithPacket | func (p *NFPacket) SetVerdictWithPacket(v Verdict, packet []byte) {
p.verdictChannel <- VerdictContainer{Verdict: v, Packet: packet}
} | go | func (p *NFPacket) SetVerdictWithPacket(v Verdict, packet []byte) {
p.verdictChannel <- VerdictContainer{Verdict: v, Packet: packet}
} | [
"func",
"(",
"p",
"*",
"NFPacket",
")",
"SetVerdictWithPacket",
"(",
"v",
"Verdict",
",",
"packet",
"[",
"]",
"byte",
")",
"{",
"p",
".",
"verdictChannel",
"<-",
"VerdictContainer",
"{",
"Verdict",
":",
"v",
",",
"Packet",
":",
"packet",
"}",
"\n",
"}"... | //Set the verdict for the packet AND provide new packet content for injection | [
"Set",
"the",
"verdict",
"for",
"the",
"packet",
"AND",
"provide",
"new",
"packet",
"content",
"for",
"injection"
] | 5b02f804b4f292cd337dc6e4f211ca1ce7627db8 | https://github.com/AkihiroSuda/go-netfilter-queue/blob/5b02f804b4f292cd337dc6e4f211ca1ce7627db8/netfilter.go#L76-L78 |
151,104 | AkihiroSuda/go-netfilter-queue | netfilter.go | NewNFQueue | func NewNFQueue(queueId uint16, maxPacketsInQueue uint32, packetSize uint32) (*NFQueue, error) {
var nfq = NFQueue{}
var err error
var ret C.int
if nfq.h, err = C.nfq_open(); err != nil {
return nil, fmt.Errorf("Error opening NFQueue handle: %v\n", err)
}
if ret, err = C.nfq_unbind_pf(nfq.h, AF_INET); err != nil || ret < 0 {
return nil, fmt.Errorf("Error unbinding existing NFQ handler from AF_INET protocol family: %v\n", err)
}
if ret, err = C.nfq_unbind_pf(nfq.h, AF_INET6); err != nil || ret < 0 {
return nil, fmt.Errorf("Error unbinding existing NFQ handler from AF_INET6 protocol family: %v\n", err)
}
if ret, err := C.nfq_bind_pf(nfq.h, AF_INET); err != nil || ret < 0 {
return nil, fmt.Errorf("Error binding to AF_INET protocol family: %v\n", err)
}
if ret, err := C.nfq_bind_pf(nfq.h, AF_INET6); err != nil || ret < 0 {
return nil, fmt.Errorf("Error binding to AF_INET6 protocol family: %v\n", err)
}
nfq.packets = make(chan NFPacket)
nfq.idx = uint32(time.Now().UnixNano())
theTabeLock.Lock()
theTable[nfq.idx] = &nfq.packets
theTabeLock.Unlock()
if nfq.qh, err = C.CreateQueue(nfq.h, C.u_int16_t(queueId), C.u_int32_t(nfq.idx)); err != nil || nfq.qh == nil {
C.nfq_close(nfq.h)
return nil, fmt.Errorf("Error binding to queue: %v\n", err)
}
if ret, err = C.nfq_set_queue_maxlen(nfq.qh, C.u_int32_t(maxPacketsInQueue)); err != nil || ret < 0 {
C.nfq_destroy_queue(nfq.qh)
C.nfq_close(nfq.h)
return nil, fmt.Errorf("Unable to set max packets in queue: %v\n", err)
}
if C.nfq_set_mode(nfq.qh, C.u_int8_t(2), C.uint(packetSize)) < 0 {
C.nfq_destroy_queue(nfq.qh)
C.nfq_close(nfq.h)
return nil, fmt.Errorf("Unable to set packets copy mode: %v\n", err)
}
if nfq.fd, err = C.nfq_fd(nfq.h); err != nil {
C.nfq_destroy_queue(nfq.qh)
C.nfq_close(nfq.h)
return nil, fmt.Errorf("Unable to get queue file-descriptor. %v\n", err)
}
go nfq.run()
return &nfq, nil
} | go | func NewNFQueue(queueId uint16, maxPacketsInQueue uint32, packetSize uint32) (*NFQueue, error) {
var nfq = NFQueue{}
var err error
var ret C.int
if nfq.h, err = C.nfq_open(); err != nil {
return nil, fmt.Errorf("Error opening NFQueue handle: %v\n", err)
}
if ret, err = C.nfq_unbind_pf(nfq.h, AF_INET); err != nil || ret < 0 {
return nil, fmt.Errorf("Error unbinding existing NFQ handler from AF_INET protocol family: %v\n", err)
}
if ret, err = C.nfq_unbind_pf(nfq.h, AF_INET6); err != nil || ret < 0 {
return nil, fmt.Errorf("Error unbinding existing NFQ handler from AF_INET6 protocol family: %v\n", err)
}
if ret, err := C.nfq_bind_pf(nfq.h, AF_INET); err != nil || ret < 0 {
return nil, fmt.Errorf("Error binding to AF_INET protocol family: %v\n", err)
}
if ret, err := C.nfq_bind_pf(nfq.h, AF_INET6); err != nil || ret < 0 {
return nil, fmt.Errorf("Error binding to AF_INET6 protocol family: %v\n", err)
}
nfq.packets = make(chan NFPacket)
nfq.idx = uint32(time.Now().UnixNano())
theTabeLock.Lock()
theTable[nfq.idx] = &nfq.packets
theTabeLock.Unlock()
if nfq.qh, err = C.CreateQueue(nfq.h, C.u_int16_t(queueId), C.u_int32_t(nfq.idx)); err != nil || nfq.qh == nil {
C.nfq_close(nfq.h)
return nil, fmt.Errorf("Error binding to queue: %v\n", err)
}
if ret, err = C.nfq_set_queue_maxlen(nfq.qh, C.u_int32_t(maxPacketsInQueue)); err != nil || ret < 0 {
C.nfq_destroy_queue(nfq.qh)
C.nfq_close(nfq.h)
return nil, fmt.Errorf("Unable to set max packets in queue: %v\n", err)
}
if C.nfq_set_mode(nfq.qh, C.u_int8_t(2), C.uint(packetSize)) < 0 {
C.nfq_destroy_queue(nfq.qh)
C.nfq_close(nfq.h)
return nil, fmt.Errorf("Unable to set packets copy mode: %v\n", err)
}
if nfq.fd, err = C.nfq_fd(nfq.h); err != nil {
C.nfq_destroy_queue(nfq.qh)
C.nfq_close(nfq.h)
return nil, fmt.Errorf("Unable to get queue file-descriptor. %v\n", err)
}
go nfq.run()
return &nfq, nil
} | [
"func",
"NewNFQueue",
"(",
"queueId",
"uint16",
",",
"maxPacketsInQueue",
"uint32",
",",
"packetSize",
"uint32",
")",
"(",
"*",
"NFQueue",
",",
"error",
")",
"{",
"var",
"nfq",
"=",
"NFQueue",
"{",
"}",
"\n",
"var",
"err",
"error",
"\n",
"var",
"ret",
... | //Create and bind to queue specified by queueId | [
"Create",
"and",
"bind",
"to",
"queue",
"specified",
"by",
"queueId"
] | 5b02f804b4f292cd337dc6e4f211ca1ce7627db8 | https://github.com/AkihiroSuda/go-netfilter-queue/blob/5b02f804b4f292cd337dc6e4f211ca1ce7627db8/netfilter.go#L108-L164 |
151,105 | AkihiroSuda/go-netfilter-queue | netfilter.go | Close | func (nfq *NFQueue) Close() {
C.nfq_destroy_queue(nfq.qh)
C.nfq_close(nfq.h)
theTabeLock.Lock()
delete(theTable, nfq.idx)
theTabeLock.Unlock()
} | go | func (nfq *NFQueue) Close() {
C.nfq_destroy_queue(nfq.qh)
C.nfq_close(nfq.h)
theTabeLock.Lock()
delete(theTable, nfq.idx)
theTabeLock.Unlock()
} | [
"func",
"(",
"nfq",
"*",
"NFQueue",
")",
"Close",
"(",
")",
"{",
"C",
".",
"nfq_destroy_queue",
"(",
"nfq",
".",
"qh",
")",
"\n",
"C",
".",
"nfq_close",
"(",
"nfq",
".",
"h",
")",
"\n",
"theTabeLock",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
... | //Unbind and close the queue | [
"Unbind",
"and",
"close",
"the",
"queue"
] | 5b02f804b4f292cd337dc6e4f211ca1ce7627db8 | https://github.com/AkihiroSuda/go-netfilter-queue/blob/5b02f804b4f292cd337dc6e4f211ca1ce7627db8/netfilter.go#L167-L173 |
151,106 | brutella/dnssd | responder.go | announce | func (r *responder) announce(services []*Service) {
names := ifaceNames(services)
if len(names) == 0 {
r.announceAtInterface(services, nil)
return
}
for _, name := range names {
if iface, err := net.InterfaceByName(name); err != nil {
log.Debug.Println("Unable to find interface", name)
} else {
r.announceAtInterface(services, iface)
}
}
} | go | func (r *responder) announce(services []*Service) {
names := ifaceNames(services)
if len(names) == 0 {
r.announceAtInterface(services, nil)
return
}
for _, name := range names {
if iface, err := net.InterfaceByName(name); err != nil {
log.Debug.Println("Unable to find interface", name)
} else {
r.announceAtInterface(services, iface)
}
}
} | [
"func",
"(",
"r",
"*",
"responder",
")",
"announce",
"(",
"services",
"[",
"]",
"*",
"Service",
")",
"{",
"names",
":=",
"ifaceNames",
"(",
"services",
")",
"\n\n",
"if",
"len",
"(",
"names",
")",
"==",
"0",
"{",
"r",
".",
"announceAtInterface",
"(",... | // announce sends announcement messages including all services. | [
"announce",
"sends",
"announcement",
"messages",
"including",
"all",
"services",
"."
] | 61d1bc6e53ace5b3d9ecb46ffd0b3158c00ae9d0 | https://github.com/brutella/dnssd/blob/61d1bc6e53ace5b3d9ecb46ffd0b3158c00ae9d0/responder.go#L118-L133 |
151,107 | hkwi/h2c | server.go | ParseSettings | func ParseSettings(b []byte) []http2.Setting {
var r []http2.Setting
for i := 0; i < len(b)/6; i++ {
r = append(r, http2.Setting{
ID: http2.SettingID(binary.BigEndian.Uint16(b[i*6:])),
Val: binary.BigEndian.Uint32(b[i*6+2:]),
})
}
return r
} | go | func ParseSettings(b []byte) []http2.Setting {
var r []http2.Setting
for i := 0; i < len(b)/6; i++ {
r = append(r, http2.Setting{
ID: http2.SettingID(binary.BigEndian.Uint16(b[i*6:])),
Val: binary.BigEndian.Uint32(b[i*6+2:]),
})
}
return r
} | [
"func",
"ParseSettings",
"(",
"b",
"[",
"]",
"byte",
")",
"[",
"]",
"http2",
".",
"Setting",
"{",
"var",
"r",
"[",
"]",
"http2",
".",
"Setting",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"b",
")",
"/",
"6",
";",
"i",
"++",
"{"... | // Converts byte slice of SETTINGS frame payload into http2.Setting slice. | [
"Converts",
"byte",
"slice",
"of",
"SETTINGS",
"frame",
"payload",
"into",
"http2",
".",
"Setting",
"slice",
"."
] | 3511cd63f456392ba97c7f2f237e8af0cbee5ae4 | https://github.com/hkwi/h2c/blob/3511cd63f456392ba97c7f2f237e8af0cbee5ae4/server.go#L32-L41 |
151,108 | cavaliercoder/badio | truncate_reader.go | NewTruncateReader | func NewTruncateReader(r io.Reader, n int64) io.Reader {
return &truncateReader{r: r, n: n}
} | go | func NewTruncateReader(r io.Reader, n int64) io.Reader {
return &truncateReader{r: r, n: n}
} | [
"func",
"NewTruncateReader",
"(",
"r",
"io",
".",
"Reader",
",",
"n",
"int64",
")",
"io",
".",
"Reader",
"{",
"return",
"&",
"truncateReader",
"{",
"r",
":",
"r",
",",
"n",
":",
"n",
"}",
"\n",
"}"
] | // NewTruncateReader returns a Reader that behaves like r except that it will
// return zero count and an io.EOF error once it has read n bytes. | [
"NewTruncateReader",
"returns",
"a",
"Reader",
"that",
"behaves",
"like",
"r",
"except",
"that",
"it",
"will",
"return",
"zero",
"count",
"and",
"an",
"io",
".",
"EOF",
"error",
"once",
"it",
"has",
"read",
"n",
"bytes",
"."
] | ce5280129e9e9d80def35bfe203b845a4eebc9db | https://github.com/cavaliercoder/badio/blob/ce5280129e9e9d80def35bfe203b845a4eebc9db/truncate_reader.go#L15-L17 |
151,109 | drone/drone-exec | client/http.go | stream | func stream(client *http.Client, rawurl, method string, in, out interface{}) (io.ReadCloser, error) {
uri, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
// if we are posting or putting data, we need to
// write it to the body of the request.
var buf io.ReadWriter
if in == nil {
// nothing
} else if rw, ok := in.(io.ReadWriter); ok {
buf = rw
} else if b, ok := in.([]byte); ok {
buf = new(bytes.Buffer)
buf.Write(b)
} else {
buf = new(bytes.Buffer)
err := json.NewEncoder(buf).Encode(in)
if err != nil {
return nil, err
}
}
// creates a new http request to bitbucket.
req, err := http.NewRequest(method, uri.String(), buf)
if err != nil {
return nil, err
}
if in == nil {
// nothing
} else if _, ok := in.(io.ReadWriter); ok {
req.Header.Set("Content-Type", "plain/text")
} else {
req.Header.Set("Content-Type", "application/json")
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode > http.StatusPartialContent {
defer resp.Body.Close()
out, _ := ioutil.ReadAll(resp.Body)
return nil, fmt.Errorf(string(out))
}
return resp.Body, nil
} | go | func stream(client *http.Client, rawurl, method string, in, out interface{}) (io.ReadCloser, error) {
uri, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
// if we are posting or putting data, we need to
// write it to the body of the request.
var buf io.ReadWriter
if in == nil {
// nothing
} else if rw, ok := in.(io.ReadWriter); ok {
buf = rw
} else if b, ok := in.([]byte); ok {
buf = new(bytes.Buffer)
buf.Write(b)
} else {
buf = new(bytes.Buffer)
err := json.NewEncoder(buf).Encode(in)
if err != nil {
return nil, err
}
}
// creates a new http request to bitbucket.
req, err := http.NewRequest(method, uri.String(), buf)
if err != nil {
return nil, err
}
if in == nil {
// nothing
} else if _, ok := in.(io.ReadWriter); ok {
req.Header.Set("Content-Type", "plain/text")
} else {
req.Header.Set("Content-Type", "application/json")
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode > http.StatusPartialContent {
defer resp.Body.Close()
out, _ := ioutil.ReadAll(resp.Body)
return nil, fmt.Errorf(string(out))
}
return resp.Body, nil
} | [
"func",
"stream",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"rawurl",
",",
"method",
"string",
",",
"in",
",",
"out",
"interface",
"{",
"}",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"uri",
",",
"err",
":=",
"url",
".",
"Pa... | // helper function to stream an http request | [
"helper",
"function",
"to",
"stream",
"an",
"http",
"request"
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/http.go#L14-L61 |
151,110 | drone/drone-exec | yaml/transform/identifier.go | Identifier | func Identifier(c *yaml.Config) error {
// creates a random prefix for the build
rand := base64.RawURLEncoding.EncodeToString(
securecookie.GenerateRandomKey(8),
)
for i, step := range c.Services {
step.ID = fmt.Sprintf("drone_%s_%d", rand, i)
}
for i, step := range c.Pipeline {
step.ID = fmt.Sprintf("drone_%s_%d", rand, i+len(c.Services))
}
return nil
} | go | func Identifier(c *yaml.Config) error {
// creates a random prefix for the build
rand := base64.RawURLEncoding.EncodeToString(
securecookie.GenerateRandomKey(8),
)
for i, step := range c.Services {
step.ID = fmt.Sprintf("drone_%s_%d", rand, i)
}
for i, step := range c.Pipeline {
step.ID = fmt.Sprintf("drone_%s_%d", rand, i+len(c.Services))
}
return nil
} | [
"func",
"Identifier",
"(",
"c",
"*",
"yaml",
".",
"Config",
")",
"error",
"{",
"// creates a random prefix for the build",
"rand",
":=",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"securecookie",
".",
"GenerateRandomKey",
"(",
"8",
")",
",",
")... | // Identifier transforms the container steps in the Yaml and assigns a unique
// container identifier. | [
"Identifier",
"transforms",
"the",
"container",
"steps",
"in",
"the",
"Yaml",
"and",
"assigns",
"a",
"unique",
"container",
"identifier",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/identifier.go#L14-L30 |
151,111 | drone/drone-exec | build/docker/internal/stdcopy.go | Write | func (w *stdWriter) Write(buf []byte) (n int, err error) {
if w == nil || w.Writer == nil {
return 0, errors.New("Writer not instantiated")
}
if buf == nil {
return 0, nil
}
header := [stdWriterPrefixLen]byte{stdWriterFdIndex: w.prefix}
binary.BigEndian.PutUint32(header[stdWriterSizeIndex:], uint32(len(buf)))
line := append(header[:], buf...)
n, err = w.Writer.Write(line)
n -= stdWriterPrefixLen
if n < 0 {
n = 0
}
return
} | go | func (w *stdWriter) Write(buf []byte) (n int, err error) {
if w == nil || w.Writer == nil {
return 0, errors.New("Writer not instantiated")
}
if buf == nil {
return 0, nil
}
header := [stdWriterPrefixLen]byte{stdWriterFdIndex: w.prefix}
binary.BigEndian.PutUint32(header[stdWriterSizeIndex:], uint32(len(buf)))
line := append(header[:], buf...)
n, err = w.Writer.Write(line)
n -= stdWriterPrefixLen
if n < 0 {
n = 0
}
return
} | [
"func",
"(",
"w",
"*",
"stdWriter",
")",
"Write",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"w",
"==",
"nil",
"||",
"w",
".",
"Writer",
"==",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"New",... | // Write sends the buffer to the underneath writer.
// It insert the prefix header before the buffer,
// so stdcopy.StdCopy knows where to multiplex the output.
// It makes stdWriter to implement io.Writer. | [
"Write",
"sends",
"the",
"buffer",
"to",
"the",
"underneath",
"writer",
".",
"It",
"insert",
"the",
"prefix",
"header",
"before",
"the",
"buffer",
"so",
"stdcopy",
".",
"StdCopy",
"knows",
"where",
"to",
"multiplex",
"the",
"output",
".",
"It",
"makes",
"s... | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/docker/internal/stdcopy.go#L39-L59 |
151,112 | drone/drone-exec | yaml/transform/secret.go | match | func match(s *drone.Secret, image, event string) bool {
return matchImage(s, image) && matchEvent(s, event)
} | go | func match(s *drone.Secret, image, event string) bool {
return matchImage(s, image) && matchEvent(s, event)
} | [
"func",
"match",
"(",
"s",
"*",
"drone",
".",
"Secret",
",",
"image",
",",
"event",
"string",
")",
"bool",
"{",
"return",
"matchImage",
"(",
"s",
",",
"image",
")",
"&&",
"matchEvent",
"(",
"s",
",",
"event",
")",
"\n",
"}"
] | // match returns true if an image and event match the restricted list. | [
"match",
"returns",
"true",
"if",
"an",
"image",
"and",
"event",
"match",
"the",
"restricted",
"list",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/secret.go#L44-L46 |
151,113 | drone/drone-exec | yaml/transform/secret.go | matchImage | func matchImage(s *drone.Secret, image string) bool {
for _, pattern := range s.Images {
if match, _ := filepath.Match(pattern, image); match {
return true
} else if pattern == "*" {
return true
}
}
return false
} | go | func matchImage(s *drone.Secret, image string) bool {
for _, pattern := range s.Images {
if match, _ := filepath.Match(pattern, image); match {
return true
} else if pattern == "*" {
return true
}
}
return false
} | [
"func",
"matchImage",
"(",
"s",
"*",
"drone",
".",
"Secret",
",",
"image",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"pattern",
":=",
"range",
"s",
".",
"Images",
"{",
"if",
"match",
",",
"_",
":=",
"filepath",
".",
"Match",
"(",
"pattern",
",",... | // matchImage returns true if an image matches the restricted list. | [
"matchImage",
"returns",
"true",
"if",
"an",
"image",
"matches",
"the",
"restricted",
"list",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/secret.go#L49-L58 |
151,114 | drone/drone-exec | yaml/transform/secret.go | matchEvent | func matchEvent(s *drone.Secret, event string) bool {
for _, pattern := range s.Events {
if match, _ := filepath.Match(pattern, event); match {
return true
}
}
return false
} | go | func matchEvent(s *drone.Secret, event string) bool {
for _, pattern := range s.Events {
if match, _ := filepath.Match(pattern, event); match {
return true
}
}
return false
} | [
"func",
"matchEvent",
"(",
"s",
"*",
"drone",
".",
"Secret",
",",
"event",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"pattern",
":=",
"range",
"s",
".",
"Events",
"{",
"if",
"match",
",",
"_",
":=",
"filepath",
".",
"Match",
"(",
"pattern",
",",... | // matchEvent returns true if an event matches the restricted list. | [
"matchEvent",
"returns",
"true",
"if",
"an",
"event",
"matches",
"the",
"restricted",
"list",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/secret.go#L61-L68 |
151,115 | drone/drone-exec | yaml/transform/plugin.go | PluginDisable | func PluginDisable(conf *yaml.Config, patterns []string) error {
for _, container := range conf.Pipeline {
if len(container.Commands) != 0 { // skip build steps
continue
}
var match bool
for _, pattern := range patterns {
if ok, _ := filepath.Match(pattern, container.Name); ok {
match = true
break
}
}
if !match {
container.Disabled = true
}
}
return nil
} | go | func PluginDisable(conf *yaml.Config, patterns []string) error {
for _, container := range conf.Pipeline {
if len(container.Commands) != 0 { // skip build steps
continue
}
var match bool
for _, pattern := range patterns {
if ok, _ := filepath.Match(pattern, container.Name); ok {
match = true
break
}
}
if !match {
container.Disabled = true
}
}
return nil
} | [
"func",
"PluginDisable",
"(",
"conf",
"*",
"yaml",
".",
"Config",
",",
"patterns",
"[",
"]",
"string",
")",
"error",
"{",
"for",
"_",
",",
"container",
":=",
"range",
"conf",
".",
"Pipeline",
"{",
"if",
"len",
"(",
"container",
".",
"Commands",
")",
... | // PluginDisable is a transform function that alters the Yaml configuration to
// disables plugins. This is intended for use when executing the pipeline
// locally on your own computer. | [
"PluginDisable",
"is",
"a",
"transform",
"function",
"that",
"alters",
"the",
"Yaml",
"configuration",
"to",
"disables",
"plugins",
".",
"This",
"is",
"intended",
"for",
"use",
"when",
"executing",
"the",
"pipeline",
"locally",
"on",
"your",
"own",
"computer",
... | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/plugin.go#L12-L29 |
151,116 | drone/drone-exec | yaml/transform/plugin.go | PluginParams | func PluginParams(conf *yaml.Config) error {
for _, container := range conf.Pipeline {
if len(container.Vargs) == 0 {
continue
}
if container.Environment == nil {
container.Environment = map[string]string{}
}
err := argsToEnv(container.Vargs, container.Environment)
if err != nil {
return err
}
}
return nil
} | go | func PluginParams(conf *yaml.Config) error {
for _, container := range conf.Pipeline {
if len(container.Vargs) == 0 {
continue
}
if container.Environment == nil {
container.Environment = map[string]string{}
}
err := argsToEnv(container.Vargs, container.Environment)
if err != nil {
return err
}
}
return nil
} | [
"func",
"PluginParams",
"(",
"conf",
"*",
"yaml",
".",
"Config",
")",
"error",
"{",
"for",
"_",
",",
"container",
":=",
"range",
"conf",
".",
"Pipeline",
"{",
"if",
"len",
"(",
"container",
".",
"Vargs",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
... | // PluginParams is a transform function that alters the Yaml configuration to
// include plugin vargs parameters as environment variables. | [
"PluginParams",
"is",
"a",
"transform",
"function",
"that",
"alters",
"the",
"Yaml",
"configuration",
"to",
"include",
"plugin",
"vargs",
"parameters",
"as",
"environment",
"variables",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/plugin.go#L33-L47 |
151,117 | drone/drone-exec | yaml/transform/clone.go | Clone | func Clone(c *yaml.Config, plugin string) error {
for _, p := range c.Pipeline {
if p.Name == clone {
return nil
}
}
if plugin == "" {
plugin = "git"
}
s := &yaml.Container{
Image: plugin,
Name: clone,
}
c.Pipeline = append([]*yaml.Container{s}, c.Pipeline...)
return nil
} | go | func Clone(c *yaml.Config, plugin string) error {
for _, p := range c.Pipeline {
if p.Name == clone {
return nil
}
}
if plugin == "" {
plugin = "git"
}
s := &yaml.Container{
Image: plugin,
Name: clone,
}
c.Pipeline = append([]*yaml.Container{s}, c.Pipeline...)
return nil
} | [
"func",
"Clone",
"(",
"c",
"*",
"yaml",
".",
"Config",
",",
"plugin",
"string",
")",
"error",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"c",
".",
"Pipeline",
"{",
"if",
"p",
".",
"Name",
"==",
"clone",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}"... | // Clone transforms the Yaml to include a clone step. | [
"Clone",
"transforms",
"the",
"Yaml",
"to",
"include",
"a",
"clone",
"step",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/clone.go#L8-L25 |
151,118 | drone/drone-exec | build/docker/util.go | toContainerConfig | func toContainerConfig(c *yaml.Container) *dockerclient.ContainerConfig {
config := &dockerclient.ContainerConfig{
Image: c.Image,
Env: toEnvironmentSlice(c.Environment),
Cmd: c.Command,
Entrypoint: c.Entrypoint,
WorkingDir: c.WorkingDir,
HostConfig: dockerclient.HostConfig{
Privileged: c.Privileged,
NetworkMode: c.Network,
Memory: c.MemLimit,
CpuShares: c.CPUShares,
CpuQuota: c.CPUQuota,
CpusetCpus: c.CPUSet,
MemorySwappiness: -1,
OomKillDisable: c.OomKillDisable,
},
}
if len(config.Entrypoint) == 0 {
config.Entrypoint = nil
}
if len(config.Cmd) == 0 {
config.Cmd = nil
}
if len(c.ExtraHosts) > 0 {
config.HostConfig.ExtraHosts = c.ExtraHosts
}
if len(c.DNS) != 0 {
config.HostConfig.Dns = c.DNS
}
if len(c.DNSSearch) != 0 {
config.HostConfig.DnsSearch = c.DNSSearch
}
if len(c.VolumesFrom) != 0 {
config.HostConfig.VolumesFrom = c.VolumesFrom
}
config.Volumes = map[string]struct{}{}
for _, path := range c.Volumes {
if strings.Index(path, ":") == -1 {
config.Volumes[path] = struct{}{}
continue
}
parts := strings.Split(path, ":")
config.Volumes[parts[1]] = struct{}{}
config.HostConfig.Binds = append(config.HostConfig.Binds, path)
}
for _, path := range c.Devices {
if strings.Index(path, ":") == -1 {
continue
}
parts := strings.Split(path, ":")
device := dockerclient.DeviceMapping{
PathOnHost: parts[0],
PathInContainer: parts[1],
CgroupPermissions: "rwm",
}
config.HostConfig.Devices = append(config.HostConfig.Devices, device)
}
return config
} | go | func toContainerConfig(c *yaml.Container) *dockerclient.ContainerConfig {
config := &dockerclient.ContainerConfig{
Image: c.Image,
Env: toEnvironmentSlice(c.Environment),
Cmd: c.Command,
Entrypoint: c.Entrypoint,
WorkingDir: c.WorkingDir,
HostConfig: dockerclient.HostConfig{
Privileged: c.Privileged,
NetworkMode: c.Network,
Memory: c.MemLimit,
CpuShares: c.CPUShares,
CpuQuota: c.CPUQuota,
CpusetCpus: c.CPUSet,
MemorySwappiness: -1,
OomKillDisable: c.OomKillDisable,
},
}
if len(config.Entrypoint) == 0 {
config.Entrypoint = nil
}
if len(config.Cmd) == 0 {
config.Cmd = nil
}
if len(c.ExtraHosts) > 0 {
config.HostConfig.ExtraHosts = c.ExtraHosts
}
if len(c.DNS) != 0 {
config.HostConfig.Dns = c.DNS
}
if len(c.DNSSearch) != 0 {
config.HostConfig.DnsSearch = c.DNSSearch
}
if len(c.VolumesFrom) != 0 {
config.HostConfig.VolumesFrom = c.VolumesFrom
}
config.Volumes = map[string]struct{}{}
for _, path := range c.Volumes {
if strings.Index(path, ":") == -1 {
config.Volumes[path] = struct{}{}
continue
}
parts := strings.Split(path, ":")
config.Volumes[parts[1]] = struct{}{}
config.HostConfig.Binds = append(config.HostConfig.Binds, path)
}
for _, path := range c.Devices {
if strings.Index(path, ":") == -1 {
continue
}
parts := strings.Split(path, ":")
device := dockerclient.DeviceMapping{
PathOnHost: parts[0],
PathInContainer: parts[1],
CgroupPermissions: "rwm",
}
config.HostConfig.Devices = append(config.HostConfig.Devices, device)
}
return config
} | [
"func",
"toContainerConfig",
"(",
"c",
"*",
"yaml",
".",
"Container",
")",
"*",
"dockerclient",
".",
"ContainerConfig",
"{",
"config",
":=",
"&",
"dockerclient",
".",
"ContainerConfig",
"{",
"Image",
":",
"c",
".",
"Image",
",",
"Env",
":",
"toEnvironmentSli... | // helper function that converts the Continer data structure to the exepcted
// dockerclient.ContainerConfig. | [
"helper",
"function",
"that",
"converts",
"the",
"Continer",
"data",
"structure",
"to",
"the",
"exepcted",
"dockerclient",
".",
"ContainerConfig",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/docker/util.go#L13-L76 |
151,119 | drone/drone-exec | build/docker/util.go | toAuthConfig | func toAuthConfig(container *yaml.Container) *dockerclient.AuthConfig {
if container.AuthConfig.Username == "" &&
container.AuthConfig.Password == "" {
return nil
}
return &dockerclient.AuthConfig{
Email: container.AuthConfig.Email,
Username: container.AuthConfig.Username,
Password: container.AuthConfig.Password,
}
} | go | func toAuthConfig(container *yaml.Container) *dockerclient.AuthConfig {
if container.AuthConfig.Username == "" &&
container.AuthConfig.Password == "" {
return nil
}
return &dockerclient.AuthConfig{
Email: container.AuthConfig.Email,
Username: container.AuthConfig.Username,
Password: container.AuthConfig.Password,
}
} | [
"func",
"toAuthConfig",
"(",
"container",
"*",
"yaml",
".",
"Container",
")",
"*",
"dockerclient",
".",
"AuthConfig",
"{",
"if",
"container",
".",
"AuthConfig",
".",
"Username",
"==",
"\"",
"\"",
"&&",
"container",
".",
"AuthConfig",
".",
"Password",
"==",
... | // helper function that converts the AuthConfig data structure to the exepcted
// dockerclient.AuthConfig. | [
"helper",
"function",
"that",
"converts",
"the",
"AuthConfig",
"data",
"structure",
"to",
"the",
"exepcted",
"dockerclient",
".",
"AuthConfig",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/docker/util.go#L80-L90 |
151,120 | drone/drone-exec | build/docker/util.go | toEnvironmentSlice | func toEnvironmentSlice(env map[string]string) []string {
var envs []string
for k, v := range env {
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
}
return envs
} | go | func toEnvironmentSlice(env map[string]string) []string {
var envs []string
for k, v := range env {
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
}
return envs
} | [
"func",
"toEnvironmentSlice",
"(",
"env",
"map",
"[",
"string",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"envs",
"[",
"]",
"string",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"env",
"{",
"envs",
"=",
"append",
"(",
"envs",
",",
"fmt",
... | // helper function that converts a key value map of environment variables to a
// string slice in key=value format. | [
"helper",
"function",
"that",
"converts",
"a",
"key",
"value",
"map",
"of",
"environment",
"variables",
"to",
"a",
"string",
"slice",
"in",
"key",
"=",
"value",
"format",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/docker/util.go#L94-L100 |
151,121 | drone/drone-exec | yaml/config.go | Parse | func Parse(data []byte) (*Config, error) {
v := struct {
Image string
Build *Build
Workspace *Workspace
Services containerList
Pipeline containerList
Networks networkList
Volumes volumeList
}{}
err := yaml.Unmarshal(data, &v)
if err != nil {
return nil, err
}
for _, c := range v.Services.containers {
c.Detached = true
}
return &Config{
Image: v.Image,
Build: v.Build,
Workspace: v.Workspace,
Services: v.Services.containers,
Pipeline: v.Pipeline.containers,
Networks: v.Networks.networks,
Volumes: v.Volumes.volumes,
}, nil
} | go | func Parse(data []byte) (*Config, error) {
v := struct {
Image string
Build *Build
Workspace *Workspace
Services containerList
Pipeline containerList
Networks networkList
Volumes volumeList
}{}
err := yaml.Unmarshal(data, &v)
if err != nil {
return nil, err
}
for _, c := range v.Services.containers {
c.Detached = true
}
return &Config{
Image: v.Image,
Build: v.Build,
Workspace: v.Workspace,
Services: v.Services.containers,
Pipeline: v.Pipeline.containers,
Networks: v.Networks.networks,
Volumes: v.Volumes.volumes,
}, nil
} | [
"func",
"Parse",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"v",
":=",
"struct",
"{",
"Image",
"string",
"\n",
"Build",
"*",
"Build",
"\n",
"Workspace",
"*",
"Workspace",
"\n",
"Services",
"containerList",
"\n",
"... | // Parse parses Yaml configuration document. | [
"Parse",
"parses",
"Yaml",
"configuration",
"document",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/config.go#L28-L57 |
151,122 | drone/drone-exec | yaml/transform/workspace.go | WorkspaceTransform | func WorkspaceTransform(c *yaml.Config, base, path string) error {
if c.Workspace == nil {
c.Workspace = &yaml.Workspace{}
}
if c.Workspace.Base == "" {
c.Workspace.Base = base
}
if c.Workspace.Path == "" {
c.Workspace.Path = path
}
if !filepath.IsAbs(c.Workspace.Path) {
c.Workspace.Path = filepath.Join(
c.Workspace.Base,
c.Workspace.Path,
)
}
for _, p := range c.Pipeline {
p.WorkingDir = c.Workspace.Path
}
return nil
} | go | func WorkspaceTransform(c *yaml.Config, base, path string) error {
if c.Workspace == nil {
c.Workspace = &yaml.Workspace{}
}
if c.Workspace.Base == "" {
c.Workspace.Base = base
}
if c.Workspace.Path == "" {
c.Workspace.Path = path
}
if !filepath.IsAbs(c.Workspace.Path) {
c.Workspace.Path = filepath.Join(
c.Workspace.Base,
c.Workspace.Path,
)
}
for _, p := range c.Pipeline {
p.WorkingDir = c.Workspace.Path
}
return nil
} | [
"func",
"WorkspaceTransform",
"(",
"c",
"*",
"yaml",
".",
"Config",
",",
"base",
",",
"path",
"string",
")",
"error",
"{",
"if",
"c",
".",
"Workspace",
"==",
"nil",
"{",
"c",
".",
"Workspace",
"=",
"&",
"yaml",
".",
"Workspace",
"{",
"}",
"\n",
"}"... | // WorkspaceTransform transforms ... | [
"WorkspaceTransform",
"transforms",
"..."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/workspace.go#L10-L32 |
151,123 | drone/drone-exec | yaml/transform/environ.go | Environ | func Environ(c *yaml.Config, envs map[string]string) error {
for _, p := range c.Pipeline {
if p.Environment == nil {
p.Environment = map[string]string{}
}
for k, v := range envs {
if v == "" {
continue
}
p.Environment[k] = v
}
if httpProxy != "" {
p.Environment["HTTP_PROXY"] = httpProxy
p.Environment["http_proxy"] = strings.ToUpper(httpProxy)
}
if httpsProxy != "" {
p.Environment["HTTPS_PROXY"] = httpsProxy
p.Environment["https_proxy"] = strings.ToUpper(httpsProxy)
}
if noProxy != "" {
p.Environment["NO_PROXY"] = noProxy
p.Environment["no_proxy"] = strings.ToUpper(noProxy)
}
}
return nil
} | go | func Environ(c *yaml.Config, envs map[string]string) error {
for _, p := range c.Pipeline {
if p.Environment == nil {
p.Environment = map[string]string{}
}
for k, v := range envs {
if v == "" {
continue
}
p.Environment[k] = v
}
if httpProxy != "" {
p.Environment["HTTP_PROXY"] = httpProxy
p.Environment["http_proxy"] = strings.ToUpper(httpProxy)
}
if httpsProxy != "" {
p.Environment["HTTPS_PROXY"] = httpsProxy
p.Environment["https_proxy"] = strings.ToUpper(httpsProxy)
}
if noProxy != "" {
p.Environment["NO_PROXY"] = noProxy
p.Environment["no_proxy"] = strings.ToUpper(noProxy)
}
}
return nil
} | [
"func",
"Environ",
"(",
"c",
"*",
"yaml",
".",
"Config",
",",
"envs",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"c",
".",
"Pipeline",
"{",
"if",
"p",
".",
"Environment",
"==",
"nil",
"{",
"p",
... | // Environ transforms the steps in the Yaml pipeline to include runtime
// environment variables. | [
"Environ",
"transforms",
"the",
"steps",
"in",
"the",
"Yaml",
"pipeline",
"to",
"include",
"runtime",
"environment",
"variables",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/environ.go#L18-L43 |
151,124 | drone/drone-exec | build/error.go | Error | func (e *ExitError) Error() string {
return fmt.Sprintf("%s : exit code %d", e.Name, e.Code)
} | go | func (e *ExitError) Error() string {
return fmt.Sprintf("%s : exit code %d", e.Name, e.Code)
} | [
"func",
"(",
"e",
"*",
"ExitError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"Name",
",",
"e",
".",
"Code",
")",
"\n",
"}"
] | // Error reteurns the error message in string format. | [
"Error",
"reteurns",
"the",
"error",
"message",
"in",
"string",
"format",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/error.go#L25-L27 |
151,125 | drone/drone-exec | yaml/transform/command.go | CommandTransform | func CommandTransform(c *yaml.Config) error {
for _, p := range c.Pipeline {
if isPlugin(p) {
continue
}
p.Entrypoint = []string{
"/bin/sh", "-c",
}
p.Command = []string{
"echo $DRONE_SCRIPT | base64 -d | /bin/sh -e",
}
if p.Environment == nil {
p.Environment = map[string]string{}
}
p.Environment["HOME"] = "/root"
p.Environment["SHELL"] = "/bin/sh"
p.Environment["DRONE_SCRIPT"] = toScript(
p.Commands,
)
}
return nil
} | go | func CommandTransform(c *yaml.Config) error {
for _, p := range c.Pipeline {
if isPlugin(p) {
continue
}
p.Entrypoint = []string{
"/bin/sh", "-c",
}
p.Command = []string{
"echo $DRONE_SCRIPT | base64 -d | /bin/sh -e",
}
if p.Environment == nil {
p.Environment = map[string]string{}
}
p.Environment["HOME"] = "/root"
p.Environment["SHELL"] = "/bin/sh"
p.Environment["DRONE_SCRIPT"] = toScript(
p.Commands,
)
}
return nil
} | [
"func",
"CommandTransform",
"(",
"c",
"*",
"yaml",
".",
"Config",
")",
"error",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"c",
".",
"Pipeline",
"{",
"if",
"isPlugin",
"(",
"p",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"p",
".",
"Entrypoint",
"=",
... | // CommandTransform transforms the custom shell commands in the Yaml pipeline
// into a container ENTRYPOINT and and CMD for execution. | [
"CommandTransform",
"transforms",
"the",
"custom",
"shell",
"commands",
"in",
"the",
"Yaml",
"pipeline",
"into",
"a",
"container",
"ENTRYPOINT",
"and",
"and",
"CMD",
"for",
"execution",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/command.go#L14-L37 |
151,126 | drone/drone-exec | yaml/transform/filter.go | ChangeFilter | func ChangeFilter(conf *yaml.Config, prev string) {
for _, step := range conf.Pipeline {
for i, status := range step.Constraints.Status.Include {
if status != "change" && status != "changed" {
continue
}
if prev == drone.StatusFailure {
step.Constraints.Status.Include[i] = drone.StatusSuccess
} else {
step.Constraints.Status.Include[i] = drone.StatusFailure
}
}
}
} | go | func ChangeFilter(conf *yaml.Config, prev string) {
for _, step := range conf.Pipeline {
for i, status := range step.Constraints.Status.Include {
if status != "change" && status != "changed" {
continue
}
if prev == drone.StatusFailure {
step.Constraints.Status.Include[i] = drone.StatusSuccess
} else {
step.Constraints.Status.Include[i] = drone.StatusFailure
}
}
}
} | [
"func",
"ChangeFilter",
"(",
"conf",
"*",
"yaml",
".",
"Config",
",",
"prev",
"string",
")",
"{",
"for",
"_",
",",
"step",
":=",
"range",
"conf",
".",
"Pipeline",
"{",
"for",
"i",
",",
"status",
":=",
"range",
"step",
".",
"Constraints",
".",
"Status... | // ChangeFilter is a transform function that alters status constraints set to
// change and replaces with the opposite of the prior status. | [
"ChangeFilter",
"is",
"a",
"transform",
"function",
"that",
"alters",
"status",
"constraints",
"set",
"to",
"change",
"and",
"replaces",
"with",
"the",
"opposite",
"of",
"the",
"prior",
"status",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/filter.go#L10-L23 |
151,127 | drone/drone-exec | yaml/transform/filter.go | DefaultFilter | func DefaultFilter(conf *yaml.Config) {
for _, step := range conf.Pipeline {
defaultStatus(step)
defaultEvent(step)
}
} | go | func DefaultFilter(conf *yaml.Config) {
for _, step := range conf.Pipeline {
defaultStatus(step)
defaultEvent(step)
}
} | [
"func",
"DefaultFilter",
"(",
"conf",
"*",
"yaml",
".",
"Config",
")",
"{",
"for",
"_",
",",
"step",
":=",
"range",
"conf",
".",
"Pipeline",
"{",
"defaultStatus",
"(",
"step",
")",
"\n",
"defaultEvent",
"(",
"step",
")",
"\n",
"}",
"\n",
"}"
] | // DefaultFilter is a transform function that applies default Filters to each
// step in the Yaml specification file. | [
"DefaultFilter",
"is",
"a",
"transform",
"function",
"that",
"applies",
"default",
"Filters",
"to",
"each",
"step",
"in",
"the",
"Yaml",
"specification",
"file",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/filter.go#L27-L32 |
151,128 | drone/drone-exec | yaml/transform/filter.go | defaultStatus | func defaultStatus(c *yaml.Container) {
if !isEmpty(c.Constraints.Status) {
return
}
c.Constraints.Status.Include = []string{
drone.StatusSuccess,
}
} | go | func defaultStatus(c *yaml.Container) {
if !isEmpty(c.Constraints.Status) {
return
}
c.Constraints.Status.Include = []string{
drone.StatusSuccess,
}
} | [
"func",
"defaultStatus",
"(",
"c",
"*",
"yaml",
".",
"Container",
")",
"{",
"if",
"!",
"isEmpty",
"(",
"c",
".",
"Constraints",
".",
"Status",
")",
"{",
"return",
"\n",
"}",
"\n",
"c",
".",
"Constraints",
".",
"Status",
".",
"Include",
"=",
"[",
"]... | // defaultStatus sets default status conditions. | [
"defaultStatus",
"sets",
"default",
"status",
"conditions",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/filter.go#L35-L42 |
151,129 | drone/drone-exec | yaml/transform/filter.go | defaultEvent | func defaultEvent(c *yaml.Container) {
if !isEmpty(c.Constraints.Event) {
return
}
if isPlugin(c) && !isClone(c) {
c.Constraints.Event.Exclude = []string{
drone.EventPull,
}
}
} | go | func defaultEvent(c *yaml.Container) {
if !isEmpty(c.Constraints.Event) {
return
}
if isPlugin(c) && !isClone(c) {
c.Constraints.Event.Exclude = []string{
drone.EventPull,
}
}
} | [
"func",
"defaultEvent",
"(",
"c",
"*",
"yaml",
".",
"Container",
")",
"{",
"if",
"!",
"isEmpty",
"(",
"c",
".",
"Constraints",
".",
"Event",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"isPlugin",
"(",
"c",
")",
"&&",
"!",
"isClone",
"(",
"c",
"... | // defaultEvent sets default event conditions. | [
"defaultEvent",
"sets",
"default",
"event",
"conditions",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/filter.go#L45-L55 |
151,130 | drone/drone-exec | yaml/transform/filter.go | isEmpty | func isEmpty(c yaml.Constraint) bool {
return len(c.Include) == 0 && len(c.Exclude) == 0
} | go | func isEmpty(c yaml.Constraint) bool {
return len(c.Include) == 0 && len(c.Exclude) == 0
} | [
"func",
"isEmpty",
"(",
"c",
"yaml",
".",
"Constraint",
")",
"bool",
"{",
"return",
"len",
"(",
"c",
".",
"Include",
")",
"==",
"0",
"&&",
"len",
"(",
"c",
".",
"Exclude",
")",
"==",
"0",
"\n",
"}"
] | // helper function returns true if the step is a clone step. | [
"helper",
"function",
"returns",
"true",
"if",
"the",
"step",
"is",
"a",
"clone",
"step",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/filter.go#L58-L60 |
151,131 | drone/drone-exec | yaml/transform/filter.go | isPlugin | func isPlugin(c *yaml.Container) bool {
return len(c.Commands) == 0 || len(c.Vargs) != 0
} | go | func isPlugin(c *yaml.Container) bool {
return len(c.Commands) == 0 || len(c.Vargs) != 0
} | [
"func",
"isPlugin",
"(",
"c",
"*",
"yaml",
".",
"Container",
")",
"bool",
"{",
"return",
"len",
"(",
"c",
".",
"Commands",
")",
"==",
"0",
"||",
"len",
"(",
"c",
".",
"Vargs",
")",
"!=",
"0",
"\n",
"}"
] | // helper function returns true if the step is a plugin step. | [
"helper",
"function",
"returns",
"true",
"if",
"the",
"step",
"is",
"a",
"plugin",
"step",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/filter.go#L63-L65 |
151,132 | drone/drone-exec | yaml/transform/pod.go | Pod | func Pod(c *yaml.Config) error {
rand := base64.RawURLEncoding.EncodeToString(
securecookie.GenerateRandomKey(8),
)
ambassador := &yaml.Container{
ID: fmt.Sprintf("drone_ambassador_%s", rand),
Name: "ambassador",
Image: "busybox:latest",
Detached: true,
Entrypoint: []string{"/bin/sleep"},
Command: []string{"86400"},
Volumes: []string{c.Workspace.Path, c.Workspace.Base},
Environment: map[string]string{},
}
network := fmt.Sprintf("container:%s", ambassador.ID)
var containers []*yaml.Container
containers = append(containers, c.Pipeline...)
containers = append(containers, c.Services...)
for _, container := range containers {
container.VolumesFrom = append(container.VolumesFrom, ambassador.ID)
if container.Network == "" {
container.Network = network
}
}
c.Services = append([]*yaml.Container{ambassador}, c.Services...)
return nil
} | go | func Pod(c *yaml.Config) error {
rand := base64.RawURLEncoding.EncodeToString(
securecookie.GenerateRandomKey(8),
)
ambassador := &yaml.Container{
ID: fmt.Sprintf("drone_ambassador_%s", rand),
Name: "ambassador",
Image: "busybox:latest",
Detached: true,
Entrypoint: []string{"/bin/sleep"},
Command: []string{"86400"},
Volumes: []string{c.Workspace.Path, c.Workspace.Base},
Environment: map[string]string{},
}
network := fmt.Sprintf("container:%s", ambassador.ID)
var containers []*yaml.Container
containers = append(containers, c.Pipeline...)
containers = append(containers, c.Services...)
for _, container := range containers {
container.VolumesFrom = append(container.VolumesFrom, ambassador.ID)
if container.Network == "" {
container.Network = network
}
}
c.Services = append([]*yaml.Container{ambassador}, c.Services...)
return nil
} | [
"func",
"Pod",
"(",
"c",
"*",
"yaml",
".",
"Config",
")",
"error",
"{",
"rand",
":=",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"securecookie",
".",
"GenerateRandomKey",
"(",
"8",
")",
",",
")",
"\n\n",
"ambassador",
":=",
"&",
"yaml",... | // Pod transforms the containers in the Yaml to use Pod networking, where every
// container shares the localhost connection. | [
"Pod",
"transforms",
"the",
"containers",
"in",
"the",
"Yaml",
"to",
"use",
"Pod",
"networking",
"where",
"every",
"container",
"shares",
"the",
"localhost",
"connection",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/pod.go#L14-L45 |
151,133 | drone/drone-exec | build/config.go | Pipeline | func (c *Config) Pipeline(spec *yaml.Config) *Pipeline {
pipeline := Pipeline{
engine: c.Engine,
pipe: make(chan *Line, c.Buffer),
next: make(chan error),
done: make(chan error),
}
var containers []*yaml.Container
containers = append(containers, spec.Services...)
containers = append(containers, spec.Pipeline...)
for _, c := range containers {
if c.Disabled {
continue
}
next := &element{Container: c}
if pipeline.head == nil {
pipeline.head = next
pipeline.tail = next
} else {
pipeline.tail.next = next
pipeline.tail = next
}
}
go func() {
pipeline.next <- nil
}()
return &pipeline
} | go | func (c *Config) Pipeline(spec *yaml.Config) *Pipeline {
pipeline := Pipeline{
engine: c.Engine,
pipe: make(chan *Line, c.Buffer),
next: make(chan error),
done: make(chan error),
}
var containers []*yaml.Container
containers = append(containers, spec.Services...)
containers = append(containers, spec.Pipeline...)
for _, c := range containers {
if c.Disabled {
continue
}
next := &element{Container: c}
if pipeline.head == nil {
pipeline.head = next
pipeline.tail = next
} else {
pipeline.tail.next = next
pipeline.tail = next
}
}
go func() {
pipeline.next <- nil
}()
return &pipeline
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Pipeline",
"(",
"spec",
"*",
"yaml",
".",
"Config",
")",
"*",
"Pipeline",
"{",
"pipeline",
":=",
"Pipeline",
"{",
"engine",
":",
"c",
".",
"Engine",
",",
"pipe",
":",
"make",
"(",
"chan",
"*",
"Line",
",",
"... | // Pipeline creates a build Pipeline using the specific configuration for
// the given Yaml specification. | [
"Pipeline",
"creates",
"a",
"build",
"Pipeline",
"using",
"the",
"specific",
"configuration",
"for",
"the",
"given",
"Yaml",
"specification",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/config.go#L16-L48 |
151,134 | drone/drone-exec | yaml/transform/validate.go | CheckEntrypoint | func CheckEntrypoint(c *yaml.Container) error {
if len(c.Entrypoint) != 0 {
return fmt.Errorf("Cannot set plugin Entrypoint")
}
if len(c.Command) != 0 {
return fmt.Errorf("Cannot set plugin Command")
}
return nil
} | go | func CheckEntrypoint(c *yaml.Container) error {
if len(c.Entrypoint) != 0 {
return fmt.Errorf("Cannot set plugin Entrypoint")
}
if len(c.Command) != 0 {
return fmt.Errorf("Cannot set plugin Command")
}
return nil
} | [
"func",
"CheckEntrypoint",
"(",
"c",
"*",
"yaml",
".",
"Container",
")",
"error",
"{",
"if",
"len",
"(",
"c",
".",
"Entrypoint",
")",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"c",
... | // validate the plugin command and entrypoint and return an error
// the user attempts to set or override these values. | [
"validate",
"the",
"plugin",
"command",
"and",
"entrypoint",
"and",
"return",
"an",
"error",
"the",
"user",
"attempts",
"to",
"set",
"or",
"override",
"these",
"values",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/validate.go#L38-L46 |
151,135 | drone/drone-exec | yaml/transform/validate.go | CheckTrusted | func CheckTrusted(c *yaml.Container) error {
if c.Privileged {
return fmt.Errorf("Insufficient privileges to use privileged mode")
}
if len(c.DNS) != 0 {
return fmt.Errorf("Insufficient privileges to use custom dns")
}
if len(c.DNSSearch) != 0 {
return fmt.Errorf("Insufficient privileges to use dns_search")
}
if len(c.Devices) != 0 {
return fmt.Errorf("Insufficient privileges to use devices")
}
if len(c.ExtraHosts) != 0 {
return fmt.Errorf("Insufficient privileges to use extra_hosts")
}
if len(c.Network) != 0 {
return fmt.Errorf("Insufficient privileges to override the network")
}
if c.OomKillDisable {
return fmt.Errorf("Insufficient privileges to disable oom_kill")
}
if len(c.Volumes) != 0 {
return fmt.Errorf("Insufficient privileges to use volumes")
}
if len(c.VolumesFrom) != 0 {
return fmt.Errorf("Insufficient privileges to use volumes_from")
}
return nil
} | go | func CheckTrusted(c *yaml.Container) error {
if c.Privileged {
return fmt.Errorf("Insufficient privileges to use privileged mode")
}
if len(c.DNS) != 0 {
return fmt.Errorf("Insufficient privileges to use custom dns")
}
if len(c.DNSSearch) != 0 {
return fmt.Errorf("Insufficient privileges to use dns_search")
}
if len(c.Devices) != 0 {
return fmt.Errorf("Insufficient privileges to use devices")
}
if len(c.ExtraHosts) != 0 {
return fmt.Errorf("Insufficient privileges to use extra_hosts")
}
if len(c.Network) != 0 {
return fmt.Errorf("Insufficient privileges to override the network")
}
if c.OomKillDisable {
return fmt.Errorf("Insufficient privileges to disable oom_kill")
}
if len(c.Volumes) != 0 {
return fmt.Errorf("Insufficient privileges to use volumes")
}
if len(c.VolumesFrom) != 0 {
return fmt.Errorf("Insufficient privileges to use volumes_from")
}
return nil
} | [
"func",
"CheckTrusted",
"(",
"c",
"*",
"yaml",
".",
"Container",
")",
"error",
"{",
"if",
"c",
".",
"Privileged",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"c",
".",
"DNS",
")",
"!=",
"0",
"{"... | // validate the container configuration and return an error if restricted
// configurations are used. | [
"validate",
"the",
"container",
"configuration",
"and",
"return",
"an",
"error",
"if",
"restricted",
"configurations",
"are",
"used",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/validate.go#L50-L79 |
151,136 | drone/drone-exec | agent/updater.go | NewClientUpdater | func NewClientUpdater(client client.Client) UpdateFunc {
return func(w *drone.Payload) {
for {
err := client.Push(w)
if err == nil {
return
}
logrus.Errorf("Error updating %s/%s#%d.%d. Retry in 30s. %s",
w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err)
logrus.Infof("Retry update in 30s")
time.Sleep(time.Second * 30)
}
}
} | go | func NewClientUpdater(client client.Client) UpdateFunc {
return func(w *drone.Payload) {
for {
err := client.Push(w)
if err == nil {
return
}
logrus.Errorf("Error updating %s/%s#%d.%d. Retry in 30s. %s",
w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err)
logrus.Infof("Retry update in 30s")
time.Sleep(time.Second * 30)
}
}
} | [
"func",
"NewClientUpdater",
"(",
"client",
"client",
".",
"Client",
")",
"UpdateFunc",
"{",
"return",
"func",
"(",
"w",
"*",
"drone",
".",
"Payload",
")",
"{",
"for",
"{",
"err",
":=",
"client",
".",
"Push",
"(",
"w",
")",
"\n",
"if",
"err",
"==",
... | // NewClientUpdater returns an updater that sends updated build details
// to the drone server. | [
"NewClientUpdater",
"returns",
"an",
"updater",
"that",
"sends",
"updated",
"build",
"details",
"to",
"the",
"drone",
"server",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/agent/updater.go#L30-L43 |
151,137 | drone/drone-exec | build/pipeline.go | Exec | func (p *Pipeline) Exec() {
go func() {
err := p.exec(p.head.Container)
if err != nil {
p.err = err
}
p.step()
}()
} | go | func (p *Pipeline) Exec() {
go func() {
err := p.exec(p.head.Container)
if err != nil {
p.err = err
}
p.step()
}()
} | [
"func",
"(",
"p",
"*",
"Pipeline",
")",
"Exec",
"(",
")",
"{",
"go",
"func",
"(",
")",
"{",
"err",
":=",
"p",
".",
"exec",
"(",
"p",
".",
"head",
".",
"Container",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
".",
"err",
"=",
"err",
"\n",... | // Exec executes the current step. | [
"Exec",
"executes",
"the",
"current",
"step",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/pipeline.go#L49-L57 |
151,138 | drone/drone-exec | build/pipeline.go | Teardown | func (p *Pipeline) Teardown() {
for _, id := range p.containers {
p.engine.ContainerRemove(id)
}
close(p.next)
close(p.done)
// TODO we have a race condition here where the program can try to async
// write to a closed pipe channel. This package, in general, needs to be
// tested for race conditions.
// close(p.pipe)
} | go | func (p *Pipeline) Teardown() {
for _, id := range p.containers {
p.engine.ContainerRemove(id)
}
close(p.next)
close(p.done)
// TODO we have a race condition here where the program can try to async
// write to a closed pipe channel. This package, in general, needs to be
// tested for race conditions.
// close(p.pipe)
} | [
"func",
"(",
"p",
"*",
"Pipeline",
")",
"Teardown",
"(",
")",
"{",
"for",
"_",
",",
"id",
":=",
"range",
"p",
".",
"containers",
"{",
"p",
".",
"engine",
".",
"ContainerRemove",
"(",
"id",
")",
"\n",
"}",
"\n",
"close",
"(",
"p",
".",
"next",
"... | // Teardown removes the pipeline environment. | [
"Teardown",
"removes",
"the",
"pipeline",
"environment",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/pipeline.go#L92-L103 |
151,139 | drone/drone-exec | build/pipeline.go | step | func (p *Pipeline) step() {
if p.head == p.tail {
go func() {
p.done <- nil
}()
} else {
go func() {
p.head = p.head.next
p.next <- nil
}()
}
} | go | func (p *Pipeline) step() {
if p.head == p.tail {
go func() {
p.done <- nil
}()
} else {
go func() {
p.head = p.head.next
p.next <- nil
}()
}
} | [
"func",
"(",
"p",
"*",
"Pipeline",
")",
"step",
"(",
")",
"{",
"if",
"p",
".",
"head",
"==",
"p",
".",
"tail",
"{",
"go",
"func",
"(",
")",
"{",
"p",
".",
"done",
"<-",
"nil",
"\n",
"}",
"(",
")",
"\n",
"}",
"else",
"{",
"go",
"func",
"("... | // step steps through the pipeline to head.next | [
"step",
"steps",
"through",
"the",
"pipeline",
"to",
"head",
".",
"next"
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/pipeline.go#L106-L117 |
151,140 | drone/drone-exec | token/token.go | New | func New(secret string) (string, error) {
token := jwt.New(jwt.SigningMethodHS256)
token.Claims["type"] = "agent"
token.Claims["text"] = ""
return token.SignedString([]byte(secret))
} | go | func New(secret string) (string, error) {
token := jwt.New(jwt.SigningMethodHS256)
token.Claims["type"] = "agent"
token.Claims["text"] = ""
return token.SignedString([]byte(secret))
} | [
"func",
"New",
"(",
"secret",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"token",
":=",
"jwt",
".",
"New",
"(",
"jwt",
".",
"SigningMethodHS256",
")",
"\n",
"token",
".",
"Claims",
"[",
"\"",
"\"",
"]",
"=",
"\"",
"\"",
"\n",
"token",
... | // New generates a new agent token for authenticating to the drone server. | [
"New",
"generates",
"a",
"new",
"agent",
"token",
"for",
"authenticating",
"to",
"the",
"drone",
"server",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/token/token.go#L6-L11 |
151,141 | drone/drone-exec | yaml/transform/image.go | ImagePull | func ImagePull(conf *yaml.Config, pull bool) error {
for _, plugin := range conf.Pipeline {
if !isPlugin(plugin) {
continue
}
plugin.Pull = pull
}
return nil
} | go | func ImagePull(conf *yaml.Config, pull bool) error {
for _, plugin := range conf.Pipeline {
if !isPlugin(plugin) {
continue
}
plugin.Pull = pull
}
return nil
} | [
"func",
"ImagePull",
"(",
"conf",
"*",
"yaml",
".",
"Config",
",",
"pull",
"bool",
")",
"error",
"{",
"for",
"_",
",",
"plugin",
":=",
"range",
"conf",
".",
"Pipeline",
"{",
"if",
"!",
"isPlugin",
"(",
"plugin",
")",
"{",
"continue",
"\n",
"}",
"\n... | // ImagePull transforms the Yaml to automatically pull the latest image. | [
"ImagePull",
"transforms",
"the",
"Yaml",
"to",
"automatically",
"pull",
"the",
"latest",
"image",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/image.go#L11-L19 |
151,142 | drone/drone-exec | yaml/transform/image.go | ImageName | func ImageName(conf *yaml.Config) error {
for _, image := range conf.Pipeline {
image.Image = strings.Replace(image.Image, "_", "-", -1)
}
return nil
} | go | func ImageName(conf *yaml.Config) error {
for _, image := range conf.Pipeline {
image.Image = strings.Replace(image.Image, "_", "-", -1)
}
return nil
} | [
"func",
"ImageName",
"(",
"conf",
"*",
"yaml",
".",
"Config",
")",
"error",
"{",
"for",
"_",
",",
"image",
":=",
"range",
"conf",
".",
"Pipeline",
"{",
"image",
".",
"Image",
"=",
"strings",
".",
"Replace",
"(",
"image",
".",
"Image",
",",
"\"",
"\... | // ImageName transforms the Yaml to replace underscores with dashes. | [
"ImageName",
"transforms",
"the",
"Yaml",
"to",
"replace",
"underscores",
"with",
"dashes",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/image.go#L37-L42 |
151,143 | drone/drone-exec | yaml/transform/image.go | ImageNamespace | func ImageNamespace(conf *yaml.Config, namespace string) error {
for _, image := range conf.Pipeline {
if strings.Contains(image.Image, "/") {
continue
}
if !isPlugin(image) {
continue
}
image.Image = filepath.Join(namespace, image.Image)
}
return nil
} | go | func ImageNamespace(conf *yaml.Config, namespace string) error {
for _, image := range conf.Pipeline {
if strings.Contains(image.Image, "/") {
continue
}
if !isPlugin(image) {
continue
}
image.Image = filepath.Join(namespace, image.Image)
}
return nil
} | [
"func",
"ImageNamespace",
"(",
"conf",
"*",
"yaml",
".",
"Config",
",",
"namespace",
"string",
")",
"error",
"{",
"for",
"_",
",",
"image",
":=",
"range",
"conf",
".",
"Pipeline",
"{",
"if",
"strings",
".",
"Contains",
"(",
"image",
".",
"Image",
",",
... | // ImageNamespace transforms the Yaml to use a default namepsace for plugins. | [
"ImageNamespace",
"transforms",
"the",
"Yaml",
"to",
"use",
"a",
"default",
"namepsace",
"for",
"plugins",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/image.go#L45-L56 |
151,144 | drone/drone-exec | yaml/transform/image.go | ImageEscalate | func ImageEscalate(conf *yaml.Config, patterns []string) error {
for _, c := range conf.Pipeline {
for _, pattern := range patterns {
if ok, _ := filepath.Match(pattern, c.Image); ok {
c.Privileged = true
}
}
}
return nil
} | go | func ImageEscalate(conf *yaml.Config, patterns []string) error {
for _, c := range conf.Pipeline {
for _, pattern := range patterns {
if ok, _ := filepath.Match(pattern, c.Image); ok {
c.Privileged = true
}
}
}
return nil
} | [
"func",
"ImageEscalate",
"(",
"conf",
"*",
"yaml",
".",
"Config",
",",
"patterns",
"[",
"]",
"string",
")",
"error",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"conf",
".",
"Pipeline",
"{",
"for",
"_",
",",
"pattern",
":=",
"range",
"patterns",
"{",
... | // ImageEscalate transforms the Yaml to automatically enable privileged mode
// for a subset of white-listed plugins matching the given patterns. | [
"ImageEscalate",
"transforms",
"the",
"Yaml",
"to",
"automatically",
"enable",
"privileged",
"mode",
"for",
"a",
"subset",
"of",
"white",
"-",
"listed",
"plugins",
"matching",
"the",
"given",
"patterns",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/transform/image.go#L60-L69 |
151,145 | drone/drone-exec | client/client_impl.go | NewClientToken | func NewClientToken(uri, token string) Client {
config := new(oauth2.Config)
auther := config.Client(oauth2.NoContext, &oauth2.Token{AccessToken: token})
return &client{client: auther, base: uri, token: token}
} | go | func NewClientToken(uri, token string) Client {
config := new(oauth2.Config)
auther := config.Client(oauth2.NoContext, &oauth2.Token{AccessToken: token})
return &client{client: auther, base: uri, token: token}
} | [
"func",
"NewClientToken",
"(",
"uri",
",",
"token",
"string",
")",
"Client",
"{",
"config",
":=",
"new",
"(",
"oauth2",
".",
"Config",
")",
"\n",
"auther",
":=",
"config",
".",
"Client",
"(",
"oauth2",
".",
"NoContext",
",",
"&",
"oauth2",
".",
"Token"... | // NewClientToken returns a client at the specified url that authenticates all
// outbound requests with the given token. | [
"NewClientToken",
"returns",
"a",
"client",
"at",
"the",
"specified",
"url",
"that",
"authenticates",
"all",
"outbound",
"requests",
"with",
"the",
"given",
"token",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L64-L68 |
151,146 | drone/drone-exec | client/client_impl.go | NewClientTokenTLS | func NewClientTokenTLS(uri, token string, c *tls.Config) Client {
config := new(oauth2.Config)
auther := config.Client(oauth2.NoContext, &oauth2.Token{AccessToken: token})
if c != nil {
if trans, ok := auther.Transport.(*oauth2.Transport); ok {
trans.Base = &http.Transport{TLSClientConfig: c}
}
}
return &client{client: auther, base: uri, token: token}
} | go | func NewClientTokenTLS(uri, token string, c *tls.Config) Client {
config := new(oauth2.Config)
auther := config.Client(oauth2.NoContext, &oauth2.Token{AccessToken: token})
if c != nil {
if trans, ok := auther.Transport.(*oauth2.Transport); ok {
trans.Base = &http.Transport{TLSClientConfig: c}
}
}
return &client{client: auther, base: uri, token: token}
} | [
"func",
"NewClientTokenTLS",
"(",
"uri",
",",
"token",
"string",
",",
"c",
"*",
"tls",
".",
"Config",
")",
"Client",
"{",
"config",
":=",
"new",
"(",
"oauth2",
".",
"Config",
")",
"\n",
"auther",
":=",
"config",
".",
"Client",
"(",
"oauth2",
".",
"No... | // NewClientTokenTLS returns a client at the specified url that authenticates
// all outbound requests with the given token and tls.Config if provided. | [
"NewClientTokenTLS",
"returns",
"a",
"client",
"at",
"the",
"specified",
"url",
"that",
"authenticates",
"all",
"outbound",
"requests",
"with",
"the",
"given",
"token",
"and",
"tls",
".",
"Config",
"if",
"provided",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L72-L81 |
151,147 | drone/drone-exec | client/client_impl.go | Push | func (c *client) Push(p *drone.Payload) error {
uri := fmt.Sprintf(pathPush, c.base, p.Job.ID)
err := c.post(uri, p, nil)
return err
} | go | func (c *client) Push(p *drone.Payload) error {
uri := fmt.Sprintf(pathPush, c.base, p.Job.ID)
err := c.post(uri, p, nil)
return err
} | [
"func",
"(",
"c",
"*",
"client",
")",
"Push",
"(",
"p",
"*",
"drone",
".",
"Payload",
")",
"error",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"pathPush",
",",
"c",
".",
"base",
",",
"p",
".",
"Job",
".",
"ID",
")",
"\n",
"err",
":=",
"c",... | // Push pushes an update to the server. | [
"Push",
"pushes",
"an",
"update",
"to",
"the",
"server",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L96-L100 |
151,148 | drone/drone-exec | client/client_impl.go | Ping | func (c *client) Ping() error {
uri := fmt.Sprintf(pathPing, c.base)
err := c.post(uri, nil, nil)
return err
} | go | func (c *client) Ping() error {
uri := fmt.Sprintf(pathPing, c.base)
err := c.post(uri, nil, nil)
return err
} | [
"func",
"(",
"c",
"*",
"client",
")",
"Ping",
"(",
")",
"error",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"pathPing",
",",
"c",
".",
"base",
")",
"\n",
"err",
":=",
"c",
".",
"post",
"(",
"uri",
",",
"nil",
",",
"nil",
")",
"\n",
"return... | // Ping pings the server. | [
"Ping",
"pings",
"the",
"server",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L103-L107 |
151,149 | drone/drone-exec | client/client_impl.go | Stream | func (c *client) Stream(id int64, rc io.ReadCloser) error {
uri := fmt.Sprintf(pathStream, c.base, id)
err := c.post(uri, rc, nil)
return err
} | go | func (c *client) Stream(id int64, rc io.ReadCloser) error {
uri := fmt.Sprintf(pathStream, c.base, id)
err := c.post(uri, rc, nil)
return err
} | [
"func",
"(",
"c",
"*",
"client",
")",
"Stream",
"(",
"id",
"int64",
",",
"rc",
"io",
".",
"ReadCloser",
")",
"error",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"pathStream",
",",
"c",
".",
"base",
",",
"id",
")",
"\n",
"err",
":=",
"c",
"."... | // Stream streams the build logs to the server. | [
"Stream",
"streams",
"the",
"build",
"logs",
"to",
"the",
"server",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L110-L115 |
151,150 | drone/drone-exec | client/client_impl.go | LogPost | func (c *client) LogPost(id int64, rc io.ReadCloser) error {
uri := fmt.Sprintf(pathLogs, c.base, id)
return c.post(uri, rc, nil)
} | go | func (c *client) LogPost(id int64, rc io.ReadCloser) error {
uri := fmt.Sprintf(pathLogs, c.base, id)
return c.post(uri, rc, nil)
} | [
"func",
"(",
"c",
"*",
"client",
")",
"LogPost",
"(",
"id",
"int64",
",",
"rc",
"io",
".",
"ReadCloser",
")",
"error",
"{",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"pathLogs",
",",
"c",
".",
"base",
",",
"id",
")",
"\n",
"return",
"c",
".",
"p... | // LogPost sends the full build logs to the server. | [
"LogPost",
"sends",
"the",
"full",
"build",
"logs",
"to",
"the",
"server",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L118-L121 |
151,151 | drone/drone-exec | client/client_impl.go | LogStream | func (c *client) LogStream(id int64) (StreamWriter, error) {
rawurl := fmt.Sprintf(pathLogsAuth, c.base, id, c.token)
uri, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
if uri.Scheme == "https" {
uri.Scheme = "wss"
} else {
uri.Scheme = "ws"
}
// TODO need TLS client configuration
conn, _, err := websocket.DefaultDialer.Dial(uri.String(), nil)
return conn, err
} | go | func (c *client) LogStream(id int64) (StreamWriter, error) {
rawurl := fmt.Sprintf(pathLogsAuth, c.base, id, c.token)
uri, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
if uri.Scheme == "https" {
uri.Scheme = "wss"
} else {
uri.Scheme = "ws"
}
// TODO need TLS client configuration
conn, _, err := websocket.DefaultDialer.Dial(uri.String(), nil)
return conn, err
} | [
"func",
"(",
"c",
"*",
"client",
")",
"LogStream",
"(",
"id",
"int64",
")",
"(",
"StreamWriter",
",",
"error",
")",
"{",
"rawurl",
":=",
"fmt",
".",
"Sprintf",
"(",
"pathLogsAuth",
",",
"c",
".",
"base",
",",
"id",
",",
"c",
".",
"token",
")",
"\... | // LogStream streams the build logs to the server. | [
"LogStream",
"streams",
"the",
"build",
"logs",
"to",
"the",
"server",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L131-L147 |
151,152 | drone/drone-exec | client/client_impl.go | Wait | func (c *client) Wait(id int64) *Wait {
ctx, cancel := context.WithCancel(context.Background())
return &Wait{id, c, ctx, cancel}
} | go | func (c *client) Wait(id int64) *Wait {
ctx, cancel := context.WithCancel(context.Background())
return &Wait{id, c, ctx, cancel}
} | [
"func",
"(",
"c",
"*",
"client",
")",
"Wait",
"(",
"id",
"int64",
")",
"*",
"Wait",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"return",
"&",
"Wait",
"{",
"id",
",",
"c",... | // Wait watches and waits for the build to cancel or finish. | [
"Wait",
"watches",
"and",
"waits",
"for",
"the",
"build",
"to",
"cancel",
"or",
"finish",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L150-L153 |
151,153 | drone/drone-exec | client/client_impl.go | do | func (c *client) do(rawurl, method string, in, out interface{}) error {
// executes the http request and returns the body as
// and io.ReadCloser
body, err := c.open(rawurl, method, in, out)
if err != nil {
return err
}
defer body.Close()
// if a json response is expected, parse and return
// the json response.
if out != nil {
return json.NewDecoder(body).Decode(out)
}
return nil
} | go | func (c *client) do(rawurl, method string, in, out interface{}) error {
// executes the http request and returns the body as
// and io.ReadCloser
body, err := c.open(rawurl, method, in, out)
if err != nil {
return err
}
defer body.Close()
// if a json response is expected, parse and return
// the json response.
if out != nil {
return json.NewDecoder(body).Decode(out)
}
return nil
} | [
"func",
"(",
"c",
"*",
"client",
")",
"do",
"(",
"rawurl",
",",
"method",
"string",
",",
"in",
",",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"// executes the http request and returns the body as",
"// and io.ReadCloser",
"body",
",",
"err",
":=",
"c",
... | // helper function to make an http request | [
"helper",
"function",
"to",
"make",
"an",
"http",
"request"
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L217-L232 |
151,154 | drone/drone-exec | client/client_impl.go | open | func (c *client) open(rawurl, method string, in, out interface{}) (io.ReadCloser, error) {
uri, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
// creates a new http request to bitbucket.
req, err := http.NewRequest(method, uri.String(), nil)
if err != nil {
return nil, err
}
// if we are posting or putting data, we need to
// write it to the body of the request.
if in != nil {
rc, ok := in.(io.ReadCloser)
if ok {
req.Body = rc
req.Header.Set("Content-Type", "plain/text")
} else {
inJson, err := json.Marshal(in)
if err != nil {
return nil, err
}
buf := bytes.NewBuffer(inJson)
req.Body = ioutil.NopCloser(buf)
req.ContentLength = int64(len(inJson))
req.Header.Set("Content-Length", strconv.Itoa(len(inJson)))
req.Header.Set("Content-Type", "application/json")
}
}
resp, err := c.client.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode > http.StatusPartialContent {
defer resp.Body.Close()
out, _ := ioutil.ReadAll(resp.Body)
return nil, fmt.Errorf("client error %d: %s", resp.StatusCode, string(out))
}
return resp.Body, nil
} | go | func (c *client) open(rawurl, method string, in, out interface{}) (io.ReadCloser, error) {
uri, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
// creates a new http request to bitbucket.
req, err := http.NewRequest(method, uri.String(), nil)
if err != nil {
return nil, err
}
// if we are posting or putting data, we need to
// write it to the body of the request.
if in != nil {
rc, ok := in.(io.ReadCloser)
if ok {
req.Body = rc
req.Header.Set("Content-Type", "plain/text")
} else {
inJson, err := json.Marshal(in)
if err != nil {
return nil, err
}
buf := bytes.NewBuffer(inJson)
req.Body = ioutil.NopCloser(buf)
req.ContentLength = int64(len(inJson))
req.Header.Set("Content-Length", strconv.Itoa(len(inJson)))
req.Header.Set("Content-Type", "application/json")
}
}
resp, err := c.client.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode > http.StatusPartialContent {
defer resp.Body.Close()
out, _ := ioutil.ReadAll(resp.Body)
return nil, fmt.Errorf("client error %d: %s", resp.StatusCode, string(out))
}
return resp.Body, nil
} | [
"func",
"(",
"c",
"*",
"client",
")",
"open",
"(",
"rawurl",
",",
"method",
"string",
",",
"in",
",",
"out",
"interface",
"{",
"}",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"uri",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"r... | // helper function to open an http request | [
"helper",
"function",
"to",
"open",
"an",
"http",
"request"
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L235-L278 |
151,155 | drone/drone-exec | client/client_impl.go | createRequest | func (c *client) createRequest(rawurl, method string, in interface{}) (*http.Request, error) {
uri, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
// if we are posting or putting data, we need to
// write it to the body of the request.
var buf io.ReadWriter
if in != nil {
buf = new(bytes.Buffer)
err := json.NewEncoder(buf).Encode(in)
if err != nil {
return nil, err
}
}
// creates a new http request to bitbucket.
req, err := http.NewRequest(method, uri.String(), buf)
if err != nil {
return nil, err
}
if in != nil {
req.Header.Set("Content-Type", "application/json")
}
return req, nil
} | go | func (c *client) createRequest(rawurl, method string, in interface{}) (*http.Request, error) {
uri, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
// if we are posting or putting data, we need to
// write it to the body of the request.
var buf io.ReadWriter
if in != nil {
buf = new(bytes.Buffer)
err := json.NewEncoder(buf).Encode(in)
if err != nil {
return nil, err
}
}
// creates a new http request to bitbucket.
req, err := http.NewRequest(method, uri.String(), buf)
if err != nil {
return nil, err
}
if in != nil {
req.Header.Set("Content-Type", "application/json")
}
return req, nil
} | [
"func",
"(",
"c",
"*",
"client",
")",
"createRequest",
"(",
"rawurl",
",",
"method",
"string",
",",
"in",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"uri",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"ra... | // createRequest is a helper function that builds an http.Request. | [
"createRequest",
"is",
"a",
"helper",
"function",
"that",
"builds",
"an",
"http",
".",
"Request",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/client/client_impl.go#L281-L307 |
151,156 | drone/drone-exec | yaml/constraint.go | Match | func (c *Constraints) Match(arch, target, event, branch, status string, matrix map[string]string) bool {
return c.Platform.Match(arch) &&
c.Environment.Match(target) &&
c.Event.Match(event) &&
c.Branch.Match(branch) &&
c.Status.Match(status) &&
c.Matrix.Match(matrix)
} | go | func (c *Constraints) Match(arch, target, event, branch, status string, matrix map[string]string) bool {
return c.Platform.Match(arch) &&
c.Environment.Match(target) &&
c.Event.Match(event) &&
c.Branch.Match(branch) &&
c.Status.Match(status) &&
c.Matrix.Match(matrix)
} | [
"func",
"(",
"c",
"*",
"Constraints",
")",
"Match",
"(",
"arch",
",",
"target",
",",
"event",
",",
"branch",
",",
"status",
"string",
",",
"matrix",
"map",
"[",
"string",
"]",
"string",
")",
"bool",
"{",
"return",
"c",
".",
"Platform",
".",
"Match",
... | // Match returns true if all constraints match the given input. If a single constraint
// fails a false value is returned. | [
"Match",
"returns",
"true",
"if",
"all",
"constraints",
"match",
"the",
"given",
"input",
".",
"If",
"a",
"single",
"constraint",
"fails",
"a",
"false",
"value",
"is",
"returned",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/constraint.go#L21-L28 |
151,157 | drone/drone-exec | yaml/constraint.go | Match | func (c *Constraint) Match(v string) bool {
if c.Excludes(v) {
return false
}
if c.Includes(v) {
return true
}
if len(c.Include) == 0 {
return true
}
return false
} | go | func (c *Constraint) Match(v string) bool {
if c.Excludes(v) {
return false
}
if c.Includes(v) {
return true
}
if len(c.Include) == 0 {
return true
}
return false
} | [
"func",
"(",
"c",
"*",
"Constraint",
")",
"Match",
"(",
"v",
"string",
")",
"bool",
"{",
"if",
"c",
".",
"Excludes",
"(",
"v",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"c",
".",
"Includes",
"(",
"v",
")",
"{",
"return",
"true",
"\n",... | // Match returns true if the string matches the include patterns and does not
// match any of the exclude patterns. | [
"Match",
"returns",
"true",
"if",
"the",
"string",
"matches",
"the",
"include",
"patterns",
"and",
"does",
"not",
"match",
"any",
"of",
"the",
"exclude",
"patterns",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/constraint.go#L38-L49 |
151,158 | drone/drone-exec | yaml/constraint.go | Includes | func (c *Constraint) Includes(v string) bool {
for _, pattern := range c.Include {
if ok, _ := filepath.Match(pattern, v); ok {
return true
}
}
return false
} | go | func (c *Constraint) Includes(v string) bool {
for _, pattern := range c.Include {
if ok, _ := filepath.Match(pattern, v); ok {
return true
}
}
return false
} | [
"func",
"(",
"c",
"*",
"Constraint",
")",
"Includes",
"(",
"v",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"pattern",
":=",
"range",
"c",
".",
"Include",
"{",
"if",
"ok",
",",
"_",
":=",
"filepath",
".",
"Match",
"(",
"pattern",
",",
"v",
")",
... | // Includes returns true if the string matches matches the include patterns. | [
"Includes",
"returns",
"true",
"if",
"the",
"string",
"matches",
"matches",
"the",
"include",
"patterns",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/constraint.go#L52-L59 |
151,159 | drone/drone-exec | yaml/constraint.go | Excludes | func (c *Constraint) Excludes(v string) bool {
for _, pattern := range c.Exclude {
if ok, _ := filepath.Match(pattern, v); ok {
return true
}
}
return false
} | go | func (c *Constraint) Excludes(v string) bool {
for _, pattern := range c.Exclude {
if ok, _ := filepath.Match(pattern, v); ok {
return true
}
}
return false
} | [
"func",
"(",
"c",
"*",
"Constraint",
")",
"Excludes",
"(",
"v",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"pattern",
":=",
"range",
"c",
".",
"Exclude",
"{",
"if",
"ok",
",",
"_",
":=",
"filepath",
".",
"Match",
"(",
"pattern",
",",
"v",
")",
... | // Excludes returns true if the string matches matches the exclude patterns. | [
"Excludes",
"returns",
"true",
"if",
"the",
"string",
"matches",
"matches",
"the",
"exclude",
"patterns",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/constraint.go#L62-L69 |
151,160 | drone/drone-exec | yaml/constraint.go | Match | func (c *ConstraintMap) Match(params map[string]string) bool {
// when no includes or excludes automatically match
if len(c.Include) == 0 && len(c.Exclude) == 0 {
return true
}
// exclusions are processed first. So we can include everything and then
// selectively include others.
if len(c.Exclude) != 0 {
var matches int
for key, val := range c.Exclude {
if params[key] == val {
matches++
}
}
if matches == len(c.Exclude) {
return false
}
}
for key, val := range c.Include {
if params[key] != val {
return false
}
}
return true
} | go | func (c *ConstraintMap) Match(params map[string]string) bool {
// when no includes or excludes automatically match
if len(c.Include) == 0 && len(c.Exclude) == 0 {
return true
}
// exclusions are processed first. So we can include everything and then
// selectively include others.
if len(c.Exclude) != 0 {
var matches int
for key, val := range c.Exclude {
if params[key] == val {
matches++
}
}
if matches == len(c.Exclude) {
return false
}
}
for key, val := range c.Include {
if params[key] != val {
return false
}
}
return true
} | [
"func",
"(",
"c",
"*",
"ConstraintMap",
")",
"Match",
"(",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"bool",
"{",
"// when no includes or excludes automatically match",
"if",
"len",
"(",
"c",
".",
"Include",
")",
"==",
"0",
"&&",
"len",
"(",
"c",... | // Match returns true if the params matches the include key values and does not
// match any of the exclude key values. | [
"Match",
"returns",
"true",
"if",
"the",
"params",
"matches",
"the",
"include",
"key",
"values",
"and",
"does",
"not",
"match",
"any",
"of",
"the",
"exclude",
"key",
"values",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/yaml/constraint.go#L100-L128 |
151,161 | drone/drone-exec | build/docker/helper.go | New | func New(host, cert string, tls bool) (build.Engine, error) {
config, err := dockerclient.TLSConfigFromCertPath(cert)
if err == nil && tls {
config.InsecureSkipVerify = true
}
client, err := dockerclient.NewDockerClient(host, config)
if err != nil {
return nil, err
}
return NewClient(client), nil
} | go | func New(host, cert string, tls bool) (build.Engine, error) {
config, err := dockerclient.TLSConfigFromCertPath(cert)
if err == nil && tls {
config.InsecureSkipVerify = true
}
client, err := dockerclient.NewDockerClient(host, config)
if err != nil {
return nil, err
}
return NewClient(client), nil
} | [
"func",
"New",
"(",
"host",
",",
"cert",
"string",
",",
"tls",
"bool",
")",
"(",
"build",
".",
"Engine",
",",
"error",
")",
"{",
"config",
",",
"err",
":=",
"dockerclient",
".",
"TLSConfigFromCertPath",
"(",
"cert",
")",
"\n",
"if",
"err",
"==",
"nil... | // New returns a new Docker engine from the provided DOCKER_HOST and
// DOCKER_CERT_PATH environment variables. | [
"New",
"returns",
"a",
"new",
"Docker",
"engine",
"from",
"the",
"provided",
"DOCKER_HOST",
"and",
"DOCKER_CERT_PATH",
"environment",
"variables",
"."
] | 79c691b24a86e70b7bff58523005c03d4487b628 | https://github.com/drone/drone-exec/blob/79c691b24a86e70b7bff58523005c03d4487b628/build/docker/helper.go#L15-L25 |
151,162 | bluebreezecf/opentsdb-goclient | client/client.go | NewClient | func NewClient(opentsdbCfg config.OpenTSDBConfig) (Client, error) {
opentsdbCfg.OpentsdbHost = strings.TrimSpace(opentsdbCfg.OpentsdbHost)
if len(opentsdbCfg.OpentsdbHost) <= 0 {
return nil, errors.New("The OpentsdbEndpoint of the given config should not be empty.")
}
transport := opentsdbCfg.Transport
if transport == nil {
transport = DefaultTransport
}
client := &http.Client{
Transport: transport,
}
if opentsdbCfg.MaxPutPointsNum <= 0 {
opentsdbCfg.MaxPutPointsNum = DefaultMaxPutPointsNum
}
if opentsdbCfg.DetectDeltaNum <= 0 {
opentsdbCfg.DetectDeltaNum = DefaultDetectDeltaNum
}
if opentsdbCfg.MaxContentLength <= 0 {
opentsdbCfg.MaxContentLength = DefaultMaxContentLength
}
tsdbEndpoint := fmt.Sprintf("http://%s", opentsdbCfg.OpentsdbHost)
clientImpl := clientImpl{
tsdbEndpoint: tsdbEndpoint,
client: client,
opentsdbCfg: opentsdbCfg,
}
return &clientImpl, nil
} | go | func NewClient(opentsdbCfg config.OpenTSDBConfig) (Client, error) {
opentsdbCfg.OpentsdbHost = strings.TrimSpace(opentsdbCfg.OpentsdbHost)
if len(opentsdbCfg.OpentsdbHost) <= 0 {
return nil, errors.New("The OpentsdbEndpoint of the given config should not be empty.")
}
transport := opentsdbCfg.Transport
if transport == nil {
transport = DefaultTransport
}
client := &http.Client{
Transport: transport,
}
if opentsdbCfg.MaxPutPointsNum <= 0 {
opentsdbCfg.MaxPutPointsNum = DefaultMaxPutPointsNum
}
if opentsdbCfg.DetectDeltaNum <= 0 {
opentsdbCfg.DetectDeltaNum = DefaultDetectDeltaNum
}
if opentsdbCfg.MaxContentLength <= 0 {
opentsdbCfg.MaxContentLength = DefaultMaxContentLength
}
tsdbEndpoint := fmt.Sprintf("http://%s", opentsdbCfg.OpentsdbHost)
clientImpl := clientImpl{
tsdbEndpoint: tsdbEndpoint,
client: client,
opentsdbCfg: opentsdbCfg,
}
return &clientImpl, nil
} | [
"func",
"NewClient",
"(",
"opentsdbCfg",
"config",
".",
"OpenTSDBConfig",
")",
"(",
"Client",
",",
"error",
")",
"{",
"opentsdbCfg",
".",
"OpentsdbHost",
"=",
"strings",
".",
"TrimSpace",
"(",
"opentsdbCfg",
".",
"OpentsdbHost",
")",
"\n",
"if",
"len",
"(",
... | // NewClient creates an instance of http client which implements the
// pre-defined rest apis of OpenTSDB.
// A non-nil error instance returned means currently the target OpenTSDB
// designated with the given endpoint is not connectable. | [
"NewClient",
"creates",
"an",
"instance",
"of",
"http",
"client",
"which",
"implements",
"the",
"pre",
"-",
"defined",
"rest",
"apis",
"of",
"OpenTSDB",
".",
"A",
"non",
"-",
"nil",
"error",
"instance",
"returned",
"means",
"currently",
"the",
"target",
"Ope... | 539764bd9a9cae6632dea52b5a587451728a3983 | https://github.com/bluebreezecf/opentsdb-goclient/blob/539764bd9a9cae6632dea52b5a587451728a3983/client/client.go#L400-L428 |
151,163 | bluebreezecf/opentsdb-goclient | client/client.go | sendRequest | func (c *clientImpl) sendRequest(method, url, reqBodyCnt string, parsedResp Response) error {
req, err := http.NewRequest(method, url, strings.NewReader(reqBodyCnt))
if err != nil {
return errors.New(fmt.Sprintf("Failed to create request for %s %s: %v", method, url, err))
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
resp, err := c.client.Do(req)
if err != nil {
return errors.New(fmt.Sprintf("Failed to send request for %s %s: %v", method, url, err))
}
defer resp.Body.Close()
var jsonBytes []byte
if jsonBytes, err = ioutil.ReadAll(resp.Body); err != nil {
return errors.New(fmt.Sprintf("Failed to read response for %s %s: %v", method, url, err))
}
parsedResp.SetStatus(resp.StatusCode)
parser := parsedResp.GetCustomParser()
if parser == nil {
if err = json.Unmarshal(jsonBytes, parsedResp); err != nil {
return errors.New(fmt.Sprintf("Failed to parse response for %s %s: %v", method, url, err))
}
} else {
if err = parser(jsonBytes); err != nil {
return err
}
}
return nil
} | go | func (c *clientImpl) sendRequest(method, url, reqBodyCnt string, parsedResp Response) error {
req, err := http.NewRequest(method, url, strings.NewReader(reqBodyCnt))
if err != nil {
return errors.New(fmt.Sprintf("Failed to create request for %s %s: %v", method, url, err))
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
resp, err := c.client.Do(req)
if err != nil {
return errors.New(fmt.Sprintf("Failed to send request for %s %s: %v", method, url, err))
}
defer resp.Body.Close()
var jsonBytes []byte
if jsonBytes, err = ioutil.ReadAll(resp.Body); err != nil {
return errors.New(fmt.Sprintf("Failed to read response for %s %s: %v", method, url, err))
}
parsedResp.SetStatus(resp.StatusCode)
parser := parsedResp.GetCustomParser()
if parser == nil {
if err = json.Unmarshal(jsonBytes, parsedResp); err != nil {
return errors.New(fmt.Sprintf("Failed to parse response for %s %s: %v", method, url, err))
}
} else {
if err = parser(jsonBytes); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"clientImpl",
")",
"sendRequest",
"(",
"method",
",",
"url",
",",
"reqBodyCnt",
"string",
",",
"parsedResp",
"Response",
")",
"error",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"method",
",",
"url",
",",
"stri... | // sendRequest dispatches the http request with the given method name, url and body contents.
// reqBodyCnt is "" means there is no contents in the request body.
// If the tsdb server responses properly, the error is nil and parsedResp is the parsed
// response with the specific type. Otherwise, the returned error is not nil. | [
"sendRequest",
"dispatches",
"the",
"http",
"request",
"with",
"the",
"given",
"method",
"name",
"url",
"and",
"body",
"contents",
".",
"reqBodyCnt",
"is",
"means",
"there",
"is",
"no",
"contents",
"in",
"the",
"request",
"body",
".",
"If",
"the",
"tsdb",
... | 539764bd9a9cae6632dea52b5a587451728a3983 | https://github.com/bluebreezecf/opentsdb-goclient/blob/539764bd9a9cae6632dea52b5a587451728a3983/client/client.go#L462-L491 |
151,164 | bluebreezecf/opentsdb-goclient | client/query.go | GetDataPoints | func (qri *QueryRespItem) GetDataPoints() []*DataPoint {
datapoints := make([]*DataPoint, 0)
timestampStrs := qri.getSortedTimestampStrs()
for _, timestampStr := range timestampStrs {
timestamp, _ := strconv.ParseInt(timestampStr, 10, 64)
datapoint := &DataPoint{
Metric: qri.Metric,
Value: qri.Dps[timestampStr],
Tags: qri.Tags,
Timestamp: timestamp,
}
datapoints = append(datapoints, datapoint)
}
return datapoints
} | go | func (qri *QueryRespItem) GetDataPoints() []*DataPoint {
datapoints := make([]*DataPoint, 0)
timestampStrs := qri.getSortedTimestampStrs()
for _, timestampStr := range timestampStrs {
timestamp, _ := strconv.ParseInt(timestampStr, 10, 64)
datapoint := &DataPoint{
Metric: qri.Metric,
Value: qri.Dps[timestampStr],
Tags: qri.Tags,
Timestamp: timestamp,
}
datapoints = append(datapoints, datapoint)
}
return datapoints
} | [
"func",
"(",
"qri",
"*",
"QueryRespItem",
")",
"GetDataPoints",
"(",
")",
"[",
"]",
"*",
"DataPoint",
"{",
"datapoints",
":=",
"make",
"(",
"[",
"]",
"*",
"DataPoint",
",",
"0",
")",
"\n",
"timestampStrs",
":=",
"qri",
".",
"getSortedTimestampStrs",
"(",... | // GetDataPoints returns the real ascending datapoints from the information of the related QueryRespItem. | [
"GetDataPoints",
"returns",
"the",
"real",
"ascending",
"datapoints",
"from",
"the",
"information",
"of",
"the",
"related",
"QueryRespItem",
"."
] | 539764bd9a9cae6632dea52b5a587451728a3983 | https://github.com/bluebreezecf/opentsdb-goclient/blob/539764bd9a9cae6632dea52b5a587451728a3983/client/query.go#L231-L245 |
151,165 | bluebreezecf/opentsdb-goclient | client/query.go | getSortedTimestampStrs | func (qri *QueryRespItem) getSortedTimestampStrs() []string {
timestampStrs := make([]string, 0)
for timestampStr := range qri.Dps {
timestampStrs = append(timestampStrs, timestampStr)
}
sort.Strings(timestampStrs)
return timestampStrs
} | go | func (qri *QueryRespItem) getSortedTimestampStrs() []string {
timestampStrs := make([]string, 0)
for timestampStr := range qri.Dps {
timestampStrs = append(timestampStrs, timestampStr)
}
sort.Strings(timestampStrs)
return timestampStrs
} | [
"func",
"(",
"qri",
"*",
"QueryRespItem",
")",
"getSortedTimestampStrs",
"(",
")",
"[",
"]",
"string",
"{",
"timestampStrs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"timestampStr",
":=",
"range",
"qri",
".",
"Dps",
"{",
"time... | // getSortedTimestampStrs returns a slice of the ascending timestamp with
// string format for the Dps of the related QueryRespItem instance. | [
"getSortedTimestampStrs",
"returns",
"a",
"slice",
"of",
"the",
"ascending",
"timestamp",
"with",
"string",
"format",
"for",
"the",
"Dps",
"of",
"the",
"related",
"QueryRespItem",
"instance",
"."
] | 539764bd9a9cae6632dea52b5a587451728a3983 | https://github.com/bluebreezecf/opentsdb-goclient/blob/539764bd9a9cae6632dea52b5a587451728a3983/client/query.go#L249-L256 |
151,166 | degdb/degdb | crypto/crypto.go | AuthorID | func (key *PrivateKey) AuthorID() (string, error) {
hasher := murmur3.New64()
buf, err := x509.MarshalPKIXPublicKey(&(*ecdsa.PrivateKey)(key).PublicKey)
if err != nil {
return "", err
}
hasher.Write(buf)
return "degdb:author_" + strconv.Itoa(int(hasher.Sum64())), nil
} | go | func (key *PrivateKey) AuthorID() (string, error) {
hasher := murmur3.New64()
buf, err := x509.MarshalPKIXPublicKey(&(*ecdsa.PrivateKey)(key).PublicKey)
if err != nil {
return "", err
}
hasher.Write(buf)
return "degdb:author_" + strconv.Itoa(int(hasher.Sum64())), nil
} | [
"func",
"(",
"key",
"*",
"PrivateKey",
")",
"AuthorID",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"hasher",
":=",
"murmur3",
".",
"New64",
"(",
")",
"\n",
"buf",
",",
"err",
":=",
"x509",
".",
"MarshalPKIXPublicKey",
"(",
"&",
"(",
"*",
"ecd... | // AuthorID generates a unique ID based on the murmur hash of the public key. | [
"AuthorID",
"generates",
"a",
"unique",
"ID",
"based",
"on",
"the",
"murmur",
"hash",
"of",
"the",
"public",
"key",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/crypto/crypto.go#L83-L91 |
151,167 | degdb/degdb | protocol/protocol.go | CloneTriples | func CloneTriples(triples []*Triple) []*Triple {
ntrips := make([]*Triple, len(triples))
for i, triple := range triples {
t := *triple
ntrips[i] = &t
}
return ntrips
} | go | func CloneTriples(triples []*Triple) []*Triple {
ntrips := make([]*Triple, len(triples))
for i, triple := range triples {
t := *triple
ntrips[i] = &t
}
return ntrips
} | [
"func",
"CloneTriples",
"(",
"triples",
"[",
"]",
"*",
"Triple",
")",
"[",
"]",
"*",
"Triple",
"{",
"ntrips",
":=",
"make",
"(",
"[",
"]",
"*",
"Triple",
",",
"len",
"(",
"triples",
")",
")",
"\n",
"for",
"i",
",",
"triple",
":=",
"range",
"tripl... | // CloneTriples makes a shallow copy of the triples. | [
"CloneTriples",
"makes",
"a",
"shallow",
"copy",
"of",
"the",
"triples",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/protocol/protocol.go#L18-L25 |
151,168 | degdb/degdb | bitcoin/bitcoin.go | Kill | func Kill() {
procsLock.Lock()
defer procsLock.Unlock()
for _, proc := range procs {
proc.Process.Kill()
}
procs = nil
} | go | func Kill() {
procsLock.Lock()
defer procsLock.Unlock()
for _, proc := range procs {
proc.Process.Kill()
}
procs = nil
} | [
"func",
"Kill",
"(",
")",
"{",
"procsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"procsLock",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"proc",
":=",
"range",
"procs",
"{",
"proc",
".",
"Process",
".",
"Kill",
"(",
")",
"\n",
"}",
"\n",
... | // Kill kills all processes launched by bitcoin. | [
"Kill",
"kills",
"all",
"processes",
"launched",
"by",
"bitcoin",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/bitcoin/bitcoin.go#L66-L73 |
151,169 | degdb/degdb | network/ip/ip.go | IP | func IP() (string, error) {
ips := make(chan string, 1)
errs := make(chan error, 1)
for _, server := range ipServers {
server := server
go func() {
resp, err := http.Get(server)
if err != nil {
errs <- err
return
}
body, _ := ioutil.ReadAll(resp.Body)
ipAddr := strings.TrimSpace(string(body))
ip := net.ParseIP(ipAddr)
if ip == nil {
errs <- fmt.Errorf("invalid ip address: %s", ipAddr)
return
}
ips <- ip.String()
}()
}
var errors []error
var resps []string
respMap := make(map[string]int)
for (len(resps) < 2 || len(respMap) > 1) && len(resps)+len(errors) < len(ipServers) {
select {
case resp := <-ips:
resps = append(resps, resp)
respMap[resp]++
case err := <-errs:
errors = append(errors, err)
}
}
if len(resps) == 0 {
return "", errors[0]
}
// pick best ip address
var best string
mostVotes := 0
for addr, votes := range respMap {
if votes > mostVotes {
mostVotes = votes
best = addr
}
}
return best, nil
} | go | func IP() (string, error) {
ips := make(chan string, 1)
errs := make(chan error, 1)
for _, server := range ipServers {
server := server
go func() {
resp, err := http.Get(server)
if err != nil {
errs <- err
return
}
body, _ := ioutil.ReadAll(resp.Body)
ipAddr := strings.TrimSpace(string(body))
ip := net.ParseIP(ipAddr)
if ip == nil {
errs <- fmt.Errorf("invalid ip address: %s", ipAddr)
return
}
ips <- ip.String()
}()
}
var errors []error
var resps []string
respMap := make(map[string]int)
for (len(resps) < 2 || len(respMap) > 1) && len(resps)+len(errors) < len(ipServers) {
select {
case resp := <-ips:
resps = append(resps, resp)
respMap[resp]++
case err := <-errs:
errors = append(errors, err)
}
}
if len(resps) == 0 {
return "", errors[0]
}
// pick best ip address
var best string
mostVotes := 0
for addr, votes := range respMap {
if votes > mostVotes {
mostVotes = votes
best = addr
}
}
return best, nil
} | [
"func",
"IP",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"ips",
":=",
"make",
"(",
"chan",
"string",
",",
"1",
")",
"\n",
"errs",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"for",
"_",
",",
"server",
":=",
"range",
"ipServer... | // IP returns the current IP address from a quorum of external servers. | [
"IP",
"returns",
"the",
"current",
"IP",
"address",
"from",
"a",
"quorum",
"of",
"external",
"servers",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/ip/ip.go#L20-L66 |
151,170 | degdb/degdb | triplestore/bloom.go | Bloom | func (ts *TripleStore) Bloom(keyspace *protocol.Keyspace) (*boom.ScalableBloomFilter, error) {
filter := boom.NewDefaultScalableBloomFilter(BloomFalsePositiveRate)
results, errs := ts.EachTripleBatch(DefaultTripleBatchSize)
for triples := range results {
for _, triple := range triples {
if keyspace != nil {
hash := murmur3.Sum64([]byte(triple.Subj))
if !keyspace.Includes(hash) {
continue
}
}
data, err := triple.Marshal()
if err != nil {
return nil, err
}
filter.Add(data)
}
}
for err := range errs {
return nil, err
}
return filter, nil
} | go | func (ts *TripleStore) Bloom(keyspace *protocol.Keyspace) (*boom.ScalableBloomFilter, error) {
filter := boom.NewDefaultScalableBloomFilter(BloomFalsePositiveRate)
results, errs := ts.EachTripleBatch(DefaultTripleBatchSize)
for triples := range results {
for _, triple := range triples {
if keyspace != nil {
hash := murmur3.Sum64([]byte(triple.Subj))
if !keyspace.Includes(hash) {
continue
}
}
data, err := triple.Marshal()
if err != nil {
return nil, err
}
filter.Add(data)
}
}
for err := range errs {
return nil, err
}
return filter, nil
} | [
"func",
"(",
"ts",
"*",
"TripleStore",
")",
"Bloom",
"(",
"keyspace",
"*",
"protocol",
".",
"Keyspace",
")",
"(",
"*",
"boom",
".",
"ScalableBloomFilter",
",",
"error",
")",
"{",
"filter",
":=",
"boom",
".",
"NewDefaultScalableBloomFilter",
"(",
"BloomFalseP... | // Bloom returns a ScalableBloomFilter containing all the triples the current node has in the optional keyspace. | [
"Bloom",
"returns",
"a",
"ScalableBloomFilter",
"containing",
"all",
"the",
"triples",
"the",
"current",
"node",
"has",
"in",
"the",
"optional",
"keyspace",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/triplestore/bloom.go#L14-L37 |
151,171 | degdb/degdb | triplestore/bloom.go | TriplesMatchingBloom | func (ts *TripleStore) TriplesMatchingBloom(filter *boom.ScalableBloomFilter) (<-chan []*protocol.Triple, <-chan error) {
c := make(chan []*protocol.Triple, 10)
cerr := make(chan error, 1)
go func() {
triples := make([]*protocol.Triple, 0, DefaultTripleBatchSize)
results, errs := ts.EachTripleBatch(DefaultTripleBatchSize)
for resultTriples := range results {
for _, triple := range resultTriples {
data, err := triple.Marshal()
if err != nil {
cerr <- err
break
}
if !filter.Test(data) {
continue
}
triples = append(triples, triple)
if len(triples) >= DefaultTripleBatchSize {
c <- triples
triples = make([]*protocol.Triple, 0, DefaultTripleBatchSize)
}
}
if len(triples) > 0 {
c <- triples
}
}
for err := range errs {
cerr <- err
}
close(c)
close(cerr)
}()
return c, cerr
} | go | func (ts *TripleStore) TriplesMatchingBloom(filter *boom.ScalableBloomFilter) (<-chan []*protocol.Triple, <-chan error) {
c := make(chan []*protocol.Triple, 10)
cerr := make(chan error, 1)
go func() {
triples := make([]*protocol.Triple, 0, DefaultTripleBatchSize)
results, errs := ts.EachTripleBatch(DefaultTripleBatchSize)
for resultTriples := range results {
for _, triple := range resultTriples {
data, err := triple.Marshal()
if err != nil {
cerr <- err
break
}
if !filter.Test(data) {
continue
}
triples = append(triples, triple)
if len(triples) >= DefaultTripleBatchSize {
c <- triples
triples = make([]*protocol.Triple, 0, DefaultTripleBatchSize)
}
}
if len(triples) > 0 {
c <- triples
}
}
for err := range errs {
cerr <- err
}
close(c)
close(cerr)
}()
return c, cerr
} | [
"func",
"(",
"ts",
"*",
"TripleStore",
")",
"TriplesMatchingBloom",
"(",
"filter",
"*",
"boom",
".",
"ScalableBloomFilter",
")",
"(",
"<-",
"chan",
"[",
"]",
"*",
"protocol",
".",
"Triple",
",",
"<-",
"chan",
"error",
")",
"{",
"c",
":=",
"make",
"(",
... | // TriplesMatchingBloom streams triples in batches of 1000 that match the bloom filter. | [
"TriplesMatchingBloom",
"streams",
"triples",
"in",
"batches",
"of",
"1000",
"that",
"match",
"the",
"bloom",
"filter",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/triplestore/bloom.go#L40-L73 |
151,172 | degdb/degdb | network/network.go | NewServer | func NewServer(logger *log.Logger, port int) (*Server, error) {
if logger == nil {
logger = log.New(os.Stdout, "", log.Flags())
}
s := &Server{
Logger: logger,
Port: port,
Peers: make(map[string]*Conn),
handlers: make(map[string]protocolHandler),
}
s.listeningWG.Add(1)
s.IP = getHost()
s.listener = &httpListener{
accept: make(chan *httpConn, 10),
}
s.initHTTPRouting()
// Handlers
s.Handle("Handshake", s.handleHandshake)
s.Handle("PeerRequest", s.handlePeerRequest)
s.Handle("PeerNotify", s.handlePeerNotify)
return s, nil
} | go | func NewServer(logger *log.Logger, port int) (*Server, error) {
if logger == nil {
logger = log.New(os.Stdout, "", log.Flags())
}
s := &Server{
Logger: logger,
Port: port,
Peers: make(map[string]*Conn),
handlers: make(map[string]protocolHandler),
}
s.listeningWG.Add(1)
s.IP = getHost()
s.listener = &httpListener{
accept: make(chan *httpConn, 10),
}
s.initHTTPRouting()
// Handlers
s.Handle("Handshake", s.handleHandshake)
s.Handle("PeerRequest", s.handlePeerRequest)
s.Handle("PeerNotify", s.handlePeerNotify)
return s, nil
} | [
"func",
"NewServer",
"(",
"logger",
"*",
"log",
".",
"Logger",
",",
"port",
"int",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"if",
"logger",
"==",
"nil",
"{",
"logger",
"=",
"log",
".",
"New",
"(",
"os",
".",
"Stdout",
",",
"\"",
"\"",
"... | // NewServer creates a new server with routing information. If log is nil, stdout is used. | [
"NewServer",
"creates",
"a",
"new",
"server",
"with",
"routing",
"information",
".",
"If",
"log",
"is",
"nil",
"stdout",
"is",
"used",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L78-L105 |
151,173 | degdb/degdb | network/network.go | Stop | func (s *Server) Stop() {
toClose := []Closable{s.netListener, s.listener}
s.peersLock.Lock()
defer s.peersLock.Unlock()
for _, peer := range s.Peers {
toClose = append(toClose, peer)
}
for _, close := range toClose {
if close == nil {
continue
}
if err := close.Close(); err != nil {
s.Println(err)
}
}
} | go | func (s *Server) Stop() {
toClose := []Closable{s.netListener, s.listener}
s.peersLock.Lock()
defer s.peersLock.Unlock()
for _, peer := range s.Peers {
toClose = append(toClose, peer)
}
for _, close := range toClose {
if close == nil {
continue
}
if err := close.Close(); err != nil {
s.Println(err)
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Stop",
"(",
")",
"{",
"toClose",
":=",
"[",
"]",
"Closable",
"{",
"s",
".",
"netListener",
",",
"s",
".",
"listener",
"}",
"\n\n",
"s",
".",
"peersLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"pe... | // Stop closes all connections and cleans up. | [
"Stop",
"closes",
"all",
"connections",
"and",
"cleans",
"up",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L112-L129 |
151,174 | degdb/degdb | network/network.go | Listen | func (s *Server) Listen() error {
ln, err := net.Listen("tcp", "0.0.0.0:"+strconv.Itoa(s.Port))
if err != nil {
return err
}
s.netListener = ln
addr := ln.Addr().(*net.TCPAddr)
if s.Port == 0 {
s.Port = addr.Port
}
go s.listenHTTP(addr)
s.Printf("Listening: 0.0.0.0:%d, ip: %s", s.Port, s.IP)
s.listeningWG.Done()
for {
conn, err := ln.Accept()
if err != nil {
return err
}
s.Printf("New connection from %s", conn.RemoteAddr())
go s.handleConnection(s.NewConn(conn))
}
} | go | func (s *Server) Listen() error {
ln, err := net.Listen("tcp", "0.0.0.0:"+strconv.Itoa(s.Port))
if err != nil {
return err
}
s.netListener = ln
addr := ln.Addr().(*net.TCPAddr)
if s.Port == 0 {
s.Port = addr.Port
}
go s.listenHTTP(addr)
s.Printf("Listening: 0.0.0.0:%d, ip: %s", s.Port, s.IP)
s.listeningWG.Done()
for {
conn, err := ln.Accept()
if err != nil {
return err
}
s.Printf("New connection from %s", conn.RemoteAddr())
go s.handleConnection(s.NewConn(conn))
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Listen",
"(",
")",
"error",
"{",
"ln",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"s",
".",
"Port",
")",
")",
"\n",
"if",
"err",
"!=",
"... | // Listen for incoming connections on the specified port. | [
"Listen",
"for",
"incoming",
"connections",
"on",
"the",
"specified",
"port",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L156-L178 |
151,175 | degdb/degdb | network/network.go | Handle | func (s *Server) Handle(typ string, f protocolHandler) {
s.handlers[typ] = f
} | go | func (s *Server) Handle(typ string, f protocolHandler) {
s.handlers[typ] = f
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Handle",
"(",
"typ",
"string",
",",
"f",
"protocolHandler",
")",
"{",
"s",
".",
"handlers",
"[",
"typ",
"]",
"=",
"f",
"\n",
"}"
] | // Handle registers a handler for a specific protobuf message type. | [
"Handle",
"registers",
"a",
"handler",
"for",
"a",
"specific",
"protobuf",
"message",
"type",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L181-L183 |
151,176 | degdb/degdb | network/network.go | Broadcast | func (s *Server) Broadcast(hash *uint64, msg *protocol.Message) error {
alreadySentTo := make(map[uint64]bool)
if msg.Gossip {
for _, to := range msg.SentTo {
alreadySentTo[to] = true
}
}
sentTo := []uint64{murmur3.Sum64([]byte(s.LocalID()))}
var toPeers []*Conn
for _, peer := range s.Peers {
peerHash := murmur3.Sum64([]byte(peer.Peer.Id))
if (hash == nil || peer.Peer.GetKeyspace().Includes(*hash)) && !alreadySentTo[peerHash] {
sentTo = append(sentTo, peerHash)
toPeers = append(toPeers, peer)
}
}
if msg.Gossip {
msg.SentTo = append(msg.SentTo, sentTo...)
}
if len(toPeers) == 0 {
return ErrNoRecipients
}
for _, peer := range toPeers {
s.Printf("Broadcasting to %s", peer.Peer.Id)
if err := peer.Send(msg); err != nil {
return err
}
}
return nil
} | go | func (s *Server) Broadcast(hash *uint64, msg *protocol.Message) error {
alreadySentTo := make(map[uint64]bool)
if msg.Gossip {
for _, to := range msg.SentTo {
alreadySentTo[to] = true
}
}
sentTo := []uint64{murmur3.Sum64([]byte(s.LocalID()))}
var toPeers []*Conn
for _, peer := range s.Peers {
peerHash := murmur3.Sum64([]byte(peer.Peer.Id))
if (hash == nil || peer.Peer.GetKeyspace().Includes(*hash)) && !alreadySentTo[peerHash] {
sentTo = append(sentTo, peerHash)
toPeers = append(toPeers, peer)
}
}
if msg.Gossip {
msg.SentTo = append(msg.SentTo, sentTo...)
}
if len(toPeers) == 0 {
return ErrNoRecipients
}
for _, peer := range toPeers {
s.Printf("Broadcasting to %s", peer.Peer.Id)
if err := peer.Send(msg); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Broadcast",
"(",
"hash",
"*",
"uint64",
",",
"msg",
"*",
"protocol",
".",
"Message",
")",
"error",
"{",
"alreadySentTo",
":=",
"make",
"(",
"map",
"[",
"uint64",
"]",
"bool",
")",
"\n",
"if",
"msg",
".",
"Goss... | // Broadcast sends a message to all peers with that have the hash in their keyspace.
// If there is no peer that can receive the message, ErrNoRecipients is returned. | [
"Broadcast",
"sends",
"a",
"message",
"to",
"all",
"peers",
"with",
"that",
"have",
"the",
"hash",
"in",
"their",
"keyspace",
".",
"If",
"there",
"is",
"no",
"peer",
"that",
"can",
"receive",
"the",
"message",
"ErrNoRecipients",
"is",
"returned",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L187-L216 |
151,177 | degdb/degdb | network/network.go | LocalPeer | func (s *Server) LocalPeer() *protocol.Peer {
return &protocol.Peer{
Id: s.LocalID(),
Serving: s.Serving,
Keyspace: s.LocalKeyspace(),
}
} | go | func (s *Server) LocalPeer() *protocol.Peer {
return &protocol.Peer{
Id: s.LocalID(),
Serving: s.Serving,
Keyspace: s.LocalKeyspace(),
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"LocalPeer",
"(",
")",
"*",
"protocol",
".",
"Peer",
"{",
"return",
"&",
"protocol",
".",
"Peer",
"{",
"Id",
":",
"s",
".",
"LocalID",
"(",
")",
",",
"Serving",
":",
"s",
".",
"Serving",
",",
"Keyspace",
":",... | // LocalPeer returns a peer object of the current server. | [
"LocalPeer",
"returns",
"a",
"peer",
"object",
"of",
"the",
"current",
"server",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L274-L280 |
151,178 | degdb/degdb | network/network.go | LocalKeyspace | func (s *Server) LocalKeyspace() *protocol.Keyspace {
center := murmur3.Sum64([]byte(s.LocalID()))
return &protocol.Keyspace{
Start: center - math.MaxUint64/4,
End: center + math.MaxUint64/4,
}
} | go | func (s *Server) LocalKeyspace() *protocol.Keyspace {
center := murmur3.Sum64([]byte(s.LocalID()))
return &protocol.Keyspace{
Start: center - math.MaxUint64/4,
End: center + math.MaxUint64/4,
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"LocalKeyspace",
"(",
")",
"*",
"protocol",
".",
"Keyspace",
"{",
"center",
":=",
"murmur3",
".",
"Sum64",
"(",
"[",
"]",
"byte",
"(",
"s",
".",
"LocalID",
"(",
")",
")",
")",
"\n",
"return",
"&",
"protocol",
... | // LocalKeyspace returns the keyspace that the local node represents. | [
"LocalKeyspace",
"returns",
"the",
"keyspace",
"that",
"the",
"local",
"node",
"represents",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L283-L289 |
151,179 | degdb/degdb | network/network.go | LocalID | func (s *Server) LocalID() string {
return net.JoinHostPort(s.IP, strconv.Itoa(s.Port))
} | go | func (s *Server) LocalID() string {
return net.JoinHostPort(s.IP, strconv.Itoa(s.Port))
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"LocalID",
"(",
")",
"string",
"{",
"return",
"net",
".",
"JoinHostPort",
"(",
"s",
".",
"IP",
",",
"strconv",
".",
"Itoa",
"(",
"s",
".",
"Port",
")",
")",
"\n",
"}"
] | // LocalID returns the local machines ID. | [
"LocalID",
"returns",
"the",
"local",
"machines",
"ID",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L292-L294 |
151,180 | degdb/degdb | network/network.go | keySpaceIncrease | func keySpaceIncrease(a, b *protocol.Keyspace) uint64 {
unionMag := a.Union(b).Mag()
aMag := a.Mag()
if unionMag > aMag {
return unionMag - aMag
}
return 0
} | go | func keySpaceIncrease(a, b *protocol.Keyspace) uint64 {
unionMag := a.Union(b).Mag()
aMag := a.Mag()
if unionMag > aMag {
return unionMag - aMag
}
return 0
} | [
"func",
"keySpaceIncrease",
"(",
"a",
",",
"b",
"*",
"protocol",
".",
"Keyspace",
")",
"uint64",
"{",
"unionMag",
":=",
"a",
".",
"Union",
"(",
"b",
")",
".",
"Mag",
"(",
")",
"\n",
"aMag",
":=",
"a",
".",
"Mag",
"(",
")",
"\n",
"if",
"unionMag",... | // keySpaceIncrease calculates the increase in keyspace if b was to be unioned. | [
"keySpaceIncrease",
"calculates",
"the",
"increase",
"in",
"keyspace",
"if",
"b",
"was",
"to",
"be",
"unioned",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/network.go#L336-L343 |
151,181 | degdb/degdb | network/http.go | handleNotFound | func (s *Server) handleNotFound(w http.ResponseWriter, r *http.Request) {
url := r.URL.String()
w.Header().Add("Content-Type", "text/html")
if url == "/" {
var urls []string
for _, path := range s.httpEndpoints {
urls = append(urls, path)
}
sort.Strings(urls)
IndexTemplate.Execute(w, customhttp.DirectoryListing{"/", urls})
} else {
w.WriteHeader(404)
ErrorTemplate.Execute(w, "File Not Found (404) "+url)
}
} | go | func (s *Server) handleNotFound(w http.ResponseWriter, r *http.Request) {
url := r.URL.String()
w.Header().Add("Content-Type", "text/html")
if url == "/" {
var urls []string
for _, path := range s.httpEndpoints {
urls = append(urls, path)
}
sort.Strings(urls)
IndexTemplate.Execute(w, customhttp.DirectoryListing{"/", urls})
} else {
w.WriteHeader(404)
ErrorTemplate.Execute(w, "File Not Found (404) "+url)
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"handleNotFound",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"url",
":=",
"r",
".",
"URL",
".",
"String",
"(",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"A... | // handleNotFound renders a 404 page for missing pages. | [
"handleNotFound",
"renders",
"a",
"404",
"page",
"for",
"missing",
"pages",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/http.go#L27-L41 |
151,182 | degdb/degdb | triplestore/triplestore.go | NewTripleStore | func NewTripleStore(file string, logger *log.Logger) (*TripleStore, error) {
ts := &TripleStore{
dbFile: file,
}
var err error
if ts.db, err = gorm.Open("sqlite3", file); err != nil {
return nil, err
}
ts.db.SetLogger(logger)
ts.db.CreateTable(&protocol.Triple{})
ts.db.Model(&protocol.Triple{}).AddIndex("idx_subj", "subj")
ts.db.Model(&protocol.Triple{}).AddIndex("idx_pred", "pred")
ts.db.Model(&protocol.Triple{}).AddUniqueIndex("idx_subj_pred_obj", "subj", "pred", "obj")
ts.db.AutoMigrate(&protocol.Triple{})
return ts, nil
} | go | func NewTripleStore(file string, logger *log.Logger) (*TripleStore, error) {
ts := &TripleStore{
dbFile: file,
}
var err error
if ts.db, err = gorm.Open("sqlite3", file); err != nil {
return nil, err
}
ts.db.SetLogger(logger)
ts.db.CreateTable(&protocol.Triple{})
ts.db.Model(&protocol.Triple{}).AddIndex("idx_subj", "subj")
ts.db.Model(&protocol.Triple{}).AddIndex("idx_pred", "pred")
ts.db.Model(&protocol.Triple{}).AddUniqueIndex("idx_subj_pred_obj", "subj", "pred", "obj")
ts.db.AutoMigrate(&protocol.Triple{})
return ts, nil
} | [
"func",
"NewTripleStore",
"(",
"file",
"string",
",",
"logger",
"*",
"log",
".",
"Logger",
")",
"(",
"*",
"TripleStore",
",",
"error",
")",
"{",
"ts",
":=",
"&",
"TripleStore",
"{",
"dbFile",
":",
"file",
",",
"}",
"\n",
"var",
"err",
"error",
"\n",
... | // NewTripleStore returns a TripleStore with the specified file. | [
"NewTripleStore",
"returns",
"a",
"TripleStore",
"with",
"the",
"specified",
"file",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/triplestore/triplestore.go#L30-L45 |
151,183 | degdb/degdb | triplestore/triplestore.go | Query | func (ts *TripleStore) Query(query *protocol.Triple, limit int) ([]*protocol.Triple, error) {
dbq := ts.db.Where(*query)
if limit > 0 {
dbq = dbq.Limit(limit)
}
var results []*protocol.Triple
if err := dbq.Find(&results).Error; err != nil {
return nil, err
}
return results, nil
} | go | func (ts *TripleStore) Query(query *protocol.Triple, limit int) ([]*protocol.Triple, error) {
dbq := ts.db.Where(*query)
if limit > 0 {
dbq = dbq.Limit(limit)
}
var results []*protocol.Triple
if err := dbq.Find(&results).Error; err != nil {
return nil, err
}
return results, nil
} | [
"func",
"(",
"ts",
"*",
"TripleStore",
")",
"Query",
"(",
"query",
"*",
"protocol",
".",
"Triple",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"*",
"protocol",
".",
"Triple",
",",
"error",
")",
"{",
"dbq",
":=",
"ts",
".",
"db",
".",
"Where",
"(",
... | // Query does a WHERE search with the set fields on query. A limit of -1
// returns all results. | [
"Query",
"does",
"a",
"WHERE",
"search",
"with",
"the",
"set",
"fields",
"on",
"query",
".",
"A",
"limit",
"of",
"-",
"1",
"returns",
"all",
"results",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/triplestore/triplestore.go#L49-L59 |
151,184 | degdb/degdb | triplestore/triplestore.go | QueryArrayOp | func (ts *TripleStore) QueryArrayOp(q *protocol.ArrayOp, limit int) ([]*protocol.Triple, error) {
query := ArrayOpToSQL(q)
args := make([]interface{}, len(query)-1)
for i, arg := range query[1:] {
args[i] = arg
}
dbq := ts.db.Where(query[0], args...)
if limit > 0 {
dbq = dbq.Limit(limit)
}
var results []*protocol.Triple
if err := dbq.Find(&results).Error; err != nil {
return nil, err
}
return results, nil
} | go | func (ts *TripleStore) QueryArrayOp(q *protocol.ArrayOp, limit int) ([]*protocol.Triple, error) {
query := ArrayOpToSQL(q)
args := make([]interface{}, len(query)-1)
for i, arg := range query[1:] {
args[i] = arg
}
dbq := ts.db.Where(query[0], args...)
if limit > 0 {
dbq = dbq.Limit(limit)
}
var results []*protocol.Triple
if err := dbq.Find(&results).Error; err != nil {
return nil, err
}
return results, nil
} | [
"func",
"(",
"ts",
"*",
"TripleStore",
")",
"QueryArrayOp",
"(",
"q",
"*",
"protocol",
".",
"ArrayOp",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"*",
"protocol",
".",
"Triple",
",",
"error",
")",
"{",
"query",
":=",
"ArrayOpToSQL",
"(",
"q",
")",
"\... | // QueryArrayOp runs an ArrayOp against the local triple store. | [
"QueryArrayOp",
"runs",
"an",
"ArrayOp",
"against",
"the",
"local",
"triple",
"store",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/triplestore/triplestore.go#L62-L77 |
151,185 | degdb/degdb | triplestore/triplestore.go | Insert | func (ts *TripleStore) Insert(triples []*protocol.Triple) int {
count := 0
tx := ts.db.Begin()
for _, triple := range triples {
if err := tx.Create(triple).Error; err != nil {
continue
}
count++
}
if err := tx.Commit().Error; err != nil {
return 0
}
return count
} | go | func (ts *TripleStore) Insert(triples []*protocol.Triple) int {
count := 0
tx := ts.db.Begin()
for _, triple := range triples {
if err := tx.Create(triple).Error; err != nil {
continue
}
count++
}
if err := tx.Commit().Error; err != nil {
return 0
}
return count
} | [
"func",
"(",
"ts",
"*",
"TripleStore",
")",
"Insert",
"(",
"triples",
"[",
"]",
"*",
"protocol",
".",
"Triple",
")",
"int",
"{",
"count",
":=",
"0",
"\n",
"tx",
":=",
"ts",
".",
"db",
".",
"Begin",
"(",
")",
"\n",
"for",
"_",
",",
"triple",
":=... | // Insert saves a bunch of triples and returns the number asserted. | [
"Insert",
"saves",
"a",
"bunch",
"of",
"triples",
"and",
"returns",
"the",
"number",
"asserted",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/triplestore/triplestore.go#L135-L148 |
151,186 | degdb/degdb | triplestore/triplestore.go | Size | func (ts *TripleStore) Size() (*Info, error) {
fileInfo, err := os.Stat(ts.dbFile)
if err != nil {
return nil, err
}
space := du.NewDiskUsage(ts.dbFile)
i := &Info{
DiskSize: uint64(fileInfo.Size()),
AvailableSpace: space.Available(),
}
ts.db.Model(&protocol.Triple{}).Count(&i.Triples)
return i, nil
} | go | func (ts *TripleStore) Size() (*Info, error) {
fileInfo, err := os.Stat(ts.dbFile)
if err != nil {
return nil, err
}
space := du.NewDiskUsage(ts.dbFile)
i := &Info{
DiskSize: uint64(fileInfo.Size()),
AvailableSpace: space.Available(),
}
ts.db.Model(&protocol.Triple{}).Count(&i.Triples)
return i, nil
} | [
"func",
"(",
"ts",
"*",
"TripleStore",
")",
"Size",
"(",
")",
"(",
"*",
"Info",
",",
"error",
")",
"{",
"fileInfo",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"ts",
".",
"dbFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // Size returns an info object about the number of triples and file size of the
// database. | [
"Size",
"returns",
"an",
"info",
"object",
"about",
"the",
"number",
"of",
"triples",
"and",
"file",
"size",
"of",
"the",
"database",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/triplestore/triplestore.go#L157-L170 |
151,187 | degdb/degdb | triplestore/triplestore.go | EachTripleBatch | func (ts *TripleStore) EachTripleBatch(size int) (<-chan []*protocol.Triple, <-chan error) {
c := make(chan []*protocol.Triple, 10)
cerr := make(chan error, 1)
go func() {
dbq := ts.db.Where(&protocol.Triple{}).Limit(size)
var triples []*protocol.Triple
for i := 0; i == 0 || len(triples) > 0; i++ {
triples = triples[0:0]
if err := dbq.Offset(i * size).Find(&triples).Error; err != nil {
cerr <- err
break
}
if len(triples) > 0 {
c <- triples
}
}
close(c)
close(cerr)
}()
return c, cerr
} | go | func (ts *TripleStore) EachTripleBatch(size int) (<-chan []*protocol.Triple, <-chan error) {
c := make(chan []*protocol.Triple, 10)
cerr := make(chan error, 1)
go func() {
dbq := ts.db.Where(&protocol.Triple{}).Limit(size)
var triples []*protocol.Triple
for i := 0; i == 0 || len(triples) > 0; i++ {
triples = triples[0:0]
if err := dbq.Offset(i * size).Find(&triples).Error; err != nil {
cerr <- err
break
}
if len(triples) > 0 {
c <- triples
}
}
close(c)
close(cerr)
}()
return c, cerr
} | [
"func",
"(",
"ts",
"*",
"TripleStore",
")",
"EachTripleBatch",
"(",
"size",
"int",
")",
"(",
"<-",
"chan",
"[",
"]",
"*",
"protocol",
".",
"Triple",
",",
"<-",
"chan",
"error",
")",
"{",
"c",
":=",
"make",
"(",
"chan",
"[",
"]",
"*",
"protocol",
... | // EachTripleBatch is used to stream triples from the database in batches of the specified size. | [
"EachTripleBatch",
"is",
"used",
"to",
"stream",
"triples",
"from",
"the",
"database",
"in",
"batches",
"of",
"the",
"specified",
"size",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/triplestore/triplestore.go#L173-L195 |
151,188 | captncraig/caddy-realip | setup.go | addIpRanges | func addIpRanges(m *module, c *caddy.Controller, ranges []string) error {
for _, v := range ranges {
if preset, ok := presets[v]; ok {
if err := addIpRanges(m, c, preset); err != nil {
return err
}
continue
}
_, cidr, err := net.ParseCIDR(v)
if err != nil {
return c.Err(err.Error())
}
m.From = append(m.From, cidr)
}
return nil
} | go | func addIpRanges(m *module, c *caddy.Controller, ranges []string) error {
for _, v := range ranges {
if preset, ok := presets[v]; ok {
if err := addIpRanges(m, c, preset); err != nil {
return err
}
continue
}
_, cidr, err := net.ParseCIDR(v)
if err != nil {
return c.Err(err.Error())
}
m.From = append(m.From, cidr)
}
return nil
} | [
"func",
"addIpRanges",
"(",
"m",
"*",
"module",
",",
"c",
"*",
"caddy",
".",
"Controller",
",",
"ranges",
"[",
"]",
"string",
")",
"error",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"ranges",
"{",
"if",
"preset",
",",
"ok",
":=",
"presets",
"[",
... | // Adds a list of CIDR IP Ranges to the From whitelist | [
"Adds",
"a",
"list",
"of",
"CIDR",
"IP",
"Ranges",
"to",
"the",
"From",
"whitelist"
] | 5dd1f4047d0f649f21ba9f8d7e491d712be9a5b0 | https://github.com/captncraig/caddy-realip/blob/5dd1f4047d0f649f21ba9f8d7e491d712be9a5b0/setup.go#L68-L83 |
151,189 | captncraig/caddy-realip | setup.go | StringArg | func StringArg(c *caddy.Controller) (string, error) {
args := c.RemainingArgs()
if len(args) != 1 {
return "", c.ArgErr()
}
return args[0], nil
} | go | func StringArg(c *caddy.Controller) (string, error) {
args := c.RemainingArgs()
if len(args) != 1 {
return "", c.ArgErr()
}
return args[0], nil
} | [
"func",
"StringArg",
"(",
"c",
"*",
"caddy",
".",
"Controller",
")",
"(",
"string",
",",
"error",
")",
"{",
"args",
":=",
"c",
".",
"RemainingArgs",
"(",
")",
"\n",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
"{",
"return",
"\"",
"\"",
",",
"c",
... | // Assert only one arg and return it | [
"Assert",
"only",
"one",
"arg",
"and",
"return",
"it"
] | 5dd1f4047d0f649f21ba9f8d7e491d712be9a5b0 | https://github.com/captncraig/caddy-realip/blob/5dd1f4047d0f649f21ba9f8d7e491d712be9a5b0/setup.go#L99-L105 |
151,190 | captncraig/caddy-realip | setup.go | CidrArg | func CidrArg(c *caddy.Controller) (*net.IPNet, error) {
a, err := StringArg(c)
if err != nil {
return nil, err
}
_, cidr, err := net.ParseCIDR(a)
if err != nil {
return nil, err
}
return cidr, nil
} | go | func CidrArg(c *caddy.Controller) (*net.IPNet, error) {
a, err := StringArg(c)
if err != nil {
return nil, err
}
_, cidr, err := net.ParseCIDR(a)
if err != nil {
return nil, err
}
return cidr, nil
} | [
"func",
"CidrArg",
"(",
"c",
"*",
"caddy",
".",
"Controller",
")",
"(",
"*",
"net",
".",
"IPNet",
",",
"error",
")",
"{",
"a",
",",
"err",
":=",
"StringArg",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",... | // Assert only one arg is a valid cidr notation | [
"Assert",
"only",
"one",
"arg",
"is",
"a",
"valid",
"cidr",
"notation"
] | 5dd1f4047d0f649f21ba9f8d7e491d712be9a5b0 | https://github.com/captncraig/caddy-realip/blob/5dd1f4047d0f649f21ba9f8d7e491d712be9a5b0/setup.go#L108-L118 |
151,191 | degdb/degdb | crypto/fingerprint.go | FingerprintTriple | func FingerprintTriple(t *protocol.Triple) ([]byte, error) {
data, err := t.Marshal()
if err != nil {
return nil, err
}
sum := sha1.Sum(data)
return sum[:], nil
} | go | func FingerprintTriple(t *protocol.Triple) ([]byte, error) {
data, err := t.Marshal()
if err != nil {
return nil, err
}
sum := sha1.Sum(data)
return sum[:], nil
} | [
"func",
"FingerprintTriple",
"(",
"t",
"*",
"protocol",
".",
"Triple",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"t",
".",
"Marshal",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
... | // FingerprintTriple generates a SHA-1 hash of the triple. | [
"FingerprintTriple",
"generates",
"a",
"SHA",
"-",
"1",
"hash",
"of",
"the",
"triple",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/crypto/fingerprint.go#L10-L17 |
151,192 | degdb/degdb | core/binary.go | initBinary | func (s *server) initBinary() error {
s.network.Handle("InsertTriples", s.handleInsertTriples)
s.network.Handle("QueryRequest", s.handleQueryRequest)
return nil
} | go | func (s *server) initBinary() error {
s.network.Handle("InsertTriples", s.handleInsertTriples)
s.network.Handle("QueryRequest", s.handleQueryRequest)
return nil
} | [
"func",
"(",
"s",
"*",
"server",
")",
"initBinary",
"(",
")",
"error",
"{",
"s",
".",
"network",
".",
"Handle",
"(",
"\"",
"\"",
",",
"s",
".",
"handleInsertTriples",
")",
"\n",
"s",
".",
"network",
".",
"Handle",
"(",
"\"",
"\"",
",",
"s",
".",
... | // initBinary initalizes the binary endpoints. | [
"initBinary",
"initalizes",
"the",
"binary",
"endpoints",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/core/binary.go#L10-L15 |
151,193 | degdb/degdb | protocol/keyspace.go | Includes | func (k *Keyspace) Includes(hash uint64) bool {
if k == nil {
return false
}
a := hash
s := k.Start
e := k.End
return s <= a && a < e || a < e && e < s || e < s && s <= a
} | go | func (k *Keyspace) Includes(hash uint64) bool {
if k == nil {
return false
}
a := hash
s := k.Start
e := k.End
return s <= a && a < e || a < e && e < s || e < s && s <= a
} | [
"func",
"(",
"k",
"*",
"Keyspace",
")",
"Includes",
"(",
"hash",
"uint64",
")",
"bool",
"{",
"if",
"k",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"a",
":=",
"hash",
"\n",
"s",
":=",
"k",
".",
"Start",
"\n",
"e",
":=",
"k",
".",
"E... | // Includes checks if the provided uint64 is inside the keyspace. | [
"Includes",
"checks",
"if",
"the",
"provided",
"uint64",
"is",
"inside",
"the",
"keyspace",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/protocol/keyspace.go#L4-L12 |
151,194 | degdb/degdb | protocol/keyspace.go | Mag | func (k *Keyspace) Mag() uint64 {
if k == nil {
return 0
}
return k.End - k.Start
} | go | func (k *Keyspace) Mag() uint64 {
if k == nil {
return 0
}
return k.End - k.Start
} | [
"func",
"(",
"k",
"*",
"Keyspace",
")",
"Mag",
"(",
")",
"uint64",
"{",
"if",
"k",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"k",
".",
"End",
"-",
"k",
".",
"Start",
"\n",
"}"
] | // Mag returns the size of the keyspace. | [
"Mag",
"returns",
"the",
"size",
"of",
"the",
"keyspace",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/protocol/keyspace.go#L15-L20 |
151,195 | degdb/degdb | protocol/keyspace.go | Union | func (k *Keyspace) Union(a *Keyspace) *Keyspace {
if a == nil && k == nil {
return nil
} else if a == nil {
return k.Clone()
} else if k == nil {
return a.Clone()
}
aSI := k.Includes(a.Start) || k.End == a.Start
aEI := k.Includes(a.End) || k.Start == a.End
kSI := a.Includes(k.Start) || a.End == k.Start
kEI := a.Includes(k.End) || a.Start == k.End
switch {
// Complete keyspace
case aSI && aEI && kSI && kEI:
return &Keyspace{Start: k.Start, End: k.Start - 1}
// k encompasses a
case aSI && aEI:
return k.Clone()
// a encompasses k
case kSI && kEI:
return a.Clone()
// a.Start is in k
case aSI:
return &Keyspace{Start: k.Start, End: a.End}
// a.End is in k
case aEI:
return &Keyspace{Start: a.Start, End: k.End}
}
return nil
} | go | func (k *Keyspace) Union(a *Keyspace) *Keyspace {
if a == nil && k == nil {
return nil
} else if a == nil {
return k.Clone()
} else if k == nil {
return a.Clone()
}
aSI := k.Includes(a.Start) || k.End == a.Start
aEI := k.Includes(a.End) || k.Start == a.End
kSI := a.Includes(k.Start) || a.End == k.Start
kEI := a.Includes(k.End) || a.Start == k.End
switch {
// Complete keyspace
case aSI && aEI && kSI && kEI:
return &Keyspace{Start: k.Start, End: k.Start - 1}
// k encompasses a
case aSI && aEI:
return k.Clone()
// a encompasses k
case kSI && kEI:
return a.Clone()
// a.Start is in k
case aSI:
return &Keyspace{Start: k.Start, End: a.End}
// a.End is in k
case aEI:
return &Keyspace{Start: a.Start, End: k.End}
}
return nil
} | [
"func",
"(",
"k",
"*",
"Keyspace",
")",
"Union",
"(",
"a",
"*",
"Keyspace",
")",
"*",
"Keyspace",
"{",
"if",
"a",
"==",
"nil",
"&&",
"k",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"a",
"==",
"nil",
"{",
"return",
"k",
".",
"... | // Union returns the union of the keyspaces. They must overlap otherwise nil is returned. | [
"Union",
"returns",
"the",
"union",
"of",
"the",
"keyspaces",
".",
"They",
"must",
"overlap",
"otherwise",
"nil",
"is",
"returned",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/protocol/keyspace.go#L23-L58 |
151,196 | degdb/degdb | protocol/keyspace.go | Maxed | func (k *Keyspace) Maxed() bool {
return k != nil && k.End == k.Start-1
} | go | func (k *Keyspace) Maxed() bool {
return k != nil && k.End == k.Start-1
} | [
"func",
"(",
"k",
"*",
"Keyspace",
")",
"Maxed",
"(",
")",
"bool",
"{",
"return",
"k",
"!=",
"nil",
"&&",
"k",
".",
"End",
"==",
"k",
".",
"Start",
"-",
"1",
"\n",
"}"
] | // Maxed returns whether the keyspace encompasses the entire keyspace. | [
"Maxed",
"returns",
"whether",
"the",
"keyspace",
"encompasses",
"the",
"entire",
"keyspace",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/protocol/keyspace.go#L105-L107 |
151,197 | degdb/degdb | protocol/keyspace.go | Complement | func (k *Keyspace) Complement() *Keyspace {
if k == nil {
return &Keyspace{1, 0}
} else if k.Maxed() {
return nil
}
return &Keyspace{Start: k.End, End: k.Start}
} | go | func (k *Keyspace) Complement() *Keyspace {
if k == nil {
return &Keyspace{1, 0}
} else if k.Maxed() {
return nil
}
return &Keyspace{Start: k.End, End: k.Start}
} | [
"func",
"(",
"k",
"*",
"Keyspace",
")",
"Complement",
"(",
")",
"*",
"Keyspace",
"{",
"if",
"k",
"==",
"nil",
"{",
"return",
"&",
"Keyspace",
"{",
"1",
",",
"0",
"}",
"\n",
"}",
"else",
"if",
"k",
".",
"Maxed",
"(",
")",
"{",
"return",
"nil",
... | // Complement returns the complement of the keyspace. | [
"Complement",
"returns",
"the",
"complement",
"of",
"the",
"keyspace",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/protocol/keyspace.go#L110-L117 |
151,198 | degdb/degdb | protocol/keyspace.go | Clone | func (k *Keyspace) Clone() *Keyspace {
return &Keyspace{Start: k.Start, End: k.End}
} | go | func (k *Keyspace) Clone() *Keyspace {
return &Keyspace{Start: k.Start, End: k.End}
} | [
"func",
"(",
"k",
"*",
"Keyspace",
")",
"Clone",
"(",
")",
"*",
"Keyspace",
"{",
"return",
"&",
"Keyspace",
"{",
"Start",
":",
"k",
".",
"Start",
",",
"End",
":",
"k",
".",
"End",
"}",
"\n",
"}"
] | // Clone makes a copy of the keyspace. | [
"Clone",
"makes",
"a",
"copy",
"of",
"the",
"keyspace",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/protocol/keyspace.go#L120-L122 |
151,199 | degdb/degdb | network/conn.go | NewConn | func (s *Server) NewConn(c net.Conn) *Conn {
return &Conn{
Conn: c,
server: s,
expectedMessages: make(map[uint64]chan *protocol.Message),
}
} | go | func (s *Server) NewConn(c net.Conn) *Conn {
return &Conn{
Conn: c,
server: s,
expectedMessages: make(map[uint64]chan *protocol.Message),
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"NewConn",
"(",
"c",
"net",
".",
"Conn",
")",
"*",
"Conn",
"{",
"return",
"&",
"Conn",
"{",
"Conn",
":",
"c",
",",
"server",
":",
"s",
",",
"expectedMessages",
":",
"make",
"(",
"map",
"[",
"uint64",
"]",
"... | // NewConn creates a new Conn with the specified net.Conn. | [
"NewConn",
"creates",
"a",
"new",
"Conn",
"with",
"the",
"specified",
"net",
".",
"Conn",
"."
] | a69b0804daddf97dcacc876daa199078a293a9d0 | https://github.com/degdb/degdb/blob/a69b0804daddf97dcacc876daa199078a293a9d0/network/conn.go#L18-L24 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.