How to use Copy method of ctxerr Package

Best Go-testdeep code snippet using ctxerr.Copy

webapp.go

Source:webapp.go Github

copy

Full Screen

...36 if err != nil {37 return nil, failure.Wrap(err, failure.Message("POST /initialize: リクエストに失敗しました"))38 }39 defer res.Body.Close()40 defer io.Copy(ioutil.Discard, res.Body)41 // MEMO: /initializeの成功ステータスによって第二引数が変わる可能性がある42 err = checkStatusCode(res, []int{http.StatusOK})43 if err != nil {44 return nil, failure.Wrap(err, failure.Message("POST /initialize: レスポンスコードが不正です"))45 }46 var initRes InitializeResponse47 err = json.NewDecoder(res.Body).Decode(&initRes)48 if err != nil {49 if ctxErr := ctx.Err(); ctxErr != nil {50 return nil, ctxErr51 }52 return nil, failure.Wrap(err, failure.Message("POST /initialize: JSONデコードに失敗しました"))53 }54 if initRes.Language == "" {55 return nil, failure.New(fails.ErrApplication, failure.Message("POST /initialize: 実装言語が設定されていません"))56 }57 return &initRes, nil58}59type ChairsResponse struct {60 Count int64 `json:"count"`61 Chairs []asset.Chair `json:"chairs"`62}63type EstatesResponse struct {64 Count int64 `json:"count"`65 Estates []asset.Estate `json:"estates"`66}67func (c *Client) GetChairDetailFromID(ctx context.Context, id string) (*asset.Chair, error) {68 req, err := c.newGetRequest(ShareTargetURLs.AppURL, "/api/chair/"+id)69 if err != nil {70 return nil, failure.Translate(err, fails.ErrBenchmarker)71 }72 req = req.WithContext(ctx)73 res, err := c.Do(req)74 if err != nil {75 if ctxErr := ctx.Err(); ctxErr != nil {76 return nil, ctxErr77 }78 return nil, failure.Wrap(err, failure.Message("GET /api/chair/:id: リクエストに失敗しました"))79 }80 defer res.Body.Close()81 defer io.Copy(ioutil.Discard, res.Body)82 err = checkStatusCode(res, []int{http.StatusOK, http.StatusNotFound})83 if err != nil {84 if c.isBot {85 return nil, failure.Translate(err, fails.ErrBot)86 }87 return nil, failure.Wrap(err, failure.Message("GET /api/chair/:id: レスポンスコードが不正です"))88 }89 if res.StatusCode == http.StatusNotFound {90 _, err = io.Copy(ioutil.Discard, res.Body)91 if err != nil {92 return nil, failure.Translate(err, fails.ErrBenchmarker)93 }94 return nil, nil95 }96 var chair asset.Chair97 err = json.NewDecoder(res.Body).Decode(&chair)98 if err != nil {99 if ctxErr := ctx.Err(); ctxErr != nil {100 return nil, ctxErr101 }102 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {103 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/chair/:id: リクエストに失敗しました"))104 }105 return nil, failure.Wrap(err, failure.Message("GET /api/chair/:id: JSONデコードに失敗しました"))106 }107 return &chair, nil108}109func (c *Client) PostChairs(ctx context.Context, chairs []asset.Chair) error {110 var (111 b bytes.Buffer112 fw io.Writer113 err error114 )115 w := multipart.NewWriter(&b)116 csv := ""117 for _, chair := range chairs {118 csv += chair.ToCSV()119 asset.StoreChair(chair)120 }121 r := strings.NewReader(csv)122 if fw, err = w.CreateFormFile("chairs", "chairs.csv"); err != nil {123 return failure.Translate(err, fails.ErrBenchmarker)124 }125 if _, err := io.Copy(fw, r); err != nil {126 return failure.Translate(err, fails.ErrBenchmarker)127 }128 w.Close()129 req, err := c.newPostRequest(ShareTargetURLs.AppURL, "/api/chair", &b)130 if err != nil {131 return failure.Translate(err, fails.ErrBenchmarker)132 }133 req.Header.Set("Content-Type", w.FormDataContentType())134 req = req.WithContext(ctx)135 res, err := c.Do(req)136 if err != nil {137 if ctxErr := ctx.Err(); ctxErr != nil {138 return ctxErr139 }140 return failure.Wrap(err, failure.Message("POST /api/chair: リクエストに失敗しました"))141 }142 defer res.Body.Close()143 defer io.Copy(ioutil.Discard, res.Body)144 err = checkStatusCode(res, []int{http.StatusCreated})145 if err != nil {146 if c.isBot {147 return failure.Translate(err, fails.ErrBot)148 }149 return failure.Wrap(err, failure.Message("POST /api/chair: リクエストに失敗しました"))150 }151 return nil152}153func (c *Client) GetChairSearchCondition(ctx context.Context) (*asset.ChairSearchCondition, error) {154 req, err := c.newGetRequest(ShareTargetURLs.AppURL, "/api/chair/search/condition")155 if err != nil {156 return nil, failure.Translate(err, fails.ErrBenchmarker)157 }158 req = req.WithContext(ctx)159 res, err := c.Do(req)160 if err != nil {161 if ctxErr := ctx.Err(); ctxErr != nil {162 return nil, ctxErr163 }164 return nil, failure.Wrap(err, failure.Message("GET /api/chair/search/condition: リクエストに失敗しました"))165 }166 err = checkStatusCode(res, []int{http.StatusOK})167 if err != nil {168 return nil, failure.Wrap(err, failure.Message("GET /api/chair/search/condition: レスポンスコードが不正です"))169 }170 defer res.Body.Close()171 defer io.Copy(ioutil.Discard, res.Body)172 var condition asset.ChairSearchCondition173 err = json.NewDecoder(res.Body).Decode(&condition)174 if err != nil {175 if ctxErr := ctx.Err(); ctxErr != nil {176 return nil, ctxErr177 }178 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {179 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/chair/search/condition: リクエストに失敗しました"))180 }181 return nil, failure.Wrap(err, failure.Message("GET /api/chair/search/condition: JSONデコードに失敗しました"))182 }183 return &condition, nil184}185func (c *Client) SearchChairsWithQuery(ctx context.Context, q url.Values) (*ChairsResponse, error) {186 req, err := c.newGetRequestWithQuery(ShareTargetURLs.AppURL, "/api/chair/search", q)187 if err != nil {188 return nil, failure.Translate(err, fails.ErrBenchmarker)189 }190 req = req.WithContext(ctx)191 res, err := c.Do(req)192 if err != nil {193 if ctxErr := ctx.Err(); ctxErr != nil {194 return nil, ctxErr195 }196 return nil, failure.Wrap(err, failure.Message("GET /api/chair/search: リクエストに失敗しました"))197 }198 defer res.Body.Close()199 defer io.Copy(ioutil.Discard, res.Body)200 err = checkStatusCode(res, []int{http.StatusOK})201 if err != nil {202 if c.isBot {203 return nil, failure.Translate(err, fails.ErrBot)204 }205 return nil, failure.Wrap(err, failure.Message("GET /api/chair/search: レスポンスコードが不正です"))206 }207 var chairs ChairsResponse208 err = json.NewDecoder(res.Body).Decode(&chairs)209 if err != nil {210 if ctxErr := ctx.Err(); ctxErr != nil {211 return nil, ctxErr212 }213 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {214 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/chair/search: リクエストに失敗しました"))215 }216 return nil, failure.Wrap(err, failure.Message("GET /api/chair/search: JSONデコードに失敗しました"))217 }218 return &chairs, nil219}220func (c *Client) GetEstateSearchCondition(ctx context.Context) (*asset.EstateSearchCondition, error) {221 req, err := c.newGetRequest(ShareTargetURLs.AppURL, "/api/estate/search/condition")222 if err != nil {223 return nil, failure.Translate(err, fails.ErrBenchmarker)224 }225 req = req.WithContext(ctx)226 res, err := c.Do(req)227 if err != nil {228 if ctxErr := ctx.Err(); ctxErr != nil {229 return nil, ctxErr230 }231 return nil, failure.Wrap(err, failure.Message("GET /api/estate/search/condition: リクエストに失敗しました"))232 }233 err = checkStatusCode(res, []int{http.StatusOK})234 if err != nil {235 return nil, failure.Wrap(err, failure.Message("GET /api/estate/search/condition: レスポンスコードが不正です"))236 }237 defer res.Body.Close()238 defer io.Copy(ioutil.Discard, res.Body)239 var condition asset.EstateSearchCondition240 err = json.NewDecoder(res.Body).Decode(&condition)241 if err != nil {242 if ctxErr := ctx.Err(); ctxErr != nil {243 return nil, ctxErr244 }245 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {246 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/estate/search/condition: リクエストに失敗しました"))247 }248 return nil, failure.Wrap(err, failure.Message("GET /api/estate/search/condition: JSONデコードに失敗しました"))249 }250 return &condition, nil251}252func (c *Client) SearchEstatesWithQuery(ctx context.Context, q url.Values) (*EstatesResponse, error) {253 req, err := c.newGetRequestWithQuery(ShareTargetURLs.AppURL, "/api/estate/search", q)254 if err != nil {255 return nil, failure.Translate(err, fails.ErrBenchmarker)256 }257 req = req.WithContext(ctx)258 res, err := c.Do(req)259 if err != nil {260 if ctxErr := ctx.Err(); ctxErr != nil {261 return nil, ctxErr262 }263 return nil, failure.Wrap(err, failure.Message("GET /api/estate/search: リクエストに失敗しました"))264 }265 defer res.Body.Close()266 defer io.Copy(ioutil.Discard, res.Body)267 err = checkStatusCode(res, []int{http.StatusOK})268 if err != nil {269 if c.isBot {270 return nil, failure.Translate(err, fails.ErrBot)271 }272 return nil, failure.Wrap(err, failure.Message("GET /api/estate/search: レスポンスコードが不正です"))273 }274 var estates EstatesResponse275 err = json.NewDecoder(res.Body).Decode(&estates)276 if err != nil {277 if ctxErr := ctx.Err(); ctxErr != nil {278 return nil, ctxErr279 }280 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {281 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/estate/search: リクエストに失敗しました"))282 }283 return nil, failure.Wrap(err, failure.Message("GET /api/estate/search: JSONデコードに失敗しました"))284 }285 return &estates, nil286}287func (c *Client) SearchEstatesNazotte(ctx context.Context, polygon *Coordinates) (*EstatesResponse, error) {288 b, err := json.Marshal(polygon)289 if err != nil {290 return nil, failure.Translate(err, fails.ErrBenchmarker)291 }292 req, err := c.newPostRequest(ShareTargetURLs.AppURL, "/api/estate/nazotte", bytes.NewBuffer(b))293 if err != nil {294 return nil, failure.Translate(err, fails.ErrBenchmarker)295 }296 req = req.WithContext(ctx)297 res, err := c.Do(req)298 if err != nil {299 if ctxErr := ctx.Err(); ctxErr != nil {300 return nil, ctxErr301 }302 return nil, failure.Wrap(err, failure.Message("POST /api/estate/nazotte: リクエストに失敗しました"))303 }304 defer res.Body.Close()305 defer io.Copy(ioutil.Discard, res.Body)306 err = checkStatusCode(res, []int{http.StatusOK})307 if err != nil {308 if c.isBot {309 return nil, failure.Translate(err, fails.ErrBot)310 }311 return nil, failure.Wrap(err, failure.Message("POST /api/estate/nazotte: レスポンスコードが不正です"))312 }313 var estates EstatesResponse314 err = json.NewDecoder(res.Body).Decode(&estates)315 if err != nil {316 if ctxErr := ctx.Err(); ctxErr != nil {317 return nil, ctxErr318 }319 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {320 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("POST /api/estate/nazotte: リクエストに失敗しました"))321 }322 return nil, failure.Wrap(err, failure.Message("POST /api/estate/nazotte: JSONデコードに失敗しました"))323 }324 return &estates, nil325}326func (c *Client) GetEstateDetailFromID(ctx context.Context, id string) (*asset.Estate, error) {327 req, err := c.newGetRequest(ShareTargetURLs.AppURL, "/api/estate/"+id)328 if err != nil {329 return nil, failure.Translate(err, fails.ErrBenchmarker)330 }331 req = req.WithContext(ctx)332 res, err := c.Do(req)333 if err != nil {334 if ctxErr := ctx.Err(); ctxErr != nil {335 return nil, ctxErr336 }337 return nil, failure.Wrap(err, failure.Message("GET /api/estate/:id: リクエストに失敗しました"))338 }339 defer res.Body.Close()340 defer io.Copy(ioutil.Discard, res.Body)341 err = checkStatusCode(res, []int{http.StatusOK})342 if err != nil {343 if c.isBot {344 return nil, failure.Translate(err, fails.ErrBot)345 }346 return nil, failure.Wrap(err, failure.Message("GET /api/estate/:id: レスポンスコードが不正です"))347 }348 var estate asset.Estate349 err = json.NewDecoder(res.Body).Decode(&estate)350 if err != nil {351 if ctxErr := ctx.Err(); ctxErr != nil {352 return nil, ctxErr353 }354 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {355 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/estate/:id: リクエストに失敗しました"))356 }357 return nil, failure.Wrap(err, failure.Message("GET /api/estate/:id: JSONデコードに失敗しました"))358 }359 return &estate, nil360}361func (c *Client) PostEstates(ctx context.Context, estates []asset.Estate) error {362 var (363 b bytes.Buffer364 fw io.Writer365 err error366 )367 w := multipart.NewWriter(&b)368 csv := ""369 for _, estate := range estates {370 csv += estate.ToCSV()371 asset.StoreEstate(estate)372 }373 r := strings.NewReader(csv)374 if fw, err = w.CreateFormFile("estates", "estates.csv"); err != nil {375 return failure.Translate(err, fails.ErrBenchmarker)376 }377 if _, err := io.Copy(fw, r); err != nil {378 return failure.Translate(err, fails.ErrBenchmarker)379 }380 w.Close()381 req, err := c.newPostRequest(ShareTargetURLs.AppURL, "/api/estate", &b)382 if err != nil {383 return failure.Translate(err, fails.ErrBenchmarker)384 }385 req.Header.Set("Content-Type", w.FormDataContentType())386 req = req.WithContext(ctx)387 res, err := c.Do(req)388 if err != nil {389 if ctxErr := ctx.Err(); ctxErr != nil {390 return ctxErr391 }392 return failure.Wrap(err, failure.Message("POST /api/estate: リクエストに失敗しました"))393 }394 defer res.Body.Close()395 defer io.Copy(ioutil.Discard, res.Body)396 err = checkStatusCode(res, []int{http.StatusCreated})397 if err != nil {398 if c.isBot {399 return failure.Translate(err, fails.ErrBot)400 }401 return failure.Wrap(err, failure.Message("POST /api/estate: リクエストに失敗しました"))402 }403 return nil404}405func (c *Client) GetLowPricedChair(ctx context.Context) (*ChairsResponse, error) {406 req, err := c.newGetRequest(ShareTargetURLs.AppURL, "/api/chair/low_priced")407 if err != nil {408 return nil, failure.Translate(err, fails.ErrBenchmarker)409 }410 req = req.WithContext(ctx)411 res, err := c.Do(req)412 if err != nil {413 if ctxErr := ctx.Err(); ctxErr != nil {414 return nil, ctxErr415 }416 return nil, failure.Wrap(err, failure.Message("GET /api/chair/low_priced: リクエストに失敗しました"))417 }418 defer res.Body.Close()419 defer io.Copy(ioutil.Discard, res.Body)420 err = checkStatusCode(res, []int{http.StatusOK})421 if err != nil {422 if c.isBot {423 return nil, failure.Translate(err, fails.ErrBot)424 }425 return nil, failure.Wrap(err, failure.Message("GET /api/chair/low_priced: レスポンスコードが不正です"))426 }427 var chairs ChairsResponse428 err = json.NewDecoder(res.Body).Decode(&chairs)429 if err != nil {430 if ctxErr := ctx.Err(); ctxErr != nil {431 return nil, ctxErr432 }433 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {434 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/chair/low_priced: リクエストに失敗しました"))435 }436 return nil, failure.Wrap(err, failure.Message("GET /api/chair/low_priced: JSONデコードに失敗しました"))437 }438 return &chairs, nil439}440func (c *Client) GetLowPricedEstate(ctx context.Context) (*EstatesResponse, error) {441 req, err := c.newGetRequest(ShareTargetURLs.AppURL, "/api/estate/low_priced")442 if err != nil {443 return nil, failure.Translate(err, fails.ErrBenchmarker)444 }445 req = req.WithContext(ctx)446 res, err := c.Do(req)447 if err != nil {448 if ctxErr := ctx.Err(); ctxErr != nil {449 return nil, ctxErr450 }451 return nil, failure.Wrap(err, failure.Message("GET /api/estate/low_priced: リクエストに失敗しました"))452 }453 defer res.Body.Close()454 defer io.Copy(ioutil.Discard, res.Body)455 err = checkStatusCode(res, []int{http.StatusOK})456 if err != nil {457 if c.isBot {458 return nil, failure.Translate(err, fails.ErrBot)459 }460 return nil, failure.Wrap(err, failure.Message("GET /api/estate/low_priced: レスポンスコードが不正です"))461 }462 var estate EstatesResponse463 err = json.NewDecoder(res.Body).Decode(&estate)464 if err != nil {465 if ctxErr := ctx.Err(); ctxErr != nil {466 return nil, ctxErr467 }468 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {469 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/estate/low_priced: リクエストに失敗しました"))470 }471 return nil, failure.Wrap(err, failure.Message("GET /api/estate/low_priced: JSONデコードに失敗しました"))472 }473 return &estate, nil474}475func (c *Client) GetRecommendedEstatesFromChair(ctx context.Context, id int64) (*EstatesResponse, error) {476 req, err := c.newGetRequest(ShareTargetURLs.AppURL, "/api/recommended_estate/"+strconv.FormatInt(id, 10))477 if err != nil {478 return nil, failure.Translate(err, fails.ErrBenchmarker)479 }480 req = req.WithContext(ctx)481 res, err := c.Do(req)482 if err != nil {483 if ctxErr := ctx.Err(); ctxErr != nil {484 return nil, ctxErr485 }486 return nil, failure.Wrap(err, failure.Message("GET /api/recommended_estate/:id: リクエストに失敗しました"))487 }488 defer res.Body.Close()489 defer io.Copy(ioutil.Discard, res.Body)490 err = checkStatusCode(res, []int{http.StatusOK})491 if err != nil {492 if c.isBot {493 return nil, failure.Translate(err, fails.ErrBot)494 }495 return nil, failure.Wrap(err, failure.Message("GET /api/recommended_estate/:id: レスポンスコードが不正です"))496 }497 var estate EstatesResponse498 err = json.NewDecoder(res.Body).Decode(&estate)499 if err != nil {500 if ctxErr := ctx.Err(); ctxErr != nil {501 return nil, ctxErr502 }503 if nerr, ok := err.(interface{ Timeout() bool }); ok && nerr.Timeout() {504 return nil, failure.Translate(err, fails.ErrTimeout, failure.Message("GET /api/recommended_estate/:id: リクエストに失敗しました"))505 }506 return nil, failure.Wrap(err, failure.Message("GET /api/recommended_estate/:id: JSONデコードに失敗しました"))507 }508 return &estate, nil509}510type EmailRequest struct {511 Email string `json:"email"`512}513func (c *Client) BuyChair(ctx context.Context, id string) error {514 jsonStr, err := json.Marshal(EmailRequest{Email: c.GetEmail()})515 if err != nil {516 return failure.Translate(err, fails.ErrBenchmarker)517 }518 req, err := c.newPostRequest(ShareTargetURLs.AppURL, "/api/chair/buy/"+id, bytes.NewBuffer(jsonStr))519 if err != nil {520 return failure.Translate(err, fails.ErrBenchmarker)521 }522 req = req.WithContext(ctx)523 res, err := c.Do(req)524 if err != nil {525 if ctxErr := ctx.Err(); ctxErr != nil {526 return ctxErr527 }528 return failure.Wrap(err, failure.Message("POST /api/chair/buy/:id: リクエストに失敗しました"))529 }530 defer res.Body.Close()531 defer io.Copy(ioutil.Discard, res.Body)532 err = checkStatusCode(res, []int{http.StatusOK})533 if err != nil {534 if c.isBot {535 return failure.Translate(err, fails.ErrBot)536 }537 return failure.Wrap(err, failure.Message("POST /api/chair/buy/:id: リクエストに失敗しました"))538 }539 intid, _ := strconv.ParseInt(id, 10, 64)540 asset.DecrementChairStock(intid)541 if !c.isBot {542 score.IncrementScore()543 }544 return nil545}546func (c *Client) RequestEstateDocument(ctx context.Context, id string) error {547 jsonStr, err := json.Marshal(EmailRequest{Email: c.GetEmail()})548 if err != nil {549 return failure.Translate(err, fails.ErrBenchmarker)550 }551 req, err := c.newPostRequest(ShareTargetURLs.AppURL, "/api/estate/req_doc/"+id, bytes.NewBuffer(jsonStr))552 if err != nil {553 return failure.Translate(err, fails.ErrBenchmarker)554 }555 req = req.WithContext(ctx)556 res, err := c.Do(req)557 if err != nil {558 if ctxErr := ctx.Err(); ctxErr != nil {559 return ctxErr560 }561 return failure.Wrap(err, failure.Message("POST /api/estate/req_doc/:id: リクエストに失敗しました"))562 }563 defer res.Body.Close()564 defer io.Copy(ioutil.Discard, res.Body)565 err = checkStatusCode(res, []int{http.StatusOK})566 if err != nil {567 if c.isBot {568 return failure.Translate(err, fails.ErrBot)569 }570 return failure.Wrap(err, failure.Message("POST /api/estate/req_doc/:id: リクエストに失敗しました"))571 }572 if !c.isBot {573 score.IncrementScore()574 }575 return nil576}...

