Commit cee747bf authored by Eteri's avatar Eteri

fluentbit: format code

parent ca3c5752
...@@ -2,14 +2,13 @@ package main ...@@ -2,14 +2,13 @@ package main
import "github.com/fluent/fluent-bit-go/output" import "github.com/fluent/fluent-bit-go/output"
import ( import (
"fmt"
"unsafe"
"C" "C"
"bytes"
"fmt"
"net/http" "net/http"
"strconv" "regexp"
"bytes" "strconv"
"regexp" "unsafe"
) )
// configuration parameters // configuration parameters
...@@ -28,7 +27,7 @@ func FLBPluginRegister(ctx unsafe.Pointer) int { ...@@ -28,7 +27,7 @@ func FLBPluginRegister(ctx unsafe.Pointer) int {
// ctx (context) pointer to fluentbit context (state/ c code) // ctx (context) pointer to fluentbit context (state/ c code)
func FLBPluginInit(ctx unsafe.Pointer) int { func FLBPluginInit(ctx unsafe.Pointer) int {
// Example to retrieve an optional configuration parameter // Example to retrieve an optional configuration parameter
// param := output.FLBPluginConfigKey(ctx, "param") // param := output.FLBPluginConfigKey(ctx, "param")
user = output.FLBPluginConfigKey(ctx, "User") user = output.FLBPluginConfigKey(ctx, "User")
password = output.FLBPluginConfigKey(ctx, "Password") password = output.FLBPluginConfigKey(ctx, "Password")
uri = output.FLBPluginConfigKey(ctx, "Uri") uri = output.FLBPluginConfigKey(ctx, "Uri")
...@@ -46,53 +45,53 @@ func FLBPluginInit(ctx unsafe.Pointer) int { ...@@ -46,53 +45,53 @@ func FLBPluginInit(ctx unsafe.Pointer) int {
//export FLBPluginFlush //export FLBPluginFlush
func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int { func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int {
request_string := uri + "/ingest?reference=" + reference request_string := uri + "/ingest?reference=" + reference
var b []byte var b []byte
b = C.GoBytes(data, C.int(length)) b = C.GoBytes(data, C.int(length))
hc := http.Client{} hc := http.Client{}
req, err := http.NewRequest("POST", request_string, bytes.NewBuffer(b)) req, err := http.NewRequest("POST", request_string, bytes.NewBuffer(b))
if err != nil { if err != nil {
return output.FLB_ERROR return output.FLB_ERROR
} }
req.Header.Set("Content-Type", "application/octet-stream") req.Header.Set("Content-Type", "application/octet-stream")
req.SetBasicAuth(user, password) req.SetBasicAuth(user, password)
resp, err := hc.Do(req) resp, err := hc.Do(req)
if err != nil { if err != nil {
return output.FLB_ERROR return output.FLB_ERROR
} }
/* /*
* Only allow the following HTTP status: * Only allow the following HTTP status:
* *
* - 200: OK * - 200: OK
* - 201: Created * - 201: Created
* - 202: Accepted * - 202: Accepted
* - 203: no authorative resp * - 203: no authorative resp
* - 204: No Content * - 204: No Content
* - 205: Reset content * - 205: Reset content
*/ */
re := regexp.MustCompile("[0-9]+") // get only the status code re := regexp.MustCompile("[0-9]+") // get only the status code
status_code := re.FindAllString(resp.Status, -1) status_code := re.FindAllString(resp.Status, -1)
resp_status, err := strconv.Atoi(status_code[0]) resp_status, err := strconv.Atoi(status_code[0])
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return output.FLB_RETRY return output.FLB_RETRY
} }
fmt.Println(resp.Status) fmt.Println(resp.Status)
fmt.Println(err) fmt.Println(err)
if resp_status < 200 && resp_status > 205 { if resp_status < 200 && resp_status > 205 {
return output.FLB_RETRY return output.FLB_RETRY
} }
defer resp.Body.Close() defer resp.Body.Close()
/* /*
* Return options: * Return options:
...@@ -100,7 +99,7 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int { ...@@ -100,7 +99,7 @@ func FLBPluginFlush(data unsafe.Pointer, length C.int, tag *C.char) int {
* - output.FLB_OK = data have been processed. * - output.FLB_OK = data have been processed.
* - output.FLB_ERROR = unrecoverable error, do not try this again. * - output.FLB_ERROR = unrecoverable error, do not try this again.
* - output.FLB_RETRY = retry to flush later. * - output.FLB_RETRY = retry to flush later.
*/ */
return output.FLB_OK return output.FLB_OK
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment