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 (m *Broadcaster) Action(action EventType, obj runtime.Object) error {
m.incomingBlock.Lock()
defer m.incomingBlock.Unlock()
select {
case <-m.stopped:
return fmt.Errorf("broadcaster already stopped")
default:
}
m.incoming <- Event{action, obj}
return nil
} | Action distributes the given event among all watchers. | Action | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) ActionOrDrop(action EventType, obj runtime.Object) (bool, error) {
m.incomingBlock.Lock()
defer m.incomingBlock.Unlock()
// Ensure that if the broadcaster is stopped we do not send events to it.
select {
case <-m.stopped:
return false, fmt.Errorf("broadcaster already stopped")
default:
}
select {
case m.incoming <- Event{action, obj}:
return true, nil
default:
return false, nil
}
} | Action distributes the given event among all watchers, or drops it on the floor
if too many incoming actions are queued up. Returns true if the action was sent,
false if dropped. | ActionOrDrop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) Shutdown() {
m.blockQueue(func() {
close(m.stopped)
close(m.incoming)
})
m.distributing.Wait()
} | Shutdown disconnects all watchers (but any queued events will still be distributed).
You must not call Action or Watch* after calling Shutdown. This call blocks
until all events have been distributed through the outbound channels. Note
that since they can be buffered, this means that the watchers might not
have received the data yet as it can remain sitting in the buffered
channel. It will block until the broadcaster stop request is actually executed | Shutdown | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) loop() {
// Deliberately not catching crashes here. Yes, bring down the process if there's a
// bug in watch.Broadcaster.
for event := range m.incoming {
if event.Type == internalRunFunctionMarker {
event.Object.(functionFakeRuntimeObject)()
continue
}
m.distribute(event)
}
m.closeAll()
m.distributing.Done()
} | loop receives from m.incoming and distributes to all watchers. | loop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) distribute(event Event) {
if m.fullChannelBehavior == DropIfChannelFull {
for _, w := range m.watchers {
select {
case w.result <- event:
case <-w.stopped:
default: // Don't block if the event can't be queued.
}
}
} else {
for _, w := range m.watchers {
select {
case w.result <- event:
case <-w.stopped:
}
}
}
} | distribute sends event to all watchers. Blocking. | distribute | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (mw *broadcasterWatcher) ResultChan() <-chan Event {
return mw.result
} | ResultChan returns a channel to use for waiting on events. | ResultChan | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (mw *broadcasterWatcher) Stop() {
mw.stop.Do(func() {
close(mw.stopped)
mw.m.stopWatching(mw.id)
})
} | Stop stops watching and removes mw from its list.
It will block until the watcher stop request is actually executed | Stop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (in *Event) DeepCopyInto(out *Event) {
*out = *in
if in.Object != nil {
out.Object = in.Object.DeepCopyObject()
}
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/zz_generated.deepcopy.go | Apache-2.0 |
func (in *Event) DeepCopy() *Event {
if in == nil {
return nil
}
out := new(Event)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Event. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/zz_generated.deepcopy.go | Apache-2.0 |
func NewStreamWatcher(d Decoder, r Reporter) *StreamWatcher {
sw := &StreamWatcher{
source: d,
reporter: r,
// It's easy for a consumer to add buffering via an extra
// goroutine/channel, but impossible for them to remove it,
// so nonbuffered is better.
result: make(chan Event),
// If the watcher is externally stopped there is no receiver anymore
// and the send operations on the result channel, especially the
// error reporting might block forever.
// Therefore a dedicated stop channel is used to resolve this blocking.
done: make(chan struct{}),
}
go sw.receive()
return sw
} | NewStreamWatcher creates a StreamWatcher from the given decoder. | NewStreamWatcher | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/streamwatcher.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/streamwatcher.go | Apache-2.0 |
func (sw *StreamWatcher) ResultChan() <-chan Event {
return sw.result
} | ResultChan implements Interface. | ResultChan | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/streamwatcher.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/streamwatcher.go | Apache-2.0 |
func (sw *StreamWatcher) Stop() {
// Call Close() exactly once by locking and setting a flag.
sw.Lock()
defer sw.Unlock()
// closing a closed channel always panics, therefore check before closing
select {
case <-sw.done:
default:
close(sw.done)
sw.source.Close()
}
} | Stop implements Interface. | Stop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/streamwatcher.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/streamwatcher.go | Apache-2.0 |
func (sw *StreamWatcher) receive() {
defer utilruntime.HandleCrash()
defer close(sw.result)
defer sw.Stop()
for {
action, obj, err := sw.source.Decode()
if err != nil {
switch err {
case io.EOF:
// watch closed normally
case io.ErrUnexpectedEOF:
klog.V(1).Infof("Unexpected EOF during watch stream event decoding: %v", err)
default:
if net.IsProbableEOF(err) || net.IsTimeout(err) {
klog.V(5).Infof("Unable to decode an event from the watch stream: %v", err)
} else {
select {
case <-sw.done:
case sw.result <- Event{
Type: Error,
Object: sw.reporter.AsObject(fmt.Errorf("unable to decode an event from the watch stream: %v", err)),
}:
}
}
}
return
}
select {
case <-sw.done:
return
case sw.result <- Event{
Type: action,
Object: obj,
}:
}
}
} | receive reads result from the decoder in a loop and sends down the result channel. | receive | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/streamwatcher.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/streamwatcher.go | Apache-2.0 |
func NewEmptyWatch() Interface {
ch := make(chan Event)
close(ch)
return emptyWatch(ch)
} | NewEmptyWatch returns a watch interface that returns no results and is closed.
May be used in certain error conditions where no information is available but
an error is not warranted. | NewEmptyWatch | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (w emptyWatch) Stop() {
} | Stop implements Interface | Stop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (w emptyWatch) ResultChan() <-chan Event {
return chan Event(w)
} | ResultChan implements Interface | ResultChan | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *FakeWatcher) Stop() {
f.Lock()
defer f.Unlock()
if !f.stopped {
klog.V(4).Infof("Stopping fake watcher.")
close(f.result)
f.stopped = true
}
} | Stop implements Interface.Stop(). | Stop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *FakeWatcher) Reset() {
f.Lock()
defer f.Unlock()
f.stopped = false
f.result = make(chan Event)
} | Reset prepares the watcher to be reused. | Reset | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *FakeWatcher) Add(obj runtime.Object) {
f.result <- Event{Added, obj}
} | Add sends an add event. | Add | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *FakeWatcher) Modify(obj runtime.Object) {
f.result <- Event{Modified, obj}
} | Modify sends a modify event. | Modify | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *FakeWatcher) Delete(lastValue runtime.Object) {
f.result <- Event{Deleted, lastValue}
} | Delete sends a delete event. | Delete | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *FakeWatcher) Error(errValue runtime.Object) {
f.result <- Event{Error, errValue}
} | Error sends an Error event. | Error | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *FakeWatcher) Action(action EventType, obj runtime.Object) {
f.result <- Event{action, obj}
} | Action sends an event of the requested type, for table-based testing. | Action | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *RaceFreeFakeWatcher) Stop() {
f.Lock()
defer f.Unlock()
if !f.Stopped {
klog.V(4).Infof("Stopping fake watcher.")
close(f.result)
f.Stopped = true
}
} | Stop implements Interface.Stop(). | Stop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *RaceFreeFakeWatcher) Reset() {
f.Lock()
defer f.Unlock()
f.Stopped = false
f.result = make(chan Event, DefaultChanSize)
} | Reset prepares the watcher to be reused. | Reset | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *RaceFreeFakeWatcher) Add(obj runtime.Object) {
f.Lock()
defer f.Unlock()
if !f.Stopped {
select {
case f.result <- Event{Added, obj}:
return
default:
panic(fmt.Errorf("channel full"))
}
}
} | Add sends an add event. | Add | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *RaceFreeFakeWatcher) Modify(obj runtime.Object) {
f.Lock()
defer f.Unlock()
if !f.Stopped {
select {
case f.result <- Event{Modified, obj}:
return
default:
panic(fmt.Errorf("channel full"))
}
}
} | Modify sends a modify event. | Modify | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *RaceFreeFakeWatcher) Delete(lastValue runtime.Object) {
f.Lock()
defer f.Unlock()
if !f.Stopped {
select {
case f.result <- Event{Deleted, lastValue}:
return
default:
panic(fmt.Errorf("channel full"))
}
}
} | Delete sends a delete event. | Delete | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *RaceFreeFakeWatcher) Error(errValue runtime.Object) {
f.Lock()
defer f.Unlock()
if !f.Stopped {
select {
case f.result <- Event{Error, errValue}:
return
default:
panic(fmt.Errorf("channel full"))
}
}
} | Error sends an Error event. | Error | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (f *RaceFreeFakeWatcher) Action(action EventType, obj runtime.Object) {
f.Lock()
defer f.Unlock()
if !f.Stopped {
select {
case f.result <- Event{action, obj}:
return
default:
panic(fmt.Errorf("channel full"))
}
}
} | Action sends an event of the requested type, for table-based testing. | Action | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func NewProxyWatcher(ch chan Event) *ProxyWatcher {
return &ProxyWatcher{
result: ch,
stopCh: make(chan struct{}),
stopped: false,
}
} | NewProxyWatcher creates new ProxyWatcher by wrapping a channel | NewProxyWatcher | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (pw *ProxyWatcher) Stop() {
pw.mutex.Lock()
defer pw.mutex.Unlock()
if !pw.stopped {
pw.stopped = true
close(pw.stopCh)
}
} | Stop implements Interface | Stop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (pw *ProxyWatcher) Stopping() bool {
pw.mutex.Lock()
defer pw.mutex.Unlock()
return pw.stopped
} | Stopping returns true if Stop() has been called | Stopping | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func (pw *ProxyWatcher) ResultChan() <-chan Event {
return pw.result
} | ResultChan implements Interface | ResultChan | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/watch.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/watch.go | Apache-2.0 |
func Filter(w Interface, f FilterFunc) Interface {
fw := &filteredWatch{
incoming: w,
result: make(chan Event),
f: f,
}
go fw.loop()
return fw
} | Filter passes all events through f before allowing them to pass on.
Putting a filter on a watch, as an unavoidable side-effect due to the way
go channels work, effectively causes the watch's event channel to have its
queue length increased by one.
WARNING: filter has a fatal flaw, in that it can't properly update the
Type field (Add/Modified/Deleted) to reflect items beginning to pass the
filter when they previously didn't. | Filter | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/filter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/filter.go | Apache-2.0 |
func (fw *filteredWatch) ResultChan() <-chan Event {
return fw.result
} | ResultChan returns a channel which will receive filtered events. | ResultChan | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/filter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/filter.go | Apache-2.0 |
func (fw *filteredWatch) Stop() {
fw.incoming.Stop()
} | Stop stops the upstream watch, which will eventually stop this watch. | Stop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/filter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/filter.go | Apache-2.0 |
func (fw *filteredWatch) loop() {
defer close(fw.result)
for event := range fw.incoming.ResultChan() {
filtered, keep := fw.f(event)
if keep {
fw.result <- filtered
}
}
} | loop waits for new values, filters them, and resends them. | loop | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/filter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/filter.go | Apache-2.0 |
func NewRecorder(w Interface) *Recorder {
r := &Recorder{}
r.Interface = Filter(w, r.record)
return r
} | NewRecorder wraps an Interface and records any changes sent across it. | NewRecorder | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/filter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/filter.go | Apache-2.0 |
func (r *Recorder) record(in Event) (Event, bool) {
r.lock.Lock()
defer r.lock.Unlock()
r.events = append(r.events, in)
return in, true
} | record is a FilterFunc and tracks each received event. | record | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/filter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/filter.go | Apache-2.0 |
func (r *Recorder) Events() []Event {
r.lock.Lock()
defer r.lock.Unlock()
copied := make([]Event, len(r.events))
copy(copied, r.events)
return copied
} | Events returns a copy of the events sent across this recorder. | Events | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/filter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/filter.go | Apache-2.0 |
func ToSchemaFromOpenAPI(models map[string]*spec.Schema, preserveUnknownFields bool) (*schema.Schema, error) {
c := convert{
preserveUnknownFields: preserveUnknownFields,
output: &schema.Schema{},
}
for name, spec := range models {
// Skip/Ignore top-level references
if len(spec.Ref.String()) > 0 {
continue
}
var a schema.Atom
// Hard-coded schemas for now as proto_models implementation functions.
// https://github.com/kubernetes/kube-openapi/issues/364
if name == quantityResource {
a = schema.Atom{
Scalar: untypedDef.Atom.Scalar,
}
} else if name == rawExtensionResource {
a = untypedDef.Atom
} else {
c2 := c.push(name, &a)
c2.visitSpec(spec)
c.pop(c2)
}
c.insertTypeDef(name, a)
}
if len(c.errorMessages) > 0 {
return nil, errors.New(strings.Join(c.errorMessages, "\n"))
}
c.addCommonTypes()
return c.output, nil
} | ToSchemaFromOpenAPI converts a directory of OpenAPI schemas to an smd Schema.
- models: a map from definition name to OpenAPI V3 structural schema for each definition.
Key in map is used to resolve references in the schema.
- preserveUnknownFields: flag indicating whether unknown fields in all schemas should be preserved.
- returns: nil and an error if there is a parse error, or if schema does not satisfy a
required structural schema invariant for conversion. If no error, returns
a new smd schema.
Schema should be validated as structural before using with this function, or
there may be information lost. | ToSchemaFromOpenAPI | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/schemaconv/openapi.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/schemaconv/openapi.go | Apache-2.0 |
func convertPrimitive(typ string, format string) (a schema.Atom) {
switch typ {
case "integer":
a.Scalar = ptr(schema.Numeric)
case "number":
a.Scalar = ptr(schema.Numeric)
case "string":
switch format {
case "":
a.Scalar = ptr(schema.String)
case "byte":
// byte really means []byte and is encoded as a string.
a.Scalar = ptr(schema.String)
case "int-or-string":
a.Scalar = ptr(schema.Scalar("untyped"))
case "date-time":
a.Scalar = ptr(schema.Scalar("untyped"))
default:
a.Scalar = ptr(schema.Scalar("untyped"))
}
case "boolean":
a.Scalar = ptr(schema.Boolean)
default:
a.Scalar = ptr(schema.Scalar("untyped"))
}
return a
} | Basic conversion functions to convert OpenAPI schema definitions to
SMD Schema atoms | convertPrimitive | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/schemaconv/smd.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/schemaconv/smd.go | Apache-2.0 |
func getMapElementRelationship(ext map[string]any) (schema.ElementRelationship, error) {
val, ok := ext["x-kubernetes-map-type"]
if !ok {
// unset Map element relationship
return "", nil
}
switch val {
case "atomic":
return schema.Atomic, nil
case "granular":
return schema.Separable, nil
default:
return "", fmt.Errorf("unknown map type %v", val)
}
} | Returns map element relationship if specified, or empty string if unspecified | getMapElementRelationship | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/schemaconv/smd.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/schemaconv/smd.go | Apache-2.0 |
func ToSchema(models proto.Models) (*schema.Schema, error) {
return ToSchemaWithPreserveUnknownFields(models, false)
} | ToSchema converts openapi definitions into a schema suitable for structured
merge (i.e. kubectl apply v2). | ToSchema | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/schemaconv/proto_models.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/schemaconv/proto_models.go | Apache-2.0 |
func ToSchemaWithPreserveUnknownFields(models proto.Models, preserveUnknownFields bool) (*schema.Schema, error) {
c := convert{
preserveUnknownFields: preserveUnknownFields,
output: &schema.Schema{},
}
for _, name := range models.ListModels() {
model := models.LookupModel(name)
var a schema.Atom
c2 := c.push(name, &a)
model.Accept(c2)
c.pop(c2)
c.insertTypeDef(name, a)
}
if len(c.errorMessages) > 0 {
return nil, errors.New(strings.Join(c.errorMessages, "\n"))
}
c.addCommonTypes()
return c.output, nil
} | ToSchemaWithPreserveUnknownFields converts openapi definitions into a schema suitable for structured
merge (i.e. kubectl apply v2), it will preserve unknown fields if specified. | ToSchemaWithPreserveUnknownFields | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/schemaconv/proto_models.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/schemaconv/proto_models.go | Apache-2.0 |
func (p *Path) ArrayPath(i int) Path {
return Path{
parent: p,
key: fmt.Sprintf("[%d]", i),
}
} | ArrayPath appends an array index and creates a new path | ArrayPath | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/openapi.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi.go | Apache-2.0 |
func (p *Path) FieldPath(field string) Path {
return Path{
parent: p,
key: fmt.Sprintf(".%s", field),
}
} | FieldPath appends a field name and creates a new path | FieldPath | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/openapi.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi.go | Apache-2.0 |
func (k *Kind) IsRequired(field string) bool {
for _, f := range k.RequiredFields {
if f == field {
return true
}
}
return false
} | IsRequired returns true if `field` is a required field for this type. | IsRequired | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/openapi.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi.go | Apache-2.0 |
func (k *Kind) Keys() []string {
keys := make([]string, 0)
for key := range k.Fields {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
} | Keys returns a alphabetically sorted list of keys. | Keys | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/openapi.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/openapi.go | Apache-2.0 |
func NewOpenAPIV3Data(doc *openapi_v3.Document) (Models, error) {
definitions := Definitions{
models: map[string]Schema{},
}
schemas := doc.GetComponents().GetSchemas()
if schemas == nil {
return &definitions, nil
}
// Save the list of all models first. This will allow us to
// validate that we don't have any dangling reference.
for _, namedSchema := range schemas.GetAdditionalProperties() {
definitions.models[namedSchema.GetName()] = nil
}
// Now, parse each model. We can validate that references exists.
for _, namedSchema := range schemas.GetAdditionalProperties() {
path := NewPath(namedSchema.GetName())
val := namedSchema.GetValue()
if val == nil {
continue
}
if schema, err := definitions.ParseV3SchemaOrReference(namedSchema.GetValue(), &path); err != nil {
return nil, err
} else if schema != nil {
// Schema may be nil if we hit incompleteness in the conversion,
// but not a fatal error
definitions.models[namedSchema.GetName()] = schema
}
}
return &definitions, nil
} | Temporary parse implementation to be used until gnostic->kube-openapi conversion
is possible. | NewOpenAPIV3Data | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/document_v3.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/document_v3.go | Apache-2.0 |
func VendorExtensionToMap(e []*openapi_v2.NamedAny) map[string]interface{} {
values := map[string]interface{}{}
for _, na := range e {
if na.GetName() == "" || na.GetValue() == nil {
continue
}
if na.GetValue().GetYaml() == "" {
continue
}
var value interface{}
err := yaml.Unmarshal([]byte(na.GetValue().GetYaml()), &value)
if err != nil {
continue
}
values[na.GetName()] = value
}
return values
} | VendorExtensionToMap converts openapi VendorExtension to a map. | VendorExtensionToMap | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | Apache-2.0 |
func NewOpenAPIData(doc *openapi_v2.Document) (Models, error) {
definitions := Definitions{
models: map[string]Schema{},
}
// Save the list of all models first. This will allow us to
// validate that we don't have any dangling reference.
for _, namedSchema := range doc.GetDefinitions().GetAdditionalProperties() {
definitions.models[namedSchema.GetName()] = nil
}
// Now, parse each model. We can validate that references exists.
for _, namedSchema := range doc.GetDefinitions().GetAdditionalProperties() {
path := NewPath(namedSchema.GetName())
schema, err := definitions.ParseSchema(namedSchema.GetValue(), &path)
if err != nil {
return nil, err
}
definitions.models[namedSchema.GetName()] = schema
}
return &definitions, nil
} | NewOpenAPIData creates a new `Models` out of the openapi document. | NewOpenAPIData | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | Apache-2.0 |
func (d *Definitions) parseReference(s *openapi_v2.Schema, path *Path) (Schema, error) {
// TODO(wrong): a schema with a $ref can have properties. We can ignore them (would be incomplete), but we cannot return an error.
if len(s.GetProperties().GetAdditionalProperties()) > 0 {
return nil, newSchemaError(path, "unallowed embedded type definition")
}
// TODO(wrong): a schema with a $ref can have a type. We can ignore it (would be incomplete), but we cannot return an error.
if len(s.GetType().GetValue()) > 0 {
return nil, newSchemaError(path, "definition reference can't have a type")
}
// TODO(wrong): $refs outside of the definitions are completely valid. We can ignore them (would be incomplete), but we cannot return an error.
if !strings.HasPrefix(s.GetXRef(), "#/definitions/") {
return nil, newSchemaError(path, "unallowed reference to non-definition %q", s.GetXRef())
}
reference := strings.TrimPrefix(s.GetXRef(), "#/definitions/")
if _, ok := d.models[reference]; !ok {
return nil, newSchemaError(path, "unknown model in reference: %q", reference)
}
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
return &Ref{
BaseSchema: base,
reference: reference,
definitions: d,
}, nil
} | We believe the schema is a reference, verify that and returns a new
Schema | parseReference | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | Apache-2.0 |
func (d *Definitions) parseMap(s *openapi_v2.Schema, path *Path) (Schema, error) {
if len(s.GetType().GetValue()) != 0 && s.GetType().GetValue()[0] != object {
return nil, newSchemaError(path, "invalid object type")
}
var sub Schema
// TODO(incomplete): this misses the boolean case as AdditionalProperties is a bool+schema sum type.
if s.GetAdditionalProperties().GetSchema() == nil {
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
sub = &Arbitrary{
BaseSchema: base,
}
} else {
var err error
sub, err = d.ParseSchema(s.GetAdditionalProperties().GetSchema(), path)
if err != nil {
return nil, err
}
}
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
return &Map{
BaseSchema: base,
SubType: sub,
}, nil
} | We believe the schema is a map, verify and return a new schema | parseMap | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | Apache-2.0 |
func (d *Definitions) ParseSchema(s *openapi_v2.Schema, path *Path) (Schema, error) {
if s.GetXRef() != "" {
// TODO(incomplete): ignoring the rest of s is wrong. As long as there are no conflict, everything from s must be considered
// Reference: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#path-item-object
return d.parseReference(s, path)
}
objectTypes := s.GetType().GetValue()
switch len(objectTypes) {
case 0:
// in the OpenAPI schema served by older k8s versions, object definitions created from structs did not include
// the type:object property (they only included the "properties" property), so we need to handle this case
// TODO: validate that we ever published empty, non-nil properties. JSON roundtripping nils them.
if s.GetProperties() != nil {
// TODO(wrong): when verifying a non-object later against this, it will be rejected as invalid type.
// TODO(CRD validation schema publishing): we have to filter properties (empty or not) if type=object is not given
return d.parseKind(s, path)
} else {
// Definition has no type and no properties. Treat it as an arbitrary value
// TODO(incomplete): what if it has additionalProperties=false or patternProperties?
// ANSWER: parseArbitrary is less strict than it has to be with patternProperties (which is ignored). So this is correct (of course not complete).
return d.parseArbitrary(s, path)
}
case 1:
t := objectTypes[0]
switch t {
case object:
if s.GetProperties() != nil {
return d.parseKind(s, path)
} else {
return d.parseMap(s, path)
}
case array:
return d.parseArray(s, path)
}
return d.parsePrimitive(s, path)
default:
// the OpenAPI generator never generates (nor it ever did in the past) OpenAPI type definitions with multiple types
// TODO(wrong): this is rejecting a completely valid OpenAPI spec
// TODO(CRD validation schema publishing): filter these out
return nil, newSchemaError(path, "definitions with multiple types aren't supported")
}
} | ParseSchema creates a walkable Schema from an openapi schema. While
this function is public, it doesn't leak through the interface. | ParseSchema | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | Apache-2.0 |
func (d *Definitions) LookupModel(model string) Schema {
return d.models[model]
} | LookupModel is public through the interface of Models. It
returns a visitable schema from the given model name. | LookupModel | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/util/proto/document.go | Apache-2.0 |
func NewOpenAPIService() *OpenAPIService {
o := &OpenAPIService{}
o.v3Schema = make(map[string]*openAPIV3Group)
// We're not locked because we haven't shared the structure yet.
o.discoveryCache.Store(o.buildDiscoveryCacheLocked())
return o
} | NewOpenAPIService builds an OpenAPIService starting with the given spec. | NewOpenAPIService | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/handler3/handler.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/handler3/handler.go | Apache-2.0 |
func (o *OpenAPIService) UpdateGroupVersionLazy(group string, openapi cached.Value[*spec3.OpenAPI]) {
o.mutex.Lock()
defer o.mutex.Unlock()
if _, ok := o.v3Schema[group]; !ok {
o.v3Schema[group] = newOpenAPIV3Group()
// Since there is a new item, we need to re-build the cache map.
o.discoveryCache.Store(o.buildDiscoveryCacheLocked())
}
o.v3Schema[group].UpdateSpec(openapi)
} | UpdateGroupVersionLazy adds or updates an existing group with the new cached. | UpdateGroupVersionLazy | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/handler3/handler.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/handler3/handler.go | Apache-2.0 |
func OpenAPITypeFormat(typeName string) (string, string) {
mapped, ok := schemaTypeFormatMap[typeName]
if !ok {
return "", ""
}
return mapped.name, mapped.format
} | This function is a reference for converting go (or any custom type) to a simple open API type,format pair. There are
two ways to customize spec for a type. If you add it here, a type will be converted to a simple type and the type
comment (the comment that is added before type definition) will be lost. The spec will still have the property
comment. The second way is to implement OpenAPIDefinitionGetter interface. That function can customize the spec (so
the spec does not need to be simple type,format) or can even return a simple type,format (e.g. IntOrString). For simple
type formats, the benefit of adding OpenAPIDefinitionGetter interface is to keep both type and property documentation.
Example:
type Sample struct {
...
// port of the server
port IntOrString
...
}
// IntOrString documentation...
type IntOrString { ... }
Adding IntOrString to this function:
"port" : {
format: "string",
type: "int-or-string",
Description: "port of the server"
}
Implement OpenAPIDefinitionGetter for IntOrString:
"port" : {
$Ref: "#/definitions/IntOrString"
Description: "port of the server"
}
...
definitions:
{
"IntOrString": {
format: "string",
type: "int-or-string",
Description: "IntOrString documentation..." // new
}
} | OpenAPITypeFormat | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/common/common.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/common/common.go | Apache-2.0 |
func OpenAPIZeroValue(typeName string) (interface{}, bool) {
mapped, ok := schemaTypeFormatMap[typeName]
if !ok {
return nil, false
}
return mapped.zero, true
} | Returns the zero-value for the given type along with true if the type
could be found. | OpenAPIZeroValue | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/common/common.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/common/common.go | Apache-2.0 |
func GenerateOpenAPIV3OneOfSchema(types []string) (oneOf []spec.Schema) {
for _, t := range types {
oneOf = append(oneOf, spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{t}}})
}
return
} | GenerateOpenAPIV3OneOfSchema generate the set of schemas that MUST be assigned to SchemaProps.OneOf | GenerateOpenAPIV3OneOfSchema | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/common/common.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/common/common.go | Apache-2.0 |
func (e *Example) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(e)
}
b1, err := json.Marshal(e.Refable)
if err != nil {
return nil, err
}
b2, err := json.Marshal(e.ExampleProps)
if err != nil {
return nil, err
}
b3, err := json.Marshal(e.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
} | MarshalJSON is a custom marshal function that knows how to encode RequestBody as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/example.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/example.go | Apache-2.0 |
func (p *Paths) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(p)
}
b1, err := json.Marshal(p.VendorExtensible)
if err != nil {
return nil, err
}
pths := make(map[string]*Path)
for k, v := range p.Paths {
if strings.HasPrefix(k, "/") {
pths[k] = v
}
}
b2, err := json.Marshal(pths)
if err != nil {
return nil, err
}
concated := swag.ConcatJSON(b1, b2)
return concated, nil
} | MarshalJSON is a custom marshal function that knows how to encode Paths as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/path.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/path.go | Apache-2.0 |
func (p *Paths) UnmarshalJSON(data []byte) error {
if internal.UseOptimizedJSONUnmarshalingV3 {
return jsonv2.Unmarshal(data, p)
}
var res map[string]json.RawMessage
if err := json.Unmarshal(data, &res); err != nil {
return err
}
for k, v := range res {
if strings.HasPrefix(strings.ToLower(k), "x-") {
if p.Extensions == nil {
p.Extensions = make(map[string]interface{})
}
var d interface{}
if err := json.Unmarshal(v, &d); err != nil {
return err
}
p.Extensions[k] = d
}
if strings.HasPrefix(k, "/") {
if p.Paths == nil {
p.Paths = make(map[string]*Path)
}
var pi *Path
if err := json.Unmarshal(v, &pi); err != nil {
return err
}
p.Paths[k] = pi
}
}
return nil
} | UnmarshalJSON hydrates this items instance with the data from JSON | UnmarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/path.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/path.go | Apache-2.0 |
func (p *Path) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(p)
}
b1, err := json.Marshal(p.Refable)
if err != nil {
return nil, err
}
b2, err := json.Marshal(p.PathProps)
if err != nil {
return nil, err
}
b3, err := json.Marshal(p.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
} | MarshalJSON is a custom marshal function that knows how to encode Path as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/path.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/path.go | Apache-2.0 |
func (e *ExternalDocumentation) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(e)
}
b1, err := json.Marshal(e.ExternalDocumentationProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(e.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2), nil
} | MarshalJSON is a custom marshal function that knows how to encode Responses as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/external_documentation.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/external_documentation.go | Apache-2.0 |
func (e *Encoding) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(e)
}
b1, err := json.Marshal(e.EncodingProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(e.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2), nil
} | MarshalJSON is a custom marshal function that knows how to encode Encoding as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/encoding.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/encoding.go | Apache-2.0 |
func (h *Header) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(h)
}
b1, err := json.Marshal(h.Refable)
if err != nil {
return nil, err
}
b2, err := json.Marshal(h.HeaderProps)
if err != nil {
return nil, err
}
b3, err := json.Marshal(h.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
} | MarshalJSON is a custom marshal function that knows how to encode Header as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/header.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/header.go | Apache-2.0 |
func (p *Parameter) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(p)
}
b1, err := json.Marshal(p.Refable)
if err != nil {
return nil, err
}
b2, err := json.Marshal(p.ParameterProps)
if err != nil {
return nil, err
}
b3, err := json.Marshal(p.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
} | MarshalJSON is a custom marshal function that knows how to encode Parameter as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/parameter.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/parameter.go | Apache-2.0 |
func (r *RequestBody) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(r)
}
b1, err := json.Marshal(r.Refable)
if err != nil {
return nil, err
}
b2, err := json.Marshal(r.RequestBodyProps)
if err != nil {
return nil, err
}
b3, err := json.Marshal(r.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
} | MarshalJSON is a custom marshal function that knows how to encode RequestBody as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/request_body.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/request_body.go | Apache-2.0 |
func (s *Server) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(s)
}
b1, err := json.Marshal(s.ServerProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(s.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2), nil
} | MarshalJSON is a custom marshal function that knows how to encode Responses as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/server.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/server.go | Apache-2.0 |
func (s *ServerVariable) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(s)
}
b1, err := json.Marshal(s.ServerVariableProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(s.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2), nil
} | MarshalJSON is a custom marshal function that knows how to encode Responses as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/server.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/server.go | Apache-2.0 |
func (r *Responses) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(r)
}
b1, err := json.Marshal(r.ResponsesProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(r.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2), nil
} | MarshalJSON is a custom marshal function that knows how to encode Responses as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/response.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/response.go | Apache-2.0 |
func (r ResponsesProps) MarshalJSON() ([]byte, error) {
toser := map[string]*Response{}
if r.Default != nil {
toser["default"] = r.Default
}
for k, v := range r.StatusCodeResponses {
toser[strconv.Itoa(k)] = v
}
return json.Marshal(toser)
} | MarshalJSON is a custom marshal function that knows how to encode ResponsesProps as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/response.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/response.go | Apache-2.0 |
func (r *ResponsesProps) UnmarshalJSON(data []byte) error {
if internal.UseOptimizedJSONUnmarshalingV3 {
return jsonv2.Unmarshal(data, r)
}
var res map[string]json.RawMessage
if err := json.Unmarshal(data, &res); err != nil {
return err
}
if v, ok := res["default"]; ok {
value := Response{}
if err := json.Unmarshal(v, &value); err != nil {
return err
}
r.Default = &value
delete(res, "default")
}
for k, v := range res {
// Take all integral keys
if nk, err := strconv.Atoi(k); err == nil {
if r.StatusCodeResponses == nil {
r.StatusCodeResponses = map[int]*Response{}
}
value := Response{}
if err := json.Unmarshal(v, &value); err != nil {
return err
}
r.StatusCodeResponses[nk] = &value
}
}
return nil
} | UnmarshalJSON unmarshals responses from JSON | UnmarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/response.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/response.go | Apache-2.0 |
func (r *Response) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(r)
}
b1, err := json.Marshal(r.Refable)
if err != nil {
return nil, err
}
b2, err := json.Marshal(r.ResponseProps)
if err != nil {
return nil, err
}
b3, err := json.Marshal(r.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
} | MarshalJSON is a custom marshal function that knows how to encode Response as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/response.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/response.go | Apache-2.0 |
func (r *Link) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(r)
}
b1, err := json.Marshal(r.Refable)
if err != nil {
return nil, err
}
b2, err := json.Marshal(r.LinkProps)
if err != nil {
return nil, err
}
b3, err := json.Marshal(r.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
} | MarshalJSON is a custom marshal function that knows how to encode Link as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/response.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/response.go | Apache-2.0 |
func (o *Operation) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(o)
}
b1, err := json.Marshal(o.OperationProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(o.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2), nil
} | MarshalJSON is a custom marshal function that knows how to encode Operation as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/operation.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/operation.go | Apache-2.0 |
func (o *Operation) UnmarshalJSON(data []byte) error {
if internal.UseOptimizedJSONUnmarshalingV3 {
return jsonv2.Unmarshal(data, o)
}
if err := json.Unmarshal(data, &o.OperationProps); err != nil {
return err
}
return json.Unmarshal(data, &o.VendorExtensible)
} | UnmarshalJSON hydrates this items instance with the data from JSON | UnmarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/operation.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/operation.go | Apache-2.0 |
func (m *MediaType) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(m)
}
b1, err := json.Marshal(m.MediaTypeProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(m.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2), nil
} | MarshalJSON is a custom marshal function that knows how to encode MediaType as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/media_type.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/media_type.go | Apache-2.0 |
func (s *SecurityScheme) MarshalJSON() ([]byte, error) {
if internal.UseOptimizedJSONMarshalingV3 {
return internal.DeterministicMarshal(s)
}
b1, err := json.Marshal(s.SecuritySchemeProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(s.VendorExtensible)
if err != nil {
return nil, err
}
b3, err := json.Marshal(s.Refable)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2, b3), nil
} | MarshalJSON is a custom marshal function that knows how to encode SecurityScheme as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/security_scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/security_scheme.go | Apache-2.0 |
func (s *SecurityScheme) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &s.SecuritySchemeProps); err != nil {
return err
}
if err := json.Unmarshal(data, &s.VendorExtensible); err != nil {
return err
}
return json.Unmarshal(data, &s.Refable)
} | UnmarshalJSON hydrates this items instance with the data from JSON | UnmarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/security_scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/security_scheme.go | Apache-2.0 |
func (o *OAuthFlow) MarshalJSON() ([]byte, error) {
b1, err := json.Marshal(o.OAuthFlowProps)
if err != nil {
return nil, err
}
b2, err := json.Marshal(o.VendorExtensible)
if err != nil {
return nil, err
}
return swag.ConcatJSON(b1, b2), nil
} | MarshalJSON is a custom marshal function that knows how to encode OAuthFlow as JSON | MarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/security_scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/security_scheme.go | Apache-2.0 |
func (o *OAuthFlow) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &o.OAuthFlowProps); err != nil {
return err
}
return json.Unmarshal(data, &o.VendorExtensible)
} | UnmarshalJSON hydrates this items instance with the data from JSON | UnmarshalJSON | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/spec3/security_scheme.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/spec3/security_scheme.go | Apache-2.0 |
func DeterministicMarshal(in any) ([]byte, error) {
return jsonv2.MarshalOptions{Deterministic: true}.Marshal(jsonv2.EncodeOptions{}, in)
} | DeterministicMarshal calls the jsonv2 library with the deterministic
flag in order to have stable marshaling. | DeterministicMarshal | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/internal/serialization.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/internal/serialization.go | Apache-2.0 |
func JSONRefFromMap(jsonRef *jsonreference.Ref, v map[string]interface{}) error {
if v == nil {
return nil
}
if vv, ok := v["$ref"]; ok {
if str, ok := vv.(string); ok {
ref, err := jsonreference.New(str)
if err != nil {
return err
}
*jsonRef = ref
}
}
return nil
} | JSONRefFromMap populates a json reference object if the map v contains a $ref key. | JSONRefFromMap | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/internal/serialization.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/internal/serialization.go | Apache-2.0 |
func SanitizeExtensions(e map[string]interface{}) map[string]interface{} {
for k := range e {
if !IsExtensionKey(k) {
delete(e, k)
}
}
if len(e) == 0 {
e = nil
}
return e
} | SanitizeExtensions sanitizes the input map such that non extension
keys (non x-*, X-*) keys are dropped from the map. Returns the new
modified map, or nil if the map is now empty. | SanitizeExtensions | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/internal/serialization.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/internal/serialization.go | Apache-2.0 |
func IsExtensionKey(k string) bool {
return len(k) > 1 && (k[0] == 'x' || k[0] == 'X') && k[1] == '-'
} | IsExtensionKey returns true if the input string is of format x-* or X-* | IsExtensionKey | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/kube-openapi/pkg/internal/serialization.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/kube-openapi/pkg/internal/serialization.go | Apache-2.0 |
func ParseAccept(header string) acceptSlice {
partsCount := 0
remaining := header
for len(remaining) > 0 {
partsCount++
_, remaining = nextSplitElement(remaining, ",")
}
accept := make(acceptSlice, 0, partsCount)
remaining = header
var part string
for len(remaining) > 0 {
part, remaining = nextSplitElement(remaining, ",")
part = strings.TrimFunc(part, stringTrimSpaceCutset)
a := Accept{
Q: 1.0,
}
sp, remainingPart := nextSplitElement(part, ";")
sp0, spRemaining := nextSplitElement(sp, "/")
a.Type = strings.TrimFunc(sp0, stringTrimSpaceCutset)
switch {
case len(spRemaining) == 0:
if a.Type == "*" {
a.SubType = "*"
} else {
continue
}
default:
var sp1 string
sp1, spRemaining = nextSplitElement(spRemaining, "/")
if len(spRemaining) > 0 {
continue
}
a.SubType = strings.TrimFunc(sp1, stringTrimSpaceCutset)
}
if len(remainingPart) == 0 {
accept = append(accept, a)
continue
}
a.Params = make(map[string]string)
for len(remainingPart) > 0 {
sp, remainingPart = nextSplitElement(remainingPart, ";")
sp0, spRemaining = nextSplitElement(sp, "=")
if len(spRemaining) == 0 {
continue
}
var sp1 string
sp1, spRemaining = nextSplitElement(spRemaining, "=")
if len(spRemaining) != 0 {
continue
}
token := strings.TrimFunc(sp0, stringTrimSpaceCutset)
if token == "q" {
a.Q, _ = strconv.ParseFloat(sp1, 32)
} else {
a.Params[token] = strings.TrimFunc(sp1, stringTrimSpaceCutset)
}
}
accept = append(accept, a)
}
sort.Sort(accept)
return accept
} | Parse an Accept Header string returning a sorted list
of clauses | ParseAccept | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/munnerz/goautoneg/autoneg.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/munnerz/goautoneg/autoneg.go | Apache-2.0 |
func Negotiate(header string, alternatives []string) (content_type string) {
asp := make([][]string, 0, len(alternatives))
for _, ctype := range alternatives {
asp = append(asp, strings.SplitN(ctype, "/", 2))
}
for _, clause := range ParseAccept(header) {
for i, ctsp := range asp {
if clause.Type == ctsp[0] && clause.SubType == ctsp[1] {
content_type = alternatives[i]
return
}
if clause.Type == ctsp[0] && clause.SubType == "*" {
content_type = alternatives[i]
return
}
if clause.Type == "*" && clause.SubType == "*" {
content_type = alternatives[i]
return
}
}
}
return
} | Negotiate the most appropriate content_type given the accept header
and a list of alternatives. | Negotiate | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/munnerz/goautoneg/autoneg.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/munnerz/goautoneg/autoneg.go | Apache-2.0 |
func NewContainer() *Container {
return &Container{
webServices: []*WebService{},
ServeMux: http.NewServeMux(),
isRegisteredOnRoot: false,
containerFilters: []FilterFunction{},
doNotRecover: true,
recoverHandleFunc: logStackOnRecover,
serviceErrorHandleFunc: writeServiceError,
router: CurlyRouter{},
contentEncodingEnabled: false}
} | NewContainer creates a new Container using a new ServeMux and default router (CurlyRouter) | NewContainer | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
func (c *Container) RecoverHandler(handler RecoverHandleFunction) {
c.recoverHandleFunc = handler
} | RecoverHandler changes the default function (logStackOnRecover) to be called
when a panic is detected. DoNotRecover must be have its default value (=false). | RecoverHandler | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
func (c *Container) ServiceErrorHandler(handler ServiceErrorHandleFunction) {
c.serviceErrorHandleFunc = handler
} | ServiceErrorHandler changes the default function (writeServiceError) to be called
when a ServiceError is detected. | ServiceErrorHandler | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
func (c *Container) DoNotRecover(doNot bool) {
c.doNotRecover = doNot
} | DoNotRecover controls whether panics will be caught to return HTTP 500.
If set to true, Route functions are responsible for handling any error situation.
Default value is true. | DoNotRecover | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
func (c *Container) Router(aRouter RouteSelector) {
c.router = aRouter
} | Router changes the default Router (currently CurlyRouter) | Router | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
func (c *Container) EnableContentEncoding(enabled bool) {
c.contentEncodingEnabled = enabled
} | EnableContentEncoding (default=false) allows for GZIP or DEFLATE encoding of responses. | EnableContentEncoding | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
func (c *Container) Add(service *WebService) *Container {
c.webServicesLock.Lock()
defer c.webServicesLock.Unlock()
// if rootPath was not set then lazy initialize it
if len(service.rootPath) == 0 {
service.Path("/")
}
// cannot have duplicate root paths
for _, each := range c.webServices {
if each.RootPath() == service.RootPath() {
log.Printf("WebService with duplicate root path detected:['%v']", each)
os.Exit(1)
}
}
// If not registered on root then add specific mapping
if !c.isRegisteredOnRoot {
c.isRegisteredOnRoot = c.addHandler(service, c.ServeMux)
}
c.webServices = append(c.webServices, service)
return c
} | Add a WebService to the Container. It will detect duplicate root paths and exit in that case. | Add | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
func (c *Container) addHandler(service *WebService, serveMux *http.ServeMux) bool {
pattern := fixedPrefixPath(service.RootPath())
// check if root path registration is needed
if "/" == pattern || "" == pattern {
serveMux.HandleFunc("/", c.dispatch)
return true
}
// detect if registration already exists
alreadyMapped := false
for _, each := range c.webServices {
if each.RootPath() == service.RootPath() {
alreadyMapped = true
break
}
}
if !alreadyMapped {
serveMux.HandleFunc(pattern, c.dispatch)
if !strings.HasSuffix(pattern, "/") {
serveMux.HandleFunc(pattern+"/", c.dispatch)
}
}
return false
} | addHandler may set a new HandleFunc for the serveMux
this function must run inside the critical region protected by the webServicesLock.
returns true if the function was registered on root ("/") | addHandler | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
func logStackOnRecover(panicReason interface{}, httpWriter http.ResponseWriter) {
var buffer bytes.Buffer
buffer.WriteString(fmt.Sprintf("recover from panic situation: - %v\r\n", panicReason))
for i := 2; ; i += 1 {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
buffer.WriteString(fmt.Sprintf(" %s:%d\r\n", file, line))
}
log.Print(buffer.String())
httpWriter.WriteHeader(http.StatusInternalServerError)
httpWriter.Write(buffer.Bytes())
} | logStackOnRecover is the default RecoverHandleFunction and is called
when DoNotRecover is false and the recoverHandleFunc is not set for the container.
Default implementation logs the stacktrace and writes the stacktrace on the response.
This may be a security issue as it exposes sourcecode information. | logStackOnRecover | go | k8snetworkplumbingwg/multus-cni | vendor/github.com/emicklei/go-restful/v3/container.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/github.com/emicklei/go-restful/v3/container.go | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.