github.com/weaviate/weaviate@v1.24.6/adapters/handlers/rest/operations/weaviate_root.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  // Code generated by go-swagger; DO NOT EDIT.
    13  
    14  package operations
    15  
    16  // This file was generated by the swagger tool.
    17  // Editing this file might prove futile when you re-run the generate command
    18  
    19  import (
    20  	"context"
    21  	"net/http"
    22  	"strconv"
    23  
    24  	"github.com/go-openapi/errors"
    25  	"github.com/go-openapi/runtime/middleware"
    26  	"github.com/go-openapi/strfmt"
    27  	"github.com/go-openapi/swag"
    28  
    29  	"github.com/weaviate/weaviate/entities/models"
    30  )
    31  
    32  // WeaviateRootHandlerFunc turns a function with the right signature into a weaviate root handler
    33  type WeaviateRootHandlerFunc func(WeaviateRootParams, *models.Principal) middleware.Responder
    34  
    35  // Handle executing the request and returning a response
    36  func (fn WeaviateRootHandlerFunc) Handle(params WeaviateRootParams, principal *models.Principal) middleware.Responder {
    37  	return fn(params, principal)
    38  }
    39  
    40  // WeaviateRootHandler interface for that can handle valid weaviate root params
    41  type WeaviateRootHandler interface {
    42  	Handle(WeaviateRootParams, *models.Principal) middleware.Responder
    43  }
    44  
    45  // NewWeaviateRoot creates a new http.Handler for the weaviate root operation
    46  func NewWeaviateRoot(ctx *middleware.Context, handler WeaviateRootHandler) *WeaviateRoot {
    47  	return &WeaviateRoot{Context: ctx, Handler: handler}
    48  }
    49  
    50  /*
    51  	WeaviateRoot swagger:route GET / weaviateRoot
    52  
    53  Home. Discover the REST API
    54  */
    55  type WeaviateRoot struct {
    56  	Context *middleware.Context
    57  	Handler WeaviateRootHandler
    58  }
    59  
    60  func (o *WeaviateRoot) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
    61  	route, rCtx, _ := o.Context.RouteInfo(r)
    62  	if rCtx != nil {
    63  		*r = *rCtx
    64  	}
    65  	var Params = NewWeaviateRootParams()
    66  	uprinc, aCtx, err := o.Context.Authorize(r, route)
    67  	if err != nil {
    68  		o.Context.Respond(rw, r, route.Produces, route, err)
    69  		return
    70  	}
    71  	if aCtx != nil {
    72  		*r = *aCtx
    73  	}
    74  	var principal *models.Principal
    75  	if uprinc != nil {
    76  		principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise
    77  	}
    78  
    79  	if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
    80  		o.Context.Respond(rw, r, route.Produces, route, err)
    81  		return
    82  	}
    83  
    84  	res := o.Handler.Handle(Params, principal) // actually handle the request
    85  	o.Context.Respond(rw, r, route.Produces, route, res)
    86  
    87  }
    88  
    89  // WeaviateRootOKBody weaviate root o k body
    90  //
    91  // swagger:model WeaviateRootOKBody
    92  type WeaviateRootOKBody struct {
    93  
    94  	// links
    95  	Links []*models.Link `json:"links" yaml:"links"`
    96  }
    97  
    98  // Validate validates this weaviate root o k body
    99  func (o *WeaviateRootOKBody) Validate(formats strfmt.Registry) error {
   100  	var res []error
   101  
   102  	if err := o.validateLinks(formats); err != nil {
   103  		res = append(res, err)
   104  	}
   105  
   106  	if len(res) > 0 {
   107  		return errors.CompositeValidationError(res...)
   108  	}
   109  	return nil
   110  }
   111  
   112  func (o *WeaviateRootOKBody) validateLinks(formats strfmt.Registry) error {
   113  	if swag.IsZero(o.Links) { // not required
   114  		return nil
   115  	}
   116  
   117  	for i := 0; i < len(o.Links); i++ {
   118  		if swag.IsZero(o.Links[i]) { // not required
   119  			continue
   120  		}
   121  
   122  		if o.Links[i] != nil {
   123  			if err := o.Links[i].Validate(formats); err != nil {
   124  				if ve, ok := err.(*errors.Validation); ok {
   125  					return ve.ValidateName("weaviateRootOK" + "." + "links" + "." + strconv.Itoa(i))
   126  				} else if ce, ok := err.(*errors.CompositeError); ok {
   127  					return ce.ValidateName("weaviateRootOK" + "." + "links" + "." + strconv.Itoa(i))
   128  				}
   129  				return err
   130  			}
   131  		}
   132  
   133  	}
   134  
   135  	return nil
   136  }
   137  
   138  // ContextValidate validate this weaviate root o k body based on the context it is used
   139  func (o *WeaviateRootOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   140  	var res []error
   141  
   142  	if err := o.contextValidateLinks(ctx, formats); err != nil {
   143  		res = append(res, err)
   144  	}
   145  
   146  	if len(res) > 0 {
   147  		return errors.CompositeValidationError(res...)
   148  	}
   149  	return nil
   150  }
   151  
   152  func (o *WeaviateRootOKBody) contextValidateLinks(ctx context.Context, formats strfmt.Registry) error {
   153  
   154  	for i := 0; i < len(o.Links); i++ {
   155  
   156  		if o.Links[i] != nil {
   157  			if err := o.Links[i].ContextValidate(ctx, formats); err != nil {
   158  				if ve, ok := err.(*errors.Validation); ok {
   159  					return ve.ValidateName("weaviateRootOK" + "." + "links" + "." + strconv.Itoa(i))
   160  				} else if ce, ok := err.(*errors.CompositeError); ok {
   161  					return ce.ValidateName("weaviateRootOK" + "." + "links" + "." + strconv.Itoa(i))
   162  				}
   163  				return err
   164  			}
   165  		}
   166  
   167  	}
   168  
   169  	return nil
   170  }
   171  
   172  // MarshalBinary interface implementation
   173  func (o *WeaviateRootOKBody) MarshalBinary() ([]byte, error) {
   174  	if o == nil {
   175  		return nil, nil
   176  	}
   177  	return swag.WriteJSON(o)
   178  }
   179  
   180  // UnmarshalBinary interface implementation
   181  func (o *WeaviateRootOKBody) UnmarshalBinary(b []byte) error {
   182  	var res WeaviateRootOKBody
   183  	if err := swag.ReadJSON(b, &res); err != nil {
   184  		return err
   185  	}
   186  	*o = res
   187  	return nil
   188  }