@@ -18,7 +18,7 @@ import (
1818	"github.com/tarantool/go-tarantool/v2/box" 
1919)
2020
21- func  Example () {
21+ func  ExampleBox_Info () {
2222	dialer  :=  tarantool.NetDialer {
2323		Address :  "127.0.0.1:3013" ,
2424		User :     "test" ,
@@ -58,3 +58,129 @@ func Example() {
5858	fmt .Printf ("Box info uuids are equal" )
5959	fmt .Printf ("Current box info: %+v\n " , resp .Info )
6060}
61+ 
62+ func  ExampleSchemaUser_Exists () {
63+ 	dialer  :=  tarantool.NetDialer {
64+ 		Address :  "127.0.0.1:3013" ,
65+ 		User :     "test" ,
66+ 		Password : "test" ,
67+ 	}
68+ 	ctx , cancel  :=  context .WithTimeout (context .Background (), 500 * time .Millisecond )
69+ 	client , err  :=  tarantool .Connect (ctx , dialer , tarantool.Opts {})
70+ 	cancel ()
71+ 	if  err  !=  nil  {
72+ 		log .Fatalf ("Failed to connect: %s" , err )
73+ 	}
74+ 
75+ 	// You can use UserExistsRequest type and call it directly. 
76+ 	fut  :=  client .Do (box .NewUserExistsRequest ("user" ))
77+ 
78+ 	resp  :=  & box.UserExistsResponse {}
79+ 
80+ 	err  =  fut .GetTyped (resp )
81+ 	if  err  !=  nil  {
82+ 		log .Fatalf ("Failed get box schema user exists with error: %s" , err )
83+ 	}
84+ 
85+ 	// Or use simple User implementation. 
86+ 	b  :=  box .New (client )
87+ 	exists , err  :=  b .Schema ().User ().Exists (ctx , "user" )
88+ 	if  err  !=  nil  {
89+ 		log .Fatalf ("Failed get box schema user exists with error: %s" , err )
90+ 	}
91+ 
92+ 	if  exists  !=  resp .Exists  {
93+ 		log .Fatalf ("Box schema users exists are not equal" )
94+ 	}
95+ 
96+ 	fmt .Printf ("Box schema users exists are equal" )
97+ 	fmt .Printf ("Current exists state: %+v\n " , exists )
98+ }
99+ 
100+ func  ExampleSchemaUser_Create () {
101+ 	// Connect to Tarantool 
102+ 	dialer  :=  tarantool.NetDialer {
103+ 		Address :  "127.0.0.1:3013" ,
104+ 		User :     "test" ,
105+ 		Password : "test" ,
106+ 	}
107+ 	ctx , cancel  :=  context .WithTimeout (context .Background (), 500 * time .Millisecond )
108+ 	client , err  :=  tarantool .Connect (ctx , dialer , tarantool.Opts {})
109+ 	cancel ()
110+ 	if  err  !=  nil  {
111+ 		log .Fatalf ("Failed to connect: %s" , err )
112+ 	}
113+ 
114+ 	// Create SchemaUser 
115+ 	schemaUser  :=  box .NewSchemaUser (client )
116+ 
117+ 	// Create a new user 
118+ 	username  :=  "new_user" 
119+ 	options  :=  box.UserCreateOptions {
120+ 		IfNotExists : true ,
121+ 		Password :    "secure_password" ,
122+ 	}
123+ 	err  =  schemaUser .Create (ctx , username , options )
124+ 	if  err  !=  nil  {
125+ 		log .Fatalf ("Failed to create user: %s" , err )
126+ 	}
127+ 
128+ 	fmt .Printf ("User '%s' created successfully\n " , username )
129+ }
130+ 
131+ func  ExampleSchemaUser_Drop () {
132+ 	// Connect to Tarantool 
133+ 	dialer  :=  tarantool.NetDialer {
134+ 		Address :  "127.0.0.1:3013" ,
135+ 		User :     "test" ,
136+ 		Password : "test" ,
137+ 	}
138+ 	ctx , cancel  :=  context .WithTimeout (context .Background (), 500 * time .Millisecond )
139+ 	client , err  :=  tarantool .Connect (ctx , dialer , tarantool.Opts {})
140+ 	cancel ()
141+ 	if  err  !=  nil  {
142+ 		log .Fatalf ("Failed to connect: %s" , err )
143+ 	}
144+ 
145+ 	// Create SchemaUser 
146+ 	schemaUser  :=  box .NewSchemaUser (client )
147+ 
148+ 	// Drop an existing user 
149+ 	username  :=  "new_user" 
150+ 	options  :=  box.UserDropOptions {
151+ 		IfExists : true ,
152+ 	}
153+ 	err  =  schemaUser .Drop (ctx , username , options )
154+ 	if  err  !=  nil  {
155+ 		log .Fatalf ("Failed to drop user: %s" , err )
156+ 	}
157+ 
158+ 	fmt .Printf ("User '%s' dropped successfully\n " , username )
159+ }
160+ 
161+ func  ExampleSchemaUser_Password () {
162+ 	// Connect to Tarantool 
163+ 	dialer  :=  tarantool.NetDialer {
164+ 		Address :  "127.0.0.1:3013" ,
165+ 		User :     "test" ,
166+ 		Password : "test" ,
167+ 	}
168+ 	ctx , cancel  :=  context .WithTimeout (context .Background (), 500 * time .Millisecond )
169+ 	client , err  :=  tarantool .Connect (ctx , dialer , tarantool.Opts {})
170+ 	cancel ()
171+ 	if  err  !=  nil  {
172+ 		log .Fatalf ("Failed to connect: %s" , err )
173+ 	}
174+ 
175+ 	// Create SchemaUser 
176+ 	schemaUser  :=  box .NewSchemaUser (client )
177+ 
178+ 	// Get the password hash of an existing user 
179+ 	username  :=  "existing_user" 
180+ 	passwordHash , err  :=  schemaUser .Password (ctx , username )
181+ 	if  err  !=  nil  {
182+ 		log .Fatalf ("Failed to get password hash: %s" , err )
183+ 	}
184+ 
185+ 	fmt .Printf ("Password hash for user '%s': %s\n " , username , passwordHash )
186+ }
0 commit comments