Merge branch 'development' of github.com:freeflowuniverse/herolib into development
* 'development' of github.com:freeflowuniverse/herolib: feat: Improve ZinitClient and JSON-RPC client
This commit is contained in:
@@ -54,7 +54,7 @@ pub fn (mut c ZinitClient) discover() !string {
|
||||
request := jsonrpc.new_request_generic('rpc.discover', []string{})
|
||||
|
||||
// Send the request and get the raw response
|
||||
raw_response := c.rpc_client.rpc_client.transport.send(request.encode(), jsonrpc.SendParams{
|
||||
raw_response := c.rpc_client.transport.send(request.encode(), jsonrpc.SendParams{
|
||||
timeout: 5 // Increase timeout to 5 seconds
|
||||
})!
|
||||
|
||||
@@ -142,7 +142,7 @@ pub:
|
||||
// - signal: The signal to send (e.g., SIGTERM, SIGKILL)
|
||||
pub fn (mut c ZinitClient) kill(name string, signal string) ! {
|
||||
params := KillParams{
|
||||
name: name
|
||||
name: name
|
||||
signal: signal
|
||||
}
|
||||
|
||||
@@ -211,11 +211,11 @@ pub fn (mut c ZinitClient) get_all_logs() ![]string {
|
||||
// ServiceConfig represents the configuration for a service
|
||||
pub struct ServiceConfig {
|
||||
pub:
|
||||
exec string
|
||||
oneshot bool
|
||||
after []string
|
||||
log string
|
||||
env map[string]string
|
||||
exec string
|
||||
oneshot bool
|
||||
after []string
|
||||
log string
|
||||
env map[string]string
|
||||
shutdown_timeout int
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ pub:
|
||||
// - A string indicating the result of the operation
|
||||
pub fn (mut c ZinitClient) create_service(name string, config ServiceConfig) !string {
|
||||
params := CreateServiceParams{
|
||||
name: name
|
||||
name: name
|
||||
content: config
|
||||
}
|
||||
|
||||
@@ -255,11 +255,11 @@ pub fn (mut c ZinitClient) delete_service(name string) !string {
|
||||
// ServiceConfigResponse represents the response from get_service
|
||||
pub struct ServiceConfigResponse {
|
||||
pub:
|
||||
exec string
|
||||
oneshot bool
|
||||
after []string
|
||||
log string
|
||||
env map[string]string
|
||||
exec string
|
||||
oneshot bool
|
||||
after []string
|
||||
log string
|
||||
env map[string]string
|
||||
shutdown_timeout int
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module jsonrpc
|
||||
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
// IRPCTransportClient defines the interface for transport mechanisms used by the JSON-RPC client.
|
||||
@@ -27,11 +28,10 @@ pub:
|
||||
retry int
|
||||
}
|
||||
|
||||
|
||||
// Client implements a JSON-RPC 2.0 client that can send requests and process responses.
|
||||
// It uses a pluggable transport layer that implements the IRPCTransportClient interface.
|
||||
pub struct Client {
|
||||
mut:
|
||||
pub mut:
|
||||
// The transport implementation used to send requests and receive responses
|
||||
transport IRPCTransportClient
|
||||
}
|
||||
@@ -44,13 +44,12 @@ mut:
|
||||
// Returns:
|
||||
// - A pointer to a new Client instance
|
||||
pub fn new_client(transport IRPCTransportClient) &Client {
|
||||
mut cl:=Client{
|
||||
mut cl := Client{
|
||||
transport: transport
|
||||
}
|
||||
return &cl
|
||||
}
|
||||
|
||||
|
||||
// send sends a JSON-RPC request with parameters of type T and expects a response with result of type D.
|
||||
// This method handles the full request-response cycle including validation and error handling.
|
||||
//
|
||||
@@ -69,7 +68,6 @@ pub fn (mut c Client) send[T, D](request RequestGeneric[T], params SendParams) !
|
||||
console.print_debug('Sending request: ${request.encode()}')
|
||||
response_json := c.transport.send(request.encode(), params)!
|
||||
|
||||
|
||||
// Decode the response JSON into a strongly-typed response object
|
||||
response := decode_response_generic[D](response_json) or {
|
||||
return error('Unable to decode response.\n- Response: ${response_json}\n- Error: ${err}')
|
||||
|
||||
Reference in New Issue
Block a user