Not reaching catalog

This commit is contained in:
pb 2024-02-15 10:48:40 +01:00
parent 2fd85737d1
commit 5004dc9b06
9 changed files with 49 additions and 7 deletions

View File

@ -32,7 +32,7 @@ COPY scripts scripts
# Configuration file : aims at making your variables suit your environment (local, docker, prod, etc) # 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 # FROM golang

17
conf/conf.go Normal file
View File

@ -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
}

View File

@ -3,6 +3,7 @@ package controllers
import ( import (
OCCatalog_cli "oc-search/api-client/oc-catalog" OCCatalog_cli "oc-search/api-client/oc-catalog"
"github.com/beego/beego/logs"
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
) )
@ -14,8 +15,14 @@ type MainController struct {
var OCCatalogAPI *OCCatalog_cli.APIClient var OCCatalogAPI *OCCatalog_cli.APIClient
func init() { 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"}) // 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{ DefaultHeader: map[string]string{
"authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE2MTMwMDI0NjAsInVzZXJfaWQiOiJhc2QifQ.TXT18aeulnCrtedKKFVaD0BapOTdVAFcJJdVS7zk0I8", "authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE2MTMwMDI0NjAsInVzZXJfaWQiOiJhc2QifQ.TXT18aeulnCrtedKKFVaD0BapOTdVAFcJJdVS7zk0I8",
}, },
@ -25,6 +32,9 @@ func init() {
// Get provides the main page // Get provides the main page
func (c *MainController) Get() { func (c *MainController) Get() {
logs.Debug("received : %v",c.Ctx.Input.RequestBody)
c.Data["Website"] = "beego.me" c.Data["Website"] = "beego.me"
c.Data["Email"] = "astaxie@gmail.com" c.Data["Email"] = "astaxie@gmail.com"
c.TplName = "index.tpl" c.TplName = "index.tpl"

View File

@ -35,6 +35,10 @@ func loadSingleFile(filename string) []models.Resource {
// Get implements simple search // Get implements simple search
func (c *SearchController) Get() { func (c *SearchController) Get() {
logs.Debug("received : %v",c.Ctx.Input.RequestBody)
query := c.GetString("q") query := c.GetString("q")
var resources OCCatalog_cli.ModelsSearchResult var resources OCCatalog_cli.ModelsSearchResult

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/beego/beego/logs"
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
"github.com/sbabiv/xml2map" "github.com/sbabiv/xml2map"
) )
@ -19,6 +20,8 @@ type WorkflowController struct {
// Get i // Get i
func (c *WorkflowController) Get() { func (c *WorkflowController) Get() {
logs.Debug("received : %v",c.Ctx.Input.RequestBody)
c.Data["Website"] = "beego.me" c.Data["Website"] = "beego.me"
c.Data["Email"] = "astaxie@gmail.com" c.Data["Email"] = "astaxie@gmail.com"
c.TplName = "workflow.tpl" c.TplName = "workflow.tpl"

View File

@ -2,7 +2,7 @@ version: '3.4'
services: services:
oc-search: oc-search:
build: . image: oc-search:debugging
container_name: oc-search container_name: oc-search
ports: ports:
- 8080:8080 - 8080:8080

3
docker_search.json Normal file
View File

@ -0,0 +1,3 @@
{
"oc-catalog" : "catalog:49618"
}

3
local_search.json Normal file
View File

@ -0,0 +1,3 @@
{
"oc-catalog" : "localhost:49618"
}

10
main.go
View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"oc-search/models" conf "oc-search/conf"
_ "oc-search/routers" _ "oc-search/routers"
_ "oc-search/views" _ "oc-search/views"
@ -11,7 +11,7 @@ import (
) )
const defaultConfigFile = "/etc/oc/search.json" const defaultConfigFile = "/etc/oc/search.json"
const localConfigFile = "./search.json" const localConfigFile = "./local_search.json"
func main() { func main() {
log := logs.NewLogger(10000) log := logs.NewLogger(10000)
@ -19,7 +19,7 @@ func main() {
configFile := "" configFile := ""
var o *onion.Onion var o *onion.Onion
l3 := onion.NewEnvLayerPrefix("_", "OCDISCOVERY_") l3 := onion.NewEnvLayerPrefix("_", "OCSEARCH_")
l2, err := onion.NewFileLayer(defaultConfigFile, nil) l2, err := onion.NewFileLayer(defaultConfigFile, nil)
if err == nil { if err == nil {
logs.Info("Config file found : " + defaultConfigFile) logs.Info("Config file found : " + defaultConfigFile)
@ -41,11 +41,13 @@ func main() {
o = onion.New(l1, l3) 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.BConfig.WebConfig.Session.SessionOn = true
beego.SetStaticPath("/favicon.ico", "/static/favicon.ico") beego.SetStaticPath("/favicon.ico", "/static/favicon.ico")
beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
logs.Info("Will contact oc-catalog at : %v", conf.GetConfig().OcCatalogUrl)
beego.Run() beego.Run()
} }