update oc-workflow lib version

This commit is contained in:
mr 2024-08-21 08:40:46 +02:00
parent 6f0b1ffcf4
commit 1be4d79c75
7 changed files with 31 additions and 16 deletions

View File

@ -3,6 +3,7 @@ package controllers
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"time" "time"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
@ -54,14 +55,17 @@ func (o *WorkflowController) Put() {
o.ServeJSON() o.ServeJSON()
} }
var NATS_SERVER = "nats://localhost:4222"
func (o *WorkflowController) SetNATSPub(res map[string]interface{}, data oclib.LibData) string { func (o *WorkflowController) SetNATSPub(res map[string]interface{}, data oclib.LibData) string {
if sched, ok := res["schedule"]; ok && sched != nil && data.Code == 200 { if sched, ok := res["schedule"]; ok && sched != nil && data.Code == 200 {
workflow := data.ToWorkflow() workflow := data.ToWorkflow()
if workflow != nil && workflow.Schedule != nil { if workflow != nil && workflow.Schedule != nil {
// HERE NATS // HERE NATS
nc, err := nats.Connect(nats.DefaultURL) fmt.Println("NATS_SERVER", NATS_SERVER)
nc, err := nats.Connect(NATS_SERVER)
if err != nil { if err != nil {
return " -> Could not reach NATS server" return " -> Could not reach NATS server : " + err.Error()
} }
start := "" start := ""
if workflow.Schedule.Start != nil { if workflow.Schedule.Start != nil {

View File

@ -30,4 +30,5 @@ volumes:
networks: networks:
catalog: catalog:
external: true
# name: catalog # name: catalog

View File

@ -1,5 +1,6 @@
{ {
"MONGO_URL":"mongodb://mongo:27017/", "MONGO_URL":"mongodb://mongo:27017/",
"MONGO_DATABASE":"DC_myDC", "MONGO_DATABASE":"DC_myDC",
"BOOKING_PATH": ":8089" "BOOKING_PATH": ":8089",
"NATS_URL": "nats://nats:4222"
} }

4
go.mod
View File

@ -5,10 +5,10 @@ go 1.22.0
toolchain go1.22.4 toolchain go1.22.4
require ( 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/beego/beego/v2 v2.2.2
github.com/goraz/onion v0.1.3 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 github.com/smartystreets/goconvey v1.7.2
) )

16
go.sum
View File

@ -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-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 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-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= 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 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= 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/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 h1:suEUPuWzTSse/XhESwqLxXGuj8vGRuPRoG7MoRN/qyU=
github.com/nats-io/nats.go v1.36.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= 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 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=

15
main.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"oc-workflow/controllers"
_ "oc-workflow/routers" _ "oc-workflow/routers"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
@ -9,34 +10,26 @@ import (
) )
const defaultConfigFile = "/etc/oc/workflow.json" const defaultConfigFile = "/etc/oc/workflow.json"
const localConfigFile = "./docker_workflow.json"
func main() { func main() {
configFile := "" configFile := ""
var o *onion.Onion var o *onion.Onion
l3 := onion.NewEnvLayerPrefix("_", "OCWORKFLOW_") l3 := onion.NewEnvLayerPrefix("_", "OCWORKFLOW_")
l1, err := onion.NewFileLayer(localConfigFile, nil)
if err == nil {
configFile = localConfigFile
}
l2, err := onion.NewFileLayer(defaultConfigFile, nil) l2, err := onion.NewFileLayer(defaultConfigFile, nil)
if err == nil { if err == nil {
configFile = defaultConfigFile configFile = defaultConfigFile
} }
if configFile == "" { if configFile == "" || l2 == nil {
o = onion.New(l3) o = onion.New(l3)
} else if l1 == nil && l2 == nil { } else {
o = onion.New(l1, l2, l3)
} else if l1 == nil {
o = onion.New(l2, l3) o = onion.New(l2, l3)
} else if l2 == nil {
o = onion.New(l1, l3)
} }
oclib.SetConfig( oclib.SetConfig(
o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
) )
oclib.Init("oc-workflow") 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")) oclib.AddPath(oclib.LibDataEnum(oclib.BOOKING), o.GetStringDefault("BOOKING_URL", ":8092"))
// Normal beego init // Normal beego init
//if beego.BConfig.RunMode == "dev" { //if beego.BConfig.RunMode == "dev" {

Binary file not shown.