package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Response struct {
Version string `json:"version"`
Data map[string][]interface{} `json:"data"`
}
func main() {
var client http.Client
resp, err := client.Get("https://api.myjson.com/bins/by9gw")
if err != nil {
panic(err)
}
defer resp.Body.Close()
simpleResp := Response{}
fmt.Println("Response code:", resp.StatusCode)
if resp.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
_ = json.Unmarshal(bodyBytes, &simpleResp)
sampleArr := simpleResp.Data["sampleArray"]
fmt.Println(sampleArr[0])
fmt.Println(sampleArr[1])
casted, ok := sampleArr[2].(map[string]interface{})
if !ok {
panic("Wrong type of sampleArr element")
}
fmt.Println("Name:")
fmt.Println(casted["name"])
}
}
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
array := make([][]uint8, dy)
for y := 0; y < dy; y++ {
array[y] = make([]uint8, dx)
for x := 0; x < dx; x++ {
pixel := uint8((x + y) / 2)
array[y][x] = pixel
}
}
return array
}
func main() {
pic.Show(Pic)
}
fmt.Println(len(resp.Data))
fmt.Println(resp.Data[0])
fmt.Println(resp.Data[1])
func (с Celsius) String() string {
return fmt.Sprintf("%g°C", c)
}
type TestStruct struct {
Id int
Data map[int]interface{}
}
func main() {
testing := map[int]TestStruct{}
testing[0] = TestStruct{
Id: 0,
}
objCopy := testing[0]
objCopy.Data = map[int]interface{}{
1: "dd",
}
testing[0] = objCopy
}
go run Setup.go
package main
import (
"fmt"
"net/http"
)
func main() {
err := http.ListenAndServe(":8090", nil)
fmt.Println("Error creating http server: ", err)
}
$ go run main.go
Error creating http server: listen tcp :8090: bind: address already in use
session, _ := mgo.Dial("mongodb://127.0.0.1")
var t = map[int]string
t := map[int]string{}
var t []string
for k, value := range config.Settings.Logs {
elem, err := tail.TailFile(value, tail.Config{Follow: true, ReOpen: true, MustExist: true})
...... тут надо ошибку проверить .....
t = append(t, elem)
}