apis: unify http response format

Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
huanggze
2019-06-24 15:07:11 +08:00
parent 5910ef4554
commit 87bdbfaaf2
4 changed files with 74 additions and 3 deletions

View File

@@ -233,6 +233,7 @@ func FluentbitOutputsQuery() *FluentbitOutputsResult {
outputs, err := GetFluentbitOutputFromConfigMap()
if err != nil {
result.Status = http.StatusNotFound
result.Error = err.Error()
return &result
}
@@ -263,6 +264,7 @@ func FluentbitOutputInsert(output fb.OutputPlugin) *FluentbitOutputsResult {
err = updateFluentbitOutputConfigMap(outputs)
if err != nil {
result.Status = http.StatusInternalServerError
result.Error = err.Error()
return &result
}
@@ -270,6 +272,7 @@ func FluentbitOutputInsert(output fb.OutputPlugin) *FluentbitOutputsResult {
err = syncFluentbitCRDOutputWithConfigMap(outputs)
if err != nil {
result.Status = http.StatusInternalServerError
result.Error = err.Error()
return &result
}
@@ -304,6 +307,7 @@ func FluentbitOutputUpdate(output fb.OutputPlugin, id string) *FluentbitOutputsR
if index >= len(outputs) {
result.Status = http.StatusNotFound
result.Error = "The output plugin to update doesn't exist. Please check the output id you provide."
return &result
}
@@ -313,6 +317,7 @@ func FluentbitOutputUpdate(output fb.OutputPlugin, id string) *FluentbitOutputsR
err = updateFluentbitOutputConfigMap(outputs)
if err != nil {
result.Status = http.StatusInternalServerError
result.Error = err.Error()
return &result
}
@@ -320,6 +325,7 @@ func FluentbitOutputUpdate(output fb.OutputPlugin, id string) *FluentbitOutputsR
err = syncFluentbitCRDOutputWithConfigMap(outputs)
if err != nil {
result.Status = http.StatusInternalServerError
result.Error = err.Error()
return &result
}
@@ -350,6 +356,7 @@ func FluentbitOutputDelete(id string) *FluentbitOutputsResult {
if index >= len(outputs) {
result.Status = http.StatusNotFound
result.Error = "The output plugin to delete doesn't exist. Please check the output id you provide."
return &result
}
@@ -358,6 +365,7 @@ func FluentbitOutputDelete(id string) *FluentbitOutputsResult {
err := updateFluentbitOutputConfigMap(outputs)
if err != nil {
result.Status = http.StatusInternalServerError
result.Error = err.Error()
return &result
}
@@ -365,6 +373,7 @@ func FluentbitOutputDelete(id string) *FluentbitOutputsResult {
err = syncFluentbitCRDOutputWithConfigMap(outputs)
if err != nil {
result.Status = http.StatusInternalServerError
result.Error = err.Error()
return &result
}

View File

@@ -49,5 +49,6 @@ type FluentbitFiltersResult struct {
type FluentbitOutputsResult struct {
Status int `json:"status" description:"response status"`
Error string `json:"error,omitempty" description:"debug information"`
Outputs []fb.OutputPlugin `json:"outputs,omitempty" description:"array of fluent bit output plugins"`
}