How to use Load method of loader Package

Best K6 code snippet using loader.Load

loader.go

Source:loader.go Github

copy

Full Screen

...27 return nil, fmt.Errorf("unsupported platform %s", runtime.GOOS)28}29type loaderState int30const (31 loaderLoading loaderState = iota32 loaderInitializing33 loaderInitialized34 loaderInjecting35 loaderInjected36 loaderStarting37 loaderStarted38 loaderClosing39 loaderClosed40 loaderFailed41)42func (ls loaderState) String() string {43 switch ls {44 case loaderLoading:45 return "Loading"46 case loaderInitializing:47 return "Initializing"48 case loaderInitialized:49 return "Initialized"50 case loaderInjecting:51 return "Injecting"52 case loaderInjected:53 return "Injected"54 case loaderStarting:55 return "Starting"56 case loaderStarted:57 return "Started"58 case loaderClosing:59 return "Closing"60 case loaderClosed:61 return "Closed"62 case loaderFailed:63 return "Failed"64 default:65 return "Unknown"66 }67}68// PluginLoader keeps track of loaded plugins.69//70// To use:71// 1. Load any desired plugins with Load and LoadDirectory. Preloaded plugins72// will automatically be loaded.73// 2. Call Initialize to run all initialization logic.74// 3. Call Inject to register the plugins.75// 4. Optionally call Start to start plugins.76// 5. Call Close to close all plugins.77type PluginLoader struct {78 state loaderState79 plugins map[string]plugin.Plugin80 started []plugin.Plugin81 config config.Plugins82 repo string83}84// NewPluginLoader creates new plugin loader85func NewPluginLoader(repo string) (*PluginLoader, error) {86 loader := &PluginLoader{plugins: make(map[string]plugin.Plugin, len(preloadPlugins)), repo: repo}87 if repo != "" {88 cfg, err := cserialize.Load(filepath.Join(repo, config.DefaultConfigFile))89 switch err {90 case cserialize.ErrNotInitialized:91 case nil:92 loader.config = cfg.Plugins93 default:94 return nil, err95 }96 }97 for _, v := range preloadPlugins {98 if err := loader.Load(v); err != nil {99 return nil, err100 }101 }102 if err := loader.LoadDirectory(filepath.Join(repo, "plugins")); err != nil {103 return nil, err104 }105 return loader, nil106}107func (loader *PluginLoader) assertState(state loaderState) error {108 if loader.state != state {109 return fmt.Errorf("loader state must be %s, was %s", state, loader.state)110 }111 return nil112}113func (loader *PluginLoader) transition(from, to loaderState) error {114 if err := loader.assertState(from); err != nil {115 return err116 }117 loader.state = to118 return nil119}120// Load loads a plugin into the plugin loader.121func (loader *PluginLoader) Load(pl plugin.Plugin) error {122 if err := loader.assertState(loaderLoading); err != nil {123 return err124 }125 name := pl.Name()126 if ppl, ok := loader.plugins[name]; ok {127 // plugin is already loaded128 return fmt.Errorf(129 "plugin: %s, is duplicated in version: %s, "+130 "while trying to load dynamically: %s",131 name, ppl.Version(), pl.Version())132 }133 if loader.config.Plugins[name].Disabled {134 log.Infof("not loading disabled plugin %s", name)135 return nil136 }137 loader.plugins[name] = pl138 return nil139}140// LoadDirectory loads a directory of plugins into the plugin loader.141func (loader *PluginLoader) LoadDirectory(pluginDir string) error {142 if err := loader.assertState(loaderLoading); err != nil {143 return err144 }145 newPls, err := loadDynamicPlugins(pluginDir)146 if err != nil {147 return err148 }149 for _, pl := range newPls {150 if err := loader.Load(pl); err != nil {151 return err152 }153 }154 return nil155}156func loadDynamicPlugins(pluginDir string) ([]plugin.Plugin, error) {157 _, err := os.Stat(pluginDir)158 if os.IsNotExist(err) {159 return nil, nil160 }161 if err != nil {162 return nil, err163 }164 var plugins []plugin.Plugin165 err = filepath.Walk(pluginDir, func(fi string, info os.FileInfo, err error) error {166 if err != nil {167 return err168 }169 if info.IsDir() {170 if fi != pluginDir {171 log.Warnf("found directory inside plugins directory: %s", fi)172 }173 return nil174 }175 if info.Mode().Perm()&0111 == 0 {176 // file is not executable let's not load it177 // this is to prevent loading plugins from for example non-executable178 // mounts, some /tmp mounts are marked as such for security179 log.Errorf("non-executable file in plugins directory: %s", fi)180 return nil181 }182 if newPlugins, err := loadPluginFunc(fi); err == nil {183 plugins = append(plugins, newPlugins...)184 } else {185 return fmt.Errorf("loading plugin %s: %s", fi, err)186 }187 return nil188 })189 return plugins, err190}191// Initialize initializes all loaded plugins192func (loader *PluginLoader) Initialize() error {193 if err := loader.transition(loaderLoading, loaderInitializing); err != nil {194 return err195 }196 for name, p := range loader.plugins {197 err := p.Init(&plugin.Environment{198 Repo: loader.repo,199 Config: loader.config.Plugins[name].Config,200 })201 if err != nil {202 loader.state = loaderFailed203 return err204 }205 }206 return loader.transition(loaderInitializing, loaderInitialized)207}208// Inject hooks all the plugins into the appropriate subsystems.209func (loader *PluginLoader) Inject() error {210 if err := loader.transition(loaderInitialized, loaderInjecting); err != nil {211 return err212 }213 for _, pl := range loader.plugins {214 if pl, ok := pl.(plugin.PluginIPLD); ok {215 err := injectIPLDPlugin(pl)216 if err != nil {217 loader.state = loaderFailed218 return err219 }220 }221 if pl, ok := pl.(plugin.PluginTracer); ok {222 err := injectTracerPlugin(pl)223 if err != nil {224 loader.state = loaderFailed225 return err226 }227 }228 if pl, ok := pl.(plugin.PluginDatastore); ok {229 err := injectDatastorePlugin(pl)230 if err != nil {231 loader.state = loaderFailed232 return err233 }234 }235 }236 return loader.transition(loaderInjecting, loaderInjected)237}238// Start starts all long-running plugins.239func (loader *PluginLoader) Start(node *core.IpfsNode) error {240 if err := loader.transition(loaderInjected, loaderStarting); err != nil {241 return err242 }243 iface, err := coreapi.NewCoreAPI(node)244 if err != nil {245 return err246 }247 for _, pl := range loader.plugins {248 if pl, ok := pl.(plugin.PluginDaemon); ok {249 err := pl.Start(iface)250 if err != nil {251 _ = loader.Close()252 return err253 }254 loader.started = append(loader.started, pl)255 }256 if pl, ok := pl.(plugin.PluginDaemonInternal); ok {257 err := pl.Start(node)258 if err != nil {259 _ = loader.Close()260 return err261 }262 loader.started = append(loader.started, pl)263 }264 }265 return loader.transition(loaderStarting, loaderStarted)266}267// StopDaemon stops all long-running plugins.268func (loader *PluginLoader) Close() error {269 switch loader.state {270 case loaderClosing, loaderFailed, loaderClosed:271 // nothing to do.272 return nil273 }274 loader.state = loaderClosing275 var errs []string276 started := loader.started277 loader.started = nil278 for _, pl := range started {279 if closer, ok := pl.(io.Closer); ok {280 err := closer.Close()281 if err != nil {282 errs = append(errs, fmt.Sprintf(...

