func (c Client) SetBucketObjectLockConfig(bucketName string, mode *RetentionMode, validity *uint, unit *ValidityUnit) error {
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return err
	}
	urlValues := make(url.Values)
	urlValues.Set("object-lock", "")
	config, err := newObjectLockConfig(mode, validity, unit)
	if err != nil {
		return err
	}
	configData, err := xml.Marshal(config)
	if err != nil {
		return err
	}
	reqMetadata := requestMetadata{
		bucketName:       bucketName,
		queryValues:      urlValues,
		contentBody:      bytes.NewReader(configData),
		contentLength:    int64(len(configData)),
		contentMD5Base64: sumMD5Base64(configData),
		contentSHA256Hex: sum256Hex(configData),
	}
	resp, err := c.executeMethod(context.Background(), "PUT", reqMetadata)
	defer closeResponse(resp)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode != http.StatusOK {
			return httpRespToErrorResponse(resp, bucketName, "")
		}
	}
	return nil
}
SetBucketObjectLockConfig sets object lock configuration in given bucket. mode, validity and unit are either all set or all nil.
package minio
import (
	"bytes"
	"context"
	"encoding/xml"
	"fmt"
	"net/http"
	"net/url"
	"time"
	"github.com/minio/minio-go/v6/pkg/s3utils"
)
type RetentionMode string
const (
	Governance RetentionMode = "GOVERNANCE"
	Compliance RetentionMode = "COMPLIANCE"
)
func (r RetentionMode) String() string {
	return string(r)
}
func (r RetentionMode) IsValid() bool {
	return r == Governance || r == Compliance
}
type ValidityUnit string
const (
	Days ValidityUnit = "DAYS"
	Years ValidityUnit = "YEARS"
)
func (unit ValidityUnit) String() string {
	return string(unit)
}
func (unit ValidityUnit) isValid() bool {
	return unit == Days || unit == Years
}
type Retention struct {
	Mode     RetentionMode
	Validity time.Duration
}
func (r Retention) String() string {
	return fmt.Sprintf("{Mode:%v, Validity:%v}", r.Mode, r.Validity)
}
func (r Retention) IsEmpty() bool {
	return r.Mode == "" || r.Validity == 0
}
type objectLockConfig struct {
	XMLNS             string   `xml:"xmlns,attr,omitempty"`
	XMLName           xml.Name `xml:"ObjectLockConfiguration"`
	ObjectLockEnabled string   `xml:"ObjectLockEnabled"`
	Rule              *struct {
		DefaultRetention struct {
			Mode  RetentionMode `xml:"Mode"`
			Days  *uint         `xml:"Days"`
			Years *uint         `xml:"Years"`
		} `xml:"DefaultRetention"`
	} `xml:"Rule,omitempty"`
}
func newObjectLockConfig(mode *RetentionMode, validity *uint, unit *ValidityUnit) (*objectLockConfig, error) {
	config := &objectLockConfig{
		ObjectLockEnabled: "Enabled",
	}
	if mode != nil && validity != nil && unit != nil {
		if !mode.IsValid() {
			return nil, fmt.Errorf("invalid retention mode `%v`", mode)
		}
		if !unit.isValid() {
			return nil, fmt.Errorf("invalid validity unit `%v`", unit)
		}
		config.Rule = &struct {
			DefaultRetention struct {
				Mode  RetentionMode `xml:"Mode"`
				Days  *uint         `xml:"Days"`
				Years *uint         `xml:"Years"`
			} `xml:"DefaultRetention"`
		}{}
		config.Rule.DefaultRetention.Mode = *mode
		if *unit == Days {
			config.Rule.DefaultRetention.Days = validity
		} else {
			config.Rule.DefaultRetention.Years = validity
		}
		return config, nil
	}
	if mode == nil && validity == nil && unit == nil {
		return config, nil
	}
	return nil, fmt.Errorf("all of retention mode, validity and validity unit must be passed")
}