Exemple #1
0
func foo(c *pakt.Context) (interface{}, error) {
	// Create a dummy value.
	data := struct {
		A, B string
		C    int
	}{}

	// Decode the received data from the peer to the dummy value.
	err := c.Decode(&data)
	if err != nil {
		// The remote peer would get this error.
		return nil, err
	}

	// Log.
	log.Printf("received data from client: %+v", data)

	// Just send the data back to the client.
	return data, nil
}
Exemple #2
0
func bar(c *pakt.Context) (interface{}, error) {
	// Decode the received data from the peer to the dummy value.
	var data string
	err := c.Decode(&data)
	if err != nil {
		// The remote peer would get this error.
		return nil, err
	}

	// Log.
	log.Printf("received data from server: %+v", data)

	// Close the socket and exit the application after a short timeout.
	go func() {
		time.Sleep(500 * time.Millisecond)
		c.Socket().Close()
	}()

	// Just send the data back to the client.
	return data, nil
}