Full Screen

Full Screen

configurator.go

Source:configurator.go Github

copy

Full Screen

...26// Configurator defines the configuration manager.27type Configurator interface {28 // Use registers a custom configuration loader.29 // The last registered configuration loader will have the highest priority.30 Use(Loader) Configurator31 // AddFile adds one or more config files to the current loader.32 // The given parameter need to comply with the search rules supported33 // by filepath.Glob.34 // This method comes from the built-in configuration file loader.35 AddFile(string) error36 // Load loads the given config target.37 // If the given config target does not exist, ErrNotFound is returned.38 // We will give priority to the custom loader. If there is no available config loader39 // or all registered config loaders cannot load the config target (the semantic target40 // does not exist), it will be automatically delegated to the built-in config file loader.41 Load(string) (Item, error)42 // LoadJSON loads the given config target and binds it to the given object as json.43 LoadJSON(string, interface{}) error44 // LoadXML loads the given config target and binds it to the given object as xml.45 LoadXML(string, interface{}) error46 // LoadTOML loads the given config target and binds it to the given object as toml.47 LoadTOML(string, interface{}) error48 // LoadYAML loads the given config target and binds it to the given object as yaml.49 LoadYAML(string, interface{}) error50}51// New creates and returns a new Configurator instance.52func New() Configurator {53 fs := newFileLoader()54 return &configurator{fs: fs, loaders: []Loader{fs}}55}56// The configurator type is a built-in implementation of the Configurator interface.57type configurator struct {58 fs *fileLoader59 loaders []Loader60}61// Use registers a custom configuration loader.62// The last registered configuration loader will have the highest priority.63func (o *configurator) Use(loader Loader) Configurator {64 o.loaders = append(o.loaders, loader)65 return o66}67// AddFile adds one or more config files to the current loader.68// The given parameter need to comply with the search rules supported69// by filepath.Glob.70// This method comes from the built-in configuration file loader.71func (o *configurator) AddFile(pattern string) error {72 return o.fs.AddFile(pattern)73}74// Load loads the given config target.75// If the given config target does not exist, ErrNotFound is returned.76// We will give priority to the custom loader. If there is no available config loader77// or all registered config loaders cannot load the config target (the semantic target78// does not exist), it will be automatically delegated to the built-in config file loader.79func (o *configurator) Load(target string) (Item, error) {80 for k := len(o.loaders) - 1; k >= 0; k-- {81 if item, err := o.loaders[k].Load(target); err == nil {82 if item != nil {83 return item, nil84 }85 } else {86 if err != ErrNotFound {87 return nil, err88 }89 }90 }91 return nil, ErrNotFound92}93// LoadJSON loads the given config target and binds it to the given object as json.94func (o *configurator) LoadJSON(target string, v interface{}) error {95 if item, err := o.Load(target); err != nil {96 return err97 } else {98 return item.JSON(v)99 }100}101// LoadXML loads the given config target and binds it to the given object as xml.102func (o *configurator) LoadXML(target string, v interface{}) error {103 if item, err := o.Load(target); err != nil {104 return err105 } else {106 return item.XML(v)107 }108}109// LoadTOML loads the given config target and binds it to the given object as toml.110func (o *configurator) LoadTOML(target string, v interface{}) error {111 if item, err := o.Load(target); err != nil {112 return err113 } else {114 return item.TOML(v)115 }116}117// LoadYAML loads the given config target and binds it to the given object as yaml.118func (o *configurator) LoadYAML(target string, v interface{}) error {119 if item, err := o.Load(target); err != nil {120 return err121 } else {122 return item.YAML(v)123 }124}...

