github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/api_health_checking.go (about)

     1  
     2  /*
     3   * Tyk Gateway API
     4   *
     5   * The Tyk Gateway API is the primary means for integrating your application with the Tyk API Gateway system. This API is very small, and has no granular permissions system. It is intended to be used purely for internal automation and integration.  **Warning: Under no circumstances should outside parties be granted access to this API.**  The Tyk Gateway API is capable of:  * Managing session objects (key generation) * Managing and listing policies * Managing and listing API Definitions (only when not using the Dashboard) * Hot reloads / reloading a cluster configuration * OAuth client creation (only when not using the Dashboard)   In order to use the Gateway API, you'll need to set the `secret` parameter in your tyk.conf file.  The shared secret you set should then be sent along as a header with each Gateway API Request in order for it to be successful:  ``` x-tyk-authorization: <your-secret> ``` <br/> <b>The Tyk Gateway API is subsumed by the Tyk Dashboard API in Pro installations.</b>
     6   *
     7   * API version: 5.5.0
     8   * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
     9   */
    10  package swagger
    11  
    12  import (
    13  	"context"
    14  	"io/ioutil"
    15  	"net/http"
    16  	"net/url"
    17  	"strings"
    18  )
    19  
    20  // Linger please
    21  var (
    22  	_ context.Context
    23  )
    24  
    25  type HealthCheckingApiService service
    26  /*
    27  HealthCheckingApiService Check the Health of the Tyk Gateway
    28  From v2.7.5 you can now rename the &#x60;/hello&#x60;  endpoint by using the &#x60;health_check_endpoint_name&#x60; option  Returns 200 response in case of success 
    29   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
    30  @return string
    31  */
    32  func (a *HealthCheckingApiService) Hello(ctx context.Context) (string, *http.Response, error) {
    33  	var (
    34  		localVarHttpMethod = strings.ToUpper("Get")
    35  		localVarPostBody   interface{}
    36  		localVarFileName   string
    37  		localVarFileBytes  []byte
    38  		localVarReturnValue string
    39  	)
    40  
    41  	// create path and map variables
    42  	localVarPath := a.client.cfg.BasePath + "/tyk/hello"
    43  
    44  	localVarHeaderParams := make(map[string]string)
    45  	localVarQueryParams := url.Values{}
    46  	localVarFormParams := url.Values{}
    47  
    48  	// to determine the Content-Type header
    49  	localVarHttpContentTypes := []string{}
    50  
    51  	// set Content-Type header
    52  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
    53  	if localVarHttpContentType != "" {
    54  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
    55  	}
    56  
    57  	// to determine the Accept header
    58  	localVarHttpHeaderAccepts := []string{"text/html"}
    59  
    60  	// set Accept header
    61  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
    62  	if localVarHttpHeaderAccept != "" {
    63  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
    64  	}
    65  	if ctx != nil {
    66  		// API Key Authentication
    67  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
    68  			var key string
    69  			if auth.Prefix != "" {
    70  				key = auth.Prefix + " " + auth.Key
    71  			} else {
    72  				key = auth.Key
    73  			}
    74  			localVarHeaderParams["X-Tyk-Authorization"] = key
    75  			
    76  		}
    77  	}
    78  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
    79  	if err != nil {
    80  		return localVarReturnValue, nil, err
    81  	}
    82  
    83  	localVarHttpResponse, err := a.client.callAPI(r)
    84  	if err != nil || localVarHttpResponse == nil {
    85  		return localVarReturnValue, localVarHttpResponse, err
    86  	}
    87  
    88  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
    89  	localVarHttpResponse.Body.Close()
    90  	if err != nil {
    91  		return localVarReturnValue, localVarHttpResponse, err
    92  	}
    93  
    94  	if localVarHttpResponse.StatusCode < 300 {
    95  		// If we succeed, return the data, otherwise pass on to decode error.
    96  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
    97  		if err == nil { 
    98  			return localVarReturnValue, localVarHttpResponse, err
    99  		}
   100  	}
   101  
   102  	if localVarHttpResponse.StatusCode >= 300 {
   103  		newErr := GenericSwaggerError{
   104  			body: localVarBody,
   105  			error: localVarHttpResponse.Status,
   106  		}
   107  		if localVarHttpResponse.StatusCode == 200 {
   108  			var v string
   109  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   110  				if err != nil {
   111  					newErr.error = err.Error()
   112  					return localVarReturnValue, localVarHttpResponse, newErr
   113  				}
   114  				newErr.model = v
   115  				return localVarReturnValue, localVarHttpResponse, newErr
   116  		}
   117  		return localVarReturnValue, localVarHttpResponse, newErr
   118  	}
   119  
   120  	return localVarReturnValue, localVarHttpResponse, nil
   121  }