-
Notifications
You must be signed in to change notification settings - Fork 11
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
Find and Invoke Slurm APIs using reflect to avoid version specific code #32
base: main
Are you sure you want to change the base?
Conversation
|
||
// Step 4: Execute the PostNode method with the updated request | ||
postNodeResp := c.helper["PostNodeExecute"].Func.Call([]reflect.Value{ | ||
reflect.ValueOf(c.apiClient.SlurmAPI), |
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's just one corner case, if the input parameters of the PostNodeExecute function (or any other function that we call) change between Slurm versions that this code will not work. Such an API change would be a breaking change though and hopefully will happen in a corner case. If it happens, user would have to manually change this code to pass the new parameters.
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.
yeah, If the API, params or the names change, then this code will have to updated.
} | ||
|
||
if _, found := c.helper[methodPing]; !found { | ||
c.helper[methodPing] = method |
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.
Is it possible to store the function pointer to the method instead of storing the reflect method? That way, when calling the method you can directly call the function pointer instead of calling the function using reflect. Just a minor optimization, if possible.
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.
// Get the function as reflect.Value
funcValue := method.Func
// Convert reflect.Value to an interface and type assert it as a function
// Here, specify the function signature you expect
funcInterface := funcValue.Interface().(func(*MyStruct, string))
// Call the function pointer with the specific arguments
funcInterface(myStruct, "Hello, world!")
If we need to convert the reflect.Method to a function pointer then we need to know the exact API signature and In this case, the parameters are also version specific.
func (a *SlurmAPIService) SlurmV0040PostNodeExecute(r ApiSlurmV0040PostNodeRequest) (*V0040OpenapiResp, *http.Response, error)
func (r ApiSlurmV0040PostNodeRequest) V0040UpdateNodeMsg(v0040UpdateNodeMsg V0040UpdateNodeMsg) ApiSlurmV0040PostNodeRequest
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.
posted few comments, please check
is this ready to land ? |
Hi @powderluv We’ll be holding off on this PR for a bit until the testing team complete their evaluations. Thank you. |
No description provided.