/
rain
/
google-auth-bot
Обзор
Документация
Войти
/
rain
/
google-auth-bot
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
internal/microservice-api/webserver/server.go
77 строк
2 KB
Kirill
mvp telegram bot and some improvements for api
11 мар 2024, 00:54
11 мар 2024, 00:54
caa6f37
Код
Авторство
О чём код?
package webserver import ( "fmt" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" echoSwagger "github.com/swaggo/echo-swagger" "go.uber.org/zap" "github.com/sudora1n/google-auth-bot/internal/microservice-api/config" _ "github.com/sudora1n/google-auth-bot/internal/microservice-api/docs" "github.com/sudora1n/google-auth-bot/internal/microservice-api/logger" "github.com/sudora1n/google-auth-bot/internal/microservice-api/webserver/routes" ) // @title Google Auth Bot API // @version 1.0.0 // @description This is a Google Auth Bot API server. // @host localhost:8080 // @BasePath /v1 // @contact.name sudora1n // @contact.email admin@servicedomain.xyz // license.name MIT // license.url https://opensource.org/licenses/MIT // @securitydefinitions.apikey ApiKeyAuth // @scheme Bearer // @in header // @name Authorization // @schemes http https func InitServer() error { e := echo.New() e.Use(middleware.Logger()) e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ LogURI: true, LogStatus: true, LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error { logger.Logger.Info("request", zap.String("URI", v.URI), zap.Int("status", v.Status), ) return nil }, })) e.Use(middleware.CORS()) authMiddleware := func(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { if c.Request().Header.Get("Authorization") != config.Config.SECRET_KEY { return echo.ErrUnauthorized } return next(c) } } users := e.Group("/v1/users") users.Use(authMiddleware) users.GET("/:userId/create_or_return", routes.CreateOrReturnUser) users.GET("/:userId/change_lang", routes.ChangeLang) totps := e.Group("/v1/totps") totps.Use(authMiddleware) totps.GET("/add", routes.AddToTP) totps.GET("/find_all", routes.FindAllToTP) totps.GET("/remove", routes.RemoveToTP) e.GET("/ping", routes.Ping) e.GET("/swagger/*", echoSwagger.WrapHandler) return e.Start(fmt.Sprintf(":%d", config.Config.PORT)) }