Skip to content

Go Go Client

Gate offers two powerful approaches to integrate with Go applications:

If you choose to use the HTTP API Client, follow along below.

HTTP API Client

  1. Install the required packages:
bash
go get buf.build/gen/go/minekube/gate/connectrpc/go@latest
go get buf.build/gen/go/minekube/gate/protocolbuffers/go@latest
  1. Example usage:
go
package main

import (
	"context"
	"encoding/json"
	"log"
	"net/http"

	"buf.build/gen/go/minekube/gate/connectrpc/go/minekube/gate/v1/gatev1connect"
	gatev1 "buf.build/gen/go/minekube/gate/protocolbuffers/go/minekube/gate/v1"
	"connectrpc.com/connect"
)

// main is an example of how to use the ListServers method.
func main() {
	ctx := context.Background()
	
	client := gatev1connect.NewGateServiceClient(
		http.DefaultClient, 
		"http://localhost:8080",
	)

	req := connect.NewRequest(&gatev1.ListServersRequest{})
	res, err := client.ListServers(ctx, req)
	if err != nil {
		log.Fatalln("make sure Gate is running with the API enabled", err)
	}

	j, _ := json.MarshalIndent(res.Msg, "", "  ")
	println(string(j))
}
  1. Run the example:
bash
go run .
{
  "servers": [
    {
      "name": "server2",
      "address": "localhost:25567"
    },
    {
      "name": "server3",
      "address": "localhost:25568"
    },
    {
      "name": "server4",
      "address": "localhost:25569"
    },
    {
      "name": "server1",
      "address": "localhost:25566"
    }
  ]
}

This example project is located in the docs/developers/api/go directory.

Learn More

For more details on using ConnectRPC with Go, check out the ConnectRPC Documentation.

Released under the Apache 2.0 License. (web version: 684aec7e)