github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/pluginenv/options.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package pluginenv
     5  
     6  import (
     7  	"github.com/mattermost/mattermost-server/model"
     8  	"github.com/mattermost/mattermost-server/plugin"
     9  	"github.com/mattermost/mattermost-server/plugin/rpcplugin"
    10  	"github.com/mattermost/mattermost-server/plugin/rpcplugin/sandbox"
    11  )
    12  
    13  // APIProvider specifies a function that provides an API implementation to each plugin.
    14  func APIProvider(provider APIProviderFunc) Option {
    15  	return func(env *Environment) {
    16  		env.apiProvider = provider
    17  	}
    18  }
    19  
    20  // SupervisorProvider specifies a function that provides a Supervisor implementation to each plugin.
    21  // If unspecified, DefaultSupervisorProvider is used.
    22  func SupervisorProvider(provider SupervisorProviderFunc) Option {
    23  	return func(env *Environment) {
    24  		env.supervisorProvider = provider
    25  	}
    26  }
    27  
    28  // SearchPath specifies a directory that contains the plugins to launch.
    29  func SearchPath(path string) Option {
    30  	return func(env *Environment) {
    31  		env.searchPath = path
    32  	}
    33  }
    34  
    35  // WebappPath specifies the static directory serving the webapp.
    36  func WebappPath(path string) Option {
    37  	return func(env *Environment) {
    38  		env.webappPath = path
    39  	}
    40  }
    41  
    42  // DefaultSupervisorProvider chooses a supervisor based on the system and the plugin's manifest
    43  // contents. E.g. if the manifest specifies a backend executable, it will be given an
    44  // rpcplugin.Supervisor.
    45  func DefaultSupervisorProvider(bundle *model.BundleInfo) (plugin.Supervisor, error) {
    46  	if err := sandbox.CheckSupport(); err == nil {
    47  		return sandbox.SupervisorProvider(bundle)
    48  	}
    49  	return rpcplugin.SupervisorProvider(bundle)
    50  }