ETRI_SMARTFARM_POC/containers/devicemanagera/main.go

48 lines
789 B
Go
Raw Permalink Normal View History

2021-11-16 12:28:52 +00:00
package main
import (
"bytes"
2021-12-15 08:07:52 +00:00
"devicemanagerb/constants"
"devicemanagerb/router"
2021-11-16 12:28:52 +00:00
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func registerToServer() {
var obj map[string]string = make(map[string]string)
2021-12-17 00:17:26 +00:00
obj["name"] = "devicemanagera"
2021-12-15 08:07:52 +00:00
obj["addr"] = constants.MyIP + ":3000"
2021-11-16 12:28:52 +00:00
b, err := json.Marshal(obj)
if err != nil {
panic(err)
}
2021-12-15 08:07:52 +00:00
req, err := http.NewRequest("PUT", "http://"+constants.ServerAddr+":3000/services", bytes.NewBuffer(b))
2021-11-16 12:28:52 +00:00
if err != nil {
panic(err)
}
2021-12-15 08:07:52 +00:00
2021-11-16 12:28:52 +00:00
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
b, err = ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
func main() {
registerToServer()
err := http.ListenAndServe(":3000", router.NewRouter())
if err != nil {
panic(err)
}
}