github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/deploy/del.go (about) 1 package deploy 2 3 import ( 4 "context" 5 6 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/middleware" 7 "github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx" 8 "github.com/machinefi/w3bstream/pkg/modules/deploy" 9 "github.com/machinefi/w3bstream/pkg/types" 10 ) 11 12 // RemoveInstance remove instance by instance id 13 type RemoveInstance struct { 14 httpx.MethodDelete 15 InstanceID types.SFID `in:"path" name:"instanceID"` 16 } 17 18 func (r *RemoveInstance) Path() string { return "/data/:instanceID" } 19 20 func (r *RemoveInstance) Output(ctx context.Context) (interface{}, error) { 21 ctx, err := middleware.MustCurrentAccountFromContext(ctx). 22 WithInstanceContextBySFID(ctx, r.InstanceID) 23 if err != nil { 24 return nil, err 25 } 26 27 return nil, deploy.RemoveBySFID(ctx, r.InstanceID) 28 } 29 30 // BatchRemoveInstance remove instances by condition 31 type BatchRemoveInstance struct { 32 httpx.MethodDelete 33 deploy.CondArgs 34 } 35 36 func (r *BatchRemoveInstance) Path() string { return "" } 37 38 func (r *BatchRemoveInstance) Output(ctx context.Context) (interface{}, error) { 39 ctx, err := middleware.MustCurrentAccountFromContext(ctx). 40 WithProjectContextByName(ctx, middleware.MustProjectName(ctx)) 41 if err != nil { 42 return nil, err 43 } 44 r.CondArgs.ProjectID = types.MustProjectFromContext(ctx).ProjectID 45 return nil, deploy.Remove(ctx, &r.CondArgs) 46 }