Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A simple Go Warden Client
Go
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.travis.yml
LICENSE
NOTICE
README.md
client.go
client_test.go
connection.go
connection_provider.go
connection_test.go
copy_in.pb.go
copy_out.pb.go
create.pb.go
destroy.pb.go
echo.pb.go
error.pb.go
helpers_test.go
info.pb.go
limit_bandwidth.pb.go
limit_disk.pb.go
limit_memory.pb.go
link.pb.go
list.pb.go
message.pb.go
net_in.pb.go
net_out.pb.go
ping.pb.go
resource_limits.pb.go
run.pb.go
spawn.pb.go
stop.pb.go
stream.pb.go

README.md

Gordon

A simple Warden client. Handles automatic reconnection, and implicitly creates new connections for blocking calls like Run, Link, and Stream.

Installation

cd $GOPATH
go get github.com/vito/gordon

Usage

package main

import (
  "fmt"
  "github.com/vito/gordon"
  "os"
)

func main() {
  client := warden.NewClient(
    &warden.ConnectionInfo{
      SocketPath: "/tmp/warden.sock"
    }
  )

  err := client.Connect()
  if err != nil {
    fmt.Println("Failed to connect to Warden: ", err)
    os.Exit(1)
    return
  }

  createResponse, err := client.Create()
  if err != nil {
    fmt.Println("Failed to create container: ", err)
    os.Exit(1)
    return
  }

  handle := createResponse.GetHandle()
  defer client.Destroy(handle)

  fmt.Printf("Container: %s\n", handle)

  spawnResponse, err := client.Spawn(handle, `
    for i in $(seq 10); do
      echo out $i;
      echo err $i 1>&2;
      sleep 1;
    done
  `)

  if err != nil {
    fmt.Println("Failed to spawn process: ", err)
    os.Exit(1)
    return
  }

  fmt.Println("Spawned!", spawnResponse)

  responses, err := client.Stream(handle, spawnResponse.GetJobId())
  if err != nil {
    fmt.Println("Failed to stream output: ", err)
    os.Exit(1)
    return
  }

  fmt.Println("Streaming output...")

  for {
    res, ok := <-responses
    if !ok {
      break
    }

    if res.ExitStatus == nil {
      fmt.Printf("%s: %s", res.GetName(), res.GetData())
    } else {
      fmt.Printf("exited: %d\n", res.GetExitStatus())
    }
  }
}
Something went wrong with that request. Please try again.