How to use SetStatus method of client Package

Best K6 code snippet using client.SetStatus

volumetype.go

Source:volumetype.go Github

copy

Full Screen

...36 id := portal.Ctx.Input.Param(":volumeTypeId")37 var cinderReq = converter.UpdateTypeReqSpec{}38 if err := json.NewDecoder(portal.Ctx.Request.Body).Decode(&cinderReq); err != nil {39 reason := fmt.Sprintf("Update a volume type, parse request body failed: %s", err.Error())40 portal.Ctx.Output.SetStatus(model.ErrorBadRequest)41 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))42 log.Error(reason)43 return44 }45 profile, err := converter.UpdateTypeReq(&cinderReq)46 if err != nil {47 reason := fmt.Sprintf("Update a volume type failed: %s", err.Error())48 portal.Ctx.Output.SetStatus(model.ErrorBadRequest)49 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))50 log.Error(reason)51 return52 }53 NewClient(portal.Ctx)54 profile, err = opensdsClient.UpdateProfile(id, profile)55 if err != nil {56 reason := fmt.Sprintf("Update a volume type failed: %s", err.Error())57 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)58 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))59 log.Error(reason)60 return61 }62 result := converter.UpdateTypeResp(profile)63 body, err := json.Marshal(result)64 if err != nil {65 reason := fmt.Sprintf("Update a volume type, marshal result failed: %s", err.Error())66 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)67 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))68 log.Error(reason)69 return70 }71 portal.Ctx.Output.SetStatus(http.StatusOK)72 portal.Ctx.Output.Body(body)73 return74}75// AddExtraProperty ...76func (portal *TypePortal) AddExtraProperty() {77 id := portal.Ctx.Input.Param(":volumeTypeId")78 var cinderReq = converter.AddExtraReqSpec{}79 if err := json.NewDecoder(portal.Ctx.Request.Body).Decode(&cinderReq); err != nil {80 reason := fmt.Sprintf("Create or update extra specs for volume type, parse request body failed: %s", err.Error())81 portal.Ctx.Output.SetStatus(model.ErrorBadRequest)82 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))83 log.Error(reason)84 return85 }86 profileExtra := converter.AddExtraReq(&cinderReq)87 NewClient(portal.Ctx)88 profileExtra, err := opensdsClient.AddCustomProperty(id, profileExtra)89 if err != nil {90 reason := fmt.Sprintf("Create or update extra specs for volume type failed: %s", err.Error())91 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)92 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))93 log.Error(reason)94 return95 }96 result := converter.AddExtraResp(profileExtra)97 // Marshal the result.98 body, err := json.Marshal(result)99 if err != nil {100 reason := fmt.Sprintf("Create or update extra specs for volume type, marshal result failed: %s", err.Error())101 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)102 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))103 log.Error(reason)104 return105 }106 portal.Ctx.Output.SetStatus(http.StatusOK)107 portal.Ctx.Output.Body(body)108 return109}110// ListExtraProperties ...111func (portal *TypePortal) ListExtraProperties() {112 id := portal.Ctx.Input.Param(":volumeTypeId")113 NewClient(portal.Ctx)114 profileExtra, err := opensdsClient.ListCustomProperties(id)115 if err != nil {116 reason := fmt.Sprintf("Show all extra specifications for volume type failed: %s", err.Error())117 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)118 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))119 log.Error(reason)120 return121 }122 result := converter.ShowAllExtraResp(profileExtra)123 body, err := json.Marshal(result)124 if err != nil {125 reason := fmt.Sprintf("Show all extra specifications for volume type, marshal result failed: %s", err.Error())126 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)127 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))128 log.Error(reason)129 return130 }131 portal.Ctx.Output.SetStatus(http.StatusOK)132 portal.Ctx.Output.Body(body)133 return134}135// ShowExtraProperty ...136func (portal *TypePortal) ShowExtraProperty() {137 id := portal.Ctx.Input.Param(":volumeTypeId")138 NewClient(portal.Ctx)139 profileExtra, err := opensdsClient.ListCustomProperties(id)140 if err != nil {141 reason := fmt.Sprintf("Show extra specification for volume type failed: %s", err.Error())142 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)143 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))144 log.Error(reason)145 return146 }147 key := portal.Ctx.Input.Param(":key")148 result := converter.ShowExtraResp(key, profileExtra)149 if nil == (*result) {150 reason := "The key name of the extra spec for the volume type can not be found"151 portal.Ctx.Output.SetStatus(http.StatusNotFound)152 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))153 log.Error(reason)154 return155 }156 body, err := json.Marshal(result)157 if err != nil {158 reason := fmt.Sprintf("Show extra specification for volume type, marshal result failed: %s", err.Error())159 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)160 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))161 log.Error(reason)162 return163 }164 portal.Ctx.Output.SetStatus(http.StatusOK)165 portal.Ctx.Output.Body(body)166 return167}168// UpdateExtraProperty ...169func (portal *TypePortal) UpdateExtraProperty() {170 id := portal.Ctx.Input.Param(":volumeTypeId")171 key := portal.Ctx.Input.Param(":key")172 var cinderReq = converter.UpdateExtraReqSpec{}173 if err := json.NewDecoder(portal.Ctx.Request.Body).Decode(&cinderReq); err != nil {174 reason := fmt.Sprintf("Update extra specification for volume type, parse request body failed: %s", err.Error())175 portal.Ctx.Output.SetStatus(model.ErrorBadRequest)176 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))177 log.Error(reason)178 return179 }180 profileExtra, err := converter.UpdateExtraReq(key, &cinderReq)181 if err != nil {182 reason := fmt.Sprintf("Update extra specification for volume type failed: %s", err.Error())183 portal.Ctx.Output.SetStatus(model.ErrorBadRequest)184 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))185 log.Error(reason)186 return187 }188 NewClient(portal.Ctx)189 profileExtra, err = opensdsClient.AddCustomProperty(id, profileExtra)190 if err != nil {191 reason := fmt.Sprintf("Update extra specification for volume type failed: %s", err.Error())192 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)193 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))194 log.Error(reason)195 return196 }197 result := converter.UpdateExtraResp(key, profileExtra)198 body, err := json.Marshal(result)199 if err != nil {200 reason := fmt.Sprintf("Update extra specification for volume type, marshal result failed: %s", err.Error())201 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)202 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))203 log.Error(reason)204 return205 }206 portal.Ctx.Output.SetStatus(http.StatusOK)207 portal.Ctx.Output.Body(body)208 return209}210// DeleteExtraProperty ...211func (portal *TypePortal) DeleteExtraProperty() {212 id := portal.Ctx.Input.Param(":volumeTypeId")213 key := portal.Ctx.Input.Param(":key")214 NewClient(portal.Ctx)215 err := opensdsClient.RemoveCustomProperty(id, key)216 if err != nil {217 reason := fmt.Sprintf("Delete extra specification for volume type failed: %s", err.Error())218 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)219 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))220 log.Error(reason)221 return222 }223 portal.Ctx.Output.SetStatus(http.StatusAccepted)224 return225}226// GetType ...227func (portal *TypePortal) GetType() {228 id := portal.Ctx.Input.Param(":volumeTypeId")229 DefaultName := os.Getenv("DEFAULT_VOLUME_TYPE_NAME")230 if ("" != DefaultName) && (DefaultTypeName != DefaultName) {231 DefaultTypeName = DefaultName232 log.Info("DefaultTypeName = " + DefaultTypeName)233 }234 var profile *model.ProfileSpec235 NewClient(portal.Ctx)236 if "default" != id {237 foundProfile, err := opensdsClient.GetProfile(id)238 if err != nil {239 reason := fmt.Sprintf("Get profile failed: %v", err)240 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)241 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))242 log.Error(reason)243 return244 }245 profile = foundProfile246 } else {247 profiles, err := opensdsClient.ListProfiles()248 if err != nil {249 reason := fmt.Sprintf("List profiles failed: %v", err)250 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)251 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))252 log.Error(reason)253 return254 }255 for _, v := range profiles {256 if DefaultTypeName == v.Name {257 profile = v258 }259 }260 if nil == profile {261 reason := "Default volume type can not be found"262 portal.Ctx.Output.SetStatus(http.StatusNotFound)263 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))264 log.Error(reason)265 return266 }267 }268 result := converter.ShowTypeResp(profile)269 body, err := json.Marshal(result)270 if err != nil {271 reason := fmt.Sprintf("Show volume type detail, marshal result failed: %v", err)272 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)273 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))274 log.Error(reason)275 return276 }277 portal.Ctx.Output.SetStatus(http.StatusOK)278 portal.Ctx.Output.Body(body)279 return280}281// DeleteType ...282func (portal *TypePortal) DeleteType() {283 id := portal.Ctx.Input.Param(":volumeTypeId")284 NewClient(portal.Ctx)285 err := opensdsClient.DeleteProfile(id)286 if err != nil {287 reason := fmt.Sprintf("Delete a volume type failed: %v", err)288 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)289 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))290 log.Error(reason)291 return292 }293 portal.Ctx.Output.SetStatus(http.StatusAccepted)294 return295}296// ListTypes ...297func (portal *TypePortal) ListTypes() {298 NewClient(portal.Ctx)299 profiles, err := opensdsClient.ListProfiles()300 if err != nil {301 reason := fmt.Sprintf("List all volume types failed: %v", err)302 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)303 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))304 log.Error(reason)305 return306 }307 result := converter.ListTypesResp(profiles)308 body, err := json.Marshal(result)309 if err != nil {310 reason := fmt.Sprintf("List all volume types, marshal result failed: %v", err)311 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)312 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))313 log.Error(reason)314 return315 }316 portal.Ctx.Output.SetStatus(http.StatusOK)317 portal.Ctx.Output.Body(body)318 return319}320// CreateType ...321func (portal *TypePortal) CreateType() {322 var cinderReq = converter.CreateTypeReqSpec{}323 if err := json.NewDecoder(portal.Ctx.Request.Body).Decode(&cinderReq); err != nil {324 reason := fmt.Sprintf("Create a volume type, parse request body failed: %s", err.Error())325 portal.Ctx.Output.SetStatus(model.ErrorBadRequest)326 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))327 log.Error(reason)328 return329 }330 profile, err := converter.CreateTypeReq(&cinderReq)331 if err != nil {332 reason := fmt.Sprintf("Create a volume type failed: %s", err.Error())333 portal.Ctx.Output.SetStatus(model.ErrorBadRequest)334 portal.Ctx.Output.Body(model.ErrorBadRequestStatus(reason))335 log.Error(reason)336 return337 }338 NewClient(portal.Ctx)339 profile, err = opensdsClient.CreateProfile(profile)340 if err != nil {341 reason := fmt.Sprintf("Create a volume type failed: %s", err.Error())342 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)343 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))344 log.Error(reason)345 return346 }347 result := converter.CreateTypeResp(profile)348 body, err := json.Marshal(result)349 if err != nil {350 reason := fmt.Sprintf("Create a volume type, marshal result failed: %s", err.Error())351 portal.Ctx.Output.SetStatus(model.ErrorInternalServer)352 portal.Ctx.Output.Body(model.ErrorInternalServerStatus(reason))353 log.Error(reason)354 return355 }356 portal.Ctx.Output.SetStatus(http.StatusOK)357 portal.Ctx.Output.Body(body)358 return359}...

