update main.go
This commit is contained in:
1 parent
d73a4f44cb
commit
4c8b4e9fce
1 file changed
+85
@@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"esauth"
|
||||
"esauth/pkg/handler"
|
||||
"esauth/pkg/handler/oauth"
|
||||
"esauth/pkg/repository"
|
||||
"esauth/pkg/service"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
logrus.SetFormatter(new(logrus.TextFormatter))
|
||||
if err := initConfig(); err != nil {
|
||||
logrus.Fatalf("error occured while init config: %s", err.Error())
|
||||
}
|
||||
|
||||
// dbViper, err := initDBConfig()
|
||||
// if err != nil {
|
||||
// log.Fatalf("failed to init db config: %s", err.Error())
|
||||
// }
|
||||
|
||||
// var dbConfig repository.Config
|
||||
// dbViper.Unmarshal(&dbConfig)
|
||||
|
||||
if err := godotenv.Load(); err != nil {
|
||||
logrus.Fatalf("error loading env vars: %s", err.Error())
|
||||
}
|
||||
|
||||
db, err := repository.NewDB(repository.Config{
|
||||
Host: viper.GetString("db.host"),
|
||||
Port: viper.GetString("db.port"),
|
||||
Username: viper.GetString("db.username"),
|
||||
DBName: viper.GetString("db.dbname"),
|
||||
Password: os.Getenv("DB_PASSWORD"),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
logrus.Fatalf("failed to init database: %s", err.Error())
|
||||
}
|
||||
|
||||
repos := repository.NewRepository(db)
|
||||
services := service.NewService(repos)
|
||||
|
||||
handlers := handler.NewHandler(
|
||||
services,
|
||||
repos,
|
||||
&oauth.TelegramOAuth{
|
||||
BotToken: os.Getenv("TELEGRAM_BOT_TOKEN"),
|
||||
BotId: viper.GetString("oauth.telegram.botId"),
|
||||
Service: services,
|
||||
Repo: repos,
|
||||
},
|
||||
&oauth.GoogleOAuth{
|
||||
GoogleOauthConfig: &oauth2.Config{
|
||||
RedirectURL: viper.GetString("oauth.google.redirectURL"), // URL для callback после авторизации
|
||||
ClientID: viper.GetString("oauth.google.clientID"),
|
||||
ClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"),
|
||||
Scopes: viper.GetStringSlice("oauth.google.scopes"),
|
||||
Endpoint: google.Endpoint,
|
||||
},
|
||||
Service: services,
|
||||
Repo: repos,
|
||||
},
|
||||
)
|
||||
|
||||
srv := new(esauth.Server)
|
||||
if err := srv.Run(viper.GetString("port"), handlers.InitRoutes()); err != nil {
|
||||
logrus.Fatalf("error occured while running http server: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func initConfig() error {
|
||||
viper.AddConfigPath("configs")
|
||||
viper.SetConfigName("config")
|
||||
return viper.ReadInConfig()
|
||||
}
|
||||
Reference in new issue
Block a user