updates
This commit is contained in:
@@ -12,7 +12,6 @@ type Controller struct {
|
||||
openaiClient *openai.Client
|
||||
unraidAPIKey string
|
||||
unraidURI string
|
||||
jwtToken string
|
||||
|
||||
config *configStruct
|
||||
}
|
||||
@@ -30,7 +29,6 @@ func NewController() *Controller {
|
||||
openaiClient := openai.NewClient(openaiApiKey)
|
||||
unraidAPIKey := os.Getenv("UNRAID_API_KEY")
|
||||
unraidURI := os.Getenv("UNRAID_URI")
|
||||
jwtToken := os.Getenv("jwtToken")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
@@ -40,7 +38,6 @@ func NewController() *Controller {
|
||||
openaiClient: openaiClient,
|
||||
unraidAPIKey: unraidAPIKey,
|
||||
unraidURI: unraidURI,
|
||||
jwtToken: jwtToken,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
controller/health.go
Normal file
21
controller/health.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// getHealth godoc
|
||||
//
|
||||
// @Summary Generate Health status
|
||||
// @Description Get the health of the API
|
||||
// @Tags health
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} json "response"
|
||||
// @Router /health/getHealth [get]
|
||||
func (c *Controller) GetHealth(ctx *gin.Context) {
|
||||
// Return the health in the response body
|
||||
ctx.JSON(http.StatusOK, gin.H{"health": "OK"})
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// generateTokenHandler godoc
|
||||
//
|
||||
// @Summary Generate JWT Token
|
||||
// @Description Gets the PSU Data from unraid
|
||||
// @Tags token
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Param token query string true "Secret Token"
|
||||
// @Success 200 {string} string "response"
|
||||
// @Router /token/generateTokenHandler [get]
|
||||
func (c *Controller) GenerateTokenHandler(ctx *gin.Context) {
|
||||
// Define the token claims
|
||||
claims := jwt.MapClaims{
|
||||
"exp": time.Now().Add(time.Hour * 24).Unix(),
|
||||
"iat": time.Now().Unix(),
|
||||
// Add any additional claims here...
|
||||
}
|
||||
|
||||
// Generate a new token with the claims
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
|
||||
// Sign the token with your secret key
|
||||
// TODO: Replace "my-secret-key" with your own secret key
|
||||
tokenString, err := token.SignedString([]byte(ctx.Query("token")))
|
||||
if err != nil {
|
||||
ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"message": "Failed to generate token"})
|
||||
return
|
||||
}
|
||||
|
||||
// Return the token in the response body
|
||||
ctx.JSON(http.StatusOK, gin.H{"token": tokenString})
|
||||
}
|
||||
Reference in New Issue
Block a user