File: index.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (72 lines) | stat: -rw-r--r-- 1,874 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package sls

import "encoding/json"

type IndexLineConfig struct {
	TokenList     []string `json:"token,omitempty"`
	CaseSensitive bool     `json:"caseSensitive"`
	IncludeKeys   []string `json:"include_keys,omitempty"`
	Exclude_keys  []string `json:"exclude_keys,omitempty"`
}

type IndexKeyConfig struct {
	TokenList     []string `json:"token,omitempty"`
	CaseSensitive bool     `json:"caseSensitive,omitempty"`
}

type IndexConfig struct {
	TTL           int                       `json:"ttl,omitempty"`
	LineConfig    IndexLineConfig           `json:"line,omitempty"`
	KeyConfigList map[string]IndexKeyConfig `json:"keys,omitempty"`
}

func (proj *Project) CreateIndex(logstore string, indexConfig *IndexConfig) error {
	data, err := json.Marshal(indexConfig)
	if err != nil {
		return err
	}

	req := &request{
		method:      METHOD_POST,
		path:        "/logstores/" + logstore + "/index",
		payload:     data,
		contentType: "application/json",
	}
	return proj.client.requestWithClose(req)
}

func (proj *Project) DeleteIndex(logstore string) error {
	req := &request{
		method: METHOD_DELETE,
		path:   "/logstores/" + logstore + "/index",
	}

	return proj.client.requestWithClose(req)
}

func (proj *Project) GetIndex(logstore string) (*IndexConfig, error) {
	req := &request{
		method: METHOD_GET,
		path:   "/logstores/" + logstore + "/index",
	}
	indexConfig := &IndexConfig{}
	if err := proj.client.requestWithJsonResponse(req, indexConfig); err != nil {
		return nil, err
	}
	return indexConfig, nil
}

func (proj *Project) UpdateIndex(logstore string, indexConfig *IndexConfig) error {
	data, err := json.Marshal(indexConfig)
	if err != nil {
		return err
	}
	req := &request{
		method:      METHOD_PUT,
		path:        "/logstores/" + logstore + "/index",
		payload:     data,
		contentType: "application/json",
	}

	return proj.client.requestWithClose(req)
}