跳到主要内容
版本:v2.5.x

CreateRole()

This method creates a role. In Milvus, you can allocate multiple privileges or privilege groups to a role and grant the role to a user so that the user gains the privileges allocated to the role.

Go
func (c *Client) CreateRole(ctx context.Context, opt CreateRoleOption, callOpts ...grpc.CallOption) error

Request Parameters​

Parameter

Description

Type

ctx

Context for the current call to work.

context.Context

opt

Optional parameters of the methods.

CreateRoleOption

callOpts

Optional parameters for calling the methods.

grpc.CallOption

CreateRoleOption​

This is an interface type. The createRoleOption struct type implements this interface type.

You can use the NewCreateRoleOption() function to get the concrete implementation.

NewCreateRoleOption​

The signature of the NewCreateRoleOption() is as follows:

Go
func NewCreateRoleOption(roleName string) *createRoleOption

Parameter

Description

Type

roleName

Name of the role to create.

string

grpc.CallOption​

This interface provided by the gRPC Go library allows you to specify additional options or configurations when making requests. For possible implementations of this interface, refer to this file.

Return​

Null

Example​

Go
import (
"context"
"google.golang.org/grpc"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)

roleName := "my_role"
opts := client.NewCreateRoleOption(roleName)

onFinish := func(ctx context.Context, err error) {
if err != nil {
fmt.Printf("gRPC call finished with error: %v\n", err)
} else {
fmt.Printf("gRPC call finished successfully")
}
}

callOption := grpc.OnFinish(onFinish)

err := mclient.CreateRole(context.Background(), opts, callOpts)