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": {
|
||||
"address": "http://localhost:8086",
|
||||
"username": "iot-relay",
|
||||
"password": "",
|
||||
"db": "grafana",
|
||||
"measurement": "iot",
|
||||
"host": "iot-relay"
|
||||
|
|
|
@ -42,7 +42,14 @@ func GetHandler(config config.Config) types.Callback {
|
|||
|
||||
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 {
|
||||
log.Println(err)
|
||||
return err
|
||||
|
|
|
@ -13,6 +13,8 @@ type Config struct {
|
|||
} `json:"server"`
|
||||
Client struct {
|
||||
Address string `json:"address"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
DB string `json:"db"`
|
||||
Measurement string `json:"measurement"`
|
||||
Host string `json:"host"`
|
||||
|
|
Loading…
Reference in a new issue