86 lines
2.4 KiB
Go
86 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/DeveloperDurp/DurpAPI/controller"
|
|
_ "github.com/DeveloperDurp/DurpAPI/docs"
|
|
"github.com/DeveloperDurp/DurpAPI/httputil"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
swaggerFiles "github.com/swaggo/files"
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
|
)
|
|
|
|
// @title Swagger Example API
|
|
// @version 1.0
|
|
// @description This is a sample server celler server.
|
|
// @termsOfService http://swagger.io/terms/
|
|
|
|
// @contact.name API Support
|
|
// @contact.url http://www.swagger.io/support
|
|
// @contact.email support@swagger.io
|
|
|
|
// @license.name Apache 2.0
|
|
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
// @host localhost:8080
|
|
// @BasePath /api/v1
|
|
|
|
// @securityDefinitions.basic BasicAuth
|
|
|
|
// @securityDefinitions.apikey ApiKeyAuth
|
|
// @in header
|
|
// @name Authorization
|
|
// @description Description for what is this security definition being used
|
|
|
|
// @securitydefinitions.oauth2.application OAuth2Application
|
|
// @tokenUrl https://example.com/oauth/token
|
|
// @scope.write Grants write access
|
|
// @scope.admin Grants read and write access to administrative information
|
|
|
|
// @securitydefinitions.oauth2.implicit OAuth2Implicit
|
|
// @authorizationUrl https://example.com/oauth/authorize
|
|
// @scope.write Grants write access
|
|
// @scope.admin Grants read and write access to administrative information
|
|
|
|
// @securitydefinitions.oauth2.password OAuth2Password
|
|
// @tokenUrl https://example.com/oauth/token
|
|
// @scope.read Grants read access
|
|
// @scope.write Grants write access
|
|
// @scope.admin Grants read and write access to administrative information
|
|
|
|
// @securitydefinitions.oauth2.accessCode OAuth2AccessCode
|
|
// @tokenUrl https://example.com/oauth/token
|
|
// @authorizationUrl https://example.com/oauth/authorize
|
|
// @scope.admin Grants read and write access to administrative information
|
|
|
|
func main() {
|
|
|
|
r := gin.Default()
|
|
|
|
c := controller.NewController()
|
|
|
|
v1 := r.Group("/api/v1")
|
|
{
|
|
openai := v1.Group("/openai")
|
|
{
|
|
openai.GET("general", c.GeneralOpenAI)
|
|
openai.GET("travelagent", c.TravelAgentOpenAI)
|
|
}
|
|
}
|
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
r.Run(":8080")
|
|
}
|
|
|
|
func auth() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if len(c.GetHeader("Authorization")) == 0 {
|
|
httputil.NewError(c, http.StatusUnauthorized, errors.New("Authorization is required Header"))
|
|
c.Abort()
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|