Exemplo n.º 1
0
func (h *Handler) Interprete(w http.ResponseWriter, r *http.Request) {
	prog := new(program)
	if err := json.NewDecoder(r.Body).Decode(prog); err != nil {
		log4go.Error("Cannot decode json code: %s", err.Error())
	}

	if err := json.NewEncoder(w).Encode(h.LanguageClient.Interprete(prog.Code)); err != nil {
		log4go.Error("Cannot encode result of code: %s", err.Error())
	}
}
Exemplo n.º 2
0
func (j *JsonHandler) InferJsonStructure(w http.ResponseWriter, r *http.Request) {
	b, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log4go.Error(err)
	}

	jsonSchema := j.Parse(b)
	if err := json.NewEncoder(w).Encode(jsonSchema); err != nil {
		log4go.Error(err)
	}
}
Exemplo n.º 3
0
func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
	var rules RuleRepository
	if err := json.NewDecoder(r.Body).Decode(&rules); err != nil {
		log4go.Error("Could not decode rule: %s", err.Error())
	}
	h.AddRules(rules)
}
Exemplo n.º 4
0
func (y *YamlHandler) ParseSchema(schema []byte) []inference.Field {
	var in []inference.Field
	if err := yaml.Unmarshal(schema, &in); err != nil {
		log4go.Error(err)
	}

	return in
}
Exemplo n.º 5
0
func (p *PipelineHandler) ReadPipelineConfig(w http.ResponseWriter, r *http.Request) {
	if err := json.NewEncoder(w).Encode(p.pipeline); err != nil {
		message := fmt.Sprintf("Could not read Pipeline: %s", err.Error())

		log4go.Error(message)
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(message))
	}
}
Exemplo n.º 6
0
func (j *JsonHandler) Parse(msg []byte) []inference.Field {
	var obj interface{}

	if err := json.Unmarshal(msg, &obj); err != nil {
		log4go.Error(err)
	}

	data, _ := parse(obj)
	return data
}
Exemplo n.º 7
0
func (p *PipelineHandler) NewPipeline(w http.ResponseWriter, r *http.Request) {
	process := new(process.Process)
	in := CreateInput()

	if err := json.NewDecoder(r.Body).Decode(process); err != nil {
		message := fmt.Sprintf("Could not create Pipeline: %s", err.Error())

		log4go.Error(message)
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(message))
	}

	p.pipeline = NewPipeline("Default", process, in)
}