Skip to content

Instantly share code, notes, and snippets.

@pims
Created February 29, 2016 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pims/cd9d8982479acd24b665 to your computer and use it in GitHub Desktop.
Save pims/cd9d8982479acd24b665 to your computer and use it in GitHub Desktop.
Simple Nomad job specification & http service written in Go.
job "nomad-example" {
region = "us"
datacenters = ["dc1"]
type = "service"
group "webservice" {
count = 3
task "app" {
driver = "raw_exec"
config {
command = "/Users/tim/codebin/go/src/github.com/pims/nomad-example/nomad-example"
}
resources {
network {
mbits = 1
port "http" {}
}
}
}
}
}
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func endpoint(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s\n", "hello world")
}
func main() {
// addr := ":8888"
addr := os.Getenv("NOMAD_ADDR_http")
http.HandleFunc("/", endpoint)
log.Println("Listening on:", addr)
err := http.ListenAndServe(addr, nil)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment