github.com/vmware/govmomi@v0.37.1/session/keep_alive.go (about)

     1  /*
     2  Copyright (c) 2015-2020 VMware, Inc. All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package session
    18  
    19  import (
    20  	"time"
    21  
    22  	"github.com/vmware/govmomi/session/keepalive"
    23  	"github.com/vmware/govmomi/vim25/soap"
    24  )
    25  
    26  // KeepAlive is a backward compatible wrapper around KeepAliveHandler.
    27  func KeepAlive(roundTripper soap.RoundTripper, idleTime time.Duration) soap.RoundTripper {
    28  	return KeepAliveHandler(roundTripper, idleTime, nil)
    29  }
    30  
    31  // KeepAliveHandler is a backward compatible wrapper around keepalive.NewHandlerSOAP.
    32  func KeepAliveHandler(roundTripper soap.RoundTripper, idleTime time.Duration, handler func(soap.RoundTripper) error) soap.RoundTripper {
    33  	var f func() error
    34  	if handler != nil {
    35  		f = func() error {
    36  			return handler(roundTripper)
    37  		}
    38  	}
    39  	return keepalive.NewHandlerSOAP(roundTripper, idleTime, f)
    40  }