github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/config/config.go (about) 1 // Copyright 2021 iLogtail Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package config 16 17 import "encoding/json" 18 19 // export http endpoints. 20 const ( 21 EnpointLoadconfig = "/loadconfig" 22 EnpointStop = "/stop" 23 EnpointHoldon = "/holdon" 24 ) 25 26 // LoadedConfig used to start logtail plugin sniffer. 27 type LoadedConfig struct { 28 Project string `json:"project"` 29 Logstore string `json:"logstore"` 30 ConfigName string `json:"config_name"` 31 LogstoreKey int64 `json:"logstore_key"` 32 JSONStr string `json:"json_str"` 33 } 34 35 func SerizlizeLoadedConfig(c []*LoadedConfig) []byte { 36 bytes, _ := json.Marshal(c) 37 return bytes 38 } 39 40 func DeserializeLoadedConfig(cfg []byte) ([]*LoadedConfig, error) { 41 var c []*LoadedConfig 42 if err := json.Unmarshal(cfg, &c); err != nil { 43 return nil, err 44 } 45 return c, nil 46 } 47 48 func GetRealConfigName(configName string) string { 49 realConfigName := configName 50 if len(configName) > 2 && (configName[len(configName)-2:] == "/1" || configName[len(configName)-2:] == "/2") { 51 realConfigName = configName[:len(configName)-2] 52 } 53 return realConfigName 54 }