@@ -2,6 +2,7 @@ package main
22
33import (
44 "context"
5+ "flag"
56
67 "github.com/micro/go-micro/v2"
78 "github.com/micro/go-micro/v2/client"
@@ -29,41 +30,51 @@ func main() {
2930 //log.Debug().Uint64("FlushInterval", cfg.Features.Tracing.FlushInterval).Send()
3031 //log.Debug().Msgf("cfg is %v", cfg)
3132
33+ username := flag .String ("username" , "sumo" , "username of user to be create" )
34+ email := flag .
String (
"email" ,
"[email protected] " ,
"email of user to be create" )
35+ limit := flag .Uint64 ("limit" , 10 , "Limit number of results" )
36+
37+ log .Debug ().Str ("username" , * username ).Str ("email" , * email ).Uint64 ("limit" , * limit ).Msg ("Flags Using:" )
38+
3239 userService := userPB .NewUserService (constants .ACCOUNT_SERVICE , client .DefaultClient )
3340
34- if _ , err := userService .Create (context .TODO (), & userPB.CreateRequest {
35- Username : & wrappers.StringValue {Value : "sumo" },
41+ if _ , err := userService .Create (context .TODO (), & userPB.CreateRequest {
42+ Username : & wrappers.StringValue {Value : * username },
3643 FirstName : & wrappers.StringValue {Value : "sumo" },
3744 LastName : & wrappers.StringValue {Value : "demo" },
38- Email :
& wrappers.
StringValue {
Value :
"[email protected] " },
39- }); err != nil {
45+ Email : & wrappers.StringValue {Value : * email },
46+ }); err != nil {
4047 log .Fatal ().Err (err ).Msg ("Unable to create User" )
4148 }
4249
43- getUserList (userService )
44- getUserList2 ()
50+ getUserList (userService , uint32 ( * limit ) )
51+ getUserList2 (uint32 ( * limit ) )
4552}
4653
47- func getUserList (us userPB.UserService ) {
48- if rsp , err := us .List (context .Background (), & userPB.ListRequest {Limit : & wrappers.UInt32Value {Value : 10 }}); err != nil {
54+ func getUserList (us userPB.UserService , limit uint32 ) {
55+ if rsp , err := us .List (context .Background (), & userPB.ListRequest {Limit : & wrappers.UInt32Value {Value : limit }}); err != nil {
4956 log .Fatal ().Err (err ).Msg ("Unable to List Users" )
5057 } else {
5158 log .Info ().Interface ("listRsp" , rsp ).Send ()
5259 }
5360}
5461
5562// Just to showcase usage of generic micro client
56- func getUserList2 () {
63+ func getUserList2 (limit uint32 ) {
64+
65+ // New Service
5766 service := micro .NewService (
5867 micro .Name ("mkit.client.account" ),
5968 micro .Version (config .Version ),
69+ micro .WrapClient (logWrapper .NewClientWrapper ()), // Showcase ClientWrapper usage
6070 )
61- service .Init (micro .WrapClient (logWrapper .NewClientWrapper ())) // Showcase ClientWrapper
6271
6372 cl := service .Client ()
6473
6574 // Create new request to service mkit.service.account, method UserService.List
66- listReq := cl .NewRequest (constants .ACCOUNT_SERVICE , "UserService.List" , & userPB.ListRequest {Limit : & wrappers.UInt32Value {Value : 10 }})
75+ listReq := cl .NewRequest (constants .ACCOUNT_SERVICE , "UserService.List" , & userPB.ListRequest {
76+ Limit : & wrappers.UInt32Value {Value : limit },
77+ })
6778 listRsp := & userPB.ListResponse {}
6879
6980 // Create context with metadata - (Optional) Just for demonstration
@@ -72,9 +83,9 @@ func getUserList2() {
7283 "X-From-Id" : "script" ,
7384 })
7485
75- if err := cl .Call (ctx , listReq , listRsp ); err != nil {
86+ if err := cl .Call (ctx , listReq , listRsp ); err != nil {
7687 log .Fatal ().Err (err ).Msg ("Unable to List Users" )
7788 } else {
78- log .Info ().Interface ("listRsp" ,listRsp ).Send ()
89+ log .Info ().Interface ("listRsp" , listRsp ).Send ()
7990 }
8091}
0 commit comments