From 45ddafc744aca8fa443c8a88ecf1e4341e88ff2d Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Sun, 22 Aug 2021 12:41:17 -0700 Subject: [PATCH] Updated network driver README to contain full quickstart Updated the network driver README to include a full quickstart program that can be run. This program also checks for errors starting the server, which is a crucial check I feel the examples need. The README now provides a quick curl command to ensure your network driver is running. Signed-off-by: ClaytonNorthey92 --- network/README.md | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/network/README.md b/network/README.md index 5c28fb1..2013218 100644 --- a/network/README.md +++ b/network/README.md @@ -12,18 +12,43 @@ This library is designed to be integrated in your program. 4. On Windows, docker daemon data dir must be provided for ServeTCP and ServeWindows functions. On Unix, this parameter is ignored. -### Example using TCP sockets: +## Quickstart (using TCP sockets) +Here is a minimalist example to start the network driver on your host machine. ```go - import "github.com/docker/go-plugins-helpers/network" +package main + +import ( + "fmt" + "os" + + "github.com/docker/go-plugins-helpers/network" +) +type MyNetworkDriver struct { + network.Driver +} + +func main() { d := MyNetworkDriver{} - h := network.NewHandler(d) - h.ServeTCP("test_network", ":8080", "") - // on windows: - h.ServeTCP("test_network", ":8080", WindowsDefaultDaemonRootDir()) + h := network.NewHandler(&d) + err := h.ServeTCP("test_network", "localhost:8080", "", nil) + if err != nil { + fmt.Printf("error occurred: %s\n", err.Error()) + os.Exit(1) + } +} + ``` +You can test this out by the following: +```bash +$ curl http://localhost:8080/Plugin.Activate +{"Implements": ["NetworkDriver"]} +``` + +## Further Examples + ### Example using Unix sockets: ```go