// MakeInfoHandler returns an HTTP handler which can be added to an exposed
// HTTP server mux by Metafora applications to provide operators with basic
// node introspection.
MakeInfoHandler returns an HTTP handler which can be added to an exposed
HTTP server mux by Metafora applications to provide operators with basic
node introspection.
// MakeInfoHandler returns an HTTP handler which can be added to an exposed // HTTP server mux by Metafora applications to provide operators with basic // node introspection .
func MakeInfoHandler(c Consumer, started time.Time) http.HandlerFunc {
	return func(w http.ResponseWriter, _ *http.Request) {
		tasks := c.Tasks()
		resp := InfoResponse{
			Frozen:  c.Frozen(),
			Name:    c.String(),
			Started: started,
			Tasks:   make([]Task, len(tasks)),
		}
		for i, task := range tasks {
			resp.Tasks[i] = Task{
				ID:      task.Task().ID(),
				Started: task.Started(),
				Task:    task.Task(),
			}
			stopped := task.Stopped()
			if !stopped.IsZero() {
				resp.Tasks[i].Stopped = &stopped
			}
			if sh, ok := task.Handler().(stateMachine); ok {
				s, ts := sh.State()
				resp.Tasks[i].State = s.String()
				resp.Tasks[i].Modified = &ts
			}
		}
		w.Header().Set("Content-Type", "application/json")
		json.NewEncoder(w).Encode(&resp)
	}
}
func MakeInfoHandler ( c Consumer , started time . Time ) http . HandlerFunc { return func ( w http . ResponseWriter , _ * http . Request ) { tasks := c . Tasks ( ) resp := InfoResponse { Frozen : c . Frozen ( ) , Name : c . String ( ) , Started : started , Tasks : make ( [ ] Task , len ( tasks ) ) , } for i , task := range tasks { resp . Tasks [ i ] = Task { ID : task . Task ( ) . ID ( ) , Started : task . Started ( ) , Task : task . Task ( ) , } stopped := task . Stopped ( ) if ! stopped . IsZero ( ) { resp . Tasks [ i ] . Stopped = & stopped } if sh , ok := task . Handler ( ) . ( stateMachine ) ; ok { s , ts := sh . State ( ) resp . Tasks [ i ] . State = s . String ( ) resp . Tasks [ i ] . Modified = & ts } } w . Header ( ) . Set ( " " , " " ) json . NewEncoder ( w ) . Encode ( & resp ) } }
MakeInfoHandler returns an HTTP handler which can be added to an exposed
HTTP server mux by Metafora applications to provide operators with basic
node introspection.
MakeInfoHandler returns an HTTP handler which can be added to an exposed HTTP server mux by Metafora applications to provide operators with basic node introspection .
// Set stopped if it's non-zero // Expose state if it exists