-
-
Notifications
You must be signed in to change notification settings - Fork 272
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
Add basic templating to input #20
Comments
Hello, Thanks for the kind word and the suggestion! I think I understand the general idea and I agree it would be useful. Can you elaborate perhaps and provide a simple example of an ideal usage or something that demonstrates the desired behaviour, just so I can be sure I understand what's required? For example request data (and metadata I suppose too) would be JSON text with template actions, and we would evaluate and fill the data with some predefined standard values before actually parsing JSON and serializing into the payload? ie something like: message HelloRequest {
string name = 1;
int32 request_number = 2;
} And maybe we have
And then Is this something like what you had in mind or am I overthinking it or going in the wrong direction? Thanks! Edit: I guess we would not necessarily need new flags, the standard data and metadata values could always just be parsed and evaluated. |
Yes to all of this, you've got it exactly! (And i agree, i think you should be able to just unconditionally parse and transform). The string i'm passing to |
Hello, I believe we should have this now in 0.7.0. Data and metadata can specify template actions that will be parsed and evaluated at every request. Each request gets a new instance of the data. The available variables / actions are: // call template data
type callTemplateData struct {
RequestNumber int64 // unique incrememnted request number for each request
FullyQualifiedName string // fully-qualified name of the method call
MethodName string // shorter call method name
ServiceName string // the service name
InputName string // name of the input message type
OutputName string // name of the output message type
IsClientStreaming bool // whether this call is client streaming
IsServerStreaming bool // whether this call is server streaming
Timestamp string // timestamp of the call in RFC3339 format
TimestampUnix int64 // timestamp of the call as unix time
} This can be useful to inject variable information into the data or metadata payload for each request, such as timestamp or unique request number. Example: $ ghz -proto ./greeter.proto -call helloworld.Greeter.SayHello -d '{"name":"Joe"}' -m '{"trace_id":"{{.RequestNumber}}","timestamp":"{{.TimestampUnix}}"}' 0.0.0.0:50051 This ends up substituting the template variables with the request number and unix timestamp respectively. Let me know how this works for you. I'll close this issue and if there are any bugs or issues let me know and feel free to create a new issue. |
Hi! This tool is super useful - thanks for putting it together!
It would be very handy, for the particular use case that i have, if it were possible to use standard Go templating to swap in variables related to the state of the current run. In particular, what i was hoping for is a unique numeric identifier that can be templated in for each individual request.
Not sure if it's feasible or not, but it'd be nifty!
The text was updated successfully, but these errors were encountered: