code
stringlengths 12
335k
| docstring
stringlengths 20
20.8k
| func_name
stringlengths 1
105
| language
stringclasses 1
value | repo
stringclasses 498
values | path
stringlengths 5
172
| url
stringlengths 43
235
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
func (p *textParser) back() { p.backed = true } | Back off the parser by one token. Can only be done between calls to next().
It makes the next advance() a no-op. | back | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text_parser.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go | Apache-2.0 |
func (p *textParser) next() *token {
if p.backed || p.done {
p.backed = false
return &p.cur
}
p.advance()
if p.done {
p.cur.value = ""
} else if len(p.cur.value) > 0 && isQuote(p.cur.value[0]) {
// Look for multiple quoted strings separated by whitespace,
// and concatenate them.
cat := p.cur
for {
p.skipWhitespace()
if p.done || !isQuote(p.s[0]) {
break
}
p.advance()
if p.cur.err != nil {
return &p.cur
}
cat.value += " " + p.cur.value
cat.unquoted += p.cur.unquoted
}
p.done = false // parser may have seen EOF, but we want to return cat
p.cur = cat
}
return &p.cur
} | Advances the parser and returns the new current token. | next | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text_parser.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go | Apache-2.0 |
func (p *textParser) missingRequiredFieldError(sv reflect.Value) *RequiredNotSetError {
st := sv.Type()
sprops := GetProperties(st)
for i := 0; i < st.NumField(); i++ {
if !isNil(sv.Field(i)) {
continue
}
props := sprops.Prop[i]
if props.Required {
return &RequiredNotSetError{fmt.Sprintf("%v.%v", st, props.OrigName)}
}
}
return &RequiredNotSetError{fmt.Sprintf("%v.<unknown field name>", st)} // should not happen
} | Return a RequiredNotSetError indicating which required field was not set. | missingRequiredFieldError | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text_parser.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go | Apache-2.0 |
func structFieldByName(sprops *StructProperties, name string) (int, *Properties, bool) {
i, ok := sprops.decoderOrigNames[name]
if ok {
return i, sprops.Prop[i], true
}
return -1, nil, false
} | Returns the index in the struct for the named field, as well as the parsed tag properties. | structFieldByName | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text_parser.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go | Apache-2.0 |
func (p *textParser) checkForColon(props *Properties, typ reflect.Type) *ParseError {
tok := p.next()
if tok.err != nil {
return tok.err
}
if tok.value != ":" {
// Colon is optional when the field is a group or message.
needColon := true
switch props.Wire {
case "group":
needColon = false
case "bytes":
// A "bytes" field is either a message, a string, or a repeated field;
// those three become *T, *string and []T respectively, so we can check for
// this field being a pointer to a non-string.
if typ.Kind() == reflect.Ptr {
// *T or *string
if typ.Elem().Kind() == reflect.String {
break
}
} else if typ.Kind() == reflect.Slice {
// []T or []*T
if typ.Elem().Kind() != reflect.Ptr {
break
}
} else if typ.Kind() == reflect.String {
// The proto3 exception is for a string field,
// which requires a colon.
break
}
needColon = false
}
if needColon {
return p.errorf("expected ':', found %q", tok.value)
}
p.back()
}
return nil
} | Consume a ':' from the input stream (if the next token is a colon),
returning an error if a colon is needed but not present. | checkForColon | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text_parser.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go | Apache-2.0 |
func (p *textParser) consumeExtName() (string, error) {
tok := p.next()
if tok.err != nil {
return "", tok.err
}
// If extension name or type url is quoted, it's a single token.
if len(tok.value) > 2 && isQuote(tok.value[0]) && tok.value[len(tok.value)-1] == tok.value[0] {
name, err := unquoteC(tok.value[1:len(tok.value)-1], rune(tok.value[0]))
if err != nil {
return "", err
}
return name, p.consumeToken("]")
}
// Consume everything up to "]"
var parts []string
for tok.value != "]" {
parts = append(parts, tok.value)
tok = p.next()
if tok.err != nil {
return "", p.errorf("unrecognized type_url or extension name: %s", tok.err)
}
if p.done && tok.value != "]" {
return "", p.errorf("unclosed type_url or extension name")
}
}
return strings.Join(parts, ""), nil
} | consumeExtName consumes extension name or expanded Any type URL and the
following ']'. It returns the name or URL consumed. | consumeExtName | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text_parser.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go | Apache-2.0 |
func (p *textParser) consumeOptionalSeparator() error {
tok := p.next()
if tok.err != nil {
return tok.err
}
if tok.value != ";" && tok.value != "," {
p.back()
}
return nil
} | consumeOptionalSeparator consumes an optional semicolon or comma.
It is used in readStruct to provide backward compatibility. | consumeOptionalSeparator | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text_parser.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go | Apache-2.0 |
func UnmarshalText(s string, pb Message) error {
if um, ok := pb.(encoding.TextUnmarshaler); ok {
return um.UnmarshalText([]byte(s))
}
pb.Reset()
v := reflect.ValueOf(pb)
return newTextParser(s).readStruct(v.Elem(), "")
} | UnmarshalText reads a protocol buffer in Text format. UnmarshalText resets pb
before starting to unmarshal, so any existing data in pb is always removed.
If a required field is not set and no other error occurs,
UnmarshalText returns *RequiredNotSetError. | UnmarshalText | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text_parser.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text_parser.go | Apache-2.0 |
func DiscardUnknown(m Message) {
if m, ok := m.(generatedDiscarder); ok {
m.XXX_DiscardUnknown()
return
}
// TODO: Dynamically populate a InternalMessageInfo for legacy messages,
// but the master branch has no implementation for InternalMessageInfo,
// so it would be more work to replicate that approach.
discardLegacy(m)
} | DiscardUnknown recursively discards all unknown fields from this message
and all embedded messages.
When unmarshaling a message with unrecognized fields, the tags and values
of such fields are preserved in the Message. This allows a later call to
marshal to be able to produce a message that continues to have those
unrecognized fields. To avoid this, DiscardUnknown is used to
explicitly clear the unknown fields after unmarshaling.
For proto2 messages, the unknown fields of message extensions are only
discarded from messages that have been accessed via GetExtension. | DiscardUnknown | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/discard.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/discard.go | Apache-2.0 |
func (a *InternalMessageInfo) DiscardUnknown(m Message) {
di := atomicLoadDiscardInfo(&a.discard)
if di == nil {
di = getDiscardInfo(reflect.TypeOf(m).Elem())
atomicStoreDiscardInfo(&a.discard, di)
}
di.discard(toPointer(&m))
} | DiscardUnknown recursively discards all unknown fields. | DiscardUnknown | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/discard.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/discard.go | Apache-2.0 |
func isAny(sv reflect.Value) bool {
type wkt interface {
XXX_WellKnownType() string
}
t, ok := sv.Addr().Interface().(wkt)
return ok && t.XXX_WellKnownType() == "Any"
} | isAny reports whether sv is a google.protobuf.Any message | isAny | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func (tm *TextMarshaler) writeProto3Any(w *textWriter, sv reflect.Value) (bool, error) {
turl := sv.FieldByName("TypeUrl")
val := sv.FieldByName("Value")
if !turl.IsValid() || !val.IsValid() {
return true, errors.New("proto: invalid google.protobuf.Any message")
}
b, ok := val.Interface().([]byte)
if !ok {
return true, errors.New("proto: invalid google.protobuf.Any message")
}
parts := strings.Split(turl.String(), "/")
mt := MessageType(parts[len(parts)-1])
if mt == nil {
return false, nil
}
m := reflect.New(mt.Elem())
if err := Unmarshal(b, m.Interface().(Message)); err != nil {
return false, nil
}
w.Write([]byte("["))
u := turl.String()
if requiresQuotes(u) {
writeString(w, u)
} else {
w.Write([]byte(u))
}
if w.compact {
w.Write([]byte("]:<"))
} else {
w.Write([]byte("]: <\n"))
w.ind++
}
if err := tm.writeStruct(w, m.Elem()); err != nil {
return true, err
}
if w.compact {
w.Write([]byte("> "))
} else {
w.ind--
w.Write([]byte(">\n"))
}
return true, nil
} | writeProto3Any writes an expanded google.protobuf.Any message.
It returns (false, nil) if sv value can't be unmarshaled (e.g. because
required messages are not linked in).
It returns (true, error) when sv was written in expanded format or an error
was encountered. | writeProto3Any | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
v = reflect.Indirect(v)
if props != nil {
if len(props.CustomType) > 0 {
custom, ok := v.Interface().(Marshaler)
if ok {
data, err := custom.Marshal()
if err != nil {
return err
}
if err := writeString(w, string(data)); err != nil {
return err
}
return nil
}
} else if len(props.CastType) > 0 {
if _, ok := v.Interface().(interface {
String() string
}); ok {
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
_, err := fmt.Fprintf(w, "%d", v.Interface())
return err
}
}
} else if props.StdTime {
t, ok := v.Interface().(time.Time)
if !ok {
return fmt.Errorf("stdtime is not time.Time, but %T", v.Interface())
}
tproto, err := timestampProto(t)
if err != nil {
return err
}
propsCopy := *props // Make a copy so that this is goroutine-safe
propsCopy.StdTime = false
err = tm.writeAny(w, reflect.ValueOf(tproto), &propsCopy)
return err
} else if props.StdDuration {
d, ok := v.Interface().(time.Duration)
if !ok {
return fmt.Errorf("stdtime is not time.Duration, but %T", v.Interface())
}
dproto := durationProto(d)
propsCopy := *props // Make a copy so that this is goroutine-safe
propsCopy.StdDuration = false
err := tm.writeAny(w, reflect.ValueOf(dproto), &propsCopy)
return err
}
}
// Floats have special cases.
if v.Kind() == reflect.Float32 || v.Kind() == reflect.Float64 {
x := v.Float()
var b []byte
switch {
case math.IsInf(x, 1):
b = posInf
case math.IsInf(x, -1):
b = negInf
case math.IsNaN(x):
b = nan
}
if b != nil {
_, err := w.Write(b)
return err
}
// Other values are handled below.
}
// We don't attempt to serialise every possible value type; only those
// that can occur in protocol buffers.
switch v.Kind() {
case reflect.Slice:
// Should only be a []byte; repeated fields are handled in writeStruct.
if err := writeString(w, string(v.Bytes())); err != nil {
return err
}
case reflect.String:
if err := writeString(w, v.String()); err != nil {
return err
}
case reflect.Struct:
// Required/optional group/message.
var bra, ket byte = '<', '>'
if props != nil && props.Wire == "group" {
bra, ket = '{', '}'
}
if err := w.WriteByte(bra); err != nil {
return err
}
if !w.compact {
if err := w.WriteByte('\n'); err != nil {
return err
}
}
w.indent()
if v.CanAddr() {
// Calling v.Interface on a struct causes the reflect package to
// copy the entire struct. This is racy with the new Marshaler
// since we atomically update the XXX_sizecache.
//
// Thus, we retrieve a pointer to the struct if possible to avoid
// a race since v.Interface on the pointer doesn't copy the struct.
//
// If v is not addressable, then we are not worried about a race
// since it implies that the binary Marshaler cannot possibly be
// mutating this value.
v = v.Addr()
}
if v.Type().Implements(textMarshalerType) {
text, err := v.Interface().(encoding.TextMarshaler).MarshalText()
if err != nil {
return err
}
if _, err = w.Write(text); err != nil {
return err
}
} else {
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
if err := tm.writeStruct(w, v); err != nil {
return err
}
}
w.unindent()
if err := w.WriteByte(ket); err != nil {
return err
}
default:
_, err := fmt.Fprint(w, v.Interface())
return err
}
return nil
} | writeAny writes an arbitrary field. | writeAny | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func isprint(c byte) bool {
return c >= 0x20 && c < 0x7f
} | equivalent to C's isprint. | isprint | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func writeString(w *textWriter, s string) error {
// use WriteByte here to get any needed indent
if err := w.WriteByte('"'); err != nil {
return err
}
// Loop over the bytes, not the runes.
for i := 0; i < len(s); i++ {
var err error
// Divergence from C++: we don't escape apostrophes.
// There's no need to escape them, and the C++ parser
// copes with a naked apostrophe.
switch c := s[i]; c {
case '\n':
_, err = w.w.Write(backslashN)
case '\r':
_, err = w.w.Write(backslashR)
case '\t':
_, err = w.w.Write(backslashT)
case '"':
_, err = w.w.Write(backslashDQ)
case '\\':
_, err = w.w.Write(backslashBS)
default:
if isprint(c) {
err = w.w.WriteByte(c)
} else {
_, err = fmt.Fprintf(w.w, "\\%03o", c)
}
}
if err != nil {
return err
}
}
return w.WriteByte('"')
} | writeString writes a string in the protocol buffer text format.
It is similar to strconv.Quote except we don't use Go escape sequences,
we treat the string as a byte sequence, and we use octal escapes.
These differences are to maintain interoperability with the other
languages' implementations of the text format. | writeString | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func (tm *TextMarshaler) writeExtensions(w *textWriter, pv reflect.Value) error {
emap := extensionMaps[pv.Type().Elem()]
e := pv.Interface().(Message)
var m map[int32]Extension
var mu sync.Locker
if em, ok := e.(extensionsBytes); ok {
eb := em.GetExtensions()
var err error
m, err = BytesToExtensionsMap(*eb)
if err != nil {
return err
}
mu = notLocker{}
} else if _, ok := e.(extendableProto); ok {
ep, _ := extendable(e)
m, mu = ep.extensionsRead()
if m == nil {
return nil
}
}
// Order the extensions by ID.
// This isn't strictly necessary, but it will give us
// canonical output, which will also make testing easier.
mu.Lock()
ids := make([]int32, 0, len(m))
for id := range m {
ids = append(ids, id)
}
sort.Sort(int32Slice(ids))
mu.Unlock()
for _, extNum := range ids {
ext := m[extNum]
var desc *ExtensionDesc
if emap != nil {
desc = emap[extNum]
}
if desc == nil {
// Unknown extension.
if err := writeUnknownStruct(w, ext.enc); err != nil {
return err
}
continue
}
pb, err := GetExtension(e, desc)
if err != nil {
return fmt.Errorf("failed getting extension: %v", err)
}
// Repeated extensions will appear as a slice.
if !desc.repeated() {
if err := tm.writeExtension(w, desc.Name, pb); err != nil {
return err
}
} else {
v := reflect.ValueOf(pb)
for i := 0; i < v.Len(); i++ {
if err := tm.writeExtension(w, desc.Name, v.Index(i).Interface()); err != nil {
return err
}
}
}
}
return nil
} | writeExtensions writes all the extensions in pv.
pv is assumed to be a pointer to a protocol message struct that is extendable. | writeExtensions | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func (tm *TextMarshaler) Marshal(w io.Writer, pb Message) error {
val := reflect.ValueOf(pb)
if pb == nil || val.IsNil() {
w.Write([]byte("<nil>"))
return nil
}
var bw *bufio.Writer
ww, ok := w.(writer)
if !ok {
bw = bufio.NewWriter(w)
ww = bw
}
aw := &textWriter{
w: ww,
complete: true,
compact: tm.Compact,
}
if etm, ok := pb.(encoding.TextMarshaler); ok {
text, err := etm.MarshalText()
if err != nil {
return err
}
if _, err = aw.Write(text); err != nil {
return err
}
if bw != nil {
return bw.Flush()
}
return nil
}
// Dereference the received pointer so we don't have outer < and >.
v := reflect.Indirect(val)
if err := tm.writeStruct(aw, v); err != nil {
return err
}
if bw != nil {
return bw.Flush()
}
return nil
} | Marshal writes a given protocol buffer in text format.
The only errors returned are from w. | Marshal | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func (tm *TextMarshaler) Text(pb Message) string {
var buf bytes.Buffer
tm.Marshal(&buf, pb)
return buf.String()
} | Text is the same as Marshal, but returns the string directly. | Text | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func MarshalText(w io.Writer, pb Message) error { return defaultTextMarshaler.Marshal(w, pb) } | MarshalText writes a given protocol buffer in text format.
The only errors returned are from w. | MarshalText | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func MarshalTextString(pb Message) string { return defaultTextMarshaler.Text(pb) } | MarshalTextString is the same as MarshalText, but returns the string directly. | MarshalTextString | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func CompactText(w io.Writer, pb Message) error { return compactTextMarshaler.Marshal(w, pb) } | CompactText writes a given protocol buffer in compact text format (one line). | CompactText | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func CompactTextString(pb Message) string { return compactTextMarshaler.Text(pb) } | CompactTextString is the same as CompactText, but returns the string directly. | CompactTextString | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/gogo/protobuf/proto/text.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/gogo/protobuf/proto/text.go | Apache-2.0 |
func FromSlogHandler(handler slog.Handler) Logger {
if handler, ok := handler.(*slogHandler); ok {
if handler.sink == nil {
return Discard()
}
return New(handler.sink).V(int(handler.levelBias))
}
return New(&slogSink{handler: handler})
} | FromSlogHandler returns a Logger which writes to the slog.Handler.
The logr verbosity level is mapped to slog levels such that V(0) becomes
slog.LevelInfo and V(4) becomes slog.LevelDebug. | FromSlogHandler | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/slogr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/slogr.go | Apache-2.0 |
func ToSlogHandler(logger Logger) slog.Handler {
if sink, ok := logger.GetSink().(*slogSink); ok && logger.GetV() == 0 {
return sink.handler
}
handler := &slogHandler{sink: logger.GetSink(), levelBias: slog.Level(logger.GetV())}
if slogSink, ok := handler.sink.(SlogSink); ok {
handler.slogSink = slogSink
}
return handler
} | ToSlogHandler returns a slog.Handler which writes to the same sink as the Logger.
The returned logger writes all records with level >= slog.LevelError as
error log entries with LogSink.Error, regardless of the verbosity level of
the Logger:
logger := <some Logger with 0 as verbosity level>
slog.New(ToSlogHandler(logger.V(10))).Error(...) -> logSink.Error(...)
The level of all other records gets reduced by the verbosity
level of the Logger and the result is negated. If it happens
to be negative, then it gets replaced by zero because a LogSink
is not expected to handled negative levels:
slog.New(ToSlogHandler(logger)).Debug(...) -> logger.GetSink().Info(level=4, ...)
slog.New(ToSlogHandler(logger)).Warning(...) -> logger.GetSink().Info(level=0, ...)
slog.New(ToSlogHandler(logger)).Info(...) -> logger.GetSink().Info(level=0, ...)
slog.New(ToSlogHandler(logger.V(4))).Info(...) -> logger.GetSink().Info(level=4, ...) | ToSlogHandler | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/slogr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/slogr.go | Apache-2.0 |
func FromContext(ctx context.Context) (Logger, error) {
v := ctx.Value(contextKey{})
if v == nil {
return Logger{}, notFoundError{}
}
switch v := v.(type) {
case Logger:
return v, nil
case *slog.Logger:
return FromSlogHandler(v.Handler()), nil
default:
// Not reached.
panic(fmt.Sprintf("unexpected value type for logr context key: %T", v))
} | FromContext returns a Logger from ctx or an error if no Logger is found. | FromContext | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/context_slog.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/context_slog.go | Apache-2.0 |
func FromContextAsSlogLogger(ctx context.Context) *slog.Logger {
v := ctx.Value(contextKey{})
if v == nil {
return nil
}
switch v := v.(type) {
case Logger:
return slog.New(ToSlogHandler(v))
case *slog.Logger:
return v
default:
// Not reached.
panic(fmt.Sprintf("unexpected value type for logr context key: %T", v))
} | FromContextAsSlogLogger returns a slog.Logger from ctx or nil if no such Logger is found. | FromContextAsSlogLogger | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/context_slog.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/context_slog.go | Apache-2.0 |
func FromContextOrDiscard(ctx context.Context) Logger {
if logger, err := FromContext(ctx); err == nil {
return logger
}
return Discard()
} | FromContextOrDiscard returns a Logger from ctx. If no Logger is found, this
returns a Logger that discards all log messages. | FromContextOrDiscard | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/context_slog.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/context_slog.go | Apache-2.0 |
func NewContext(ctx context.Context, logger Logger) context.Context {
return context.WithValue(ctx, contextKey{}, logger)
} | NewContext returns a new Context, derived from ctx, which carries the
provided Logger. | NewContext | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/context_slog.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/context_slog.go | Apache-2.0 |
func NewContextWithSlogLogger(ctx context.Context, logger *slog.Logger) context.Context {
return context.WithValue(ctx, contextKey{}, logger)
} | NewContextWithSlogLogger returns a new Context, derived from ctx, which carries the
provided slog.Logger. | NewContextWithSlogLogger | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/context_slog.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/context_slog.go | Apache-2.0 |
func New(sink LogSink) Logger {
logger := Logger{}
logger.setSink(sink)
if sink != nil {
sink.Init(runtimeInfo)
}
return logger
} | New returns a new Logger instance. This is primarily used by libraries
implementing LogSink, rather than end users. Passing a nil sink will create
a Logger which discards all log lines. | New | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l *Logger) setSink(sink LogSink) {
l.sink = sink
} | setSink stores the sink and updates any related fields. It mutates the
logger and thus is only safe to use for loggers that are not currently being
used concurrently. | setSink | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) GetSink() LogSink {
return l.sink
} | GetSink returns the stored sink. | GetSink | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) WithSink(sink LogSink) Logger {
l.setSink(sink)
return l
} | WithSink returns a copy of the logger with the new sink. | WithSink | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) Enabled() bool {
// Some implementations of LogSink look at the caller in Enabled (e.g.
// different verbosity levels per package or file), but we only pass one
// CallDepth in (via Init). This means that all calls from Logger to the
// LogSink's Enabled, Info, and Error methods must have the same number of
// frames. In other words, Logger methods can't call other Logger methods
// which call these LogSink methods unless we do it the same in all paths.
return l.sink != nil && l.sink.Enabled(l.level)
} | Enabled tests whether this Logger is enabled. For example, commandline
flags might be used to set the logging verbosity and disable some info logs. | Enabled | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) Info(msg string, keysAndValues ...any) {
if l.sink == nil {
return
}
if l.sink.Enabled(l.level) { // see comment in Enabled
if withHelper, ok := l.sink.(CallStackHelperLogSink); ok {
withHelper.GetCallStackHelper()()
}
l.sink.Info(l.level, msg, keysAndValues...)
}
} | Info logs a non-error message with the given key/value pairs as context.
The msg argument should be used to add some constant description to the log
line. The key/value pairs can then be used to add additional variable
information. The key/value pairs must alternate string keys and arbitrary
values. | Info | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) Error(err error, msg string, keysAndValues ...any) {
if l.sink == nil {
return
}
if withHelper, ok := l.sink.(CallStackHelperLogSink); ok {
withHelper.GetCallStackHelper()()
}
l.sink.Error(err, msg, keysAndValues...)
} | Error logs an error, with the given message and key/value pairs as context.
It functions similarly to Info, but may have unique behavior, and should be
preferred for logging errors (see the package documentations for more
information). The log message will always be emitted, regardless of
verbosity level.
The msg argument should be used to add context to any underlying error,
while the err argument should be used to attach the actual error that
triggered this log line, if present. The err parameter is optional
and nil may be passed instead of an error instance. | Error | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) V(level int) Logger {
if l.sink == nil {
return l
}
if level < 0 {
level = 0
}
l.level += level
return l
} | V returns a new Logger instance for a specific verbosity level, relative to
this Logger. In other words, V-levels are additive. A higher verbosity
level means a log message is less important. Negative V-levels are treated
as 0. | V | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) GetV() int {
// 0 if l.sink nil because of the if check in V above.
return l.level
} | GetV returns the verbosity level of the logger. If the logger's LogSink is
nil as in the Discard logger, this will always return 0. | GetV | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) WithValues(keysAndValues ...any) Logger {
if l.sink == nil {
return l
}
l.setSink(l.sink.WithValues(keysAndValues...))
return l
} | WithValues returns a new Logger instance with additional key/value pairs.
See Info for documentation on how key/value pairs work. | WithValues | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) WithName(name string) Logger {
if l.sink == nil {
return l
}
l.setSink(l.sink.WithName(name))
return l
} | WithName returns a new Logger instance with the specified name element added
to the Logger's name. Successive calls with WithName append additional
suffixes to the Logger's name. It's strongly recommended that name segments
contain only letters, digits, and hyphens (see the package documentation for
more information). | WithName | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) WithCallDepth(depth int) Logger {
if l.sink == nil {
return l
}
if withCallDepth, ok := l.sink.(CallDepthLogSink); ok {
l.setSink(withCallDepth.WithCallDepth(depth))
}
return l
} | WithCallDepth returns a Logger instance that offsets the call stack by the
specified number of frames when logging call site information, if possible.
This is useful for users who have helper functions between the "real" call
site and the actual calls to Logger methods. If depth is 0 the attribution
should be to the direct caller of this function. If depth is 1 the
attribution should skip 1 call frame, and so on. Successive calls to this
are additive.
If the underlying log implementation supports a WithCallDepth(int) method,
it will be called and the result returned. If the implementation does not
support CallDepthLogSink, the original Logger will be returned.
To skip one level, WithCallStackHelper() should be used instead of
WithCallDepth(1) because it works with implementions that support the
CallDepthLogSink and/or CallStackHelperLogSink interfaces. | WithCallDepth | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) WithCallStackHelper() (func(), Logger) {
if l.sink == nil {
return func() {}, l
}
var helper func()
if withCallDepth, ok := l.sink.(CallDepthLogSink); ok {
l.setSink(withCallDepth.WithCallDepth(1))
}
if withHelper, ok := l.sink.(CallStackHelperLogSink); ok {
helper = withHelper.GetCallStackHelper()
} else {
helper = func() {}
}
return helper, l
} | WithCallStackHelper returns a new Logger instance that skips the direct
caller when logging call site information, if possible. This is useful for
users who have helper functions between the "real" call site and the actual
calls to Logger methods and want to support loggers which depend on marking
each individual helper function, like loggers based on testing.T.
In addition to using that new logger instance, callers also must call the
returned function.
If the underlying log implementation supports a WithCallDepth(int) method,
WithCallDepth(1) will be called to produce a new logger. If it supports a
WithCallStackHelper() method, that will be also called. If the
implementation does not support either of these, the original Logger will be
returned. | WithCallStackHelper | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func (l Logger) IsZero() bool {
return l.sink == nil
} | IsZero returns true if this logger is an uninitialized zero value | IsZero | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/logr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/logr.go | Apache-2.0 |
func FromContext(ctx context.Context) (Logger, error) {
if v, ok := ctx.Value(contextKey{}).(Logger); ok {
return v, nil
}
return Logger{}, notFoundError{}
} | FromContext returns a Logger from ctx or an error if no Logger is found. | FromContext | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/context_noslog.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/context_noslog.go | Apache-2.0 |
func FromContextOrDiscard(ctx context.Context) Logger {
if v, ok := ctx.Value(contextKey{}).(Logger); ok {
return v
}
return Discard()
} | FromContextOrDiscard returns a Logger from ctx. If no Logger is found, this
returns a Logger that discards all log messages. | FromContextOrDiscard | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/context_noslog.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/context_noslog.go | Apache-2.0 |
func NewContext(ctx context.Context, logger Logger) context.Context {
return context.WithValue(ctx, contextKey{}, logger)
} | NewContext returns a new Context, derived from ctx, which carries the
provided Logger. | NewContext | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/context_noslog.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/context_noslog.go | Apache-2.0 |
func (l *slogHandler) GetLevel() slog.Level {
return l.levelBias
} | GetLevel is used for black box unit testing. | GetLevel | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/sloghandler.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/sloghandler.go | Apache-2.0 |
func (l *slogHandler) sinkWithCallDepth() LogSink {
if sink, ok := l.sink.(CallDepthLogSink); ok {
return sink.WithCallDepth(2)
}
return l.sink
} | sinkWithCallDepth adjusts the stack unwinding so that when Error or Info
are called by Handle, code in slog gets skipped.
This offset currently (Go 1.21.0) works for calls through
slog.New(ToSlogHandler(...)). There's no guarantee that the call
chain won't change. Wrapping the handler will also break unwinding. It's
still better than not adjusting at all....
This cannot be done when constructing the handler because FromSlogHandler needs
access to the original sink without this adjustment. A second copy would
work, but then WithAttrs would have to be called for both of them. | sinkWithCallDepth | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/sloghandler.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/sloghandler.go | Apache-2.0 |
func attrToKVs(attr slog.Attr, groupPrefix string, kvList []any) []any {
attrVal := attr.Value.Resolve()
if attrVal.Kind() == slog.KindGroup {
groupVal := attrVal.Group()
grpKVs := make([]any, 0, 2*len(groupVal))
prefix := groupPrefix
if attr.Key != "" {
prefix = addPrefix(groupPrefix, attr.Key)
}
for _, attr := range groupVal {
grpKVs = attrToKVs(attr, prefix, grpKVs)
}
kvList = append(kvList, grpKVs...)
} else if attr.Key != "" {
kvList = append(kvList, addPrefix(groupPrefix, attr.Key), attrVal.Any())
}
return kvList
} | attrToKVs appends a slog.Attr to a logr-style kvList. It handle slog Groups
and other details of slog. | attrToKVs | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/sloghandler.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/sloghandler.go | Apache-2.0 |
func (l *slogHandler) levelFromSlog(level slog.Level) int {
result := -level
result += l.levelBias // in case the original Logger had a V level
if result < 0 {
result = 0 // because LogSink doesn't expect negative V levels
}
return int(result)
} | levelFromSlog adjusts the level by the logger's verbosity and negates it.
It ensures that the result is >= 0. This is necessary because the result is
passed to a LogSink and that API did not historically document whether
levels could be negative or what that meant.
Some example usage:
logrV0 := getMyLogger()
logrV2 := logrV0.V(2)
slogV2 := slog.New(logr.ToSlogHandler(logrV2))
slogV2.Debug("msg") // =~ logrV2.V(4) =~ logrV0.V(6)
slogV2.Info("msg") // =~ logrV2.V(0) =~ logrV0.V(2)
slogv2.Warn("msg") // =~ logrV2.V(-4) =~ logrV0.V(0) | levelFromSlog | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/sloghandler.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/sloghandler.go | Apache-2.0 |
func Discard() Logger {
return New(nil)
} | Discard returns a Logger that discards all messages logged to it. It can be
used whenever the caller is not interested in the logs. Logger instances
produced by this function always compare as equal. | Discard | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/discard.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/discard.go | Apache-2.0 |
func NewLogr(handler slog.Handler) logr.Logger {
return logr.FromSlogHandler(handler)
} | NewLogr returns a logr.Logger which writes to the slog.Handler.
Deprecated: use [logr.FromSlogHandler] instead. | NewLogr | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/slogr/slogr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/slogr/slogr.go | Apache-2.0 |
func NewSlogHandler(logger logr.Logger) slog.Handler {
return logr.ToSlogHandler(logger)
} | NewSlogHandler returns a slog.Handler which writes to the same sink as the logr.Logger.
Deprecated: use [logr.ToSlogHandler] instead. | NewSlogHandler | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/slogr/slogr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/slogr/slogr.go | Apache-2.0 |
func ToSlogHandler(logger logr.Logger) slog.Handler {
return logr.ToSlogHandler(logger)
} | ToSlogHandler returns a slog.Handler which writes to the same sink as the logr.Logger.
Deprecated: use [logr.ToSlogHandler] instead. | ToSlogHandler | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/slogr/slogr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/slogr/slogr.go | Apache-2.0 |
func attrToKVs(attr slog.Attr, kvList []any) []any {
attrVal := attr.Value.Resolve()
if attrVal.Kind() == slog.KindGroup {
groupVal := attrVal.Group()
grpKVs := make([]any, 0, 2*len(groupVal))
for _, attr := range groupVal {
grpKVs = attrToKVs(attr, grpKVs)
}
if attr.Key == "" {
// slog says we have to inline these
kvList = append(kvList, grpKVs...)
} else {
kvList = append(kvList, attr.Key, PseudoStruct(grpKVs))
}
} else if attr.Key != "" {
kvList = append(kvList, attr.Key, attrVal.Any())
}
return kvList
} | attrToKVs appends a slog.Attr to a logr-style kvList. It handle slog Groups
and other details of slog. | attrToKVs | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/slogsink.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/slogsink.go | Apache-2.0 |
func (l fnlogger) levelFromSlog(level slog.Level) int {
result := -level
if result < 0 {
result = 0 // because LogSink doesn't expect negative V levels
}
return int(result)
} | levelFromSlog adjusts the level by the logger's verbosity and negates it.
It ensures that the result is >= 0. This is necessary because the result is
passed to a LogSink and that API did not historically document whether
levels could be negative or what that meant.
Some example usage:
logrV0 := getMyLogger()
logrV2 := logrV0.V(2)
slogV2 := slog.New(logr.ToSlogHandler(logrV2))
slogV2.Debug("msg") // =~ logrV2.V(4) =~ logrV0.V(6)
slogV2.Info("msg") // =~ logrV2.V(0) =~ logrV0.V(2)
slogv2.Warn("msg") // =~ logrV2.V(-4) =~ logrV0.V(0) | levelFromSlog | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/slogsink.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/slogsink.go | Apache-2.0 |
func New(fn func(prefix, args string), opts Options) logr.Logger {
return logr.New(newSink(fn, NewFormatter(opts)))
} | New returns a logr.Logger which is implemented by an arbitrary function. | New | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/funcr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/funcr.go | Apache-2.0 |
func NewJSON(fn func(obj string), opts Options) logr.Logger {
fnWrapper := func(_, obj string) {
fn(obj)
}
return logr.New(newSink(fnWrapper, NewFormatterJSON(opts)))
} | NewJSON returns a logr.Logger which is implemented by an arbitrary function
and produces JSON output. | NewJSON | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/funcr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/funcr.go | Apache-2.0 |
func NewFormatter(opts Options) Formatter {
return newFormatter(opts, outputKeyValue)
} | NewFormatter constructs a Formatter which emits a JSON-like key=value format. | NewFormatter | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/funcr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/funcr.go | Apache-2.0 |
func NewFormatterJSON(opts Options) Formatter {
return newFormatter(opts, outputJSON)
} | NewFormatterJSON constructs a Formatter which emits strict JSON. | NewFormatterJSON | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/funcr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/funcr.go | Apache-2.0 |
func (f Formatter) render(builtins, args []any) string {
// Empirically bytes.Buffer is faster than strings.Builder for this.
buf := bytes.NewBuffer(make([]byte, 0, 1024))
if f.outputFormat == outputJSON {
buf.WriteByte('{') // for the whole record
}
// Render builtins
vals := builtins
if hook := f.opts.RenderBuiltinsHook; hook != nil {
vals = hook(f.sanitize(vals))
}
f.flatten(buf, vals, false) // keys are ours, no need to escape
continuing := len(builtins) > 0
// Turn the inner-most group into a string
argsStr := func() string {
buf := bytes.NewBuffer(make([]byte, 0, 1024))
vals = args
if hook := f.opts.RenderArgsHook; hook != nil {
vals = hook(f.sanitize(vals))
}
f.flatten(buf, vals, true) // escape user-provided keys
return buf.String()
}()
// Render the stack of groups from the inside out.
bodyStr := f.renderGroup(f.groupName, f.valuesStr, argsStr)
for i := len(f.groups) - 1; i >= 0; i-- {
grp := &f.groups[i]
if grp.values == "" && bodyStr == "" {
// no contents, so we must elide the whole group
continue
}
bodyStr = f.renderGroup(grp.name, grp.values, bodyStr)
}
if bodyStr != "" {
if continuing {
buf.WriteByte(f.comma())
}
buf.WriteString(bodyStr)
}
if f.outputFormat == outputJSON {
buf.WriteByte('}') // for the whole record
}
return buf.String()
} | render produces a log line, ready to use. | render | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/funcr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/funcr.go | Apache-2.0 |
func (f Formatter) renderGroup(name string, values string, args string) string {
buf := bytes.NewBuffer(make([]byte, 0, 1024))
needClosingBrace := false
if name != "" && (values != "" || args != "") {
buf.WriteString(f.quoted(name, true)) // escape user-provided keys
buf.WriteByte(f.colon())
buf.WriteByte('{')
needClosingBrace = true
}
continuing := false
if values != "" {
buf.WriteString(values)
continuing = true
}
if args != "" {
if continuing {
buf.WriteByte(f.comma())
}
buf.WriteString(args)
}
if needClosingBrace {
buf.WriteByte('}')
}
return buf.String()
} | renderGroup returns a string representation of the named group with rendered
values and args. If the name is empty, this will return the values and args,
joined. If the name is not empty, this will return a single key-value pair,
where the value is a grouping of the values and args. If the values and
args are both empty, this will return an empty string, even if the name was
specified. | renderGroup | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/funcr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/funcr.go | Apache-2.0 |
func (f Formatter) flatten(buf *bytes.Buffer, kvList []any, escapeKeys bool) []any {
// This logic overlaps with sanitize() but saves one type-cast per key,
// which can be measurable.
if len(kvList)%2 != 0 {
kvList = append(kvList, noValue)
}
copied := false
for i := 0; i < len(kvList); i += 2 {
k, ok := kvList[i].(string)
if !ok {
if !copied {
newList := make([]any, len(kvList))
copy(newList, kvList)
kvList = newList
copied = true
}
k = f.nonStringKey(kvList[i])
kvList[i] = k
}
v := kvList[i+1]
if i > 0 {
if f.outputFormat == outputJSON {
buf.WriteByte(f.comma())
} else {
// In theory the format could be something we don't understand. In
// practice, we control it, so it won't be.
buf.WriteByte(' ')
}
}
buf.WriteString(f.quoted(k, escapeKeys))
buf.WriteByte(f.colon())
buf.WriteString(f.pretty(v))
}
return kvList
} | flatten renders a list of key-value pairs into a buffer. If escapeKeys is
true, the keys are assumed to have non-JSON-compatible characters in them
and must be evaluated for escapes.
This function returns a potentially modified version of kvList, which
ensures that there is a value for every key (adding a value if needed) and
that each key is a string (substituting a key if needed). | flatten | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/funcr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/funcr.go | Apache-2.0 |
func needsEscape(s string) bool {
for _, r := range s {
if !strconv.IsPrint(r) || r == '\\' || r == '"' {
return true
}
}
return false
} | needsEscape determines whether the input string needs to be escaped or not,
without doing any allocations. | needsEscape | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/go-logr/logr/funcr/funcr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/go-logr/logr/funcr/funcr.go | Apache-2.0 |
func deepMap(dst, src reflect.Value, visited map[uintptr]*visit, depth int, config *Config) (err error) {
overwrite := config.Overwrite
if dst.CanAddr() {
addr := dst.UnsafeAddr()
h := 17 * addr
seen := visited[h]
typ := dst.Type()
for p := seen; p != nil; p = p.next {
if p.ptr == addr && p.typ == typ {
return nil
}
}
// Remember, remember...
visited[h] = &visit{addr, typ, seen}
}
zeroValue := reflect.Value{}
switch dst.Kind() {
case reflect.Map:
dstMap := dst.Interface().(map[string]interface{})
for i, n := 0, src.NumField(); i < n; i++ {
srcType := src.Type()
field := srcType.Field(i)
if !isExported(field) {
continue
}
fieldName := field.Name
fieldName = changeInitialCase(fieldName, unicode.ToLower)
if v, ok := dstMap[fieldName]; !ok || (isEmptyValue(reflect.ValueOf(v)) || overwrite) {
dstMap[fieldName] = src.Field(i).Interface()
}
}
case reflect.Ptr:
if dst.IsNil() {
v := reflect.New(dst.Type().Elem())
dst.Set(v)
}
dst = dst.Elem()
fallthrough
case reflect.Struct:
srcMap := src.Interface().(map[string]interface{})
for key := range srcMap {
config.overwriteWithEmptyValue = true
srcValue := srcMap[key]
fieldName := changeInitialCase(key, unicode.ToUpper)
dstElement := dst.FieldByName(fieldName)
if dstElement == zeroValue {
// We discard it because the field doesn't exist.
continue
}
srcElement := reflect.ValueOf(srcValue)
dstKind := dstElement.Kind()
srcKind := srcElement.Kind()
if srcKind == reflect.Ptr && dstKind != reflect.Ptr {
srcElement = srcElement.Elem()
srcKind = reflect.TypeOf(srcElement.Interface()).Kind()
} else if dstKind == reflect.Ptr {
// Can this work? I guess it can't.
if srcKind != reflect.Ptr && srcElement.CanAddr() {
srcPtr := srcElement.Addr()
srcElement = reflect.ValueOf(srcPtr)
srcKind = reflect.Ptr
}
}
if !srcElement.IsValid() {
continue
}
if srcKind == dstKind {
if err = deepMerge(dstElement, srcElement, visited, depth+1, config); err != nil {
return
}
} else if dstKind == reflect.Interface && dstElement.Kind() == reflect.Interface {
if err = deepMerge(dstElement, srcElement, visited, depth+1, config); err != nil {
return
}
} else if srcKind == reflect.Map {
if err = deepMap(dstElement, srcElement, visited, depth+1, config); err != nil {
return
}
} else {
return fmt.Errorf("type mismatch on %s field: found %v, expected %v", fieldName, srcKind, dstKind)
}
}
}
return
} | Traverses recursively both values, assigning src's fields values to dst.
The map argument tracks comparisons that have already been seen, which allows
short circuiting on recursive types. | deepMap | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/map.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/map.go | Apache-2.0 |
func Map(dst, src interface{}, opts ...func(*Config)) error {
return _map(dst, src, opts...)
} | Map sets fields' values in dst from src.
src can be a map with string keys or a struct. dst must be the opposite:
if src is a map, dst must be a valid pointer to struct. If src is a struct,
dst must be map[string]interface{}.
It won't merge unexported (private) fields and will do recursively
any exported field.
If dst is a map, keys will be src fields' names in lower camel case.
Missing key in src that doesn't match a field in dst will be skipped. This
doesn't apply if dst is a map.
This is separated method from Merge because it is cleaner and it keeps sane
semantics: merging equal types, mapping different (restricted) types. | Map | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/map.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/map.go | Apache-2.0 |
func MapWithOverwrite(dst, src interface{}, opts ...func(*Config)) error {
return _map(dst, src, append(opts, WithOverride)...)
} | MapWithOverwrite will do the same as Map except that non-empty dst attributes will be overridden by
non-empty src attribute values.
Deprecated: Use Map(…) with WithOverride | MapWithOverwrite | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/map.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/map.go | Apache-2.0 |
func isEmptyValue(v reflect.Value) bool {
switch v.Kind() {
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
return v.Len() == 0
case reflect.Bool:
return !v.Bool()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return v.Int() == 0
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return v.Uint() == 0
case reflect.Float32, reflect.Float64:
return v.Float() == 0
case reflect.Interface, reflect.Ptr:
if v.IsNil() {
return true
}
return isEmptyValue(v.Elem())
case reflect.Func:
return v.IsNil()
case reflect.Invalid:
return true
}
return false
} | From src/pkg/encoding/json/encode.go. | isEmptyValue | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/mergo.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/mergo.go | Apache-2.0 |
func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, config *Config) (err error) {
overwrite := config.Overwrite
typeCheck := config.TypeCheck
overwriteWithEmptySrc := config.overwriteWithEmptyValue
overwriteSliceWithEmptySrc := config.overwriteSliceWithEmptyValue
sliceDeepCopy := config.sliceDeepCopy
if !src.IsValid() {
return
}
if dst.CanAddr() {
addr := dst.UnsafeAddr()
h := 17 * addr
seen := visited[h]
typ := dst.Type()
for p := seen; p != nil; p = p.next {
if p.ptr == addr && p.typ == typ {
return nil
}
}
// Remember, remember...
visited[h] = &visit{addr, typ, seen}
}
if config.Transformers != nil && !isEmptyValue(dst) {
if fn := config.Transformers.Transformer(dst.Type()); fn != nil {
err = fn(dst, src)
return
}
}
switch dst.Kind() {
case reflect.Struct:
if hasMergeableFields(dst) {
for i, n := 0, dst.NumField(); i < n; i++ {
if err = deepMerge(dst.Field(i), src.Field(i), visited, depth+1, config); err != nil {
return
}
}
} else {
if (isReflectNil(dst) || overwrite) && (!isEmptyValue(src) || overwriteWithEmptySrc) {
dst.Set(src)
}
}
case reflect.Map:
if dst.IsNil() && !src.IsNil() {
dst.Set(reflect.MakeMap(dst.Type()))
}
if src.Kind() != reflect.Map {
if overwrite {
dst.Set(src)
}
return
}
for _, key := range src.MapKeys() {
srcElement := src.MapIndex(key)
if !srcElement.IsValid() {
continue
}
dstElement := dst.MapIndex(key)
switch srcElement.Kind() {
case reflect.Chan, reflect.Func, reflect.Map, reflect.Interface, reflect.Slice:
if srcElement.IsNil() {
if overwrite {
dst.SetMapIndex(key, srcElement)
}
continue
}
fallthrough
default:
if !srcElement.CanInterface() {
continue
}
switch reflect.TypeOf(srcElement.Interface()).Kind() {
case reflect.Struct:
fallthrough
case reflect.Ptr:
fallthrough
case reflect.Map:
srcMapElm := srcElement
dstMapElm := dstElement
if srcMapElm.CanInterface() {
srcMapElm = reflect.ValueOf(srcMapElm.Interface())
if dstMapElm.IsValid() {
dstMapElm = reflect.ValueOf(dstMapElm.Interface())
}
}
if err = deepMerge(dstMapElm, srcMapElm, visited, depth+1, config); err != nil {
return
}
case reflect.Slice:
srcSlice := reflect.ValueOf(srcElement.Interface())
var dstSlice reflect.Value
if !dstElement.IsValid() || dstElement.IsNil() {
dstSlice = reflect.MakeSlice(srcSlice.Type(), 0, srcSlice.Len())
} else {
dstSlice = reflect.ValueOf(dstElement.Interface())
}
if (!isEmptyValue(src) || overwriteWithEmptySrc || overwriteSliceWithEmptySrc) && (overwrite || isEmptyValue(dst)) && !config.AppendSlice && !sliceDeepCopy {
if typeCheck && srcSlice.Type() != dstSlice.Type() {
return fmt.Errorf("cannot override two slices with different type (%s, %s)", srcSlice.Type(), dstSlice.Type())
}
dstSlice = srcSlice
} else if config.AppendSlice {
if srcSlice.Type() != dstSlice.Type() {
return fmt.Errorf("cannot append two slices with different type (%s, %s)", srcSlice.Type(), dstSlice.Type())
}
dstSlice = reflect.AppendSlice(dstSlice, srcSlice)
} else if sliceDeepCopy {
i := 0
for ; i < srcSlice.Len() && i < dstSlice.Len(); i++ {
srcElement := srcSlice.Index(i)
dstElement := dstSlice.Index(i)
if srcElement.CanInterface() {
srcElement = reflect.ValueOf(srcElement.Interface())
}
if dstElement.CanInterface() {
dstElement = reflect.ValueOf(dstElement.Interface())
}
if err = deepMerge(dstElement, srcElement, visited, depth+1, config); err != nil {
return
}
}
}
dst.SetMapIndex(key, dstSlice)
}
}
if dstElement.IsValid() && !isEmptyValue(dstElement) && (reflect.TypeOf(srcElement.Interface()).Kind() == reflect.Map || reflect.TypeOf(srcElement.Interface()).Kind() == reflect.Slice) {
continue
}
if srcElement.IsValid() && ((srcElement.Kind() != reflect.Ptr && overwrite) || !dstElement.IsValid() || isEmptyValue(dstElement)) {
if dst.IsNil() {
dst.Set(reflect.MakeMap(dst.Type()))
}
dst.SetMapIndex(key, srcElement)
}
}
case reflect.Slice:
if !dst.CanSet() {
break
}
if (!isEmptyValue(src) || overwriteWithEmptySrc || overwriteSliceWithEmptySrc) && (overwrite || isEmptyValue(dst)) && !config.AppendSlice && !sliceDeepCopy {
dst.Set(src)
} else if config.AppendSlice {
if src.Type() != dst.Type() {
return fmt.Errorf("cannot append two slice with different type (%s, %s)", src.Type(), dst.Type())
}
dst.Set(reflect.AppendSlice(dst, src))
} else if sliceDeepCopy {
for i := 0; i < src.Len() && i < dst.Len(); i++ {
srcElement := src.Index(i)
dstElement := dst.Index(i)
if srcElement.CanInterface() {
srcElement = reflect.ValueOf(srcElement.Interface())
}
if dstElement.CanInterface() {
dstElement = reflect.ValueOf(dstElement.Interface())
}
if err = deepMerge(dstElement, srcElement, visited, depth+1, config); err != nil {
return
}
}
}
case reflect.Ptr:
fallthrough
case reflect.Interface:
if isReflectNil(src) {
if overwriteWithEmptySrc && dst.CanSet() && src.Type().AssignableTo(dst.Type()) {
dst.Set(src)
}
break
}
if src.Kind() != reflect.Interface {
if dst.IsNil() || (src.Kind() != reflect.Ptr && overwrite) {
if dst.CanSet() && (overwrite || isEmptyValue(dst)) {
dst.Set(src)
}
} else if src.Kind() == reflect.Ptr {
if err = deepMerge(dst.Elem(), src.Elem(), visited, depth+1, config); err != nil {
return
}
} else if dst.Elem().Type() == src.Type() {
if err = deepMerge(dst.Elem(), src, visited, depth+1, config); err != nil {
return
}
} else {
return ErrDifferentArgumentsTypes
}
break
}
if dst.IsNil() || overwrite {
if dst.CanSet() && (overwrite || isEmptyValue(dst)) {
dst.Set(src)
}
break
}
if dst.Elem().Kind() == src.Elem().Kind() {
if err = deepMerge(dst.Elem(), src.Elem(), visited, depth+1, config); err != nil {
return
}
break
}
default:
mustSet := (isEmptyValue(dst) || overwrite) && (!isEmptyValue(src) || overwriteWithEmptySrc)
if mustSet {
if dst.CanSet() {
dst.Set(src)
} else {
dst = src
}
}
}
return
} | Traverses recursively both values, assigning src's fields values to dst.
The map argument tracks comparisons that have already been seen, which allows
short circuiting on recursive types. | deepMerge | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func Merge(dst, src interface{}, opts ...func(*Config)) error {
return merge(dst, src, opts...)
} | Merge will fill any empty for value type attributes on the dst struct using corresponding
src attributes if they themselves are not empty. dst and src must be valid same-type structs
and dst must be a pointer to struct.
It won't merge unexported (private) fields and will do recursively any exported field. | Merge | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func MergeWithOverwrite(dst, src interface{}, opts ...func(*Config)) error {
return merge(dst, src, append(opts, WithOverride)...)
} | MergeWithOverwrite will do the same as Merge except that non-empty dst attributes will be overridden by
non-empty src attribute values.
Deprecated: use Merge(…) with WithOverride | MergeWithOverwrite | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func WithTransformers(transformers Transformers) func(*Config) {
return func(config *Config) {
config.Transformers = transformers
}
} | WithTransformers adds transformers to merge, allowing to customize the merging of some types. | WithTransformers | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func WithOverride(config *Config) {
config.Overwrite = true
} | WithOverride will make merge override non-empty dst attributes with non-empty src attributes values. | WithOverride | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func WithOverwriteWithEmptyValue(config *Config) {
config.Overwrite = true
config.overwriteWithEmptyValue = true
} | WithOverwriteWithEmptyValue will make merge override non empty dst attributes with empty src attributes values. | WithOverwriteWithEmptyValue | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func WithOverrideEmptySlice(config *Config) {
config.overwriteSliceWithEmptyValue = true
} | WithOverrideEmptySlice will make merge override empty dst slice with empty src slice. | WithOverrideEmptySlice | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func WithAppendSlice(config *Config) {
config.AppendSlice = true
} | WithAppendSlice will make merge append slices instead of overwriting it. | WithAppendSlice | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func WithTypeCheck(config *Config) {
config.TypeCheck = true
} | WithTypeCheck will make merge check types while overwriting it (must be used with WithOverride). | WithTypeCheck | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func WithSliceDeepCopy(config *Config) {
config.sliceDeepCopy = true
config.Overwrite = true
} | WithSliceDeepCopy will merge slice element one by one with Overwrite flag. | WithSliceDeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func isReflectNil(v reflect.Value) bool {
k := v.Kind()
switch k {
case reflect.Interface, reflect.Slice, reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr:
// Both interface and slice are nil if first word is 0.
// Both are always bigger than a word; assume flagIndir.
return v.IsNil()
default:
return false
}
} | IsReflectNil is the reflect value provided nil | isReflectNil | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/imdario/mergo/merge.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/imdario/mergo/merge.go | Apache-2.0 |
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
} | Resource takes an unqualified resource and returns a Group qualified GroupResource | Resource | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/register.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/register.go | Apache-2.0 |
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&NetworkAttachmentDefinition{},
&NetworkAttachmentDefinitionList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
} | Adds the list of known types to api.Scheme. | addKnownTypes | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/register.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/register.go | Apache-2.0 |
func (in *DeviceInfo) DeepCopyInto(out *DeviceInfo) {
*out = *in
if in.Pci != nil {
in, out := &in.Pci, &out.Pci
*out = new(PciDevice)
**out = **in
}
if in.Vdpa != nil {
in, out := &in.Vdpa, &out.Vdpa
*out = new(VdpaDevice)
**out = **in
}
if in.VhostUser != nil {
in, out := &in.VhostUser, &out.VhostUser
*out = new(VhostDevice)
**out = **in
}
if in.Memif != nil {
in, out := &in.Memif, &out.Memif
*out = new(MemifDevice)
**out = **in
}
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *DeviceInfo) DeepCopy() *DeviceInfo {
if in == nil {
return nil
}
out := new(DeviceInfo)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeviceInfo. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *MemifDevice) DeepCopyInto(out *MemifDevice) {
*out = *in
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *MemifDevice) DeepCopy() *MemifDevice {
if in == nil {
return nil
}
out := new(MemifDevice)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemifDevice. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *NetworkAttachmentDefinition) DeepCopyInto(out *NetworkAttachmentDefinition) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *NetworkAttachmentDefinition) DeepCopy() *NetworkAttachmentDefinition {
if in == nil {
return nil
}
out := new(NetworkAttachmentDefinition)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkAttachmentDefinition. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *NetworkAttachmentDefinition) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
} | DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. | DeepCopyObject | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *NetworkAttachmentDefinitionList) DeepCopyInto(out *NetworkAttachmentDefinitionList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]NetworkAttachmentDefinition, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *NetworkAttachmentDefinitionList) DeepCopy() *NetworkAttachmentDefinitionList {
if in == nil {
return nil
}
out := new(NetworkAttachmentDefinitionList)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkAttachmentDefinitionList. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *NetworkAttachmentDefinitionList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
} | DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. | DeepCopyObject | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *NetworkAttachmentDefinitionSpec) DeepCopyInto(out *NetworkAttachmentDefinitionSpec) {
*out = *in
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *NetworkAttachmentDefinitionSpec) DeepCopy() *NetworkAttachmentDefinitionSpec {
if in == nil {
return nil
}
out := new(NetworkAttachmentDefinitionSpec)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkAttachmentDefinitionSpec. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *PciDevice) DeepCopyInto(out *PciDevice) {
*out = *in
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *PciDevice) DeepCopy() *PciDevice {
if in == nil {
return nil
}
out := new(PciDevice)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PciDevice. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *VdpaDevice) DeepCopyInto(out *VdpaDevice) {
*out = *in
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *VdpaDevice) DeepCopy() *VdpaDevice {
if in == nil {
return nil
}
out := new(VdpaDevice)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VdpaDevice. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *VhostDevice) DeepCopyInto(out *VhostDevice) {
*out = *in
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func (in *VhostDevice) DeepCopy() *VhostDevice {
if in == nil {
return nil
}
out := new(VhostDevice)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VhostDevice. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1/zz_generated.deepcopy.go | Apache-2.0 |
func convertDNS(dns cnitypes.DNS) *v1.DNS {
var v1dns v1.DNS
v1dns.Nameservers = append([]string{}, dns.Nameservers...)
v1dns.Domain = dns.Domain
v1dns.Search = append([]string{}, dns.Search...)
v1dns.Options = append([]string{}, dns.Options...)
return &v1dns
} | convertDNS converts CNI's DNS type to client DNS | convertDNS | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/utils/net-attach-def.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/utils/net-attach-def.go | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.