// WriteEvent does the actual work of formatting an SSE compliant message // sending it over the provided ResponseWriter and flushing. func WriteEvent(ctx context.Context, w http.ResponseWriter, e Event) { if e.Error != nil { fmt.Fprint(w, "event: err\n") fmt.Fprintf(w, "data: %s\n\n", e.Error.Error()) w.(http.Flusher).Flush() log.Error(ctx, e.Error) return } // TODO: add tests to ensure retry get's properly rendered if e.Retry != 0 { fmt.Fprintf(w, "retry: %d\n", e.Retry) } if e.ID != "" { fmt.Fprintf(w, "id: %s\n", e.ID) } if e.Event != "" { fmt.Fprintf(w, "event: %s\n", e.Event) } fmt.Fprintf(w, "data: %s\n\n", getJSON(e.Data)) w.(http.Flusher).Flush() }
hlog "github.com/stellar/horizon/log" ) var dbCmd = &cobra.Command{ Use: "db [command]", Short: "commands to manage horizon's postgres db", } var dbInitCmd = &cobra.Command{ Use: "init", Short: "install schema", Long: "init initializes the postgres database used by horizon.", Run: func(cmd *cobra.Command, args []string) { db, err := db2.Open(viper.GetString("db-url")) if err != nil { hlog.Error(err) os.Exit(1) } err = schema.Init(db) if err != nil { hlog.Error(err) os.Exit(1) } }, } var dbMigrateCmd = &cobra.Command{ Use: "migrate [up|down|redo] [COUNT]", Short: "migrate schema", Long: "performs a schema migration command",