Full Screen

Full Screen

texture_loader.go

Source:texture_loader.go Github

copy

Full Screen

...14package three15import (16 "github.com/gopherjs/gopherjs/js"17)18// TextureLoader is a class for loading a texture.19type TextureLoader struct{ p *js.Object }20// JSObject returns the underlying *js.Object.21func (t *TextureLoader) JSObject() *js.Object { return t.p }22// TextureLoader returns a TextureLoader JavaScript class.23func (t *Three) TextureLoader() *TextureLoader {24 p := t.ctx.Get("TextureLoader")25 return TextureLoaderFromJSObject(p)26}27// TextureLoaderFromJSObject returns a wrapped TextureLoader JavaScript class.28func TextureLoaderFromJSObject(p *js.Object) *TextureLoader {29 return &TextureLoader{p: p}30}31// NewTextureLoader creates a new TextureLoader object.32//33// manager — The loadingManager for the loader to use. Default is THREE.DefaultLoadingManager.34func (t *Three) NewTextureLoader() *TextureLoader {35 p := t.ctx.Get("TextureLoader").New()36 return TextureLoaderFromJSObject(p)37}38// TextureLoadFunc is a callback function called by Load.39type TextureLoadFunc func(geometry *Geometry, materials []*Material)40// onTextureLoadWrapperFunc wraps the geometry and materials to a typed LoadFunc.41func onTextureLoadWrapperFunc(onLoad TextureLoadFunc) func(geometry, materials *js.Object) {42 return func(geom, materialArray *js.Object) {43 var materials []*Material44 if materialArray != nil && materialArray != js.Undefined {45 for i := 0; i < materialArray.Length(); i++ {46 materials = append(materials, MaterialFromJSObject(materialArray.Index(i)))47 }48 }49 onLoad(GeometryFromJSObject(geom), materials)50 }51}52// Load begins loading from url and passes the loaded texture to onLoad.53//54// url — required55// onLoad — Will be called when load completes. The argument will be the loaded texture.56// onProgress — Will be called while load progresses. The argument will be the XmlHttpRequest instance, that contain .total and .loaded bytes.57// onError — Will be called when load errors.58func (t *TextureLoader) Load(url string, onLoad TextureLoadFunc, onProgress, onError interface{}) *Texture {59 var onLoadWrapper func(geometry, materials *js.Object)60 if onLoad != nil {61 onLoadWrapper = onTextureLoadWrapperFunc(onLoad)62 }63 var p *js.Object64 switch {65 case onLoad != nil && onProgress != nil && onError != nil:66 p = t.p.Call("load", url, onLoadWrapper, onProgress, onError)67 case onLoad != nil && onProgress != nil:68 p = t.p.Call("load", url, onLoadWrapper, onProgress)69 case onLoad != nil:70 p = t.p.Call("load", url, onLoadWrapper)71 default:72 p = t.p.Call("load", url)73 }74 return TextureFromJSObject(p)75}76// SetCrossOrigin TODO description.77func (t *TextureLoader) SetCrossOrigin(value string) *TextureLoader {78 t.p.Call("setCrossOrigin", value)79 return t80}81// SetPath TODO description.82func (t *TextureLoader) SetPath(value float64) *TextureLoader {83 t.p.Call("setPath", value)84 return t85}...

