Pārlūkot izejas kodu

dont start http listener until after goroutine returns

reid 2 gadi atpakaļ
vecāks
revīzija
92bd8ae43e
2 mainītis faili ar 3 papildinājumiem un 24 dzēšanām
  1. 0 21
      broadcast/broadcast.go
  2. 3 3
      main.go

+ 0 - 21
broadcast/broadcast.go

@@ -86,27 +86,6 @@ func bootstrapBroadcastState(config structs.SysConfig) (structs.AuthBroadcast, e
 	return res, nil
 }
 
-// // update broadcastState with a map of items
-// func UpdateBroadcastState(values map[string]interface{}) error {
-// 	mu.Lock()
-// 	defer mu.Unlock()
-// 	v := reflect.ValueOf(&broadcastState).Elem()
-// 	for key, value := range values {
-// 		// we are matching the map key with the broadcastState item
-// 		field := v.FieldByName(key)
-// 		if !field.IsValid() || !field.CanSet() {
-// 			return fmt.Errorf("field %s does not exist or is not settable", key)
-// 		}
-// 		val := reflect.ValueOf(value)
-// 		if field.Type() != val.Type() {
-// 			return fmt.Errorf("type mismatch for field %s: expected %s, got %s", key, field.Type(), val.Type())
-// 		}
-// 		field.Set(val)
-// 	}
-// 	BroadcastToClients()
-// 	return nil
-// }
-
 // update broadcastState with a map of items
 func UpdateBroadcastState(values map[string]interface{}) error {
     mu.Lock()

+ 3 - 3
main.go

@@ -26,9 +26,6 @@ func main() {
 	}
 	logger.Info("Starting GroundSeg")
 	logger.Info("Urbit is love <3")
-	r := mux.NewRouter()
-	r.HandleFunc("/ws", ws.WsHandler)
-	http.ListenAndServe(":3000", r)
 	// global SysConfig var is managed through config package
 	conf := config.Conf()
 	internetAvailable := config.NetCheck("1.1.1.1:53")
@@ -53,4 +50,7 @@ func main() {
 	logger.Info(pierList)
 	// block until returns (debug)
 	<-versionUpdateChannel
+	r := mux.NewRouter()
+	r.HandleFunc("/ws", ws.WsHandler)
+	http.ListenAndServe(":3000", r)
 }