github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/debug/instance.go (about)

     1  package debug
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/base/types"
     7  	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
     8  	"github.com/machinefi/w3bstream/pkg/modules/vm"
     9  )
    10  
    11  // FetchInstances fetch instances states in memory
    12  type FetchInstances struct {
    13  	httpx.MethodGet
    14  }
    15  
    16  func (r *FetchInstances) Path() string { return "/instances" }
    17  
    18  func (r *FetchInstances) Output(ctx context.Context) (interface{}, error) {
    19  	return vm.FetchInstances(), nil
    20  }
    21  
    22  type GetInstance struct {
    23  	httpx.MethodGet
    24  	ID types.SFID `in:"path" name:"id"`
    25  }
    26  
    27  func (r *GetInstance) Path() string {
    28  	return "/instance/:id"
    29  }
    30  
    31  func (r *GetInstance) Output(ctx context.Context) (interface{}, error) {
    32  	state, _ := vm.GetInstanceState(r.ID)
    33  	return state, nil
    34  }