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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
mdlayher/netlink | attribute.go | Uint8 | func (ae *AttributeEncoder) Uint8(typ uint16, v uint8) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: []byte{v},
})
} | go | func (ae *AttributeEncoder) Uint8(typ uint16, v uint8) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: []byte{v},
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Uint8",
"(",
"typ",
"uint16",
",",
"v",
"uint8",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ae",
".",
"attrs",
"=",
"append",
"(",
"ae",
".",
"attrs",
",",
... | // Uint8 encodes uint8 data into an Attribute specified by typ. | [
"Uint8",
"encodes",
"uint8",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L331-L340 | train |
mdlayher/netlink | attribute.go | Uint16 | func (ae *AttributeEncoder) Uint16(typ uint16, v uint16) {
if ae.err != nil {
return
}
b := make([]byte, 2)
ae.ByteOrder.PutUint16(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | go | func (ae *AttributeEncoder) Uint16(typ uint16, v uint16) {
if ae.err != nil {
return
}
b := make([]byte, 2)
ae.ByteOrder.PutUint16(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Uint16",
"(",
"typ",
"uint16",
",",
"v",
"uint16",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
")",
"\n",... | // Uint16 encodes uint16 data into an Attribute specified by typ. | [
"Uint16",
"encodes",
"uint16",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L343-L355 | train |
mdlayher/netlink | attribute.go | Uint32 | func (ae *AttributeEncoder) Uint32(typ uint16, v uint32) {
if ae.err != nil {
return
}
b := make([]byte, 4)
ae.ByteOrder.PutUint32(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | go | func (ae *AttributeEncoder) Uint32(typ uint16, v uint32) {
if ae.err != nil {
return
}
b := make([]byte, 4)
ae.ByteOrder.PutUint32(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Uint32",
"(",
"typ",
"uint16",
",",
"v",
"uint32",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"4",
")",
"\n",... | // Uint32 encodes uint32 data into an Attribute specified by typ. | [
"Uint32",
"encodes",
"uint32",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L358-L370 | train |
mdlayher/netlink | attribute.go | Uint64 | func (ae *AttributeEncoder) Uint64(typ uint16, v uint64) {
if ae.err != nil {
return
}
b := make([]byte, 8)
ae.ByteOrder.PutUint64(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | go | func (ae *AttributeEncoder) Uint64(typ uint16, v uint64) {
if ae.err != nil {
return
}
b := make([]byte, 8)
ae.ByteOrder.PutUint64(b, v)
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Uint64",
"(",
"typ",
"uint16",
",",
"v",
"uint64",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
")",
"\n",... | // Uint64 encodes uint64 data into an Attribute specified by typ. | [
"Uint64",
"encodes",
"uint64",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L373-L385 | train |
mdlayher/netlink | attribute.go | String | func (ae *AttributeEncoder) String(typ uint16, s string) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: nlenc.Bytes(s),
})
} | go | func (ae *AttributeEncoder) String(typ uint16, s string) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: nlenc.Bytes(s),
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"String",
"(",
"typ",
"uint16",
",",
"s",
"string",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ae",
".",
"attrs",
"=",
"append",
"(",
"ae",
".",
"attrs",
",",... | // String encodes string s as a null-terminated string into an Attribute
// specified by typ. | [
"String",
"encodes",
"string",
"s",
"as",
"a",
"null",
"-",
"terminated",
"string",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L389-L398 | train |
mdlayher/netlink | attribute.go | Bytes | func (ae *AttributeEncoder) Bytes(typ uint16, b []byte) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | go | func (ae *AttributeEncoder) Bytes(typ uint16, b []byte) {
if ae.err != nil {
return
}
ae.attrs = append(ae.attrs, Attribute{
Type: typ,
Data: b,
})
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Bytes",
"(",
"typ",
"uint16",
",",
"b",
"[",
"]",
"byte",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ae",
".",
"attrs",
"=",
"append",
"(",
"ae",
".",
"att... | // Bytes embeds raw byte data into an Attribute specified by typ. | [
"Bytes",
"embeds",
"raw",
"byte",
"data",
"into",
"an",
"Attribute",
"specified",
"by",
"typ",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L401-L410 | train |
mdlayher/netlink | attribute.go | Encode | func (ae *AttributeEncoder) Encode() ([]byte, error) {
if ae.err != nil {
return nil, ae.err
}
return MarshalAttributes(ae.attrs)
} | go | func (ae *AttributeEncoder) Encode() ([]byte, error) {
if ae.err != nil {
return nil, ae.err
}
return MarshalAttributes(ae.attrs)
} | [
"func",
"(",
"ae",
"*",
"AttributeEncoder",
")",
"Encode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"ae",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"ae",
".",
"err",
"\n",
"}",
"\n\n",
"return",
"MarshalAttributes",
... | // Encode returns the encoded bytes representing the attributes. | [
"Encode",
"returns",
"the",
"encoded",
"bytes",
"representing",
"the",
"attributes",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/attribute.go#L436-L442 | train |
mdlayher/netlink | conn.go | Dial | func Dial(family int, config *Config) (*Conn, error) {
// Use OS-specific dial() to create Socket
c, pid, err := dial(family, config)
if err != nil {
return nil, err
}
return NewConn(c, pid), nil
} | go | func Dial(family int, config *Config) (*Conn, error) {
// Use OS-specific dial() to create Socket
c, pid, err := dial(family, config)
if err != nil {
return nil, err
}
return NewConn(c, pid), nil
} | [
"func",
"Dial",
"(",
"family",
"int",
",",
"config",
"*",
"Config",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"// Use OS-specific dial() to create Socket",
"c",
",",
"pid",
",",
"err",
":=",
"dial",
"(",
"family",
",",
"config",
")",
"\n",
"if",
"... | // Dial dials a connection to netlink, using the specified netlink family.
// Config specifies optional configuration for Conn. If config is nil, a default
// configuration will be used. | [
"Dial",
"dials",
"a",
"connection",
"to",
"netlink",
"using",
"the",
"specified",
"netlink",
"family",
".",
"Config",
"specifies",
"optional",
"configuration",
"for",
"Conn",
".",
"If",
"config",
"is",
"nil",
"a",
"default",
"configuration",
"will",
"be",
"use... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L53-L61 | train |
mdlayher/netlink | conn.go | NewConn | func NewConn(sock Socket, pid uint32) *Conn {
// Seed the sequence number using a random number generator.
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seq := r.Uint32()
// Configure a debugger if arguments are set.
var d *debugger
if len(debugArgs) > 0 {
d = newDebugger(debugArgs)
}
return &Conn{
... | go | func NewConn(sock Socket, pid uint32) *Conn {
// Seed the sequence number using a random number generator.
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seq := r.Uint32()
// Configure a debugger if arguments are set.
var d *debugger
if len(debugArgs) > 0 {
d = newDebugger(debugArgs)
}
return &Conn{
... | [
"func",
"NewConn",
"(",
"sock",
"Socket",
",",
"pid",
"uint32",
")",
"*",
"Conn",
"{",
"// Seed the sequence number using a random number generator.",
"r",
":=",
"rand",
".",
"New",
"(",
"rand",
".",
"NewSource",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix... | // NewConn creates a Conn using the specified Socket and PID for netlink
// communications.
//
// NewConn is primarily useful for tests. Most applications should use
// Dial instead. | [
"NewConn",
"creates",
"a",
"Conn",
"using",
"the",
"specified",
"Socket",
"and",
"PID",
"for",
"netlink",
"communications",
".",
"NewConn",
"is",
"primarily",
"useful",
"for",
"tests",
".",
"Most",
"applications",
"should",
"use",
"Dial",
"instead",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L68-L85 | train |
mdlayher/netlink | conn.go | debug | func (c *Conn) debug(fn func(d *debugger)) {
if c.d == nil {
return
}
fn(c.d)
} | go | func (c *Conn) debug(fn func(d *debugger)) {
if c.d == nil {
return
}
fn(c.d)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"debug",
"(",
"fn",
"func",
"(",
"d",
"*",
"debugger",
")",
")",
"{",
"if",
"c",
".",
"d",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"fn",
"(",
"c",
".",
"d",
")",
"\n",
"}"
] | // debug executes fn with the debugger if the debugger is not nil. | [
"debug",
"executes",
"fn",
"with",
"the",
"debugger",
"if",
"the",
"debugger",
"is",
"not",
"nil",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L88-L94 | train |
mdlayher/netlink | conn.go | SendMessages | func (c *Conn) SendMessages(messages []Message) ([]Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
for idx, m := range messages {
ml := nlmsgLength(len(m.Data))
// TODO(mdlayher): fine-tune this limit.
if ml > (1024 * 32) {
retu... | go | func (c *Conn) SendMessages(messages []Message) ([]Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
for idx, m := range messages {
ml := nlmsgLength(len(m.Data))
// TODO(mdlayher): fine-tune this limit.
if ml > (1024 * 32) {
retu... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SendMessages",
"(",
"messages",
"[",
"]",
"Message",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"// Wait for any concurrent calls to Execute to finish before proceeding.",
"c",
".",
"mu",
".",
"RLock",
"(",
")",... | // SendMessages sends multiple Messages to netlink. The handling of
// a Header's Length, Sequence and PID fields is the same as when
// calling Send. | [
"SendMessages",
"sends",
"multiple",
"Messages",
"to",
"netlink",
".",
"The",
"handling",
"of",
"a",
"Header",
"s",
"Length",
"Sequence",
"and",
"PID",
"fields",
"is",
"the",
"same",
"as",
"when",
"calling",
"Send",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L144-L175 | train |
mdlayher/netlink | conn.go | Send | func (c *Conn) Send(message Message) (Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
return c.lockedSend(message)
} | go | func (c *Conn) Send(message Message) (Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
return c.lockedSend(message)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Send",
"(",
"message",
"Message",
")",
"(",
"Message",
",",
"error",
")",
"{",
"// Wait for any concurrent calls to Execute to finish before proceeding.",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"... | // Send sends a single Message to netlink. In most cases, a Header's Length,
// Sequence, and PID fields should be set to 0, so they can be populated
// automatically before the Message is sent. On success, Send returns a copy
// of the Message with all parameters populated, for later validation.
//
// If Header.Leng... | [
"Send",
"sends",
"a",
"single",
"Message",
"to",
"netlink",
".",
"In",
"most",
"cases",
"a",
"Header",
"s",
"Length",
"Sequence",
"and",
"PID",
"fields",
"should",
"be",
"set",
"to",
"0",
"so",
"they",
"can",
"be",
"populated",
"automatically",
"before",
... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L190-L196 | train |
mdlayher/netlink | conn.go | lockedSend | func (c *Conn) lockedSend(message Message) (Message, error) {
ml := nlmsgLength(len(message.Data))
// TODO(mdlayher): fine-tune this limit.
if ml > (1024 * 32) {
return Message{}, errors.New("netlink message data too large")
}
c.fixMsg(&message, ml)
c.debug(func(d *debugger) {
d.debugf(1, "send: %+v", mess... | go | func (c *Conn) lockedSend(message Message) (Message, error) {
ml := nlmsgLength(len(message.Data))
// TODO(mdlayher): fine-tune this limit.
if ml > (1024 * 32) {
return Message{}, errors.New("netlink message data too large")
}
c.fixMsg(&message, ml)
c.debug(func(d *debugger) {
d.debugf(1, "send: %+v", mess... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"lockedSend",
"(",
"message",
"Message",
")",
"(",
"Message",
",",
"error",
")",
"{",
"ml",
":=",
"nlmsgLength",
"(",
"len",
"(",
"message",
".",
"Data",
")",
")",
"\n\n",
"// TODO(mdlayher): fine-tune this limit.",
"if"... | // lockedSend implements Send, but must be called with c.mu acquired for reading.
// We rely on the kernel to deal with concurrent reads and writes to the netlink
// socket itself. | [
"lockedSend",
"implements",
"Send",
"but",
"must",
"be",
"called",
"with",
"c",
".",
"mu",
"acquired",
"for",
"reading",
".",
"We",
"rely",
"on",
"the",
"kernel",
"to",
"deal",
"with",
"concurrent",
"reads",
"and",
"writes",
"to",
"the",
"netlink",
"socket... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L201-L224 | train |
mdlayher/netlink | conn.go | Receive | func (c *Conn) Receive() ([]Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
return c.lockedReceive()
} | go | func (c *Conn) Receive() ([]Message, error) {
// Wait for any concurrent calls to Execute to finish before proceeding.
c.mu.RLock()
defer c.mu.RUnlock()
return c.lockedReceive()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Receive",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"// Wait for any concurrent calls to Execute to finish before proceeding.",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".... | // Receive receives one or more messages from netlink. Multi-part messages are
// handled transparently and returned as a single slice of Messages, with the
// final empty "multi-part done" message removed.
//
// If any of the messages indicate a netlink error, that error will be returned. | [
"Receive",
"receives",
"one",
"or",
"more",
"messages",
"from",
"netlink",
".",
"Multi",
"-",
"part",
"messages",
"are",
"handled",
"transparently",
"and",
"returned",
"as",
"a",
"single",
"slice",
"of",
"Messages",
"with",
"the",
"final",
"empty",
"multi",
... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L231-L237 | train |
mdlayher/netlink | conn.go | lockedReceive | func (c *Conn) lockedReceive() ([]Message, error) {
msgs, err := c.receive()
if err != nil {
c.debug(func(d *debugger) {
d.debugf(1, "recv: err: %v", err)
})
return nil, err
}
c.debug(func(d *debugger) {
for _, m := range msgs {
d.debugf(1, "recv: %+v", m)
}
})
// When using nltest, it's possib... | go | func (c *Conn) lockedReceive() ([]Message, error) {
msgs, err := c.receive()
if err != nil {
c.debug(func(d *debugger) {
d.debugf(1, "recv: err: %v", err)
})
return nil, err
}
c.debug(func(d *debugger) {
for _, m := range msgs {
d.debugf(1, "recv: %+v", m)
}
})
// When using nltest, it's possib... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"lockedReceive",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"msgs",
",",
"err",
":=",
"c",
".",
"receive",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"debug",
"(",
"func",
"("... | // lockedReceive implements Receive, but must be called with c.mu acquired for reading.
// We rely on the kernel to deal with concurrent reads and writes to the netlink
// socket itself. | [
"lockedReceive",
"implements",
"Receive",
"but",
"must",
"be",
"called",
"with",
"c",
".",
"mu",
"acquired",
"for",
"reading",
".",
"We",
"rely",
"on",
"the",
"kernel",
"to",
"deal",
"with",
"concurrent",
"reads",
"and",
"writes",
"to",
"the",
"netlink",
"... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L242-L270 | train |
mdlayher/netlink | conn.go | receive | func (c *Conn) receive() ([]Message, error) {
// NB: All non-nil errors returned from this function *must* be of type
// OpError in order to maintain the appropriate contract with callers of
// this package.
//
// This contract also applies to functions called within this function,
// such as checkMessage.
var ... | go | func (c *Conn) receive() ([]Message, error) {
// NB: All non-nil errors returned from this function *must* be of type
// OpError in order to maintain the appropriate contract with callers of
// this package.
//
// This contract also applies to functions called within this function,
// such as checkMessage.
var ... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"receive",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"// NB: All non-nil errors returned from this function *must* be of type",
"// OpError in order to maintain the appropriate contract with callers of",
"// this package.",
... | // receive is the internal implementation of Conn.Receive, which can be called
// recursively to handle multi-part messages. | [
"receive",
"is",
"the",
"internal",
"implementation",
"of",
"Conn",
".",
"Receive",
"which",
"can",
"be",
"called",
"recursively",
"to",
"handle",
"multi",
"-",
"part",
"messages",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L274-L316 | train |
mdlayher/netlink | conn.go | JoinGroup | func (c *Conn) JoinGroup(group uint32) error {
conn, ok := c.sock.(groupJoinLeaver)
if !ok {
return notSupported("join-group")
}
return newOpError("join-group", conn.JoinGroup(group))
} | go | func (c *Conn) JoinGroup(group uint32) error {
conn, ok := c.sock.(groupJoinLeaver)
if !ok {
return notSupported("join-group")
}
return newOpError("join-group", conn.JoinGroup(group))
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"JoinGroup",
"(",
"group",
"uint32",
")",
"error",
"{",
"conn",
",",
"ok",
":=",
"c",
".",
"sock",
".",
"(",
"groupJoinLeaver",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"notSupported",
"(",
"\"",
"\"",
")",
"... | // JoinGroup joins a netlink multicast group by its ID. | [
"JoinGroup",
"joins",
"a",
"netlink",
"multicast",
"group",
"by",
"its",
"ID",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L327-L334 | train |
mdlayher/netlink | conn.go | SetBPF | func (c *Conn) SetBPF(filter []bpf.RawInstruction) error {
conn, ok := c.sock.(bpfSetter)
if !ok {
return notSupported("set-bpf")
}
return newOpError("set-bpf", conn.SetBPF(filter))
} | go | func (c *Conn) SetBPF(filter []bpf.RawInstruction) error {
conn, ok := c.sock.(bpfSetter)
if !ok {
return notSupported("set-bpf")
}
return newOpError("set-bpf", conn.SetBPF(filter))
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetBPF",
"(",
"filter",
"[",
"]",
"bpf",
".",
"RawInstruction",
")",
"error",
"{",
"conn",
",",
"ok",
":=",
"c",
".",
"sock",
".",
"(",
"bpfSetter",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"notSupported",
"... | // SetBPF attaches an assembled BPF program to a Conn. | [
"SetBPF",
"attaches",
"an",
"assembled",
"BPF",
"program",
"to",
"a",
"Conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L354-L361 | train |
mdlayher/netlink | conn.go | RemoveBPF | func (c *Conn) RemoveBPF() error {
conn, ok := c.sock.(bpfSetter)
if !ok {
return notSupported("remove-bpf")
}
return newOpError("remove-bpf", conn.RemoveBPF())
} | go | func (c *Conn) RemoveBPF() error {
conn, ok := c.sock.(bpfSetter)
if !ok {
return notSupported("remove-bpf")
}
return newOpError("remove-bpf", conn.RemoveBPF())
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"RemoveBPF",
"(",
")",
"error",
"{",
"conn",
",",
"ok",
":=",
"c",
".",
"sock",
".",
"(",
"bpfSetter",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"notSupported",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"retu... | // RemoveBPF removes a BPF filter from a Conn. | [
"RemoveBPF",
"removes",
"a",
"BPF",
"filter",
"from",
"a",
"Conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L364-L371 | train |
mdlayher/netlink | conn.go | SetDeadline | func (c *Conn) SetDeadline(t time.Time) error {
conn, ok := c.sock.(deadlineSetter)
if !ok {
return notSupported("set-deadline")
}
return newOpError("set-deadline", conn.SetDeadline(t))
} | go | func (c *Conn) SetDeadline(t time.Time) error {
conn, ok := c.sock.(deadlineSetter)
if !ok {
return notSupported("set-deadline")
}
return newOpError("set-deadline", conn.SetDeadline(t))
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SetDeadline",
"(",
"t",
"time",
".",
"Time",
")",
"error",
"{",
"conn",
",",
"ok",
":=",
"c",
".",
"sock",
".",
"(",
"deadlineSetter",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"notSupported",
"(",
"\"",
"\""... | // SetDeadline sets the read and write deadlines associated with the connection.
//
// Deadline functionality is only supported on Go 1.12+. Calling this function
// on older versions of Go will result in an error. | [
"SetDeadline",
"sets",
"the",
"read",
"and",
"write",
"deadlines",
"associated",
"with",
"the",
"connection",
".",
"Deadline",
"functionality",
"is",
"only",
"supported",
"on",
"Go",
"1",
".",
"12",
"+",
".",
"Calling",
"this",
"function",
"on",
"older",
"ve... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L385-L392 | train |
mdlayher/netlink | conn.go | fixMsg | func (c *Conn) fixMsg(m *Message, ml int) {
if m.Header.Length == 0 {
m.Header.Length = uint32(nlmsgAlign(ml))
}
if m.Header.Sequence == 0 {
m.Header.Sequence = c.nextSequence()
}
if m.Header.PID == 0 {
m.Header.PID = c.pid
}
} | go | func (c *Conn) fixMsg(m *Message, ml int) {
if m.Header.Length == 0 {
m.Header.Length = uint32(nlmsgAlign(ml))
}
if m.Header.Sequence == 0 {
m.Header.Sequence = c.nextSequence()
}
if m.Header.PID == 0 {
m.Header.PID = c.pid
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"fixMsg",
"(",
"m",
"*",
"Message",
",",
"ml",
"int",
")",
"{",
"if",
"m",
".",
"Header",
".",
"Length",
"==",
"0",
"{",
"m",
".",
"Header",
".",
"Length",
"=",
"uint32",
"(",
"nlmsgAlign",
"(",
"ml",
")",
... | // fixMsg updates the fields of m using the logic specified in Send. | [
"fixMsg",
"updates",
"the",
"fields",
"of",
"m",
"using",
"the",
"logic",
"specified",
"in",
"Send",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L513-L525 | train |
mdlayher/netlink | conn.go | Validate | func Validate(request Message, replies []Message) error {
for _, m := range replies {
// Check for mismatched sequence, unless:
// - request had no sequence, meaning we are probably validating
// a multicast reply
if m.Header.Sequence != request.Header.Sequence && request.Header.Sequence != 0 {
return... | go | func Validate(request Message, replies []Message) error {
for _, m := range replies {
// Check for mismatched sequence, unless:
// - request had no sequence, meaning we are probably validating
// a multicast reply
if m.Header.Sequence != request.Header.Sequence && request.Header.Sequence != 0 {
return... | [
"func",
"Validate",
"(",
"request",
"Message",
",",
"replies",
"[",
"]",
"Message",
")",
"error",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"replies",
"{",
"// Check for mismatched sequence, unless:",
"// - request had no sequence, meaning we are probably validating",
... | // Validate validates one or more reply Messages against a request Message,
// ensuring that they contain matching sequence numbers and PIDs. | [
"Validate",
"validates",
"one",
"or",
"more",
"reply",
"Messages",
"against",
"a",
"request",
"Message",
"ensuring",
"that",
"they",
"contain",
"matching",
"sequence",
"numbers",
"and",
"PIDs",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn.go#L535-L555 | train |
mdlayher/netlink | errors.go | IsNotExist | func IsNotExist(err error) bool {
switch err := err.(type) {
case *OpError:
// TODO(mdlayher): more error handling logic?
// Unwrap the inner error and use the stdlib's logic.
return os.IsNotExist(err.Err)
default:
return os.IsNotExist(err)
}
} | go | func IsNotExist(err error) bool {
switch err := err.(type) {
case *OpError:
// TODO(mdlayher): more error handling logic?
// Unwrap the inner error and use the stdlib's logic.
return os.IsNotExist(err.Err)
default:
return os.IsNotExist(err)
}
} | [
"func",
"IsNotExist",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"OpError",
":",
"// TODO(mdlayher): more error handling logic?",
"// Unwrap the inner error and use the stdlib's logic.",
"return",
"os"... | // IsNotExist determines if an error is produced as the result of querying some
// file, object, resource, etc. which does not exist. Users of this package
// should always use netlink.IsNotExist, rather than os.IsNotExist, when
// checking for specific netlink-related errors.
//
// Errors types created by this packag... | [
"IsNotExist",
"determines",
"if",
"an",
"error",
"is",
"produced",
"as",
"the",
"result",
"of",
"querying",
"some",
"file",
"object",
"resource",
"etc",
".",
"which",
"does",
"not",
"exist",
".",
"Users",
"of",
"this",
"package",
"should",
"always",
"use",
... | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/errors.go#L35-L45 | train |
mdlayher/netlink | errors.go | Temporary | func (e *OpError) Temporary() bool {
if ne, ok := e.Err.(*os.SyscallError); ok {
t, ok := ne.Err.(temporary)
return ok && t.Temporary()
}
t, ok := e.Err.(temporary)
return ok && t.Temporary()
} | go | func (e *OpError) Temporary() bool {
if ne, ok := e.Err.(*os.SyscallError); ok {
t, ok := ne.Err.(temporary)
return ok && t.Temporary()
}
t, ok := e.Err.(temporary)
return ok && t.Temporary()
} | [
"func",
"(",
"e",
"*",
"OpError",
")",
"Temporary",
"(",
")",
"bool",
"{",
"if",
"ne",
",",
"ok",
":=",
"e",
".",
"Err",
".",
"(",
"*",
"os",
".",
"SyscallError",
")",
";",
"ok",
"{",
"t",
",",
"ok",
":=",
"ne",
".",
"Err",
".",
"(",
"tempo... | // Temporary reports whether an operation may succeed if retried. | [
"Temporary",
"reports",
"whether",
"an",
"operation",
"may",
"succeed",
"if",
"retried",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/errors.go#L112-L119 | train |
mdlayher/netlink | netns_linux.go | setThreadNetNS | func setThreadNetNS(fd int) error {
return os.NewSyscallError("setns", unix.Setns(fd, unix.CLONE_NEWNET))
} | go | func setThreadNetNS(fd int) error {
return os.NewSyscallError("setns", unix.Setns(fd, unix.CLONE_NEWNET))
} | [
"func",
"setThreadNetNS",
"(",
"fd",
"int",
")",
"error",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"unix",
".",
"Setns",
"(",
"fd",
",",
"unix",
".",
"CLONE_NEWNET",
")",
")",
"\n",
"}"
] | // setThreadNetNS sets the network namespace of the thread of the current goroutine to
// the namespace described by the user-provided file descriptor. | [
"setThreadNetNS",
"sets",
"the",
"network",
"namespace",
"of",
"the",
"thread",
"of",
"the",
"current",
"goroutine",
"to",
"the",
"namespace",
"described",
"by",
"the",
"user",
"-",
"provided",
"file",
"descriptor",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/netns_linux.go#L25-L27 | train |
mdlayher/netlink | conn_linux.go | dial | func dial(family int, config *Config) (*conn, uint32, error) {
// Prepare sysSocket's internal loop and create the socket.
//
// The conditional is inverted because a zero value of false is desired
// if no config, but it's easier to interpret within this code when the
// value is inverted.
if config == nil {
c... | go | func dial(family int, config *Config) (*conn, uint32, error) {
// Prepare sysSocket's internal loop and create the socket.
//
// The conditional is inverted because a zero value of false is desired
// if no config, but it's easier to interpret within this code when the
// value is inverted.
if config == nil {
c... | [
"func",
"dial",
"(",
"family",
"int",
",",
"config",
"*",
"Config",
")",
"(",
"*",
"conn",
",",
"uint32",
",",
"error",
")",
"{",
"// Prepare sysSocket's internal loop and create the socket.",
"//",
"// The conditional is inverted because a zero value of false is desired",
... | // dial is the entry point for Dial. dial opens a netlink socket using
// system calls, and returns its PID. | [
"dial",
"is",
"the",
"entry",
"point",
"for",
"Dial",
".",
"dial",
"opens",
"a",
"netlink",
"socket",
"using",
"system",
"calls",
"and",
"returns",
"its",
"PID",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L49-L69 | train |
mdlayher/netlink | conn_linux.go | bind | func bind(s socket, config *Config) (*conn, uint32, error) {
if config == nil {
config = &Config{}
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
Groups: config.Groups,
}
// Socket must be closed in the event of any system call errors, to avoid
// leaking file descriptors.
if err := s.Bind(ad... | go | func bind(s socket, config *Config) (*conn, uint32, error) {
if config == nil {
config = &Config{}
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
Groups: config.Groups,
}
// Socket must be closed in the event of any system call errors, to avoid
// leaking file descriptors.
if err := s.Bind(ad... | [
"func",
"bind",
"(",
"s",
"socket",
",",
"config",
"*",
"Config",
")",
"(",
"*",
"conn",
",",
"uint32",
",",
"error",
")",
"{",
"if",
"config",
"==",
"nil",
"{",
"config",
"=",
"&",
"Config",
"{",
"}",
"\n",
"}",
"\n\n",
"addr",
":=",
"&",
"uni... | // bind binds a connection to netlink using the input socket, which may be
// a system call implementation or a mocked one for tests. | [
"bind",
"binds",
"a",
"connection",
"to",
"netlink",
"using",
"the",
"input",
"socket",
"which",
"may",
"be",
"a",
"system",
"call",
"implementation",
"or",
"a",
"mocked",
"one",
"for",
"tests",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L73-L103 | train |
mdlayher/netlink | conn_linux.go | SendMessages | func (c *conn) SendMessages(messages []Message) error {
var buf []byte
for _, m := range messages {
b, err := m.MarshalBinary()
if err != nil {
return err
}
buf = append(buf, b...)
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return os.NewSyscallError("sendmsg", c.s.Sendmsg(buf, nil... | go | func (c *conn) SendMessages(messages []Message) error {
var buf []byte
for _, m := range messages {
b, err := m.MarshalBinary()
if err != nil {
return err
}
buf = append(buf, b...)
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return os.NewSyscallError("sendmsg", c.s.Sendmsg(buf, nil... | [
"func",
"(",
"c",
"*",
"conn",
")",
"SendMessages",
"(",
"messages",
"[",
"]",
"Message",
")",
"error",
"{",
"var",
"buf",
"[",
"]",
"byte",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"messages",
"{",
"b",
",",
"err",
":=",
"m",
".",
"MarshalBina... | // SendMessages serializes multiple Messages and sends them to netlink. | [
"SendMessages",
"serializes",
"multiple",
"Messages",
"and",
"sends",
"them",
"to",
"netlink",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L106-L122 | train |
mdlayher/netlink | conn_linux.go | Send | func (c *conn) Send(m Message) error {
b, err := m.MarshalBinary()
if err != nil {
return err
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return os.NewSyscallError("sendmsg", c.s.Sendmsg(b, nil, addr, 0))
} | go | func (c *conn) Send(m Message) error {
b, err := m.MarshalBinary()
if err != nil {
return err
}
addr := &unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
}
return os.NewSyscallError("sendmsg", c.s.Sendmsg(b, nil, addr, 0))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"Send",
"(",
"m",
"Message",
")",
"error",
"{",
"b",
",",
"err",
":=",
"m",
".",
"MarshalBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"addr",
":=",
"&",
"unix",
... | // Send sends a single Message to netlink. | [
"Send",
"sends",
"a",
"single",
"Message",
"to",
"netlink",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L125-L136 | train |
mdlayher/netlink | conn_linux.go | Receive | func (c *conn) Receive() ([]Message, error) {
b := make([]byte, os.Getpagesize())
for {
// Peek at the buffer to see how many bytes are available.
//
// TODO(mdlayher): deal with OOB message data if available, such as
// when PacketInfo ConnOption is true.
n, _, _, _, err := c.s.Recvmsg(b, nil, unix.MSG_PEE... | go | func (c *conn) Receive() ([]Message, error) {
b := make([]byte, os.Getpagesize())
for {
// Peek at the buffer to see how many bytes are available.
//
// TODO(mdlayher): deal with OOB message data if available, such as
// when PacketInfo ConnOption is true.
n, _, _, _, err := c.s.Recvmsg(b, nil, unix.MSG_PEE... | [
"func",
"(",
"c",
"*",
"conn",
")",
"Receive",
"(",
")",
"(",
"[",
"]",
"Message",
",",
"error",
")",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"os",
".",
"Getpagesize",
"(",
")",
")",
"\n",
"for",
"{",
"// Peek at the buffer to see how m... | // Receive receives one or more Messages from netlink. | [
"Receive",
"receives",
"one",
"or",
"more",
"Messages",
"from",
"netlink",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L139-L184 | train |
mdlayher/netlink | conn_linux.go | JoinGroup | func (c *conn) JoinGroup(group uint32) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_NETLINK,
unix.NETLINK_ADD_MEMBERSHIP,
int(group),
))
} | go | func (c *conn) JoinGroup(group uint32) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_NETLINK,
unix.NETLINK_ADD_MEMBERSHIP,
int(group),
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"JoinGroup",
"(",
"group",
"uint32",
")",
"error",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"c",
".",
"s",
".",
"SetSockoptInt",
"(",
"unix",
".",
"SOL_NETLINK",
",",
"unix",
".",
"NETLINK... | // JoinGroup joins a multicast group by ID. | [
"JoinGroup",
"joins",
"a",
"multicast",
"group",
"by",
"ID",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L202-L208 | train |
mdlayher/netlink | conn_linux.go | LeaveGroup | func (c *conn) LeaveGroup(group uint32) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_NETLINK,
unix.NETLINK_DROP_MEMBERSHIP,
int(group),
))
} | go | func (c *conn) LeaveGroup(group uint32) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_NETLINK,
unix.NETLINK_DROP_MEMBERSHIP,
int(group),
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"LeaveGroup",
"(",
"group",
"uint32",
")",
"error",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"c",
".",
"s",
".",
"SetSockoptInt",
"(",
"unix",
".",
"SOL_NETLINK",
",",
"unix",
".",
"NETLIN... | // LeaveGroup leaves a multicast group by ID. | [
"LeaveGroup",
"leaves",
"a",
"multicast",
"group",
"by",
"ID",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L211-L217 | train |
mdlayher/netlink | conn_linux.go | SetBPF | func (c *conn) SetBPF(filter []bpf.RawInstruction) error {
prog := unix.SockFprog{
Len: uint16(len(filter)),
Filter: (*unix.SockFilter)(unsafe.Pointer(&filter[0])),
}
return os.NewSyscallError("setsockopt", c.s.SetSockoptSockFprog(
unix.SOL_SOCKET,
unix.SO_ATTACH_FILTER,
&prog,
))
} | go | func (c *conn) SetBPF(filter []bpf.RawInstruction) error {
prog := unix.SockFprog{
Len: uint16(len(filter)),
Filter: (*unix.SockFilter)(unsafe.Pointer(&filter[0])),
}
return os.NewSyscallError("setsockopt", c.s.SetSockoptSockFprog(
unix.SOL_SOCKET,
unix.SO_ATTACH_FILTER,
&prog,
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"SetBPF",
"(",
"filter",
"[",
"]",
"bpf",
".",
"RawInstruction",
")",
"error",
"{",
"prog",
":=",
"unix",
".",
"SockFprog",
"{",
"Len",
":",
"uint16",
"(",
"len",
"(",
"filter",
")",
")",
",",
"Filter",
":",
"(... | // SetBPF attaches an assembled BPF program to a conn. | [
"SetBPF",
"attaches",
"an",
"assembled",
"BPF",
"program",
"to",
"a",
"conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L220-L231 | train |
mdlayher/netlink | conn_linux.go | RemoveBPF | func (c *conn) RemoveBPF() error {
// 0 argument is ignored by SO_DETACH_FILTER.
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_SOCKET,
unix.SO_DETACH_FILTER,
0,
))
} | go | func (c *conn) RemoveBPF() error {
// 0 argument is ignored by SO_DETACH_FILTER.
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_SOCKET,
unix.SO_DETACH_FILTER,
0,
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"RemoveBPF",
"(",
")",
"error",
"{",
"// 0 argument is ignored by SO_DETACH_FILTER.",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"c",
".",
"s",
".",
"SetSockoptInt",
"(",
"unix",
".",
"SOL_SOCKET",
",",
... | // RemoveBPF removes a BPF filter from a conn. | [
"RemoveBPF",
"removes",
"a",
"BPF",
"filter",
"from",
"a",
"conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L234-L241 | train |
mdlayher/netlink | conn_linux.go | SetWriteBuffer | func (c *conn) SetWriteBuffer(bytes int) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_SOCKET,
unix.SO_SNDBUF,
bytes,
))
} | go | func (c *conn) SetWriteBuffer(bytes int) error {
return os.NewSyscallError("setsockopt", c.s.SetSockoptInt(
unix.SOL_SOCKET,
unix.SO_SNDBUF,
bytes,
))
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"SetWriteBuffer",
"(",
"bytes",
"int",
")",
"error",
"{",
"return",
"os",
".",
"NewSyscallError",
"(",
"\"",
"\"",
",",
"c",
".",
"s",
".",
"SetSockoptInt",
"(",
"unix",
".",
"SOL_SOCKET",
",",
"unix",
".",
"SO_SND... | // SetReadBuffer sets the size of the operating system's transmit buffer
// associated with the Conn. | [
"SetReadBuffer",
"sets",
"the",
"size",
"of",
"the",
"operating",
"system",
"s",
"transmit",
"buffer",
"associated",
"with",
"the",
"Conn",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L287-L293 | train |
mdlayher/netlink | conn_linux.go | linuxOption | func linuxOption(o ConnOption) (int, bool) {
switch o {
case PacketInfo:
return unix.NETLINK_PKTINFO, true
case BroadcastError:
return unix.NETLINK_BROADCAST_ERROR, true
case NoENOBUFS:
return unix.NETLINK_NO_ENOBUFS, true
case ListenAllNSID:
return unix.NETLINK_LISTEN_ALL_NSID, true
case CapAcknowledge:
... | go | func linuxOption(o ConnOption) (int, bool) {
switch o {
case PacketInfo:
return unix.NETLINK_PKTINFO, true
case BroadcastError:
return unix.NETLINK_BROADCAST_ERROR, true
case NoENOBUFS:
return unix.NETLINK_NO_ENOBUFS, true
case ListenAllNSID:
return unix.NETLINK_LISTEN_ALL_NSID, true
case CapAcknowledge:
... | [
"func",
"linuxOption",
"(",
"o",
"ConnOption",
")",
"(",
"int",
",",
"bool",
")",
"{",
"switch",
"o",
"{",
"case",
"PacketInfo",
":",
"return",
"unix",
".",
"NETLINK_PKTINFO",
",",
"true",
"\n",
"case",
"BroadcastError",
":",
"return",
"unix",
".",
"NETL... | // linuxOption converts a ConnOption to its Linux value. | [
"linuxOption",
"converts",
"a",
"ConnOption",
"to",
"its",
"Linux",
"value",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L296-L311 | train |
mdlayher/netlink | conn_linux.go | newSysSocket | func newSysSocket(config *Config) (*sysSocket, error) {
g, err := newLockedNetNSGoroutine(config.NetNS)
if err != nil {
return nil, err
}
return &sysSocket{
g: g,
}, nil
} | go | func newSysSocket(config *Config) (*sysSocket, error) {
g, err := newLockedNetNSGoroutine(config.NetNS)
if err != nil {
return nil, err
}
return &sysSocket{
g: g,
}, nil
} | [
"func",
"newSysSocket",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"sysSocket",
",",
"error",
")",
"{",
"g",
",",
"err",
":=",
"newLockedNetNSGoroutine",
"(",
"config",
".",
"NetNS",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"... | // newSysSocket creates a sysSocket that optionally locks its internal goroutine
// to a single thread. | [
"newSysSocket",
"creates",
"a",
"sysSocket",
"that",
"optionally",
"locks",
"its",
"internal",
"goroutine",
"to",
"a",
"single",
"thread",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L338-L346 | train |
mdlayher/netlink | conn_linux.go | do | func (s *sysSocket) do(f func()) error {
// All operations handled by this function are assumed to only
// read from s.done.
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
s.g.run(f)
return nil
} | go | func (s *sysSocket) do(f func()) error {
// All operations handled by this function are assumed to only
// read from s.done.
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
s.g.run(f)
return nil
} | [
"func",
"(",
"s",
"*",
"sysSocket",
")",
"do",
"(",
"f",
"func",
"(",
")",
")",
"error",
"{",
"// All operations handled by this function are assumed to only",
"// read from s.done.",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
"."... | // do runs f in a worker goroutine which can be locked to one thread. | [
"do",
"runs",
"f",
"in",
"a",
"worker",
"goroutine",
"which",
"can",
"be",
"locked",
"to",
"one",
"thread",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L349-L361 | train |
mdlayher/netlink | conn_linux.go | read | func (s *sysSocket) read(f func(fd int) bool) error {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
var err error
s.g.run(func() {
err = fdread(s.fd, f)
})
return err
} | go | func (s *sysSocket) read(f func(fd int) bool) error {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
var err error
s.g.run(func() {
err = fdread(s.fd, f)
})
return err
} | [
"func",
"(",
"s",
"*",
"sysSocket",
")",
"read",
"(",
"f",
"func",
"(",
"fd",
"int",
")",
"bool",
")",
"error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"c... | // read executes f, a read function, against the associated file descriptor. | [
"read",
"executes",
"f",
"a",
"read",
"function",
"against",
"the",
"associated",
"file",
"descriptor",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L364-L377 | train |
mdlayher/netlink | conn_linux.go | control | func (s *sysSocket) control(f func(fd int)) error {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
var err error
s.g.run(func() {
err = fdcontrol(s.fd, f)
})
return err
} | go | func (s *sysSocket) control(f func(fd int)) error {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return syscall.EBADF
}
var err error
s.g.run(func() {
err = fdcontrol(s.fd, f)
})
return err
} | [
"func",
"(",
"s",
"*",
"sysSocket",
")",
"control",
"(",
"f",
"func",
"(",
"fd",
"int",
")",
")",
"error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"closed",... | // control executes f, a control function, against the associated file descriptor. | [
"control",
"executes",
"f",
"a",
"control",
"function",
"against",
"the",
"associated",
"file",
"descriptor",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L396-L409 | train |
mdlayher/netlink | conn_linux.go | run | func (g *lockedNetNSGoroutine) run(f func()) {
done := make(chan struct{})
g.funcC <- func() {
defer close(done)
f()
}
<-done
} | go | func (g *lockedNetNSGoroutine) run(f func()) {
done := make(chan struct{})
g.funcC <- func() {
defer close(done)
f()
}
<-done
} | [
"func",
"(",
"g",
"*",
"lockedNetNSGoroutine",
")",
"run",
"(",
"f",
"func",
"(",
")",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"g",
".",
"funcC",
"<-",
"func",
"(",
")",
"{",
"defer",
"close",
"(",
"done",
")... | // run runs f on the worker goroutine. | [
"run",
"runs",
"f",
"on",
"the",
"worker",
"goroutine",
"."
] | b540351f6c5108aa445eaa6677010703c7294f8d | https://github.com/mdlayher/netlink/blob/b540351f6c5108aa445eaa6677010703c7294f8d/conn_linux.go#L670-L677 | train |
looplab/eventhorizon | repo/version/repo.go | Find | func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error) {
// If there is no min version set just return the item as normally.
minVersion, ok := eh.MinVersionFromContext(ctx)
if !ok || minVersion < 1 {
return r.ReadWriteRepo.Find(ctx, id)
}
// Try to get the correct version, retry with exponent... | go | func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error) {
// If there is no min version set just return the item as normally.
minVersion, ok := eh.MinVersionFromContext(ctx)
if !ok || minVersion < 1 {
return r.ReadWriteRepo.Find(ctx, id)
}
// Try to get the correct version, retry with exponent... | [
"func",
"(",
"r",
"*",
"Repo",
")",
"Find",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"uuid",
".",
"UUID",
")",
"(",
"eh",
".",
"Entity",
",",
"error",
")",
"{",
"// If there is no min version set just return the item as normally.",
"minVersion",
",",
... | // Find implements the Find method of the eventhorizon.ReadModel interface.
// If the context contains a min version set by WithMinVersion it will only
// return an item if its version is at least min version. If a timeout or
// deadline is set on the context it will repetedly try to get the item until
// either the ve... | [
"Find",
"implements",
"the",
"Find",
"method",
"of",
"the",
"eventhorizon",
".",
"ReadModel",
"interface",
".",
"If",
"the",
"context",
"contains",
"a",
"min",
"version",
"set",
"by",
"WithMinVersion",
"it",
"will",
"only",
"return",
"an",
"item",
"if",
"its... | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/version/repo.go#L48-L83 | train |
looplab/eventhorizon | repo/version/repo.go | findMinVersion | func (r *Repo) findMinVersion(ctx context.Context, id uuid.UUID, minVersion int) (eh.Entity, error) {
entity, err := r.ReadWriteRepo.Find(ctx, id)
if err != nil {
return nil, err
}
versionable, ok := entity.(eh.Versionable)
if !ok {
return nil, eh.RepoError{
Err: eh.ErrEntityHasNoVersion,
Namespac... | go | func (r *Repo) findMinVersion(ctx context.Context, id uuid.UUID, minVersion int) (eh.Entity, error) {
entity, err := r.ReadWriteRepo.Find(ctx, id)
if err != nil {
return nil, err
}
versionable, ok := entity.(eh.Versionable)
if !ok {
return nil, eh.RepoError{
Err: eh.ErrEntityHasNoVersion,
Namespac... | [
"func",
"(",
"r",
"*",
"Repo",
")",
"findMinVersion",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"uuid",
".",
"UUID",
",",
"minVersion",
"int",
")",
"(",
"eh",
".",
"Entity",
",",
"error",
")",
"{",
"entity",
",",
"err",
":=",
"r",
".",
"R... | // findMinVersion finds an item if it has a version and it is at least minVersion. | [
"findMinVersion",
"finds",
"an",
"item",
"if",
"it",
"has",
"a",
"version",
"and",
"it",
"is",
"at",
"least",
"minVersion",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/version/repo.go#L86-L108 | train |
looplab/eventhorizon | repo/version/repo.go | Repository | func Repository(repo eh.ReadRepo) *Repo {
if repo == nil {
return nil
}
if r, ok := repo.(*Repo); ok {
return r
}
return Repository(repo.Parent())
} | go | func Repository(repo eh.ReadRepo) *Repo {
if repo == nil {
return nil
}
if r, ok := repo.(*Repo); ok {
return r
}
return Repository(repo.Parent())
} | [
"func",
"Repository",
"(",
"repo",
"eh",
".",
"ReadRepo",
")",
"*",
"Repo",
"{",
"if",
"repo",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"r",
",",
"ok",
":=",
"repo",
".",
"(",
"*",
"Repo",
")",
";",
"ok",
"{",
"return",
"r",
... | // Repository returns a parent ReadRepo if there is one. | [
"Repository",
"returns",
"a",
"parent",
"ReadRepo",
"if",
"there",
"is",
"one",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/version/repo.go#L111-L121 | train |
looplab/eventhorizon | repo/mongodb/repo.go | NewRepoWithSession | func NewRepoWithSession(session *mgo.Session, dbPrefix, collection string) (*Repo, error) {
if session == nil {
return nil, ErrNoDBSession
}
r := &Repo{
session: session,
dbPrefix: dbPrefix,
collection: collection,
}
return r, nil
} | go | func NewRepoWithSession(session *mgo.Session, dbPrefix, collection string) (*Repo, error) {
if session == nil {
return nil, ErrNoDBSession
}
r := &Repo{
session: session,
dbPrefix: dbPrefix,
collection: collection,
}
return r, nil
} | [
"func",
"NewRepoWithSession",
"(",
"session",
"*",
"mgo",
".",
"Session",
",",
"dbPrefix",
",",
"collection",
"string",
")",
"(",
"*",
"Repo",
",",
"error",
")",
"{",
"if",
"session",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNoDBSession",
"\n",
"}",
... | // NewRepoWithSession creates a new Repo with a session. | [
"NewRepoWithSession",
"creates",
"a",
"new",
"Repo",
"with",
"a",
"session",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/mongodb/repo.go#L64-L76 | train |
looplab/eventhorizon | repo/mongodb/repo.go | FindCustomIter | func (r *Repo) FindCustomIter(ctx context.Context, callback func(*mgo.Collection) *mgo.Query) (eh.Iter, error) {
sess := r.session.Copy()
if r.factoryFn == nil {
return nil, eh.RepoError{
Err: ErrModelNotSet,
Namespace: eh.NamespaceFromContext(ctx),
}
}
collection := sess.DB(r.dbName(ctx)).C(r.col... | go | func (r *Repo) FindCustomIter(ctx context.Context, callback func(*mgo.Collection) *mgo.Query) (eh.Iter, error) {
sess := r.session.Copy()
if r.factoryFn == nil {
return nil, eh.RepoError{
Err: ErrModelNotSet,
Namespace: eh.NamespaceFromContext(ctx),
}
}
collection := sess.DB(r.dbName(ctx)).C(r.col... | [
"func",
"(",
"r",
"*",
"Repo",
")",
"FindCustomIter",
"(",
"ctx",
"context",
".",
"Context",
",",
"callback",
"func",
"(",
"*",
"mgo",
".",
"Collection",
")",
"*",
"mgo",
".",
"Query",
")",
"(",
"eh",
".",
"Iter",
",",
"error",
")",
"{",
"sess",
... | // FindCustomIter returns a mgo cursor you can use to stream results of very large datasets | [
"FindCustomIter",
"returns",
"a",
"mgo",
"cursor",
"you",
"can",
"use",
"to",
"stream",
"results",
"of",
"very",
"large",
"datasets"
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/mongodb/repo.go#L163-L187 | train |
looplab/eventhorizon | repo/mongodb/repo.go | FindCustom | func (r *Repo) FindCustom(ctx context.Context, callback func(*mgo.Collection) *mgo.Query) ([]interface{}, error) {
sess := r.session.Copy()
defer sess.Close()
if r.factoryFn == nil {
return nil, eh.RepoError{
Err: ErrModelNotSet,
Namespace: eh.NamespaceFromContext(ctx),
}
}
collection := sess.DB(... | go | func (r *Repo) FindCustom(ctx context.Context, callback func(*mgo.Collection) *mgo.Query) ([]interface{}, error) {
sess := r.session.Copy()
defer sess.Close()
if r.factoryFn == nil {
return nil, eh.RepoError{
Err: ErrModelNotSet,
Namespace: eh.NamespaceFromContext(ctx),
}
}
collection := sess.DB(... | [
"func",
"(",
"r",
"*",
"Repo",
")",
"FindCustom",
"(",
"ctx",
"context",
".",
"Context",
",",
"callback",
"func",
"(",
"*",
"mgo",
".",
"Collection",
")",
"*",
"mgo",
".",
"Query",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{"... | // FindCustom uses a callback to specify a custom query for returning models.
// It can also be used to do queries that does not map to the model by executing
// the query in the callback and returning nil to block a second execution of
// the same query in FindCustom. Expect a ErrInvalidQuery if returning a nil
// que... | [
"FindCustom",
"uses",
"a",
"callback",
"to",
"specify",
"a",
"custom",
"query",
"for",
"returning",
"models",
".",
"It",
"can",
"also",
"be",
"used",
"to",
"do",
"queries",
"that",
"does",
"not",
"map",
"to",
"the",
"model",
"by",
"executing",
"the",
"qu... | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/mongodb/repo.go#L194-L229 | train |
looplab/eventhorizon | repo/mongodb/repo.go | Collection | func (r *Repo) Collection(ctx context.Context, f func(*mgo.Collection) error) error {
sess := r.session.Copy()
defer sess.Close()
c := sess.DB(r.dbName(ctx)).C(r.collection)
if err := f(c); err != nil {
return eh.RepoError{
Err: err,
Namespace: eh.NamespaceFromContext(ctx),
}
}
return nil
} | go | func (r *Repo) Collection(ctx context.Context, f func(*mgo.Collection) error) error {
sess := r.session.Copy()
defer sess.Close()
c := sess.DB(r.dbName(ctx)).C(r.collection)
if err := f(c); err != nil {
return eh.RepoError{
Err: err,
Namespace: eh.NamespaceFromContext(ctx),
}
}
return nil
} | [
"func",
"(",
"r",
"*",
"Repo",
")",
"Collection",
"(",
"ctx",
"context",
".",
"Context",
",",
"f",
"func",
"(",
"*",
"mgo",
".",
"Collection",
")",
"error",
")",
"error",
"{",
"sess",
":=",
"r",
".",
"session",
".",
"Copy",
"(",
")",
"\n",
"defer... | // Collection lets the function do custom actions on the collection. | [
"Collection",
"lets",
"the",
"function",
"do",
"custom",
"actions",
"on",
"the",
"collection",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/mongodb/repo.go#L273-L286 | train |
looplab/eventhorizon | repo/mongodb/repo.go | Clear | func (r *Repo) Clear(ctx context.Context) error {
if err := r.session.DB(r.dbName(ctx)).C(r.collection).DropCollection(); err != nil {
return eh.RepoError{
Err: ErrCouldNotClearDB,
BaseErr: err,
Namespace: eh.NamespaceFromContext(ctx),
}
}
return nil
} | go | func (r *Repo) Clear(ctx context.Context) error {
if err := r.session.DB(r.dbName(ctx)).C(r.collection).DropCollection(); err != nil {
return eh.RepoError{
Err: ErrCouldNotClearDB,
BaseErr: err,
Namespace: eh.NamespaceFromContext(ctx),
}
}
return nil
} | [
"func",
"(",
"r",
"*",
"Repo",
")",
"Clear",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"err",
":=",
"r",
".",
"session",
".",
"DB",
"(",
"r",
".",
"dbName",
"(",
"ctx",
")",
")",
".",
"C",
"(",
"r",
".",
"collection",
")... | // Clear clears the read model database. | [
"Clear",
"clears",
"the",
"read",
"model",
"database",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/mongodb/repo.go#L294-L303 | train |
looplab/eventhorizon | context.go | NamespaceFromContext | func NamespaceFromContext(ctx context.Context) string {
if ns, ok := ctx.Value(namespaceKey).(string); ok {
return ns
}
return DefaultNamespace
} | go | func NamespaceFromContext(ctx context.Context) string {
if ns, ok := ctx.Value(namespaceKey).(string); ok {
return ns
}
return DefaultNamespace
} | [
"func",
"NamespaceFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"string",
"{",
"if",
"ns",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"namespaceKey",
")",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"ns",
"\n",
"}",
"\n",
"return",... | // NamespaceFromContext returns the namespace from the context, or the default
// namespace. | [
"NamespaceFromContext",
"returns",
"the",
"namespace",
"from",
"the",
"context",
"or",
"the",
"default",
"namespace",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L78-L83 | train |
looplab/eventhorizon | context.go | NewContextWithNamespace | func NewContextWithNamespace(ctx context.Context, namespace string) context.Context {
return context.WithValue(ctx, namespaceKey, namespace)
} | go | func NewContextWithNamespace(ctx context.Context, namespace string) context.Context {
return context.WithValue(ctx, namespaceKey, namespace)
} | [
"func",
"NewContextWithNamespace",
"(",
"ctx",
"context",
".",
"Context",
",",
"namespace",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"namespaceKey",
",",
"namespace",
")",
"\n",
"}"
] | // NewContextWithNamespace sets the namespace to use in the context. The
// namespace is used to determine which database. | [
"NewContextWithNamespace",
"sets",
"the",
"namespace",
"to",
"use",
"in",
"the",
"context",
".",
"The",
"namespace",
"is",
"used",
"to",
"determine",
"which",
"database",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L87-L89 | train |
looplab/eventhorizon | context.go | MinVersionFromContext | func MinVersionFromContext(ctx context.Context) (int, bool) {
minVersion, ok := ctx.Value(minVersionKey).(int)
return minVersion, ok
} | go | func MinVersionFromContext(ctx context.Context) (int, bool) {
minVersion, ok := ctx.Value(minVersionKey).(int)
return minVersion, ok
} | [
"func",
"MinVersionFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"int",
",",
"bool",
")",
"{",
"minVersion",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"minVersionKey",
")",
".",
"(",
"int",
")",
"\n",
"return",
"minVersion",
",",
"ok"... | // MinVersionFromContext returns the min version from the context. | [
"MinVersionFromContext",
"returns",
"the",
"min",
"version",
"from",
"the",
"context",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L92-L95 | train |
looplab/eventhorizon | context.go | NewContextWithMinVersion | func NewContextWithMinVersion(ctx context.Context, minVersion int) context.Context {
return context.WithValue(ctx, minVersionKey, minVersion)
} | go | func NewContextWithMinVersion(ctx context.Context, minVersion int) context.Context {
return context.WithValue(ctx, minVersionKey, minVersion)
} | [
"func",
"NewContextWithMinVersion",
"(",
"ctx",
"context",
".",
"Context",
",",
"minVersion",
"int",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"minVersionKey",
",",
"minVersion",
")",
"\n",
"}"
] | // NewContextWithMinVersion returns the context with min version set. | [
"NewContextWithMinVersion",
"returns",
"the",
"context",
"with",
"min",
"version",
"set",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L98-L100 | train |
looplab/eventhorizon | context.go | NewContextWithMinVersionWait | func NewContextWithMinVersionWait(ctx context.Context, minVersion int) (c context.Context, cancel func()) {
ctx = context.WithValue(ctx, minVersionKey, minVersion)
return context.WithTimeout(ctx, DefaultMinVersionDeadline)
} | go | func NewContextWithMinVersionWait(ctx context.Context, minVersion int) (c context.Context, cancel func()) {
ctx = context.WithValue(ctx, minVersionKey, minVersion)
return context.WithTimeout(ctx, DefaultMinVersionDeadline)
} | [
"func",
"NewContextWithMinVersionWait",
"(",
"ctx",
"context",
".",
"Context",
",",
"minVersion",
"int",
")",
"(",
"c",
"context",
".",
"Context",
",",
"cancel",
"func",
"(",
")",
")",
"{",
"ctx",
"=",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"minVe... | // NewContextWithMinVersionWait returns the context with min version and a
// default deadline set. | [
"NewContextWithMinVersionWait",
"returns",
"the",
"context",
"with",
"min",
"version",
"and",
"a",
"default",
"deadline",
"set",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L104-L107 | train |
looplab/eventhorizon | context.go | RegisterContextMarshaler | func RegisterContextMarshaler(f ContextMarshalFunc) {
contextMarshalFuncsMu.Lock()
defer contextMarshalFuncsMu.Unlock()
contextMarshalFuncs = append(contextMarshalFuncs, f)
} | go | func RegisterContextMarshaler(f ContextMarshalFunc) {
contextMarshalFuncsMu.Lock()
defer contextMarshalFuncsMu.Unlock()
contextMarshalFuncs = append(contextMarshalFuncs, f)
} | [
"func",
"RegisterContextMarshaler",
"(",
"f",
"ContextMarshalFunc",
")",
"{",
"contextMarshalFuncsMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"contextMarshalFuncsMu",
".",
"Unlock",
"(",
")",
"\n",
"contextMarshalFuncs",
"=",
"append",
"(",
"contextMarshalFuncs",
","... | // RegisterContextMarshaler registers a marshaler function used by MarshalContext. | [
"RegisterContextMarshaler",
"registers",
"a",
"marshaler",
"function",
"used",
"by",
"MarshalContext",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L123-L127 | train |
looplab/eventhorizon | context.go | MarshalContext | func MarshalContext(ctx context.Context) map[string]interface{} {
contextMarshalFuncsMu.RLock()
defer contextMarshalFuncsMu.RUnlock()
allVals := map[string]interface{}{}
for _, f := range contextMarshalFuncs {
vals := map[string]interface{}{}
f(ctx, vals)
for key, val := range vals {
if _, ok := allVals... | go | func MarshalContext(ctx context.Context) map[string]interface{} {
contextMarshalFuncsMu.RLock()
defer contextMarshalFuncsMu.RUnlock()
allVals := map[string]interface{}{}
for _, f := range contextMarshalFuncs {
vals := map[string]interface{}{}
f(ctx, vals)
for key, val := range vals {
if _, ok := allVals... | [
"func",
"MarshalContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"contextMarshalFuncsMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"contextMarshalFuncsMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"allVals",... | // MarshalContext marshals a context into a map. | [
"MarshalContext",
"marshals",
"a",
"context",
"into",
"a",
"map",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L130-L149 | train |
looplab/eventhorizon | context.go | RegisterContextUnmarshaler | func RegisterContextUnmarshaler(f ContextUnmarshalFunc) {
contextUnmarshalFuncsMu.Lock()
defer contextUnmarshalFuncsMu.Unlock()
contextUnmarshalFuncs = append(contextUnmarshalFuncs, f)
} | go | func RegisterContextUnmarshaler(f ContextUnmarshalFunc) {
contextUnmarshalFuncsMu.Lock()
defer contextUnmarshalFuncsMu.Unlock()
contextUnmarshalFuncs = append(contextUnmarshalFuncs, f)
} | [
"func",
"RegisterContextUnmarshaler",
"(",
"f",
"ContextUnmarshalFunc",
")",
"{",
"contextUnmarshalFuncsMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"contextUnmarshalFuncsMu",
".",
"Unlock",
"(",
")",
"\n",
"contextUnmarshalFuncs",
"=",
"append",
"(",
"contextUnmarshalF... | // RegisterContextUnmarshaler registers a marshaler function used by UnmarshalContext. | [
"RegisterContextUnmarshaler",
"registers",
"a",
"marshaler",
"function",
"used",
"by",
"UnmarshalContext",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L156-L160 | train |
looplab/eventhorizon | context.go | UnmarshalContext | func UnmarshalContext(vals map[string]interface{}) context.Context {
contextUnmarshalFuncsMu.RLock()
defer contextUnmarshalFuncsMu.RUnlock()
ctx := context.Background()
if vals == nil {
return ctx
}
for _, f := range contextUnmarshalFuncs {
ctx = f(ctx, vals)
}
return ctx
} | go | func UnmarshalContext(vals map[string]interface{}) context.Context {
contextUnmarshalFuncsMu.RLock()
defer contextUnmarshalFuncsMu.RUnlock()
ctx := context.Background()
if vals == nil {
return ctx
}
for _, f := range contextUnmarshalFuncs {
ctx = f(ctx, vals)
}
return ctx
} | [
"func",
"UnmarshalContext",
"(",
"vals",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"context",
".",
"Context",
"{",
"contextUnmarshalFuncsMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"contextUnmarshalFuncsMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"ct... | // UnmarshalContext unmarshals a context from a map. | [
"UnmarshalContext",
"unmarshals",
"a",
"context",
"from",
"a",
"map",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/context.go#L163-L177 | train |
looplab/eventhorizon | middleware/commandhandler/validator/commandhandler.go | NewMiddleware | func NewMiddleware() eh.CommandHandlerMiddleware {
return eh.CommandHandlerMiddleware(func(h eh.CommandHandler) eh.CommandHandler {
return eh.CommandHandlerFunc(func(ctx context.Context, cmd eh.Command) error {
// Call the validation method if it exists
if c, ok := cmd.(Command); ok {
err := c.Validate()
... | go | func NewMiddleware() eh.CommandHandlerMiddleware {
return eh.CommandHandlerMiddleware(func(h eh.CommandHandler) eh.CommandHandler {
return eh.CommandHandlerFunc(func(ctx context.Context, cmd eh.Command) error {
// Call the validation method if it exists
if c, ok := cmd.(Command); ok {
err := c.Validate()
... | [
"func",
"NewMiddleware",
"(",
")",
"eh",
".",
"CommandHandlerMiddleware",
"{",
"return",
"eh",
".",
"CommandHandlerMiddleware",
"(",
"func",
"(",
"h",
"eh",
".",
"CommandHandler",
")",
"eh",
".",
"CommandHandler",
"{",
"return",
"eh",
".",
"CommandHandlerFunc",
... | // NewMiddleware returns a new async handling middleware that validate commands
// with its own validation method. | [
"NewMiddleware",
"returns",
"a",
"new",
"async",
"handling",
"middleware",
"that",
"validate",
"commands",
"with",
"its",
"own",
"validation",
"method",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/middleware/commandhandler/validator/commandhandler.go#L25-L40 | train |
looplab/eventhorizon | middleware/commandhandler/validator/commandhandler.go | CommandWithValidation | func CommandWithValidation(cmd eh.Command, v func() error) Command {
return &command{Command: cmd, validate: v}
} | go | func CommandWithValidation(cmd eh.Command, v func() error) Command {
return &command{Command: cmd, validate: v}
} | [
"func",
"CommandWithValidation",
"(",
"cmd",
"eh",
".",
"Command",
",",
"v",
"func",
"(",
")",
"error",
")",
"Command",
"{",
"return",
"&",
"command",
"{",
"Command",
":",
"cmd",
",",
"validate",
":",
"v",
"}",
"\n",
"}"
] | // CommandWithValidation returns a wrapped command with a validation method. | [
"CommandWithValidation",
"returns",
"a",
"wrapped",
"command",
"with",
"a",
"validation",
"method",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/middleware/commandhandler/validator/commandhandler.go#L51-L53 | train |
looplab/eventhorizon | mocks/mocks.go | NewAggregate | func NewAggregate(id uuid.UUID) *Aggregate {
return &Aggregate{
ID: id,
Commands: []eh.Command{},
}
} | go | func NewAggregate(id uuid.UUID) *Aggregate {
return &Aggregate{
ID: id,
Commands: []eh.Command{},
}
} | [
"func",
"NewAggregate",
"(",
"id",
"uuid",
".",
"UUID",
")",
"*",
"Aggregate",
"{",
"return",
"&",
"Aggregate",
"{",
"ID",
":",
"id",
",",
"Commands",
":",
"[",
"]",
"eh",
".",
"Command",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewAggregate returns a new Aggregate. | [
"NewAggregate",
"returns",
"a",
"new",
"Aggregate",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L66-L71 | train |
looplab/eventhorizon | mocks/mocks.go | HandleCommand | func (a *Aggregate) HandleCommand(ctx context.Context, cmd eh.Command) error {
if a.Err != nil {
return a.Err
}
a.Commands = append(a.Commands, cmd)
a.Context = ctx
return nil
} | go | func (a *Aggregate) HandleCommand(ctx context.Context, cmd eh.Command) error {
if a.Err != nil {
return a.Err
}
a.Commands = append(a.Commands, cmd)
a.Context = ctx
return nil
} | [
"func",
"(",
"a",
"*",
"Aggregate",
")",
"HandleCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"eh",
".",
"Command",
")",
"error",
"{",
"if",
"a",
".",
"Err",
"!=",
"nil",
"{",
"return",
"a",
".",
"Err",
"\n",
"}",
"\n",
"a",
".",
... | // HandleCommand implements the HandleCommand method of the eventhorizon.Aggregate interface. | [
"HandleCommand",
"implements",
"the",
"HandleCommand",
"method",
"of",
"the",
"eventhorizon",
".",
"Aggregate",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L86-L93 | train |
looplab/eventhorizon | mocks/mocks.go | Reset | func (m *EventHandler) Reset() {
m.Events = []eh.Event{}
m.Context = context.Background()
m.Time = time.Time{}
} | go | func (m *EventHandler) Reset() {
m.Events = []eh.Event{}
m.Context = context.Background()
m.Time = time.Time{}
} | [
"func",
"(",
"m",
"*",
"EventHandler",
")",
"Reset",
"(",
")",
"{",
"m",
".",
"Events",
"=",
"[",
"]",
"eh",
".",
"Event",
"{",
"}",
"\n",
"m",
".",
"Context",
"=",
"context",
".",
"Background",
"(",
")",
"\n",
"m",
".",
"Time",
"=",
"time",
... | // Reset resets the mock data. | [
"Reset",
"resets",
"the",
"mock",
"data",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L231-L235 | train |
looplab/eventhorizon | mocks/mocks.go | Wait | func (m *EventHandler) Wait(d time.Duration) bool {
select {
case <-m.Recv:
return true
case <-time.After(d):
return false
}
} | go | func (m *EventHandler) Wait(d time.Duration) bool {
select {
case <-m.Recv:
return true
case <-time.After(d):
return false
}
} | [
"func",
"(",
"m",
"*",
"EventHandler",
")",
"Wait",
"(",
"d",
"time",
".",
"Duration",
")",
"bool",
"{",
"select",
"{",
"case",
"<-",
"m",
".",
"Recv",
":",
"return",
"true",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"d",
")",
":",
"return",... | // Wait is a helper to wait some duration until for an event to be handled. | [
"Wait",
"is",
"a",
"helper",
"to",
"wait",
"some",
"duration",
"until",
"for",
"an",
"event",
"to",
"be",
"handled",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L238-L245 | train |
looplab/eventhorizon | mocks/mocks.go | Load | func (m *AggregateStore) Load(ctx context.Context, aggregateType eh.AggregateType, id uuid.UUID) (eh.Aggregate, error) {
if m.Err != nil {
return nil, m.Err
}
m.Context = ctx
return m.Aggregates[id], nil
} | go | func (m *AggregateStore) Load(ctx context.Context, aggregateType eh.AggregateType, id uuid.UUID) (eh.Aggregate, error) {
if m.Err != nil {
return nil, m.Err
}
m.Context = ctx
return m.Aggregates[id], nil
} | [
"func",
"(",
"m",
"*",
"AggregateStore",
")",
"Load",
"(",
"ctx",
"context",
".",
"Context",
",",
"aggregateType",
"eh",
".",
"AggregateType",
",",
"id",
"uuid",
".",
"UUID",
")",
"(",
"eh",
".",
"Aggregate",
",",
"error",
")",
"{",
"if",
"m",
".",
... | // Load implements the Load method of the eventhorizon.AggregateStore interface. | [
"Load",
"implements",
"the",
"Load",
"method",
"of",
"the",
"eventhorizon",
".",
"AggregateStore",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L258-L264 | train |
looplab/eventhorizon | mocks/mocks.go | Save | func (m *AggregateStore) Save(ctx context.Context, aggregate eh.Aggregate) error {
if m.Err != nil {
return m.Err
}
m.Context = ctx
m.Aggregates[aggregate.EntityID()] = aggregate
return nil
} | go | func (m *AggregateStore) Save(ctx context.Context, aggregate eh.Aggregate) error {
if m.Err != nil {
return m.Err
}
m.Context = ctx
m.Aggregates[aggregate.EntityID()] = aggregate
return nil
} | [
"func",
"(",
"m",
"*",
"AggregateStore",
")",
"Save",
"(",
"ctx",
"context",
".",
"Context",
",",
"aggregate",
"eh",
".",
"Aggregate",
")",
"error",
"{",
"if",
"m",
".",
"Err",
"!=",
"nil",
"{",
"return",
"m",
".",
"Err",
"\n",
"}",
"\n",
"m",
".... | // Save implements the Save method of the eventhorizon.AggregateStore interface. | [
"Save",
"implements",
"the",
"Save",
"method",
"of",
"the",
"eventhorizon",
".",
"AggregateStore",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L267-L274 | train |
looplab/eventhorizon | mocks/mocks.go | Save | func (r *Repo) Save(ctx context.Context, entity eh.Entity) error {
r.SaveCalled = true
if r.SaveErr != nil {
return r.SaveErr
}
r.Entity = entity
return nil
} | go | func (r *Repo) Save(ctx context.Context, entity eh.Entity) error {
r.SaveCalled = true
if r.SaveErr != nil {
return r.SaveErr
}
r.Entity = entity
return nil
} | [
"func",
"(",
"r",
"*",
"Repo",
")",
"Save",
"(",
"ctx",
"context",
".",
"Context",
",",
"entity",
"eh",
".",
"Entity",
")",
"error",
"{",
"r",
".",
"SaveCalled",
"=",
"true",
"\n",
"if",
"r",
".",
"SaveErr",
"!=",
"nil",
"{",
"return",
"r",
".",
... | // Save implements the Save method of the eventhorizon.ReadRepo interface. | [
"Save",
"implements",
"the",
"Save",
"method",
"of",
"the",
"eventhorizon",
".",
"ReadRepo",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L387-L394 | train |
looplab/eventhorizon | mocks/mocks.go | Remove | func (r *Repo) Remove(ctx context.Context, id uuid.UUID) error {
r.RemoveCalled = true
if r.SaveErr != nil {
return r.SaveErr
}
r.Entity = nil
return nil
} | go | func (r *Repo) Remove(ctx context.Context, id uuid.UUID) error {
r.RemoveCalled = true
if r.SaveErr != nil {
return r.SaveErr
}
r.Entity = nil
return nil
} | [
"func",
"(",
"r",
"*",
"Repo",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"uuid",
".",
"UUID",
")",
"error",
"{",
"r",
".",
"RemoveCalled",
"=",
"true",
"\n",
"if",
"r",
".",
"SaveErr",
"!=",
"nil",
"{",
"return",
"r",
".",
... | // Remove implements the Remove method of the eventhorizon.ReadRepo interface. | [
"Remove",
"implements",
"the",
"Remove",
"method",
"of",
"the",
"eventhorizon",
".",
"ReadRepo",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L397-L404 | train |
looplab/eventhorizon | mocks/mocks.go | WithContextOne | func WithContextOne(ctx context.Context, val string) context.Context {
return context.WithValue(ctx, contextKeyOne, val)
} | go | func WithContextOne(ctx context.Context, val string) context.Context {
return context.WithValue(ctx, contextKeyOne, val)
} | [
"func",
"WithContextOne",
"(",
"ctx",
"context",
".",
"Context",
",",
"val",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"contextKeyOne",
",",
"val",
")",
"\n",
"}"
] | // WithContextOne sets a value for One one the context. | [
"WithContextOne",
"sets",
"a",
"value",
"for",
"One",
"one",
"the",
"context",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L413-L415 | train |
looplab/eventhorizon | mocks/mocks.go | ContextOne | func ContextOne(ctx context.Context) (string, bool) {
val, ok := ctx.Value(contextKeyOne).(string)
return val, ok
} | go | func ContextOne(ctx context.Context) (string, bool) {
val, ok := ctx.Value(contextKeyOne).(string)
return val, ok
} | [
"func",
"ContextOne",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"string",
",",
"bool",
")",
"{",
"val",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"contextKeyOne",
")",
".",
"(",
"string",
")",
"\n",
"return",
"val",
",",
"ok",
"\n",
"}"
] | // ContextOne returns a value for One from the context. | [
"ContextOne",
"returns",
"a",
"value",
"for",
"One",
"from",
"the",
"context",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L418-L421 | train |
looplab/eventhorizon | mocks/mocks.go | init | func init() {
eh.RegisterContextMarshaler(func(ctx context.Context, vals map[string]interface{}) {
if val, ok := ContextOne(ctx); ok {
vals[contextKeyOneStr] = val
}
})
eh.RegisterContextUnmarshaler(func(ctx context.Context, vals map[string]interface{}) context.Context {
if val, ok := vals[contextKeyOneStr]... | go | func init() {
eh.RegisterContextMarshaler(func(ctx context.Context, vals map[string]interface{}) {
if val, ok := ContextOne(ctx); ok {
vals[contextKeyOneStr] = val
}
})
eh.RegisterContextUnmarshaler(func(ctx context.Context, vals map[string]interface{}) context.Context {
if val, ok := vals[contextKeyOneStr]... | [
"func",
"init",
"(",
")",
"{",
"eh",
".",
"RegisterContextMarshaler",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"vals",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"val",
",",
"ok",
":=",
"ContextOne",
"(",
"ctx",... | // Register the marshalers and unmarshalers for ContextOne. | [
"Register",
"the",
"marshalers",
"and",
"unmarshalers",
"for",
"ContextOne",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/mocks/mocks.go#L429-L441 | train |
looplab/eventhorizon | eventbus/local/eventbus.go | NewEventBus | func NewEventBus(g *Group) *EventBus {
if g == nil {
g = NewGroup()
}
return &EventBus{
group: g,
registered: map[eh.EventHandlerType]struct{}{},
errCh: make(chan eh.EventBusError, 100),
}
} | go | func NewEventBus(g *Group) *EventBus {
if g == nil {
g = NewGroup()
}
return &EventBus{
group: g,
registered: map[eh.EventHandlerType]struct{}{},
errCh: make(chan eh.EventBusError, 100),
}
} | [
"func",
"NewEventBus",
"(",
"g",
"*",
"Group",
")",
"*",
"EventBus",
"{",
"if",
"g",
"==",
"nil",
"{",
"g",
"=",
"NewGroup",
"(",
")",
"\n",
"}",
"\n",
"return",
"&",
"EventBus",
"{",
"group",
":",
"g",
",",
"registered",
":",
"map",
"[",
"eh",
... | // NewEventBus creates a EventBus. | [
"NewEventBus",
"creates",
"a",
"EventBus",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventbus/local/eventbus.go#L40-L49 | train |
looplab/eventhorizon | eventbus/local/eventbus.go | channel | func (b *EventBus) channel(m eh.EventMatcher, h eh.EventHandler, observer bool) <-chan evt {
b.registeredMu.Lock()
defer b.registeredMu.Unlock()
if m == nil {
panic("matcher can't be nil")
}
if h == nil {
panic("handler can't be nil")
}
if _, ok := b.registered[h.HandlerType()]; ok {
panic(fmt.Sprintf("mu... | go | func (b *EventBus) channel(m eh.EventMatcher, h eh.EventHandler, observer bool) <-chan evt {
b.registeredMu.Lock()
defer b.registeredMu.Unlock()
if m == nil {
panic("matcher can't be nil")
}
if h == nil {
panic("handler can't be nil")
}
if _, ok := b.registered[h.HandlerType()]; ok {
panic(fmt.Sprintf("mu... | [
"func",
"(",
"b",
"*",
"EventBus",
")",
"channel",
"(",
"m",
"eh",
".",
"EventMatcher",
",",
"h",
"eh",
".",
"EventHandler",
",",
"observer",
"bool",
")",
"<-",
"chan",
"evt",
"{",
"b",
".",
"registeredMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b"... | // Checks the matcher and handler and gets the event channel from the group. | [
"Checks",
"the",
"matcher",
"and",
"handler",
"and",
"gets",
"the",
"event",
"channel",
"from",
"the",
"group",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventbus/local/eventbus.go#L93-L113 | train |
looplab/eventhorizon | eventbus/local/eventbus.go | Close | func (g *Group) Close() {
for _, ch := range g.bus {
close(ch)
}
g.bus = nil
} | go | func (g *Group) Close() {
for _, ch := range g.bus {
close(ch)
}
g.bus = nil
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"Close",
"(",
")",
"{",
"for",
"_",
",",
"ch",
":=",
"range",
"g",
".",
"bus",
"{",
"close",
"(",
"ch",
")",
"\n",
"}",
"\n",
"g",
".",
"bus",
"=",
"nil",
"\n",
"}"
] | // Close all the open channels | [
"Close",
"all",
"the",
"open",
"channels"
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventbus/local/eventbus.go#L170-L175 | train |
looplab/eventhorizon | middleware/commandhandler/scheduler/commandhandler.go | CommandWithExecuteTime | func CommandWithExecuteTime(cmd eh.Command, t time.Time) Command {
return &command{Command: cmd, t: t}
} | go | func CommandWithExecuteTime(cmd eh.Command, t time.Time) Command {
return &command{Command: cmd, t: t}
} | [
"func",
"CommandWithExecuteTime",
"(",
"cmd",
"eh",
".",
"Command",
",",
"t",
"time",
".",
"Time",
")",
"Command",
"{",
"return",
"&",
"command",
"{",
"Command",
":",
"cmd",
",",
"t",
":",
"t",
"}",
"\n",
"}"
] | // CommandWithExecuteTime returns a wrapped command with a execution time set. | [
"CommandWithExecuteTime",
"returns",
"a",
"wrapped",
"command",
"with",
"a",
"execution",
"time",
"set",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/middleware/commandhandler/scheduler/commandhandler.go#L68-L70 | train |
looplab/eventhorizon | examples/guestlist/domain/saga.go | NewResponseSaga | func NewResponseSaga(guestLimit int) *ResponseSaga {
return &ResponseSaga{
acceptedGuests: map[uuid.UUID]bool{},
guestLimit: guestLimit,
}
} | go | func NewResponseSaga(guestLimit int) *ResponseSaga {
return &ResponseSaga{
acceptedGuests: map[uuid.UUID]bool{},
guestLimit: guestLimit,
}
} | [
"func",
"NewResponseSaga",
"(",
"guestLimit",
"int",
")",
"*",
"ResponseSaga",
"{",
"return",
"&",
"ResponseSaga",
"{",
"acceptedGuests",
":",
"map",
"[",
"uuid",
".",
"UUID",
"]",
"bool",
"{",
"}",
",",
"guestLimit",
":",
"guestLimit",
",",
"}",
"\n",
"... | // NewResponseSaga returns a new ResponseSage with a guest limit. | [
"NewResponseSaga",
"returns",
"a",
"new",
"ResponseSage",
"with",
"a",
"guest",
"limit",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/saga.go#L38-L43 | train |
looplab/eventhorizon | examples/guestlist/domain/saga.go | RunSaga | func (s *ResponseSaga) RunSaga(ctx context.Context, event eh.Event) []eh.Command {
switch event.EventType() {
case InviteAcceptedEvent:
// Do nothing for already accepted guests.
s.acceptedGuestsMu.RLock()
ok, _ := s.acceptedGuests[event.AggregateID()]
s.acceptedGuestsMu.RUnlock()
if ok {
return nil
}
... | go | func (s *ResponseSaga) RunSaga(ctx context.Context, event eh.Event) []eh.Command {
switch event.EventType() {
case InviteAcceptedEvent:
// Do nothing for already accepted guests.
s.acceptedGuestsMu.RLock()
ok, _ := s.acceptedGuests[event.AggregateID()]
s.acceptedGuestsMu.RUnlock()
if ok {
return nil
}
... | [
"func",
"(",
"s",
"*",
"ResponseSaga",
")",
"RunSaga",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"eh",
".",
"Event",
")",
"[",
"]",
"eh",
".",
"Command",
"{",
"switch",
"event",
".",
"EventType",
"(",
")",
"{",
"case",
"InviteAcceptedEvent",... | // RunSaga implements the Run saga method of the Saga interface. | [
"RunSaga",
"implements",
"the",
"Run",
"saga",
"method",
"of",
"the",
"Saga",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/saga.go#L51-L80 | train |
looplab/eventhorizon | examples/guestlist/domain/logger.go | LoggingMiddleware | func LoggingMiddleware(h eh.CommandHandler) eh.CommandHandler {
return eh.CommandHandlerFunc(func(ctx context.Context, cmd eh.Command) error {
log.Printf("command: %#v", cmd)
return h.HandleCommand(ctx, cmd)
})
} | go | func LoggingMiddleware(h eh.CommandHandler) eh.CommandHandler {
return eh.CommandHandlerFunc(func(ctx context.Context, cmd eh.Command) error {
log.Printf("command: %#v", cmd)
return h.HandleCommand(ctx, cmd)
})
} | [
"func",
"LoggingMiddleware",
"(",
"h",
"eh",
".",
"CommandHandler",
")",
"eh",
".",
"CommandHandler",
"{",
"return",
"eh",
".",
"CommandHandlerFunc",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"eh",
".",
"Command",
")",
"error",
"{",
... | // LoggingMiddleware is a tiny command handle middleware for logging. | [
"LoggingMiddleware",
"is",
"a",
"tiny",
"command",
"handle",
"middleware",
"for",
"logging",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/logger.go#L25-L30 | train |
looplab/eventhorizon | repo/cache/repo.go | Notify | func (r *Repo) Notify(ctx context.Context, event eh.Event) {
// Bust the cache on entity updates.
ns := r.namespace(ctx)
r.cacheMu.Lock()
delete(r.cache[ns], event.AggregateID())
r.cacheMu.Unlock()
} | go | func (r *Repo) Notify(ctx context.Context, event eh.Event) {
// Bust the cache on entity updates.
ns := r.namespace(ctx)
r.cacheMu.Lock()
delete(r.cache[ns], event.AggregateID())
r.cacheMu.Unlock()
} | [
"func",
"(",
"r",
"*",
"Repo",
")",
"Notify",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"eh",
".",
"Event",
")",
"{",
"// Bust the cache on entity updates.",
"ns",
":=",
"r",
".",
"namespace",
"(",
"ctx",
")",
"\n",
"r",
".",
"cacheMu",
".",... | // Notify implements the Notify method of the eventhorizon.Observer interface. | [
"Notify",
"implements",
"the",
"Notify",
"method",
"of",
"the",
"eventhorizon",
".",
"Observer",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/cache/repo.go#L47-L53 | train |
looplab/eventhorizon | repo/cache/repo.go | Find | func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error) {
ns := r.namespace(ctx)
// First check the cache.
r.cacheMu.RLock()
entity, ok := r.cache[ns][id]
r.cacheMu.RUnlock()
if ok {
return entity, nil
}
// Fetch and store the entity in the cache.
entity, err := r.ReadWriteRepo.Find(ctx, ... | go | func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error) {
ns := r.namespace(ctx)
// First check the cache.
r.cacheMu.RLock()
entity, ok := r.cache[ns][id]
r.cacheMu.RUnlock()
if ok {
return entity, nil
}
// Fetch and store the entity in the cache.
entity, err := r.ReadWriteRepo.Find(ctx, ... | [
"func",
"(",
"r",
"*",
"Repo",
")",
"Find",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"uuid",
".",
"UUID",
")",
"(",
"eh",
".",
"Entity",
",",
"error",
")",
"{",
"ns",
":=",
"r",
".",
"namespace",
"(",
"ctx",
")",
"\n\n",
"// First check ... | // Find implements the Find method of the eventhorizon.ReadModel interface. | [
"Find",
"implements",
"the",
"Find",
"method",
"of",
"the",
"eventhorizon",
".",
"ReadModel",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/repo/cache/repo.go#L61-L82 | train |
looplab/eventhorizon | commandhandler/aggregate/commandhandler.go | NewCommandHandler | func NewCommandHandler(t eh.AggregateType, store eh.AggregateStore) (*CommandHandler, error) {
if store == nil {
return nil, ErrNilAggregateStore
}
h := &CommandHandler{
t: t,
store: store,
}
return h, nil
} | go | func NewCommandHandler(t eh.AggregateType, store eh.AggregateStore) (*CommandHandler, error) {
if store == nil {
return nil, ErrNilAggregateStore
}
h := &CommandHandler{
t: t,
store: store,
}
return h, nil
} | [
"func",
"NewCommandHandler",
"(",
"t",
"eh",
".",
"AggregateType",
",",
"store",
"eh",
".",
"AggregateStore",
")",
"(",
"*",
"CommandHandler",
",",
"error",
")",
"{",
"if",
"store",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilAggregateStore",
"\n",
"}",... | // NewCommandHandler creates a new CommandHandler for an aggregate type. | [
"NewCommandHandler",
"creates",
"a",
"new",
"CommandHandler",
"for",
"an",
"aggregate",
"type",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/commandhandler/aggregate/commandhandler.go#L42-L52 | train |
looplab/eventhorizon | commandhandler/aggregate/commandhandler.go | HandleCommand | func (h *CommandHandler) HandleCommand(ctx context.Context, cmd eh.Command) error {
err := eh.CheckCommand(cmd)
if err != nil {
return err
}
a, err := h.store.Load(ctx, h.t, cmd.AggregateID())
if err != nil {
return err
} else if a == nil {
return eh.ErrAggregateNotFound
}
if err = a.HandleCommand(ctx, ... | go | func (h *CommandHandler) HandleCommand(ctx context.Context, cmd eh.Command) error {
err := eh.CheckCommand(cmd)
if err != nil {
return err
}
a, err := h.store.Load(ctx, h.t, cmd.AggregateID())
if err != nil {
return err
} else if a == nil {
return eh.ErrAggregateNotFound
}
if err = a.HandleCommand(ctx, ... | [
"func",
"(",
"h",
"*",
"CommandHandler",
")",
"HandleCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"eh",
".",
"Command",
")",
"error",
"{",
"err",
":=",
"eh",
".",
"CheckCommand",
"(",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // HandleCommand handles a command with the registered aggregate.
// Returns ErrAggregateNotFound if no aggregate could be found. | [
"HandleCommand",
"handles",
"a",
"command",
"with",
"the",
"registered",
"aggregate",
".",
"Returns",
"ErrAggregateNotFound",
"if",
"no",
"aggregate",
"could",
"be",
"found",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/commandhandler/aggregate/commandhandler.go#L56-L74 | train |
looplab/eventhorizon | event.go | NewEvent | func NewEvent(eventType EventType, data EventData, timestamp time.Time) Event {
return event{
eventType: eventType,
data: data,
timestamp: timestamp,
}
} | go | func NewEvent(eventType EventType, data EventData, timestamp time.Time) Event {
return event{
eventType: eventType,
data: data,
timestamp: timestamp,
}
} | [
"func",
"NewEvent",
"(",
"eventType",
"EventType",
",",
"data",
"EventData",
",",
"timestamp",
"time",
".",
"Time",
")",
"Event",
"{",
"return",
"event",
"{",
"eventType",
":",
"eventType",
",",
"data",
":",
"data",
",",
"timestamp",
":",
"timestamp",
",",... | // NewEvent creates a new event with a type and data, setting its timestamp. | [
"NewEvent",
"creates",
"a",
"new",
"event",
"with",
"a",
"type",
"and",
"data",
"setting",
"its",
"timestamp",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/event.go#L62-L68 | train |
looplab/eventhorizon | event.go | NewEventForAggregate | func NewEventForAggregate(eventType EventType, data EventData, timestamp time.Time,
aggregateType AggregateType, aggregateID uuid.UUID, version int) Event {
return event{
eventType: eventType,
data: data,
timestamp: timestamp,
aggregateType: aggregateType,
aggregateID: aggregateID,
vers... | go | func NewEventForAggregate(eventType EventType, data EventData, timestamp time.Time,
aggregateType AggregateType, aggregateID uuid.UUID, version int) Event {
return event{
eventType: eventType,
data: data,
timestamp: timestamp,
aggregateType: aggregateType,
aggregateID: aggregateID,
vers... | [
"func",
"NewEventForAggregate",
"(",
"eventType",
"EventType",
",",
"data",
"EventData",
",",
"timestamp",
"time",
".",
"Time",
",",
"aggregateType",
"AggregateType",
",",
"aggregateID",
"uuid",
".",
"UUID",
",",
"version",
"int",
")",
"Event",
"{",
"return",
... | // NewEventForAggregate creates a new event with a type and data, setting its
// timestamp. It also sets the aggregate data on it. | [
"NewEventForAggregate",
"creates",
"a",
"new",
"event",
"with",
"a",
"type",
"and",
"data",
"setting",
"its",
"timestamp",
".",
"It",
"also",
"sets",
"the",
"aggregate",
"data",
"on",
"it",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/event.go#L72-L82 | train |
looplab/eventhorizon | event.go | String | func (e event) String() string {
return fmt.Sprintf("%s@%d", e.eventType, e.version)
} | go | func (e event) String() string {
return fmt.Sprintf("%s@%d", e.eventType, e.version)
} | [
"func",
"(",
"e",
"event",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"eventType",
",",
"e",
".",
"version",
")",
"\n",
"}"
] | // String implements the String method of the Event interface. | [
"String",
"implements",
"the",
"String",
"method",
"of",
"the",
"Event",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/event.go#L127-L129 | train |
looplab/eventhorizon | event.go | UnregisterEventData | func UnregisterEventData(eventType EventType) {
if eventType == EventType("") {
panic("eventhorizon: attempt to unregister empty event type")
}
eventDataFactoriesMu.Lock()
defer eventDataFactoriesMu.Unlock()
if _, ok := eventDataFactories[eventType]; !ok {
panic(fmt.Sprintf("eventhorizon: unregister of non-re... | go | func UnregisterEventData(eventType EventType) {
if eventType == EventType("") {
panic("eventhorizon: attempt to unregister empty event type")
}
eventDataFactoriesMu.Lock()
defer eventDataFactoriesMu.Unlock()
if _, ok := eventDataFactories[eventType]; !ok {
panic(fmt.Sprintf("eventhorizon: unregister of non-re... | [
"func",
"UnregisterEventData",
"(",
"eventType",
"EventType",
")",
"{",
"if",
"eventType",
"==",
"EventType",
"(",
"\"",
"\"",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"eventDataFactoriesMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"even... | // UnregisterEventData removes the registration of the event data factory for
// a type. This is mainly useful in mainenance situations where the event data
// needs to be switched in a migrations. | [
"UnregisterEventData",
"removes",
"the",
"registration",
"of",
"the",
"event",
"data",
"factory",
"for",
"a",
"type",
".",
"This",
"is",
"mainly",
"useful",
"in",
"mainenance",
"situations",
"where",
"the",
"event",
"data",
"needs",
"to",
"be",
"switched",
"in... | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/event.go#L161-L172 | train |
looplab/eventhorizon | event.go | CreateEventData | func CreateEventData(eventType EventType) (EventData, error) {
eventDataFactoriesMu.RLock()
defer eventDataFactoriesMu.RUnlock()
if factory, ok := eventDataFactories[eventType]; ok {
return factory(), nil
}
return nil, ErrEventDataNotRegistered
} | go | func CreateEventData(eventType EventType) (EventData, error) {
eventDataFactoriesMu.RLock()
defer eventDataFactoriesMu.RUnlock()
if factory, ok := eventDataFactories[eventType]; ok {
return factory(), nil
}
return nil, ErrEventDataNotRegistered
} | [
"func",
"CreateEventData",
"(",
"eventType",
"EventType",
")",
"(",
"EventData",
",",
"error",
")",
"{",
"eventDataFactoriesMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"eventDataFactoriesMu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"factory",
",",
"ok",
":=",
... | // CreateEventData creates an event data of a type using the factory registered
// with RegisterEventData. | [
"CreateEventData",
"creates",
"an",
"event",
"data",
"of",
"a",
"type",
"using",
"the",
"factory",
"registered",
"with",
"RegisterEventData",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/event.go#L176-L183 | train |
looplab/eventhorizon | examples/todomvc/internal/domain/aggregate.go | ApplyEvent | func (a *Aggregate) ApplyEvent(ctx context.Context, event eh.Event) error {
switch event.EventType() {
case Created:
a.created = true
case Deleted:
a.created = false
case ItemAdded:
data, ok := event.Data().(*ItemAddedData)
if !ok {
return errors.New("invalid event data")
}
a.items = append(a.items, ... | go | func (a *Aggregate) ApplyEvent(ctx context.Context, event eh.Event) error {
switch event.EventType() {
case Created:
a.created = true
case Deleted:
a.created = false
case ItemAdded:
data, ok := event.Data().(*ItemAddedData)
if !ok {
return errors.New("invalid event data")
}
a.items = append(a.items, ... | [
"func",
"(",
"a",
"*",
"Aggregate",
")",
"ApplyEvent",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"eh",
".",
"Event",
")",
"error",
"{",
"switch",
"event",
".",
"EventType",
"(",
")",
"{",
"case",
"Created",
":",
"a",
".",
"created",
"=",
... | // ApplyEvent implements the ApplyEvent method of the
// eventhorizon.Aggregate interface. | [
"ApplyEvent",
"implements",
"the",
"ApplyEvent",
"method",
"of",
"the",
"eventhorizon",
".",
"Aggregate",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/todomvc/internal/domain/aggregate.go#L155-L206 | train |
looplab/eventhorizon | examples/todomvc/internal/domain/projector.go | Project | func (p *Projector) Project(ctx context.Context,
event eh.Event, entity eh.Entity) (eh.Entity, error) {
model, ok := entity.(*TodoList)
if !ok {
return nil, errors.New("model is of incorrect type")
}
switch event.EventType() {
case Created:
// Set the ID when first created.
model.ID = event.AggregateID()
... | go | func (p *Projector) Project(ctx context.Context,
event eh.Event, entity eh.Entity) (eh.Entity, error) {
model, ok := entity.(*TodoList)
if !ok {
return nil, errors.New("model is of incorrect type")
}
switch event.EventType() {
case Created:
// Set the ID when first created.
model.ID = event.AggregateID()
... | [
"func",
"(",
"p",
"*",
"Projector",
")",
"Project",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"eh",
".",
"Event",
",",
"entity",
"eh",
".",
"Entity",
")",
"(",
"eh",
".",
"Entity",
",",
"error",
")",
"{",
"model",
",",
"ok",
":=",
"ent... | // Project implements the Project method of the eventhorizon.Projector interface. | [
"Project",
"implements",
"the",
"Project",
"method",
"of",
"the",
"eventhorizon",
".",
"Projector",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/todomvc/internal/domain/projector.go#L36-L102 | train |
looplab/eventhorizon | eventhandler/waiter/eventhandler.go | NewEventHandler | func NewEventHandler() *EventHandler {
h := EventHandler{
inbox: make(chan eh.Event, 1),
register: make(chan *EventListener),
unregister: make(chan *EventListener),
}
go h.run()
return &h
} | go | func NewEventHandler() *EventHandler {
h := EventHandler{
inbox: make(chan eh.Event, 1),
register: make(chan *EventListener),
unregister: make(chan *EventListener),
}
go h.run()
return &h
} | [
"func",
"NewEventHandler",
"(",
")",
"*",
"EventHandler",
"{",
"h",
":=",
"EventHandler",
"{",
"inbox",
":",
"make",
"(",
"chan",
"eh",
".",
"Event",
",",
"1",
")",
",",
"register",
":",
"make",
"(",
"chan",
"*",
"EventListener",
")",
",",
"unregister"... | // NewEventHandler returns a new EventHandler. | [
"NewEventHandler",
"returns",
"a",
"new",
"EventHandler",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler/waiter/eventhandler.go#L34-L42 | train |
looplab/eventhorizon | eventhandler/waiter/eventhandler.go | HandleEvent | func (h *EventHandler) HandleEvent(ctx context.Context, event eh.Event) error {
h.inbox <- event
return nil
} | go | func (h *EventHandler) HandleEvent(ctx context.Context, event eh.Event) error {
h.inbox <- event
return nil
} | [
"func",
"(",
"h",
"*",
"EventHandler",
")",
"HandleEvent",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"eh",
".",
"Event",
")",
"error",
"{",
"h",
".",
"inbox",
"<-",
"event",
"\n",
"return",
"nil",
"\n",
"}"
] | // HandleEvent implements the HandleEvent method of the eventhorizon.EventHandler interface.
// It forwards events to the waiters so that they can match the events. | [
"HandleEvent",
"implements",
"the",
"HandleEvent",
"method",
"of",
"the",
"eventhorizon",
".",
"EventHandler",
"interface",
".",
"It",
"forwards",
"events",
"to",
"the",
"waiters",
"so",
"that",
"they",
"can",
"match",
"the",
"events",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler/waiter/eventhandler.go#L51-L54 | train |
looplab/eventhorizon | eventhandler/waiter/eventhandler.go | Listen | func (h *EventHandler) Listen(match func(eh.Event) bool) *EventListener {
l := &EventListener{
id: uuid.New(),
inbox: make(chan eh.Event, 1),
match: match,
unregister: h.unregister,
}
// Register us to the in-flight listeners.
h.register <- l
return l
} | go | func (h *EventHandler) Listen(match func(eh.Event) bool) *EventListener {
l := &EventListener{
id: uuid.New(),
inbox: make(chan eh.Event, 1),
match: match,
unregister: h.unregister,
}
// Register us to the in-flight listeners.
h.register <- l
return l
} | [
"func",
"(",
"h",
"*",
"EventHandler",
")",
"Listen",
"(",
"match",
"func",
"(",
"eh",
".",
"Event",
")",
"bool",
")",
"*",
"EventListener",
"{",
"l",
":=",
"&",
"EventListener",
"{",
"id",
":",
"uuid",
".",
"New",
"(",
")",
",",
"inbox",
":",
"m... | // Listen waits unil the match function returns true for an event, or the context
// deadline expires. The match function can be used to filter or otherwise select
// interesting events by analysing the event data. | [
"Listen",
"waits",
"unil",
"the",
"match",
"function",
"returns",
"true",
"for",
"an",
"event",
"or",
"the",
"context",
"deadline",
"expires",
".",
"The",
"match",
"function",
"can",
"be",
"used",
"to",
"filter",
"or",
"otherwise",
"select",
"interesting",
"... | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler/waiter/eventhandler.go#L59-L70 | train |
looplab/eventhorizon | eventhandler/waiter/eventhandler.go | Wait | func (l *EventListener) Wait(ctx context.Context) (eh.Event, error) {
select {
case event := <-l.inbox:
return event, nil
case <-ctx.Done():
return nil, ctx.Err()
}
} | go | func (l *EventListener) Wait(ctx context.Context) (eh.Event, error) {
select {
case event := <-l.inbox:
return event, nil
case <-ctx.Done():
return nil, ctx.Err()
}
} | [
"func",
"(",
"l",
"*",
"EventListener",
")",
"Wait",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"eh",
".",
"Event",
",",
"error",
")",
"{",
"select",
"{",
"case",
"event",
":=",
"<-",
"l",
".",
"inbox",
":",
"return",
"event",
",",
"nil",
"... | // Wait waits for the event to arrive or the context to be cancelled. | [
"Wait",
"waits",
"for",
"the",
"event",
"to",
"arrive",
"or",
"the",
"context",
"to",
"be",
"cancelled",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler/waiter/eventhandler.go#L81-L88 | train |
looplab/eventhorizon | examples/guestlist/domain/setup.go | Setup | func Setup(
eventStore eh.EventStore,
eventBus eh.EventBus,
commandBus *bus.CommandHandler,
invitationRepo, guestListRepo eh.ReadWriteRepo,
eventID uuid.UUID) {
// Add a logger as an observer.
eventBus.AddObserver(eh.MatchAny(), &Logger{})
// Create the aggregate repository.
aggregateStore, err := events.New... | go | func Setup(
eventStore eh.EventStore,
eventBus eh.EventBus,
commandBus *bus.CommandHandler,
invitationRepo, guestListRepo eh.ReadWriteRepo,
eventID uuid.UUID) {
// Add a logger as an observer.
eventBus.AddObserver(eh.MatchAny(), &Logger{})
// Create the aggregate repository.
aggregateStore, err := events.New... | [
"func",
"Setup",
"(",
"eventStore",
"eh",
".",
"EventStore",
",",
"eventBus",
"eh",
".",
"EventBus",
",",
"commandBus",
"*",
"bus",
".",
"CommandHandler",
",",
"invitationRepo",
",",
"guestListRepo",
"eh",
".",
"ReadWriteRepo",
",",
"eventID",
"uuid",
".",
"... | // Setup configures the domain. | [
"Setup",
"configures",
"the",
"domain",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/examples/guestlist/domain/setup.go#L30-L83 | train |
looplab/eventhorizon | commandhandler.go | HandleCommand | func (h CommandHandlerFunc) HandleCommand(ctx context.Context, cmd Command) error {
return h(ctx, cmd)
} | go | func (h CommandHandlerFunc) HandleCommand(ctx context.Context, cmd Command) error {
return h(ctx, cmd)
} | [
"func",
"(",
"h",
"CommandHandlerFunc",
")",
"HandleCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"Command",
")",
"error",
"{",
"return",
"h",
"(",
"ctx",
",",
"cmd",
")",
"\n",
"}"
] | // HandleCommand implements the HandleCommand method of the CommandHandler. | [
"HandleCommand",
"implements",
"the",
"HandleCommand",
"method",
"of",
"the",
"CommandHandler",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/commandhandler.go#L30-L32 | train |
looplab/eventhorizon | commandhandler.go | UseCommandHandlerMiddleware | func UseCommandHandlerMiddleware(h CommandHandler, middleware ...CommandHandlerMiddleware) CommandHandler {
// Apply in reverse order.
for i := len(middleware) - 1; i >= 0; i-- {
m := middleware[i]
h = m(h)
}
return h
} | go | func UseCommandHandlerMiddleware(h CommandHandler, middleware ...CommandHandlerMiddleware) CommandHandler {
// Apply in reverse order.
for i := len(middleware) - 1; i >= 0; i-- {
m := middleware[i]
h = m(h)
}
return h
} | [
"func",
"UseCommandHandlerMiddleware",
"(",
"h",
"CommandHandler",
",",
"middleware",
"...",
"CommandHandlerMiddleware",
")",
"CommandHandler",
"{",
"// Apply in reverse order.",
"for",
"i",
":=",
"len",
"(",
"middleware",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
... | // UseCommandHandlerMiddleware wraps a CommandHandler in one or more middleware. | [
"UseCommandHandlerMiddleware",
"wraps",
"a",
"CommandHandler",
"in",
"one",
"or",
"more",
"middleware",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/commandhandler.go#L39-L46 | train |
looplab/eventhorizon | eventhandler/projector/eventhandler.go | Error | func (e Error) Error() string {
errStr := e.Err.Error()
if e.BaseErr != nil {
errStr += ": " + e.BaseErr.Error()
}
return "projector: " + errStr + " (" + e.Namespace + ")"
} | go | func (e Error) Error() string {
errStr := e.Err.Error()
if e.BaseErr != nil {
errStr += ": " + e.BaseErr.Error()
}
return "projector: " + errStr + " (" + e.Namespace + ")"
} | [
"func",
"(",
"e",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"errStr",
":=",
"e",
".",
"Err",
".",
"Error",
"(",
")",
"\n",
"if",
"e",
".",
"BaseErr",
"!=",
"nil",
"{",
"errStr",
"+=",
"\"",
"\"",
"+",
"e",
".",
"BaseErr",
".",
"Error",
... | // Error implements the Error method of the errors.Error interface. | [
"Error",
"implements",
"the",
"Error",
"method",
"of",
"the",
"errors",
".",
"Error",
"interface",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler/projector/eventhandler.go#L57-L63 | train |
looplab/eventhorizon | eventhandler/projector/eventhandler.go | HandleEvent | func (h *EventHandler) HandleEvent(ctx context.Context, event eh.Event) error {
// Get or create the model, trying to use a waiting find with a min version
// if the underlying repo supports it.
findCtx, cancel := eh.NewContextWithMinVersionWait(ctx, event.Version()-1)
defer cancel()
entity, err := h.repo.Find(fin... | go | func (h *EventHandler) HandleEvent(ctx context.Context, event eh.Event) error {
// Get or create the model, trying to use a waiting find with a min version
// if the underlying repo supports it.
findCtx, cancel := eh.NewContextWithMinVersionWait(ctx, event.Version()-1)
defer cancel()
entity, err := h.repo.Find(fin... | [
"func",
"(",
"h",
"*",
"EventHandler",
")",
"HandleEvent",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"eh",
".",
"Event",
")",
"error",
"{",
"// Get or create the model, trying to use a waiting find with a min version",
"// if the underlying repo supports it.",
... | // HandleEvent implements the HandleEvent method of the eventhorizon.EventHandler interface.
// It will try to find the correct version of the model, waiting for it if needed. | [
"HandleEvent",
"implements",
"the",
"HandleEvent",
"method",
"of",
"the",
"eventhorizon",
".",
"EventHandler",
"interface",
".",
"It",
"will",
"try",
"to",
"find",
"the",
"correct",
"version",
"of",
"the",
"model",
"waiting",
"for",
"it",
"if",
"needed",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventhandler/projector/eventhandler.go#L83-L151 | train |
looplab/eventhorizon | eventbus/gcp/eventbus.go | NewEventBus | func NewEventBus(projectID, appID string, opts ...option.ClientOption) (*EventBus, error) {
ctx := context.Background()
client, err := pubsub.NewClient(ctx, projectID, opts...)
if err != nil {
return nil, err
}
// Get or create the topic.
name := appID + "_events"
topic := client.Topic(name)
if ok, err := to... | go | func NewEventBus(projectID, appID string, opts ...option.ClientOption) (*EventBus, error) {
ctx := context.Background()
client, err := pubsub.NewClient(ctx, projectID, opts...)
if err != nil {
return nil, err
}
// Get or create the topic.
name := appID + "_events"
topic := client.Topic(name)
if ok, err := to... | [
"func",
"NewEventBus",
"(",
"projectID",
",",
"appID",
"string",
",",
"opts",
"...",
"option",
".",
"ClientOption",
")",
"(",
"*",
"EventBus",
",",
"error",
")",
"{",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"client",
",",
"err",
":="... | // NewEventBus creates an EventBus, with optional GCP connection settings. | [
"NewEventBus",
"creates",
"an",
"EventBus",
"with",
"optional",
"GCP",
"connection",
"settings",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventbus/gcp/eventbus.go#L47-L72 | train |
looplab/eventhorizon | eventbus/gcp/eventbus.go | subscription | func (b *EventBus) subscription(m eh.EventMatcher, h eh.EventHandler, observer bool) *pubsub.Subscription {
b.registeredMu.Lock()
defer b.registeredMu.Unlock()
if m == nil {
panic("matcher can't be nil")
}
if h == nil {
panic("handler can't be nil")
}
if _, ok := b.registered[h.HandlerType()]; ok {
panic(... | go | func (b *EventBus) subscription(m eh.EventMatcher, h eh.EventHandler, observer bool) *pubsub.Subscription {
b.registeredMu.Lock()
defer b.registeredMu.Unlock()
if m == nil {
panic("matcher can't be nil")
}
if h == nil {
panic("handler can't be nil")
}
if _, ok := b.registered[h.HandlerType()]; ok {
panic(... | [
"func",
"(",
"b",
"*",
"EventBus",
")",
"subscription",
"(",
"m",
"eh",
".",
"EventMatcher",
",",
"h",
"eh",
".",
"EventHandler",
",",
"observer",
"bool",
")",
"*",
"pubsub",
".",
"Subscription",
"{",
"b",
".",
"registeredMu",
".",
"Lock",
"(",
")",
... | // Checks the matcher and handler and gets the event subscription. | [
"Checks",
"the",
"matcher",
"and",
"handler",
"and",
"gets",
"the",
"event",
"subscription",
"."
] | 6fd1f17be266c5a217ff8c05dd1403d722cae7f2 | https://github.com/looplab/eventhorizon/blob/6fd1f17be266c5a217ff8c05dd1403d722cae7f2/eventbus/gcp/eventbus.go#L131-L170 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.