github.com/openshift-online/ocm-sdk-go@v0.1.473/response.go (about)

     1  /*
     2  Copyright (c) 2018 Red Hat, Inc.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8    http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // This file contains the implementation of the response type.
    18  
    19  package sdk
    20  
    21  import (
    22  	"net/http"
    23  )
    24  
    25  // Response contains the information extracted from an HTTP POST response.
    26  type Response struct {
    27  	status int
    28  	header http.Header
    29  	body   []byte
    30  }
    31  
    32  // Status returns the response status code.
    33  func (r *Response) Status() int {
    34  	return r.status
    35  }
    36  
    37  // Bytes returns an slice of bytes containing the response body. Not that this will never return
    38  // nil; if the response body is empty it will return an empty slice.
    39  func (r *Response) Bytes() []byte {
    40  	return r.body
    41  }
    42  
    43  // Bytes returns an string containing the response body.
    44  func (r *Response) String() string {
    45  	return string(r.body)
    46  }
    47  
    48  // Header returns the header value. In case there's no value for the header, an empty string ("") will be returned.
    49  func (r *Response) Header(name string) string {
    50  	if r.header == nil {
    51  		return ""
    52  	}
    53  	return r.header.Get(name)
    54  }