/
client_api.go
67 lines (57 loc) · 1.35 KB
/
client_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package grid
import (
_ "fmt"
"github.com/ant0ine/go-json-rest/rest"
"github.com/braintree/manners"
"github.com/golang/glog"
"log"
// "net/http"
)
/*
type ClientApi struct {
}
func (this *ClientApi) CreateJob(jobDef JobDefinition, jobID *JobID) (err error) {
// TODO: consider how to extract client IP/port, client hostname, and potentially
// username if we use a secure transport. Or maybe this is too much of a hassle;
// we could make the client lib supply this instead...
*jobID, err = CreateJob(&jobDef)
return err
}
*/
type clientApi struct {
server *manners.GracefulServer
}
func (this *clientApi) CreateJob(w rest.ResponseWriter, r *rest.Request) {
log.Print("CreateJob")
w.WriteJson(1)
}
/*
func waitForShutdown(server *manners.GracefulServer) {
shutdown := <- Model.ShutdownFlag
server <-
}
*/
var api *clientApi
func init() {
api = new(clientApi)
}
func StartClientApi() {
handler := rest.ResourceHandler{
EnableRelaxedContentType: true,
}
//api := clientApi{}
err := handler.SetRoutes(
rest.RouteObjectMethod("POST", "/jobs", api, "CreateJob"),
)
if err != nil {
log.Fatal(err)
}
api.server = manners.NewServer()
glog.Info("client api starting")
api.server.ListenAndServe(":8080", &handler)
}
func ShutdownClientApi() {
glog.Info("shutting down client api...")
api.server.Shutdown <- true
glog.Info("client api stopped")
}