MCPcopy Create free account
hub / github.com/devld/go-drive / newScriptDrive

Function newScriptDrive

drive/script/utils.go:51–89  ·  view source on GitHub ↗
(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils)

Source from the content-addressed store, hash-verified

49var t = i18n.TPrefix("drive.script.")
50
51func newScriptDrive(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils) (types.IDrive, error) {
52 cfg, e := driveUtils.Data.Load("_script")
53 if e != nil {
54 return nil, e
55 }
56
57 if cfg["_script"] == "" {
58 return nil, err.NewNotAllowedMessageError(i18n.T("drive.not_configured"))
59 }
60
61 poolConfig, e := parsePoolConfig(config["pool"])
62 if e != nil {
63 return nil, err.NewNotAllowedMessageError(i18n.T("drive.script.invalid_pool_config", e.Error()))
64 }
65
66 vm, e := createVm(ctx, driveUtils.Config, cfg["_script"])
67 if e != nil {
68 return nil, e
69 }
70
71 d := &ScriptDrive{
72 baseVM: vm,
73 data: make(map[string]json.RawMessage),
74 }
75
76 vm.Set("setData", s.WrapVmCall(vm, d.setData))
77 vm.Set("getData", s.WrapVmCall(vm, d.getData))
78
79 _, e = vm.Call(ctx, "__driveCreate", s.NewContext(vm, ctx), config, newScriptDriveUtils(driveUtils))
80
81 if e != nil {
82 _ = d.Dispose()
83 return nil, e
84 }
85 vm.Set("selfDrive", s.NewDrive(d))
86 d.pool = s.NewVMPool(vm, poolConfig)
87
88 return d, nil
89}
90
91func initConfig(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils) (*drive_util.DriveInitConfig, error) {
92 selectedScript := config["script"]

Callers

nothing calls this directly

Calls 9

DisposeMethod · 0.95
TFunction · 0.92
parsePoolConfigFunction · 0.85
createVmFunction · 0.85
newScriptDriveUtilsFunction · 0.85
LoadMethod · 0.65
ErrorMethod · 0.65
SetMethod · 0.45
CallMethod · 0.45

Tested by

no test coverage detected