25 lines
551 B
Go
25 lines
551 B
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"git.dynamicdiscord.de/malobeo/portal/openapi"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetApiClient(c *gin.Context) *openapi.APIClient {
|
|
configuration := openapi.NewConfiguration()
|
|
//TODO: read from env
|
|
configuration.Host = "localhost:8000"
|
|
configuration.Scheme = "http"
|
|
|
|
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)
|
|
}
|