Full Screen

Full Screen

Load

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 loader.Load()5}6import (7func main() {8 fmt.Println("Hello World")9 loader.Load()10}11import "fmt"12func Load() {13 fmt.Println("Loader is loading")14}

Full Screen

Full Screen

Load

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Loading...")4 loader.Load()5}6import (7func Load() {8 fmt.Println("Loaded")9}10import (11func TestLoad(t *testing.T) {12 fmt.Println("Testing...")13 Load()14}15import (16func BenchmarkLoad(b *testing.B) {17 for i := 0; i < b.N; i++ {18 Load()19 }20}21import (22func ExampleLoad() {23 fmt.Println("Example...")24 Load()25}26import (27func TestXXX(t *testing.T) {28 fmt.Println("Testing...")29 Load()30}31import (32func TestYYY(t *testing.T) {33 fmt.Println("Testing...")34 Load()35}36func TestXxx(*testing.T)37func BenchmarkXxx(*testing.B)

Full Screen

Full Screen

Load

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 obj := loader.Load("1.txt")4 fmt.Println(obj)5}6{1 2 3 4 5 6 7 8 9 10}

Full Screen

Full Screen

Load

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 l := loader.NewLoader()4 l.Load()5 fmt.Println(l.Data)6}7import (8type Loader struct {9}10func NewLoader() *Loader {11 return &Loader{}12}13func (l *Loader) Load() {14 l.Data, _ = ioutil.ReadFile("data.txt")15}16import (17func main() {18 l := loader.NewLoader()19 l.Load()20 fmt.Println(string(l.Data))21}22import (23func main() {24 l := loader.NewCustomLoader()25 l.Load()26 fmt.Println(l.Data)27}28import (29type Loader struct {30}31func NewLoader() *Loader {32 return &Loader{}33}34func (l *Loader) Load

Full Screen

Full Screen

Load

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 loader.Load("1.class")4 loader.Load("2.class")5 loader.Load("3.class")6 loader.Load("4.class")7 loader.Load("5.class")8 loader.Load("6.class")9 loader.Load("7.class")10 loader.Load("8.class")11 loader.Load("9.class")12 loader.Load("10.class")13 loader.Load("11.class")14 loader.Load("12.class")15 loader.Load("13.class")16 loader.Load("14.class")17 loader.Load("15.class")18 loader.Load("16.class")19 loader.Load("17.class")20 loader.Load("18.class")21 loader.Load("19.class")22 loader.Load("20.class")23 loader.Load("21.class")24 loader.Load("22.class")25 loader.Load("23.class")26 loader.Load("24.class")27 loader.Load("25.class")28 loader.Load("26.class")29 loader.Load("27.class")30 loader.Load("28.class")31 loader.Load("29.class")32 loader.Load("30.class")33 loader.Load("31.class")34 loader.Load("32.class")35 loader.Load("33.class")36 loader.Load("34.class")37 loader.Load("35.class")38 loader.Load("36.class")39 loader.Load("37.class")

Full Screen

Full Screen

Load

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data := loader.Load("data.csv", ",")4 for i := 0; i < len(data); i++ {5 fmt.Println(data[i])6 }7}

Full Screen

Full Screen

Load

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config := loader.Load("config.yaml", "yaml")4 for key, value := range config {5 fmt.Println(key, ":", value)6 }7}8import (9func main() {10 config := loader.Load("config.toml", "toml")11 for key, value := range config {12 fmt.Println(key, ":", value)13 }14}15import (16func main() {17 config := loader.Load("config.json", "json")18 for key, value := range config {19 fmt.Println(key, ":", value)20 }21}22{23}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful