github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/css/v1/thesaurus/requests.go (about)

     1  package thesaurus
     2  
     3  import "github.com/chnsz/golangsdk"
     4  
     5  var RequestOpts = golangsdk.RequestOpts{
     6  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
     7  }
     8  
     9  // LoadCustomThesaurusReq This is a auto create Body Object
    10  type LoadThesaurusReq struct {
    11  	// OBS bucket where word dictionary files are stored. The bucket must be a standard storage or infrequently
    12  	// accessed storage and cannot be the archived storage.
    13  	BucketName string `json:"bucketName" required:"true"`
    14  	// Main word dictionary file object, which must be a text file encoded in UTF-8 without BOM. Each line contains
    15  	// one sub-word. The maximum file size is 100 MB.
    16  	MainObject string `json:"mainObject,omitempty"`
    17  	// Stop word dictionary file object, which must be a text file encoded in UTF-8 without BOM. Each line contains
    18  	// one sub-word. The maximum file size is 20 MB.
    19  	StopObject string `json:"stopObject,omitempty"`
    20  	// Synonym word dictionary file, which must be a text file encoded in UTF-8 without BOM. Each line contains one
    21  	// group of sub-words. The maximum file size is 20 MB.
    22  	SynonymObject string `json:"synonymObject,omitempty"`
    23  }
    24  
    25  func Get(c *golangsdk.ServiceClient, clusterId string) (*ThesaurusStatusResp, error) {
    26  	var rst ThesaurusStatusResp
    27  	_, err := c.Get(getURL(c, clusterId), &rst, &golangsdk.RequestOpts{
    28  		MoreHeaders: RequestOpts.MoreHeaders,
    29  	})
    30  	if err == nil {
    31  		return &rst, nil
    32  	}
    33  	return nil, err
    34  }
    35  
    36  // LoadIKThesaurus
    37  func Load(c *golangsdk.ServiceClient, clusterId string, opts LoadThesaurusReq) *golangsdk.ErrResult {
    38  	var r golangsdk.ErrResult
    39  
    40  	b, err := golangsdk.BuildRequestBody(opts, "")
    41  	if err != nil {
    42  		r.Err = err
    43  		return &r
    44  	}
    45  
    46  	_, r.Err = c.Post(loadURL(c, clusterId), b, nil, &golangsdk.RequestOpts{
    47  		MoreHeaders: RequestOpts.MoreHeaders,
    48  	})
    49  	return &r
    50  }
    51  
    52  // DeleteIKThesaurus
    53  func Delete(c *golangsdk.ServiceClient, clusterId string) *golangsdk.ErrResult {
    54  	var r golangsdk.ErrResult
    55  	_, r.Err = c.Delete(deleteURL(c, clusterId), &golangsdk.RequestOpts{
    56  		MoreHeaders: RequestOpts.MoreHeaders,
    57  	})
    58  	return &r
    59  }