2023-08-26 22:04:56 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
OCCatalog_cli "oc-search/api-client/oc-catalog"
|
2024-02-16 10:23:22 +01:00
|
|
|
conf "oc-search/conf"
|
2023-08-26 22:04:56 +02:00
|
|
|
|
2024-02-15 10:48:40 +01:00
|
|
|
"github.com/beego/beego/logs"
|
2023-08-26 22:04:56 +02:00
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MainController is in charge of the main page
|
|
|
|
type MainController struct {
|
|
|
|
beego.Controller
|
|
|
|
}
|
|
|
|
|
|
|
|
var OCCatalogAPI *OCCatalog_cli.APIClient
|
|
|
|
|
2024-02-16 10:23:22 +01:00
|
|
|
// This method should not be called init() because it will
|
|
|
|
// lead to the parameter BasePath to not be able to
|
|
|
|
// retrieve its value from a config file, that will
|
|
|
|
// be read after the init has happened (at import of the package)
|
|
|
|
|
2023-08-26 22:04:56 +02:00
|
|
|
func init() {
|
2024-02-15 10:48:40 +01:00
|
|
|
|
|
|
|
// OcCatalogURL := conf.GetConfig().OcCatalogUrl
|
|
|
|
// if OcCatalogURL == "" {
|
|
|
|
// panic("OcCatalogUrl is blank")
|
|
|
|
// }
|
|
|
|
|
2023-08-26 22:04:56 +02:00
|
|
|
// auth := context.WithValue(context.Background(), OCCatalog_cli.ContextAPIKey, OCCatalog_cli.APIKey{Key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE2MTI1OTI3MDIsInVzZXJfaWQiOiJ4ZCJ9.kTLb1FtpdnaobUpe5u9Jw8S7Cc6gf7ExmU4U3XMcC2o"})
|
2024-02-16 10:23:22 +01:00
|
|
|
OCCatalogAPI = OCCatalog_cli.NewAPIClient(&OCCatalog_cli.Configuration{BasePath: "http://"+ conf.GetConfig().OcCatalogUrl +"/v1",
|
2023-08-26 22:04:56 +02:00
|
|
|
DefaultHeader: map[string]string{
|
|
|
|
"authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE2MTMwMDI0NjAsInVzZXJfaWQiOiJhc2QifQ.TXT18aeulnCrtedKKFVaD0BapOTdVAFcJJdVS7zk0I8",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
//TODO: Test API is reachable or throw exception
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get provides the main page
|
|
|
|
func (c *MainController) Get() {
|
2024-02-15 10:48:40 +01:00
|
|
|
|
|
|
|
logs.Debug("received : %v",c.Ctx.Input.RequestBody)
|
|
|
|
|
2023-08-26 22:04:56 +02:00
|
|
|
c.Data["Website"] = "beego.me"
|
|
|
|
c.Data["Email"] = "astaxie@gmail.com"
|
|
|
|
c.TplName = "index.tpl"
|
|
|
|
}
|