diff --git a/consumer/README.md b/consumer/README.md index 31970bd6..5a99beba 100644 --- a/consumer/README.md +++ b/consumer/README.md @@ -77,7 +77,7 @@ consumerWorker.Start() ``` ch:=make(chan os.Signal) //将os信号值作为信道 -signal.Notify(ch) +signal.Notify(ch, os.Kill, os.Interrupt) consumerWorker.Start() if _, ok := <-ch; ok { // 当获取到os停止信号以后,例如ctrl+c触发的os信号,会调用消费者退出方法进行退出。 consumerWorker.StopAndWait() diff --git a/example/consumer/copy_data/copy_data.go b/example/consumer/copy_data/copy_data.go index 2c8d1d4b..fa81f9b8 100644 --- a/example/consumer/copy_data/copy_data.go +++ b/example/consumer/copy_data/copy_data.go @@ -2,11 +2,12 @@ package main import ( "fmt" - "github.com/aliyun/aliyun-log-go-sdk" - "github.com/aliyun/aliyun-log-go-sdk/consumer" - "github.com/go-kit/kit/log/level" "os" "os/signal" + + sls "github.com/aliyun/aliyun-log-go-sdk" + consumerLibrary "github.com/aliyun/aliyun-log-go-sdk/consumer" + "github.com/go-kit/kit/log/level" ) // README : @@ -47,7 +48,7 @@ func main() { } consumerWorker := consumerLibrary.InitConsumerWorker(option, process) ch := make(chan os.Signal) - signal.Notify(ch) + signal.Notify(ch, os.Kill, os.Interrupt) consumerWorker.Start() if _, ok := <-ch; ok { level.Info(consumerWorker.Logger).Log("msg", "get stop signal, start to stop consumer worker", "consumer worker name", option.ConsumerName) diff --git a/example/producer/native_pb_demo.go b/example/producer/native_pb_demo.go index f456624e..79fef074 100644 --- a/example/producer/native_pb_demo.go +++ b/example/producer/native_pb_demo.go @@ -19,7 +19,7 @@ func main() { producerConfig.AccessKeySecret = os.Getenv("AccessKeySecret") producerInstance := producer.InitProducer(producerConfig) ch := make(chan os.Signal) - signal.Notify(ch) + signal.Notify(ch, os.Kill, os.Interrupt) producerInstance.Start() var m sync.WaitGroup for i := 0; i < 10; i++ { diff --git a/example/producer/performance_test_demo.go b/example/producer/performance_test_demo.go index 0264232b..0ffeae66 100644 --- a/example/producer/performance_test_demo.go +++ b/example/producer/performance_test_demo.go @@ -2,14 +2,15 @@ package main import ( "fmt" - "github.com/aliyun/aliyun-log-go-sdk" - "github.com/aliyun/aliyun-log-go-sdk/producer" - "github.com/gogo/protobuf/proto" "math/rand" "os" "os/signal" "runtime" "time" + + sls "github.com/aliyun/aliyun-log-go-sdk" + "github.com/aliyun/aliyun-log-go-sdk/producer" + "github.com/gogo/protobuf/proto" ) var valueList [][]*string @@ -28,7 +29,7 @@ func main() { producerInstance := producer.InitProducer(producerConfig) ch := make(chan os.Signal) - signal.Notify(ch) + signal.Notify(ch, os.Kill, os.Interrupt) producerInstance.Start() fmt.Println("start send logs") for i := 0; i < 10; i++ { diff --git a/example/producer/producer_simple_demo.go b/example/producer/producer_simple_demo.go index c29fc4e9..c88ec588 100644 --- a/example/producer/producer_simple_demo.go +++ b/example/producer/producer_simple_demo.go @@ -17,7 +17,7 @@ func main() { producerConfig.AccessKeySecret = os.Getenv("AccessKeySecret") producerInstance := producer.InitProducer(producerConfig) ch := make(chan os.Signal) - signal.Notify(ch) + signal.Notify(ch, os.Kill, os.Interrupt) producerInstance.Start() var m sync.WaitGroup for i := 0; i < 10; i++ { diff --git a/example/producer/simple_callback_demo.go b/example/producer/simple_callback_demo.go index 026b756e..e5616ff2 100644 --- a/example/producer/simple_callback_demo.go +++ b/example/producer/simple_callback_demo.go @@ -36,7 +36,7 @@ func main() { producerConfig.AccessKeySecret = os.Getenv("AccessKeySecret") producerInstance := producer.InitProducer(producerConfig) ch := make(chan os.Signal) - signal.Notify(ch) + signal.Notify(ch, os.Kill, os.Interrupt) producerInstance.Start() var m sync.WaitGroup callBack := &Callback{} diff --git a/example/producer/use_ststoken_demo.go b/example/producer/use_ststoken_demo.go index 6a71faad..6818af8b 100644 --- a/example/producer/use_ststoken_demo.go +++ b/example/producer/use_ststoken_demo.go @@ -20,7 +20,7 @@ func main() { producerConfig.UpdateStsToken = updateStsToken producerInstance := producer.InitProducer(producerConfig) ch := make(chan os.Signal) - signal.Notify(ch) + signal.Notify(ch, os.Kill, os.Interrupt) producerInstance.Start() var m sync.WaitGroup for i := 0; i < 10; i++ { diff --git a/log_store.go b/log_store.go index d280bab4..e4e5589c 100644 --- a/log_store.go +++ b/log_store.go @@ -754,27 +754,15 @@ func (s *LogStore) UpdateIndexString(indexStr string) error { // DeleteIndex ... func (s *LogStore) DeleteIndex() error { - type Body struct { - project string `json:"projectName"` - store string `json:"logstoreName"` - } - - body, err := json.Marshal(Body{ - project: s.project.Name, - store: s.Name, - }) - if err != nil { - return err - } h := map[string]string{ - "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), + "x-log-bodyrawsize": "0", "Content-Type": "application/json", "Accept-Encoding": "deflate", // TODO: support lz4 } uri := fmt.Sprintf("/logstores/%s/index", s.Name) - r, err := request(s.project, "DELETE", uri, h, body) + r, err := request(s.project, "DELETE", uri, h, nil) if r != nil { r.Body.Close() } @@ -783,27 +771,14 @@ func (s *LogStore) DeleteIndex() error { // GetIndex ... func (s *LogStore) GetIndex() (*Index, error) { - type Body struct { - project string `json:"projectName"` - store string `json:"logstoreName"` - } - - body, err := json.Marshal(Body{ - project: s.project.Name, - store: s.Name, - }) - if err != nil { - return nil, err - } - h := map[string]string{ - "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/json", - "Accept-Encoding": "deflate", // TODO: support lz4 + "x-log-bodyrawsize": "0", + "Accept-Encoding": "deflate", } uri := fmt.Sprintf("/logstores/%s/index", s.Name) - r, err := request(s.project, "GET", uri, h, body) + r, err := request(s.project, "GET", uri, h, nil) if err != nil { return nil, err } @@ -820,27 +795,14 @@ func (s *LogStore) GetIndex() (*Index, error) { // GetIndexString ... func (s *LogStore) GetIndexString() (string, error) { - type Body struct { - project string `json:"projectName"` - store string `json:"logstoreName"` - } - - body, err := json.Marshal(Body{ - project: s.project.Name, - store: s.Name, - }) - if err != nil { - return "", err - } - h := map[string]string{ - "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/json", - "Accept-Encoding": "deflate", // TODO: support lz4 + "x-log-bodyrawsize": "0", + "Accept-Encoding": "deflate", } uri := fmt.Sprintf("/logstores/%s/index", s.Name) - r, err := request(s.project, "GET", uri, h, body) + r, err := request(s.project, "GET", uri, h, nil) if err != nil { return "", err } diff --git a/producer/README.md b/producer/README.md index 5a921b88..d7702e65 100644 --- a/producer/README.md +++ b/producer/README.md @@ -47,7 +47,7 @@ producerConfig.AccessKeyID = os.Getenv("AccessKeyID") producerConfig.AccessKeySecret = os.Getenv("AccessKeySecret") producerInstance:=producer.InitProducer(producerConfig) ch := make(chan os.Signal) -signal.Notify(ch) +signal.Notify(ch, os.Kill, os.Interrupt) producerInstance.Start() // 启动producer实例 ``` diff --git a/producer/callback_test.go b/producer/callback_test.go index aa3dbe84..a0bf29ec 100644 --- a/producer/callback_test.go +++ b/producer/callback_test.go @@ -9,8 +9,6 @@ import ( "time" ) - - type Callback struct { t *testing.T } @@ -34,7 +32,6 @@ func (callback *Callback) Fail(result *Result) { callback.t.Error("Failed to get error code") } - } func TestProducer_CallBack(t *testing.T) { @@ -44,7 +41,7 @@ func TestProducer_CallBack(t *testing.T) { producerConfig.AccessKeySecret = "" producerInstance := InitProducer(producerConfig) ch := make(chan os.Signal) - signal.Notify(ch) + signal.Notify(ch, os.Kill, os.Interrupt) producerInstance.Start() var m sync.WaitGroup callBack := &Callback{} @@ -68,7 +65,4 @@ func TestProducer_CallBack(t *testing.T) { producerInstance.Close(60000) } - - - -} \ No newline at end of file +}