check sse good
This commit is contained in:
parent
eba2e48bc4
commit
a4782cb630
@ -126,6 +126,8 @@ func Run(ctx context.Context, cfg initialize.Config, build Build) error {
|
||||
}
|
||||
}()
|
||||
|
||||
srv.ListRoutes()
|
||||
|
||||
shutdownGroup.Add(closer.CloserFunc(srv.Shutdown))
|
||||
//shutdownGroup.Add(closer.CloserFunc(adminServer.Shutdown))
|
||||
//shutdownGroup.Add(closer.CloserFunc(grpcServer.Stop))
|
||||
|
@ -17,7 +17,6 @@ func (t *TicketController) Register(router fiber.Router) {
|
||||
router.Post("/vote", t.Vote)
|
||||
router.Post("/close", t.CloseTicket)
|
||||
router.Post("/shown", t.SetShown)
|
||||
|
||||
}
|
||||
|
||||
func (t *TicketController) Name() string {
|
||||
|
@ -7,21 +7,26 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
MongoURI string `env:"BB_MONGO_URI" envDefault:"mongodb://localhost:27017"`
|
||||
MongoHost string `env:"MONGO_HOST" envDefault:"127.0.0.1"`
|
||||
MongoPort string `env:"MONGO_PORT" envDefault:"27020"`
|
||||
MongoUser string `env:"MONGO_USER" envDefault:"test"`
|
||||
MongoPassword string `env:"MONGO_PASSWORD" envDefault:"test"`
|
||||
MongoDatabase string `env:"MONGO_DB" envDefault:"admin"`
|
||||
MongoAuth string `env:"MONGO_AUTH" envDefault:"admin"`
|
||||
NumberPortLocal string `env:"BB_PORT" envDefault:"1488"`
|
||||
AccountAddress string `env:"BB_AccountAddress" envDefault:":8931"`
|
||||
LoggerDevMode bool `env:"BB_IS_PROD" envDefault:"false"`
|
||||
MinioEndpoint string `env:"BB_MINIO_EP" envDefault:"minio:9001"`
|
||||
MinioAccessKey string `env:"BB_MINIO_AK" envDefault:"minio"`
|
||||
MinioSecretKey string `env:"BB_MINIO_SK" envDefault:"miniostorage"`
|
||||
MinioEndpoint string `env:"BB_MINIO_EP" envDefault:"localhost:9005"`
|
||||
MinioAccessKey string `env:"BB_MINIO_AK" envDefault:"admin"`
|
||||
MinioSecretKey string `env:"BB_MINIO_SK" envDefault:"admin123"`
|
||||
MinioRegion string `env:"S3_REGION" envDefault:""`
|
||||
MinioToken string `env:"BB_MINIO_TOKEN" envDefault:""`
|
||||
MongoDbTable string `env:"DATABASE_TABLE" envDefault:"profile"`
|
||||
MongoCollections string `env:"COLLECTION_NAME" envDefault:"profile,role"`
|
||||
TgToken string `env:"TELEGRAM_TOKEN" envDefault:"5851043588:AAGXhigZAaNV1--n-jfS8eBgM7iZ2IDm668"`
|
||||
TgToken string `env:"TELEGRAM_TOKEN" envDefault:"7127966184:AAG1steOCH4wDvHRe9QcsXJPS4dWRyRYsqg"`
|
||||
RedisHost string `env:"REDIS_HOST" envDefault:"localhost:6379"`
|
||||
RedisPassword string `env:"REDIS_PASSWORD" envDefault:""`
|
||||
RedisDB int `env:"REDIS_DB" envDefault:"0"`
|
||||
RedisPassword string `env:"REDIS_PASSWORD" envDefault:"admin"`
|
||||
RedisDB int `env:"REDIS_DB" envDefault:"2"`
|
||||
TgChatID uint64 `env:"TELEGRAM_CHAT_ID" envDefault:"1001344671794"`
|
||||
HTTPHost string `env:"HTTP_HOST" envDefault:"localhost"`
|
||||
HTTPPort string `env:"HTTP_PORT" envDefault:"3000"`
|
||||
|
@ -2,24 +2,37 @@ package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
mdb "penahub.gitlab.yandexcloud.net/backend/penahub_common/mongo"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MongoDB(ctx context.Context, cfg Config) (*mongo.Database, error) {
|
||||
dbConfig := &mdb.Configuration{
|
||||
Host: cfg.MongoHost,
|
||||
Port: cfg.MongoPort,
|
||||
User: cfg.MongoUser,
|
||||
Password: cfg.MongoPassword,
|
||||
DatabaseName: cfg.MongoDatabase,
|
||||
Auth: cfg.MongoAuth,
|
||||
}
|
||||
|
||||
newCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
clientOptions := options.Client().ApplyURI(cfg.MongoURI)
|
||||
client, err := mongo.Connect(newCtx, clientOptions)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to connect to MongoDB: %w", err)
|
||||
|
||||
mongoDeps := &mdb.ConnectDeps{
|
||||
Configuration: dbConfig,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
err = client.Ping(newCtx, nil)
|
||||
|
||||
db, err := mdb.Connect(newCtx, mongoDeps)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to ping MongoDB: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
db := client.Database(cfg.MongoDbTable)
|
||||
err = db.Client().Ping(newCtx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
@ -25,7 +25,10 @@ type Server struct {
|
||||
func NewServer(config ServerConfig) *Server {
|
||||
app := fiber.New()
|
||||
|
||||
app.Use(config.MW.ExtractHostMiddleware, config.MW.MiddlewareLogger, config.MW.MiddlewareJwt, config.MW.MiddlewareRecovery, config.MW.MiddlewareGetJwt, config.MW.MiddlewareOriginAccess)
|
||||
app.Use(config.MW.MiddlewareLogger)
|
||||
app.Use(config.MW.MiddlewareOriginAccess)
|
||||
app.Use(config.MW.MiddlewareJwt)
|
||||
app.Use(config.MW.ExtractHostMiddleware)
|
||||
|
||||
s := &Server{
|
||||
Logger: config.Logger,
|
||||
|
@ -39,7 +39,7 @@ func SseWrapper(emitter DataEmitter) fiber.Handler {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("no token")
|
||||
}
|
||||
|
||||
ctx.Status(fiber.StatusOK).Context().SetBodyStreamWriter(func(w *bufio.Writer) {
|
||||
ctx.Context().SetBodyStreamWriter(func(w *bufio.Writer) {
|
||||
pingTicker := time.NewTicker(5 * time.Second)
|
||||
defer pingTicker.Stop()
|
||||
defer close(dE)
|
||||
|
Loading…
Reference in New Issue
Block a user