소스 검색

defer server close

Darien Raymond 7 년 전
부모
커밋
0bc22154e5
1개의 변경된 파일6개의 추가작업 그리고 5개의 파일을 삭제
  1. 6 5
      main/main.go

+ 6 - 5
main/main.go

@@ -109,6 +109,7 @@ func main() {
 		// Configuration error. Exit with a special value to prevent systemd from restarting.
 		os.Exit(23)
 	}
+	defer server.Close()
 
 	if *test {
 		fmt.Println("Configuration OK.")
@@ -123,9 +124,9 @@ func main() {
 	// Explicitly triggering GC to remove garbage from config loading.
 	runtime.GC()
 
-	osSignals := make(chan os.Signal, 1)
-	signal.Notify(osSignals, os.Interrupt, os.Kill, syscall.SIGTERM)
-
-	<-osSignals
-	server.Close()
+	{
+		osSignals := make(chan os.Signal, 1)
+		signal.Notify(osSignals, os.Interrupt, os.Kill, syscall.SIGTERM)
+		<-osSignals
+	}
 }