package controllers import ( OCCatalog_cli "oc-search/api-client/oc-catalog" conf "oc-search/conf" "github.com/beego/beego/logs" 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 // 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) func init() { // OcCatalogURL := conf.GetConfig().OcCatalogUrl // if OcCatalogURL == "" { // panic("OcCatalogUrl is blank") // } // auth := context.WithValue(context.Background(), OCCatalog_cli.ContextAPIKey, OCCatalog_cli.APIKey{Key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE2MTI1OTI3MDIsInVzZXJfaWQiOiJ4ZCJ9.kTLb1FtpdnaobUpe5u9Jw8S7Cc6gf7ExmU4U3XMcC2o"}) OCCatalogAPI = OCCatalog_cli.NewAPIClient(&OCCatalog_cli.Configuration{BasePath: "http://"+ conf.GetConfig().OcCatalogUrl +"/v1", 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() { logs.Debug("received : %v",c.Ctx.Input.RequestBody) c.Data["Website"] = "beego.me" c.Data["Email"] = "astaxie@gmail.com" c.TplName = "index.tpl" }