update
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
openai "github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
@@ -12,23 +10,33 @@ type Controller struct {
|
||||
openaiClient *openai.Client
|
||||
unraidAPIKey string
|
||||
unraidURI string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
RedirectURL string
|
||||
AuthURL string
|
||||
TokenURL string
|
||||
}
|
||||
|
||||
func NewController() *Controller {
|
||||
err := godotenv.Load(".env")
|
||||
|
||||
openaiApiKey := os.Getenv("OPENAI_API_KEY")
|
||||
openaiClient := openai.NewClient(openaiApiKey)
|
||||
unraidAPIKey := os.Getenv("UNRAID_API_KEY")
|
||||
unraidURI := os.Getenv("UNRAID_URI")
|
||||
ClientID := os.Getenv("ClientID")
|
||||
ClientSecret := os.Getenv("ClientSecret")
|
||||
RedirectURL := os.Getenv("RedirectURL")
|
||||
AuthURL := os.Getenv("AuthURL")
|
||||
TokenURL := os.Getenv("TokenURL")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(".env file not found, using environment variables")
|
||||
}
|
||||
return &Controller{
|
||||
openaiClient: openaiClient,
|
||||
openaiClient: openai.NewClient(openaiApiKey),
|
||||
unraidAPIKey: unraidAPIKey,
|
||||
unraidURI: unraidURI,
|
||||
ClientID: ClientID,
|
||||
ClientSecret: ClientSecret,
|
||||
RedirectURL: RedirectURL,
|
||||
AuthURL: AuthURL,
|
||||
TokenURL: TokenURL,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
controller/token.go
Normal file
25
controller/token.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
// GenerateToken godoc
|
||||
//
|
||||
// @Summary Generate Health status
|
||||
// @Description Get the health of the API
|
||||
// @Tags token
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} json "response"
|
||||
// @Router /token/GenerateToken [get]
|
||||
func (c *Controller) GenerateToken(conf *oauth2.Config) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// Redirect user to the authorization URL
|
||||
authURL := conf.AuthCodeURL("state", oauth2.AccessTypeOffline)
|
||||
c.Redirect(http.StatusTemporaryRedirect, authURL)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user