| 1 | package sls |
| 2 | |
| 3 | import "encoding/json" |
| 4 | |
| 5 | type IndexLineConfig struct { |
| 6 | TokenList []string `json:"token,omitempty"` |
| 7 | CaseSensitive bool `json:"caseSensitive"` |
| 8 | IncludeKeys []string `json:"include_keys,omitempty"` |
| 9 | Exclude_keys []string `json:"exclude_keys,omitempty"` |
| 10 | } |
| 11 | |
| 12 | type IndexKeyConfig struct { |
| 13 | TokenList []string `json:"token,omitempty"` |
| 14 | CaseSensitive bool `json:"caseSensitive,omitempty"` |
| 15 | } |
| 16 | |
| 17 | type IndexConfig struct { |
| 18 | TTL int `json:"ttl,omitempty"` |
| 19 | LineConfig IndexLineConfig `json:"line,omitempty"` |
| 20 | KeyConfigList map[string]IndexKeyConfig `json:"keys,omitempty"` |
| 21 | } |
| 22 | |
| 23 | func (proj *Project) CreateIndex(logstore string, indexConfig *IndexConfig) error { |
| 24 | data, err := json.Marshal(indexConfig) |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | |
| 29 | req := &request{ |
| 30 | method: METHOD_POST, |
| 31 | path: "/logstores/" + logstore + "/index", |
| 32 | payload: data, |
| 33 | contentType: "application/json", |
| 34 | } |
| 35 | return proj.client.requestWithClose(req) |
| 36 | } |
| 37 | |
| 38 | func (proj *Project) DeleteIndex(logstore string) error { |
| 39 | req := &request{ |
| 40 | method: METHOD_DELETE, |
| 41 | path: "/logstores/" + logstore + "/index", |
| 42 | } |
| 43 | |
| 44 | return proj.client.requestWithClose(req) |
| 45 | } |
| 46 | |
| 47 | func (proj *Project) GetIndex(logstore string) (*IndexConfig, error) { |
| 48 | req := &request{ |
| 49 | method: METHOD_GET, |
| 50 | path: "/logstores/" + logstore + "/index", |
| 51 | } |
| 52 | indexConfig := &IndexConfig{} |
| 53 | if err := proj.client.requestWithJsonResponse(req, indexConfig); err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | return indexConfig, nil |
| 57 | } |
| 58 | |
| 59 | func (proj *Project) UpdateIndex(logstore string, indexConfig *IndexConfig) error { |
| 60 | data, err := json.Marshal(indexConfig) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | req := &request{ |
| 65 | method: METHOD_PUT, |
| 66 | path: "/logstores/" + logstore + "/index", |
| 67 | payload: data, |
| 68 | contentType: "application/json", |
| 69 | } |
| 70 | |
| 71 | return proj.client.requestWithClose(req) |
| 72 | } |