github.com/free5gc/openapi@v1.0.8/Npcf_UEPolicy/configuration.go (about)

     1  /*
     2   * Npcf_UEPolicyControl
     3   *
     4   * UE Policy Control Service API
     5   *
     6   * API version: 1.0.0
     7   * Generated by: OpenAPI Generator (https://openapi-generator.tech)
     8   */
     9  
    10  package Npcf_UEPolicy
    11  
    12  import (
    13  	"net/http"
    14  	"strings"
    15  )
    16  
    17  // contextKeys are used to identify the type of value in the context.
    18  // Since these are string, it is possible to get a short description of the
    19  // context key for logging and debugging using key.String().
    20  
    21  type contextKey string
    22  
    23  func (c contextKey) String() string {
    24  	return "auth " + string(c)
    25  }
    26  
    27  var (
    28  	// ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
    29  	ContextOAuth2 = contextKey("token")
    30  
    31  	// ContextBasicAuth takes BasicAuth as authentication for the request.
    32  	ContextBasicAuth = contextKey("basic")
    33  
    34  	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
    35  	ContextAccessToken = contextKey("accesstoken")
    36  
    37  	// ContextAPIKey takes an APIKey as authentication for the request
    38  	ContextAPIKey = contextKey("apikey")
    39  )
    40  
    41  // BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth
    42  type BasicAuth struct {
    43  	UserName string `json:"userName,omitempty"`
    44  	Password string `json:"password,omitempty"`
    45  }
    46  
    47  // APIKey provides API key based authentication to a request passed via context using ContextAPIKey
    48  type APIKey struct {
    49  	Key    string
    50  	Prefix string
    51  }
    52  
    53  type Configuration struct {
    54  	Scheme        string `json:"scheme,omitempty"`
    55  	url           string
    56  	basePath      string
    57  	host          string
    58  	defaultHeader map[string]string
    59  	userAgent     string
    60  	httpClient    *http.Client
    61  }
    62  
    63  func NewConfiguration() *Configuration {
    64  	cfg := &Configuration{
    65  		basePath:      "https://example.com/",
    66  		url:           "{apiRoot}",
    67  		defaultHeader: make(map[string]string),
    68  		userAgent:     "OpenAPI-Generator/1.0.0/go",
    69  	}
    70  	return cfg
    71  }
    72  
    73  func (c *Configuration) SetBasePath(apiRoot string) {
    74  	url := c.url
    75  
    76  	// Replace apiRoot
    77  	url = strings.Replace(url, "{"+"apiRoot"+"}", apiRoot, -1)
    78  
    79  	c.basePath = url
    80  }
    81  
    82  func (c *Configuration) BasePath() string {
    83  	return c.basePath
    84  }
    85  
    86  func (c *Configuration) Host() string {
    87  	return c.host
    88  }
    89  
    90  func (c *Configuration) SetHost(host string) {
    91  	c.host = host
    92  }
    93  
    94  func (c *Configuration) UserAgent() string {
    95  	return c.userAgent
    96  }
    97  
    98  func (c *Configuration) SetUserAgent(userAgent string) {
    99  	c.userAgent = userAgent
   100  }
   101  
   102  func (c *Configuration) DefaultHeader() map[string]string {
   103  	return c.defaultHeader
   104  }
   105  
   106  func (c *Configuration) AddDefaultHeader(key string, value string) {
   107  	c.defaultHeader[key] = value
   108  }
   109  
   110  func (c *Configuration) HTTPClient() *http.Client {
   111  	return c.httpClient
   112  }