github.com/minio/console@v1.4.1/api/operations/object/share_object_urlbuilder.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // This file is part of MinIO Console Server
     4  // Copyright (c) 2023 MinIO, Inc.
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU Affero General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU Affero General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU Affero General Public License
    17  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18  //
    19  
    20  package object
    21  
    22  // This file was generated by the swagger tool.
    23  // Editing this file might prove futile when you re-run the generate command
    24  
    25  import (
    26  	"errors"
    27  	"net/url"
    28  	golangswaggerpaths "path"
    29  	"strings"
    30  )
    31  
    32  // ShareObjectURL generates an URL for the share object operation
    33  type ShareObjectURL struct {
    34  	BucketName string
    35  
    36  	Expires   *string
    37  	Prefix    string
    38  	VersionID string
    39  
    40  	_basePath string
    41  	// avoid unkeyed usage
    42  	_ struct{}
    43  }
    44  
    45  // WithBasePath sets the base path for this url builder, only required when it's different from the
    46  // base path specified in the swagger spec.
    47  // When the value of the base path is an empty string
    48  func (o *ShareObjectURL) WithBasePath(bp string) *ShareObjectURL {
    49  	o.SetBasePath(bp)
    50  	return o
    51  }
    52  
    53  // SetBasePath sets the base path for this url builder, only required when it's different from the
    54  // base path specified in the swagger spec.
    55  // When the value of the base path is an empty string
    56  func (o *ShareObjectURL) SetBasePath(bp string) {
    57  	o._basePath = bp
    58  }
    59  
    60  // Build a url path and query string
    61  func (o *ShareObjectURL) Build() (*url.URL, error) {
    62  	var _result url.URL
    63  
    64  	var _path = "/buckets/{bucket_name}/objects/share"
    65  
    66  	bucketName := o.BucketName
    67  	if bucketName != "" {
    68  		_path = strings.Replace(_path, "{bucket_name}", bucketName, -1)
    69  	} else {
    70  		return nil, errors.New("bucketName is required on ShareObjectURL")
    71  	}
    72  
    73  	_basePath := o._basePath
    74  	if _basePath == "" {
    75  		_basePath = "/api/v1"
    76  	}
    77  	_result.Path = golangswaggerpaths.Join(_basePath, _path)
    78  
    79  	qs := make(url.Values)
    80  
    81  	var expiresQ string
    82  	if o.Expires != nil {
    83  		expiresQ = *o.Expires
    84  	}
    85  	if expiresQ != "" {
    86  		qs.Set("expires", expiresQ)
    87  	}
    88  
    89  	prefixQ := o.Prefix
    90  	if prefixQ != "" {
    91  		qs.Set("prefix", prefixQ)
    92  	}
    93  
    94  	versionIDQ := o.VersionID
    95  	if versionIDQ != "" {
    96  		qs.Set("version_id", versionIDQ)
    97  	}
    98  
    99  	_result.RawQuery = qs.Encode()
   100  
   101  	return &_result, nil
   102  }
   103  
   104  // Must is a helper function to panic when the url builder returns an error
   105  func (o *ShareObjectURL) Must(u *url.URL, err error) *url.URL {
   106  	if err != nil {
   107  		panic(err)
   108  	}
   109  	if u == nil {
   110  		panic("url can't be nil")
   111  	}
   112  	return u
   113  }
   114  
   115  // String returns the string representation of the path with query string
   116  func (o *ShareObjectURL) String() string {
   117  	return o.Must(o.Build()).String()
   118  }
   119  
   120  // BuildFull builds a full url with scheme, host, path and query string
   121  func (o *ShareObjectURL) BuildFull(scheme, host string) (*url.URL, error) {
   122  	if scheme == "" {
   123  		return nil, errors.New("scheme is required for a full url on ShareObjectURL")
   124  	}
   125  	if host == "" {
   126  		return nil, errors.New("host is required for a full url on ShareObjectURL")
   127  	}
   128  
   129  	base, err := o.Build()
   130  	if err != nil {
   131  		return nil, err
   132  	}
   133  
   134  	base.Scheme = scheme
   135  	base.Host = host
   136  	return base, nil
   137  }
   138  
   139  // StringFull returns the string representation of a complete url
   140  func (o *ShareObjectURL) StringFull(scheme, host string) string {
   141  	return o.Must(o.BuildFull(scheme, host)).String()
   142  }