= yaml = title: Playground example - Fortune status: draft sort: 05 = yaml =
(Taken from: https://docs.google.com/a/google.com/document/d/189JXetSjHc980LuSl88Y7_VtG4tyZ0iggILEWD2_JKc/edit#)
This is an example of a simple Fortune application in Vanadium. It has two parts, a client and a server. The client can either request a fortune from the server, or add a new fortune to the server.
The remote interface exposed by the server is defined in a .vdl file. Here is an example Fortune service:
package fortune type Fortune interface { // Returns a random fortune. Get() (Fortune string | error) // Adds a fortune to the set used by Get(). Add(Fortune string) error }
The services exposes two methods - Get
which returns a random fortune string from a fortune repository held by the service, and Add
that adds the provided fortune string to the repository.
Inside the main()
function, we create a new Vanadium runtime with r := rt.New()
, and use the runtime to create a new server with r.NewServer()
.
We use the fortune
package generated from the vdl along with the fortuned implementation to create a new fortune server.
The server listens for a tcp connection on localhost, and mounts itself on the mounttable with the name “fortune”.