Improve code readability
This commit is contained in:
		
							parent
							
								
									3fc1601f5d
								
							
						
					
					
						commit
						e0b3743a00
					
				| @ -21,7 +21,7 @@ func New(st *storage.Storage) *Hub { | |||||||
| 		subscribers: []*Subscription{}, | 		subscribers: []*Subscription{}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	go h.cleanupPeriodically() | 	go h.cleanupEverySecond() | ||||||
| 
 | 
 | ||||||
| 	return h | 	return h | ||||||
| } | } | ||||||
| @ -57,7 +57,7 @@ func (h *Hub) Sub(s *Subscription) { | |||||||
| 	h.subscribers = append(h.subscribers, s) | 	h.subscribers = append(h.subscribers, s) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (h *Hub) cleanupPeriodically() { | func (h *Hub) cleanupEverySecond() { | ||||||
| 	t := time.NewTicker(1 * time.Second) | 	t := time.NewTicker(1 * time.Second) | ||||||
| 
 | 
 | ||||||
| 	for { | 	for { | ||||||
|  | |||||||
							
								
								
									
										15
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								main.go
									
									
									
									
									
								
							| @ -17,7 +17,6 @@ const ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var ( | var ( | ||||||
| 	theStorage *storage.Storage |  | ||||||
| 	theHub *hub.Hub | 	theHub *hub.Hub | ||||||
| 	config struct { | 	config struct { | ||||||
| 		storage string | 		storage string | ||||||
| @ -30,18 +29,16 @@ func main() { | |||||||
| 	flag.IntVar(&config.port, "port", 4401, "Server HTTP port") | 	flag.IntVar(&config.port, "port", 4401, "Server HTTP port") | ||||||
| 	flag.Parse() | 	flag.Parse() | ||||||
| 
 | 
 | ||||||
| 	theStorage, err := storage.New(config.storage) | 	store, err := storage.New(config.storage) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		panic(err) | 		panic(err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	theHub = hub.New(theStorage) | 	shutdown := make(chan os.Signal) | ||||||
| 	ch := make(chan os.Signal) | 	signal.Notify(shutdown, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT) | ||||||
| 	signal.Notify(ch, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT) |  | ||||||
| 
 |  | ||||||
| 	go func() { | 	go func() { | ||||||
| 		<-ch | 		<-shutdown | ||||||
| 		theStorage.Close() | 		store.Close() | ||||||
| 		os.Exit(0) | 		os.Exit(0) | ||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
| @ -50,5 +47,7 @@ func main() { | |||||||
| 	fmt.Println("Storage path: %s", config.storage) | 	fmt.Println("Storage path: %s", config.storage) | ||||||
| 	fmt.Println("Server is running at http://127.0.0.1:%d", config.port) | 	fmt.Println("Server is running at http://127.0.0.1:%d", config.port) | ||||||
| 
 | 
 | ||||||
|  | 	theHub = hub.New(store) | ||||||
|  | 
 | ||||||
| 	startServer() | 	startServer() | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user