storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/madmin/examples/bucket-quota.go (about)

     1  //go:build ignore
     2  // +build ignore
     3  
     4  /*
     5   * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
     6   *
     7   * Licensed under the Apache License, Version 2.0 (the "License");
     8   * you may not use this file except in compliance with the License.
     9   * You may obtain a copy of the License at
    10   *
    11   *     http://www.apache.org/licenses/LICENSE-2.0
    12   *
    13   * Unless required by applicable law or agreed to in writing, software
    14   * distributed under the License is distributed on an "AS IS" BASIS,
    15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16   * See the License for the specific language governing permissions and
    17   * limitations under the License.
    18   *
    19   */
    20  
    21  package main
    22  
    23  import (
    24  	"context"
    25  	"fmt"
    26  	"log"
    27  
    28  	"storj.io/minio/pkg/madmin"
    29  )
    30  
    31  func main() {
    32  	// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
    33  	// dummy values, please replace them with original values.
    34  
    35  	// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
    36  	// New returns an MinIO Admin client object.
    37  	madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
    38  	if err != nil {
    39  		log.Fatalln(err)
    40  	}
    41  	var kiB int64 = 1 << 10
    42  	ctx := context.Background()
    43  	// set bucket quota config
    44  	if err := madmClnt.SetBucketQuota(ctx, "bucket-name", 64*kiB, HardQuota); err != nil {
    45  		log.Fatalln(err)
    46  	}
    47  	// gets bucket quota config
    48  	quotaCfg, err := madmClnt.GetBucketQuota(ctx, "bucket-name")
    49  	if err != nil {
    50  		log.Fatalln(err)
    51  	}
    52  	fmt.Println(quotaCfg)
    53  	// remove bucket quota config
    54  	if err := madmClnt.RemoveBucketQuota(ctx, "bucket-name"); err != nil {
    55  		log.Fatalln(err)
    56  	}
    57  }