update for gojs
This commit is contained in:
		
							parent
							
								
									715de5e442
								
							
						
					
					
						commit
						57db518ef9
					
				
							
								
								
									
										8
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								go.mod
									
									
									
									
									
								
							@ -1,14 +1,14 @@
 | 
			
		||||
module apigo.cc/gojs/service
 | 
			
		||||
 | 
			
		||||
go 1.23.0
 | 
			
		||||
go 1.24
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	apigo.cc/gojs v0.0.23
 | 
			
		||||
	apigo.cc/gojs v0.0.25
 | 
			
		||||
	apigo.cc/gojs/console v0.0.2
 | 
			
		||||
	apigo.cc/gojs/file v0.0.4
 | 
			
		||||
	apigo.cc/gojs/file v0.0.5
 | 
			
		||||
	apigo.cc/gojs/http v0.0.7
 | 
			
		||||
	apigo.cc/gojs/runtime v0.0.3
 | 
			
		||||
	apigo.cc/gojs/task v0.0.4
 | 
			
		||||
	apigo.cc/gojs/task v0.0.6
 | 
			
		||||
	apigo.cc/gojs/util v0.0.13
 | 
			
		||||
	github.com/gorilla/websocket v1.5.3
 | 
			
		||||
	github.com/ssgo/config v1.7.9
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										26
									
								
								service.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								service.go
									
									
									
									
									
								
							@ -89,7 +89,7 @@ var configed = false
 | 
			
		||||
func initConfig(opt *gojs.Obj, logger *log.Logger, vm *goja.Runtime) {
 | 
			
		||||
	configed = true
 | 
			
		||||
	s.InitConfig()
 | 
			
		||||
	if startPath, ok := vm.GoData["startPath"]; ok {
 | 
			
		||||
	if startPath := vm.GetData("startPath"); startPath != nil {
 | 
			
		||||
		s.SetWorkPath(u.String(startPath))
 | 
			
		||||
	}
 | 
			
		||||
	// 处理配置
 | 
			
		||||
@ -266,10 +266,10 @@ func init() {
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// 处理Watch
 | 
			
		||||
			if vm.GoData["inWatch"] == true {
 | 
			
		||||
			if inWatch := vm.GetData("inWatch"); inWatch != nil && inWatch.(bool) {
 | 
			
		||||
				onWatchConn := map[string]*websocket.Conn{}
 | 
			
		||||
				onWatchLock := sync.Mutex{}
 | 
			
		||||
				vm.GoData["onWatch"] = func(filename string) {
 | 
			
		||||
				vm.SetData("onWatch", func(filename string) {
 | 
			
		||||
					onWatchLock.Lock()
 | 
			
		||||
					defer onWatchLock.Unlock()
 | 
			
		||||
					for id, conn := range onWatchConn {
 | 
			
		||||
@ -277,7 +277,7 @@ func init() {
 | 
			
		||||
							delete(onWatchConn, id)
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				})
 | 
			
		||||
				s.AddShutdownHook(func() {
 | 
			
		||||
					for _, conn := range onWatchConn {
 | 
			
		||||
						conn.Close()
 | 
			
		||||
@ -497,7 +497,7 @@ func init() {
 | 
			
		||||
				for i, require := range requiresObj {
 | 
			
		||||
					requires[i] = u.String(require)
 | 
			
		||||
				}
 | 
			
		||||
				vm.GoData[fmt.Sprint("REQUIRE_"+host, method, path)] = requires
 | 
			
		||||
				vm.SetData(fmt.Sprint("REQUIRE_"+host, method, path), requires)
 | 
			
		||||
			}
 | 
			
		||||
			if verifiesObj := o.Obj("verifies"); verifiesObj != nil {
 | 
			
		||||
				verifiesSet := map[string]func(any, *goja.Runtime) bool{}
 | 
			
		||||
@ -531,7 +531,7 @@ func init() {
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				vm.GoData[fmt.Sprint("VERIFY_"+host, method, path)] = verifiesSet
 | 
			
		||||
				vm.SetData(fmt.Sprint("VERIFY_"+host, method, path), verifiesSet)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			opt := s.WebServiceOptions{
 | 
			
		||||
@ -542,18 +542,18 @@ func init() {
 | 
			
		||||
				Limiters: usedLimiters,
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			startFile := u.String(vm.GoData["startFile"])
 | 
			
		||||
			startFile := u.String(vm.GetData("startFile"))
 | 
			
		||||
			poolsLock.RLock()
 | 
			
		||||
			poolExist := poolExists[startFile]
 | 
			
		||||
			poolsLock.RUnlock()
 | 
			
		||||
			if poolExist {
 | 
			
		||||
				// 从对象调用(支持并发)
 | 
			
		||||
				actionKey := "REGISTER_" + host + method + path
 | 
			
		||||
				vm.GoData[actionKey] = action
 | 
			
		||||
				vm.GoData[actionKey+"This"] = args.This
 | 
			
		||||
				vm.SetData(actionKey, action)
 | 
			
		||||
				vm.SetData(actionKey+"This", args.This)
 | 
			
		||||
				if method == "WS" {
 | 
			
		||||
					vm.GoData[actionKey+"onMessage"] = o.Func("onMessage")
 | 
			
		||||
					vm.GoData[actionKey+"onClose"] = o.Func("onClose")
 | 
			
		||||
					vm.SetData(actionKey+"onMessage", o.Func("onMessage"))
 | 
			
		||||
					vm.SetData(actionKey+"onClose", o.Func("onClose"))
 | 
			
		||||
				}
 | 
			
		||||
				poolsLock.Lock()
 | 
			
		||||
				actionRegistered := poolActionRegistered[actionKey]
 | 
			
		||||
@ -871,10 +871,10 @@ func runAction(action goja.Callable, vm *goja.Runtime, thisArg goja.Value, args
 | 
			
		||||
	defer vm.CallbackLocker.Unlock()
 | 
			
		||||
 | 
			
		||||
	// 验证请求参数的有效性
 | 
			
		||||
	if verifies, ok := vm.GoData["VERIFY_"+u.String(request.Get("registerTag"))].(map[string]func(any, *goja.Runtime) bool); ok {
 | 
			
		||||
	if verifies, ok := vm.GetData("VERIFY_" + u.String(request.Get("registerTag"))).(map[string]func(any, *goja.Runtime) bool); ok {
 | 
			
		||||
		failedFields := make([]string, 0)
 | 
			
		||||
		// 检查必填字段
 | 
			
		||||
		if requires, ok := vm.GoData["REQUIRE_"+u.String(request.Get("registerTag"))].([]string); ok {
 | 
			
		||||
		if requires, ok := vm.GetData("REQUIRE_" + u.String(request.Get("registerTag"))).([]string); ok {
 | 
			
		||||
			for _, requireField := range requires {
 | 
			
		||||
				if _, ok := args[requireField]; !ok {
 | 
			
		||||
					failedFields = append(failedFields, requireField)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user