Created
August 24, 2018 14:14
-
-
Save richardsonlima/1907d91327f9112ba7e8ccc218a4512d to your computer and use it in GitHub Desktop.
Consul Client Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
//"encoding/json" | |
//"context" | |
"fmt" | |
//"io/ioutil" | |
"net/http" | |
"encoding/json" | |
// "github.com/hashicorp/consul/api" | |
// "github.com/hashicorp/consul/connect" | |
) | |
type Q struct{ | |
Address string `json:"address"` | |
} | |
func main() { | |
// Create a Consul API client | |
//client, _ := api.NewClient(api.DefaultConfig()) | |
req, err := http.Get("http://localhost:8500/v1/catalog/service/repairorder_local") | |
if err != nil { | |
fmt.Println("NewRequest err: ", err) | |
} else { | |
var target []Q | |
json.NewDecoder(req.Body).Decode(&target) | |
//data,_:= ioutil.ReadAll(req.Body) | |
fmt.Println("---------------------------------") | |
//var q interface{} | |
// json.Unmarshal(target,&q) | |
//data,_ :=json.Marshal(target) | |
//n := string(data) | |
fmt.Println(target[0].Address) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment