Use go-ipam as a gRPC microservice
masterThe project can be run as a standalone microservice providing a gRPC API.
Running the service
Start the container with your chosen database backend. For example, using Postgres:
docker run -it --rm ghcr.io/metal-stack/go-ipam postgresClient implementation
Use the generated gRPC client to interact with the service. You can specify a namespace using goipam.NewContextWithNamespace to ensure requests are scoped correctly.
package main
import (
"context"
"http"
v1 "github.com/metal-stack/go-ipam/api/v1"
"github.com/metal-stack/go-ipam/api/v1/apiv1connect"
)
func main() {
c := apiv1connect.NewIpamServiceClient(
http.DefaultClient,
"http://localhost:9090",
connect.WithGRPC(),
)
bgCtx := context.Background()
// Optional with Namespace
ctx := goipam.NewContextWithNamespace(bgCtx, "tenant-a")
result, err := c.CreatePrefix(ctx, &v1.CreatePrefixRequest{Cidr: "192.168.0.0/16"})
if err != nil {
panic(err)
}
fmt.Println("Prefix:%q created", result.GetPrefix().GetCidr())
}