Skip to content
Snippets Groups Projects
encode_decode.go 3.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • // Code generated by goa v3.7.0, DO NOT EDIT.
    //
    // health HTTP client encoders and decoders
    //
    // Command:
    // $ goa gen code.vereign.com/gaiax/tsa/policy/design
    
    package client
    
    import (
    	"bytes"
    	"context"
    	"io/ioutil"
    	"net/http"
    	"net/url"
    
    	goahttp "goa.design/goa/v3/http"
    )
    
    // BuildLivenessRequest instantiates a HTTP request object with method and path
    // set to call the "health" service "Liveness" endpoint
    func (c *Client) BuildLivenessRequest(ctx context.Context, v interface{}) (*http.Request, error) {
    	u := &url.URL{Scheme: c.scheme, Host: c.host, Path: LivenessHealthPath()}
    	req, err := http.NewRequest("GET", u.String(), nil)
    	if err != nil {
    		return nil, goahttp.ErrInvalidURL("health", "Liveness", u.String(), err)
    	}
    	if ctx != nil {
    		req = req.WithContext(ctx)
    	}
    
    	return req, nil
    }
    
    // DecodeLivenessResponse returns a decoder for responses returned by the
    // health Liveness endpoint. restoreBody controls whether the response body
    // should be restored after having been read.
    func DecodeLivenessResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody bool) func(*http.Response) (interface{}, error) {
    	return func(resp *http.Response) (interface{}, error) {
    		if restoreBody {
    			b, err := ioutil.ReadAll(resp.Body)
    			if err != nil {
    				return nil, err
    			}
    			resp.Body = ioutil.NopCloser(bytes.NewBuffer(b))
    			defer func() {
    				resp.Body = ioutil.NopCloser(bytes.NewBuffer(b))
    			}()
    		} else {
    			defer resp.Body.Close()
    		}
    		switch resp.StatusCode {
    		case http.StatusOK:
    			return nil, nil
    		default:
    			body, _ := ioutil.ReadAll(resp.Body)
    			return nil, goahttp.ErrInvalidResponse("health", "Liveness", resp.StatusCode, string(body))
    		}
    	}
    }
    
    // BuildReadinessRequest instantiates a HTTP request object with method and
    // path set to call the "health" service "Readiness" endpoint
    func (c *Client) BuildReadinessRequest(ctx context.Context, v interface{}) (*http.Request, error) {
    	u := &url.URL{Scheme: c.scheme, Host: c.host, Path: ReadinessHealthPath()}
    	req, err := http.NewRequest("GET", u.String(), nil)
    	if err != nil {
    		return nil, goahttp.ErrInvalidURL("health", "Readiness", u.String(), err)
    	}
    	if ctx != nil {
    		req = req.WithContext(ctx)
    	}
    
    	return req, nil
    }
    
    // DecodeReadinessResponse returns a decoder for responses returned by the
    // health Readiness endpoint. restoreBody controls whether the response body
    // should be restored after having been read.
    func DecodeReadinessResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody bool) func(*http.Response) (interface{}, error) {
    	return func(resp *http.Response) (interface{}, error) {
    		if restoreBody {
    			b, err := ioutil.ReadAll(resp.Body)
    			if err != nil {
    				return nil, err
    			}
    			resp.Body = ioutil.NopCloser(bytes.NewBuffer(b))
    			defer func() {
    				resp.Body = ioutil.NopCloser(bytes.NewBuffer(b))
    			}()
    		} else {
    			defer resp.Body.Close()
    		}
    		switch resp.StatusCode {
    		case http.StatusOK:
    			return nil, nil
    		default:
    			body, _ := ioutil.ReadAll(resp.Body)
    			return nil, goahttp.ErrInvalidResponse("health", "Readiness", resp.StatusCode, string(body))
    		}
    	}
    }