example

module
v0.0.0-...-9508e94 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2020 License: Apache-2.0

README

socket-sysl example

An example socket-sysl app.

Build

make

Implementation

Code generation will produce all the moving parts that you need to build the system, but they still require some simple orchestration.

In your main function, you'll need to call a Serve function to serve the API that the client will use. This requires the construction of a ServiceInterface, which in turn requires the implementation of functions to handle inbound requests.

These functions must implement a generated signature (based on the Sysl spec), and they will be passed helper functions to fire downstream events.

Optionally, you may also want to serve the directory of generated client code on the / path, so that it can be accessed from the same server.

Here is an example with a nil implementation of the ServiceInterface for brevity. See the implementation of example for a more complete demonstration.

package main

import (
	"context"
	"log"
	"net/http"

	chatservice "github.com/orlade/socket-sysl/example/gen/ChatService"
)

func main() {
	// Serve the generated client code from /gen, allowing custom client code to import it.
	http.Handle("/", http.FileServer(http.Dir("web")))
	http.Handle("/gen/", http.StripPrefix("/gen", http.FileServer(http.Dir("gen/ChatClient/"))))

	// Listen and serve the WebSockets API.
	log.Fatal(chatservice.Serve(
		context.Background(),
		func(ctx context.Context, config interface{}) (*chatservice.ServiceInterface, error) {
			return &chatservice.ServiceInterface{
				// Provide implementations here.
				OnChatServiceConnect: nil,
				OnChatClientSendMessage: nil,
			 }, nil
		},
	))
}

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL