The Client provides several methods to send commands (sentences) to a RouterOS device and wait for the response. You can use variadic methods for simple commands or slice-based methods for pre-constructed argument lists.
Synchronous Methods
Run(sentences ...string) (*Reply, error): A convenience method that accepts a variadic list of strings representing the command parts.RunArgs(sentences []string) (*Reply, error): Sends a slice of strings and waits for the reply using context.Background().RunContext(ctx context.Context, sentences ...string) (*Reply, error): Sends a variadic list of strings while respecting the provided context.Context for cancellation or timeouts.RunArgsContext(ctx context.Context, sentences []string) (*Reply, error): Sends a slice of strings while respecting the provided context.Context.
If the client is not in asynchronous mode, these methods will block until the RouterOS device returns a Done signal or an error occurs.
// Using variadic Run
reply, err := client.Run("/ip", "address", "print")
// Using RunArgsContext with a timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
sentences := []string{"/ip", "address", "print"}
reply, err := client.RunArgsContext(ctx, sentences)