我正在尝试在 DGraph 数据库中进行突变,但是当我运行代码时,它会抛出下一个错误:


rpc 错误:代码 = 不可用 desc = 连接关闭退出状态 1


我在端口 8000 中使用 dGraph 和 docker,我的 golang 代码在这里:


package main


import (

   "fmt"

   "context"

   "encoding/json"

   "log"

   dgo "github.com/dgraph-io/dgo"

   api "github.com/dgraph-io/dgo/protos/api"

   grpc "google.golang.org/grpc"

)


type Person struct {

   Name string `json:"name,omitempty"`

   Lastname string `json:"lastname,omitempty"`

}


func main() {

conn, err := grpc.Dial("localhost:8000", grpc.WithInsecure())

if err != nil {

  log.Fatal(err)

}

defer conn.Close()

dgraphClient := dgo.NewDgraphClient(api.NewDgraphClient(conn))

p := Person {

    Name: "Giovanni",

    Lastname: "Mosquera Diazgranados",

}

txn := dgraphClient.NewTxn()

ctx := context.Background()

defer txn.Discard(ctx)

pb, err := json.Marshal(p)

if err != nil {

    log.Fatal(err)

}

mu := &api.Mutation{

    SetJson: pb,

}

res, err := txn.Mutate(ctx, mu)

if err != nil {

    fmt.Println("Aqui toy")

    log.Fatal(err)

} else {

    fmt.Println(res)

}

}

如何解决此错误以连接我的 DGraph 并进行突变?