_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q14900
Log
train
func (l *Logger) Log(level Level, v ...interface{}) { l.print(level, fmt.Sprint(v...), l.NewLine) }
go
{ "resource": "" }
q14901
Errorf
train
func (l *Logger) Errorf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Error(msg) }
go
{ "resource": "" }
q14902
Warnf
train
func (l *Logger) Warnf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Warn(msg) }
go
{ "resource": "" }
q14903
Infof
train
func (l *Logger) Infof(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) l.Info(msg) }
go
{ "resource": "" }
q14904
Debugf
train
func (l *Logger) Debugf(format string, args ...interface{}) { // On debug mode don't even try to fmt.Sprintf if it's not required, // this can be used to allow `Debugf` to be called without even the `fmt.Sprintf`'s // performance cost if the logger doesn't allow debug logging. if l.Level >= DebugLevel { msg := fmt.Sprintf(format, args...) l.Debug(msg) } }
go
{ "resource": "" }
q14905
Handle
train
func (l *Logger) Handle(handler Handler) { l.mu.Lock() l.handlers = append(l.handlers, handler) l.mu.Unlock() }
go
{ "resource": "" }
q14906
Hijack
train
func (l *Logger) Hijack(hijacker func(ctx *pio.Ctx)) { l.Printer.Hijack(hijacker) }
go
{ "resource": "" }
q14907
Scan
train
func (l *Logger) Scan(r io.Reader) (cancel func()) { l.once.Do(func() { // add a marshaler once // in order to handle []byte and string // as its input. // Because scan doesn't care about // logging levels (because of the io.Reader) // Note: We don't use the `pio.Text` built'n marshaler // because we want to manage time log too. l.Printer.MarshalFunc(func(v interface{}) ([]byte, error) { var line []byte if b, ok := v.([]byte); ok { line = b } else if s, ok := v.(string); ok { line = []byte(s) } if len(line) == 0 { return nil, pio.ErrMarshalNotResponsible } formattedTime := time.Now().Format(l.TimeFormat) if formattedTime != "" { line = append([]byte(formattedTime+" "), line...) } return line, nil }) }) return l.Printer.Scan(r, true) }
go
{ "resource": "" }
q14908
Clone
train
func (l *Logger) Clone() *Logger { return &Logger{ Prefix: l.Prefix, Level: l.Level, TimeFormat: l.TimeFormat, Printer: l.Printer, handlers: l.handlers, children: newLoggerMap(), mu: sync.Mutex{}, once: sync.Once{}, } }
go
{ "resource": "" }
q14909
FormatTime
train
func (l Log) FormatTime() string { if l.Logger.TimeFormat == "" { return "" } return l.Time.Format(l.Logger.TimeFormat) }
go
{ "resource": "" }
q14910
SetWordList
train
func SetWordList(list []string) { wordList = list wordMap = map[string]int{} for i, v := range wordList { wordMap[v] = i } }
go
{ "resource": "" }
q14911
GetWordIndex
train
func GetWordIndex(word string) (int, bool) { idx, ok := wordMap[word] return idx, ok }
go
{ "resource": "" }
q14912
EntropyFromMnemonic
train
func EntropyFromMnemonic(mnemonic string) ([]byte, error) { mnemonicSlice, isValid := splitMnemonicWords(mnemonic) if !isValid { return nil, ErrInvalidMnemonic } // Decode the words into a big.Int. b := big.NewInt(0) for _, v := range mnemonicSlice { index, found := wordMap[v] if found == false { return nil, fmt.Errorf("word `%v` not found in reverse map", v) } var wordBytes [2]byte binary.BigEndian.PutUint16(wordBytes[:], uint16(index)) b = b.Mul(b, shift11BitsMask) b = b.Or(b, big.NewInt(0).SetBytes(wordBytes[:])) } // Build and add the checksum to the big.Int. checksum := big.NewInt(0) checksumMask := wordLengthChecksumMasksMapping[len(mnemonicSlice)] checksum = checksum.And(b, checksumMask) b.Div(b, big.NewInt(0).Add(checksumMask, bigOne)) // The entropy is the underlying bytes of the big.Int. Any upper bytes of // all 0's are not returned so we pad the beginning of the slice with empty // bytes if necessary. entropy := b.Bytes() entropy = padByteSlice(entropy, len(mnemonicSlice)/3*4) // Generate the checksum and compare with the one we got from the mneomnic. entropyChecksumBytes := computeChecksum(entropy) entropyChecksum := big.NewInt(int64(entropyChecksumBytes[0])) if l := len(mnemonicSlice); l != 24 { checksumShift := wordLengthChecksumShiftMapping[l] entropyChecksum.Div(entropyChecksum, checksumShift) } if checksum.Cmp(entropyChecksum) != 0 { return nil, ErrChecksumIncorrect } return entropy, nil }
go
{ "resource": "" }
q14913
NewMnemonic
train
func NewMnemonic(entropy []byte) (string, error) { // Compute some lengths for convenience. entropyBitLength := len(entropy) * 8 checksumBitLength := entropyBitLength / 32 sentenceLength := (entropyBitLength + checksumBitLength) / 11 // Validate that the requested size is supported. err := validateEntropyBitSize(entropyBitLength) if err != nil { return "", err } // Add checksum to entropy. entropy = addChecksum(entropy) // Break entropy up into sentenceLength chunks of 11 bits. // For each word AND mask the rightmost 11 bits and find the word at that index. // Then bitshift entropy 11 bits right and repeat. // Add to the last empty slot so we can work with LSBs instead of MSB. // Entropy as an int so we can bitmask without worrying about bytes slices. entropyInt := new(big.Int).SetBytes(entropy) // Slice to hold words in. words := make([]string, sentenceLength) // Throw away big.Int for AND masking. word := big.NewInt(0) for i := sentenceLength - 1; i >= 0; i-- { // Get 11 right most bits and bitshift 11 to the right for next time. word.And(entropyInt, last11BitsMask) entropyInt.Div(entropyInt, shift11BitsMask) // Get the bytes representing the 11 bits as a 2 byte slice. wordBytes := padByteSlice(word.Bytes(), 2) // Convert bytes to an index and add that word to the list. words[i] = wordList[binary.BigEndian.Uint16(wordBytes)] } return strings.Join(words, " "), nil }
go
{ "resource": "" }
q14914
MnemonicToByteArray
train
func MnemonicToByteArray(mnemonic string, raw ...bool) ([]byte, error) { var ( mnemonicSlice = strings.Split(mnemonic, " ") entropyBitSize = len(mnemonicSlice) * 11 checksumBitSize = entropyBitSize % 32 fullByteSize = (entropyBitSize-checksumBitSize)/8 + 1 checksumByteSize = fullByteSize - (fullByteSize % 4) ) // Pre validate that the mnemonic is well formed and only contains words that // are present in the word list. if !IsMnemonicValid(mnemonic) { return nil, ErrInvalidMnemonic } // Convert word indices to a big.Int representing the entropy. checksummedEntropy := big.NewInt(0) modulo := big.NewInt(2048) for _, v := range mnemonicSlice { index := big.NewInt(int64(wordMap[v])) checksummedEntropy.Mul(checksummedEntropy, modulo) checksummedEntropy.Add(checksummedEntropy, index) } // Calculate the unchecksummed entropy so we can validate that the checksum is // correct. checksumModulo := big.NewInt(0).Exp(bigTwo, big.NewInt(int64(checksumBitSize)), nil) rawEntropy := big.NewInt(0).Div(checksummedEntropy, checksumModulo) // Convert big.Ints to byte padded byte slices. rawEntropyBytes := padByteSlice(rawEntropy.Bytes(), checksumByteSize) checksummedEntropyBytes := padByteSlice(checksummedEntropy.Bytes(), fullByteSize) // Validate that the checksum is correct. newChecksummedEntropyBytes := padByteSlice(addChecksum(rawEntropyBytes), fullByteSize) if !compareByteSlices(checksummedEntropyBytes, newChecksummedEntropyBytes) { return nil, ErrChecksumIncorrect } if len(raw) > 0 && raw[0] { return rawEntropyBytes, nil } return checksummedEntropyBytes, nil }
go
{ "resource": "" }
q14915
NewSeedWithErrorChecking
train
func NewSeedWithErrorChecking(mnemonic string, password string) ([]byte, error) { _, err := MnemonicToByteArray(mnemonic) if err != nil { return nil, err } return NewSeed(mnemonic, password), nil }
go
{ "resource": "" }
q14916
NewSeed
train
func NewSeed(mnemonic string, password string) []byte { return pbkdf2.Key([]byte(mnemonic), []byte("mnemonic"+password), 2048, 64, sha512.New) }
go
{ "resource": "" }
q14917
IsMnemonicValid
train
func IsMnemonicValid(mnemonic string) bool { // Create a list of all the words in the mnemonic sentence words := strings.Fields(mnemonic) // Get word count wordCount := len(words) // The number of words should be 12, 15, 18, 21 or 24 if wordCount%3 != 0 || wordCount < 12 || wordCount > 24 { return false } // Check if all words belong in the wordlist for _, word := range words { if _, ok := wordMap[word]; !ok { return false } } return true }
go
{ "resource": "" }
q14918
padByteSlice
train
func padByteSlice(slice []byte, length int) []byte { offset := length - len(slice) if offset <= 0 { return slice } newSlice := make([]byte, length) copy(newSlice[offset:], slice) return newSlice }
go
{ "resource": "" }
q14919
New
train
func New(host, authtoken string) (*TCP, error) { client := &TCP{ host: host, messages: make(chan mist.Message), token: authtoken, } return client, client.connect() }
go
{ "resource": "" }
q14920
connect
train
func (c *TCP) connect() error { // attempt to connect to the server conn, err := net.Dial("tcp", c.host) if err != nil { return fmt.Errorf("Failed to dial '%s' - %s", c.host, err.Error()) } // set the connection for the client c.conn = conn // create a new json encoder for the clients connection c.encoder = json.NewEncoder(c.conn) // if the client was created with a token, authentication is needed if c.token != "" { err = c.encoder.Encode(&mist.Message{Command: "auth", Data: c.token}) if err != nil { return fmt.Errorf("Failed to send auth - %s", err.Error()) } } // ensure we are authorized/still connected (unauthorized clients get disconnected) c.Ping() decoder := json.NewDecoder(conn) msg := mist.Message{} if err := decoder.Decode(&msg); err != nil { conn.Close() close(c.messages) return fmt.Errorf("Ping failed, possibly bad token, or can't read from mist - %s", err.Error()) } // connection loop (blocking); continually read off the connection. Once something // is read, check to see if it's a message the client understands to be one of // its commands. If so attempt to execute the command. go func() { for { msg := mist.Message{} // decode an array value (Message) if err := decoder.Decode(&msg); err != nil { switch err { case io.EOF: lumber.Debug("[mist client] Mist terminated connection") case io.ErrUnexpectedEOF: lumber.Debug("[mist client] Mist terminated connection unexpectedly") default: lumber.Error("[mist client] Failed to get message from mist - %s", err.Error()) } conn.Close() close(c.messages) return } c.messages <- msg // read from this using the .Messages() function lumber.Trace("[mist client] Received message - %#v", msg) } }() return nil }
go
{ "resource": "" }
q14921
Ping
train
func (c *TCP) Ping() error { return c.encoder.Encode(&mist.Message{Command: "ping"}) }
go
{ "resource": "" }
q14922
Subscribe
train
func (c *TCP) Subscribe(tags []string) error { if len(tags) == 0 { return fmt.Errorf("Unable to subscribe - missing tags") } return c.encoder.Encode(&mist.Message{Command: "subscribe", Tags: tags}) }
go
{ "resource": "" }
q14923
Publish
train
func (c *TCP) Publish(tags []string, data string) error { if len(tags) == 0 { return fmt.Errorf("Unable to publish - missing tags") } if data == "" { return fmt.Errorf("Unable to publish - missing data") } return c.encoder.Encode(&mist.Message{Command: "publish", Tags: tags, Data: data}) }
go
{ "resource": "" }
q14924
PublishAfter
train
func (c *TCP) PublishAfter(tags []string, data string, delay time.Duration) error { go func() { <-time.After(delay) c.Publish(tags, data) }() return nil }
go
{ "resource": "" }
q14925
handleListAll
train
func handleListAll(proxy *mist.Proxy, msg mist.Message) error { subscriptions := mist.Subscribers() proxy.Pipe <- mist.Message{Command: "listall", Tags: msg.Tags, Data: subscriptions} return nil }
go
{ "resource": "" }
q14926
handleWho
train
func handleWho(proxy *mist.Proxy, msg mist.Message) error { who, max := mist.Who() subscribers := fmt.Sprintf("Lifetime connections: %d\nSubscribers connected: %d", max, who) proxy.Pipe <- mist.Message{Command: "who", Tags: msg.Tags, Data: subscribers} return nil }
go
{ "resource": "" }
q14927
findMemoryToken
train
func (a memory) findMemoryToken(token string) (mapset.Set, error) { // look for existing token entry, ok := a[token] if !ok { return nil, ErrTokenNotFound } return entry, nil }
go
{ "resource": "" }
q14928
List
train
func (p *Proxy) List() (data [][]string) { lumber.Trace("Proxy listing subscriptions...") p.RLock() data = p.subscriptions.ToSlice() p.RUnlock() return }
go
{ "resource": "" }
q14929
Register
train
func Register(name string, auth handleFunc) { serversTex.Lock() servers[name] = auth serversTex.Unlock() }
go
{ "resource": "" }
q14930
Add
train
func (node *Node) Add(keys []string) { if len(keys) == 0 { return } sort.Strings(keys) node.add(keys) }
go
{ "resource": "" }
q14931
Remove
train
func (node *Node) Remove(keys []string) { if len(keys) == 0 { return } sort.Strings(keys) node.remove(keys) }
go
{ "resource": "" }
q14932
Match
train
func (node *Node) Match(keys []string) bool { sort.Strings(keys) return node.match(keys) }
go
{ "resource": "" }
q14933
ToSlice
train
func (node *Node) ToSlice() (list [][]string) { // iterate through each leaf appending it as a slice to the list of keys for leaf := range node.leaves { list = append(list, []string{leaf}) } // iterate through each branch getting its list of branches and appending those // to the list for branch, node := range node.branches { // get the current nodes slice of branches and leaves nodeSlice := node.ToSlice() // for each branch in the nodes list apppend the key to that key for _, nodeKey := range nodeSlice { list = append(list, append(nodeKey, branch)) } } // sort each list for _, l := range list { sort.Strings(l) } return }
go
{ "resource": "" }
q14934
Register
train
func Register(name string, auth handleFunc) { authTex.Lock() authenticators[name] = auth authTex.Unlock() }
go
{ "resource": "" }
q14935
NewPostgres
train
func NewPostgres(url *url.URL) (Authenticator, error) { host, port, err := net.SplitHostPort(url.Host) db := url.Query().Get("db") user := url.User.Username() // pass, _ := url.User.Password() pg := postgres(fmt.Sprintf("user=%s database=%s sslmode=disable host=%s port=%s", user, db, host, port)) // create the tables needed to support mist authentication if _, err = pg.exec(` CREATE TABLE IF NOT EXISTS tokens ( token text NOT NULL, token_id SERIAL UNIQUE NOT NULL, PRIMARY KEY (token) )`); err != nil { return pg, err } if _, err = pg.exec(` CREATE TABLE IF NOT EXISTS tags ( token_id integer NOT NULL REFERENCES tokens (token_id) ON DELETE CASCADE, tag text NOT NULL, PRIMARY KEY (token_id, tag) )`); err != nil { return pg, err } return pg, nil }
go
{ "resource": "" }
q14936
query
train
func (a postgres) query(query string, args ...interface{}) (*sql.Rows, error) { client, err := a.connect() if err != nil { return nil, err } defer client.Close() return client.Query(query, args...) }
go
{ "resource": "" }
q14937
exec
train
func (a postgres) exec(query string, args ...interface{}) (sql.Result, error) { client, err := a.connect() if err != nil { return nil, err } defer client.Close() return client.Exec(query, args...) }
go
{ "resource": "" }
q14938
Subscribers
train
func Subscribers() string { subs := make(map[string]bool) // no duplicates // get tags all clients subscribed to for i := range subscribers { s := subscribers[i].subscriptions.ToSlice() for j := range s { for k := range s[j] { subs[s[j][k]] = true } } } // slice it subSlice := []string{} for k, _ := range subs { subSlice = append(subSlice, k) } return strings.Join(subSlice, " ") }
go
{ "resource": "" }
q14939
Who
train
func Who() (int, int) { // subs := make(map[string]bool) // no duplicates subs := []string{} // get tags all clients subscribed to for i := range subscribers { subs = append(subs, fmt.Sprint(subscribers[i].id)) } return len(subs), int(uid) }
go
{ "resource": "" }
q14940
PublishAfter
train
func PublishAfter(tags []string, data string, delay time.Duration) error { go func() { <-time.After(delay) if err := Publish(tags, data); err != nil { // log this error and continue? lumber.Error("Failed to PublishAfter - %s", err.Error()) } }() return nil }
go
{ "resource": "" }
q14941
publish
train
func publish(pid uint32, tags []string, data string) error { if len(tags) == 0 { return fmt.Errorf("Failed to publish. Missing tags") } // if there are no subscribers, the message goes nowhere // // this could be more optimized, but it might not be an issue unless thousands // of clients are using mist. go func() { mutex.RLock() for _, subscriber := range subscribers { select { case <-subscriber.done: lumber.Trace("Subscriber done") // do nothing? default: // dont send this message to the publisher who just sent it if subscriber.id == pid { lumber.Trace("Subscriber is publisher, skipping publish") continue } // create message msg := Message{Command: "publish", Tags: tags, Data: data} // we don't want this operation blocking the range of other subscribers // waiting to get messages go func(p *Proxy, msg Message) { p.check <- msg lumber.Trace("Published message") }(subscriber, msg) } } mutex.RUnlock() }() return nil }
go
{ "resource": "" }
q14942
subscribe
train
func subscribe(p *Proxy) { lumber.Trace("Adding proxy to subscribers...") mutex.Lock() subscribers[p.id] = p mutex.Unlock() }
go
{ "resource": "" }
q14943
unsubscribe
train
func unsubscribe(pid uint32) { lumber.Trace("Removing proxy from subscribers...") mutex.Lock() delete(subscribers, pid) mutex.Unlock() }
go
{ "resource": "" }
q14944
NewScribble
train
func NewScribble(url *url.URL) (Authenticator, error) { // get the desired location of the scribble database dir := url.Query().Get("db") // if no database location is provided, fail if dir == "" { return nil, fmt.Errorf("Missing database location in scheme (?db=)") } // create a new scribble database at the specified location db, err := scribbleDB.New(dir, nil) if err != nil { return nil, err } return &scribble{driver: db}, nil }
go
{ "resource": "" }
q14945
findScribbleToken
train
func (a *scribble) findScribbleToken(token string) (entry scribbleToken, err error) { // look for existing token if err = a.driver.Read("tokens", token, &entry); err != nil { return entry, err } return entry, nil }
go
{ "resource": "" }
q14946
StartHTTP
train
func StartHTTP(uri string, errChan chan<- error) { if err := newHTTP(uri); err != nil { errChan <- fmt.Errorf("Unable to start mist http listener - %s", err.Error()) } }
go
{ "resource": "" }
q14947
routes
train
func routes() *pat.Router { Router.Get("/ping", func(rw http.ResponseWriter, req *http.Request) { rw.Write([]byte("pong\n")) }) // Router.Get("/list", handleRequest(list)) // Router.Get("/subscribe", handleRequest(subscribe)) // Router.Get("/unsubscribe", handleRequest(unsubscribe)) return Router }
go
{ "resource": "" }
q14948
handleRequest
train
func handleRequest(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { fn(rw, req) } }
go
{ "resource": "" }
q14949
Negotiate
train
func (k KerberizedServer) Negotiate(cred *gssapi.CredId, inHeader, outHeader http.Header) (string, int, error) { var challengeHeader, authHeader string var challengeStatus int if k.UseProxyAuthentication { challengeHeader = "Proxy-Authenticate" challengeStatus = http.StatusProxyAuthRequired authHeader = "Proxy-Authorization" } else { challengeHeader = "WWW-Authenticate" challengeStatus = http.StatusUnauthorized authHeader = "Authorization" } negotiate, inputToken := CheckSPNEGONegotiate(k.Lib, inHeader, authHeader) defer inputToken.Release() // Here, challenge the client to initiate the security context. The first // request a client has made will often be unauthenticated, so we return a // 401, which the client handles. if !negotiate || inputToken.Length() == 0 { AddSPNEGONegotiate(outHeader, challengeHeader, inputToken) return "", challengeStatus, errors.New("SPNEGO: unauthorized") } // FIXME: GSS_S_CONTINUED_NEEDED handling? ctx, srcName, _, outputToken, _, _, delegatedCredHandle, err := k.AcceptSecContext(k.GSS_C_NO_CONTEXT, cred, inputToken, k.GSS_C_NO_CHANNEL_BINDINGS) if err != nil { return "", http.StatusBadRequest, err } delegatedCredHandle.Release() ctx.DeleteSecContext() outputToken.Release() defer srcName.Release() return srcName.String(), http.StatusOK, nil }
go
{ "resource": "" }
q14950
MakeOIDSet
train
func (lib *Lib) MakeOIDSet(oids ...*OID) (s *OIDSet, err error) { s = &OIDSet{ Lib: lib, } var min C.OM_uint32 maj := C.wrap_gss_create_empty_oid_set(s.Fp_gss_create_empty_oid_set, &min, &s.C_gss_OID_set) err = s.stashLastStatus(maj, min) if err != nil { return nil, err } err = s.Add(oids...) if err != nil { return nil, err } return s, nil }
go
{ "resource": "" }
q14951
Release
train
func (s *OIDSet) Release() (err error) { if s == nil || s.C_gss_OID_set == nil { return nil } var min C.OM_uint32 maj := C.wrap_gss_release_oid_set(s.Fp_gss_release_oid_set, &min, &s.C_gss_OID_set) return s.stashLastStatus(maj, min) }
go
{ "resource": "" }
q14952
Add
train
func (s *OIDSet) Add(oids ...*OID) (err error) { var min C.OM_uint32 for _, oid := range oids { maj := C.wrap_gss_add_oid_set_member(s.Fp_gss_add_oid_set_member, &min, oid.C_gss_OID, &s.C_gss_OID_set) err = s.stashLastStatus(maj, min) if err != nil { return err } } return nil }
go
{ "resource": "" }
q14953
Length
train
func (s *OIDSet) Length() int { if s == nil { return 0 } return int(s.C_gss_OID_set.count) }
go
{ "resource": "" }
q14954
Get
train
func (s *OIDSet) Get(index int) (*OID, error) { if s == nil || index < 0 || index >= int(s.C_gss_OID_set.count) { return nil, fmt.Errorf("index %d out of bounds", index) } oid := s.NewOID() oid.C_gss_OID = C.get_oid_set_member(s.C_gss_OID_set, C.int(index)) return oid, nil }
go
{ "resource": "" }
q14955
Path
train
func (o *Options) Path() string { switch { case o.LibPath != "": return o.LibPath case o.LoadDefault == MIT: return appendOSExt("libgssapi_krb5") case o.LoadDefault == Heimdal: return appendOSExt("libgssapi") } return "" }
go
{ "resource": "" }
q14956
Load
train
func Load(o *Options) (*Lib, error) { if o == nil { o = &Options{} } // We get the error in a separate call, so we need to lock OS thread runtime.LockOSThread() defer runtime.UnlockOSThread() lib := &Lib{ Printers: o.Printers, } if o.Krb5Config != "" { err := os.Setenv("KRB5_CONFIG", o.Krb5Config) if err != nil { return nil, err } } if o.Krb5Ktname != "" { err := os.Setenv("KRB5_KTNAME", o.Krb5Ktname) if err != nil { return nil, err } } path := o.Path() lib.Debug(fmt.Sprintf("Loading %q", path)) lib_cs := C.CString(path) defer C.free(unsafe.Pointer(lib_cs)) // we don't use RTLD_FIRST, it might be the case that the GSSAPI lib // delegates symbols to other libs it links against (eg, Kerberos) lib.handle = C.dlopen(lib_cs, C.RTLD_NOW|C.RTLD_LOCAL) if lib.handle == nil { return nil, fmt.Errorf("%s", C.GoString(C.dlerror())) } err := lib.populateFunctions() if err != nil { lib.Unload() return nil, err } lib.initConstants() return lib, nil }
go
{ "resource": "" }
q14957
Unload
train
func (lib *Lib) Unload() error { if lib == nil || lib.handle == nil { return nil } runtime.LockOSThread() defer runtime.UnlockOSThread() i := C.dlclose(lib.handle) if i == -1 { return fmt.Errorf("%s", C.GoString(C.dlerror())) } lib.handle = nil return nil }
go
{ "resource": "" }
q14958
populateFunctions
train
func (lib *Lib) populateFunctions() error { libT := reflect.TypeOf(lib.ftable) functionsV := reflect.ValueOf(lib).Elem().FieldByName("ftable") n := libT.NumField() for i := 0; i < n; i++ { // Get the field name, and make sure it's an Fp_. f := libT.FieldByIndex([]int{i}) if !strings.HasPrefix(f.Name, fpPrefix) { return fmt.Errorf( "Unexpected: field %q does not start with %q", f.Name, fpPrefix) } // Resolve the symbol. cfname := C.CString(f.Name[len(fpPrefix):]) v := C.dlsym(lib.handle, cfname) C.free(unsafe.Pointer(cfname)) if v == nil { return fmt.Errorf("%s", C.GoString(C.dlerror())) } // Save the value into the struct functionsV.FieldByIndex([]int{i}).SetPointer(v) } return nil }
go
{ "resource": "" }
q14959
initConstants
train
func (lib *Lib) initConstants() { lib.GSS_C_NO_BUFFER = &Buffer{ Lib: lib, // C_gss_buffer_t: C.GSS_C_NO_BUFFER, already nil // alloc: allocNone, already 0 } lib.GSS_C_NO_OID = lib.NewOID() lib.GSS_C_NO_OID_SET = lib.NewOIDSet() lib.GSS_C_NO_CONTEXT = lib.NewCtxId() lib.GSS_C_NO_CREDENTIAL = lib.NewCredId() lib.GSS_C_NT_USER_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_USER_NAME} lib.GSS_C_NT_MACHINE_UID_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_MACHINE_UID_NAME} lib.GSS_C_NT_STRING_UID_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_MACHINE_UID_NAME} lib.GSS_C_NT_HOSTBASED_SERVICE_X = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_HOSTBASED_SERVICE_X} lib.GSS_C_NT_HOSTBASED_SERVICE = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_HOSTBASED_SERVICE} lib.GSS_C_NT_ANONYMOUS = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_ANONYMOUS} lib.GSS_C_NT_EXPORT_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_C_NT_EXPORT_NAME} lib.GSS_KRB5_NT_PRINCIPAL_NAME = &OID{Lib: lib, C_gss_OID: C._GSS_KRB5_NT_PRINCIPAL_NAME} lib.GSS_KRB5_NT_PRINCIPAL = &OID{Lib: lib, C_gss_OID: C._GSS_KRB5_NT_PRINCIPAL} lib.GSS_MECH_KRB5 = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5} lib.GSS_MECH_KRB5_LEGACY = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5_LEGACY} lib.GSS_MECH_KRB5_OLD = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_KRB5_OLD} lib.GSS_MECH_SPNEGO = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_SPNEGO} lib.GSS_MECH_IAKERB = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_IAKERB} lib.GSS_MECH_NTLMSSP = &OID{Lib: lib, C_gss_OID: C._GSS_MECH_NTLMSSP} }
go
{ "resource": "" }
q14960
Print
train
func (lib *Lib) Print(level Severity, a ...interface{}) { if lib == nil || lib.Printers == nil || level >= Severity(len(lib.Printers)) { return } lib.Printers[level].Print(a...) }
go
{ "resource": "" }
q14961
Release
train
func (c *CredId) Release() error { if c == nil || c.C_gss_cred_id_t == nil { return nil } min := C.OM_uint32(0) maj := C.wrap_gss_release_cred(c.Fp_gss_release_cred, &min, &c.C_gss_cred_id_t) return c.stashLastStatus(maj, min) }
go
{ "resource": "" }
q14962
MakeBufferBytes
train
func (lib *Lib) MakeBufferBytes(data []byte) (*Buffer, error) { if len(data) == 0 { return lib.GSS_C_NO_BUFFER, nil } // have to allocate the memory in C land and copy b, err := lib.MakeBuffer(allocMalloc) if err != nil { return nil, err } l := C.size_t(len(data)) c := C.malloc(l) if b == nil { return nil, ErrMallocFailed } C.memmove(c, (unsafe.Pointer)(&data[0]), l) b.C_gss_buffer_t.length = l b.C_gss_buffer_t.value = c b.alloc = allocMalloc return b, nil }
go
{ "resource": "" }
q14963
MakeBufferString
train
func (lib *Lib) MakeBufferString(content string) (*Buffer, error) { return lib.MakeBufferBytes([]byte(content)) }
go
{ "resource": "" }
q14964
Release
train
func (b *Buffer) Release() error { if b == nil || b.C_gss_buffer_t == nil { return nil } defer func() { C.free(unsafe.Pointer(b.C_gss_buffer_t)) b.C_gss_buffer_t = nil b.alloc = allocNone }() // free the value as needed switch { case b.C_gss_buffer_t.value == nil: // do nothing case b.alloc == allocMalloc: C.free(b.C_gss_buffer_t.value) case b.alloc == allocGSSAPI: var min C.OM_uint32 maj := C.wrap_gss_release_buffer(b.Fp_gss_release_buffer, &min, b.C_gss_buffer_t) err := b.stashLastStatus(maj, min) if err != nil { return err } } return nil }
go
{ "resource": "" }
q14965
Length
train
func (b *Buffer) Length() int { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return 0 } return int(b.C_gss_buffer_t.length) }
go
{ "resource": "" }
q14966
Bytes
train
func (b *Buffer) Bytes() []byte { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return make([]byte, 0) } return C.GoBytes(b.C_gss_buffer_t.value, C.int(b.C_gss_buffer_t.length)) }
go
{ "resource": "" }
q14967
String
train
func (b *Buffer) String() string { if b == nil || b.C_gss_buffer_t == nil || b.C_gss_buffer_t.length == 0 { return "" } return C.GoStringN((*C.char)(b.C_gss_buffer_t.value), C.int(b.C_gss_buffer_t.length)) }
go
{ "resource": "" }
q14968
Equal
train
func (b *Buffer) Equal(other *Buffer) bool { isEqual := C.wrap_gss_buffer_equal(b.C_gss_buffer_t, other.C_gss_buffer_t) return isEqual != 0 }
go
{ "resource": "" }
q14969
MakeOIDBytes
train
func (lib *Lib) MakeOIDBytes(data []byte) (*OID, error) { oid := lib.NewOID() s := C.malloc(C.gss_OID_size) // s for struct if s == nil { return nil, ErrMallocFailed } C.memset(s, 0, C.gss_OID_size) l := C.size_t(len(data)) e := C.malloc(l) // c for contents if e == nil { return nil, ErrMallocFailed } C.memmove(e, (unsafe.Pointer)(&data[0]), l) oid.C_gss_OID = C.gss_OID(s) oid.alloc = allocMalloc // because of the alignment issues I can't access o.oid's fields from go, // so invoking a C function to do the same as: // oid.C_gss_OID.length = l // oid.C_gss_OID.elements = c C.helper_gss_OID_desc_set_elements(oid.C_gss_OID, C.OM_uint32(l), e) return oid, nil }
go
{ "resource": "" }
q14970
MakeOIDString
train
func (lib *Lib) MakeOIDString(data string) (*OID, error) { return lib.MakeOIDBytes([]byte(data)) }
go
{ "resource": "" }
q14971
Release
train
func (oid *OID) Release() error { if oid == nil || oid.C_gss_OID == nil { return nil } switch oid.alloc { case allocMalloc: // same as with get and set, use a C helper to free(oid.C_gss_OID.elements) C.helper_gss_OID_desc_free_elements(oid.C_gss_OID) C.free(unsafe.Pointer(oid.C_gss_OID)) oid.C_gss_OID = nil oid.alloc = allocNone } return nil }
go
{ "resource": "" }
q14972
Bytes
train
func (oid OID) Bytes() []byte { var l C.OM_uint32 var p *C.char C.helper_gss_OID_desc_get_elements(oid.C_gss_OID, &l, &p) return C.GoBytes(unsafe.Pointer(p), C.int(l)) }
go
{ "resource": "" }
q14973
String
train
func (oid *OID) String() string { var l C.OM_uint32 var p *C.char C.helper_gss_OID_desc_get_elements(oid.C_gss_OID, &l, &p) return fmt.Sprintf(`%x`, C.GoStringN(p, C.int(l))) }
go
{ "resource": "" }
q14974
DebugString
train
func (oid *OID) DebugString() string { switch { case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_USER_NAME.Bytes()): return "GSS_C_NT_USER_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_MACHINE_UID_NAME.Bytes()): return "GSS_C_NT_MACHINE_UID_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_STRING_UID_NAME.Bytes()): return "GSS_C_NT_STRING_UID_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_HOSTBASED_SERVICE_X.Bytes()): return "GSS_C_NT_HOSTBASED_SERVICE_X" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_HOSTBASED_SERVICE.Bytes()): return "GSS_C_NT_HOSTBASED_SERVICE" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_ANONYMOUS.Bytes()): return "GSS_C_NT_ANONYMOUS" case bytes.Equal(oid.Bytes(), oid.GSS_C_NT_EXPORT_NAME.Bytes()): return "GSS_C_NT_EXPORT_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_KRB5_NT_PRINCIPAL_NAME.Bytes()): return "GSS_KRB5_NT_PRINCIPAL_NAME" case bytes.Equal(oid.Bytes(), oid.GSS_KRB5_NT_PRINCIPAL.Bytes()): return "GSS_KRB5_NT_PRINCIPAL" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5.Bytes()): return "GSS_MECH_KRB5" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5_LEGACY.Bytes()): return "GSS_MECH_KRB5_LEGACY" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_KRB5_OLD.Bytes()): return "GSS_MECH_KRB5_OLD" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_SPNEGO.Bytes()): return "GSS_MECH_SPNEGO" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_IAKERB.Bytes()): return "GSS_MECH_IAKERB" case bytes.Equal(oid.Bytes(), oid.GSS_MECH_NTLMSSP.Bytes()): return "GSS_MECH_NTLMSSP" } return oid.String() }
go
{ "resource": "" }
q14975
AcceptSecContext
train
func (lib *Lib) AcceptSecContext( ctxIn *CtxId, acceptorCredHandle *CredId, inputToken *Buffer, inputChanBindings ChannelBindings) ( ctxOut *CtxId, srcName *Name, actualMechType *OID, outputToken *Buffer, retFlags uint32, timeRec time.Duration, delegatedCredHandle *CredId, err error) { runtime.LockOSThread() defer runtime.UnlockOSThread() // prepare the inputs C_acceptorCredHandle := C.gss_cred_id_t(nil) if acceptorCredHandle != nil { C_acceptorCredHandle = acceptorCredHandle.C_gss_cred_id_t } C_inputToken := C.gss_buffer_t(nil) if inputToken != nil { C_inputToken = inputToken.C_gss_buffer_t } // prepare the outputs if ctxIn != nil { ctxCopy := *ctxIn ctxOut = &ctxCopy } else { ctxOut = lib.GSS_C_NO_CONTEXT } min := C.OM_uint32(0) srcName = lib.NewName() actualMechType = lib.NewOID() outputToken, err = lib.MakeBuffer(allocGSSAPI) if err != nil { return nil, nil, nil, nil, 0, 0, nil, err } flags := C.OM_uint32(0) timerec := C.OM_uint32(0) delegatedCredHandle = lib.NewCredId() maj := C.wrap_gss_accept_sec_context(lib.Fp_gss_accept_sec_context, &min, &ctxOut.C_gss_ctx_id_t, // used as both in and out param C_acceptorCredHandle, C_inputToken, C.gss_channel_bindings_t(inputChanBindings), &srcName.C_gss_name_t, &actualMechType.C_gss_OID, outputToken.C_gss_buffer_t, &flags, &timerec, &delegatedCredHandle.C_gss_cred_id_t) err = lib.stashLastStatus(maj, min) if err != nil { lib.Err("AcceptSecContext: ", err) return nil, nil, nil, nil, 0, 0, nil, err } if MajorStatus(maj).ContinueNeeded() { err = ErrContinueNeeded } return ctxOut, srcName, actualMechType, outputToken, uint32(flags), time.Duration(timerec) * time.Second, delegatedCredHandle, err }
go
{ "resource": "" }
q14976
InquireContext
train
func (ctx *CtxId) InquireContext() ( srcName *Name, targetName *Name, lifetimeRec time.Duration, mechType *OID, ctxFlags uint64, locallyInitiated bool, open bool, err error) { min := C.OM_uint32(0) srcName = ctx.NewName() targetName = ctx.NewName() rec := C.OM_uint32(0) mechType = ctx.NewOID() flags := C.OM_uint32(0) li := C.int(0) opn := C.int(0) maj := C.wrap_gss_inquire_context(ctx.Fp_gss_inquire_context, &min, ctx.C_gss_ctx_id_t, &srcName.C_gss_name_t, &targetName.C_gss_name_t, &rec, &mechType.C_gss_OID, &flags, &li, &opn) err = ctx.stashLastStatus(maj, min) if err != nil { ctx.Err("InquireContext: ", err) return nil, nil, 0, nil, 0, false, false, err } lifetimeRec = time.Duration(rec) * time.Second ctxFlags = uint64(flags) if li != 0 { locallyInitiated = true } if opn != 0 { open = true } return srcName, targetName, lifetimeRec, mechType, ctxFlags, locallyInitiated, open, nil }
go
{ "resource": "" }
q14977
AddSPNEGONegotiate
train
func AddSPNEGONegotiate(h http.Header, name string, token *gssapi.Buffer) { if name == "" { return } v := negotiateScheme if token.Length() != 0 { data := token.Bytes() v = v + " " + base64.StdEncoding.EncodeToString(data) } h.Set(name, v) }
go
{ "resource": "" }
q14978
CheckSPNEGONegotiate
train
func CheckSPNEGONegotiate(lib *gssapi.Lib, h http.Header, name string) (bool, *gssapi.Buffer) { var err error defer func() { if err != nil { lib.Debug(fmt.Sprintf("CheckSPNEGONegotiate: %v", err)) } }() for _, header := range h[http.CanonicalHeaderKey(name)] { if len(header) < len(negotiateScheme) { continue } if !strings.EqualFold(header[:len(negotiateScheme)], negotiateScheme) { continue } // Remove the "Negotiate" prefix normalizedToken := header[len(negotiateScheme):] // Trim leading and trailing whitespace normalizedToken = strings.TrimSpace(normalizedToken) // Remove internal whitespace (some servers insert whitespace every 76 chars) normalizedToken = strings.Replace(normalizedToken, " ", "", -1) // Pad to a multiple of 4 chars for base64 (some servers strip trailing padding) if unpaddedChars := len(normalizedToken) % 4; unpaddedChars != 0 { normalizedToken += strings.Repeat("=", 4-unpaddedChars) } tbytes, err := base64.StdEncoding.DecodeString(normalizedToken) if err != nil { continue } if len(tbytes) == 0 { return true, nil } token, err := lib.MakeBufferBytes(tbytes) if err != nil { continue } return true, token } return false, nil }
go
{ "resource": "" }
q14979
Release
train
func (n *Name) Release() error { if n == nil || n.C_gss_name_t == nil { return nil } var min C.OM_uint32 maj := C.wrap_gss_release_name(n.Fp_gss_release_name, &min, &n.C_gss_name_t) err := n.stashLastStatus(maj, min) if err == nil { n.C_gss_name_t = nil } return err }
go
{ "resource": "" }
q14980
Display
train
func (n Name) Display() (name string, oid *OID, err error) { var min C.OM_uint32 b, err := n.MakeBuffer(allocGSSAPI) if err != nil { return "", nil, err } defer b.Release() oid = n.NewOID() maj := C.wrap_gss_display_name(n.Fp_gss_display_name, &min, n.C_gss_name_t, b.C_gss_buffer_t, &oid.C_gss_OID) err = n.stashLastStatus(maj, min) if err != nil { oid.Release() return "", nil, err } return b.String(), oid, err }
go
{ "resource": "" }
q14981
Canonicalize
train
func (n Name) Canonicalize(mech_type *OID) (canonical *Name, err error) { canonical = &Name{ Lib: n.Lib, } var min C.OM_uint32 maj := C.wrap_gss_canonicalize_name(n.Fp_gss_canonicalize_name, &min, n.C_gss_name_t, mech_type.C_gss_OID, &canonical.C_gss_name_t) err = n.stashLastStatus(maj, min) if err != nil { return nil, err } return canonical, nil }
go
{ "resource": "" }
q14982
InquireMechs
train
func (n *Name) InquireMechs() (oids *OIDSet, err error) { oidset := n.NewOIDSet() if err != nil { return nil, err } var min C.OM_uint32 maj := C.wrap_gss_inquire_mechs_for_name(n.Fp_gss_inquire_mechs_for_name, &min, n.C_gss_name_t, &oidset.C_gss_OID_set) err = n.stashLastStatus(maj, min) if err != nil { return nil, err } return oidset, nil }
go
{ "resource": "" }
q14983
InquireNamesForMechs
train
func (lib *Lib) InquireNamesForMechs(mech *OID) (name_types *OIDSet, err error) { oidset := lib.NewOIDSet() if err != nil { return nil, err } var min C.OM_uint32 maj := C.wrap_gss_inquire_names_for_mech(lib.Fp_gss_inquire_mechs_for_name, &min, mech.C_gss_OID, &oidset.C_gss_OID_set) err = lib.stashLastStatus(maj, min) if err != nil { return nil, err } return oidset, nil }
go
{ "resource": "" }
q14984
MakeError
train
func (lib *Lib) MakeError(major, minor C.OM_uint32) *Error { return &Error{ Lib: lib, Major: MajorStatus(major), Minor: minor, } }
go
{ "resource": "" }
q14985
Error
train
func (e *Error) Error() string { messages := []string{} nOther := 0 context := C.OM_uint32(0) inquiry := C.OM_uint32(0) code_type := 0 first := true if e.Major.RoutineError() == GSS_S_FAILURE { inquiry = e.Minor code_type = GSS_C_MECH_CODE } else { inquiry = C.OM_uint32(e.Major) code_type = GSS_C_GSS_CODE } for first || context != C.OM_uint32(0) { first = false min := C.OM_uint32(0) b, err := e.MakeBuffer(allocGSSAPI) if err != nil { break } // TODO: store a mech_type at the lib level? Or context? For now GSS_C_NO_OID... maj := C.wrap_gss_display_status( e.Fp_gss_display_status, &min, inquiry, C.int(code_type), nil, &context, b.C_gss_buffer_t) err = e.MakeError(maj, min).GoError() if err != nil { nOther = nOther + 1 } messages = append(messages, b.String()) b.Release() } if nOther > 0 { messages = append(messages, fmt.Sprintf("additionally, %d conversions failed", nOther)) } messages = append(messages, "") return strings.Join(messages, "\n") }
go
{ "resource": "" }
q14986
Map
train
func Map(w io.Writer, is ...interface{}) { var iVals []reflect.Value for _, i := range is { iVal := reflect.ValueOf(i) if !iVal.CanAddr() { if iVal.Kind() != reflect.Ptr && iVal.Kind() != reflect.Interface { fmt.Fprint(w, "error: cannot map unaddressable value") return } iVal = iVal.Elem() } iVals = append(iVals, iVal) } m := &mapper{ w, map[nodeKey]nodeID{nilKey: 0}, map[nodeKey]string{nilKey: "nil"}, 2, } fmt.Fprintln(w, "digraph structs {") fmt.Fprintln(w, " node [shape=Mrecord];") for _, iVal := range iVals { m.mapValue(iVal, 0, false) } fmt.Fprintln(w, "}") }
go
{ "resource": "" }
q14987
newOperatorNode
train
func newOperatorNode(op string, left, right node) node { return &operatorNode{nodeType: nodeOperator, Op: op, Left: left, Right: right} }
go
{ "resource": "" }
q14988
newAxisNode
train
func newAxisNode(axeTyp, localName, prefix, prop string, n node) node { return &axisNode{ nodeType: nodeAxis, LocalName: localName, Prefix: prefix, AxeType: axeTyp, Prop: prop, Input: n, } }
go
{ "resource": "" }
q14989
newVariableNode
train
func newVariableNode(prefix, name string) node { return &variableNode{nodeType: nodeVariable, Name: name, Prefix: prefix} }
go
{ "resource": "" }
q14990
newFilterNode
train
func newFilterNode(n, m node) node { return &filterNode{nodeType: nodeFilter, Input: n, Condition: m} }
go
{ "resource": "" }
q14991
newFunctionNode
train
func newFunctionNode(name, prefix string, args []node) node { return &functionNode{nodeType: nodeFunction, Prefix: prefix, FuncName: name, Args: args} }
go
{ "resource": "" }
q14992
parseExpression
train
func (p *parser) parseExpression(n node) node { if p.d = p.d + 1; p.d > 200 { panic("the xpath query is too complex(depth > 200)") } n = p.parseOrExpr(n) p.d-- return n }
go
{ "resource": "" }
q14993
parse
train
func parse(expr string) node { r := &scanner{text: expr} r.nextChar() r.nextItem() p := &parser{r: r} return p.parseExpression(nil) }
go
{ "resource": "" }
q14994
cmpNumberNumberF
train
func cmpNumberNumberF(op string, a, b float64) bool { switch op { case "=": return a == b case ">": return a > b case "<": return a < b case ">=": return a >= b case "<=": return a <= b case "!=": return a != b } return false }
go
{ "resource": "" }
q14995
cmpStringStringF
train
func cmpStringStringF(op string, a, b string) bool { switch op { case "=": return a == b case ">": return a > b case "<": return a < b case ">=": return a >= b case "<=": return a <= b case "!=": return a != b } return false }
go
{ "resource": "" }
q14996
eqFunc
train
func eqFunc(t iterator, m, n interface{}) interface{} { t1 := getValueType(m) t2 := getValueType(n) return logicalFuncs[t1][t2](t, "=", m, n) }
go
{ "resource": "" }
q14997
axisPredicate
train
func axisPredicate(root *axisNode) func(NodeNavigator) bool { // get current axix node type. typ := ElementNode switch root.AxeType { case "attribute": typ = AttributeNode case "self", "parent": typ = allNode default: switch root.Prop { case "comment": typ = CommentNode case "text": typ = TextNode // case "processing-instruction": // typ = ProcessingInstructionNode case "node": typ = allNode } } nametest := root.LocalName != "" || root.Prefix != "" predicate := func(n NodeNavigator) bool { if typ == n.NodeType() || typ == allNode || typ == TextNode { if nametest { if root.LocalName == n.LocalName() && root.Prefix == n.Prefix() { return true } } else { return true } } return false } return predicate }
go
{ "resource": "" }
q14998
processFilterNode
train
func (b *builder) processFilterNode(root *filterNode) (query, error) { b.flag |= filterFlag qyInput, err := b.processNode(root.Input) if err != nil { return nil, err } qyCond, err := b.processNode(root.Condition) if err != nil { return nil, err } qyOutput := &filterQuery{Input: qyInput, Predicate: qyCond} return qyOutput, nil }
go
{ "resource": "" }
q14999
build
train
func build(expr string) (q query, err error) { defer func() { if e := recover(); e != nil { switch x := e.(type) { case string: err = errors.New(x) case error: err = x default: err = errors.New("unknown panic") } } }() root := parse(expr) b := &builder{} return b.processNode(root) }
go
{ "resource": "" }