feat: setup middleware
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.dynamicdiscord.de/malobeo/portal/openapi"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var apiClient *openapi.APIClient
|
||||
func GetApiClient(c *gin.Context) *openapi.APIClient {
|
||||
configuration := openapi.NewConfiguration()
|
||||
//TODO: read from env
|
||||
configuration.Host = "localhost:8000"
|
||||
configuration.Scheme = "http"
|
||||
|
||||
func GetApiClient() *openapi.APIClient {
|
||||
if apiClient == nil {
|
||||
configuration := openapi.NewConfiguration()
|
||||
configuration.Host = "localhost:8000"
|
||||
configuration.Scheme = "http"
|
||||
apiClient = openapi.NewAPIClient(configuration)
|
||||
if c != nil {
|
||||
authToken, err := c.Cookie("Authorization")
|
||||
|
||||
if err == nil && len(authToken) > 0 {
|
||||
configuration.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %v", authToken))
|
||||
}
|
||||
}
|
||||
|
||||
return apiClient
|
||||
return openapi.NewAPIClient(configuration)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user