26 lines
593 B
Go
26 lines
593 B
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"git.dynamicdiscord.de/malobeo/portal/openapi"
|
|
"github.com/gin-gonic/gin"
|
|
"os"
|
|
)
|
|
|
|
func GetApiClient(c *gin.Context) *openapi.APIClient {
|
|
configuration := openapi.NewConfiguration()
|
|
//TODO: read from env
|
|
configuration.Host = os.Getenv("GATEKEEPER_HOST")
|
|
configuration.Scheme = os.Getenv("GATEKEEPER_SCHEME")
|
|
|
|
if c != nil {
|
|
authToken, err := c.Cookie("Authorization")
|
|
|
|
if err == nil && len(authToken) > 0 {
|
|
configuration.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %v", authToken))
|
|
}
|
|
}
|
|
|
|
return openapi.NewAPIClient(configuration)
|
|
}
|