Almost Good RPC Over WebSockets
AGROWS is a framework that allows you to easily execute server-side functions from a WebAssembly (WASM) client using WebSockets. It enables you to define your RPC functions in Golang without worrying about the complexities of client-server communication.
- Go 1.22.1 or higher
-
Clone the repository:
git clone https://github.com/codeupdateandmodificationsystem/agrows.git cd agrows -
Install dependencies:
go mod download
Define your RPC functions in a Go file. Here is an example:
package functions
import "context"
// SayHello sends a greeting
func SayHello(name string) string {
return "Hello, " + name
}
// CrazyMath performs some math operations
type CalcInput struct {
A int
B int
}
func CrazyMath(inp CalcInput) string {
return fmt.Sprintf("Result: %d", inp.A+inp.B)
}- Generate the client and server code using the
agrowsCLI:
agrows --input internal/functions/functions.go client agrows --input internal/functions/functions.go server- The generated code will be saved as
agrows_client_functions.goandagrows_server_functions.go.
To start the server, run:
go run cmd/main.goAGROWS provides the following CLI options:
--input: Specifies the input file containing the RPC functions (required).--output: Specifies the output file for the generated code (default:agrows_<server|client>_<input_file>).--dbg: Enables debug logging.--compress: Enables compression in the protocol.
The usage example repository demonstrates a full application using AGROWS, Templ, TypeScript, and HTMX. It includes development features like auto-reloading. To explore the example:
- Clone the usage example repository:
git clone https://github.com/codeupdateandmodificationsystem/agrows-usage-example.git cd agrows-usage-example- Run the example:
just watchContributions are welcome! Please fork the repository and submit a pull request.
AGROWS is released under the GPL license. See LICENSE for details.