-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat : add script routing functionality #2669
Conversation
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
if err != nil { | ||
return nil, err | ||
} | ||
result := make([]protocol.Invoker, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map add cap
Signed-off-by: YarBor <[email protected]>
add comment to jsInstance Signed-off-by: YarBor <[email protected]>
package instance | ||
|
||
import ( | ||
"dubbo.apache.org/dubbo-go/v3/protocol" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what the problem is, I ran go fmt and it doesn't work, looks the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what the problem is, I ran go fmt and it doesn't work, looks the same.
Go fmt will not change the order of the import, it will only format locks and spaces. You can use goimports instead,https://pkg.go.dev/golang.org/x/tools/cmd/goimports
Generally speaking, the standard import format is:
import (
go standard packages (sorted alphabetically)
(space)
Three-party packages (sorted alphabetically)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们 dubbogo 有自己的 import format 工具 https://github.com/dubbogo/tools/tree/master/cmd/imports-formatter
编译出二进制,在项目根目录下执行一次,就可以 format 整个工程的 import 顺序。比你们找的这个工具高级多了。
用好前人积累的工具。
) | ||
|
||
type ScriptInstances interface { | ||
RunScript(rawScript string, invokers []protocol.Invoker, invocation protocol.Invocation) ([]protocol.Invoker, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ScriptInstances struct 里面已经有 Script 了,Run() 这个函数名就 ok 了
factory[tpName] = instance | ||
} | ||
|
||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init 函数挪到 struct 定义下面
package instance | ||
|
||
import ( | ||
"dubbo.apache.org/dubbo-go/v3/protocol" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformat
} | ||
} | ||
|
||
func (i *jsInstances) RunScript(_ string, invokers []protocol.Invoker, invocation protocol.Invocation) ([]protocol.Invoker, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成 Run
package script | ||
|
||
import ( | ||
ins "dubbo.apache.org/dubbo-go/v3/cluster/router/script/instance" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformat
The current problem is that the parameter passed in is a reference. When the URL is modified, the original copy will be modified, which will lead to undefined behavior. Signed-off-by: YarBor <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2669 +/- ##
==========================================
- Coverage 47.38% 47.21% -0.17%
==========================================
Files 341 343 +2
Lines 25122 25286 +164
==========================================
+ Hits 11904 11940 +36
- Misses 12074 12188 +114
- Partials 1144 1158 +14 ☔ View full report in Codecov by Sentry. |
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
|
…nces. Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
} | ||
i.pgLock.Unlock() | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lock used here is a bit strange, try the following steps:
- check without lock
- if exists, return
- if not exists, get the lock
3.1 check again
3.2 if exists return
3.3 if not exists compile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I previously thought that "compiling" was a time-consuming operation that was not suitable to be performed while occupying a lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will rewite it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I thought the following lock was not necessary, it seems to be necessary in this case.
i.pgLock.RLock()
pg, ok = i.program[rawScript]
i.pgLock.RUnlock()
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Signed-off-by: YarBor <[email protected]>
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
JS Standard
Parameter methods are mapped by the passed in type.
The called method first letter is capitalized (does not comply with js specifications).
e.g.
invokers[i].GetURL().SetParam("testKey","testValue")
e.g.
invokers[i].GetURL().Port
Important
In the js-support.
invokers, invocation, context
,The following methods are not allowed.
invokers.Invoke(...)
invokers.Destroy()
invokers.IsAvailable()
will always return truefor example:
for example: