github.com/launchdarkly/api-client-go@v5.3.0+incompatible/api_user_record.go (about) 1 /* 2 * LaunchDarkly REST API 3 * 4 * Build custom integrations with the LaunchDarkly REST API 5 * 6 * API version: 5.0.0 7 * Contact: support@launchdarkly.com 8 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 9 */ 10 11 package ldapi 12 13 import ( 14 "context" 15 "io/ioutil" 16 "net/http" 17 "net/url" 18 "strings" 19 "fmt" 20 ) 21 22 // Linger please 23 var ( 24 _ context.Context 25 ) 26 27 type UserRecordApiService service 28 29 /* 30 UserRecordApiService Get a user by key. 31 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 32 * @param projectKey The project key, used to tie the flags together under one project so they can be managed together. 33 * @param environmentKey The environment key, used to tie together flag configuration and users under one environment so they can be managed together. 34 * @param userKey The user's key. 35 36 @return User 37 */ 38 func (a *UserRecordApiService) GetUser(ctx context.Context, projectKey string, environmentKey string, userKey string) (User, *http.Response, error) { 39 var ( 40 localVarHttpMethod = strings.ToUpper("Get") 41 localVarPostBody interface{} 42 localVarFileName string 43 localVarFileBytes []byte 44 localVarReturnValue User 45 ) 46 47 // create path and map variables 48 localVarPath := a.client.cfg.BasePath + "/users/{projectKey}/{environmentKey}/{userKey}" 49 localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1) 50 localVarPath = strings.Replace(localVarPath, "{"+"environmentKey"+"}", fmt.Sprintf("%v", environmentKey), -1) 51 localVarPath = strings.Replace(localVarPath, "{"+"userKey"+"}", fmt.Sprintf("%v", userKey), -1) 52 53 localVarHeaderParams := make(map[string]string) 54 localVarQueryParams := url.Values{} 55 localVarFormParams := url.Values{} 56 57 // to determine the Content-Type header 58 localVarHttpContentTypes := []string{"application/json"} 59 60 // set Content-Type header 61 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 62 if localVarHttpContentType != "" { 63 localVarHeaderParams["Content-Type"] = localVarHttpContentType 64 } 65 66 // to determine the Accept header 67 localVarHttpHeaderAccepts := []string{"application/json"} 68 69 // set Accept header 70 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 71 if localVarHttpHeaderAccept != "" { 72 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 73 } 74 if ctx != nil { 75 // API Key Authentication 76 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 77 var key string 78 if auth.Prefix != "" { 79 key = auth.Prefix + " " + auth.Key 80 } else { 81 key = auth.Key 82 } 83 localVarHeaderParams["Authorization"] = key 84 85 } 86 } 87 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 88 if err != nil { 89 return localVarReturnValue, nil, err 90 } 91 92 localVarHttpResponse, err := a.client.callAPI(r) 93 if err != nil || localVarHttpResponse == nil { 94 return localVarReturnValue, localVarHttpResponse, err 95 } 96 97 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 98 localVarHttpResponse.Body.Close() 99 if err != nil { 100 return localVarReturnValue, localVarHttpResponse, err 101 } 102 103 if localVarHttpResponse.StatusCode < 300 { 104 // If we succeed, return the data, otherwise pass on to decode error. 105 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 106 if err == nil { 107 return localVarReturnValue, localVarHttpResponse, err 108 } 109 } 110 111 if localVarHttpResponse.StatusCode >= 300 { 112 newErr := GenericSwaggerError{ 113 body: localVarBody, 114 error: localVarHttpResponse.Status, 115 } 116 117 if localVarHttpResponse.StatusCode == 200 { 118 var v User 119 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 120 if err != nil { 121 newErr.error = err.Error() 122 return localVarReturnValue, localVarHttpResponse, newErr 123 } 124 newErr.model = v 125 return localVarReturnValue, localVarHttpResponse, newErr 126 } 127 128 return localVarReturnValue, localVarHttpResponse, newErr 129 } 130 131 return localVarReturnValue, localVarHttpResponse, nil 132 }