From 5004dc9b06849409d7d9f1cca8b43fc12fb573c8 Mon Sep 17 00:00:00 2001 From: pb Date: Thu, 15 Feb 2024 10:48:40 +0100 Subject: [PATCH] Not reaching catalog --- Dockerfile | 2 +- conf/conf.go | 17 +++++++++++++++++ controllers/default.go | 12 +++++++++++- controllers/search.go | 4 ++++ controllers/workflow.go | 3 +++ docker-compose.yml | 2 +- docker_search.json | 3 +++ local_search.json | 3 +++ main.go | 10 ++++++---- 9 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 conf/conf.go create mode 100644 docker_search.json create mode 100644 local_search.json diff --git a/Dockerfile b/Dockerfile index ef0ccd6..b0fd28e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ COPY scripts scripts # Configuration file : aims at making your variables suit your environment (local, docker, prod, etc) -COPY local_search.json /etc/oc/search.json +COPY docker_search.json /etc/oc/search.json # FROM golang diff --git a/conf/conf.go b/conf/conf.go new file mode 100644 index 0000000..85bebce --- /dev/null +++ b/conf/conf.go @@ -0,0 +1,17 @@ +package conf + +import "sync" + +type Config struct { + OcCatalogUrl string +} + +var instance *Config +var once sync.Once + +func GetConfig() *Config { + once.Do(func() { + instance = &Config{} + }) + return instance +} diff --git a/controllers/default.go b/controllers/default.go index afcca0c..4afe330 100644 --- a/controllers/default.go +++ b/controllers/default.go @@ -3,6 +3,7 @@ package controllers import ( OCCatalog_cli "oc-search/api-client/oc-catalog" + "github.com/beego/beego/logs" beego "github.com/beego/beego/v2/server/web" ) @@ -14,8 +15,14 @@ type MainController struct { var OCCatalogAPI *OCCatalog_cli.APIClient 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://localhost:49618/v1", + OCCatalogAPI = OCCatalog_cli.NewAPIClient(&OCCatalog_cli.Configuration{BasePath: "http://"+ "oc-catalog:8080" +"/v1", DefaultHeader: map[string]string{ "authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE2MTMwMDI0NjAsInVzZXJfaWQiOiJhc2QifQ.TXT18aeulnCrtedKKFVaD0BapOTdVAFcJJdVS7zk0I8", }, @@ -25,6 +32,9 @@ func init() { // 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" diff --git a/controllers/search.go b/controllers/search.go index 2b8a5db..b18bf70 100644 --- a/controllers/search.go +++ b/controllers/search.go @@ -35,6 +35,10 @@ func loadSingleFile(filename string) []models.Resource { // Get implements simple search func (c *SearchController) Get() { + + logs.Debug("received : %v",c.Ctx.Input.RequestBody) + + query := c.GetString("q") var resources OCCatalog_cli.ModelsSearchResult diff --git a/controllers/workflow.go b/controllers/workflow.go index 991e963..1ad7ddc 100644 --- a/controllers/workflow.go +++ b/controllers/workflow.go @@ -7,6 +7,7 @@ import ( "os" "strings" + "github.com/beego/beego/logs" beego "github.com/beego/beego/v2/server/web" "github.com/sbabiv/xml2map" ) @@ -19,6 +20,8 @@ type WorkflowController struct { // Get i func (c *WorkflowController) Get() { + logs.Debug("received : %v",c.Ctx.Input.RequestBody) + c.Data["Website"] = "beego.me" c.Data["Email"] = "astaxie@gmail.com" c.TplName = "workflow.tpl" diff --git a/docker-compose.yml b/docker-compose.yml index 4aa6d99..2b949f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.4' services: oc-search: - build: . + image: oc-search:debugging container_name: oc-search ports: - 8080:8080 diff --git a/docker_search.json b/docker_search.json new file mode 100644 index 0000000..af01247 --- /dev/null +++ b/docker_search.json @@ -0,0 +1,3 @@ +{ + "oc-catalog" : "catalog:49618" +} \ No newline at end of file diff --git a/local_search.json b/local_search.json new file mode 100644 index 0000000..d2d79e9 --- /dev/null +++ b/local_search.json @@ -0,0 +1,3 @@ +{ + "oc-catalog" : "localhost:49618" +} \ No newline at end of file diff --git a/main.go b/main.go index a003e94..5454bd5 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main import ( - "oc-search/models" + conf "oc-search/conf" _ "oc-search/routers" _ "oc-search/views" @@ -11,7 +11,7 @@ import ( ) const defaultConfigFile = "/etc/oc/search.json" -const localConfigFile = "./search.json" +const localConfigFile = "./local_search.json" func main() { log := logs.NewLogger(10000) @@ -19,7 +19,7 @@ func main() { configFile := "" var o *onion.Onion - l3 := onion.NewEnvLayerPrefix("_", "OCDISCOVERY_") + l3 := onion.NewEnvLayerPrefix("_", "OCSEARCH_") l2, err := onion.NewFileLayer(defaultConfigFile, nil) if err == nil { logs.Info("Config file found : " + defaultConfigFile) @@ -41,11 +41,13 @@ func main() { o = onion.New(l1, l3) } - models.GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog", "localhost:49618") + conf.GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog", "localhost:49618") beego.BConfig.WebConfig.Session.SessionOn = true beego.SetStaticPath("/favicon.ico", "/static/favicon.ico") beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" + logs.Info("Will contact oc-catalog at : %v", conf.GetConfig().OcCatalogUrl) + beego.Run() }