Full Screen

Full Screen

kube_docker_client.go

Source:kube_docker_client.go Github

copy

Full Screen

1// +build !dockerless2/*3Copyright 2016 The Kubernetes Authors.4Licensed under the Apache License, Version 2.0 (the "License");5you may not use this file except in compliance with the License.6You may obtain a copy of the License at7 http://www.apache.org/licenses/LICENSE-2.08Unless required by applicable law or agreed to in writing, software9distributed under the License is distributed on an "AS IS" BASIS,10WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11See the License for the specific language governing permissions and12limitations under the License.13*/14package libdocker15import (16 "bytes"17 "context"18 "encoding/base64"19 "encoding/json"20 "fmt"21 "io"22 "io/ioutil"23 "regexp"24 "sync"25 "time"26 "k8s.io/klog/v2"27 dockertypes "github.com/docker/docker/api/types"28 dockercontainer "github.com/docker/docker/api/types/container"29 dockerimagetypes "github.com/docker/docker/api/types/image"30 dockerapi "github.com/docker/docker/client"31 dockermessage "github.com/docker/docker/pkg/jsonmessage"32 dockerstdcopy "github.com/docker/docker/pkg/stdcopy"33)34// kubeDockerClient is a wrapped layer of docker client for kubelet internal use. This layer is added to:35// 1) Redirect stream for exec and attach operations.36// 2) Wrap the context in this layer to make the Interface cleaner.37type kubeDockerClient struct {38 // timeout is the timeout of short running docker operations.39 timeout time.Duration40 // If no pulling progress is made before imagePullProgressDeadline, the image pulling will be cancelled.41 // Docker reports image progress for every 512kB block, so normally there shouldn't be too long interval42 // between progress updates.43 imagePullProgressDeadline time.Duration44 client *dockerapi.Client45}46// Make sure that kubeDockerClient implemented the Interface.47var _ Interface = &kubeDockerClient{}48// There are 2 kinds of docker operations categorized by running time:49// * Long running operation: The long running operation could run for arbitrary long time, and the running time50// usually depends on some uncontrollable factors. These operations include: PullImage, Logs, StartExec, AttachToContainer.51// * Non-long running operation: Given the maximum load of the system, the non-long running operation should finish52// in expected and usually short time. These include all other operations.53// kubeDockerClient only applies timeout on non-long running operations.54const (55 // defaultTimeout is the default timeout of short running docker operations.56 // Value is slightly offset from 2 minutes to make timeouts due to this57 // constant recognizable.58 defaultTimeout = 2*time.Minute - 1*time.Second59 // defaultShmSize is the default ShmSize to use (in bytes) if not specified.60 defaultShmSize = int64(1024 * 1024 * 64)61 // defaultImagePullingProgressReportInterval is the default interval of image pulling progress reporting.62 defaultImagePullingProgressReportInterval = 10 * time.Second63)64// newKubeDockerClient creates an kubeDockerClient from an existing docker client. If requestTimeout is 0,65// defaultTimeout will be applied.66func newKubeDockerClient(dockerClient *dockerapi.Client, requestTimeout, imagePullProgressDeadline time.Duration) Interface {67 if requestTimeout == 0 {68 requestTimeout = defaultTimeout69 }70 k := &kubeDockerClient{71 client: dockerClient,72 timeout: requestTimeout,73 imagePullProgressDeadline: imagePullProgressDeadline,74 }75 // Notice that this assumes that docker is running before kubelet is started.76 ctx, cancel := k.getTimeoutContext()77 defer cancel()78 dockerClient.NegotiateAPIVersion(ctx)79 return k80}81func (d *kubeDockerClient) ListContainers(options dockertypes.ContainerListOptions) ([]dockertypes.Container, error) {82 ctx, cancel := d.getTimeoutContext()83 defer cancel()84 containers, err := d.client.ContainerList(ctx, options)85 if ctxErr := contextError(ctx); ctxErr != nil {86 return nil, ctxErr87 }88 if err != nil {89 return nil, err90 }91 return containers, nil92}93func (d *kubeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJSON, error) {94 ctx, cancel := d.getTimeoutContext()95 defer cancel()96 containerJSON, err := d.client.ContainerInspect(ctx, id)97 if ctxErr := contextError(ctx); ctxErr != nil {98 return nil, ctxErr99 }100 if err != nil {101 return nil, err102 }103 return &containerJSON, nil104}105// InspectContainerWithSize is currently only used for Windows container stats106func (d *kubeDockerClient) InspectContainerWithSize(id string) (*dockertypes.ContainerJSON, error) {107 ctx, cancel := d.getTimeoutContext()108 defer cancel()109 // Inspects the container including the fields SizeRw and SizeRootFs.110 containerJSON, _, err := d.client.ContainerInspectWithRaw(ctx, id, true)111 if ctxErr := contextError(ctx); ctxErr != nil {112 return nil, ctxErr113 }114 if err != nil {115 return nil, err116 }117 return &containerJSON, nil118}119func (d *kubeDockerClient) CreateContainer(opts dockertypes.ContainerCreateConfig) (*dockercontainer.ContainerCreateCreatedBody, error) {120 ctx, cancel := d.getTimeoutContext()121 defer cancel()122 // we provide an explicit default shm size as to not depend on docker daemon.123 // TODO: evaluate exposing this as a knob in the API124 if opts.HostConfig != nil && opts.HostConfig.ShmSize <= 0 {125 opts.HostConfig.ShmSize = defaultShmSize126 }127 createResp, err := d.client.ContainerCreate(ctx, opts.Config, opts.HostConfig, opts.NetworkingConfig, opts.Name)128 if ctxErr := contextError(ctx); ctxErr != nil {129 return nil, ctxErr130 }131 if err != nil {132 return nil, err133 }134 return &createResp, nil135}136func (d *kubeDockerClient) StartContainer(id string) error {137 ctx, cancel := d.getTimeoutContext()138 defer cancel()139 err := d.client.ContainerStart(ctx, id, dockertypes.ContainerStartOptions{})140 if ctxErr := contextError(ctx); ctxErr != nil {141 return ctxErr142 }143 return err144}145// Stopping an already stopped container will not cause an error in dockerapi.146func (d *kubeDockerClient) StopContainer(id string, timeout time.Duration) error {147 ctx, cancel := d.getCustomTimeoutContext(timeout)148 defer cancel()149 err := d.client.ContainerStop(ctx, id, &timeout)150 if ctxErr := contextError(ctx); ctxErr != nil {151 return ctxErr152 }153 return err154}155func (d *kubeDockerClient) RemoveContainer(id string, opts dockertypes.ContainerRemoveOptions) error {156 ctx, cancel := d.getTimeoutContext()157 defer cancel()158 err := d.client.ContainerRemove(ctx, id, opts)159 if ctxErr := contextError(ctx); ctxErr != nil {160 return ctxErr161 }162 return err163}164func (d *kubeDockerClient) UpdateContainerResources(id string, updateConfig dockercontainer.UpdateConfig) error {165 ctx, cancel := d.getTimeoutContext()166 defer cancel()167 _, err := d.client.ContainerUpdate(ctx, id, updateConfig)168 if ctxErr := contextError(ctx); ctxErr != nil {169 return ctxErr170 }171 return err172}173func (d *kubeDockerClient) inspectImageRaw(ref string) (*dockertypes.ImageInspect, error) {174 ctx, cancel := d.getTimeoutContext()175 defer cancel()176 resp, _, err := d.client.ImageInspectWithRaw(ctx, ref)177 if ctxErr := contextError(ctx); ctxErr != nil {178 return nil, ctxErr179 }180 if err != nil {181 if dockerapi.IsErrNotFound(err) {182 err = ImageNotFoundError{ID: ref}183 }184 return nil, err185 }186 return &resp, nil187}188func (d *kubeDockerClient) InspectImageByID(imageID string) (*dockertypes.ImageInspect, error) {189 resp, err := d.inspectImageRaw(imageID)190 if err != nil {191 return nil, err192 }193 if !matchImageIDOnly(*resp, imageID) {194 return nil, ImageNotFoundError{ID: imageID}195 }196 return resp, nil197}198func (d *kubeDockerClient) InspectImageByRef(imageRef string) (*dockertypes.ImageInspect, error) {199 resp, err := d.inspectImageRaw(imageRef)200 if err != nil {201 return nil, err202 }203 if !matchImageTagOrSHA(*resp, imageRef) {204 return nil, ImageNotFoundError{ID: imageRef}205 }206 return resp, nil207}208func (d *kubeDockerClient) ImageHistory(id string) ([]dockerimagetypes.HistoryResponseItem, error) {209 ctx, cancel := d.getTimeoutContext()210 defer cancel()211 resp, err := d.client.ImageHistory(ctx, id)212 if ctxErr := contextError(ctx); ctxErr != nil {213 return nil, ctxErr214 }215 return resp, err216}217func (d *kubeDockerClient) ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.ImageSummary, error) {218 ctx, cancel := d.getTimeoutContext()219 defer cancel()220 images, err := d.client.ImageList(ctx, opts)221 if ctxErr := contextError(ctx); ctxErr != nil {222 return nil, ctxErr223 }224 if err != nil {225 return nil, err226 }227 return images, nil228}229func base64EncodeAuth(auth dockertypes.AuthConfig) (string, error) {230 var buf bytes.Buffer231 if err := json.NewEncoder(&buf).Encode(auth); err != nil {232 return "", err233 }234 return base64.URLEncoding.EncodeToString(buf.Bytes()), nil235}236// progress is a wrapper of dockermessage.JSONMessage with a lock protecting it.237type progress struct {238 sync.RWMutex239 // message stores the latest docker json message.240 message *dockermessage.JSONMessage241 // timestamp of the latest update.242 timestamp time.Time243}244func newProgress() *progress {245 return &progress{timestamp: time.Now()}246}247func (p *progress) set(msg *dockermessage.JSONMessage) {248 p.Lock()249 defer p.Unlock()250 p.message = msg251 p.timestamp = time.Now()252}253func (p *progress) get() (string, time.Time) {254 p.RLock()255 defer p.RUnlock()256 if p.message == nil {257 return "No progress", p.timestamp258 }259 // The following code is based on JSONMessage.Display260 var prefix string261 if p.message.ID != "" {262 prefix = fmt.Sprintf("%s: ", p.message.ID)263 }264 if p.message.Progress == nil {265 return fmt.Sprintf("%s%s", prefix, p.message.Status), p.timestamp266 }267 return fmt.Sprintf("%s%s %s", prefix, p.message.Status, p.message.Progress.String()), p.timestamp268}269// progressReporter keeps the newest image pulling progress and periodically report the newest progress.270type progressReporter struct {271 *progress272 image string273 cancel context.CancelFunc274 stopCh chan struct{}275 imagePullProgressDeadline time.Duration276}277// newProgressReporter creates a new progressReporter for specific image with specified reporting interval278func newProgressReporter(image string, cancel context.CancelFunc, imagePullProgressDeadline time.Duration) *progressReporter {279 return &progressReporter{280 progress: newProgress(),281 image: image,282 cancel: cancel,283 stopCh: make(chan struct{}),284 imagePullProgressDeadline: imagePullProgressDeadline,285 }286}287// start starts the progressReporter288func (p *progressReporter) start() {289 go func() {290 ticker := time.NewTicker(defaultImagePullingProgressReportInterval)291 defer ticker.Stop()292 for {293 // TODO(random-liu): Report as events.294 select {295 case <-ticker.C:296 progress, timestamp := p.progress.get()297 // If there is no progress for p.imagePullProgressDeadline, cancel the operation.298 if time.Since(timestamp) > p.imagePullProgressDeadline {299 klog.Errorf("Cancel pulling image %q because of no progress for %v, latest progress: %q", p.image, p.imagePullProgressDeadline, progress)300 p.cancel()301 return302 }303 klog.V(2).Infof("Pulling image %q: %q", p.image, progress)304 case <-p.stopCh:305 progress, _ := p.progress.get()306 klog.V(2).Infof("Stop pulling image %q: %q", p.image, progress)307 return308 }309 }310 }()311}312// stop stops the progressReporter313func (p *progressReporter) stop() {314 close(p.stopCh)315}316func (d *kubeDockerClient) PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error {317 // RegistryAuth is the base64 encoded credentials for the registry318 base64Auth, err := base64EncodeAuth(auth)319 if err != nil {320 return err321 }322 opts.RegistryAuth = base64Auth323 ctx, cancel := d.getCancelableContext()324 defer cancel()325 resp, err := d.client.ImagePull(ctx, image, opts)326 if err != nil {327 return err328 }329 defer resp.Close()330 reporter := newProgressReporter(image, cancel, d.imagePullProgressDeadline)331 reporter.start()332 defer reporter.stop()333 decoder := json.NewDecoder(resp)334 for {335 var msg dockermessage.JSONMessage336 err := decoder.Decode(&msg)337 if err == io.EOF {338 break339 }340 if err != nil {341 return err342 }343 if msg.Error != nil {344 return msg.Error345 }346 reporter.set(&msg)347 }348 return nil349}350func (d *kubeDockerClient) RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {351 ctx, cancel := d.getTimeoutContext()352 defer cancel()353 resp, err := d.client.ImageRemove(ctx, image, opts)354 if ctxErr := contextError(ctx); ctxErr != nil {355 return nil, ctxErr356 }357 if dockerapi.IsErrNotFound(err) {358 return nil, ImageNotFoundError{ID: image}359 }360 return resp, err361}362func (d *kubeDockerClient) Logs(id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions) error {363 ctx, cancel := d.getCancelableContext()364 defer cancel()365 resp, err := d.client.ContainerLogs(ctx, id, opts)366 if ctxErr := contextError(ctx); ctxErr != nil {367 return ctxErr368 }369 if err != nil {370 return err371 }372 defer resp.Close()373 return d.redirectResponseToOutputStream(sopts.RawTerminal, sopts.OutputStream, sopts.ErrorStream, resp)374}375func (d *kubeDockerClient) Version() (*dockertypes.Version, error) {376 ctx, cancel := d.getTimeoutContext()377 defer cancel()378 resp, err := d.client.ServerVersion(ctx)379 if ctxErr := contextError(ctx); ctxErr != nil {380 return nil, ctxErr381 }382 if err != nil {383 return nil, err384 }385 return &resp, nil386}387func (d *kubeDockerClient) Info() (*dockertypes.Info, error) {388 ctx, cancel := d.getTimeoutContext()389 defer cancel()390 resp, err := d.client.Info(ctx)391 if ctxErr := contextError(ctx); ctxErr != nil {392 return nil, ctxErr393 }394 if err != nil {395 return nil, err396 }397 return &resp, nil398}399// TODO(random-liu): Add unit test for exec and attach functions, just like what go-dockerclient did.400func (d *kubeDockerClient) CreateExec(id string, opts dockertypes.ExecConfig) (*dockertypes.IDResponse, error) {401 ctx, cancel := d.getTimeoutContext()402 defer cancel()403 resp, err := d.client.ContainerExecCreate(ctx, id, opts)404 if ctxErr := contextError(ctx); ctxErr != nil {405 return nil, ctxErr406 }407 if err != nil {408 return nil, err409 }410 return &resp, nil411}412func (d *kubeDockerClient) StartExec(startExec string, opts dockertypes.ExecStartCheck, sopts StreamOptions) error {413 ctx, cancel := d.getCancelableContext()414 defer cancel()415 if opts.Detach {416 err := d.client.ContainerExecStart(ctx, startExec, opts)417 if ctxErr := contextError(ctx); ctxErr != nil {418 return ctxErr419 }420 return err421 }422 resp, err := d.client.ContainerExecAttach(ctx, startExec, dockertypes.ExecStartCheck{423 Detach: opts.Detach,424 Tty: opts.Tty,425 })426 if ctxErr := contextError(ctx); ctxErr != nil {427 return ctxErr428 }429 if err != nil {430 return err431 }432 defer resp.Close()433 if sopts.ExecStarted != nil {434 // Send a message to the channel indicating that the exec has started. This is needed so435 // interactive execs can handle resizing correctly - the request to resize the TTY has to happen436 // after the call to d.client.ContainerExecAttach, and because d.holdHijackedConnection below437 // blocks, we use sopts.ExecStarted to signal the caller that it's ok to resize.438 sopts.ExecStarted <- struct{}{}439 }440 return d.holdHijackedConnection(sopts.RawTerminal || opts.Tty, sopts.InputStream, sopts.OutputStream, sopts.ErrorStream, resp)441}442func (d *kubeDockerClient) InspectExec(id string) (*dockertypes.ContainerExecInspect, error) {443 ctx, cancel := d.getTimeoutContext()444 defer cancel()445 resp, err := d.client.ContainerExecInspect(ctx, id)446 if ctxErr := contextError(ctx); ctxErr != nil {447 return nil, ctxErr448 }449 if err != nil {450 return nil, err451 }452 return &resp, nil453}454func (d *kubeDockerClient) AttachToContainer(id string, opts dockertypes.ContainerAttachOptions, sopts StreamOptions) error {455 ctx, cancel := d.getCancelableContext()456 defer cancel()457 resp, err := d.client.ContainerAttach(ctx, id, opts)458 if ctxErr := contextError(ctx); ctxErr != nil {459 return ctxErr460 }461 if err != nil {462 return err463 }464 defer resp.Close()465 return d.holdHijackedConnection(sopts.RawTerminal, sopts.InputStream, sopts.OutputStream, sopts.ErrorStream, resp)466}467func (d *kubeDockerClient) ResizeExecTTY(id string, height, width uint) error {468 ctx, cancel := d.getCancelableContext()469 defer cancel()470 return d.client.ContainerExecResize(ctx, id, dockertypes.ResizeOptions{471 Height: height,472 Width: width,473 })474}475func (d *kubeDockerClient) ResizeContainerTTY(id string, height, width uint) error {476 ctx, cancel := d.getCancelableContext()477 defer cancel()478 return d.client.ContainerResize(ctx, id, dockertypes.ResizeOptions{479 Height: height,480 Width: width,481 })482}483// GetContainerStats is currently only used for Windows container stats484func (d *kubeDockerClient) GetContainerStats(id string) (*dockertypes.StatsJSON, error) {485 ctx, cancel := d.getCancelableContext()486 defer cancel()487 response, err := d.client.ContainerStats(ctx, id, false)488 if err != nil {489 return nil, err490 }491 dec := json.NewDecoder(response.Body)492 var stats dockertypes.StatsJSON493 err = dec.Decode(&stats)494 if err != nil {495 return nil, err496 }497 defer response.Body.Close()498 return &stats, nil499}500// redirectResponseToOutputStream redirect the response stream to stdout and stderr. When tty is true, all stream will501// only be redirected to stdout.502func (d *kubeDockerClient) redirectResponseToOutputStream(tty bool, outputStream, errorStream io.Writer, resp io.Reader) error {503 if outputStream == nil {504 outputStream = ioutil.Discard505 }506 if errorStream == nil {507 errorStream = ioutil.Discard508 }509 var err error510 if tty {511 _, err = io.Copy(outputStream, resp)512 } else {513 _, err = dockerstdcopy.StdCopy(outputStream, errorStream, resp)514 }515 return err516}517// holdHijackedConnection hold the HijackedResponse, redirect the inputStream to the connection, and redirect the response518// stream to stdout and stderr. NOTE: If needed, we could also add context in this function.519func (d *kubeDockerClient) holdHijackedConnection(tty bool, inputStream io.Reader, outputStream, errorStream io.Writer, resp dockertypes.HijackedResponse) error {520 receiveStdout := make(chan error)521 if outputStream != nil || errorStream != nil {522 go func() {523 receiveStdout <- d.redirectResponseToOutputStream(tty, outputStream, errorStream, resp.Reader)524 }()525 }526 stdinDone := make(chan struct{})527 go func() {528 if inputStream != nil {529 io.Copy(resp.Conn, inputStream)530 }531 resp.CloseWrite()532 close(stdinDone)533 }()534 select {535 case err := <-receiveStdout:536 return err537 case <-stdinDone:538 if outputStream != nil || errorStream != nil {539 return <-receiveStdout540 }541 }542 return nil543}...

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1func main() {2 err := ctxerrcopytest2.Test()3 if err != nil {4 fmt.Println(err)5 }6}7func main() {8 err := ctxerrcopytest2a.Test()9 if err != nil {10 fmt.Println(err)11 }12}

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1func main() {2 e := errors.New("test")3 fmt.Println(e)4 e2 := ctxerr.Copy(e)5 fmt.Println(e2)6}

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctxerr := golctxerr.New("main")4 ctxerr.Error("error in main")5 ctxerr.Error("error in main with more details", "more details")6 ctxerr.Error("error in main with more details", "more details", "more details")7 fmt.Println(ctxerr.Copy())8}9import (10func main() {11 ctxerr := golctxerr.New("main")12 ctxerr.Error("error in main")13 ctxerr.Error("error in main with more details", "more details")14 ctxerr.Error("error in main with more details", "more details", "more details")15 fmt.Println(ctxerr.Copy())16}17import (18func main() {19 ctxerr := golctxerr.New("main")20 ctxerr.Error("error in main")21 ctxerr.Error("error in main with more details", "more details")22 ctxerr.Error("error in main with more details", "more details", "more details")23 fmt.Println(ctxerr.Copy())24}25import (

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctxerr := golctxerr.New("main.go")4 ctxerr.Add("main.go", "function main()")5 fmt.Println(ctxerr)6 fmt.Println(ctxerr.Copy())7 fmt.Println(ctxerr.Copy().Add("1.go", "function main()"))8 fmt.Println(ctxerr.Copy().Add("2.go", "function main()"))9 fmt.Println(ctxerr.Copy().Add("3.go", "function main()"))10}11import (12func main() {13 ctxerr := golctxerr.New("main.go")14 ctxerr.Add("main.go", "function main()")15 fmt.Println(ctxerr)16 fmt.Println(ctxerr.Add("1.go", "function main()"))17 fmt.Println(ctxerr.Add("2.go", "function main()"))18 fmt.Println(ctxerr.Add("3.go", "function main()"))19}20import (21func main() {22 ctxerr := golctxerr.New("main.go")23 ctxerr.Add("main.go", "function main()")

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("ctxerr Copy example")4 ctxerr := golctxerr.New("ctxerr Copy example")5 ctxerr.Add("error2")6 ctxerr.Add("error3")7 ctxerr.Add("error4")8 ctxerr.Add("error5")9 ctxerr.Add("error6")10 ctxerr.Add("error7")11 ctxerr.Add("error8")12 ctxerr.Add("error9")13 ctxerr.Add("error10")14 ctxerr.Add("error11")15 ctxerr.Add("error12")16 ctxerr.Add("error13")17 ctxerr.Add("error14")18 ctxerr.Add("error15")19 ctxerr.Add("error16")20 ctxerr.Add("error17")21 ctxerr.Add("error18")22 ctxerr.Add("error19")23 ctxerr.Add("error20")24 ctxerr.Add("error21")25 ctxerr.Add("error22")26 ctxerr.Add("error23")27 ctxerr.Add("error24")28 ctxerr.Add("error25")29 ctxerr.Add("error26")30 ctxerr.Add("error27")31 ctxerr.Add("error28")32 ctxerr.Add("error29")33 ctxerr.Add("error30")34 ctxerr.Add("error31")35 ctxerr.Add("error32")36 ctxerr.Add("error33")37 ctxerr.Add("error34")38 ctxerr.Add("error35")39 ctxerr.Add("error36")40 ctxerr.Add("error37")41 ctxerr.Add("error38")42 ctxerr.Add("error39")43 ctxerr.Add("error40")44 ctxerr.Add("error41")45 ctxerr.Add("error42")46 ctxerr.Add("error43")47 ctxerr.Add("error44")48 ctxerr.Add("error45")49 ctxerr.Add("error46")50 ctxerr.Add("error47")51 ctxerr.Add("error48")52 ctxerr.Add("error49")53 ctxerr.Add("error50")54 ctxerr.Add("error51")55 ctxerr.Add("error52")56 ctxerr.Add("error53")57 ctxerr.Add("error54")58 ctxerr.Add("error55")59 ctxerr.Add("error56")60 ctxerr.Add("error57")61 ctxerr.Add("error58")62 ctxerr.Add("error59")63 ctxerr.Add("error60")64 ctxerr.Add("error61")65 ctxerr.Add("error62")66 ctxerr.Add("error63")67 ctxerr.Add("error64

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 e := ctxerr.New("error occurred")4 e.AddContext("context1", "value1")5 e.AddContext("context2", "value2")6 e.AddContext("context3", "value3")7 e.AddContext("context4", "value4")8 e.AddContext("context5", "value5")9 e.AddContext("context6", "value6")10 e.AddContext("context7", "value7")11 e.AddContext("context8", "value8")12 e.AddContext("context9", "value9")13 e.AddContext("context10", "value10")14 e.AddContext("context11", "value11")15 e.AddContext("context12", "value12")16 e.AddContext("context13", "value13")17 e.AddContext("context14", "value14")18 e.AddContext("context15", "value15")19 e.AddContext("context16", "value16")20 e.AddContext("context17", "value17")21 e.AddContext("context18", "value18")22 e.AddContext("context19", "value19")23 e.AddContext("context20", "value20")24 e.AddContext("context21", "value21")25 e.AddContext("context22", "value22")26 e.AddContext("context23", "value23")27 e.AddContext("context24", "value24")28 e.AddContext("context25", "value25")29 e.AddContext("context26", "value26")30 e.AddContext("context27", "value27")31 e.AddContext("context28", "value28")32 e.AddContext("context29", "value29")33 e.AddContext("context30", "value30")34 e.AddContext("context31", "value31")35 e.AddContext("context32", "value32")36 e.AddContext("context33", "value33")37 e.AddContext("context34", "value34")38 e.AddContext("context35", "value35")39 e.AddContext("context36", "value36")40 e.AddContext("context37", "value37")41 e.AddContext("context38", "value38")

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx := ctxerr.NewCtxErr()4 err := fmt.Errorf("error")5 ctx.Add(err)6 fmt.Println(ctx.Error())7}8import (9func main() {10 ctx := ctxerr.NewCtxErr()11 err := fmt.Errorf("error")12 ctx.Add(err)13 fmt.Println(ctx.Error())14}15import (16func main() {17 ctx := ctxerr.NewCtxErr()18 ctx.Addf("error")19 fmt.Println(ctx.Error())20}21import (22func main() {23 ctx := ctxerr.NewCtxErr()24 ctx.Addf("error %s", "string")25 fmt.Println(ctx.Error())26}27import (28func main() {29 ctx := ctxerr.NewCtxErr()30 ctx.Addf("error %s", "string")31 fmt.Println(ctx.Error())32}33import (34func main() {35 ctx := ctxerr.NewCtxErr()36 ctx.Addf("error %s", "string")37 fmt.Println(ctx.Error())38}39import (40func main() {41 ctx := ctxerr.NewCtxErr()42 ctx.Addf("error %s", "string")43 fmt.Println(ctx.Error())44}

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx := ctxerr.New()4 ctx.Add("foo", "bar")5 ctx.Add("baz", 123)6 ctx.Add("qux", 3.14)7 newCtx := ctx.Copy()8}9import (10func main() {11 ctx := ctxerr.New()12 ctx.Add("foo", "bar")13 ctx.Add("baz", 123)14 ctx.Add("qux", 3.14)15 newCtx := ctx.Copy()16}17import (18func main() {19 ctx := ctxerr.New()20 ctx.Add("foo", "bar")21 ctx.Add("baz", 123)22 ctx.Add("qux", 3.14)23 newCtx := ctx.Copy()24}25import (26func main() {27 ctx := ctxerr.New()28 ctx.Add("foo", "bar")29 ctx.Add("baz", 123)30 ctx.Add("qux", 3.14)31 newCtx := ctx.Copy()

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx := ctxerr.New("This is a new context error")4 ctx.AddContext("This is a new context")5 ctx2 := ctxerr.New("This is a second context error")6 ctx2.AddContext("This is a second context")7 ctx.Copy(ctx2)8 fmt.Println(ctx)9}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful