id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
18,400
mailgun/mailgun-go
messages.go
ReSend
func (mg *MailgunImpl) ReSend(ctx context.Context, url string, recipients ...string) (string, string, error) { r := newHTTPRequest(url) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) payload := newFormDataPayload() if len(recipients) == 0 { return "", "", errors.New("must provide at least one recipient") } for _, to := range recipients { payload.addValue("to", to) } var resp sendMessageResponse err := postResponseFromJSON(ctx, r, payload, &resp) if err != nil { return "", "", err } return resp.Message, resp.Id, nil }
go
func (mg *MailgunImpl) ReSend(ctx context.Context, url string, recipients ...string) (string, string, error) { r := newHTTPRequest(url) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) payload := newFormDataPayload() if len(recipients) == 0 { return "", "", errors.New("must provide at least one recipient") } for _, to := range recipients { payload.addValue("to", to) } var resp sendMessageResponse err := postResponseFromJSON(ctx, r, payload, &resp) if err != nil { return "", "", err } return resp.Message, resp.Id, nil }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "ReSend", "(", "ctx", "context", ".", "Context", ",", "url", "string", ",", "recipients", "...", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "url", ...
// Given a storage id resend the stored message to the specified recipients
[ "Given", "a", "storage", "id", "resend", "the", "stored", "message", "to", "the", "specified", "recipients" ]
df421608b66e7dd4c03112d5bb01525c51f344a2
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/messages.go#L724-L746
18,401
mailgun/mailgun-go
messages.go
GetStoredMessageRaw
func (mg *MailgunImpl) GetStoredMessageRaw(ctx context.Context, url string) (StoredMessageRaw, error) { r := newHTTPRequest(url) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) r.addHeader("Accept", "message/rfc2822") var response StoredMessageRaw err := getResponseFromJSON(ctx, r, &response) return response, err }
go
func (mg *MailgunImpl) GetStoredMessageRaw(ctx context.Context, url string) (StoredMessageRaw, error) { r := newHTTPRequest(url) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) r.addHeader("Accept", "message/rfc2822") var response StoredMessageRaw err := getResponseFromJSON(ctx, r, &response) return response, err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "GetStoredMessageRaw", "(", "ctx", "context", ".", "Context", ",", "url", "string", ")", "(", "StoredMessageRaw", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "url", ")", "\n", "r", ".", "setClient...
// GetStoredMessageRaw retrieves the raw MIME body of a received e-mail message. // Compared to GetStoredMessage, it gives access to the unparsed MIME body, and // thus delegates to the caller the required parsing.
[ "GetStoredMessageRaw", "retrieves", "the", "raw", "MIME", "body", "of", "a", "received", "e", "-", "mail", "message", ".", "Compared", "to", "GetStoredMessage", "it", "gives", "access", "to", "the", "unparsed", "MIME", "body", "and", "thus", "delegates", "to",...
df421608b66e7dd4c03112d5bb01525c51f344a2
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/messages.go#L751-L760
18,402
mailgun/mailgun-go
messages.go
GetStoredAttachment
func (mg *MailgunImpl) GetStoredAttachment(ctx context.Context, url string) ([]byte, error) { r := newHTTPRequest(url) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) r.addHeader("Accept", "message/rfc2822") response, err := makeGetRequest(ctx, r) return response.Data, err }
go
func (mg *MailgunImpl) GetStoredAttachment(ctx context.Context, url string) ([]byte, error) { r := newHTTPRequest(url) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) r.addHeader("Accept", "message/rfc2822") response, err := makeGetRequest(ctx, r) return response.Data, err }
[ "func", "(", "mg", "*", "MailgunImpl", ")", "GetStoredAttachment", "(", "ctx", "context", ".", "Context", ",", "url", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "r", ":=", "newHTTPRequest", "(", "url", ")", "\n", "r", ".", "setClie...
// GetStoredAttachment retrieves the raw MIME body of a received e-mail message attachment.
[ "GetStoredAttachment", "retrieves", "the", "raw", "MIME", "body", "of", "a", "received", "e", "-", "mail", "message", "attachment", "." ]
df421608b66e7dd4c03112d5bb01525c51f344a2
https://github.com/mailgun/mailgun-go/blob/df421608b66e7dd4c03112d5bb01525c51f344a2/messages.go#L773-L782
18,403
xtaci/smux
stream.go
newStream
func newStream(id uint32, frameSize int, sess *Session) *Stream { s := new(Stream) s.id = id s.chReadEvent = make(chan struct{}, 1) s.frameSize = frameSize s.sess = sess s.die = make(chan struct{}) return s }
go
func newStream(id uint32, frameSize int, sess *Session) *Stream { s := new(Stream) s.id = id s.chReadEvent = make(chan struct{}, 1) s.frameSize = frameSize s.sess = sess s.die = make(chan struct{}) return s }
[ "func", "newStream", "(", "id", "uint32", ",", "frameSize", "int", ",", "sess", "*", "Session", ")", "*", "Stream", "{", "s", ":=", "new", "(", "Stream", ")", "\n", "s", ".", "id", "=", "id", "\n", "s", ".", "chReadEvent", "=", "make", "(", "chan...
// newStream initiates a Stream struct
[ "newStream", "initiates", "a", "Stream", "struct" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/stream.go#L29-L37
18,404
xtaci/smux
stream.go
Write
func (s *Stream) Write(b []byte) (n int, err error) { var deadline <-chan time.Time if d, ok := s.writeDeadline.Load().(time.Time); ok && !d.IsZero() { timer := time.NewTimer(time.Until(d)) defer timer.Stop() deadline = timer.C } select { case <-s.die: return 0, errors.New(errBrokenPipe) default: } // frame split and transmit sent := 0 frame := newFrame(cmdPSH, s.id) bts := b for len(bts) > 0 { sz := len(bts) if sz > s.frameSize { sz = s.frameSize } frame.data = bts[:sz] bts = bts[sz:] n, err := s.sess.writeFrameInternal(frame, deadline) sent += n if err != nil { return sent, err } } return sent, nil }
go
func (s *Stream) Write(b []byte) (n int, err error) { var deadline <-chan time.Time if d, ok := s.writeDeadline.Load().(time.Time); ok && !d.IsZero() { timer := time.NewTimer(time.Until(d)) defer timer.Stop() deadline = timer.C } select { case <-s.die: return 0, errors.New(errBrokenPipe) default: } // frame split and transmit sent := 0 frame := newFrame(cmdPSH, s.id) bts := b for len(bts) > 0 { sz := len(bts) if sz > s.frameSize { sz = s.frameSize } frame.data = bts[:sz] bts = bts[sz:] n, err := s.sess.writeFrameInternal(frame, deadline) sent += n if err != nil { return sent, err } } return sent, nil }
[ "func", "(", "s", "*", "Stream", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "var", "deadline", "<-", "chan", "time", ".", "Time", "\n", "if", "d", ",", "ok", ":=", "s", ".", "writeDeadline", ...
// Write implements net.Conn
[ "Write", "implements", "net", ".", "Conn" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/stream.go#L93-L126
18,405
xtaci/smux
stream.go
Close
func (s *Stream) Close() error { s.dieLock.Lock() select { case <-s.die: s.dieLock.Unlock() return errors.New(errBrokenPipe) default: close(s.die) s.dieLock.Unlock() s.sess.streamClosed(s.id) _, err := s.sess.writeFrame(newFrame(cmdFIN, s.id)) return err } }
go
func (s *Stream) Close() error { s.dieLock.Lock() select { case <-s.die: s.dieLock.Unlock() return errors.New(errBrokenPipe) default: close(s.die) s.dieLock.Unlock() s.sess.streamClosed(s.id) _, err := s.sess.writeFrame(newFrame(cmdFIN, s.id)) return err } }
[ "func", "(", "s", "*", "Stream", ")", "Close", "(", ")", "error", "{", "s", ".", "dieLock", ".", "Lock", "(", ")", "\n\n", "select", "{", "case", "<-", "s", ".", "die", ":", "s", ".", "dieLock", ".", "Unlock", "(", ")", "\n", "return", "errors"...
// Close implements net.Conn
[ "Close", "implements", "net", ".", "Conn" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/stream.go#L129-L143
18,406
xtaci/smux
stream.go
sessionClose
func (s *Stream) sessionClose() { s.dieLock.Lock() defer s.dieLock.Unlock() select { case <-s.die: default: close(s.die) } }
go
func (s *Stream) sessionClose() { s.dieLock.Lock() defer s.dieLock.Unlock() select { case <-s.die: default: close(s.die) } }
[ "func", "(", "s", "*", "Stream", ")", "sessionClose", "(", ")", "{", "s", ".", "dieLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "dieLock", ".", "Unlock", "(", ")", "\n\n", "select", "{", "case", "<-", "s", ".", "die", ":", "default", ...
// session closes the stream
[ "session", "closes", "the", "stream" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/stream.go#L181-L190
18,407
xtaci/smux
stream.go
RemoteAddr
func (s *Stream) RemoteAddr() net.Addr { if ts, ok := s.sess.conn.(interface { RemoteAddr() net.Addr }); ok { return ts.RemoteAddr() } return nil }
go
func (s *Stream) RemoteAddr() net.Addr { if ts, ok := s.sess.conn.(interface { RemoteAddr() net.Addr }); ok { return ts.RemoteAddr() } return nil }
[ "func", "(", "s", "*", "Stream", ")", "RemoteAddr", "(", ")", "net", ".", "Addr", "{", "if", "ts", ",", "ok", ":=", "s", ".", "sess", ".", "conn", ".", "(", "interface", "{", "RemoteAddr", "(", ")", "net", ".", "Addr", "\n", "}", ")", ";", "o...
// RemoteAddr satisfies net.Conn interface
[ "RemoteAddr", "satisfies", "net", ".", "Conn", "interface" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/stream.go#L203-L210
18,408
xtaci/smux
stream.go
pushBytes
func (s *Stream) pushBytes(buf []byte) (written int, err error) { s.bufferLock.Lock() s.buffers = append(s.buffers, buf) s.bufferLock.Unlock() return }
go
func (s *Stream) pushBytes(buf []byte) (written int, err error) { s.bufferLock.Lock() s.buffers = append(s.buffers, buf) s.bufferLock.Unlock() return }
[ "func", "(", "s", "*", "Stream", ")", "pushBytes", "(", "buf", "[", "]", "byte", ")", "(", "written", "int", ",", "err", "error", ")", "{", "s", ".", "bufferLock", ".", "Lock", "(", ")", "\n", "s", ".", "buffers", "=", "append", "(", "s", ".", ...
// pushBytes append buf to buffers
[ "pushBytes", "append", "buf", "to", "buffers" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/stream.go#L213-L218
18,409
xtaci/smux
session.go
Close
func (s *Session) Close() (err error) { s.dieLock.Lock() select { case <-s.die: s.dieLock.Unlock() return errors.New(errBrokenPipe) default: close(s.die) s.dieLock.Unlock() err = s.conn.Close() s.streamLock.Lock() for k := range s.streams { s.streams[k].sessionClose() } s.streamLock.Unlock() return } }
go
func (s *Session) Close() (err error) { s.dieLock.Lock() select { case <-s.die: s.dieLock.Unlock() return errors.New(errBrokenPipe) default: close(s.die) s.dieLock.Unlock() err = s.conn.Close() s.streamLock.Lock() for k := range s.streams { s.streams[k].sessionClose() } s.streamLock.Unlock() return } }
[ "func", "(", "s", "*", "Session", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "s", ".", "dieLock", ".", "Lock", "(", ")", "\n\n", "select", "{", "case", "<-", "s", ".", "die", ":", "s", ".", "dieLock", ".", "Unlock", "(", ")", "\n"...
// Close is used to close the session and all streams.
[ "Close", "is", "used", "to", "close", "the", "session", "and", "all", "streams", "." ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/session.go#L145-L163
18,410
xtaci/smux
session.go
streamClosed
func (s *Session) streamClosed(sid uint32) { s.streamLock.Lock() if n := s.streams[sid].recycleTokens(); n > 0 { // return remaining tokens to the bucket if atomic.AddInt32(&s.bucket, int32(n)) > 0 { s.notifyBucket() } } delete(s.streams, sid) s.streamLock.Unlock() }
go
func (s *Session) streamClosed(sid uint32) { s.streamLock.Lock() if n := s.streams[sid].recycleTokens(); n > 0 { // return remaining tokens to the bucket if atomic.AddInt32(&s.bucket, int32(n)) > 0 { s.notifyBucket() } } delete(s.streams, sid) s.streamLock.Unlock() }
[ "func", "(", "s", "*", "Session", ")", "streamClosed", "(", "sid", "uint32", ")", "{", "s", ".", "streamLock", ".", "Lock", "(", ")", "\n", "if", "n", ":=", "s", ".", "streams", "[", "sid", "]", ".", "recycleTokens", "(", ")", ";", "n", ">", "0...
// notify the session that a stream has closed
[ "notify", "the", "session", "that", "a", "stream", "has", "closed" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/session.go#L201-L210
18,411
xtaci/smux
session.go
returnTokens
func (s *Session) returnTokens(n int) { if atomic.AddInt32(&s.bucket, int32(n)) > 0 { s.notifyBucket() } }
go
func (s *Session) returnTokens(n int) { if atomic.AddInt32(&s.bucket, int32(n)) > 0 { s.notifyBucket() } }
[ "func", "(", "s", "*", "Session", ")", "returnTokens", "(", "n", "int", ")", "{", "if", "atomic", ".", "AddInt32", "(", "&", "s", ".", "bucket", ",", "int32", "(", "n", ")", ")", ">", "0", "{", "s", ".", "notifyBucket", "(", ")", "\n", "}", "...
// returnTokens is called by stream to return token after read
[ "returnTokens", "is", "called", "by", "stream", "to", "return", "token", "after", "read" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/session.go#L213-L217
18,412
xtaci/smux
session.go
recvLoop
func (s *Session) recvLoop() { var hdr rawHeader for { for atomic.LoadInt32(&s.bucket) <= 0 && !s.IsClosed() { select { case <-s.bucketNotify: case <-s.die: return } } // read header first if _, err := io.ReadFull(s.conn, hdr[:]); err == nil { atomic.StoreInt32(&s.dataReady, 1) if hdr.Version() != version { s.Close() return } sid := hdr.StreamID() switch hdr.Cmd() { case cmdNOP: case cmdSYN: s.streamLock.Lock() if _, ok := s.streams[sid]; !ok { stream := newStream(sid, s.config.MaxFrameSize, s) s.streams[sid] = stream select { case s.chAccepts <- stream: case <-s.die: } } s.streamLock.Unlock() case cmdFIN: s.streamLock.Lock() if stream, ok := s.streams[sid]; ok { stream.markRST() stream.notifyReadEvent() } s.streamLock.Unlock() case cmdPSH: if hdr.Length() > 0 { newbuf := make([]byte, hdr.Length()) if written, err := io.ReadFull(s.conn, newbuf); err == nil { s.streamLock.Lock() if stream, ok := s.streams[sid]; ok { stream.pushBytes(newbuf) atomic.AddInt32(&s.bucket, -int32(written)) stream.notifyReadEvent() } s.streamLock.Unlock() } else { s.Close() return } } default: s.Close() return } } else { s.Close() return } } }
go
func (s *Session) recvLoop() { var hdr rawHeader for { for atomic.LoadInt32(&s.bucket) <= 0 && !s.IsClosed() { select { case <-s.bucketNotify: case <-s.die: return } } // read header first if _, err := io.ReadFull(s.conn, hdr[:]); err == nil { atomic.StoreInt32(&s.dataReady, 1) if hdr.Version() != version { s.Close() return } sid := hdr.StreamID() switch hdr.Cmd() { case cmdNOP: case cmdSYN: s.streamLock.Lock() if _, ok := s.streams[sid]; !ok { stream := newStream(sid, s.config.MaxFrameSize, s) s.streams[sid] = stream select { case s.chAccepts <- stream: case <-s.die: } } s.streamLock.Unlock() case cmdFIN: s.streamLock.Lock() if stream, ok := s.streams[sid]; ok { stream.markRST() stream.notifyReadEvent() } s.streamLock.Unlock() case cmdPSH: if hdr.Length() > 0 { newbuf := make([]byte, hdr.Length()) if written, err := io.ReadFull(s.conn, newbuf); err == nil { s.streamLock.Lock() if stream, ok := s.streams[sid]; ok { stream.pushBytes(newbuf) atomic.AddInt32(&s.bucket, -int32(written)) stream.notifyReadEvent() } s.streamLock.Unlock() } else { s.Close() return } } default: s.Close() return } } else { s.Close() return } } }
[ "func", "(", "s", "*", "Session", ")", "recvLoop", "(", ")", "{", "var", "hdr", "rawHeader", "\n\n", "for", "{", "for", "atomic", ".", "LoadInt32", "(", "&", "s", ".", "bucket", ")", "<=", "0", "&&", "!", "s", ".", "IsClosed", "(", ")", "{", "s...
// recvLoop keeps on reading from underlying connection if tokens are available
[ "recvLoop", "keeps", "on", "reading", "from", "underlying", "connection", "if", "tokens", "are", "available" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/session.go#L220-L285
18,413
xtaci/smux
session.go
writeFrame
func (s *Session) writeFrame(f Frame) (n int, err error) { return s.writeFrameInternal(f, nil) }
go
func (s *Session) writeFrame(f Frame) (n int, err error) { return s.writeFrameInternal(f, nil) }
[ "func", "(", "s", "*", "Session", ")", "writeFrame", "(", "f", "Frame", ")", "(", "n", "int", ",", "err", "error", ")", "{", "return", "s", ".", "writeFrameInternal", "(", "f", ",", "nil", ")", "\n", "}" ]
// writeFrame writes the frame to the underlying connection // and returns the number of bytes written if successful
[ "writeFrame", "writes", "the", "frame", "to", "the", "underlying", "connection", "and", "returns", "the", "number", "of", "bytes", "written", "if", "successful" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/session.go#L359-L361
18,414
xtaci/smux
session.go
writeFrameInternal
func (s *Session) writeFrameInternal(f Frame, deadline <-chan time.Time) (int, error) { req := writeRequest{ frame: f, result: make(chan writeResult, 1), } select { case <-s.die: return 0, errors.New(errBrokenPipe) case s.writes <- req: case <-deadline: return 0, errTimeout } select { case result := <-req.result: return result.n, result.err case <-deadline: return 0, errTimeout case <-s.die: return 0, errors.New(errBrokenPipe) } }
go
func (s *Session) writeFrameInternal(f Frame, deadline <-chan time.Time) (int, error) { req := writeRequest{ frame: f, result: make(chan writeResult, 1), } select { case <-s.die: return 0, errors.New(errBrokenPipe) case s.writes <- req: case <-deadline: return 0, errTimeout } select { case result := <-req.result: return result.n, result.err case <-deadline: return 0, errTimeout case <-s.die: return 0, errors.New(errBrokenPipe) } }
[ "func", "(", "s", "*", "Session", ")", "writeFrameInternal", "(", "f", "Frame", ",", "deadline", "<-", "chan", "time", ".", "Time", ")", "(", "int", ",", "error", ")", "{", "req", ":=", "writeRequest", "{", "frame", ":", "f", ",", "result", ":", "m...
// internal writeFrame version to support deadline used in keepalive
[ "internal", "writeFrame", "version", "to", "support", "deadline", "used", "in", "keepalive" ]
401b0da0596a2d1eb2d94aae5fa16973d6f50962
https://github.com/xtaci/smux/blob/401b0da0596a2d1eb2d94aae5fa16973d6f50962/session.go#L364-L385
18,415
dop251/goja
date_parser.go
skip
func skip(value, prefix string) (string, error) { for len(prefix) > 0 { if prefix[0] == ' ' { if len(value) > 0 && value[0] != ' ' { return value, errBad } prefix = cutspace(prefix) value = cutspace(value) continue } if len(value) == 0 || value[0] != prefix[0] { return value, errBad } prefix = prefix[1:] value = value[1:] } return value, nil }
go
func skip(value, prefix string) (string, error) { for len(prefix) > 0 { if prefix[0] == ' ' { if len(value) > 0 && value[0] != ' ' { return value, errBad } prefix = cutspace(prefix) value = cutspace(value) continue } if len(value) == 0 || value[0] != prefix[0] { return value, errBad } prefix = prefix[1:] value = value[1:] } return value, nil }
[ "func", "skip", "(", "value", ",", "prefix", "string", ")", "(", "string", ",", "error", ")", "{", "for", "len", "(", "prefix", ")", ">", "0", "{", "if", "prefix", "[", "0", "]", "==", "' '", "{", "if", "len", "(", "value", ")", ">", "0", "&&...
// skip removes the given prefix from value, // treating runs of space characters as equivalent.
[ "skip", "removes", "the", "given", "prefix", "from", "value", "treating", "runs", "of", "space", "characters", "as", "equivalent", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/date_parser.go#L649-L666
18,416
dop251/goja
date_parser.go
atoi
func atoi(s string) (x int, err error) { q, rem, err := signedLeadingInt(s) x = int(q) if err != nil || rem != "" { return 0, atoiError } return x, nil }
go
func atoi(s string) (x int, err error) { q, rem, err := signedLeadingInt(s) x = int(q) if err != nil || rem != "" { return 0, atoiError } return x, nil }
[ "func", "atoi", "(", "s", "string", ")", "(", "x", "int", ",", "err", "error", ")", "{", "q", ",", "rem", ",", "err", ":=", "signedLeadingInt", "(", "s", ")", "\n", "x", "=", "int", "(", "q", ")", "\n", "if", "err", "!=", "nil", "||", "rem", ...
// Duplicates functionality in strconv, but avoids dependency.
[ "Duplicates", "functionality", "in", "strconv", "but", "avoids", "dependency", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/date_parser.go#L672-L679
18,417
dop251/goja
date_parser.go
match
func match(s1, s2 string) bool { for i := 0; i < len(s1); i++ { c1 := s1[i] c2 := s2[i] if c1 != c2 { // Switch to lower-case; 'a'-'A' is known to be a single bit. c1 |= 'a' - 'A' c2 |= 'a' - 'A' if c1 != c2 || c1 < 'a' || c1 > 'z' { return false } } } return true }
go
func match(s1, s2 string) bool { for i := 0; i < len(s1); i++ { c1 := s1[i] c2 := s2[i] if c1 != c2 { // Switch to lower-case; 'a'-'A' is known to be a single bit. c1 |= 'a' - 'A' c2 |= 'a' - 'A' if c1 != c2 || c1 < 'a' || c1 > 'z' { return false } } } return true }
[ "func", "match", "(", "s1", ",", "s2", "string", ")", "bool", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s1", ")", ";", "i", "++", "{", "c1", ":=", "s1", "[", "i", "]", "\n", "c2", ":=", "s2", "[", "i", "]", "\n", "if", "c1...
// match reports whether s1 and s2 match ignoring case. // It is assumed s1 and s2 are the same length.
[ "match", "reports", "whether", "s1", "and", "s2", "match", "ignoring", "case", ".", "It", "is", "assumed", "s1", "and", "s2", "are", "the", "same", "length", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/date_parser.go#L683-L697
18,418
dop251/goja
date_parser.go
parseTimeZone
func parseTimeZone(value string) (length int, ok bool) { if len(value) < 3 { return 0, false } // Special case 1: ChST and MeST are the only zones with a lower-case letter. if len(value) >= 4 && (value[:4] == "ChST" || value[:4] == "MeST") { return 4, true } // Special case 2: GMT may have an hour offset; treat it specially. if value[:3] == "GMT" { length = parseGMT(value) return length, true } // Special Case 3: Some time zones are not named, but have +/-00 format if value[0] == '+' || value[0] == '-' { length = parseSignedOffset(value) return length, true } // How many upper-case letters are there? Need at least three, at most five. var nUpper int for nUpper = 0; nUpper < 6; nUpper++ { if nUpper >= len(value) { break } if c := value[nUpper]; c < 'A' || 'Z' < c { break } } switch nUpper { case 0, 1, 2, 6: return 0, false case 5: // Must end in T to match. if value[4] == 'T' { return 5, true } case 4: // Must end in T, except one special case. if value[3] == 'T' || value[:4] == "WITA" { return 4, true } case 3: return 3, true } return 0, false }
go
func parseTimeZone(value string) (length int, ok bool) { if len(value) < 3 { return 0, false } // Special case 1: ChST and MeST are the only zones with a lower-case letter. if len(value) >= 4 && (value[:4] == "ChST" || value[:4] == "MeST") { return 4, true } // Special case 2: GMT may have an hour offset; treat it specially. if value[:3] == "GMT" { length = parseGMT(value) return length, true } // Special Case 3: Some time zones are not named, but have +/-00 format if value[0] == '+' || value[0] == '-' { length = parseSignedOffset(value) return length, true } // How many upper-case letters are there? Need at least three, at most five. var nUpper int for nUpper = 0; nUpper < 6; nUpper++ { if nUpper >= len(value) { break } if c := value[nUpper]; c < 'A' || 'Z' < c { break } } switch nUpper { case 0, 1, 2, 6: return 0, false case 5: // Must end in T to match. if value[4] == 'T' { return 5, true } case 4: // Must end in T, except one special case. if value[3] == 'T' || value[:4] == "WITA" { return 4, true } case 3: return 3, true } return 0, false }
[ "func", "parseTimeZone", "(", "value", "string", ")", "(", "length", "int", ",", "ok", "bool", ")", "{", "if", "len", "(", "value", ")", "<", "3", "{", "return", "0", ",", "false", "\n", "}", "\n", "// Special case 1: ChST and MeST are the only zones with a ...
// parseTimeZone parses a time zone string and returns its length. Time zones // are human-generated and unpredictable. We can't do precise error checking. // On the other hand, for a correct parse there must be a time zone at the // beginning of the string, so it's almost always true that there's one // there. We look at the beginning of the string for a run of upper-case letters. // If there are more than 5, it's an error. // If there are 4 or 5 and the last is a T, it's a time zone. // If there are 3, it's a time zone. // Otherwise, other than special cases, it's not a time zone. // GMT is special because it can have an hour offset.
[ "parseTimeZone", "parses", "a", "time", "zone", "string", "and", "returns", "its", "length", ".", "Time", "zones", "are", "human", "-", "generated", "and", "unpredictable", ".", "We", "can", "t", "do", "precise", "error", "checking", ".", "On", "the", "oth...
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/date_parser.go#L748-L792
18,419
dop251/goja
date_parser.go
parseGMT
func parseGMT(value string) int { value = value[3:] if len(value) == 0 { return 3 } return 3 + parseSignedOffset(value) }
go
func parseGMT(value string) int { value = value[3:] if len(value) == 0 { return 3 } return 3 + parseSignedOffset(value) }
[ "func", "parseGMT", "(", "value", "string", ")", "int", "{", "value", "=", "value", "[", "3", ":", "]", "\n", "if", "len", "(", "value", ")", "==", "0", "{", "return", "3", "\n", "}", "\n\n", "return", "3", "+", "parseSignedOffset", "(", "value", ...
// parseGMT parses a GMT time zone. The input string is known to start "GMT". // The function checks whether that is followed by a sign and a number in the // range -14 through 12 excluding zero.
[ "parseGMT", "parses", "a", "GMT", "time", "zone", ".", "The", "input", "string", "is", "known", "to", "start", "GMT", ".", "The", "function", "checks", "whether", "that", "is", "followed", "by", "a", "sign", "and", "a", "number", "in", "the", "range", ...
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/date_parser.go#L797-L804
18,420
dop251/goja
date_parser.go
startsWithLowerCase
func startsWithLowerCase(str string) bool { if len(str) == 0 { return false } c := str[0] return 'a' <= c && c <= 'z' }
go
func startsWithLowerCase(str string) bool { if len(str) == 0 { return false } c := str[0] return 'a' <= c && c <= 'z' }
[ "func", "startsWithLowerCase", "(", "str", "string", ")", "bool", "{", "if", "len", "(", "str", ")", "==", "0", "{", "return", "false", "\n", "}", "\n", "c", ":=", "str", "[", "0", "]", "\n", "return", "'a'", "<=", "c", "&&", "c", "<=", "'z'", ...
// startsWithLowerCase reports whether the string has a lower-case letter at the beginning. // Its purpose is to prevent matching strings like "Month" when looking for "Mon".
[ "startsWithLowerCase", "reports", "whether", "the", "string", "has", "a", "lower", "-", "case", "letter", "at", "the", "beginning", ".", "Its", "purpose", "is", "to", "prevent", "matching", "strings", "like", "Month", "when", "looking", "for", "Mon", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/date_parser.go#L854-L860
18,421
dop251/goja
object_goreflect.go
SetFieldNameMapper
func (r *Runtime) SetFieldNameMapper(mapper FieldNameMapper) { r.fieldNameMapper = mapper r.typeInfoCache = nil }
go
func (r *Runtime) SetFieldNameMapper(mapper FieldNameMapper) { r.fieldNameMapper = mapper r.typeInfoCache = nil }
[ "func", "(", "r", "*", "Runtime", ")", "SetFieldNameMapper", "(", "mapper", "FieldNameMapper", ")", "{", "r", ".", "fieldNameMapper", "=", "mapper", "\n", "r", ".", "typeInfoCache", "=", "nil", "\n", "}" ]
// Sets a custom field name mapper for Go types. It can be called at any time, however // the mapping for any given value is fixed at the point of creation. // Setting this to nil restores the default behaviour which is all exported fields and methods are mapped to their // original unchanged names.
[ "Sets", "a", "custom", "field", "name", "mapper", "for", "Go", "types", ".", "It", "can", "be", "called", "at", "any", "time", "however", "the", "mapping", "for", "any", "given", "value", "is", "fixed", "at", "the", "point", "of", "creation", ".", "Set...
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/object_goreflect.go#L515-L518
18,422
dop251/goja
builtin_global.go
parseInt
func parseInt(s string, base int) (Value, error) { var n int64 var err error var cutoff, maxVal int64 var sign bool i := 0 if len(s) < 1 { err = strconv.ErrSyntax goto Error } switch s[0] { case '-': sign = true s = s[1:] case '+': s = s[1:] } if len(s) < 1 { err = strconv.ErrSyntax goto Error } // Look for hex prefix. if s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X') { if base == 0 || base == 16 { base = 16 s = s[2:] } } switch { case len(s) < 1: err = strconv.ErrSyntax goto Error case 2 <= base && base <= 36: // valid base; nothing to do case base == 0: // Look for hex prefix. switch { case s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X'): if len(s) < 3 { err = strconv.ErrSyntax goto Error } base = 16 s = s[2:] default: base = 10 } default: err = errors.New("invalid base " + strconv.Itoa(base)) goto Error } // Cutoff is the smallest number such that cutoff*base > maxInt64. // Use compile-time constants for common cases. switch base { case 10: cutoff = math.MaxInt64/10 + 1 case 16: cutoff = math.MaxInt64/16 + 1 default: cutoff = math.MaxInt64/int64(base) + 1 } maxVal = math.MaxInt64 for ; i < len(s); i++ { if n >= cutoff { // n*base overflows return parseLargeInt(float64(n), s[i:], base, sign) } v := digitVal(s[i]) if v >= base { break } n *= int64(base) n1 := n + int64(v) if n1 < n || n1 > maxVal { // n+v overflows return parseLargeInt(float64(n)+float64(v), s[i+1:], base, sign) } n = n1 } if i == 0 { err = strconv.ErrSyntax goto Error } if sign { n = -n } return intToValue(n), nil Error: return _NaN, err }
go
func parseInt(s string, base int) (Value, error) { var n int64 var err error var cutoff, maxVal int64 var sign bool i := 0 if len(s) < 1 { err = strconv.ErrSyntax goto Error } switch s[0] { case '-': sign = true s = s[1:] case '+': s = s[1:] } if len(s) < 1 { err = strconv.ErrSyntax goto Error } // Look for hex prefix. if s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X') { if base == 0 || base == 16 { base = 16 s = s[2:] } } switch { case len(s) < 1: err = strconv.ErrSyntax goto Error case 2 <= base && base <= 36: // valid base; nothing to do case base == 0: // Look for hex prefix. switch { case s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X'): if len(s) < 3 { err = strconv.ErrSyntax goto Error } base = 16 s = s[2:] default: base = 10 } default: err = errors.New("invalid base " + strconv.Itoa(base)) goto Error } // Cutoff is the smallest number such that cutoff*base > maxInt64. // Use compile-time constants for common cases. switch base { case 10: cutoff = math.MaxInt64/10 + 1 case 16: cutoff = math.MaxInt64/16 + 1 default: cutoff = math.MaxInt64/int64(base) + 1 } maxVal = math.MaxInt64 for ; i < len(s); i++ { if n >= cutoff { // n*base overflows return parseLargeInt(float64(n), s[i:], base, sign) } v := digitVal(s[i]) if v >= base { break } n *= int64(base) n1 := n + int64(v) if n1 < n || n1 > maxVal { // n+v overflows return parseLargeInt(float64(n)+float64(v), s[i+1:], base, sign) } n = n1 } if i == 0 { err = strconv.ErrSyntax goto Error } if sign { n = -n } return intToValue(n), nil Error: return _NaN, err }
[ "func", "parseInt", "(", "s", "string", ",", "base", "int", ")", "(", "Value", ",", "error", ")", "{", "var", "n", "int64", "\n", "var", "err", "error", "\n", "var", "cutoff", ",", "maxVal", "int64", "\n", "var", "sign", "bool", "\n", "i", ":=", ...
// ECMAScript compatible version of strconv.ParseInt
[ "ECMAScript", "compatible", "version", "of", "strconv", ".", "ParseInt" ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/builtin_global.go#L275-L378
18,423
dop251/goja
string_ascii.go
strToInt
func strToInt(ss string) (int64, error) { if ss == "" { return 0, nil } if ss == "-0" { return 0, strconv.ErrSyntax } if len(ss) > 2 { switch ss[:2] { case "0x", "0X": i, _ := strconv.ParseInt(ss[2:], 16, 64) return i, nil case "0b", "0B": i, _ := strconv.ParseInt(ss[2:], 2, 64) return i, nil case "0o", "0O": i, _ := strconv.ParseInt(ss[2:], 8, 64) return i, nil } } return strconv.ParseInt(ss, 10, 64) }
go
func strToInt(ss string) (int64, error) { if ss == "" { return 0, nil } if ss == "-0" { return 0, strconv.ErrSyntax } if len(ss) > 2 { switch ss[:2] { case "0x", "0X": i, _ := strconv.ParseInt(ss[2:], 16, 64) return i, nil case "0b", "0B": i, _ := strconv.ParseInt(ss[2:], 2, 64) return i, nil case "0o", "0O": i, _ := strconv.ParseInt(ss[2:], 8, 64) return i, nil } } return strconv.ParseInt(ss, 10, 64) }
[ "func", "strToInt", "(", "ss", "string", ")", "(", "int64", ",", "error", ")", "{", "if", "ss", "==", "\"", "\"", "{", "return", "0", ",", "nil", "\n", "}", "\n", "if", "ss", "==", "\"", "\"", "{", "return", "0", ",", "strconv", ".", "ErrSyntax...
// ss must be trimmed
[ "ss", "must", "be", "trimmed" ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/string_ascii.go#L37-L58
18,424
dop251/goja
runtime.go
MustCompile
func MustCompile(name, src string, strict bool) *Program { prg, err := Compile(name, src, strict) if err != nil { panic(err) } return prg }
go
func MustCompile(name, src string, strict bool) *Program { prg, err := Compile(name, src, strict) if err != nil { panic(err) } return prg }
[ "func", "MustCompile", "(", "name", ",", "src", "string", ",", "strict", "bool", ")", "*", "Program", "{", "prg", ",", "err", ":=", "Compile", "(", "name", ",", "src", ",", "strict", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ...
// MustCompile is like Compile but panics if the code cannot be compiled. // It simplifies safe initialization of global variables holding compiled JavaScript code.
[ "MustCompile", "is", "like", "Compile", "but", "panics", "if", "the", "code", "cannot", "be", "compiled", ".", "It", "simplifies", "safe", "initialization", "of", "global", "variables", "holding", "compiled", "JavaScript", "code", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/runtime.go#L781-L788
18,425
dop251/goja
runtime.go
RunString
func (r *Runtime) RunString(str string) (Value, error) { return r.RunScript("", str) }
go
func (r *Runtime) RunString(str string) (Value, error) { return r.RunScript("", str) }
[ "func", "(", "r", "*", "Runtime", ")", "RunString", "(", "str", "string", ")", "(", "Value", ",", "error", ")", "{", "return", "r", ".", "RunScript", "(", "\"", "\"", ",", "str", ")", "\n", "}" ]
// RunString executes the given string in the global context.
[ "RunString", "executes", "the", "given", "string", "in", "the", "global", "context", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/runtime.go#L858-L860
18,426
dop251/goja
runtime.go
RunScript
func (r *Runtime) RunScript(name, src string) (Value, error) { p, err := Compile(name, src, false) if err != nil { return nil, err } return r.RunProgram(p) }
go
func (r *Runtime) RunScript(name, src string) (Value, error) { p, err := Compile(name, src, false) if err != nil { return nil, err } return r.RunProgram(p) }
[ "func", "(", "r", "*", "Runtime", ")", "RunScript", "(", "name", ",", "src", "string", ")", "(", "Value", ",", "error", ")", "{", "p", ",", "err", ":=", "Compile", "(", "name", ",", "src", ",", "false", ")", "\n\n", "if", "err", "!=", "nil", "{...
// RunScript executes the given string in the global context.
[ "RunScript", "executes", "the", "given", "string", "in", "the", "global", "context", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/runtime.go#L863-L871
18,427
dop251/goja
runtime.go
ExportTo
func (r *Runtime) ExportTo(v Value, target interface{}) error { tval := reflect.ValueOf(target) if tval.Kind() != reflect.Ptr || tval.IsNil() { return errors.New("target must be a non-nil pointer") } vv, err := r.toReflectValue(v, tval.Elem().Type()) if err != nil { return err } tval.Elem().Set(vv) return nil }
go
func (r *Runtime) ExportTo(v Value, target interface{}) error { tval := reflect.ValueOf(target) if tval.Kind() != reflect.Ptr || tval.IsNil() { return errors.New("target must be a non-nil pointer") } vv, err := r.toReflectValue(v, tval.Elem().Type()) if err != nil { return err } tval.Elem().Set(vv) return nil }
[ "func", "(", "r", "*", "Runtime", ")", "ExportTo", "(", "v", "Value", ",", "target", "interface", "{", "}", ")", "error", "{", "tval", ":=", "reflect", ".", "ValueOf", "(", "target", ")", "\n", "if", "tval", ".", "Kind", "(", ")", "!=", "reflect", ...
// ExportTo converts a JavaScript value into the specified Go value. The second parameter must be a non-nil pointer. // Returns error if conversion is not possible.
[ "ExportTo", "converts", "a", "JavaScript", "value", "into", "the", "specified", "Go", "value", ".", "The", "second", "parameter", "must", "be", "a", "non", "-", "nil", "pointer", ".", "Returns", "error", "if", "conversion", "is", "not", "possible", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/runtime.go#L1360-L1371
18,428
dop251/goja
runtime.go
Get
func (r *Runtime) Get(name string) Value { return r.globalObject.self.getStr(name) }
go
func (r *Runtime) Get(name string) Value { return r.globalObject.self.getStr(name) }
[ "func", "(", "r", "*", "Runtime", ")", "Get", "(", "name", "string", ")", "Value", "{", "return", "r", ".", "globalObject", ".", "self", ".", "getStr", "(", "name", ")", "\n", "}" ]
// Get the specified property of the global object.
[ "Get", "the", "specified", "property", "of", "the", "global", "object", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/runtime.go#L1385-L1387
18,429
dop251/goja
runtime.go
AssertFunction
func AssertFunction(v Value) (Callable, bool) { if obj, ok := v.(*Object); ok { if f, ok := obj.self.assertCallable(); ok { return func(this Value, args ...Value) (ret Value, err error) { defer func() { if x := recover(); x != nil { if ex, ok := x.(*InterruptedError); ok { err = ex } else { panic(x) } } }() ex := obj.runtime.vm.try(func() { ret = f(FunctionCall{ This: this, Arguments: args, }) }) if ex != nil { err = ex } obj.runtime.vm.clearStack() return }, true } } return nil, false }
go
func AssertFunction(v Value) (Callable, bool) { if obj, ok := v.(*Object); ok { if f, ok := obj.self.assertCallable(); ok { return func(this Value, args ...Value) (ret Value, err error) { defer func() { if x := recover(); x != nil { if ex, ok := x.(*InterruptedError); ok { err = ex } else { panic(x) } } }() ex := obj.runtime.vm.try(func() { ret = f(FunctionCall{ This: this, Arguments: args, }) }) if ex != nil { err = ex } obj.runtime.vm.clearStack() return }, true } } return nil, false }
[ "func", "AssertFunction", "(", "v", "Value", ")", "(", "Callable", ",", "bool", ")", "{", "if", "obj", ",", "ok", ":=", "v", ".", "(", "*", "Object", ")", ";", "ok", "{", "if", "f", ",", "ok", ":=", "obj", ".", "self", ".", "assertCallable", "(...
// AssertFunction checks if the Value is a function and returns a Callable.
[ "AssertFunction", "checks", "if", "the", "Value", "is", "a", "function", "and", "returns", "a", "Callable", "." ]
8d6ee3d1661108ff8433016620abb64dfa6d9937
https://github.com/dop251/goja/blob/8d6ee3d1661108ff8433016620abb64dfa6d9937/runtime.go#L1398-L1426
18,430
pelletier/go-toml
marshal.go
isPrimitive
func isPrimitive(mtype reflect.Type) bool { switch mtype.Kind() { case reflect.Ptr: return isPrimitive(mtype.Elem()) case reflect.Bool: return true case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return true case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: return true case reflect.Float32, reflect.Float64: return true case reflect.String: return true case reflect.Struct: return mtype == timeType || isCustomMarshaler(mtype) default: return false } }
go
func isPrimitive(mtype reflect.Type) bool { switch mtype.Kind() { case reflect.Ptr: return isPrimitive(mtype.Elem()) case reflect.Bool: return true case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return true case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: return true case reflect.Float32, reflect.Float64: return true case reflect.String: return true case reflect.Struct: return mtype == timeType || isCustomMarshaler(mtype) default: return false } }
[ "func", "isPrimitive", "(", "mtype", "reflect", ".", "Type", ")", "bool", "{", "switch", "mtype", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Ptr", ":", "return", "isPrimitive", "(", "mtype", ".", "Elem", "(", ")", ")", "\n", "case", "reflec...
// Check if the given marshal type maps to a Tree primitive
[ "Check", "if", "the", "given", "marshal", "type", "maps", "to", "a", "Tree", "primitive" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L73-L92
18,431
pelletier/go-toml
marshal.go
isTreeSlice
func isTreeSlice(mtype reflect.Type) bool { switch mtype.Kind() { case reflect.Slice: return !isOtherSlice(mtype) default: return false } }
go
func isTreeSlice(mtype reflect.Type) bool { switch mtype.Kind() { case reflect.Slice: return !isOtherSlice(mtype) default: return false } }
[ "func", "isTreeSlice", "(", "mtype", "reflect", ".", "Type", ")", "bool", "{", "switch", "mtype", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Slice", ":", "return", "!", "isOtherSlice", "(", "mtype", ")", "\n", "default", ":", "return", "false...
// Check if the given marshal type maps to a Tree slice
[ "Check", "if", "the", "given", "marshal", "type", "maps", "to", "a", "Tree", "slice" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L95-L102
18,432
pelletier/go-toml
marshal.go
isOtherSlice
func isOtherSlice(mtype reflect.Type) bool { switch mtype.Kind() { case reflect.Ptr: return isOtherSlice(mtype.Elem()) case reflect.Slice: return isPrimitive(mtype.Elem()) || isOtherSlice(mtype.Elem()) default: return false } }
go
func isOtherSlice(mtype reflect.Type) bool { switch mtype.Kind() { case reflect.Ptr: return isOtherSlice(mtype.Elem()) case reflect.Slice: return isPrimitive(mtype.Elem()) || isOtherSlice(mtype.Elem()) default: return false } }
[ "func", "isOtherSlice", "(", "mtype", "reflect", ".", "Type", ")", "bool", "{", "switch", "mtype", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Ptr", ":", "return", "isOtherSlice", "(", "mtype", ".", "Elem", "(", ")", ")", "\n", "case", "refl...
// Check if the given marshal type maps to a non-Tree slice
[ "Check", "if", "the", "given", "marshal", "type", "maps", "to", "a", "non", "-", "Tree", "slice" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L105-L114
18,433
pelletier/go-toml
marshal.go
isTree
func isTree(mtype reflect.Type) bool { switch mtype.Kind() { case reflect.Map: return true case reflect.Struct: return !isPrimitive(mtype) default: return false } }
go
func isTree(mtype reflect.Type) bool { switch mtype.Kind() { case reflect.Map: return true case reflect.Struct: return !isPrimitive(mtype) default: return false } }
[ "func", "isTree", "(", "mtype", "reflect", ".", "Type", ")", "bool", "{", "switch", "mtype", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Map", ":", "return", "true", "\n", "case", "reflect", ".", "Struct", ":", "return", "!", "isPrimitive", ...
// Check if the given marshal type maps to a Tree
[ "Check", "if", "the", "given", "marshal", "type", "maps", "to", "a", "Tree" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L117-L126
18,434
pelletier/go-toml
marshal.go
Encode
func (e *Encoder) Encode(v interface{}) error { b, err := e.marshal(v) if err != nil { return err } if _, err := e.w.Write(b); err != nil { return err } return nil }
go
func (e *Encoder) Encode(v interface{}) error { b, err := e.marshal(v) if err != nil { return err } if _, err := e.w.Write(b); err != nil { return err } return nil }
[ "func", "(", "e", "*", "Encoder", ")", "Encode", "(", "v", "interface", "{", "}", ")", "error", "{", "b", ",", "err", ":=", "e", ".", "marshal", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "_", ...
// Encode writes the TOML encoding of v to the stream. // // See the documentation for Marshal for details.
[ "Encode", "writes", "the", "TOML", "encoding", "of", "v", "to", "the", "stream", ".", "See", "the", "documentation", "for", "Marshal", "for", "details", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L206-L215
18,435
pelletier/go-toml
marshal.go
QuoteMapKeys
func (e *Encoder) QuoteMapKeys(v bool) *Encoder { e.quoteMapKeys = v return e }
go
func (e *Encoder) QuoteMapKeys(v bool) *Encoder { e.quoteMapKeys = v return e }
[ "func", "(", "e", "*", "Encoder", ")", "QuoteMapKeys", "(", "v", "bool", ")", "*", "Encoder", "{", "e", ".", "quoteMapKeys", "=", "v", "\n", "return", "e", "\n", "}" ]
// QuoteMapKeys sets up the encoder to encode // maps with string type keys with quoted TOML keys. // // This relieves the character limitations on map keys.
[ "QuoteMapKeys", "sets", "up", "the", "encoder", "to", "encode", "maps", "with", "string", "type", "keys", "with", "quoted", "TOML", "keys", ".", "This", "relieves", "the", "character", "limitations", "on", "map", "keys", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L221-L224
18,436
pelletier/go-toml
marshal.go
Order
func (e *Encoder) Order(ord marshalOrder) *Encoder { e.order = ord return e }
go
func (e *Encoder) Order(ord marshalOrder) *Encoder { e.order = ord return e }
[ "func", "(", "e", "*", "Encoder", ")", "Order", "(", "ord", "marshalOrder", ")", "*", "Encoder", "{", "e", ".", "order", "=", "ord", "\n", "return", "e", "\n", "}" ]
// Order allows to change in which order fields will be written to the output stream.
[ "Order", "allows", "to", "change", "in", "which", "order", "fields", "will", "be", "written", "to", "the", "output", "stream", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L246-L249
18,437
pelletier/go-toml
marshal.go
SetTagComment
func (e *Encoder) SetTagComment(v string) *Encoder { e.comment = v return e }
go
func (e *Encoder) SetTagComment(v string) *Encoder { e.comment = v return e }
[ "func", "(", "e", "*", "Encoder", ")", "SetTagComment", "(", "v", "string", ")", "*", "Encoder", "{", "e", ".", "comment", "=", "v", "\n", "return", "e", "\n", "}" ]
// SetTagComment allows changing default tag "comment"
[ "SetTagComment", "allows", "changing", "default", "tag", "comment" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L258-L261
18,438
pelletier/go-toml
marshal.go
SetTagCommented
func (e *Encoder) SetTagCommented(v string) *Encoder { e.commented = v return e }
go
func (e *Encoder) SetTagCommented(v string) *Encoder { e.commented = v return e }
[ "func", "(", "e", "*", "Encoder", ")", "SetTagCommented", "(", "v", "string", ")", "*", "Encoder", "{", "e", ".", "commented", "=", "v", "\n", "return", "e", "\n", "}" ]
// SetTagCommented allows changing default tag "commented"
[ "SetTagCommented", "allows", "changing", "default", "tag", "commented" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L264-L267
18,439
pelletier/go-toml
marshal.go
SetTagMultiline
func (e *Encoder) SetTagMultiline(v string) *Encoder { e.multiline = v return e }
go
func (e *Encoder) SetTagMultiline(v string) *Encoder { e.multiline = v return e }
[ "func", "(", "e", "*", "Encoder", ")", "SetTagMultiline", "(", "v", "string", ")", "*", "Encoder", "{", "e", ".", "multiline", "=", "v", "\n", "return", "e", "\n", "}" ]
// SetTagMultiline allows changing default tag "multiline"
[ "SetTagMultiline", "allows", "changing", "default", "tag", "multiline" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L270-L273
18,440
pelletier/go-toml
marshal.go
nextTree
func (e *Encoder) nextTree() *Tree { return newTreeWithPosition(Position{Line: e.line, Col: 1}) }
go
func (e *Encoder) nextTree() *Tree { return newTreeWithPosition(Position{Line: e.line, Col: 1}) }
[ "func", "(", "e", "*", "Encoder", ")", "nextTree", "(", ")", "*", "Tree", "{", "return", "newTreeWithPosition", "(", "Position", "{", "Line", ":", "e", ".", "line", ",", "Col", ":", "1", "}", ")", "\n", "}" ]
// Create next tree with a position based on Encoder.line
[ "Create", "next", "tree", "with", "a", "position", "based", "on", "Encoder", ".", "line" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L304-L306
18,441
pelletier/go-toml
marshal.go
valueToTree
func (e *Encoder) valueToTree(mtype reflect.Type, mval reflect.Value) (*Tree, error) { if mtype.Kind() == reflect.Ptr { return e.valueToTree(mtype.Elem(), mval.Elem()) } tval := e.nextTree() switch mtype.Kind() { case reflect.Struct: for i := 0; i < mtype.NumField(); i++ { mtypef, mvalf := mtype.Field(i), mval.Field(i) opts := tomlOptions(mtypef, e.annotation) if opts.include && (!opts.omitempty || !isZero(mvalf)) { val, err := e.valueToToml(mtypef.Type, mvalf) if err != nil { return nil, err } tval.SetWithOptions(opts.name, SetOptions{ Comment: opts.comment, Commented: opts.commented, Multiline: opts.multiline, }, val) } } case reflect.Map: keys := mval.MapKeys() if e.order == OrderPreserve && len(keys) > 0 { // Sorting []reflect.Value is not straight forward. // // OrderPreserve will support deterministic results when string is used // as the key to maps. typ := keys[0].Type() kind := keys[0].Kind() if kind == reflect.String { ikeys := make([]string, len(keys)) for i := range keys { ikeys[i] = keys[i].Interface().(string) } sort.Strings(ikeys) for i := range ikeys { keys[i] = reflect.ValueOf(ikeys[i]).Convert(typ) } } } for _, key := range keys { mvalf := mval.MapIndex(key) val, err := e.valueToToml(mtype.Elem(), mvalf) if err != nil { return nil, err } if e.quoteMapKeys { keyStr, err := tomlValueStringRepresentation(key.String(), "", e.arraysOneElementPerLine) if err != nil { return nil, err } tval.SetPath([]string{keyStr}, val) } else { tval.Set(key.String(), val) } } } return tval, nil }
go
func (e *Encoder) valueToTree(mtype reflect.Type, mval reflect.Value) (*Tree, error) { if mtype.Kind() == reflect.Ptr { return e.valueToTree(mtype.Elem(), mval.Elem()) } tval := e.nextTree() switch mtype.Kind() { case reflect.Struct: for i := 0; i < mtype.NumField(); i++ { mtypef, mvalf := mtype.Field(i), mval.Field(i) opts := tomlOptions(mtypef, e.annotation) if opts.include && (!opts.omitempty || !isZero(mvalf)) { val, err := e.valueToToml(mtypef.Type, mvalf) if err != nil { return nil, err } tval.SetWithOptions(opts.name, SetOptions{ Comment: opts.comment, Commented: opts.commented, Multiline: opts.multiline, }, val) } } case reflect.Map: keys := mval.MapKeys() if e.order == OrderPreserve && len(keys) > 0 { // Sorting []reflect.Value is not straight forward. // // OrderPreserve will support deterministic results when string is used // as the key to maps. typ := keys[0].Type() kind := keys[0].Kind() if kind == reflect.String { ikeys := make([]string, len(keys)) for i := range keys { ikeys[i] = keys[i].Interface().(string) } sort.Strings(ikeys) for i := range ikeys { keys[i] = reflect.ValueOf(ikeys[i]).Convert(typ) } } } for _, key := range keys { mvalf := mval.MapIndex(key) val, err := e.valueToToml(mtype.Elem(), mvalf) if err != nil { return nil, err } if e.quoteMapKeys { keyStr, err := tomlValueStringRepresentation(key.String(), "", e.arraysOneElementPerLine) if err != nil { return nil, err } tval.SetPath([]string{keyStr}, val) } else { tval.Set(key.String(), val) } } } return tval, nil }
[ "func", "(", "e", "*", "Encoder", ")", "valueToTree", "(", "mtype", "reflect", ".", "Type", ",", "mval", "reflect", ".", "Value", ")", "(", "*", "Tree", ",", "error", ")", "{", "if", "mtype", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{...
// Convert given marshal struct or map value to toml tree
[ "Convert", "given", "marshal", "struct", "or", "map", "value", "to", "toml", "tree" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L309-L370
18,442
pelletier/go-toml
marshal.go
valueToTreeSlice
func (e *Encoder) valueToTreeSlice(mtype reflect.Type, mval reflect.Value) ([]*Tree, error) { tval := make([]*Tree, mval.Len(), mval.Len()) for i := 0; i < mval.Len(); i++ { val, err := e.valueToTree(mtype.Elem(), mval.Index(i)) if err != nil { return nil, err } tval[i] = val } return tval, nil }
go
func (e *Encoder) valueToTreeSlice(mtype reflect.Type, mval reflect.Value) ([]*Tree, error) { tval := make([]*Tree, mval.Len(), mval.Len()) for i := 0; i < mval.Len(); i++ { val, err := e.valueToTree(mtype.Elem(), mval.Index(i)) if err != nil { return nil, err } tval[i] = val } return tval, nil }
[ "func", "(", "e", "*", "Encoder", ")", "valueToTreeSlice", "(", "mtype", "reflect", ".", "Type", ",", "mval", "reflect", ".", "Value", ")", "(", "[", "]", "*", "Tree", ",", "error", ")", "{", "tval", ":=", "make", "(", "[", "]", "*", "Tree", ",",...
// Convert given marshal slice to slice of Toml trees
[ "Convert", "given", "marshal", "slice", "to", "slice", "of", "Toml", "trees" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L373-L383
18,443
pelletier/go-toml
marshal.go
valueToOtherSlice
func (e *Encoder) valueToOtherSlice(mtype reflect.Type, mval reflect.Value) (interface{}, error) { tval := make([]interface{}, mval.Len(), mval.Len()) for i := 0; i < mval.Len(); i++ { val, err := e.valueToToml(mtype.Elem(), mval.Index(i)) if err != nil { return nil, err } tval[i] = val } return tval, nil }
go
func (e *Encoder) valueToOtherSlice(mtype reflect.Type, mval reflect.Value) (interface{}, error) { tval := make([]interface{}, mval.Len(), mval.Len()) for i := 0; i < mval.Len(); i++ { val, err := e.valueToToml(mtype.Elem(), mval.Index(i)) if err != nil { return nil, err } tval[i] = val } return tval, nil }
[ "func", "(", "e", "*", "Encoder", ")", "valueToOtherSlice", "(", "mtype", "reflect", ".", "Type", ",", "mval", "reflect", ".", "Value", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "tval", ":=", "make", "(", "[", "]", "interface", "{", ...
// Convert given marshal slice to slice of toml values
[ "Convert", "given", "marshal", "slice", "to", "slice", "of", "toml", "values" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L386-L396
18,444
pelletier/go-toml
marshal.go
valueToToml
func (e *Encoder) valueToToml(mtype reflect.Type, mval reflect.Value) (interface{}, error) { e.line++ if mtype.Kind() == reflect.Ptr { return e.valueToToml(mtype.Elem(), mval.Elem()) } switch { case isCustomMarshaler(mtype): return callCustomMarshaler(mval) case isTree(mtype): return e.valueToTree(mtype, mval) case isTreeSlice(mtype): return e.valueToTreeSlice(mtype, mval) case isOtherSlice(mtype): return e.valueToOtherSlice(mtype, mval) default: switch mtype.Kind() { case reflect.Bool: return mval.Bool(), nil case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: if mtype.Kind() == reflect.Int64 && mtype == reflect.TypeOf(time.Duration(1)) { return fmt.Sprint(mval), nil } return mval.Int(), nil case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: return mval.Uint(), nil case reflect.Float32, reflect.Float64: return mval.Float(), nil case reflect.String: return mval.String(), nil case reflect.Struct: return mval.Interface().(time.Time), nil default: return nil, fmt.Errorf("Marshal can't handle %v(%v)", mtype, mtype.Kind()) } } }
go
func (e *Encoder) valueToToml(mtype reflect.Type, mval reflect.Value) (interface{}, error) { e.line++ if mtype.Kind() == reflect.Ptr { return e.valueToToml(mtype.Elem(), mval.Elem()) } switch { case isCustomMarshaler(mtype): return callCustomMarshaler(mval) case isTree(mtype): return e.valueToTree(mtype, mval) case isTreeSlice(mtype): return e.valueToTreeSlice(mtype, mval) case isOtherSlice(mtype): return e.valueToOtherSlice(mtype, mval) default: switch mtype.Kind() { case reflect.Bool: return mval.Bool(), nil case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: if mtype.Kind() == reflect.Int64 && mtype == reflect.TypeOf(time.Duration(1)) { return fmt.Sprint(mval), nil } return mval.Int(), nil case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: return mval.Uint(), nil case reflect.Float32, reflect.Float64: return mval.Float(), nil case reflect.String: return mval.String(), nil case reflect.Struct: return mval.Interface().(time.Time), nil default: return nil, fmt.Errorf("Marshal can't handle %v(%v)", mtype, mtype.Kind()) } } }
[ "func", "(", "e", "*", "Encoder", ")", "valueToToml", "(", "mtype", "reflect", ".", "Type", ",", "mval", "reflect", ".", "Value", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "e", ".", "line", "++", "\n", "if", "mtype", ".", "Kind", "...
// Convert given marshal value to toml value
[ "Convert", "given", "marshal", "value", "to", "toml", "value" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L399-L434
18,445
pelletier/go-toml
marshal.go
Unmarshal
func (t *Tree) Unmarshal(v interface{}) error { d := Decoder{tval: t, tagName: tagFieldName} return d.unmarshal(v) }
go
func (t *Tree) Unmarshal(v interface{}) error { d := Decoder{tval: t, tagName: tagFieldName} return d.unmarshal(v) }
[ "func", "(", "t", "*", "Tree", ")", "Unmarshal", "(", "v", "interface", "{", "}", ")", "error", "{", "d", ":=", "Decoder", "{", "tval", ":", "t", ",", "tagName", ":", "tagFieldName", "}", "\n", "return", "d", ".", "unmarshal", "(", "v", ")", "\n"...
// Unmarshal attempts to unmarshal the Tree into a Go struct pointed by v. // Neither Unmarshaler interfaces nor UnmarshalTOML functions are supported for // sub-structs, and only definite types can be unmarshaled.
[ "Unmarshal", "attempts", "to", "unmarshal", "the", "Tree", "into", "a", "Go", "struct", "pointed", "by", "v", ".", "Neither", "Unmarshaler", "interfaces", "nor", "UnmarshalTOML", "functions", "are", "supported", "for", "sub", "-", "structs", "and", "only", "de...
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L439-L442
18,446
pelletier/go-toml
marshal.go
Decode
func (d *Decoder) Decode(v interface{}) error { var err error d.tval, err = LoadReader(d.r) if err != nil { return err } return d.unmarshal(v) }
go
func (d *Decoder) Decode(v interface{}) error { var err error d.tval, err = LoadReader(d.r) if err != nil { return err } return d.unmarshal(v) }
[ "func", "(", "d", "*", "Decoder", ")", "Decode", "(", "v", "interface", "{", "}", ")", "error", "{", "var", "err", "error", "\n", "d", ".", "tval", ",", "err", "=", "LoadReader", "(", "d", ".", "r", ")", "\n", "if", "err", "!=", "nil", "{", "...
// Decode reads a TOML-encoded value from it's input // and unmarshals it in the value pointed at by v. // // See the documentation for Marshal for details.
[ "Decode", "reads", "a", "TOML", "-", "encoded", "value", "from", "it", "s", "input", "and", "unmarshals", "it", "in", "the", "value", "pointed", "at", "by", "v", ".", "See", "the", "documentation", "for", "Marshal", "for", "details", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L500-L507
18,447
pelletier/go-toml
marshal.go
valueFromOtherSlice
func (d *Decoder) valueFromOtherSlice(mtype reflect.Type, tval []interface{}) (reflect.Value, error) { mval := reflect.MakeSlice(mtype, len(tval), len(tval)) for i := 0; i < len(tval); i++ { val, err := d.valueFromToml(mtype.Elem(), tval[i]) if err != nil { return mval, err } mval.Index(i).Set(val) } return mval, nil }
go
func (d *Decoder) valueFromOtherSlice(mtype reflect.Type, tval []interface{}) (reflect.Value, error) { mval := reflect.MakeSlice(mtype, len(tval), len(tval)) for i := 0; i < len(tval); i++ { val, err := d.valueFromToml(mtype.Elem(), tval[i]) if err != nil { return mval, err } mval.Index(i).Set(val) } return mval, nil }
[ "func", "(", "d", "*", "Decoder", ")", "valueFromOtherSlice", "(", "mtype", "reflect", ".", "Type", ",", "tval", "[", "]", "interface", "{", "}", ")", "(", "reflect", ".", "Value", ",", "error", ")", "{", "mval", ":=", "reflect", ".", "MakeSlice", "(...
// Convert toml value to marshal primitive slice, using marshal type
[ "Convert", "toml", "value", "to", "marshal", "primitive", "slice", "using", "marshal", "type" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/marshal.go#L638-L648
18,448
pelletier/go-toml
lexer.go
read
func (l *tomlLexer) read() rune { r := l.peek() if r == '\n' { l.endbufferLine++ l.endbufferCol = 1 } else { l.endbufferCol++ } l.inputIdx++ return r }
go
func (l *tomlLexer) read() rune { r := l.peek() if r == '\n' { l.endbufferLine++ l.endbufferCol = 1 } else { l.endbufferCol++ } l.inputIdx++ return r }
[ "func", "(", "l", "*", "tomlLexer", ")", "read", "(", ")", "rune", "{", "r", ":=", "l", ".", "peek", "(", ")", "\n", "if", "r", "==", "'\\n'", "{", "l", ".", "endbufferLine", "++", "\n", "l", ".", "endbufferCol", "=", "1", "\n", "}", "else", ...
// Basic read operations on input
[ "Basic", "read", "operations", "on", "input" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/lexer.go#L38-L48
18,449
pelletier/go-toml
lexer.go
lexKey
func (l *tomlLexer) lexKey() tomlLexStateFn { growingString := "" for r := l.peek(); isKeyChar(r) || r == '\n' || r == '\r'; r = l.peek() { if r == '"' { l.next() str, err := l.lexStringAsString(`"`, false, true) if err != nil { return l.errorf(err.Error()) } growingString += "\"" + str + "\"" l.next() continue } else if r == '\'' { l.next() str, err := l.lexLiteralStringAsString(`'`, false) if err != nil { return l.errorf(err.Error()) } growingString += "'" + str + "'" l.next() continue } else if r == '\n' { return l.errorf("keys cannot contain new lines") } else if isSpace(r) { break } else if r == '.' { // skip } else if !isValidBareChar(r) { return l.errorf("keys cannot contain %c character", r) } growingString += string(r) l.next() } l.emitWithValue(tokenKey, growingString) return l.lexVoid }
go
func (l *tomlLexer) lexKey() tomlLexStateFn { growingString := "" for r := l.peek(); isKeyChar(r) || r == '\n' || r == '\r'; r = l.peek() { if r == '"' { l.next() str, err := l.lexStringAsString(`"`, false, true) if err != nil { return l.errorf(err.Error()) } growingString += "\"" + str + "\"" l.next() continue } else if r == '\'' { l.next() str, err := l.lexLiteralStringAsString(`'`, false) if err != nil { return l.errorf(err.Error()) } growingString += "'" + str + "'" l.next() continue } else if r == '\n' { return l.errorf("keys cannot contain new lines") } else if isSpace(r) { break } else if r == '.' { // skip } else if !isValidBareChar(r) { return l.errorf("keys cannot contain %c character", r) } growingString += string(r) l.next() } l.emitWithValue(tokenKey, growingString) return l.lexVoid }
[ "func", "(", "l", "*", "tomlLexer", ")", "lexKey", "(", ")", "tomlLexStateFn", "{", "growingString", ":=", "\"", "\"", "\n\n", "for", "r", ":=", "l", ".", "peek", "(", ")", ";", "isKeyChar", "(", "r", ")", "||", "r", "==", "'\\n'", "||", "r", "==...
// Parse the key and emits its value without escape sequences. // bare keys, basic string keys and literal string keys are supported.
[ "Parse", "the", "key", "and", "emits", "its", "value", "without", "escape", "sequences", ".", "bare", "keys", "basic", "string", "keys", "and", "literal", "string", "keys", "are", "supported", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/lexer.go#L302-L338
18,450
pelletier/go-toml
lexer.go
lexStringAsString
func (l *tomlLexer) lexStringAsString(terminator string, discardLeadingNewLine, acceptNewLines bool) (string, error) { growingString := "" if discardLeadingNewLine { if l.follow("\r\n") { l.skip() l.skip() } else if l.peek() == '\n' { l.skip() } } for { if l.follow(terminator) { return growingString, nil } if l.follow("\\") { l.next() switch l.peek() { case '\r': fallthrough case '\n': fallthrough case '\t': fallthrough case ' ': // skip all whitespace chars following backslash for strings.ContainsRune("\r\n\t ", l.peek()) { l.next() } case '"': growingString += "\"" l.next() case 'n': growingString += "\n" l.next() case 'b': growingString += "\b" l.next() case 'f': growingString += "\f" l.next() case '/': growingString += "/" l.next() case 't': growingString += "\t" l.next() case 'r': growingString += "\r" l.next() case '\\': growingString += "\\" l.next() case 'u': l.next() code := "" for i := 0; i < 4; i++ { c := l.peek() if !isHexDigit(c) { return "", errors.New("unfinished unicode escape") } l.next() code = code + string(c) } intcode, err := strconv.ParseInt(code, 16, 32) if err != nil { return "", errors.New("invalid unicode escape: \\u" + code) } growingString += string(rune(intcode)) case 'U': l.next() code := "" for i := 0; i < 8; i++ { c := l.peek() if !isHexDigit(c) { return "", errors.New("unfinished unicode escape") } l.next() code = code + string(c) } intcode, err := strconv.ParseInt(code, 16, 64) if err != nil { return "", errors.New("invalid unicode escape: \\U" + code) } growingString += string(rune(intcode)) default: return "", errors.New("invalid escape sequence: \\" + string(l.peek())) } } else { r := l.peek() if 0x00 <= r && r <= 0x1F && !(acceptNewLines && (r == '\n' || r == '\r')) { return "", fmt.Errorf("unescaped control character %U", r) } l.next() growingString += string(r) } if l.peek() == eof { break } } return "", errors.New("unclosed string") }
go
func (l *tomlLexer) lexStringAsString(terminator string, discardLeadingNewLine, acceptNewLines bool) (string, error) { growingString := "" if discardLeadingNewLine { if l.follow("\r\n") { l.skip() l.skip() } else if l.peek() == '\n' { l.skip() } } for { if l.follow(terminator) { return growingString, nil } if l.follow("\\") { l.next() switch l.peek() { case '\r': fallthrough case '\n': fallthrough case '\t': fallthrough case ' ': // skip all whitespace chars following backslash for strings.ContainsRune("\r\n\t ", l.peek()) { l.next() } case '"': growingString += "\"" l.next() case 'n': growingString += "\n" l.next() case 'b': growingString += "\b" l.next() case 'f': growingString += "\f" l.next() case '/': growingString += "/" l.next() case 't': growingString += "\t" l.next() case 'r': growingString += "\r" l.next() case '\\': growingString += "\\" l.next() case 'u': l.next() code := "" for i := 0; i < 4; i++ { c := l.peek() if !isHexDigit(c) { return "", errors.New("unfinished unicode escape") } l.next() code = code + string(c) } intcode, err := strconv.ParseInt(code, 16, 32) if err != nil { return "", errors.New("invalid unicode escape: \\u" + code) } growingString += string(rune(intcode)) case 'U': l.next() code := "" for i := 0; i < 8; i++ { c := l.peek() if !isHexDigit(c) { return "", errors.New("unfinished unicode escape") } l.next() code = code + string(c) } intcode, err := strconv.ParseInt(code, 16, 64) if err != nil { return "", errors.New("invalid unicode escape: \\U" + code) } growingString += string(rune(intcode)) default: return "", errors.New("invalid escape sequence: \\" + string(l.peek())) } } else { r := l.peek() if 0x00 <= r && r <= 0x1F && !(acceptNewLines && (r == '\n' || r == '\r')) { return "", fmt.Errorf("unescaped control character %U", r) } l.next() growingString += string(r) } if l.peek() == eof { break } } return "", errors.New("unclosed string") }
[ "func", "(", "l", "*", "tomlLexer", ")", "lexStringAsString", "(", "terminator", "string", ",", "discardLeadingNewLine", ",", "acceptNewLines", "bool", ")", "(", "string", ",", "error", ")", "{", "growingString", ":=", "\"", "\"", "\n\n", "if", "discardLeading...
// Lex a string and return the results as a string. // Terminator is the substring indicating the end of the token. // The resulting string does not include the terminator.
[ "Lex", "a", "string", "and", "return", "the", "results", "as", "a", "string", ".", "Terminator", "is", "the", "substring", "indicating", "the", "end", "of", "the", "token", ".", "The", "resulting", "string", "does", "not", "include", "the", "terminator", "...
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/lexer.go#L414-L520
18,451
pelletier/go-toml
lexer.go
lexInsideTableArrayKey
func (l *tomlLexer) lexInsideTableArrayKey() tomlLexStateFn { for r := l.peek(); r != eof; r = l.peek() { switch r { case ']': if l.currentTokenStop > l.currentTokenStart { l.emit(tokenKeyGroupArray) } l.next() if l.peek() != ']' { break } l.next() l.emit(tokenDoubleRightBracket) return l.lexVoid case '[': return l.errorf("table array key cannot contain ']'") default: l.next() } } return l.errorf("unclosed table array key") }
go
func (l *tomlLexer) lexInsideTableArrayKey() tomlLexStateFn { for r := l.peek(); r != eof; r = l.peek() { switch r { case ']': if l.currentTokenStop > l.currentTokenStart { l.emit(tokenKeyGroupArray) } l.next() if l.peek() != ']' { break } l.next() l.emit(tokenDoubleRightBracket) return l.lexVoid case '[': return l.errorf("table array key cannot contain ']'") default: l.next() } } return l.errorf("unclosed table array key") }
[ "func", "(", "l", "*", "tomlLexer", ")", "lexInsideTableArrayKey", "(", ")", "tomlLexStateFn", "{", "for", "r", ":=", "l", ".", "peek", "(", ")", ";", "r", "!=", "eof", ";", "r", "=", "l", ".", "peek", "(", ")", "{", "switch", "r", "{", "case", ...
// Parse the key till "]]", but only bare keys are supported
[ "Parse", "the", "key", "till", "]]", "but", "only", "bare", "keys", "are", "supported" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/lexer.go#L564-L585
18,452
pelletier/go-toml
lexer.go
lexInsideTableKey
func (l *tomlLexer) lexInsideTableKey() tomlLexStateFn { for r := l.peek(); r != eof; r = l.peek() { switch r { case ']': if l.currentTokenStop > l.currentTokenStart { l.emit(tokenKeyGroup) } l.next() l.emit(tokenRightBracket) return l.lexVoid case '[': return l.errorf("table key cannot contain ']'") default: l.next() } } return l.errorf("unclosed table key") }
go
func (l *tomlLexer) lexInsideTableKey() tomlLexStateFn { for r := l.peek(); r != eof; r = l.peek() { switch r { case ']': if l.currentTokenStop > l.currentTokenStart { l.emit(tokenKeyGroup) } l.next() l.emit(tokenRightBracket) return l.lexVoid case '[': return l.errorf("table key cannot contain ']'") default: l.next() } } return l.errorf("unclosed table key") }
[ "func", "(", "l", "*", "tomlLexer", ")", "lexInsideTableKey", "(", ")", "tomlLexStateFn", "{", "for", "r", ":=", "l", ".", "peek", "(", ")", ";", "r", "!=", "eof", ";", "r", "=", "l", ".", "peek", "(", ")", "{", "switch", "r", "{", "case", "']'...
// Parse the key till "]" but only bare keys are supported
[ "Parse", "the", "key", "till", "]", "but", "only", "bare", "keys", "are", "supported" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/lexer.go#L588-L605
18,453
pelletier/go-toml
toml.go
TreeFromMap
func TreeFromMap(m map[string]interface{}) (*Tree, error) { result, err := toTree(m) if err != nil { return nil, err } return result.(*Tree), nil }
go
func TreeFromMap(m map[string]interface{}) (*Tree, error) { result, err := toTree(m) if err != nil { return nil, err } return result.(*Tree), nil }
[ "func", "TreeFromMap", "(", "m", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "*", "Tree", ",", "error", ")", "{", "result", ",", "err", ":=", "toTree", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "e...
// TreeFromMap initializes a new Tree object using the given map.
[ "TreeFromMap", "initializes", "a", "new", "Tree", "object", "using", "the", "given", "map", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L41-L47
18,454
pelletier/go-toml
toml.go
Has
func (t *Tree) Has(key string) bool { if key == "" { return false } return t.HasPath(strings.Split(key, ".")) }
go
func (t *Tree) Has(key string) bool { if key == "" { return false } return t.HasPath(strings.Split(key, ".")) }
[ "func", "(", "t", "*", "Tree", ")", "Has", "(", "key", "string", ")", "bool", "{", "if", "key", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n", "return", "t", ".", "HasPath", "(", "strings", ".", "Split", "(", "key", ",", "\"", "\"",...
// Has returns a boolean indicating if the given key exists.
[ "Has", "returns", "a", "boolean", "indicating", "if", "the", "given", "key", "exists", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L55-L60
18,455
pelletier/go-toml
toml.go
HasPath
func (t *Tree) HasPath(keys []string) bool { return t.GetPath(keys) != nil }
go
func (t *Tree) HasPath(keys []string) bool { return t.GetPath(keys) != nil }
[ "func", "(", "t", "*", "Tree", ")", "HasPath", "(", "keys", "[", "]", "string", ")", "bool", "{", "return", "t", ".", "GetPath", "(", "keys", ")", "!=", "nil", "\n", "}" ]
// HasPath returns true if the given path of keys exists, false otherwise.
[ "HasPath", "returns", "true", "if", "the", "given", "path", "of", "keys", "exists", "false", "otherwise", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L63-L65
18,456
pelletier/go-toml
toml.go
GetPath
func (t *Tree) GetPath(keys []string) interface{} { if len(keys) == 0 { return t } subtree := t for _, intermediateKey := range keys[:len(keys)-1] { value, exists := subtree.values[intermediateKey] if !exists { return nil } switch node := value.(type) { case *Tree: subtree = node case []*Tree: // go to most recent element if len(node) == 0 { return nil } subtree = node[len(node)-1] default: return nil // cannot navigate through other node types } } // branch based on final node type switch node := subtree.values[keys[len(keys)-1]].(type) { case *tomlValue: return node.value default: return node } }
go
func (t *Tree) GetPath(keys []string) interface{} { if len(keys) == 0 { return t } subtree := t for _, intermediateKey := range keys[:len(keys)-1] { value, exists := subtree.values[intermediateKey] if !exists { return nil } switch node := value.(type) { case *Tree: subtree = node case []*Tree: // go to most recent element if len(node) == 0 { return nil } subtree = node[len(node)-1] default: return nil // cannot navigate through other node types } } // branch based on final node type switch node := subtree.values[keys[len(keys)-1]].(type) { case *tomlValue: return node.value default: return node } }
[ "func", "(", "t", "*", "Tree", ")", "GetPath", "(", "keys", "[", "]", "string", ")", "interface", "{", "}", "{", "if", "len", "(", "keys", ")", "==", "0", "{", "return", "t", "\n", "}", "\n", "subtree", ":=", "t", "\n", "for", "_", ",", "inte...
// GetPath returns the element in the tree indicated by 'keys'. // If keys is of length zero, the current tree is returned.
[ "GetPath", "returns", "the", "element", "in", "the", "tree", "indicated", "by", "keys", ".", "If", "keys", "is", "of", "length", "zero", "the", "current", "tree", "is", "returned", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L92-L122
18,457
pelletier/go-toml
toml.go
GetPosition
func (t *Tree) GetPosition(key string) Position { if key == "" { return t.position } return t.GetPositionPath(strings.Split(key, ".")) }
go
func (t *Tree) GetPosition(key string) Position { if key == "" { return t.position } return t.GetPositionPath(strings.Split(key, ".")) }
[ "func", "(", "t", "*", "Tree", ")", "GetPosition", "(", "key", "string", ")", "Position", "{", "if", "key", "==", "\"", "\"", "{", "return", "t", ".", "position", "\n", "}", "\n", "return", "t", ".", "GetPositionPath", "(", "strings", ".", "Split", ...
// GetPosition returns the position of the given key.
[ "GetPosition", "returns", "the", "position", "of", "the", "given", "key", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L125-L130
18,458
pelletier/go-toml
toml.go
GetPositionPath
func (t *Tree) GetPositionPath(keys []string) Position { if len(keys) == 0 { return t.position } subtree := t for _, intermediateKey := range keys[:len(keys)-1] { value, exists := subtree.values[intermediateKey] if !exists { return Position{0, 0} } switch node := value.(type) { case *Tree: subtree = node case []*Tree: // go to most recent element if len(node) == 0 { return Position{0, 0} } subtree = node[len(node)-1] default: return Position{0, 0} } } // branch based on final node type switch node := subtree.values[keys[len(keys)-1]].(type) { case *tomlValue: return node.position case *Tree: return node.position case []*Tree: // go to most recent element if len(node) == 0 { return Position{0, 0} } return node[len(node)-1].position default: return Position{0, 0} } }
go
func (t *Tree) GetPositionPath(keys []string) Position { if len(keys) == 0 { return t.position } subtree := t for _, intermediateKey := range keys[:len(keys)-1] { value, exists := subtree.values[intermediateKey] if !exists { return Position{0, 0} } switch node := value.(type) { case *Tree: subtree = node case []*Tree: // go to most recent element if len(node) == 0 { return Position{0, 0} } subtree = node[len(node)-1] default: return Position{0, 0} } } // branch based on final node type switch node := subtree.values[keys[len(keys)-1]].(type) { case *tomlValue: return node.position case *Tree: return node.position case []*Tree: // go to most recent element if len(node) == 0 { return Position{0, 0} } return node[len(node)-1].position default: return Position{0, 0} } }
[ "func", "(", "t", "*", "Tree", ")", "GetPositionPath", "(", "keys", "[", "]", "string", ")", "Position", "{", "if", "len", "(", "keys", ")", "==", "0", "{", "return", "t", ".", "position", "\n", "}", "\n", "subtree", ":=", "t", "\n", "for", "_", ...
// GetPositionPath returns the element in the tree indicated by 'keys'. // If keys is of length zero, the current tree is returned.
[ "GetPositionPath", "returns", "the", "element", "in", "the", "tree", "indicated", "by", "keys", ".", "If", "keys", "is", "of", "length", "zero", "the", "current", "tree", "is", "returned", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L134-L172
18,459
pelletier/go-toml
toml.go
GetDefault
func (t *Tree) GetDefault(key string, def interface{}) interface{} { val := t.Get(key) if val == nil { return def } return val }
go
func (t *Tree) GetDefault(key string, def interface{}) interface{} { val := t.Get(key) if val == nil { return def } return val }
[ "func", "(", "t", "*", "Tree", ")", "GetDefault", "(", "key", "string", ",", "def", "interface", "{", "}", ")", "interface", "{", "}", "{", "val", ":=", "t", ".", "Get", "(", "key", ")", "\n", "if", "val", "==", "nil", "{", "return", "def", "\n...
// GetDefault works like Get but with a default value
[ "GetDefault", "works", "like", "Get", "but", "with", "a", "default", "value" ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L175-L181
18,460
pelletier/go-toml
toml.go
LoadReader
func LoadReader(reader io.Reader) (tree *Tree, err error) { inputBytes, err := ioutil.ReadAll(reader) if err != nil { return } tree, err = LoadBytes(inputBytes) return }
go
func LoadReader(reader io.Reader) (tree *Tree, err error) { inputBytes, err := ioutil.ReadAll(reader) if err != nil { return } tree, err = LoadBytes(inputBytes) return }
[ "func", "LoadReader", "(", "reader", "io", ".", "Reader", ")", "(", "tree", "*", "Tree", ",", "err", "error", ")", "{", "inputBytes", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n...
// LoadReader creates a Tree from any io.Reader.
[ "LoadReader", "creates", "a", "Tree", "from", "any", "io", ".", "Reader", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L371-L378
18,461
pelletier/go-toml
toml.go
Load
func Load(content string) (tree *Tree, err error) { return LoadBytes([]byte(content)) }
go
func Load(content string) (tree *Tree, err error) { return LoadBytes([]byte(content)) }
[ "func", "Load", "(", "content", "string", ")", "(", "tree", "*", "Tree", ",", "err", "error", ")", "{", "return", "LoadBytes", "(", "[", "]", "byte", "(", "content", ")", ")", "\n", "}" ]
// Load creates a Tree from a string.
[ "Load", "creates", "a", "Tree", "from", "a", "string", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L381-L383
18,462
pelletier/go-toml
toml.go
LoadFile
func LoadFile(path string) (tree *Tree, err error) { file, err := os.Open(path) if err != nil { return nil, err } defer file.Close() return LoadReader(file) }
go
func LoadFile(path string) (tree *Tree, err error) { file, err := os.Open(path) if err != nil { return nil, err } defer file.Close() return LoadReader(file) }
[ "func", "LoadFile", "(", "path", "string", ")", "(", "tree", "*", "Tree", ",", "err", "error", ")", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}",...
// LoadFile creates a Tree from a file.
[ "LoadFile", "creates", "a", "Tree", "from", "a", "file", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L386-L393
18,463
pelletier/go-toml
tomltree_write.go
encodeMultilineTomlString
func encodeMultilineTomlString(value string) string { var b bytes.Buffer for _, rr := range value { switch rr { case '\b': b.WriteString(`\b`) case '\t': b.WriteString("\t") case '\n': b.WriteString("\n") case '\f': b.WriteString(`\f`) case '\r': b.WriteString("\r") case '"': b.WriteString(`"`) case '\\': b.WriteString(`\`) default: intRr := uint16(rr) if intRr < 0x001F { b.WriteString(fmt.Sprintf("\\u%0.4X", intRr)) } else { b.WriteRune(rr) } } } return b.String() }
go
func encodeMultilineTomlString(value string) string { var b bytes.Buffer for _, rr := range value { switch rr { case '\b': b.WriteString(`\b`) case '\t': b.WriteString("\t") case '\n': b.WriteString("\n") case '\f': b.WriteString(`\f`) case '\r': b.WriteString("\r") case '"': b.WriteString(`"`) case '\\': b.WriteString(`\`) default: intRr := uint16(rr) if intRr < 0x001F { b.WriteString(fmt.Sprintf("\\u%0.4X", intRr)) } else { b.WriteRune(rr) } } } return b.String() }
[ "func", "encodeMultilineTomlString", "(", "value", "string", ")", "string", "{", "var", "b", "bytes", ".", "Buffer", "\n\n", "for", "_", ",", "rr", ":=", "range", "value", "{", "switch", "rr", "{", "case", "'\\b'", ":", "b", ".", "WriteString", "(", "`...
// Encodes a string to a TOML-compliant multi-line string value // This function is a clone of the existing encodeTomlString function, except that whitespace characters // are preserved. Quotation marks and backslashes are also not escaped.
[ "Encodes", "a", "string", "to", "a", "TOML", "-", "compliant", "multi", "-", "line", "string", "value", "This", "function", "is", "a", "clone", "of", "the", "existing", "encodeTomlString", "function", "except", "that", "whitespace", "characters", "are", "prese...
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/tomltree_write.go#L30-L59
18,464
pelletier/go-toml
tomltree_write.go
WriteTo
func (t *Tree) WriteTo(w io.Writer) (int64, error) { return t.writeTo(w, "", "", 0, false) }
go
func (t *Tree) WriteTo(w io.Writer) (int64, error) { return t.writeTo(w, "", "", 0, false) }
[ "func", "(", "t", "*", "Tree", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "return", "t", ".", "writeTo", "(", "w", ",", "\"", "\"", ",", "\"", "\"", ",", "0", ",", "false", ")", "\n", "}" ]
// WriteTo encode the Tree as Toml and writes it to the writer w. // Returns the number of bytes written in case of success, or an error if anything happened.
[ "WriteTo", "encode", "the", "Tree", "as", "Toml", "and", "writes", "it", "to", "the", "writer", "w", ".", "Returns", "the", "number", "of", "bytes", "written", "in", "case", "of", "success", "or", "an", "error", "if", "anything", "happened", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/tomltree_write.go#L382-L384
18,465
pelletier/go-toml
tomltree_write.go
ToTomlString
func (t *Tree) ToTomlString() (string, error) { var buf bytes.Buffer _, err := t.WriteTo(&buf) if err != nil { return "", err } return buf.String(), nil }
go
func (t *Tree) ToTomlString() (string, error) { var buf bytes.Buffer _, err := t.WriteTo(&buf) if err != nil { return "", err } return buf.String(), nil }
[ "func", "(", "t", "*", "Tree", ")", "ToTomlString", "(", ")", "(", "string", ",", "error", ")", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "_", ",", "err", ":=", "t", ".", "WriteTo", "(", "&", "buf", ")", "\n", "if", "err", "!=", "nil", ...
// ToTomlString generates a human-readable representation of the current tree. // Output spans multiple lines, and is suitable for ingest by a TOML parser. // If the conversion cannot be performed, ToString returns a non-nil error.
[ "ToTomlString", "generates", "a", "human", "-", "readable", "representation", "of", "the", "current", "tree", ".", "Output", "spans", "multiple", "lines", "and", "is", "suitable", "for", "ingest", "by", "a", "TOML", "parser", ".", "If", "the", "conversion", ...
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/tomltree_write.go#L389-L396
18,466
pelletier/go-toml
query/query.go
Execute
func (q *Query) Execute(tree *toml.Tree) *Result { result := &Result{ items: []interface{}{}, positions: []toml.Position{}, } if q.root == nil { result.appendResult(tree, tree.GetPosition("")) } else { ctx := &queryContext{ result: result, filters: q.filters, } ctx.lastPosition = tree.Position() q.root.call(tree, ctx) } return result }
go
func (q *Query) Execute(tree *toml.Tree) *Result { result := &Result{ items: []interface{}{}, positions: []toml.Position{}, } if q.root == nil { result.appendResult(tree, tree.GetPosition("")) } else { ctx := &queryContext{ result: result, filters: q.filters, } ctx.lastPosition = tree.Position() q.root.call(tree, ctx) } return result }
[ "func", "(", "q", "*", "Query", ")", "Execute", "(", "tree", "*", "toml", ".", "Tree", ")", "*", "Result", "{", "result", ":=", "&", "Result", "{", "items", ":", "[", "]", "interface", "{", "}", "{", "}", ",", "positions", ":", "[", "]", "toml"...
// Execute executes a query against a Tree, and returns the result of the query.
[ "Execute", "executes", "a", "query", "against", "a", "Tree", "and", "returns", "the", "result", "of", "the", "query", "." ]
728039f679cbcd4f6a54e080d2219a4c4928c546
https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/query/query.go#L93-L109
18,467
spf13/cast
caste.go
ToTimeE
func ToTimeE(i interface{}) (tim time.Time, err error) { i = indirect(i) switch v := i.(type) { case time.Time: return v, nil case string: return StringToDate(v) case int: return time.Unix(int64(v), 0), nil case int64: return time.Unix(v, 0), nil case int32: return time.Unix(int64(v), 0), nil case uint: return time.Unix(int64(v), 0), nil case uint64: return time.Unix(int64(v), 0), nil case uint32: return time.Unix(int64(v), 0), nil default: return time.Time{}, fmt.Errorf("unable to cast %#v of type %T to Time", i, i) } }
go
func ToTimeE(i interface{}) (tim time.Time, err error) { i = indirect(i) switch v := i.(type) { case time.Time: return v, nil case string: return StringToDate(v) case int: return time.Unix(int64(v), 0), nil case int64: return time.Unix(v, 0), nil case int32: return time.Unix(int64(v), 0), nil case uint: return time.Unix(int64(v), 0), nil case uint64: return time.Unix(int64(v), 0), nil case uint32: return time.Unix(int64(v), 0), nil default: return time.Time{}, fmt.Errorf("unable to cast %#v of type %T to Time", i, i) } }
[ "func", "ToTimeE", "(", "i", "interface", "{", "}", ")", "(", "tim", "time", ".", "Time", ",", "err", "error", ")", "{", "i", "=", "indirect", "(", "i", ")", "\n\n", "switch", "v", ":=", "i", ".", "(", "type", ")", "{", "case", "time", ".", "...
// ToTimeE casts an interface to a time.Time type.
[ "ToTimeE", "casts", "an", "interface", "to", "a", "time", ".", "Time", "type", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L22-L45
18,468
spf13/cast
caste.go
ToDurationE
func ToDurationE(i interface{}) (d time.Duration, err error) { i = indirect(i) switch s := i.(type) { case time.Duration: return s, nil case int, int64, int32, int16, int8, uint, uint64, uint32, uint16, uint8: d = time.Duration(ToInt64(s)) return case float32, float64: d = time.Duration(ToFloat64(s)) return case string: if strings.ContainsAny(s, "nsuµmh") { d, err = time.ParseDuration(s) } else { d, err = time.ParseDuration(s + "ns") } return default: err = fmt.Errorf("unable to cast %#v of type %T to Duration", i, i) return } }
go
func ToDurationE(i interface{}) (d time.Duration, err error) { i = indirect(i) switch s := i.(type) { case time.Duration: return s, nil case int, int64, int32, int16, int8, uint, uint64, uint32, uint16, uint8: d = time.Duration(ToInt64(s)) return case float32, float64: d = time.Duration(ToFloat64(s)) return case string: if strings.ContainsAny(s, "nsuµmh") { d, err = time.ParseDuration(s) } else { d, err = time.ParseDuration(s + "ns") } return default: err = fmt.Errorf("unable to cast %#v of type %T to Duration", i, i) return } }
[ "func", "ToDurationE", "(", "i", "interface", "{", "}", ")", "(", "d", "time", ".", "Duration", ",", "err", "error", ")", "{", "i", "=", "indirect", "(", "i", ")", "\n\n", "switch", "s", ":=", "i", ".", "(", "type", ")", "{", "case", "time", "....
// ToDurationE casts an interface to a time.Duration type.
[ "ToDurationE", "casts", "an", "interface", "to", "a", "time", ".", "Duration", "type", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L48-L71
18,469
spf13/cast
caste.go
ToBoolE
func ToBoolE(i interface{}) (bool, error) { i = indirect(i) switch b := i.(type) { case bool: return b, nil case nil: return false, nil case int: if i.(int) != 0 { return true, nil } return false, nil case string: return strconv.ParseBool(i.(string)) default: return false, fmt.Errorf("unable to cast %#v of type %T to bool", i, i) } }
go
func ToBoolE(i interface{}) (bool, error) { i = indirect(i) switch b := i.(type) { case bool: return b, nil case nil: return false, nil case int: if i.(int) != 0 { return true, nil } return false, nil case string: return strconv.ParseBool(i.(string)) default: return false, fmt.Errorf("unable to cast %#v of type %T to bool", i, i) } }
[ "func", "ToBoolE", "(", "i", "interface", "{", "}", ")", "(", "bool", ",", "error", ")", "{", "i", "=", "indirect", "(", "i", ")", "\n\n", "switch", "b", ":=", "i", ".", "(", "type", ")", "{", "case", "bool", ":", "return", "b", ",", "nil", "...
// ToBoolE casts an interface to a bool type.
[ "ToBoolE", "casts", "an", "interface", "to", "a", "bool", "type", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L74-L92
18,470
spf13/cast
caste.go
ToFloat64E
func ToFloat64E(i interface{}) (float64, error) { i = indirect(i) switch s := i.(type) { case float64: return s, nil case float32: return float64(s), nil case int: return float64(s), nil case int64: return float64(s), nil case int32: return float64(s), nil case int16: return float64(s), nil case int8: return float64(s), nil case uint: return float64(s), nil case uint64: return float64(s), nil case uint32: return float64(s), nil case uint16: return float64(s), nil case uint8: return float64(s), nil case string: v, err := strconv.ParseFloat(s, 64) if err == nil { return v, nil } return 0, fmt.Errorf("unable to cast %#v of type %T to float64", i, i) case bool: if s { return 1, nil } return 0, nil default: return 0, fmt.Errorf("unable to cast %#v of type %T to float64", i, i) } }
go
func ToFloat64E(i interface{}) (float64, error) { i = indirect(i) switch s := i.(type) { case float64: return s, nil case float32: return float64(s), nil case int: return float64(s), nil case int64: return float64(s), nil case int32: return float64(s), nil case int16: return float64(s), nil case int8: return float64(s), nil case uint: return float64(s), nil case uint64: return float64(s), nil case uint32: return float64(s), nil case uint16: return float64(s), nil case uint8: return float64(s), nil case string: v, err := strconv.ParseFloat(s, 64) if err == nil { return v, nil } return 0, fmt.Errorf("unable to cast %#v of type %T to float64", i, i) case bool: if s { return 1, nil } return 0, nil default: return 0, fmt.Errorf("unable to cast %#v of type %T to float64", i, i) } }
[ "func", "ToFloat64E", "(", "i", "interface", "{", "}", ")", "(", "float64", ",", "error", ")", "{", "i", "=", "indirect", "(", "i", ")", "\n\n", "switch", "s", ":=", "i", ".", "(", "type", ")", "{", "case", "float64", ":", "return", "s", ",", "...
// ToFloat64E casts an interface to a float64 type.
[ "ToFloat64E", "casts", "an", "interface", "to", "a", "float64", "type", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L95-L137
18,471
spf13/cast
caste.go
ToInt32E
func ToInt32E(i interface{}) (int32, error) { i = indirect(i) switch s := i.(type) { case int: return int32(s), nil case int64: return int32(s), nil case int32: return s, nil case int16: return int32(s), nil case int8: return int32(s), nil case uint: return int32(s), nil case uint64: return int32(s), nil case uint32: return int32(s), nil case uint16: return int32(s), nil case uint8: return int32(s), nil case float64: return int32(s), nil case float32: return int32(s), nil case string: v, err := strconv.ParseInt(s, 0, 0) if err == nil { return int32(v), nil } return 0, fmt.Errorf("unable to cast %#v of type %T to int32", i, i) case bool: if s { return 1, nil } return 0, nil case nil: return 0, nil default: return 0, fmt.Errorf("unable to cast %#v of type %T to int32", i, i) } }
go
func ToInt32E(i interface{}) (int32, error) { i = indirect(i) switch s := i.(type) { case int: return int32(s), nil case int64: return int32(s), nil case int32: return s, nil case int16: return int32(s), nil case int8: return int32(s), nil case uint: return int32(s), nil case uint64: return int32(s), nil case uint32: return int32(s), nil case uint16: return int32(s), nil case uint8: return int32(s), nil case float64: return int32(s), nil case float32: return int32(s), nil case string: v, err := strconv.ParseInt(s, 0, 0) if err == nil { return int32(v), nil } return 0, fmt.Errorf("unable to cast %#v of type %T to int32", i, i) case bool: if s { return 1, nil } return 0, nil case nil: return 0, nil default: return 0, fmt.Errorf("unable to cast %#v of type %T to int32", i, i) } }
[ "func", "ToInt32E", "(", "i", "interface", "{", "}", ")", "(", "int32", ",", "error", ")", "{", "i", "=", "indirect", "(", "i", ")", "\n\n", "switch", "s", ":=", "i", ".", "(", "type", ")", "{", "case", "int", ":", "return", "int32", "(", "s", ...
// ToInt32E casts an interface to an int32 type.
[ "ToInt32E", "casts", "an", "interface", "to", "an", "int32", "type", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L232-L276
18,472
spf13/cast
caste.go
ToUintE
func ToUintE(i interface{}) (uint, error) { i = indirect(i) switch s := i.(type) { case string: v, err := strconv.ParseUint(s, 0, 0) if err == nil { return uint(v), nil } return 0, fmt.Errorf("unable to cast %#v to uint: %s", i, err) case int: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case int64: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case int32: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case int16: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case int8: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case uint: return s, nil case uint64: return uint(s), nil case uint32: return uint(s), nil case uint16: return uint(s), nil case uint8: return uint(s), nil case float64: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case float32: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case bool: if s { return 1, nil } return 0, nil case nil: return 0, nil default: return 0, fmt.Errorf("unable to cast %#v of type %T to uint", i, i) } }
go
func ToUintE(i interface{}) (uint, error) { i = indirect(i) switch s := i.(type) { case string: v, err := strconv.ParseUint(s, 0, 0) if err == nil { return uint(v), nil } return 0, fmt.Errorf("unable to cast %#v to uint: %s", i, err) case int: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case int64: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case int32: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case int16: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case int8: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case uint: return s, nil case uint64: return uint(s), nil case uint32: return uint(s), nil case uint16: return uint(s), nil case uint8: return uint(s), nil case float64: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case float32: if s < 0 { return 0, errNegativeNotAllowed } return uint(s), nil case bool: if s { return 1, nil } return 0, nil case nil: return 0, nil default: return 0, fmt.Errorf("unable to cast %#v of type %T to uint", i, i) } }
[ "func", "ToUintE", "(", "i", "interface", "{", "}", ")", "(", "uint", ",", "error", ")", "{", "i", "=", "indirect", "(", "i", ")", "\n\n", "switch", "s", ":=", "i", ".", "(", "type", ")", "{", "case", "string", ":", "v", ",", "err", ":=", "st...
// ToUintE casts an interface to a uint type.
[ "ToUintE", "casts", "an", "interface", "to", "a", "uint", "type", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L420-L485
18,473
spf13/cast
caste.go
ToStringE
func ToStringE(i interface{}) (string, error) { i = indirectToStringerOrError(i) switch s := i.(type) { case string: return s, nil case bool: return strconv.FormatBool(s), nil case float64: return strconv.FormatFloat(s, 'f', -1, 64), nil case float32: return strconv.FormatFloat(float64(s), 'f', -1, 32), nil case int: return strconv.Itoa(s), nil case int64: return strconv.FormatInt(s, 10), nil case int32: return strconv.Itoa(int(s)), nil case int16: return strconv.FormatInt(int64(s), 10), nil case int8: return strconv.FormatInt(int64(s), 10), nil case uint: return strconv.FormatInt(int64(s), 10), nil case uint64: return strconv.FormatInt(int64(s), 10), nil case uint32: return strconv.FormatInt(int64(s), 10), nil case uint16: return strconv.FormatInt(int64(s), 10), nil case uint8: return strconv.FormatInt(int64(s), 10), nil case []byte: return string(s), nil case template.HTML: return string(s), nil case template.URL: return string(s), nil case template.JS: return string(s), nil case template.CSS: return string(s), nil case template.HTMLAttr: return string(s), nil case nil: return "", nil case fmt.Stringer: return s.String(), nil case error: return s.Error(), nil default: return "", fmt.Errorf("unable to cast %#v of type %T to string", i, i) } }
go
func ToStringE(i interface{}) (string, error) { i = indirectToStringerOrError(i) switch s := i.(type) { case string: return s, nil case bool: return strconv.FormatBool(s), nil case float64: return strconv.FormatFloat(s, 'f', -1, 64), nil case float32: return strconv.FormatFloat(float64(s), 'f', -1, 32), nil case int: return strconv.Itoa(s), nil case int64: return strconv.FormatInt(s, 10), nil case int32: return strconv.Itoa(int(s)), nil case int16: return strconv.FormatInt(int64(s), 10), nil case int8: return strconv.FormatInt(int64(s), 10), nil case uint: return strconv.FormatInt(int64(s), 10), nil case uint64: return strconv.FormatInt(int64(s), 10), nil case uint32: return strconv.FormatInt(int64(s), 10), nil case uint16: return strconv.FormatInt(int64(s), 10), nil case uint8: return strconv.FormatInt(int64(s), 10), nil case []byte: return string(s), nil case template.HTML: return string(s), nil case template.URL: return string(s), nil case template.JS: return string(s), nil case template.CSS: return string(s), nil case template.HTMLAttr: return string(s), nil case nil: return "", nil case fmt.Stringer: return s.String(), nil case error: return s.Error(), nil default: return "", fmt.Errorf("unable to cast %#v of type %T to string", i, i) } }
[ "func", "ToStringE", "(", "i", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "i", "=", "indirectToStringerOrError", "(", "i", ")", "\n\n", "switch", "s", ":=", "i", ".", "(", "type", ")", "{", "case", "string", ":", "return", "...
// ToStringE casts an interface to a string type.
[ "ToStringE", "casts", "an", "interface", "to", "a", "string", "type", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L799-L852
18,474
spf13/cast
caste.go
StringToDate
func StringToDate(s string) (time.Time, error) { return parseDateWith(s, []string{ time.RFC3339, "2006-01-02T15:04:05", // iso8601 without timezone time.RFC1123Z, time.RFC1123, time.RFC822Z, time.RFC822, time.RFC850, time.ANSIC, time.UnixDate, time.RubyDate, "2006-01-02 15:04:05.999999999 -0700 MST", // Time.String() "2006-01-02", "02 Jan 2006", "2006-01-02T15:04:05-0700", // RFC3339 without timezone hh:mm colon "2006-01-02 15:04:05 -07:00", "2006-01-02 15:04:05 -0700", "2006-01-02 15:04:05Z07:00", // RFC3339 without T "2006-01-02 15:04:05Z0700", // RFC3339 without T or timezone hh:mm colon "2006-01-02 15:04:05", time.Kitchen, time.Stamp, time.StampMilli, time.StampMicro, time.StampNano, }) }
go
func StringToDate(s string) (time.Time, error) { return parseDateWith(s, []string{ time.RFC3339, "2006-01-02T15:04:05", // iso8601 without timezone time.RFC1123Z, time.RFC1123, time.RFC822Z, time.RFC822, time.RFC850, time.ANSIC, time.UnixDate, time.RubyDate, "2006-01-02 15:04:05.999999999 -0700 MST", // Time.String() "2006-01-02", "02 Jan 2006", "2006-01-02T15:04:05-0700", // RFC3339 without timezone hh:mm colon "2006-01-02 15:04:05 -07:00", "2006-01-02 15:04:05 -0700", "2006-01-02 15:04:05Z07:00", // RFC3339 without T "2006-01-02 15:04:05Z0700", // RFC3339 without T or timezone hh:mm colon "2006-01-02 15:04:05", time.Kitchen, time.Stamp, time.StampMilli, time.StampMicro, time.StampNano, }) }
[ "func", "StringToDate", "(", "s", "string", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "parseDateWith", "(", "s", ",", "[", "]", "string", "{", "time", ".", "RFC3339", ",", "\"", "\"", ",", "// iso8601 without timezone", "time", "...
// StringToDate attempts to parse a string into a time.Time type using a // predefined list of formats. If no suitable format is found, an error is // returned.
[ "StringToDate", "attempts", "to", "parse", "a", "string", "into", "a", "time", ".", "Time", "type", "using", "a", "predefined", "list", "of", "formats", ".", "If", "no", "suitable", "format", "is", "found", "an", "error", "is", "returned", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L1206-L1233
18,475
spf13/cast
caste.go
jsonStringToObject
func jsonStringToObject(s string, v interface{}) error { data := []byte(s) return json.Unmarshal(data, v) }
go
func jsonStringToObject(s string, v interface{}) error { data := []byte(s) return json.Unmarshal(data, v) }
[ "func", "jsonStringToObject", "(", "s", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "data", ":=", "[", "]", "byte", "(", "s", ")", "\n", "return", "json", ".", "Unmarshal", "(", "data", ",", "v", ")", "\n", "}" ]
// jsonStringToObject attempts to unmarshall a string as JSON into // the object passed as pointer.
[ "jsonStringToObject", "attempts", "to", "unmarshall", "a", "string", "as", "JSON", "into", "the", "object", "passed", "as", "pointer", "." ]
8c9545af88b134710ab1cd196795e7f2388358d7
https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L1246-L1249
18,476
hashicorp/go-sockaddr
route_info_linux.go
NewRouteInfo
func NewRouteInfo() (routeInfo, error) { // CoreOS Container Linux moved ip to /usr/bin/ip, so look it up on // $PATH and fallback to /sbin/ip on error. path, _ := exec.LookPath("ip") if path == "" { path = "/sbin/ip" } return routeInfo{ cmds: map[string][]string{"ip": {path, "route"}}, }, nil }
go
func NewRouteInfo() (routeInfo, error) { // CoreOS Container Linux moved ip to /usr/bin/ip, so look it up on // $PATH and fallback to /sbin/ip on error. path, _ := exec.LookPath("ip") if path == "" { path = "/sbin/ip" } return routeInfo{ cmds: map[string][]string{"ip": {path, "route"}}, }, nil }
[ "func", "NewRouteInfo", "(", ")", "(", "routeInfo", ",", "error", ")", "{", "// CoreOS Container Linux moved ip to /usr/bin/ip, so look it up on", "// $PATH and fallback to /sbin/ip on error.", "path", ",", "_", ":=", "exec", ".", "LookPath", "(", "\"", "\"", ")", "\n",...
// NewRouteInfo returns a Linux-specific implementation of the RouteInfo // interface.
[ "NewRouteInfo", "returns", "a", "Linux", "-", "specific", "implementation", "of", "the", "RouteInfo", "interface", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/route_info_linux.go#L16-L27
18,477
hashicorp/go-sockaddr
template/template.go
Attr
func Attr(selectorName string, ifAddrsRaw interface{}) (string, error) { switch v := ifAddrsRaw.(type) { case sockaddr.IfAddr: return sockaddr.IfAttr(selectorName, v) case sockaddr.IfAddrs: return sockaddr.IfAttrs(selectorName, v) default: return "", fmt.Errorf("unable to obtain attribute %s from type %T (%v)", selectorName, ifAddrsRaw, ifAddrsRaw) } }
go
func Attr(selectorName string, ifAddrsRaw interface{}) (string, error) { switch v := ifAddrsRaw.(type) { case sockaddr.IfAddr: return sockaddr.IfAttr(selectorName, v) case sockaddr.IfAddrs: return sockaddr.IfAttrs(selectorName, v) default: return "", fmt.Errorf("unable to obtain attribute %s from type %T (%v)", selectorName, ifAddrsRaw, ifAddrsRaw) } }
[ "func", "Attr", "(", "selectorName", "string", ",", "ifAddrsRaw", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "switch", "v", ":=", "ifAddrsRaw", ".", "(", "type", ")", "{", "case", "sockaddr", ".", "IfAddr", ":", "return", "socka...
// Attr returns the attribute from the ifAddrRaw argument. If the argument is // an IfAddrs, only the first element will be evaluated for resolution.
[ "Attr", "returns", "the", "attribute", "from", "the", "ifAddrRaw", "argument", ".", "If", "the", "argument", "is", "an", "IfAddrs", "only", "the", "first", "element", "will", "be", "evaluated", "for", "resolution", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/template/template.go#L106-L115
18,478
hashicorp/go-sockaddr
template/template.go
Parse
func Parse(input string) (string, error) { addrs, err := sockaddr.GetAllInterfaces() if err != nil { return "", errwrap.Wrapf("unable to query interface addresses: {{err}}", err) } return ParseIfAddrs(input, addrs) }
go
func Parse(input string) (string, error) { addrs, err := sockaddr.GetAllInterfaces() if err != nil { return "", errwrap.Wrapf("unable to query interface addresses: {{err}}", err) } return ParseIfAddrs(input, addrs) }
[ "func", "Parse", "(", "input", "string", ")", "(", "string", ",", "error", ")", "{", "addrs", ",", "err", ":=", "sockaddr", ".", "GetAllInterfaces", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errwrap", ".", "Wrapf", ...
// Parse parses input as template input using the addresses available on the // host, then returns the string output if there are no errors.
[ "Parse", "parses", "input", "as", "template", "input", "using", "the", "addresses", "available", "on", "the", "host", "then", "returns", "the", "string", "output", "if", "there", "are", "no", "errors", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/template/template.go#L119-L126
18,479
hashicorp/go-sockaddr
template/template.go
ParseIfAddrs
func ParseIfAddrs(input string, ifAddrs sockaddr.IfAddrs) (string, error) { return ParseIfAddrsTemplate(input, ifAddrs, template.New("sockaddr.Parse")) }
go
func ParseIfAddrs(input string, ifAddrs sockaddr.IfAddrs) (string, error) { return ParseIfAddrsTemplate(input, ifAddrs, template.New("sockaddr.Parse")) }
[ "func", "ParseIfAddrs", "(", "input", "string", ",", "ifAddrs", "sockaddr", ".", "IfAddrs", ")", "(", "string", ",", "error", ")", "{", "return", "ParseIfAddrsTemplate", "(", "input", ",", "ifAddrs", ",", "template", ".", "New", "(", "\"", "\"", ")", ")"...
// ParseIfAddrs parses input as template input using the IfAddrs inputs, then // returns the string output if there are no errors.
[ "ParseIfAddrs", "parses", "input", "as", "template", "input", "using", "the", "IfAddrs", "inputs", "then", "returns", "the", "string", "output", "if", "there", "are", "no", "errors", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/template/template.go#L130-L132
18,480
hashicorp/go-sockaddr
template/template.go
ParseIfAddrsTemplate
func ParseIfAddrsTemplate(input string, ifAddrs sockaddr.IfAddrs, tmplIn *template.Template) (string, error) { // Create a template, add the function map, and parse the text. tmpl, err := tmplIn.Option("missingkey=error"). Funcs(SourceFuncs). Funcs(SortFuncs). Funcs(FilterFuncs). Funcs(HelperFuncs). Parse(input) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("unable to parse template %+q: {{err}}", input), err) } var outWriter bytes.Buffer err = tmpl.Execute(&outWriter, ifAddrs) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("unable to execute sockaddr input %+q: {{err}}", input), err) } return outWriter.String(), nil }
go
func ParseIfAddrsTemplate(input string, ifAddrs sockaddr.IfAddrs, tmplIn *template.Template) (string, error) { // Create a template, add the function map, and parse the text. tmpl, err := tmplIn.Option("missingkey=error"). Funcs(SourceFuncs). Funcs(SortFuncs). Funcs(FilterFuncs). Funcs(HelperFuncs). Parse(input) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("unable to parse template %+q: {{err}}", input), err) } var outWriter bytes.Buffer err = tmpl.Execute(&outWriter, ifAddrs) if err != nil { return "", errwrap.Wrapf(fmt.Sprintf("unable to execute sockaddr input %+q: {{err}}", input), err) } return outWriter.String(), nil }
[ "func", "ParseIfAddrsTemplate", "(", "input", "string", ",", "ifAddrs", "sockaddr", ".", "IfAddrs", ",", "tmplIn", "*", "template", ".", "Template", ")", "(", "string", ",", "error", ")", "{", "// Create a template, add the function map, and parse the text.", "tmpl", ...
// ParseIfAddrsTemplate parses input as template input using the IfAddrs inputs, // then returns the string output if there are no errors.
[ "ParseIfAddrsTemplate", "parses", "input", "as", "template", "input", "using", "the", "IfAddrs", "inputs", "then", "returns", "the", "string", "output", "if", "there", "are", "no", "errors", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/template/template.go#L136-L155
18,481
hashicorp/go-sockaddr
ipv6addr.go
AddressBinString
func (ipv6 IPv6Addr) AddressBinString() string { bi := big.Int(*ipv6.Address) return fmt.Sprintf("%0128s", bi.Text(2)) }
go
func (ipv6 IPv6Addr) AddressBinString() string { bi := big.Int(*ipv6.Address) return fmt.Sprintf("%0128s", bi.Text(2)) }
[ "func", "(", "ipv6", "IPv6Addr", ")", "AddressBinString", "(", ")", "string", "{", "bi", ":=", "big", ".", "Int", "(", "*", "ipv6", ".", "Address", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "bi", ".", "Text", "(", "2", ")"...
// AddressBinString returns a string with the IPv6Addr's Address represented // as a sequence of '0' and '1' characters. This method is useful for // debugging or by operators who want to inspect an address.
[ "AddressBinString", "returns", "a", "string", "with", "the", "IPv6Addr", "s", "Address", "represented", "as", "a", "sequence", "of", "0", "and", "1", "characters", ".", "This", "method", "is", "useful", "for", "debugging", "or", "by", "operators", "who", "wa...
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L161-L164
18,482
hashicorp/go-sockaddr
ipv6addr.go
ContainsAddress
func (ipv6 IPv6Addr) ContainsAddress(x IPv6Address) bool { xAddr := IPv6Addr{ Address: x, Mask: ipv6HostMask, } { xIPv6 := xAddr.FirstUsable().(IPv6Addr) yIPv6 := ipv6.FirstUsable().(IPv6Addr) if xIPv6.CmpAddress(yIPv6) >= 1 { return false } } { xIPv6 := xAddr.LastUsable().(IPv6Addr) yIPv6 := ipv6.LastUsable().(IPv6Addr) if xIPv6.CmpAddress(yIPv6) <= -1 { return false } } return true }
go
func (ipv6 IPv6Addr) ContainsAddress(x IPv6Address) bool { xAddr := IPv6Addr{ Address: x, Mask: ipv6HostMask, } { xIPv6 := xAddr.FirstUsable().(IPv6Addr) yIPv6 := ipv6.FirstUsable().(IPv6Addr) if xIPv6.CmpAddress(yIPv6) >= 1 { return false } } { xIPv6 := xAddr.LastUsable().(IPv6Addr) yIPv6 := ipv6.LastUsable().(IPv6Addr) if xIPv6.CmpAddress(yIPv6) <= -1 { return false } } return true }
[ "func", "(", "ipv6", "IPv6Addr", ")", "ContainsAddress", "(", "x", "IPv6Address", ")", "bool", "{", "xAddr", ":=", "IPv6Addr", "{", "Address", ":", "x", ",", "Mask", ":", "ipv6HostMask", ",", "}", "\n\n", "{", "xIPv6", ":=", "xAddr", ".", "FirstUsable", ...
// ContainsAddress returns true if the IPv6Address is contained within the // receiver.
[ "ContainsAddress", "returns", "true", "if", "the", "IPv6Address", "is", "contained", "within", "the", "receiver", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L267-L289
18,483
hashicorp/go-sockaddr
ipv6addr.go
ContainsNetwork
func (x IPv6Addr) ContainsNetwork(y IPv6Addr) bool { { xIPv6 := x.FirstUsable().(IPv6Addr) yIPv6 := y.FirstUsable().(IPv6Addr) if ret := xIPv6.CmpAddress(yIPv6); ret >= 1 { return false } } { xIPv6 := x.LastUsable().(IPv6Addr) yIPv6 := y.LastUsable().(IPv6Addr) if ret := xIPv6.CmpAddress(yIPv6); ret <= -1 { return false } } return true }
go
func (x IPv6Addr) ContainsNetwork(y IPv6Addr) bool { { xIPv6 := x.FirstUsable().(IPv6Addr) yIPv6 := y.FirstUsable().(IPv6Addr) if ret := xIPv6.CmpAddress(yIPv6); ret >= 1 { return false } } { xIPv6 := x.LastUsable().(IPv6Addr) yIPv6 := y.LastUsable().(IPv6Addr) if ret := xIPv6.CmpAddress(yIPv6); ret <= -1 { return false } } return true }
[ "func", "(", "x", "IPv6Addr", ")", "ContainsNetwork", "(", "y", "IPv6Addr", ")", "bool", "{", "{", "xIPv6", ":=", "x", ".", "FirstUsable", "(", ")", ".", "(", "IPv6Addr", ")", "\n", "yIPv6", ":=", "y", ".", "FirstUsable", "(", ")", ".", "(", "IPv6A...
// ContainsNetwork returns true if the network from IPv6Addr is contained within // the receiver.
[ "ContainsNetwork", "returns", "true", "if", "the", "network", "from", "IPv6Addr", "is", "contained", "within", "the", "receiver", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L293-L310
18,484
hashicorp/go-sockaddr
ipv6addr.go
LastUsable
func (ipv6 IPv6Addr) LastUsable() IPAddr { addr := new(big.Int) addr.Set(ipv6.Address) mask := new(big.Int) mask.Set(ipv6.Mask) negMask := new(big.Int) negMask.Xor(ipv6HostMask, mask) lastAddr := new(big.Int) lastAddr.And(addr, mask) lastAddr.Or(lastAddr, negMask) return IPv6Addr{ Address: IPv6Address(lastAddr), Mask: ipv6HostMask, } }
go
func (ipv6 IPv6Addr) LastUsable() IPAddr { addr := new(big.Int) addr.Set(ipv6.Address) mask := new(big.Int) mask.Set(ipv6.Mask) negMask := new(big.Int) negMask.Xor(ipv6HostMask, mask) lastAddr := new(big.Int) lastAddr.And(addr, mask) lastAddr.Or(lastAddr, negMask) return IPv6Addr{ Address: IPv6Address(lastAddr), Mask: ipv6HostMask, } }
[ "func", "(", "ipv6", "IPv6Addr", ")", "LastUsable", "(", ")", "IPAddr", "{", "addr", ":=", "new", "(", "big", ".", "Int", ")", "\n", "addr", ".", "Set", "(", "ipv6", ".", "Address", ")", "\n\n", "mask", ":=", "new", "(", "big", ".", "Int", ")", ...
// LastUsable returns the last address in a given network.
[ "LastUsable", "returns", "the", "last", "address", "in", "a", "given", "network", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L390-L408
18,485
hashicorp/go-sockaddr
ipv6addr.go
MustIPv6Addr
func MustIPv6Addr(addr string) IPv6Addr { ipv6, err := NewIPv6Addr(addr) if err != nil { panic(fmt.Sprintf("Unable to create an IPv6Addr from %+q: %v", addr, err)) } return ipv6 }
go
func MustIPv6Addr(addr string) IPv6Addr { ipv6, err := NewIPv6Addr(addr) if err != nil { panic(fmt.Sprintf("Unable to create an IPv6Addr from %+q: %v", addr, err)) } return ipv6 }
[ "func", "MustIPv6Addr", "(", "addr", "string", ")", "IPv6Addr", "{", "ipv6", ",", "err", ":=", "NewIPv6Addr", "(", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "addr", ",", "err", ")",...
// MustIPv6Addr is a helper method that must return an IPv6Addr or panic on // invalid input.
[ "MustIPv6Addr", "is", "a", "helper", "method", "that", "must", "return", "an", "IPv6Addr", "or", "panic", "on", "invalid", "input", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L442-L448
18,486
hashicorp/go-sockaddr
ipv6addr.go
NetIPMask
func (ipv6 IPv6Addr) NetIPMask() *net.IPMask { ipv6Mask := make(net.IPMask, IPv6len) m := big.Int(*ipv6.Mask) copy(ipv6Mask, m.Bytes()) return &ipv6Mask }
go
func (ipv6 IPv6Addr) NetIPMask() *net.IPMask { ipv6Mask := make(net.IPMask, IPv6len) m := big.Int(*ipv6.Mask) copy(ipv6Mask, m.Bytes()) return &ipv6Mask }
[ "func", "(", "ipv6", "IPv6Addr", ")", "NetIPMask", "(", ")", "*", "net", ".", "IPMask", "{", "ipv6Mask", ":=", "make", "(", "net", ".", "IPMask", ",", "IPv6len", ")", "\n", "m", ":=", "big", ".", "Int", "(", "*", "ipv6", ".", "Mask", ")", "\n", ...
// NetIPMask create a new net.IPMask from the IPv6Addr.
[ "NetIPMask", "create", "a", "new", "net", ".", "IPMask", "from", "the", "IPv6Addr", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L456-L461
18,487
hashicorp/go-sockaddr
ipv6addr.go
NetIPNet
func (ipv6 IPv6Addr) NetIPNet() *net.IPNet { ipv6net := &net.IPNet{} ipv6net.IP = make(net.IP, IPv6len) copy(ipv6net.IP, *ipv6.NetIP()) ipv6net.Mask = *ipv6.NetIPMask() return ipv6net }
go
func (ipv6 IPv6Addr) NetIPNet() *net.IPNet { ipv6net := &net.IPNet{} ipv6net.IP = make(net.IP, IPv6len) copy(ipv6net.IP, *ipv6.NetIP()) ipv6net.Mask = *ipv6.NetIPMask() return ipv6net }
[ "func", "(", "ipv6", "IPv6Addr", ")", "NetIPNet", "(", ")", "*", "net", ".", "IPNet", "{", "ipv6net", ":=", "&", "net", ".", "IPNet", "{", "}", "\n", "ipv6net", ".", "IP", "=", "make", "(", "net", ".", "IP", ",", "IPv6len", ")", "\n", "copy", "...
// Network returns a pointer to the net.IPNet within IPv4Addr receiver.
[ "Network", "returns", "a", "pointer", "to", "the", "net", ".", "IPNet", "within", "IPv4Addr", "receiver", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L464-L470
18,488
hashicorp/go-sockaddr
ipv6addr.go
NetworkAddress
func (ipv6 IPv6Addr) NetworkAddress() IPv6Network { addr := new(big.Int) addr.SetBytes((*ipv6.Address).Bytes()) mask := new(big.Int) mask.SetBytes(*ipv6.NetIPMask()) netAddr := new(big.Int) netAddr.And(addr, mask) return IPv6Network(netAddr) }
go
func (ipv6 IPv6Addr) NetworkAddress() IPv6Network { addr := new(big.Int) addr.SetBytes((*ipv6.Address).Bytes()) mask := new(big.Int) mask.SetBytes(*ipv6.NetIPMask()) netAddr := new(big.Int) netAddr.And(addr, mask) return IPv6Network(netAddr) }
[ "func", "(", "ipv6", "IPv6Addr", ")", "NetworkAddress", "(", ")", "IPv6Network", "{", "addr", ":=", "new", "(", "big", ".", "Int", ")", "\n", "addr", ".", "SetBytes", "(", "(", "*", "ipv6", ".", "Address", ")", ".", "Bytes", "(", ")", ")", "\n\n", ...
// NetworkAddress returns an IPv6Network of the IPv6Addr's network address.
[ "NetworkAddress", "returns", "an", "IPv6Network", "of", "the", "IPv6Addr", "s", "network", "address", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L481-L492
18,489
hashicorp/go-sockaddr
ipv6addr.go
Octets
func (ipv6 IPv6Addr) Octets() []int { x := make([]int, IPv6len) for i, b := range *bigIntToNetIPv6(ipv6.Address) { x[i] = int(b) } return x }
go
func (ipv6 IPv6Addr) Octets() []int { x := make([]int, IPv6len) for i, b := range *bigIntToNetIPv6(ipv6.Address) { x[i] = int(b) } return x }
[ "func", "(", "ipv6", "IPv6Addr", ")", "Octets", "(", ")", "[", "]", "int", "{", "x", ":=", "make", "(", "[", "]", "int", ",", "IPv6len", ")", "\n", "for", "i", ",", "b", ":=", "range", "*", "bigIntToNetIPv6", "(", "ipv6", ".", "Address", ")", "...
// Octets returns a slice of the 16 octets in an IPv6Addr's Address. The // order of the bytes is big endian.
[ "Octets", "returns", "a", "slice", "of", "the", "16", "octets", "in", "an", "IPv6Addr", "s", "Address", ".", "The", "order", "of", "the", "bytes", "is", "big", "endian", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L496-L503
18,490
hashicorp/go-sockaddr
ipv6addr.go
String
func (ipv6 IPv6Addr) String() string { if ipv6.Port != 0 { return fmt.Sprintf("[%s]:%d", ipv6.NetIP().String(), ipv6.Port) } if ipv6.Maskbits() == 128 { return ipv6.NetIP().String() } return fmt.Sprintf("%s/%d", ipv6.NetIP().String(), ipv6.Maskbits()) }
go
func (ipv6 IPv6Addr) String() string { if ipv6.Port != 0 { return fmt.Sprintf("[%s]:%d", ipv6.NetIP().String(), ipv6.Port) } if ipv6.Maskbits() == 128 { return ipv6.NetIP().String() } return fmt.Sprintf("%s/%d", ipv6.NetIP().String(), ipv6.Maskbits()) }
[ "func", "(", "ipv6", "IPv6Addr", ")", "String", "(", ")", "string", "{", "if", "ipv6", ".", "Port", "!=", "0", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ipv6", ".", "NetIP", "(", ")", ".", "String", "(", ")", ",", "ipv6", "."...
// String returns a string representation of the IPv6Addr
[ "String", "returns", "a", "string", "representation", "of", "the", "IPv6Addr" ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L506-L516
18,491
hashicorp/go-sockaddr
ipv6addr.go
IPv6AddrAttr
func IPv6AddrAttr(ipv6 IPv6Addr, selector AttrName) string { fn, found := ipv6AddrAttrMap[selector] if !found { return "" } return fn(ipv6) }
go
func IPv6AddrAttr(ipv6 IPv6Addr, selector AttrName) string { fn, found := ipv6AddrAttrMap[selector] if !found { return "" } return fn(ipv6) }
[ "func", "IPv6AddrAttr", "(", "ipv6", "IPv6Addr", ",", "selector", "AttrName", ")", "string", "{", "fn", ",", "found", ":=", "ipv6AddrAttrMap", "[", "selector", "]", "\n", "if", "!", "found", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "fn", ...
// IPv6AddrAttr returns a string representation of an attribute for the given // IPv6Addr.
[ "IPv6AddrAttr", "returns", "a", "string", "representation", "of", "an", "attribute", "for", "the", "given", "IPv6Addr", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L530-L537
18,492
hashicorp/go-sockaddr
ipv6addr.go
bigIntToNetIPv6
func bigIntToNetIPv6(bi *big.Int) *net.IP { x := make(net.IP, IPv6len) ipv6Bytes := bi.Bytes() // It's possibe for ipv6Bytes to be less than IPv6len bytes in size. If // they are different sizes we to pad the size of response. if len(ipv6Bytes) < IPv6len { buf := new(bytes.Buffer) buf.Grow(IPv6len) for i := len(ipv6Bytes); i < IPv6len; i++ { if err := binary.Write(buf, binary.BigEndian, byte(0)); err != nil { panic(fmt.Sprintf("Unable to pad byte %d of input %v: %v", i, bi, err)) } } for _, b := range ipv6Bytes { if err := binary.Write(buf, binary.BigEndian, b); err != nil { panic(fmt.Sprintf("Unable to preserve endianness of input %v: %v", bi, err)) } } ipv6Bytes = buf.Bytes() } i := copy(x, ipv6Bytes) if i != IPv6len { panic("IPv6 wrong size") } return &x }
go
func bigIntToNetIPv6(bi *big.Int) *net.IP { x := make(net.IP, IPv6len) ipv6Bytes := bi.Bytes() // It's possibe for ipv6Bytes to be less than IPv6len bytes in size. If // they are different sizes we to pad the size of response. if len(ipv6Bytes) < IPv6len { buf := new(bytes.Buffer) buf.Grow(IPv6len) for i := len(ipv6Bytes); i < IPv6len; i++ { if err := binary.Write(buf, binary.BigEndian, byte(0)); err != nil { panic(fmt.Sprintf("Unable to pad byte %d of input %v: %v", i, bi, err)) } } for _, b := range ipv6Bytes { if err := binary.Write(buf, binary.BigEndian, b); err != nil { panic(fmt.Sprintf("Unable to preserve endianness of input %v: %v", bi, err)) } } ipv6Bytes = buf.Bytes() } i := copy(x, ipv6Bytes) if i != IPv6len { panic("IPv6 wrong size") } return &x }
[ "func", "bigIntToNetIPv6", "(", "bi", "*", "big", ".", "Int", ")", "*", "net", ".", "IP", "{", "x", ":=", "make", "(", "net", ".", "IP", ",", "IPv6len", ")", "\n", "ipv6Bytes", ":=", "bi", ".", "Bytes", "(", ")", "\n\n", "// It's possibe for ipv6Byte...
// bigIntToNetIPv6 is a helper function that correctly returns a net.IP with the // correctly padded values.
[ "bigIntToNetIPv6", "is", "a", "helper", "function", "that", "correctly", "returns", "a", "net", ".", "IP", "with", "the", "correctly", "padded", "values", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L562-L591
18,493
hashicorp/go-sockaddr
cmd/sockaddr/command/autohelp.go
MakeHelp
func MakeHelp(c AutoHelp) string { usageText := c.Usage() // If the length of Usage() is zero, then assume this is a hidden // command. if len(usageText) == 0 { return "" } descriptionText := wordwrap.WrapString(c.Description(), 60) descrLines := strings.Split(descriptionText, "\n") prefixedLines := make([]string, len(descrLines)) for i := range descrLines { prefixedLines[i] = " " + descrLines[i] } descriptionText = strings.Join(prefixedLines, "\n") c.InitOpts() flags := []*flag.Flag{} c.VisitAllFlags(func(f *flag.Flag) { flags = append(flags, f) }) optionsText := OptionsHelpOutput(flags) var helpOutput string switch { case len(optionsText) == 0 && len(descriptionText) == 0: helpOutput = usageText case len(optionsText) == 0: helpOutput = fmt.Sprintf(`Usage: %s %s`, usageText, descriptionText) case len(descriptionText) == 0 && len(optionsText) > 0: helpOutput = fmt.Sprintf(`Usage: %s Options: %s`, usageText, optionsText) default: helpOutput = fmt.Sprintf(`Usage: %s %s Options: %s`, usageText, descriptionText, optionsText) } return strings.TrimSpace(helpOutput) }
go
func MakeHelp(c AutoHelp) string { usageText := c.Usage() // If the length of Usage() is zero, then assume this is a hidden // command. if len(usageText) == 0 { return "" } descriptionText := wordwrap.WrapString(c.Description(), 60) descrLines := strings.Split(descriptionText, "\n") prefixedLines := make([]string, len(descrLines)) for i := range descrLines { prefixedLines[i] = " " + descrLines[i] } descriptionText = strings.Join(prefixedLines, "\n") c.InitOpts() flags := []*flag.Flag{} c.VisitAllFlags(func(f *flag.Flag) { flags = append(flags, f) }) optionsText := OptionsHelpOutput(flags) var helpOutput string switch { case len(optionsText) == 0 && len(descriptionText) == 0: helpOutput = usageText case len(optionsText) == 0: helpOutput = fmt.Sprintf(`Usage: %s %s`, usageText, descriptionText) case len(descriptionText) == 0 && len(optionsText) > 0: helpOutput = fmt.Sprintf(`Usage: %s Options: %s`, usageText, optionsText) default: helpOutput = fmt.Sprintf(`Usage: %s %s Options: %s`, usageText, descriptionText, optionsText) } return strings.TrimSpace(helpOutput) }
[ "func", "MakeHelp", "(", "c", "AutoHelp", ")", "string", "{", "usageText", ":=", "c", ".", "Usage", "(", ")", "\n\n", "// If the length of Usage() is zero, then assume this is a hidden", "// command.", "if", "len", "(", "usageText", ")", "==", "0", "{", "return", ...
// MakeHelp generates a help string based on the capabilities of the Command
[ "MakeHelp", "generates", "a", "help", "string", "based", "on", "the", "capabilities", "of", "the", "Command" ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/cmd/sockaddr/command/autohelp.go#L23-L75
18,494
hashicorp/go-sockaddr
cmd/sockaddr/command/autohelp.go
OptionsHelpOutput
func OptionsHelpOutput(flags []*flag.Flag) string { sort.Sort(ByName(flags)) var output []string for _, f := range flags { if len(f.Usage) == 0 { continue } output = append(output, fmt.Sprintf("-%s | %s", f.Name, f.Usage)) } optionsOutput := columnize.Format(output, &columnize.Config{ Delim: "|", Glue: " ", Prefix: " ", Empty: "", }) return optionsOutput }
go
func OptionsHelpOutput(flags []*flag.Flag) string { sort.Sort(ByName(flags)) var output []string for _, f := range flags { if len(f.Usage) == 0 { continue } output = append(output, fmt.Sprintf("-%s | %s", f.Name, f.Usage)) } optionsOutput := columnize.Format(output, &columnize.Config{ Delim: "|", Glue: " ", Prefix: " ", Empty: "", }) return optionsOutput }
[ "func", "OptionsHelpOutput", "(", "flags", "[", "]", "*", "flag", ".", "Flag", ")", "string", "{", "sort", ".", "Sort", "(", "ByName", "(", "flags", ")", ")", "\n\n", "var", "output", "[", "]", "string", "\n", "for", "_", ",", "f", ":=", "range", ...
// OptionsHelpOutput returns a string of formatted options
[ "OptionsHelpOutput", "returns", "a", "string", "of", "formatted", "options" ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/cmd/sockaddr/command/autohelp.go#L102-L121
18,495
hashicorp/go-sockaddr
unixsock.go
Equal
func (us UnixSock) Equal(sa SockAddr) bool { usb, ok := sa.(UnixSock) if !ok { return false } if us.Path() != usb.Path() { return false } return true }
go
func (us UnixSock) Equal(sa SockAddr) bool { usb, ok := sa.(UnixSock) if !ok { return false } if us.Path() != usb.Path() { return false } return true }
[ "func", "(", "us", "UnixSock", ")", "Equal", "(", "sa", "SockAddr", ")", "bool", "{", "usb", ",", "ok", ":=", "sa", ".", "(", "UnixSock", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n\n", "if", "us", ".", "Path", "(", ")", ...
// Equal returns true if a SockAddr is equal to the receiving UnixSock.
[ "Equal", "returns", "true", "if", "a", "SockAddr", "is", "equal", "to", "the", "receiving", "UnixSock", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/unixsock.go#L57-L68
18,496
hashicorp/go-sockaddr
unixsock.go
MustUnixSock
func MustUnixSock(addr string) UnixSock { us, err := NewUnixSock(addr) if err != nil { panic(fmt.Sprintf("Unable to create a UnixSock from %+q: %v", addr, err)) } return us }
go
func MustUnixSock(addr string) UnixSock { us, err := NewUnixSock(addr) if err != nil { panic(fmt.Sprintf("Unable to create a UnixSock from %+q: %v", addr, err)) } return us }
[ "func", "MustUnixSock", "(", "addr", "string", ")", "UnixSock", "{", "us", ",", "err", ":=", "NewUnixSock", "(", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "addr", ",", "err", ")", ...
// MustUnixSock is a helper method that must return an UnixSock or panic on // invalid input.
[ "MustUnixSock", "is", "a", "helper", "method", "that", "must", "return", "an", "UnixSock", "or", "panic", "on", "invalid", "input", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/unixsock.go#L84-L90
18,497
hashicorp/go-sockaddr
unixsock.go
UnixSockAttr
func UnixSockAttr(us UnixSock, attrName AttrName) string { fn, found := unixAttrMap[attrName] if !found { return "" } return fn(us) }
go
func UnixSockAttr(us UnixSock, attrName AttrName) string { fn, found := unixAttrMap[attrName] if !found { return "" } return fn(us) }
[ "func", "UnixSockAttr", "(", "us", "UnixSock", ",", "attrName", "AttrName", ")", "string", "{", "fn", ",", "found", ":=", "unixAttrMap", "[", "attrName", "]", "\n", "if", "!", "found", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "fn", "(", ...
// UnixSockAttr returns a string representation of an attribute for the given // UnixSock.
[ "UnixSockAttr", "returns", "a", "string", "representation", "of", "an", "attribute", "for", "the", "given", "UnixSock", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/unixsock.go#L114-L121
18,498
hashicorp/go-sockaddr
ifaddr.go
IfAddrAttr
func IfAddrAttr(ifAddr IfAddr, attrName AttrName) string { fn, found := ifAddrAttrMap[attrName] if !found { return "" } return fn(ifAddr) }
go
func IfAddrAttr(ifAddr IfAddr, attrName AttrName) string { fn, found := ifAddrAttrMap[attrName] if !found { return "" } return fn(ifAddr) }
[ "func", "IfAddrAttr", "(", "ifAddr", "IfAddr", ",", "attrName", "AttrName", ")", "string", "{", "fn", ",", "found", ":=", "ifAddrAttrMap", "[", "attrName", "]", "\n", "if", "!", "found", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "fn", "("...
// IfAddrAttr returns a string representation of an attribute for the given // IfAddr.
[ "IfAddrAttr", "returns", "a", "string", "representation", "of", "an", "attribute", "for", "the", "given", "IfAddr", "." ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddr.go#L229-L236
18,499
hashicorp/go-sockaddr
rfc.go
IsRFC
func IsRFC(rfcNum uint, sa SockAddr) bool { rfcNetMap := KnownRFCs() rfcNets, ok := rfcNetMap[rfcNum] if !ok { return false } var contained bool for _, rfcNet := range rfcNets { if rfcNet.Contains(sa) { contained = true break } } return contained }
go
func IsRFC(rfcNum uint, sa SockAddr) bool { rfcNetMap := KnownRFCs() rfcNets, ok := rfcNetMap[rfcNum] if !ok { return false } var contained bool for _, rfcNet := range rfcNets { if rfcNet.Contains(sa) { contained = true break } } return contained }
[ "func", "IsRFC", "(", "rfcNum", "uint", ",", "sa", "SockAddr", ")", "bool", "{", "rfcNetMap", ":=", "KnownRFCs", "(", ")", "\n", "rfcNets", ",", "ok", ":=", "rfcNetMap", "[", "rfcNum", "]", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", ...
// IsRFC tests to see if an SockAddr matches the specified RFC
[ "IsRFC", "tests", "to", "see", "if", "an", "SockAddr", "matches", "the", "specified", "RFC" ]
c7188e74f6acae5a989bdc959aa779f8b9f42faf
https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/rfc.go#L9-L24