Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6434438023/oph24 8 documentation swagger #11

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ REDIS_PASSWORD=123456

APP_PORT=3000
APP_ENV=development
APP_HOST=127.0.0.1:3000

OAUTH2_CLIENT_ID=123456
OAUTH2_CLIENT_SECRET=123456
OAUTH2_REDIRECT_URL=http://localhost:3000/auth/callback
OAUTH2_SCOPES=openid,email

CORS_ORIGINS=https://openhouse.chula.ac.th,https://isd-sgcu.in.th,https://openhouse.isd-sgcu.in.th
CORS_ORIGINS=https://openhouse.chula.ac.th,https://isd-sgcu.in.th,https://openhouse.isd-sgcu.in.th
1 change: 1 addition & 0 deletions cfgldr/cfgldr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type DatabaseConfig struct {
type AppConfig struct {
Port string `mapstructure:"PORT"`
Env string `mapstructure:"ENV"`
Host string `mapstructure:"HOST"`
}

type RedisConfig struct {
Expand Down
17 changes: 16 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,34 @@ import (

"github.com/gin-gonic/gin"
"github.com/isd-sgcu/oph66-backend/di"
"github.com/isd-sgcu/oph66-backend/docs"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)

// @title OPH-66 Backend API
// @version 1.0
// @description Documentation outlines the specifications and endpoints for the OPH-66 Backend API.
// @Schemes http https
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @description Type "Bearer" followed by a space and JWT token.
func main() {
container, err := di.Init()
if err != nil {
panic(fmt.Sprintf("unable to init di: %v", err))
}
container.Logger.Info("init container successfully")

docs.SwaggerInfo.Host = container.Config.AppConfig.Host

if !container.Config.AppConfig.IsDevelopment() {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()

r.Use(gin.HandlerFunc(container.CorsHandler))

r.GET("/_hc", container.HcHandler.HealthCheck)
r.GET("/live", container.FeatureflagHandler.GetLivestreamInfo)
r.GET("/events", container.EventHandler.GetAllEvents)
Expand All @@ -30,6 +42,9 @@ func main() {
r.GET("/auth/login", container.AuthHandler.GoogleLogin)
r.GET("/auth/callback", container.AuthHandler.GoogleCallback)

if container.Config.AppConfig.Env == "development" {
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}
if err := r.Run(fmt.Sprintf(":%v", container.Config.AppConfig.Port)); err != nil {
container.Logger.Fatal("unable to start server")
}
Expand Down
Loading