_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q14000 | pk | train | func (s *structValue) pk() map[string]interface{} {
if len(s.pkNames) == 0 {
return nil
}
return s.columns(s.pkNames, nil)
} | go | {
"resource": ""
} |
q14001 | columns | train | func (s *structValue) columns(include, exclude []string) map[string]interface{} {
v := make(map[string]interface{}, len(s.nameMap))
if len(include) == 0 {
for _, fi := range s.nameMap {
v[fi.dbName] = fi.getValue(s.value)
}
} else {
for _, attr := range include {
if fi, ok := s.nameMap[attr]; ok {
v[... | go | {
"resource": ""
} |
q14002 | getValue | train | func (fi *fieldInfo) getValue(a reflect.Value) interface{} {
for _, i := range fi.path {
a = a.Field(i)
if a.Kind() == reflect.Ptr {
if a.IsNil() {
return nil
}
a = a.Elem()
}
}
return a.Interface()
} | go | {
"resource": ""
} |
q14003 | getField | train | func (fi *fieldInfo) getField(a reflect.Value) reflect.Value {
i := 0
for ; i < len(fi.path)-1; i++ {
a = indirect(a.Field(fi.path[i]))
}
return a.Field(fi.path[i])
} | go | {
"resource": ""
} |
q14004 | indirect | train | func indirect(v reflect.Value) reflect.Value {
for v.Kind() == reflect.Ptr {
if v.IsNil() {
v.Set(reflect.New(v.Type().Elem()))
}
v = v.Elem()
}
return v
} | go | {
"resource": ""
} |
q14005 | NewExp | train | func NewExp(e string, params ...Params) Expression {
if len(params) > 0 {
return &Exp{e, params[0]}
}
return &Exp{e, nil}
} | go | {
"resource": ""
} |
q14006 | Escape | train | func (e *LikeExp) Escape(chars ...string) *LikeExp {
e.escape = chars
return e
} | go | {
"resource": ""
} |
q14007 | String | train | func (o Op) String() string {
switch o {
case Insert:
return "insert"
case Update:
return "update"
case Delete:
return "delete"
case Command:
return "command"
case Noop:
return "noop"
case Skip:
return "skip"
default:
return "unknown"
}
} | go | {
"resource": ""
} |
q14008 | OpTypeFromString | train | func OpTypeFromString(s string) Op {
switch s[0] {
case 'i':
return Insert
case 'u':
return Update
case 'd':
return Delete
case 'c':
return Command
case 'n':
return Noop
case 's':
return Skip
default:
return Unknown
}
} | go | {
"resource": ""
} |
q14009 | GetFunction | train | func GetFunction(name string, conf map[string]interface{}) (Function, error) {
creator, ok := functions[name]
if ok {
a := creator()
b, err := json.Marshal(conf)
if err != nil {
return nil, err
}
err = json.Unmarshal(b, a)
if err != nil {
return nil, err
}
return a, nil
}
return nil, ErrNotFou... | go | {
"resource": ""
} |
q14010 | RegisteredFunctions | train | func RegisteredFunctions() []string {
all := make([]string, 0)
for i := range functions {
all = append(all, i)
}
return all
} | go | {
"resource": ""
} |
q14011 | Read | train | func (t *Tailer) Read(resumeMap map[string]client.MessageSet, filterFn client.NsFilterFunc) client.MessageChanFunc {
return func(s client.Session, done chan struct{}) (chan client.MessageSet, error) {
readFunc := t.reader.Read(resumeMap, filterFn)
msgChan, err := readFunc(s, done)
if err != nil {
return nil, ... | go | {
"resource": ""
} |
q14012 | pluckFromLogicalDecoding | train | func (t *Tailer) pluckFromLogicalDecoding(s *Session, filterFn client.NsFilterFunc) ([]client.MessageSet, error) {
var result []client.MessageSet
dataMatcher := regexp.MustCompile("(?s)^table ([^\\.]+)\\.([^:]+): (INSERT|DELETE|UPDATE): (.+)$") // 1 - schema, 2 - table, 3 - action, 4 - remaining
changesResult, err ... | go | {
"resource": ""
} |
q14013 | Stop | train | func (pipeline *Pipeline) Stop() {
endpoints := pipeline.source.Endpoints()
pipeline.source.Stop()
// pipeline has stopped, emit one last round of metrics and send the exit event
close(pipeline.done)
pipeline.emitMetrics()
pipeline.source.pipe.Event <- events.NewExitEvent(time.Now().UnixNano(), pipeline.version,... | go | {
"resource": ""
} |
q14014 | Run | train | func (pipeline *Pipeline) Run() error {
endpoints := pipeline.source.Endpoints()
// send a boot event
pipeline.source.pipe.Event <- events.NewBootEvent(time.Now().UnixNano(), pipeline.version, endpoints)
errors := make(chan error, 2)
go func() {
errors <- pipeline.startErrorListener()
}()
go func() {
errors... | go | {
"resource": ""
} |
q14015 | startErrorListener | train | func (pipeline *Pipeline) startErrorListener() error {
for {
select {
case err := <-pipeline.source.pipe.Err:
return err
case <-pipeline.done:
return nil
}
}
} | go | {
"resource": ""
} |
q14016 | emitMetrics | train | func (pipeline *Pipeline) emitMetrics() {
pipeline.apply(func(node *Node) {
pipeline.source.pipe.Event <- events.NewMetricsEvent(time.Now().UnixNano(), node.path, node.pipe.MessageCount)
})
} | go | {
"resource": ""
} |
q14017 | apply | train | func (pipeline *Pipeline) apply(f func(*Node)) {
head := pipeline.source
nodes := []*Node{head}
for len(nodes) > 0 {
head, nodes = nodes[0], nodes[1:]
f(head)
nodes = append(nodes, head.children...)
}
} | go | {
"resource": ""
} |
q14018 | Writer | train | func (f *File) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) {
return newWriter(), nil
} | go | {
"resource": ""
} |
q14019 | Construct | train | func (c *Config) Construct(conf interface{}) error {
b, err := json.Marshal(c)
if err != nil {
return err
}
err = json.Unmarshal(b, conf)
if err != nil {
return err
}
return nil
} | go | {
"resource": ""
} |
q14020 | GetString | train | func (c Config) GetString(key string) string {
i, ok := c[key]
if !ok {
return ""
}
s, ok := i.(string)
if !ok {
return ""
}
return s
} | go | {
"resource": ""
} |
q14021 | Add | train | func Add(v string, constraint version.Constraints, creator Creator) {
Clients[v] = &VersionedClient{constraint, creator}
} | go | {
"resource": ""
} |
q14022 | NewLogManager | train | func NewLogManager(path, name string) (*LogManager, error) {
m := &LogManager{
name: name,
nsMap: make(map[string]uint64),
}
l, err := commitlog.New(
commitlog.WithPath(filepath.Join(path, fmt.Sprintf("%s-%s", offsetPrefixDir, name))),
commitlog.WithMaxSegmentBytes(1024*1024*1024),
)
if err != nil {
re... | go | {
"resource": ""
} |
q14023 | CommitOffset | train | func (m *LogManager) CommitOffset(o Offset, override bool) error {
m.Lock()
defer m.Unlock()
if currentOffset, ok := m.nsMap[o.Namespace]; !override && ok && currentOffset >= o.LogOffset {
log.With("currentOffest", currentOffset).
With("providedOffset", o.LogOffset).
Debugln("refusing to commit offset")
re... | go | {
"resource": ""
} |
q14024 | OffsetMap | train | func (m *LogManager) OffsetMap() map[string]uint64 {
m.Lock()
defer m.Unlock()
return m.nsMap
} | go | {
"resource": ""
} |
q14025 | NewestOffset | train | func (m *LogManager) NewestOffset() int64 {
m.Lock()
defer m.Unlock()
if len(m.nsMap) == 0 {
return -1
}
var newestOffset uint64
for _, v := range m.nsMap {
if newestOffset < v {
newestOffset = v
}
}
return int64(newestOffset)
} | go | {
"resource": ""
} |
q14026 | WithURI | train | func WithURI(uri string) ClientOptionFunc {
return func(c *Client) error {
if _, err := amqp.ParseURI(uri); err != nil {
return client.InvalidURIError{URI: uri, Err: err.Error()}
}
c.uri = uri
return nil
}
} | go | {
"resource": ""
} |
q14027 | WithSSL | train | func WithSSL(ssl bool) ClientOptionFunc {
return func(c *Client) error {
if ssl {
tlsConfig := &tls.Config{InsecureSkipVerify: true}
tlsConfig.RootCAs = x509.NewCertPool()
c.tlsConfig = tlsConfig
}
return nil
}
} | go | {
"resource": ""
} |
q14028 | WithCACerts | train | func WithCACerts(certs []string) ClientOptionFunc {
return func(c *Client) error {
if len(certs) > 0 {
roots := x509.NewCertPool()
for _, cert := range certs {
if _, err := os.Stat(cert); err == nil {
filepath.Abs(cert)
c, err := ioutil.ReadFile(cert)
if err != nil {
return err
}
... | go | {
"resource": ""
} |
q14029 | Connect | train | func (c *Client) Connect() (client.Session, error) {
if c.conn == nil {
if err := c.initConnection(); err != nil {
return nil, err
}
}
return &Session{c.conn, c.ch}, nil
} | go | {
"resource": ""
} |
q14030 | String | train | func (t *Transporter) String() string {
out := "Transporter:\n"
out += fmt.Sprintf("%s", t.sourceNode.String())
return out
} | go | {
"resource": ""
} |
q14031 | Config | train | func (t *Transporter) Config(call goja.FunctionCall) goja.Value {
if cfg, ok := call.Argument(0).Export().(map[string]interface{}); ok {
b, err := json.Marshal(cfg)
if err != nil {
panic(err)
}
var c config
if err = json.Unmarshal(b, &c); err != nil {
panic(err)
}
t.config = &c
}
return t.vm.ToV... | go | {
"resource": ""
} |
q14032 | Reader | train | func (e *Elasticsearch) Reader() (client.Reader, error) {
return nil, adaptor.ErrFuncNotSupported{Name: "Reader()", Func: "elasticsearch"}
} | go | {
"resource": ""
} |
q14033 | Writer | train | func (e *Elasticsearch) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) {
return setupWriter(e)
} | go | {
"resource": ""
} |
q14034 | Has | train | func (d Data) Has(key string) (interface{}, bool) {
val, ok := d[key]
return val, ok
} | go | {
"resource": ""
} |
q14035 | PutOffset | train | func (l Log) PutOffset(offset int64) {
encoding.PutUint64(l[offsetPos:sizePos], uint64(offset))
} | go | {
"resource": ""
} |
q14036 | WithPath | train | func WithPath(path string) OptionFunc {
return func(c *CommitLog) error {
if path == "" {
return ErrEmptyPath
}
c.path = path
return nil
}
} | go | {
"resource": ""
} |
q14037 | WithMaxSegmentBytes | train | func WithMaxSegmentBytes(max int64) OptionFunc {
return func(c *CommitLog) error {
if max > 0 {
c.maxSegmentBytes = max
}
return nil
}
} | go | {
"resource": ""
} |
q14038 | OldestOffset | train | func (c *CommitLog) OldestOffset() int64 {
c.mu.RLock()
defer c.mu.RUnlock()
return c.segments[0].BaseOffset
} | go | {
"resource": ""
} |
q14039 | Segments | train | func (c *CommitLog) Segments() []*Segment {
c.mu.Lock()
defer c.mu.Unlock()
return c.segments
} | go | {
"resource": ""
} |
q14040 | DeleteAll | train | func (c *CommitLog) DeleteAll() error {
if err := c.Close(); err != nil {
return err
}
return os.RemoveAll(c.path)
} | go | {
"resource": ""
} |
q14041 | NewReader | train | func (c *CommitLog) NewReader(offset int64) (io.Reader, error) {
c.mu.RLock()
defer c.mu.RUnlock()
log.With("num_segments", len(c.segments)).
With("offset", offset).
Infoln("searching segments")
// in the event there has been data committed to the segment but no offset for a path,
// then we need to create a ... | go | {
"resource": ""
} |
q14042 | NewPipe | train | func NewPipe(pipe *Pipe, path string) *Pipe {
p := &Pipe{
Out: make([]messageChan, 0),
path: path,
chStop: make(chan struct{}),
}
if pipe != nil {
pipe.Out = append(pipe.Out, newMessageChan())
p.In = pipe.Out[len(pipe.Out)-1] // use the last out channel
p.Err = pipe.Err
p.Event = pipe.Event
} e... | go | {
"resource": ""
} |
q14043 | Stop | train | func (p *Pipe) Stop() {
if !p.Stopped {
p.Stopped = true
// we only worry about the stop channel if we're in a listening loop
if p.listening {
close(p.chStop)
p.wg.Wait()
return
}
timeout := time.After(10 * time.Second)
for {
select {
case <-timeout:
log.With("path", p.path).Errorln("t... | go | {
"resource": ""
} |
q14044 | Send | train | func (p *Pipe) Send(msg message.Msg, off offset.Offset) {
p.MessageCount++
for _, ch := range p.Out {
A:
for {
select {
case ch <- TrackedMessage{msg, off}:
break A
}
}
}
} | go | {
"resource": ""
} |
q14045 | getOriginalDoc | train | func (r *Reader) getOriginalDoc(doc bson.M, c string, s *mgo.Session) (result bson.M, err error) {
id, exists := doc["_id"]
if !exists {
return result, fmt.Errorf("can't get _id from document")
}
query := bson.M{}
if f, ok := r.collectionFilters[c]; ok {
query = bson.M(f)
}
query["_id"] = id
err = s.DB(""... | go | {
"resource": ""
} |
q14046 | validOp | train | func (o *oplogDoc) validOp(ns string) bool {
return ns == o.Ns && (o.Op == "i" || o.Op == "d" || o.Op == "u")
} | go | {
"resource": ""
} |
q14047 | WithURI | train | func WithURI(uri string) ClientOptionFunc {
return func(c *Client) error {
_, err := mgo.ParseURL(uri)
if err != nil {
return client.InvalidURIError{URI: uri, Err: err.Error()}
}
c.uri = uri
return nil
}
} | go | {
"resource": ""
} |
q14048 | WithTimeout | train | func WithTimeout(timeout string) ClientOptionFunc {
return func(c *Client) error {
if timeout == "" {
c.sessionTimeout = DefaultSessionTimeout
return nil
}
t, err := time.ParseDuration(timeout)
if err != nil {
return client.InvalidTimeoutError{Timeout: timeout}
}
c.sessionTimeout = t
return nil... | go | {
"resource": ""
} |
q14049 | WithReadPreference | train | func WithReadPreference(readPreference string) ClientOptionFunc {
return func(c *Client) error {
if readPreference == "" {
c.readPreference = DefaultReadPreference
return nil
}
switch strings.ToLower(readPreference) {
case "primary":
c.readPreference = mgo.Primary
case "primarypreferred":
c.readP... | go | {
"resource": ""
} |
q14050 | Connect | train | func (c *Client) Connect() (client.Session, error) {
if c.mgoSession == nil {
if err := c.initConnection(); err != nil {
return nil, err
}
}
return c.session(), nil
} | go | {
"resource": ""
} |
q14051 | session | train | func (c *Client) session() client.Session {
sess := c.mgoSession.Copy()
return &Session{sess}
} | go | {
"resource": ""
} |
q14052 | Connect | train | func (c *Client) Connect() (client.Session, error) {
if c.file == nil {
if err := c.initFile(); err != nil {
return nil, err
}
}
return &Session{c.file}, nil
} | go | {
"resource": ""
} |
q14053 | Close | train | func (c *Client) Close() {
if c.file != nil && c.file != os.Stdout {
c.file.Close()
}
} | go | {
"resource": ""
} |
q14054 | NewMetricsEvent | train | func NewMetricsEvent(ts int64, path string, records int) Event {
e := &metricsEvent{
Ts: ts,
Kind: "metrics",
Path: path,
Records: records,
}
return e
} | go | {
"resource": ""
} |
q14055 | NewErrorEvent | train | func NewErrorEvent(ts int64, path string, record interface{}, message string) Event {
e := &errorEvent{
Ts: ts,
Kind: "error",
Path: path,
Record: record,
Message: message,
}
return e
} | go | {
"resource": ""
} |
q14056 | NewNodeWithOptions | train | func NewNodeWithOptions(name, kind, ns string, options ...OptionFunc) (*Node, error) {
compiledNs, err := regexp.Compile(strings.Trim(ns, "/"))
if err != nil {
return nil, err
}
n := &Node{
Name: name,
Type: kind,
path: name,
depth: 1,
nsFilter: ... | go | {
"resource": ""
} |
q14057 | WithReader | train | func WithReader(a adaptor.Adaptor) OptionFunc {
return func(n *Node) error {
r, err := a.Reader()
n.reader = r
return err
}
} | go | {
"resource": ""
} |
q14058 | WithWriter | train | func WithWriter(a adaptor.Adaptor) OptionFunc {
return func(n *Node) error {
w, err := a.Writer(n.done, &n.wg)
n.writer = w
return err
}
} | go | {
"resource": ""
} |
q14059 | WithParent | train | func WithParent(parent *Node) OptionFunc {
return func(n *Node) error {
n.parent = parent
parent.children = append(parent.children, n)
n.path = parent.path + "/" + n.Name
n.depth = parent.depth + 1
n.pipe = pipe.NewPipe(parent.pipe, n.path)
return nil
}
} | go | {
"resource": ""
} |
q14060 | WithTransforms | train | func WithTransforms(t []*Transform) OptionFunc {
return func(n *Node) error {
n.transforms = t
return nil
}
} | go | {
"resource": ""
} |
q14061 | WithCommitLog | train | func WithCommitLog(options ...commitlog.OptionFunc) OptionFunc {
return func(n *Node) error {
clog, err := commitlog.New(options...)
n.clog = clog
return err
}
} | go | {
"resource": ""
} |
q14062 | WithResumeTimeout | train | func WithResumeTimeout(timeout time.Duration) OptionFunc {
return func(n *Node) error {
n.resumeTimeout = timeout
return nil
}
} | go | {
"resource": ""
} |
q14063 | WithWriteTimeout | train | func WithWriteTimeout(timeout string) OptionFunc {
return func(n *Node) error {
if timeout == "" {
n.writeTimeout = defaultWriteTimeout
return nil
}
wt, err := time.ParseDuration(timeout)
if err != nil {
return err
}
n.writeTimeout = wt
return nil
}
} | go | {
"resource": ""
} |
q14064 | WithOffsetManager | train | func WithOffsetManager(om offset.Manager) OptionFunc {
return func(n *Node) error {
n.om = om
return nil
}
} | go | {
"resource": ""
} |
q14065 | WithCompactionInterval | train | func WithCompactionInterval(interval string) OptionFunc {
return func(n *Node) error {
if interval == "" {
n.compactionInterval = defaultCompactionInterval
return nil
}
ci, err := time.ParseDuration(interval)
if err != nil {
return err
}
n.compactionInterval = ci
return nil
}
} | go | {
"resource": ""
} |
q14066 | start | train | func (n *Node) start(nsMap map[string]client.MessageSet) error {
n.l.Infoln("adaptor Starting...")
s, err := n.c.Connect()
if err != nil {
return err
}
if closer, ok := s.(client.Closer); ok {
defer func() {
n.l.Debugln("closing session...")
closer.Close()
n.l.Debugln("session closed...")
}()
}
r... | go | {
"resource": ""
} |
q14067 | Stop | train | func (n *Node) Stop() {
n.stop()
for _, node := range n.children {
node.Stop()
}
} | go | {
"resource": ""
} |
q14068 | Validate | train | func (n *Node) Validate() bool {
if n.parent == nil && len(n.children) == 0 { // the root node should have children
return false
}
for _, child := range n.children {
if !child.Validate() {
return false
}
}
return true
} | go | {
"resource": ""
} |
q14069 | Endpoints | train | func (n *Node) Endpoints() map[string]string {
m := map[string]string{n.Name: n.Type}
for _, child := range n.children {
childMap := child.Endpoints()
for k, v := range childMap {
m[k] = v
}
}
return m
} | go | {
"resource": ""
} |
q14070 | WithURI | train | func WithURI(uri string) ClientOptionFunc {
return func(c *Client) error {
_, err := url.Parse(c.uri)
if err != nil {
return client.InvalidURIError{URI: uri, Err: err.Error()}
}
c.uri = uri
return nil
}
} | go | {
"resource": ""
} |
q14071 | WithSessionTimeout | train | func WithSessionTimeout(timeout string) ClientOptionFunc {
return func(c *Client) error {
if timeout == "" {
c.sessionTimeout = DefaultTimeout
return nil
}
t, err := time.ParseDuration(timeout)
if err != nil {
return client.InvalidTimeoutError{Timeout: timeout}
}
c.sessionTimeout = t
return nil... | go | {
"resource": ""
} |
q14072 | WithWriteTimeout | train | func WithWriteTimeout(timeout string) ClientOptionFunc {
return func(c *Client) error {
if timeout == "" {
c.writeTimeout = DefaultTimeout
return nil
}
t, err := time.ParseDuration(timeout)
if err != nil {
return client.InvalidTimeoutError{Timeout: timeout}
}
c.writeTimeout = t
return nil
}
} | go | {
"resource": ""
} |
q14073 | WithReadTimeout | train | func WithReadTimeout(timeout string) ClientOptionFunc {
return func(c *Client) error {
if timeout == "" {
c.readTimeout = DefaultTimeout
return nil
}
t, err := time.ParseDuration(timeout)
if err != nil {
return client.InvalidTimeoutError{Timeout: timeout}
}
c.readTimeout = t
return nil
}
} | go | {
"resource": ""
} |
q14074 | Close | train | func (c *Client) Close() {
if c.session != nil {
c.session.Close(r.CloseOpts{NoReplyWait: false})
}
} | go | {
"resource": ""
} |
q14075 | From | train | func From(op ops.Op, namespace string, d data.Data) Msg {
return &Base{
Operation: op,
TS: time.Now().Unix(),
NS: namespace,
MapData: d,
confirm: nil,
}
} | go | {
"resource": ""
} |
q14076 | WithConfirms | train | func WithConfirms(confirm chan struct{}, msg Msg) Msg {
switch m := msg.(type) {
case *Base:
m.confirm = confirm
}
return msg
} | go | {
"resource": ""
} |
q14077 | ID | train | func (m *Base) ID() string {
if _, ok := m.MapData["_id"]; !ok {
return ""
}
switch id := m.MapData["_id"].(type) {
case string:
return id
case bson.ObjectId:
return id.Hex()
default:
return fmt.Sprintf("%v", id)
}
} | go | {
"resource": ""
} |
q14078 | prepareDocument | train | func prepareDocument(msg message.Msg) map[string]interface{} {
if _, ok := msg.Data()["id"]; ok {
return msg.Data()
}
if _, ok := msg.Data()["_id"]; ok {
msg.Data().Set("id", msg.ID())
msg.Data().Delete("_id")
}
return msg.Data()
} | go | {
"resource": ""
} |
q14079 | handleResponse | train | func handleResponse(resp *r.WriteResponse, confirms chan struct{}) error {
if resp.Errors != 0 {
if !strings.Contains(resp.FirstError, "Duplicate primary key") { // we don't care about this error
return fmt.Errorf("%s\n%s", "problem inserting docs", resp.FirstError)
}
}
if confirms != nil {
confirms <- stru... | go | {
"resource": ""
} |
q14080 | NewEmitter | train | func NewEmitter(listen chan Event, emit EmitFunc) Emitter {
return &emitter{
listenChan: listen,
emit: emit,
stop: make(chan struct{}),
started: false,
}
} | go | {
"resource": ""
} |
q14081 | Start | train | func (e *emitter) Start() {
if !e.started {
e.started = true
e.wg.Add(1)
go e.startEventListener(&e.wg)
}
} | go | {
"resource": ""
} |
q14082 | Stop | train | func (e *emitter) Stop() {
close(e.stop)
e.wg.Wait()
e.started = false
} | go | {
"resource": ""
} |
q14083 | HTTPPostEmitter | train | func HTTPPostEmitter(uri, key, pid string) EmitFunc {
return EmitFunc(func(event Event) error {
ba, err := event.Emit()
if err != nil {
return err
}
req, err := http.NewRequest("POST", uri, bytes.NewBuffer(ba))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
if le... | go | {
"resource": ""
} |
q14084 | GetAdaptor | train | func GetAdaptor(name string, conf Config) (Adaptor, error) {
creator, ok := adaptors[name]
if ok {
a := creator()
err := conf.Construct(a)
return a, err
}
return nil, ErrNotFound{name}
} | go | {
"resource": ""
} |
q14085 | RegisteredAdaptors | train | func RegisteredAdaptors() []string {
all := make([]string, 0)
for i := range adaptors {
all = append(all, i)
}
return all
} | go | {
"resource": ""
} |
q14086 | Adaptors | train | func Adaptors() map[string]Adaptor {
all := make(map[string]Adaptor)
for name, c := range adaptors {
a := c()
all[name] = a
}
return all
} | go | {
"resource": ""
} |
q14087 | NewSegment | train | func NewSegment(path, format string, baseOffset int64, maxBytes int64) (*Segment, error) {
logPath := filepath.Join(path, fmt.Sprintf(format, baseOffset))
log, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
s := &Segment{
log: log,
path: l... | go | {
"resource": ""
} |
q14088 | IsFull | train | func (s *Segment) IsFull() bool {
s.Lock()
defer s.Unlock()
return s.Position >= s.maxBytes
} | go | {
"resource": ""
} |
q14089 | ReadAt | train | func (s *Segment) ReadAt(p []byte, off int64) (n int, err error) {
s.Lock()
defer s.Unlock()
return s.log.ReadAt(p, off)
} | go | {
"resource": ""
} |
q14090 | FindOffsetPosition | train | func (s *Segment) FindOffsetPosition(offset uint64) (int64, error) {
if _, err := s.log.Seek(0, 0); err != nil {
return 0, err
}
var position int64
for {
b := new(bytes.Buffer)
// get offset and size
_, err := io.CopyN(b, s.log, 8)
if err != nil {
return position, ErrOffsetNotFound
}
o := encoding... | go | {
"resource": ""
} |
q14091 | Bytes | train | func (o Offset) Bytes() []byte {
valBytes := make([]byte, 8)
encoding.PutUint64(valBytes, o.LogOffset)
l := commitlog.NewLogFromEntry(commitlog.LogEntry{
Key: []byte(o.Namespace),
Value: valBytes,
Timestamp: uint64(o.Timestamp),
})
return l
} | go | {
"resource": ""
} |
q14092 | WithURI | train | func WithURI(uri string) ClientOptionFunc {
return func(c *Client) error {
_, err := url.Parse(uri)
c.uri = uri
return err
}
} | go | {
"resource": ""
} |
q14093 | Connect | train | func (c *Client) Connect() (client.Session, error) {
if c.pqSession == nil {
// there's really no way for this to error because we know the driver we're passing is
// available.
c.pqSession, _ = sql.Open("postgres", c.uri)
uri, _ := url.Parse(c.uri)
if uri.Path != "" {
c.db = uri.Path[1:]
}
}
err := c... | go | {
"resource": ""
} |
q14094 | ModeOpToByte | train | func (le LogEntry) ModeOpToByte() byte {
return byte(int(le.Mode) | (int(le.Op) << opShift))
} | go | {
"resource": ""
} |
q14095 | ReadEntry | train | func ReadEntry(r io.Reader) (uint64, LogEntry, error) {
header := make([]byte, logEntryHeaderLen)
if _, err := r.Read(header); err != nil {
return 0, LogEntry{}, err
}
k, v, err := readKeyValue(encoding.Uint32(header[sizePos:tsPos]), r)
if err != nil {
return 0, LogEntry{}, err
}
l := LogEntry{
Key: ... | go | {
"resource": ""
} |
q14096 | readKeyValue | train | func readKeyValue(size uint32, r io.Reader) ([]byte, []byte, error) {
kvBytes := make([]byte, size)
if _, err := r.Read(kvBytes); err != nil {
return nil, nil, err
}
keyLen := encoding.Uint32(kvBytes[0:4])
// we can grab the key from keyLen and the we know the value is stored
// after the keyLen + 8 (4 byte siz... | go | {
"resource": ""
} |
q14097 | Apply | train | func (g *goja) Apply(msg message.Msg) (message.Msg, error) {
if g.vm == nil {
if err := g.initVM(); err != nil {
return nil, err
}
}
return g.transformOne(msg)
} | go | {
"resource": ""
} |
q14098 | Profile | train | func (u *User) Profile() (interface{}, error) {
urlStr := GetApiBaseURL() + "/user/"
return u.c.execute("GET", urlStr, "")
} | go | {
"resource": ""
} |
q14099 | Emails | train | func (u *User) Emails() (interface{}, error) {
urlStr := GetApiBaseURL() + "/user/emails"
return u.c.execute("GET", urlStr, "")
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.