-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feature: arbitrary function call from HTTP debug server #85
Comments
The reasons this is being useful:
|
I'm interested in this. Can you introduce the implementation principle and a fast poc about usage? |
@WAY29 Huh thanks for replying. This has been adopted inside my team. Actually, the whole xgo is an open source equivalent of a library we're using from day to day internally. Brief DesignBrief design overview for this functionality:
type InvokeFuncRequest struct {
Pkg string `json:"pkg"`
Func string `json:"func"`
MockData *MockData `json:"mockData"` // this is yet to be discussed
Request json.RawMessage `json:"request"`
}
type InvokeFuncResponse struct {
Response interface{} `json:"response,omitempty"`
Error string `json:"error"`
StackTrace json.RawMessage`json:"stackTrace"`
}
Usage exampleAssuming user have a go project like this: main.go
service/
greet.go
go.mod
func Greet(s string) string {
return "hello " + s
} Typical usage from the user side: $ xgo run --debug-server .
Debug server listens at http://localhost:45000
$ curl localhost:45000/debug/invoke -H 'Content-Type: application/json' --data '{"pkg":"./service", "func":"Greet", "request":{"s":"world"}}'
# Browser will automatically open to show the trace
hello world Real usageThis is an example from our live-canary environment, the live-canary environment is the same as live environment except it's traffic is rather small, about 1/1000 of the live. This tool helps debugging a lot. |
Design brief:
Also allow attach to an existing http server programmatically: package main
import "github.com/xhd2015/xgo/runtime/debug"
func Init(mux *http.ServeMux){
// will add three sub routes: /testing, /testing/listFunc, /testing/invokeFunc
// user can view the debug page when opening http://localhost:PORT/testing
debug.AttachHandlers(mux,"/testing", ...options...)
} |
Xgo's principal when providing tools: no invading the source code, so it becomes completely optional, people can choose to opt in or out any any time they want. No enforcement. |
General input/output follow the function's arg and result name. Special cases are:
|
The problem is: is it possible to call arbitrary function through http without modifying any code?
The answer is: it is possible, and could be a major feature of xgo. Because package
runtime/functab
already have all registered func informations, so we can call them.This could be a standalone usage apart from trap, mock and trace.
The text was updated successfully, but these errors were encountered: