diff --git a/controllers/workflow.go b/controllers/workflow.go index ed35753..eabd1c4 100644 --- a/controllers/workflow.go +++ b/controllers/workflow.go @@ -3,6 +3,7 @@ package controllers import ( "encoding/json" "errors" + "fmt" "time" oclib "cloud.o-forge.io/core/oc-lib" @@ -54,14 +55,17 @@ func (o *WorkflowController) Put() { o.ServeJSON() } +var NATS_SERVER = "nats://localhost:4222" + func (o *WorkflowController) SetNATSPub(res map[string]interface{}, data oclib.LibData) string { if sched, ok := res["schedule"]; ok && sched != nil && data.Code == 200 { workflow := data.ToWorkflow() if workflow != nil && workflow.Schedule != nil { // HERE NATS - nc, err := nats.Connect(nats.DefaultURL) + fmt.Println("NATS_SERVER", NATS_SERVER) + nc, err := nats.Connect(NATS_SERVER) if err != nil { - return " -> Could not reach NATS server" + return " -> Could not reach NATS server : " + err.Error() } start := "" if workflow.Schedule.Start != nil { diff --git a/docker-compose.base.yml b/docker-compose.base.yml index 7376a79..cefe5d6 100644 --- a/docker-compose.base.yml +++ b/docker-compose.base.yml @@ -30,4 +30,5 @@ volumes: networks: catalog: + external: true # name: catalog diff --git a/docker_workflow.json b/docker_workflow.json index 68e4a35..5c7185b 100644 --- a/docker_workflow.json +++ b/docker_workflow.json @@ -1,5 +1,6 @@ { "MONGO_URL":"mongodb://mongo:27017/", "MONGO_DATABASE":"DC_myDC", - "BOOKING_PATH": ":8089" + "BOOKING_PATH": ":8089", + "NATS_URL": "nats://nats:4222" } \ No newline at end of file diff --git a/go.mod b/go.mod index 3f8908b..b19cb50 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.22.0 toolchain go1.22.4 require ( - cloud.o-forge.io/core/oc-lib v0.0.0-20240813084212-4911e32ec215 + cloud.o-forge.io/core/oc-lib v0.0.0-20240820133125-d13249d87ded github.com/beego/beego/v2 v2.2.2 github.com/goraz/onion v0.1.3 - github.com/nats-io/nats.go v1.36.0 + github.com/nats-io/nats.go v1.37.0 github.com/smartystreets/goconvey v1.7.2 ) diff --git a/go.sum b/go.sum index 91982a2..691f531 100644 --- a/go.sum +++ b/go.sum @@ -150,6 +150,20 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240813082955-3962b7c7aa52 h1:za+jN2MkDfi/H cloud.o-forge.io/core/oc-lib v0.0.0-20240813082955-3962b7c7aa52/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= cloud.o-forge.io/core/oc-lib v0.0.0-20240813084212-4911e32ec215 h1:Ra1RbFC41IFxJa38krCOHqWcTZvHj8W7FDPKcGnDIuw= cloud.o-forge.io/core/oc-lib v0.0.0-20240813084212-4911e32ec215/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240813123326-2d9b4587ac95 h1:YxgRbjwoBYMW/js9kc+9GJkg3rXrFF/cMXzTAJSM96M= +cloud.o-forge.io/core/oc-lib v0.0.0-20240813123326-2d9b4587ac95/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820072802-d848585b7cec h1:cXSOv6QDsp1XC0A30YJLFDHnFH45Hwzo31PBLLALxB4= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820072802-d848585b7cec/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820102030-8751d36b347d h1:zGfqhP8EHfp1nUPyDHCbKxeElAFXBGsjBYuMhAsHzR8= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820102030-8751d36b347d/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820105950-fbf4040f630c h1:euTfaTAgq3aVaCrUBkqmHkwItNZr6eDyi3wv+1xVJLE= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820105950-fbf4040f630c/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820113111-f59913170810 h1:mk5I3/uHManzfAyntYjNPoujS8iQ1SHCAfgbUUFCdpI= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820113111-f59913170810/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820125906-b6d9b6910fcd h1:77a73Cjf0gVVYDisVnz3xBOuRt/bGuImOng3FjtI5i8= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820125906-b6d9b6910fcd/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820133125-d13249d87ded h1:BtpPdQts0TMBle+LAEOdrkPlDLEFyF26ypJkSyQA9O4= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820133125-d13249d87ded/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= @@ -412,6 +426,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nats-io/nats.go v1.36.0 h1:suEUPuWzTSse/XhESwqLxXGuj8vGRuPRoG7MoRN/qyU= github.com/nats-io/nats.go v1.36.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= +github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= +github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= diff --git a/main.go b/main.go index 5de7233..6649763 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "oc-workflow/controllers" _ "oc-workflow/routers" oclib "cloud.o-forge.io/core/oc-lib" @@ -9,34 +10,26 @@ import ( ) const defaultConfigFile = "/etc/oc/workflow.json" -const localConfigFile = "./docker_workflow.json" func main() { configFile := "" var o *onion.Onion l3 := onion.NewEnvLayerPrefix("_", "OCWORKFLOW_") - l1, err := onion.NewFileLayer(localConfigFile, nil) - if err == nil { - configFile = localConfigFile - } l2, err := onion.NewFileLayer(defaultConfigFile, nil) if err == nil { configFile = defaultConfigFile } - if configFile == "" { + if configFile == "" || l2 == nil { o = onion.New(l3) - } else if l1 == nil && l2 == nil { - o = onion.New(l1, l2, l3) - } else if l1 == nil { + } else { o = onion.New(l2, l3) - } else if l2 == nil { - o = onion.New(l1, l3) } oclib.SetConfig( o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), ) oclib.Init("oc-workflow") + controllers.NATS_SERVER = o.GetStringDefault("NATS_URL", "nats://localhost:4222") oclib.AddPath(oclib.LibDataEnum(oclib.BOOKING), o.GetStringDefault("BOOKING_URL", ":8092")) // Normal beego init //if beego.BConfig.RunMode == "dev" { diff --git a/oc-workflow b/oc-workflow index fb319c4..6b54fc2 100755 Binary files a/oc-workflow and b/oc-workflow differ