_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q20700
NewSource
train
func NewSource(ctx *plan.Context, p *plan.Source) (*Source, error) { if p.Stmt == nil { return nil, fmt.Errorf("must have from for Source") } if p.Conn == nil { return nil, fmt.Errorf("Must have existing connection on Plan") } scanner, hasScanner := p.Conn.(schema.ConnScanner) // Some sources require conte...
go
{ "resource": "" }
q20701
NewResultExecWriter
train
func NewResultExecWriter(ctx *plan.Context) *ResultExecWriter { m := &ResultExecWriter{ TaskBase: NewTaskBase(ctx), } m.Handler = func(ctx *plan.Context, msg schema.Message) bool { switch mt := msg.(type) { case *datasource.SqlDriverMessage: if len(mt.Vals) > 1 { m.lastInsertID = mt.Vals[0].(int64) ...
go
{ "resource": "" }
q20702
NewResultWriter
train
func NewResultWriter(ctx *plan.Context) *ResultWriter { m := &ResultWriter{ TaskBase: NewTaskBase(ctx), } m.Handler = resultWrite(m) return m }
go
{ "resource": "" }
q20703
NewResultRows
train
func NewResultRows(ctx *plan.Context, cols []string) *ResultWriter { stepper := NewTaskStepper(ctx) m := &ResultWriter{ TaskBase: stepper.TaskBase, cols: cols, } return m }
go
{ "resource": "" }
q20704
NewResultBuffer
train
func NewResultBuffer(ctx *plan.Context, writeTo *[]schema.Message) *ResultBuffer { m := &ResultBuffer{ TaskBase: NewTaskBase(ctx), } m.Handler = func(ctx *plan.Context, msg schema.Message) bool { *writeTo = append(*writeTo, msg) //u.Infof("write to msgs: %v", len(*writeTo)) return true } return m }
go
{ "resource": "" }
q20705
Result
train
func (m *ResultExecWriter) Result() driver.Result { return &qlbResult{m.lastInsertID, m.rowsAffected, m.err} }
go
{ "resource": "" }
q20706
NewJsonHandlerTables
train
func NewJsonHandlerTables(lh datasource.FileLineHandler, tables []string) FileHandler { return &jsonHandlerTables{ FileHandler: &jsonHandler{lh}, tables: tables, } }
go
{ "resource": "" }
q20707
Numeric
train
func (f *FieldType) Numeric() bool { if f.Type == value.NumberType || f.Type == value.IntType { return true } // If a nested field with numeric values it's numeric if f.Nested() { switch f.Type { case value.MapIntType, value.MapNumberType: return true } } // Nothing else is numeric return false }
go
{ "resource": "" }
q20708
Exec
train
func (m *qlbConn) Exec(query string, args []driver.Value) (driver.Result, error) { stmt := &qlbStmt{conn: m, query: query} return stmt.Exec(args) }
go
{ "resource": "" }
q20709
Query
train
func (m *qlbConn) Query(query string, args []driver.Value) (driver.Rows, error) { stmt := &qlbStmt{conn: m, query: query} return stmt.Query(args) }
go
{ "resource": "" }
q20710
Close
train
func (m *qlbStmt) Close() error { if m.job != nil { m.job.Close() } return nil }
go
{ "resource": "" }
q20711
Exec
train
func (m *qlbStmt) Exec(args []driver.Value) (driver.Result, error) { var err error if len(args) > 0 { m.query, err = queryArgsConvert(m.query, args) if err != nil { return nil, err } } // Create a Job, which is Dag of Tasks that Run() ctx := plan.NewContext(m.query) ctx.Schema = m.conn.schema job, err ...
go
{ "resource": "" }
q20712
Query
train
func (m *qlbStmt) Query(args []driver.Value) (driver.Rows, error) { var err error if len(args) > 0 { m.query, err = queryArgsConvert(m.query, args) if err != nil { return nil, err } } u.Debugf("query: %v", m.query) // Create a Job, which is Dag of Tasks that Run() ctx := plan.NewContext(m.query) ctx.Sc...
go
{ "resource": "" }
q20713
Application
train
func Application( funcs map[string]func([]string), scripts []string, loader func(string) ([]byte, error), copyEnv bool) { bashDir, err := homedir.Expand("~/.basher") if err != nil { log.Fatal(err, "1") } bashPath := bashDir + "/bash" if _, err := os.Stat(bashPath); os.IsNotExist(err) { err = RestoreAsset...
go
{ "resource": "" }
q20714
ApplicationWithPath
train
func ApplicationWithPath( funcs map[string]func([]string), scripts []string, loader func(string) ([]byte, error), copyEnv bool, bashPath string) { bash, err := NewContext(bashPath, os.Getenv("DEBUG") != "") if err != nil { log.Fatal(err) } for name, fn := range funcs { bash.ExportFunc(name, fn) } if bas...
go
{ "resource": "" }
q20715
NewContext
train
func NewContext(bashpath string, debug bool) (*Context, error) { executable, err := osext.Executable() if err != nil { return nil, err } return &Context{ Debug: debug, BashPath: bashpath, SelfPath: executable, Stdin: os.Stdin, Stdout: os.Stdout, Stderr: os.Stderr, scripts: make([][]byte, ...
go
{ "resource": "" }
q20716
CopyEnv
train
func (c *Context) CopyEnv() { c.Lock() defer c.Unlock() c.vars = append(c.vars, os.Environ()...) }
go
{ "resource": "" }
q20717
Source
train
func (c *Context) Source(filepath string, loader func(string) ([]byte, error)) error { if loader == nil { loader = ioutil.ReadFile } data, err := loader(filepath) if err != nil { return err } c.Lock() defer c.Unlock() c.scripts = append(c.scripts, data) return nil }
go
{ "resource": "" }
q20718
Export
train
func (c *Context) Export(name string, value string) { c.Lock() defer c.Unlock() c.vars = append(c.vars, name+"="+value) }
go
{ "resource": "" }
q20719
ExportFunc
train
func (c *Context) ExportFunc(name string, fn func([]string)) { c.Lock() defer c.Unlock() c.funcs[name] = fn }
go
{ "resource": "" }
q20720
HandleFuncs
train
func (c *Context) HandleFuncs(args []string) bool { for i, arg := range args { if arg == ":::" && len(args) > i+1 { c.Lock() defer c.Unlock() for cmd := range c.funcs { if cmd == args[i+1] { c.funcs[cmd](args[i+2:]) return true } } return false } } return false }
go
{ "resource": "" }
q20721
MustAsset
train
func MustAsset(name string) []byte { a, err := Asset(name) if (err != nil) { panic("asset: Asset(" + name + "): " + err.Error()) } return a }
go
{ "resource": "" }
q20722
createTrustedApplication
train
func createTrustedApplication(trustedApplication string) (C.CFTypeRef, error) { var trustedApplicationCStr *C.char if trustedApplication != "" { trustedApplicationCStr = C.CString(trustedApplication) defer C.free(unsafe.Pointer(trustedApplicationCStr)) } var trustedApplicationRef C.SecTrustedApplicationRef er...
go
{ "resource": "" }
q20723
Convert
train
func (a Access) Convert() (C.CFTypeRef, error) { return createAccess(a.Label, a.TrustedApplications) }
go
{ "resource": "" }
q20724
SetAccess
train
func (k *Item) SetAccess(a *Access) { if a != nil { k.attr[AccessKey] = a } else { delete(k.attr, AccessKey) } }
go
{ "resource": "" }
q20725
DeleteItemRef
train
func DeleteItemRef(ref C.CFTypeRef) error { errCode := C.SecKeychainItemDelete(C.SecKeychainItemRef(ref)) return checkError(errCode) }
go
{ "resource": "" }
q20726
NewKeychain
train
func NewKeychain(path string, password string) (Keychain, error) { return newKeychain(path, password, false) }
go
{ "resource": "" }
q20727
Status
train
func (kc Keychain) Status() error { // returns no error even if it doesn't exist kref, err := openKeychainRef(kc.path) if err != nil { return err } defer C.CFRelease(C.CFTypeRef(kref)) var status C.SecKeychainStatus return checkError(C.SecKeychainGetStatus(kref, &status)) }
go
{ "resource": "" }
q20728
openKeychainRef
train
func openKeychainRef(path string) (C.SecKeychainRef, error) { pathName := C.CString(path) defer C.free(unsafe.Pointer(pathName)) var kref C.SecKeychainRef if err := checkError(C.SecKeychainOpen(pathName, &kref)); err != nil { return 0, err } return kref, nil }
go
{ "resource": "" }
q20729
UnlockAtPath
train
func UnlockAtPath(path string, password string) error { kref, err := openKeychainRef(path) defer Release(C.CFTypeRef(kref)) if err != nil { return err } passwordRef := C.CString(password) defer C.free(unsafe.Pointer(passwordRef)) return checkError(C.SecKeychainUnlock(kref, C.UInt32(len(password)), unsafe.Point...
go
{ "resource": "" }
q20730
LockAtPath
train
func LockAtPath(path string) error { kref, err := openKeychainRef(path) defer Release(C.CFTypeRef(kref)) if err != nil { return err } return checkError(C.SecKeychainLock(kref)) }
go
{ "resource": "" }
q20731
Convert
train
func (kc Keychain) Convert() (C.CFTypeRef, error) { keyRef, err := openKeychainRef(kc.path) return C.CFTypeRef(keyRef), err }
go
{ "resource": "" }
q20732
Convert
train
func (ka keychainArray) Convert() (C.CFTypeRef, error) { var refs = make([]C.CFTypeRef, len(ka)) var err error for idx, kc := range ka { if refs[idx], err = kc.Convert(); err != nil { // If we error trying to convert lets release any we converted before for _, ref := range refs { if ref != 0 { Rele...
go
{ "resource": "" }
q20733
SetMatchSearchList
train
func (k *Item) SetMatchSearchList(karr ...Keychain) { k.attr[MatchSearchListKey] = keychainArray(karr) }
go
{ "resource": "" }
q20734
AddGenericPassword
train
func AddGenericPassword(service string, account string, label string, password string, accessGroup string) error { item := keychain.NewGenericPassword(service, account, label, []byte(password), accessGroup) return keychain.AddItem(item) }
go
{ "resource": "" }
q20735
DeleteGenericPassword
train
func DeleteGenericPassword(service string, account string, accessGroup string) error { item := keychain.NewItem() item.SetSecClass(keychain.SecClassGenericPassword) item.SetService(service) item.SetAccount(account) item.SetAccessGroup(accessGroup) return keychain.DeleteItem(item) }
go
{ "resource": "" }
q20736
PromptAndWait
train
func (s *SecretService) PromptAndWait(prompt dbus.ObjectPath) (paths *dbus.Variant, err error) { if prompt == NullPrompt { return nil, nil } call := s.Obj(prompt).Call("org.freedesktop.Secret.Prompt.Prompt", NilFlags, "Keyring Prompt") if call.Err != nil { return nil, errors.Wrap(err, "failed to prompt") } fo...
go
{ "resource": "" }
q20737
CFDateToTime
train
func CFDateToTime(d C.CFDateRef) time.Time { abs := C.CFDateGetAbsoluteTime(d) s, ns := absoluteTimeToUnix(abs) return time.Unix(s, ns) }
go
{ "resource": "" }
q20738
CFDataToBytes
train
func CFDataToBytes(cfData C.CFDataRef) ([]byte, error) { return C.GoBytes(unsafe.Pointer(C.CFDataGetBytePtr(cfData)), C.int(C.CFDataGetLength(cfData))), nil }
go
{ "resource": "" }
q20739
CFStringToString
train
func CFStringToString(s C.CFStringRef) string { p := C.CFStringGetCStringPtr(s, C.kCFStringEncodingUTF8) if p != nil { return C.GoString(p) } length := C.CFStringGetLength(s) if length == 0 { return "" } maxBufLen := C.CFStringGetMaximumSizeForEncoding(length, C.kCFStringEncodingUTF8) if maxBufLen == 0 { ...
go
{ "resource": "" }
q20740
CFTypeDescription
train
func CFTypeDescription(ref C.CFTypeRef) string { typeID := C.CFGetTypeID(ref) typeDesc := C.CFCopyTypeIDDescription(typeID) defer Release(C.CFTypeRef(typeDesc)) return CFStringToString(typeDesc) }
go
{ "resource": "" }
q20741
Convert
train
func Convert(ref C.CFTypeRef) (interface{}, error) { typeID := C.CFGetTypeID(ref) if typeID == C.CFStringGetTypeID() { return CFStringToString(C.CFStringRef(ref)), nil } else if typeID == C.CFDictionaryGetTypeID() { return ConvertCFDictionary(C.CFDictionaryRef(ref)) } else if typeID == C.CFArrayGetTypeID() { ...
go
{ "resource": "" }
q20742
RandBytes
train
func RandBytes(length int) ([]byte, error) { buf := make([]byte, length) if _, err := randRead(buf); err != nil { return nil, err } return buf, nil }
go
{ "resource": "" }
q20743
CFDictionaryToMap
train
func CFDictionaryToMap(cfDict C.CFDictionaryRef) (m map[C.CFTypeRef]uintptr) { count := C.CFDictionaryGetCount(cfDict) if count > 0 { keys := make([]C.CFTypeRef, count) values := make([]C.CFTypeRef, count) C.CFDictionaryGetKeysAndValues(cfDict, (*unsafe.Pointer)(&keys[0]), (*unsafe.Pointer)(&values[0])) m = m...
go
{ "resource": "" }
q20744
CFArrayToArray
train
func CFArrayToArray(cfArray C.CFArrayRef) (a []C.CFTypeRef) { count := C.CFArrayGetCount(cfArray) if count > 0 { a = make([]C.CFTypeRef, count) C.CFArrayGetValues(cfArray, C.CFRange{0, count}, (*unsafe.Pointer)(&a[0])) } return }
go
{ "resource": "" }
q20745
SetSecClass
train
func (k *Item) SetSecClass(sc SecClass) { k.attr[SecClassKey] = secClassTypeRef[sc] }
go
{ "resource": "" }
q20746
SetString
train
func (k *Item) SetString(key string, s string) { if s != "" { k.attr[key] = s } else { delete(k.attr, key) } }
go
{ "resource": "" }
q20747
SetData
train
func (k *Item) SetData(b []byte) { if b != nil { k.attr[DataKey] = b } else { delete(k.attr, DataKey) } }
go
{ "resource": "" }
q20748
SetSynchronizable
train
func (k *Item) SetSynchronizable(sync Synchronizable) { if sync != SynchronizableDefault { k.attr[SynchronizableKey] = syncTypeRef[sync] } else { delete(k.attr, SynchronizableKey) } }
go
{ "resource": "" }
q20749
SetAccessible
train
func (k *Item) SetAccessible(accessible Accessible) { if accessible != AccessibleDefault { k.attr[AccessibleKey] = accessibleTypeRef[accessible] } else { delete(k.attr, AccessibleKey) } }
go
{ "resource": "" }
q20750
SetMatchLimit
train
func (k *Item) SetMatchLimit(matchLimit MatchLimit) { if matchLimit != MatchLimitDefault { k.attr[MatchLimitKey] = matchTypeRef[matchLimit] } else { delete(k.attr, MatchLimitKey) } }
go
{ "resource": "" }
q20751
NewGenericPassword
train
func NewGenericPassword(service string, account string, label string, data []byte, accessGroup string) Item { item := NewItem() item.SetSecClass(SecClassGenericPassword) item.SetService(service) item.SetAccount(account) item.SetLabel(label) item.SetData(data) item.SetAccessGroup(accessGroup) return item }
go
{ "resource": "" }
q20752
AddItem
train
func AddItem(item Item) error { cfDict, err := ConvertMapToCFDictionary(item.attr) if err != nil { return err } defer Release(C.CFTypeRef(cfDict)) errCode := C.SecItemAdd(cfDict, nil) err = checkError(errCode) return err }
go
{ "resource": "" }
q20753
UpdateItem
train
func UpdateItem(queryItem Item, updateItem Item) error { cfDict, err := ConvertMapToCFDictionary(queryItem.attr) if err != nil { return err } defer Release(C.CFTypeRef(cfDict)) cfDictUpdate, err := ConvertMapToCFDictionary(updateItem.attr) if err != nil { return err } defer Release(C.CFTypeRef(cfDictUpdate)...
go
{ "resource": "" }
q20754
DeleteGenericPasswordItem
train
func DeleteGenericPasswordItem(service string, account string) error { item := NewItem() item.SetSecClass(SecClassGenericPassword) item.SetService(service) item.SetAccount(account) return DeleteItem(item) }
go
{ "resource": "" }
q20755
DeleteItem
train
func DeleteItem(item Item) error { cfDict, err := ConvertMapToCFDictionary(item.attr) if err != nil { return err } defer Release(C.CFTypeRef(cfDict)) errCode := C.SecItemDelete(cfDict) return checkError(errCode) }
go
{ "resource": "" }
q20756
GetGenericPasswordAccounts
train
func GetGenericPasswordAccounts(service string) ([]string, error) { query := NewItem() query.SetSecClass(SecClassGenericPassword) query.SetService(service) query.SetMatchLimit(MatchLimitAll) query.SetReturnAttributes(true) results, err := QueryItem(query) if err != nil { return nil, err } accounts := make([...
go
{ "resource": "" }
q20757
GetGenericPassword
train
func GetGenericPassword(service string, account string, label string, accessGroup string) ([]byte, error) { query := NewItem() query.SetSecClass(SecClassGenericPassword) query.SetService(service) query.SetAccount(account) query.SetLabel(label) query.SetAccessGroup(accessGroup) query.SetMatchLimit(MatchLimitOne) ...
go
{ "resource": "" }
q20758
createAccess
train
func createAccess(label string, trustedApplications []string) (C.CFTypeRef, error) { var err error var labelRef C.CFStringRef if labelRef, err = StringToCFString(label); err != nil { return nil, err } defer C.CFRelease(C.CFTypeRef(labelRef)) var trustedApplicationsArray C.CFArrayRef if trustedApplications != ...
go
{ "resource": "" }
q20759
QueryItemRef
train
func QueryItemRef(item Item) (C.CFTypeRef, error) { cfDict, err := ConvertMapToCFDictionary(item.attr) if err != nil { return nil, err } defer Release(C.CFTypeRef(cfDict)) var resultsRef C.CFTypeRef errCode := C.SecItemCopyMatching(cfDict, &resultsRef) if Error(errCode) == ErrorItemNotFound { return nil, ni...
go
{ "resource": "" }
q20760
QueryItem
train
func QueryItem(item Item) ([]QueryResult, error) { resultsRef, err := QueryItemRef(item) if err != nil { return nil, err } if resultsRef == nil { return nil, nil } defer Release(resultsRef) results := make([]QueryResult, 0, 1) typeID := C.CFGetTypeID(resultsRef) if typeID == C.CFArrayGetTypeID() { arr ...
go
{ "resource": "" }
q20761
NewClientCodec
train
func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec { return NewCodec(true, true, conn) }
go
{ "resource": "" }
q20762
NewServerCodec
train
func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec { return NewCodec(true, true, conn) }
go
{ "resource": "" }
q20763
NewCodec
train
func NewCodec(bufReads, bufWrites bool, conn io.ReadWriteCloser) *MsgpackCodec { return NewCodecFromHandle(bufReads, bufWrites, conn, msgpackHandle) }
go
{ "resource": "" }
q20764
NewCodecFromHandle
train
func NewCodecFromHandle(bufReads, bufWrites bool, conn io.ReadWriteCloser, h *codec.MsgpackHandle) *MsgpackCodec { cc := &MsgpackCodec{ conn: conn, } if bufReads { cc.bufR = bufio.NewReader(conn) cc.dec = codec.NewDecoder(cc.bufR, h) } else { cc.dec = codec.NewDecoder(cc.conn, h) } if bufWrites { cc.bu...
go
{ "resource": "" }
q20765
XGoogHeader
train
func XGoogHeader(keyval ...string) string { if len(keyval) == 0 { return "" } if len(keyval)%2 != 0 { panic("gax.Header: odd argument count") } var buf bytes.Buffer for i := 0; i < len(keyval); i += 2 { buf.WriteByte(' ') buf.WriteString(keyval[i]) buf.WriteByte('/') buf.WriteString(keyval[i+1]) } r...
go
{ "resource": "" }
q20766
invoke
train
func invoke(ctx context.Context, call APICall, settings CallSettings, sp sleeper) error { var retryer Retryer for { err := call(ctx, settings) if err == nil { return nil } if settings.Retry == nil { return err } // Never retry permanent certificate errors. (e.x. if ca-certificates // are not insta...
go
{ "resource": "" }
q20767
Pause
train
func (bo *Backoff) Pause() time.Duration { if bo.Initial == 0 { bo.Initial = time.Second } if bo.cur == 0 { bo.cur = bo.Initial } if bo.Max == 0 { bo.Max = 30 * time.Second } if bo.Multiplier < 1 { bo.Multiplier = 2 } // Select a duration between 1ns and the current max. It might seem // counterintuit...
go
{ "resource": "" }
q20768
WithGRPCOptions
train
func WithGRPCOptions(opt ...grpc.CallOption) CallOption { return grpcOpt(append([]grpc.CallOption(nil), opt...)) }
go
{ "resource": "" }
q20769
Run
train
func Run(client RedisClient, key string, opts *Options, handler func()) error { locker, err := Obtain(client, key, opts) if err != nil { return err } sem := make(chan struct{}) go func() { handler() close(sem) }() select { case <-sem: return locker.Unlock() case <-time.After(locker.opts.LockTimeout):...
go
{ "resource": "" }
q20770
New
train
func New(client RedisClient, key string, opts *Options) *Locker { var o Options if opts != nil { o = *opts } o.normalize() return &Locker{client: client, key: key, opts: o} }
go
{ "resource": "" }
q20771
IsLocked
train
func (l *Locker) IsLocked() bool { l.mutex.Lock() locked := l.token != "" l.mutex.Unlock() return locked }
go
{ "resource": "" }
q20772
LockWithContext
train
func (l *Locker) LockWithContext(ctx context.Context) (bool, error) { l.mutex.Lock() defer l.mutex.Unlock() if l.token != "" { return l.refresh(ctx) } return l.create(ctx) }
go
{ "resource": "" }
q20773
Unlock
train
func (l *Locker) Unlock() error { l.mutex.Lock() err := l.release() l.mutex.Unlock() return err }
go
{ "resource": "" }
q20774
Field
train
func (entry *Entry) Field(name string) (value string, err error) { value, ok := entry.fields[name] if !ok { err = fmt.Errorf("field '%v' does not found in record %+v", name, *entry) } return }
go
{ "resource": "" }
q20775
FloatField
train
func (entry *Entry) FloatField(name string) (value float64, err error) { tmp, err := entry.Field(name) if err == nil { value, err = strconv.ParseFloat(tmp, 64) } return }
go
{ "resource": "" }
q20776
SetField
train
func (entry *Entry) SetField(name string, value string) { entry.fields[name] = value }
go
{ "resource": "" }
q20777
SetFloatField
train
func (entry *Entry) SetFloatField(name string, value float64) { entry.SetField(name, strconv.FormatFloat(value, 'f', 2, 64)) }
go
{ "resource": "" }
q20778
SetUintField
train
func (entry *Entry) SetUintField(name string, value uint64) { entry.SetField(name, strconv.FormatUint(uint64(value), 10)) }
go
{ "resource": "" }
q20779
Merge
train
func (entry *Entry) Merge(merge *Entry) { for name, value := range merge.fields { entry.SetField(name, value) } }
go
{ "resource": "" }
q20780
FieldsHash
train
func (entry *Entry) FieldsHash(fields []string) string { var key []string for _, name := range fields { value, err := entry.Field(name) if err != nil { value = "NULL" } key = append(key, fmt.Sprintf("'%v'=%v", name, value)) } return strings.Join(key, ";") }
go
{ "resource": "" }
q20781
Partial
train
func (entry *Entry) Partial(fields []string) *Entry { partial := NewEmptyEntry() for _, name := range fields { value, _ := entry.Field(name) partial.SetField(name, value) } return partial }
go
{ "resource": "" }
q20782
NewReader
train
func NewReader(logFile io.Reader, format string) *Reader { return NewParserReader(logFile, NewParser(format)) }
go
{ "resource": "" }
q20783
NewParserReader
train
func NewParserReader(logFile io.Reader, parser StringParser) *Reader { return &Reader{ file: logFile, parser: parser, } }
go
{ "resource": "" }
q20784
NewNginxReader
train
func NewNginxReader(logFile io.Reader, nginxConf io.Reader, formatName string) (reader *Reader, err error) { parser, err := NewNginxParser(nginxConf, formatName) if err != nil { return nil, err } reader = &Reader{ file: logFile, parser: parser, } return }
go
{ "resource": "" }
q20785
Read
train
func (r *Reader) Read() (entry *Entry, err error) { if r.entries == nil { r.entries = MapReduce(r.file, r.parser, new(ReadAll)) } entry, ok := <-r.entries if !ok { err = io.EOF } return }
go
{ "resource": "" }
q20786
NewParser
train
func NewParser(format string) *Parser { // First split up multiple concatenated fields with placeholder placeholder := " _PLACEHOLDER___ " preparedFormat := format concatenatedRe := regexp.MustCompile(`[A-Za-z0-9_]\$[A-Za-z0-9_]`) for concatenatedRe.MatchString(preparedFormat) { preparedFormat = regexp.MustCompi...
go
{ "resource": "" }
q20787
ParseString
train
func (parser *Parser) ParseString(line string) (entry *Entry, err error) { re := parser.regexp fields := re.FindStringSubmatch(line) if fields == nil { err = fmt.Errorf("access log line '%v' does not match given format '%v'", line, re) return } // Iterate over subexp foung and fill the map record entry = New...
go
{ "resource": "" }
q20788
NewNginxParser
train
func NewNginxParser(conf io.Reader, name string) (parser *Parser, err error) { scanner := bufio.NewScanner(conf) re := regexp.MustCompile(fmt.Sprintf(`^\s*log_format\s+%v\s+(.+)\s*$`, name)) found := false var format string for scanner.Scan() { var line string if !found { // Find a log_format definition ...
go
{ "resource": "" }
q20789
MapReduce
train
func MapReduce(file io.Reader, parser StringParser, reducer Reducer) chan *Entry { // Input file lines. This channel is unbuffered to publish // next line to handle only when previous is taken by mapper. var lines = make(chan string) // Host thread to spawn new mappers var entries = make(chan *Entry, 10) go func...
go
{ "resource": "" }
q20790
Filter
train
func (i *Datetime) Filter(entry *Entry) (validEntry *Entry) { val, err := entry.Field(i.Field) if err != nil { // TODO handle error return } t, err := time.Parse(i.Format, val) if err != nil { // TODO handle error return } if i.withinBounds(t) { validEntry = entry } return }
go
{ "resource": "" }
q20791
Reduce
train
func (i *Datetime) Reduce(input chan *Entry, output chan *Entry) { for entry := range input { if valid := i.Filter(entry); valid != nil { output <- valid } } close(output) }
go
{ "resource": "" }
q20792
Reduce
train
func (r *ReadAll) Reduce(input chan *Entry, output chan *Entry) { for entry := range input { output <- entry } close(output) }
go
{ "resource": "" }
q20793
Reduce
train
func (r *Count) Reduce(input chan *Entry, output chan *Entry) { var count uint64 for { _, ok := <-input if !ok { break } count++ } entry := NewEmptyEntry() entry.SetUintField("count", count) output <- entry close(output) }
go
{ "resource": "" }
q20794
Reduce
train
func (r *Sum) Reduce(input chan *Entry, output chan *Entry) { sum := make(map[string]float64) for entry := range input { for _, name := range r.Fields { val, err := entry.FloatField(name) if err == nil { sum[name] += val } } } entry := NewEmptyEntry() for name, val := range sum { entry.SetFloatF...
go
{ "resource": "" }
q20795
NewChain
train
func NewChain(reducers ...Reducer) *Chain { chain := new(Chain) for _, r := range reducers { if f, ok := interface{}(r).(Filter); ok { chain.filters = append(chain.filters, f) } else { chain.reducers = append(chain.reducers, r) } } return chain }
go
{ "resource": "" }
q20796
Reduce
train
func (r *Chain) Reduce(input chan *Entry, output chan *Entry) { // Make input and output channel for each reducer subInput := make([]chan *Entry, len(r.reducers)) subOutput := make([]chan *Entry, len(r.reducers)) for i, reducer := range r.reducers { subInput[i] = make(chan *Entry, cap(input)) subOutput[i] = mak...
go
{ "resource": "" }
q20797
NewGroupBy
train
func NewGroupBy(fields []string, reducers ...Reducer) *GroupBy { return &GroupBy{ Fields: fields, reducers: reducers, } }
go
{ "resource": "" }
q20798
Reduce
train
func (r *GroupBy) Reduce(input chan *Entry, output chan *Entry) { subInput := make(map[string]chan *Entry) subOutput := make(map[string]chan *Entry) // Read reducer master input channel and create discinct input chanel // for each entry key we group by for entry := range input { key := entry.FieldsHash(r.Fields...
go
{ "resource": "" }
q20799
destroy
train
func (vn *VecN) destroy() { if vn == nil || vn.vec == nil { return } if shouldPool { returnToPool(vn.vec) } vn.vec = nil }
go
{ "resource": "" }