func (receiver *EphemeralScript) Create(_ extension.Model, db *gorm.DB, _ gin.Params, _ url.Values, inputContainer interface{}) (interface{}, error) {
	ephemeralScript := NewEphemeralScript()
	if err := mapstructutilpkg.GetUtility().MapToStruct(inputContainer, ephemeralScript); err != nil {
		logging.Logger().Debug(err.Error())
		return nil, err
	}
	nameEphemeralScriptMapMutex.Lock()
	defer nameEphemeralScriptMapMutex.Unlock()
	if _, exists := nameEphemeralScriptMap[ephemeralScript.Name]; exists {
		logging.Logger().Debugf("ephemeralScript %s already exists", ephemeralScript.Name)
		return nil, fmt.Errorf("ephemeralScript %s already exists", ephemeralScript.Name)
	}
	if _, err := parser.ParseFile(nil, "", fmt.Sprintf(`(function() { %s })();`, ephemeralScript.ScriptContent), 0); err != nil {
		if _, ok := err.(parser.ErrorList); ok {
			logging.Logger().Debugf("parse errors have occured during parsing %s: ", ephemeralScript.Name)
			errList := err.(parser.ErrorList)
			for _, err := range errList {
				logging.Logger().Debugf("%v", err.Error())
			}
			return nil, fmt.Errorf("parse errors have occured during parsing %s: %v", ephemeralScript.Name, err.Error())
		}
		logging.Logger().Debugf("a parse error has occured during parsing %s: %v", ephemeralScript.Name, err.Error())
		return nil, fmt.Errorf("a parse error has occured during parsing %s: %v", ephemeralScript.Name, err.Error())
	}
	ephemeralScript.Status = ephemeralScriptStatusCreated
	ephemeralScript.ReturnValue = ""
	ephemeralScript.Error = ""
	ephemeralScript.StartedAt = ""
	ephemeralScript.FinishedAt = ""
	ephemeralScript.vm = otto.New()
	ephemeralScript.vm.Interrupt = make(chan func(), 1)
	nameEphemeralScriptMap[ephemeralScript.Name] = ephemeralScript
	return ephemeralScript, nil
}
Create corresponds HTTP POST message and handles a request for multi resource to create a new information
package model
import (
	"errors"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/jinzhu/gorm"
	"github.com/qb0C80aE/clay/extension"
	"github.com/qb0C80aE/clay/logging"
	mapstructutilpkg "github.com/qb0C80aE/clay/util/mapstruct"
	"github.com/robertkrimen/otto"
	"github.com/robertkrimen/otto/parser"
	"net/url"
	"sort"
	"sync"
)
var nameEphemeralScriptMap = map[string]*EphemeralScript{}
var nameEphemeralScriptMapMutex = new(sync.Mutex)
const (
	ephemeralScriptStatusCreated  = "created"
	ephemeralScriptStatusRunning  = "running"
	ephemeralScriptStatusFinished = "finished"
)
type EphemeralScript struct {
	Base
	Name          string `json:"name" yaml:"name" form:"name" gorm:"primary_key" validate:"required"`
	Description   string `json:"description" yaml:"description" form:"description"`
	ScriptContent string `json:"script_content" yaml:"script_content" form:"script_content" sql:"type:text"`
	Status        string `json:"status" yaml:"status"`
	ReturnValue   string `json:"return_value" yaml:"return_value" sql:"type:text"`
	Error         string `json:"error" yaml:"error" sql:"type:text"`
	StartedAt     string `json:"started_at" yaml:"started_at"`
	FinishedAt    string `json:"finished_at" yaml:"finished_at"`
	vm            *otto.Otto
}
func NewEphemeralScript() *EphemeralScript {
	return &EphemeralScript{}
}
func (receiver *EphemeralScript) GetContainerForMigration() (interface{}, error) {
	return nil, nil
}
func (receiver *EphemeralScript) GetSingle(model extension.Model, db *gorm.DB, parameters gin.Params, _ url.Values, queryFields string) (interface{}, error) {
	modelKey, err := model.GetModelKey(model, "")
	if err != nil {
		logging.Logger().Debug(err.Error())
		return nil, err
	}
	name := parameters.ByName(modelKey.KeyParameter)
	result, exists := nameEphemeralScriptMap[name]
	if !exists {
		logging.Logger().Debug(errors.New("record not found"))
		return nil, errors.New("record not found")
	}
	return result, nil
}
func (receiver *EphemeralScript) GetMulti(_ extension.Model, db *gorm.DB, _ gin.Params, _ url.Values, queryFields string) (interface{}, error) {
	nameEphemeralScriptMapMutex.Lock()
	defer nameEphemeralScriptMapMutex.Unlock()
	keyList := make([]string, 0, len(nameEphemeralScriptMap))
	for key := range nameEphemeralScriptMap {
		keyList = append(keyList, key)
	}
	sort.Strings(keyList)
	ephemeralScriptList := make([]*EphemeralScript, len(nameEphemeralScriptMap))
	for i, key := range keyList {
		ephemeralScriptList[i] = nameEphemeralScriptMap[key]
	}
	return ephemeralScriptList, nil
}