本文整理汇总了Golang中github.com/vmware/vic/lib/apiservers/portlayer/restapi/operations.PortLayerAPI.ServerShutdown方法的典型用法代码示例。如果您正苦于以下问题:Golang PortLayerAPI.ServerShutdown方法的具体用法?Golang PortLayerAPI.ServerShutdown怎么用?Golang PortLayerAPI.ServerShutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/vic/lib/apiservers/portlayer/restapi/operations.PortLayerAPI
的用法示例。
在下文中一共展示了PortLayerAPI.ServerShutdown方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: configureAPI
func configureAPI(api *operations.PortLayerAPI) http.Handler {
if options.PortLayerOptions.Debug {
log.SetLevel(log.DebugLevel)
}
ctx := context.Background()
sessionconfig := &session.Config{
Service: options.PortLayerOptions.SDK,
Insecure: options.PortLayerOptions.Insecure,
Keepalive: options.PortLayerOptions.Keepalive,
DatacenterPath: options.PortLayerOptions.DatacenterPath,
ClusterPath: options.PortLayerOptions.ClusterPath,
PoolPath: options.PortLayerOptions.PoolPath,
DatastorePath: options.PortLayerOptions.DatastorePath,
}
sess, err := session.NewSession(sessionconfig).Create(ctx)
if err != nil {
log.Fatalf("configure_port_layer ERROR: %s", err)
}
// Configure the func invoked if the PL panics or is restarted by vic-init
api.ServerShutdown = func() {
log.Infof("Shutting down port-layer-server")
// Logout the session
if err := sess.Logout(ctx); err != nil {
log.Warnf("unable to log out of session: %s", err)
}
}
// initialize the port layer
if err = portlayer.Init(ctx, sess); err != nil {
log.Fatalf("could not initialize port layer: %s", err)
}
// configure the api here
api.ServeError = errors.ServeError
api.BinConsumer = httpkit.ByteStreamConsumer()
api.JSONConsumer = httpkit.JSONConsumer()
api.JSONProducer = httpkit.JSONProducer()
api.TxtProducer = httpkit.TextProducer()
handlerCtx := &handlers.HandlerContext{
Session: sess,
}
for _, handler := range portlayerhandlers {
handler.Configure(api, handlerCtx)
}
return setupGlobalMiddleware(api.Serve(setupMiddlewares))
}