mirror of
https://github.com/sigmasternchen/iot-relay
synced 2025-03-15 06:28:55 +00:00
added basic auth for client
This commit is contained in:
parent
3ac76e0d99
commit
6ac99dc2af
3 changed files with 12 additions and 1 deletions
|
@ -5,6 +5,8 @@
|
||||||
},
|
},
|
||||||
"client": {
|
"client": {
|
||||||
"address": "http://localhost:8086",
|
"address": "http://localhost:8086",
|
||||||
|
"username": "iot-relay",
|
||||||
|
"password": "",
|
||||||
"db": "grafana",
|
"db": "grafana",
|
||||||
"measurement": "iot",
|
"measurement": "iot",
|
||||||
"host": "iot-relay"
|
"host": "iot-relay"
|
||||||
|
|
|
@ -42,7 +42,14 @@ func GetHandler(config config.Config) types.Callback {
|
||||||
|
|
||||||
url := config.Client.Address + "/write?db=" + config.Client.DB
|
url := config.Client.Address + "/write?db=" + config.Client.DB
|
||||||
|
|
||||||
resp, err := http.Post(url, "application/octet-stream", strings.NewReader(line))
|
client := &http.Client{}
|
||||||
|
req, err := http.NewRequest("POST", url, strings.NewReader(line))
|
||||||
|
|
||||||
|
if len(config.Client.Username) != 0 && len(config.Client.Password) != 0 {
|
||||||
|
req.SetBasicAuth(config.Client.Username, config.Client.Password)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -13,6 +13,8 @@ type Config struct {
|
||||||
} `json:"server"`
|
} `json:"server"`
|
||||||
Client struct {
|
Client struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Password string `json:"password"`
|
||||||
DB string `json:"db"`
|
DB string `json:"db"`
|
||||||
Measurement string `json:"measurement"`
|
Measurement string `json:"measurement"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
|
|
Loading…
Reference in a new issue