Full Screen

Full Screen

client.go

Source:client.go Github

copy

Full Screen

...103 c.arrBehavior[c.status]()104 }105 }106}107func (c *Client) SetStatus(status int32) {108 c.status = status109}110func (c *Client) GetStatus() int32 {111 return c.status112}113func (c *Client) calcSign(params []string) string {114 strSrc := fmt.Sprintf("%s%s", strings.Join(params, ""), GlobalConfig.ClientKey)115 sum := md5.Sum([]byte(strSrc))116 return hex.EncodeToString(append(sum[:]))117}118type LoginAccountRsp struct {119 Code int32 `json:"code"`120 AccountId int64 `json:"account_id"`121 Token string `json:"token"`122 Ts int64 `json:"ts"`123}124func (c *Client) LoginAccount() {125 curTs := vgtime.Now()126 sign := c.calcSign([]string{strconv.Itoa(int(c.loginType)), c.accountName, c.password, strconv.FormatInt(curTs, 10)})127 resp, err := http.Get(fmt.Sprintf("%s/login?login_type=%d&account_name=%s&password=%s&time=%d&sign=%s",128 GlobalConfig.LoginServerAddr, c.loginType, c.accountName, c.password, curTs, sign))129 if err != nil {130 logger.Error(err)131 c.SetStatus(ClientStatus_Close)132 return133 }134 defer resp.Body.Close()135 rspBuf, err := ioutil.ReadAll(resp.Body)136 if err != nil {137 logger.Error(err)138 c.SetStatus(ClientStatus_Close)139 return140 }141 rsp := LoginAccountRsp{}142 err = json.Unmarshal(rspBuf, &rsp)143 if err != nil {144 logger.Error(err)145 c.SetStatus(ClientStatus_Close)146 return147 }148 if rsp.Code == ec.AccountNotFound {149 logger.Debugf("%s: account not found, try register", c.accountName)150 c.SetStatus(ClientStatus_RegisterAccount)151 } else if rsp.Code == ec.Success {152 c.accountId = rsp.AccountId153 c.token = rsp.Token154 c.ts = rsp.Ts155 logger.Debugf("%s: login account suc", c.accountName)156 c.SetStatus(ClientStatus_GetServerInfo)157 } else {158 logger.Debugf("%s: login account fail", c.accountName)159 c.SetStatus(ClientStatus_Close)160 }161}162type CodeRsp struct {163 Code int32 `json:"code"`164}165func (c *Client) RegisterAccount() {166 curTs := vgtime.Now()167 sign := c.calcSign([]string{c.accountName, c.password, strconv.FormatInt(curTs, 10)})168 resp, err := http.Get(fmt.Sprintf("%s/register?account_name=%s&password=%s&time=%d&sign=%s",169 GlobalConfig.LoginServerAddr, c.accountName, c.password, curTs, sign))170 if err != nil {171 logger.Error(err)172 c.SetStatus(ClientStatus_Close)173 return174 }175 defer resp.Body.Close()176 rspBuf, err := ioutil.ReadAll(resp.Body)177 if err != nil {178 logger.Error(err)179 c.SetStatus(ClientStatus_Close)180 return181 }182 rsp := CodeRsp{}183 err = json.Unmarshal(rspBuf, &rsp)184 if err != nil {185 logger.Error(err)186 c.SetStatus(ClientStatus_Close)187 return188 }189 if rsp.Code == ec.Success {190 logger.Debugf("%s: register account suc", c.accountName)191 c.SetStatus(ClientStatus_LoginAccount)192 } else {193 logger.Debugf("%s: register account fail", c.accountName)194 c.SetStatus(ClientStatus_Close)195 }196}197type GameServer struct {198 ServerId int32199 Name string200 Status int32201 Addr string202}203type ServerInfoRsp struct {204 Code int32 `json:"code"`205 Server map[int32]*GameServer `json:"server"`206}207func (c *Client) GetServerInfo() {208 resp, err := http.Get(fmt.Sprintf("%s/server_list", GlobalConfig.LoginServerAddr))209 if err != nil {210 logger.Error(err)211 c.SetStatus(ClientStatus_Close)212 return213 }214 defer resp.Body.Close()215 rspBuf, err := ioutil.ReadAll(resp.Body)216 if err != nil {217 logger.Error(err)218 c.SetStatus(ClientStatus_Close)219 return220 }221 rsp := ServerInfoRsp{}222 err = json.Unmarshal(rspBuf, &rsp)223 if err != nil {224 logger.Error(err)225 c.SetStatus(ClientStatus_Close)226 return227 }228 if rsp.Code == ec.Success {229 logger.Debugf("%s: get server info suc", c.accountName)230 c.gsAddr = "ws://" + rsp.Server[1].Addr231 c.SetStatus(ClientStatus_LoginGame)232 } else {233 logger.Debugf("%s: get server info fail", c.accountName)234 c.SetStatus(ClientStatus_Close)235 }236}237func (c *Client) LoginGame() {238 wg := sync.WaitGroup{}239 wg.Add(1)240 bConnectSuc := false241 websocket.Dialer.Dial(c.gsAddr, func(conn network.Connection, e error) {242 if e != nil {243 return244 }245 conn.Accept(c)246 c.conn = conn247 bConnectSuc = true248 wg.Done()249 })250 wg.Wait()251 if !bConnectSuc {252 c.SetStatus(ClientStatus_Close)253 }254 pMsgReq := new(msg.C2S_Login)255 pMsgReq.AccountId = c.accountId256 pMsgReq.Token = c.token257 pMsgReq.ServerId = 1258 pMsgReq.Ts = c.ts259 c.Write(pMsgReq)260 pMsgRsp := c.WaitResponse(&msg.S2C_Login{}).(*msg.S2C_Login)261 if pMsgRsp.Code != ec.Success {262 logger.Debugf("%s: login game server fail", c.accountName)263 c.SetStatus(ClientStatus_Close)264 return265 }266 logger.Debugf("%s: login game server suc", c.accountName)267 if pMsgRsp.PlayerId == 0 {268 c.SetStatus(ClientStatus_CreateCharacter)269 return270 } else {271 c.SetStatus(ClientStatus_Close)272 return273 }274}275func (c *Client) CreateCharacter() {276 pMsgReq := new(msg.C2S_CreateCharacter)277 pMsgReq.Name = strconv.FormatUint(rand.Uint64(), 16)278 c.Write(pMsgReq)279 pMsgRsp := c.WaitResponse(&msg.S2C_CreateCharacter{}).(*msg.S2C_CreateCharacter)280 if pMsgRsp.Code != ec.Success {281 c.SetStatus(ClientStatus_Close)282 return283 } else {284 logger.Debugf("%s: create character success", c.accountName)285 c.SetStatus(ClientStatus_Close)286 return287 }288}289func (c *Client) Write(msg proto.Message) {290 c.conn.Write(msg)291}292func (c *Client) WaitResponse(msg proto.Message) proto.Message {293 c.waitMsgId = msgDesc.GetMessageId(msg)294 rsp := <-c.waitChan295 c.waitMsgId = 0296 return rsp297}298func (c *Client) OnClose(err error) {299 if err != nil {...

Full Screen

Full Screen

SetStatus

Using AI Code Generation

copy

Full Screen

1client.SetStatus(1)2client.SetStatus(2)3client.SetStatus(3)4client.SetStatus(4)5client.SetStatus(5)6client.SetStatus(6)7client.SetStatus(7)8client.SetStatus(8)9client.SetStatus(9)10client.SetStatus(10)11client.SetStatus(11)12client.SetStatus(12)13client.SetStatus(13)14client.SetStatus(14)15client.SetStatus(15)16client.SetStatus(16)17client.SetStatus(17)18client.SetStatus(18)19client.SetStatus(19)20client.SetStatus(20)21client.SetStatus(21)

Full Screen

Full Screen

SetStatus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())4 if err != nil {5 grpclog.Fatalf("did not connect: %v", err)6 }7 defer conn.Close()8 c := helloworld.NewGreeterClient(conn)9 r, err := c.SayHello(context.Background(), &helloworld.HelloRequest{Name: name})10 if err != nil {11 grpclog.Fatalf("could not greet: %v", err)12 }13 fmt.Println(r.Message)14 st := status.New(codes.Unauthenticated, "unauthenticated")15 err = st.Err()16 grpclog.Fatalf("could not greet: %v", err)17}

Full Screen

Full Screen

SetStatus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config := sarama.NewConfig()4 client, err := sarama.NewClient([]string{"localhost:9092"}, config)5 if err != nil {6 log.Fatal(err)7 }8 defer func() {9 if err := client.Close(); err != nil {10 log.Fatal(err)11 }12 }()13 err = client.SetStatus("my_topic", true)14 if err != nil {15 log.Fatal(err)16 }17 status, err := client.GetStatus("my_topic")18 if err != nil {19 log.Fatal(err)20 }21 fmt.Println(status)22}

Full Screen

Full Screen

SetStatus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 config := sarama.NewConfig()5 p, err := sarama.NewAsyncProducer([]string{"localhost:9092"}, config)6 if err != nil {7 panic(err)8 }9 defer p.Close()10 select {11 case <-p.AsyncCloseChan():12 case err := <-p.Errors():13 panic(err)14 case <-p.Successes():15 }16 status := &sarama.ControllerStatus{17 }18 client := sarama.NewClient([]string{"localhost:9092"}, config)19 err = client.SetController(status)20 if err != nil {21 panic(err)22 }23 client.Close()24}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful