diff --git a/Dockerfile b/Dockerfile index 1ed82d0..37fbe7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN timeout 15 bee run -gendoc=true -downdoc=true -runmode=dev || : RUN sed -i 's/http:\/\/127.0.0.1:8080\/swagger\/swagger.json/swagger.json/g' swagger/index.html -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o setup . RUN ls /app @@ -20,11 +20,11 @@ FROM scratch WORKDIR /app -COPY --from=builder /app/oc-workflow /usr/bin/ +COPY --from=builder /app/setup /usr/bin/ COPY --from=builder /app/swagger /app/swagger -COPY docker_workflow.json /etc/oc/workflow.json +COPY docker_conf.json /etc/oc/conf.json EXPOSE 8080 -ENTRYPOINT ["oc-workflow"] +ENTRYPOINT ["setup"] diff --git a/controllers/version.go b/controllers/version.go index 5c9af81..5d19edc 100644 --- a/controllers/version.go +++ b/controllers/version.go @@ -1,9 +1,9 @@ package controllers import ( - oclib "cloud.o-forge.io/core/oc-lib" "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" + "github.com/nats-io/nats.go" ) // VersionController operations for Version @@ -30,9 +30,7 @@ func (c *VersionController) Status() { state, code, err := api.GetState() if state == tools.ALIVE { - state, _, err = api.CheckRemoteAPIs([]string{ - "http://" + oclib.LibDataEnum(oclib.BOOKING).String() + oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)), - }) + _, err = nats.Connect(tools.GetConfig().NATSUrl) } if err != nil { errStr = err.Error() diff --git a/controllers/workflow.go b/controllers/workflow.go index 1d1acfc..99df64d 100644 --- a/controllers/workflow.go +++ b/controllers/workflow.go @@ -3,11 +3,10 @@ package controllers import ( "encoding/json" "errors" - "time" + "fmt" oclib "cloud.o-forge.io/core/oc-lib" "cloud.o-forge.io/core/oc-lib/models/utils" - w "cloud.o-forge.io/core/oc-lib/models/workflow" "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" ) @@ -41,6 +40,9 @@ func (o *WorkflowController) Put() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/", tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id", }, + utils.PEER.String(): { + tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc", + }, } // store and return Id or post with UUID var res map[string]interface{} @@ -63,6 +65,9 @@ func (o *WorkflowController) Post() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/", tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id", }, + utils.PEER.String(): { + tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc", + }, } var res map[string]interface{} json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) @@ -119,6 +124,9 @@ func (o *WorkflowController) Delete() { tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/", tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id", }, + utils.PEER.String(): { + tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc", + }, } id := o.Ctx.Input.Param(":id") caller := tools.NewHTTPCaller(paths) @@ -128,15 +136,15 @@ func (o *WorkflowController) Delete() { // @Title Check // @Description check booking -// @Param start_date path string "the booking start date" format "2006-01-02T15:04:05" -// @Param end_date path string "the booking end date" format "2006-01-02T15:04:05" +// @Param id path string "the booking workflow id" +// @Param start_date path string "the booking start date format "2006-01-02T15:04:05" +// @Param end_date path string "the booking end date" format 2006-01-02T15:04:05" // @Success 200 {object} models.object -// @router /check/:start_date/:end_date [get] +// @router /check/:id/:start_date/:end_date [get] func (o *WorkflowController) Check() { // store and return Id or post with UUID - date, err := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":start_date")) - date2, err2 := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":end_date")) - if err != nil || err2 != nil { + id := o.Ctx.Input.Param(":id") + if id == "" { o.Data["json"] = map[string]interface{}{ "data": map[string]interface{}{ "is_available": false, @@ -145,20 +153,34 @@ func (o *WorkflowController) Check() { "error": errors.New("invalid date format"), } } else { - workflow := &w.Workflow{} - workflow.Schedule = &w.WorkflowSchedule{Start: &date, End: &date2} - isAvailable, err := workflow.CheckBooking(oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/check/:start_date/:end_date") - code := 200 - if !isAvailable { - code = 409 - } - o.Data["json"] = map[string]interface{}{ - "data": map[string]interface{}{ - "is_available": isAvailable, - }, - "code": code, - "error": err, + fmt.Println("id", id) + res := oclib.LoadOne(oclib.LibDataEnum(oclib.WORKFLOW), id) + if res.Code == 200 { + workflow := res.ToWorkflow() + caller := tools.NewHTTPCaller(map[string]map[tools.METHOD]string{ + utils.PEER.String(): { + tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc", + }, + utils.BOOKING.String(): { + tools.GET: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/check/:id/" + o.Ctx.Input.Param(":start_date") + "/" + o.Ctx.Input.Param(":end_date"), + }, + }) + isAvailable, err := workflow.CheckBooking(caller) + code := 200 + if !isAvailable { + code = 409 + } + o.Data["json"] = map[string]interface{}{ + "data": map[string]interface{}{ + "is_available": isAvailable, + }, + "code": code, + "error": err, + } + } else { + o.Data["json"] = res } + } o.ServeJSON() } diff --git a/demo.json b/demo.json deleted file mode 100644 index 0637a08..0000000 --- a/demo.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/docker_conf.json b/docker_conf.json new file mode 100644 index 0000000..a5e44a8 --- /dev/null +++ b/docker_conf.json @@ -0,0 +1,8 @@ +{ + "MONGO_URL":"mongodb://mongo:27017/", + "MONGO_DATABASE":"DC_myDC", + "BOOKING_PATH": ":8092", + "NATS_URL": "nats://nats:4222", + "HOSTNAME": "oc-workflow", + "PORT" : 8080 +} \ No newline at end of file diff --git a/docker_workflow.json b/docker_workflow.json deleted file mode 100644 index 5c7185b..0000000 --- a/docker_workflow.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "MONGO_URL":"mongodb://mongo:27017/", - "MONGO_DATABASE":"DC_myDC", - "BOOKING_PATH": ":8089", - "NATS_URL": "nats://nats:4222" -} \ No newline at end of file diff --git a/go.mod b/go.mod index 907dbd1..3b2d2a9 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.0 toolchain go1.22.4 require ( - cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06 + cloud.o-forge.io/core/oc-lib v0.0.0-20240826085916-d0e1474f8f34 github.com/beego/beego/v2 v2.2.2 github.com/goraz/onion v0.1.3 github.com/nats-io/nats.go v1.37.0 @@ -87,7 +87,7 @@ require ( golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/mod v0.19.0 // indirect + golang.org/x/mod v0.20.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.24.0 // indirect diff --git a/go.sum b/go.sum index d8d4532..57be4e4 100644 --- a/go.sum +++ b/go.sum @@ -174,6 +174,66 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240821085824-c5f45e03f365 h1:Oh5yP25jvfv1n cloud.o-forge.io/core/oc-lib v0.0.0-20240821085824-c5f45e03f365/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06 h1:sYveE1C/0mpSr+ZmOYxuZ3fTWID7mr5hPiq0jQenv3Q= cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8 h1:y4hngS1bedPKYXecTCcZk2WkuQNFazD11rMng9dmIzI= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821141151-cf6143887ef2 h1:kO/RodX7gaND3s/zLad9f4yFDmb0vGRzlzP/j8Yqe0c= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821141151-cf6143887ef2/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821143829-498ec3e9d8b5 h1:xgB9hmFg6kQfk0Hpb/yjdVK6Q3IzDihSPSbQfnOJQEY= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821143829-498ec3e9d8b5/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821151922-b8b62dc2c8bf h1:s+Ow2r6UPXRbxAEHalPx7+89M3f99Fpl1HMMpMFIcTI= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821151922-b8b62dc2c8bf/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b h1:A7NBwTXoHTg/oDbnxnnSdiT85kZY4VvhcbUeb3q7Irk= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822081914-4abf59a10d97 h1:6tbeTQvRnD0vDUl+5SLMgAh9ukjGxQ9WKjNcvvxN7cQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822081914-4abf59a10d97/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822083903-bfa176a7c5ce h1:nJqBNioYDdki6O6N8m6AKChbBjpzcSwt1ixvpkIg+so= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822083903-bfa176a7c5ce/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822095923-d766e3a7c34f h1:Zvz2KtaU2NRf5PeHpis3Qrt2cRuoDaGPCrxuKq7rs9Y= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822095923-d766e3a7c34f/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822102938-1d3620845d08 h1:pyiba9+2PUPzia21HK9dXWodG8lg0kRI4ujsfypjS50= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822102938-1d3620845d08/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822103656-ce343459148b h1:yg+FCQ4onXSHwTGie+A+16f1YyZxJzO5unvZZ9jRi3I= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822103656-ce343459148b/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822112243-e69e13d8daf8 h1:35Hrl4lwqUom5Rbfi9wLRg2yMou3bTeL2ZAaDY0N79Y= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822112243-e69e13d8daf8/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822122949-9c0107e87c71 h1:9ACkwlAOi4DVh4xeE4TtOG8evqRmGI0K55LgPrKoGpA= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822122949-9c0107e87c71/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822125632-c8a137785133 h1:PWixdgAdoIvPQgywHhLIi68BxKP7vQPMekMC0l63o2c= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822125632-c8a137785133/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822131859-a42b6198cb8e h1:UwGalgCxXLbMadhyMe4/qfl6sJ6TkEA3cAP2vsSl6wo= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822131859-a42b6198cb8e/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822133827-d89826db44e0 h1:vy7/XwyvRv0ZjSjnwh1fs4xLB25pL2MsWaM1wL5ZH0c= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822133827-d89826db44e0/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822141307-d9b26e3fce6e h1:sBdqakykLKOE4Zb2Qg5++rtE3OnXgSSekuz4Qkmm65E= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822141307-d9b26e3fce6e/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822142821-3232cce1b4b6 h1:WOrh9TVPEXxYRWjA0wF3tqo0poboSLAChHat95w6O6U= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822142821-3232cce1b4b6/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822145413-fd2ad33f61db h1:RACtdyHFEDOkWgXsp7LtmRpUWGXIDAbikb0uEVdnIlg= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822145413-fd2ad33f61db/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822150931-37b7ed8d83fe h1:76XfxprM3O40tn1EgF6/iR0ZLagfKe5vEt9czStyQEQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822150931-37b7ed8d83fe/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823062324-2ad4c0bb911b h1:Fr0ORjIbXBsjM5IyvM0F7Oq/rAyV2ANQFr6ZvzKEZm4= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823062324-2ad4c0bb911b/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823082553-98fa1f6ca807 h1:BqqCAnV2pbrX09IoE3EaVgrKIJPTvzqPeMnt2nYhCs4= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823082553-98fa1f6ca807/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823091301-5b3779e4cb21 h1:OzsSJVL2jaLewUWfW4C30SVrY4y20+mxI3rbOGLCPyo= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823091301-5b3779e4cb21/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823134312-1986143dd0db h1:yqXbsLcBgSbTzg12TKfb+vpgEQ8zETHigvWKNs0TgC8= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823134312-1986143dd0db/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823153529-fd730741a424 h1:QNyxS3NfwqbsPgpq4qN5FqF92GZksXQVOuoxhtVW8EU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823153529-fd730741a424/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823161829-dd3570fa3736 h1:LPMkli9xpgNBYKb0DWU6agkvxQlunnMcV93ErkyDNrU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823161829-dd3570fa3736/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823201703-762cc19c1437 h1:kUo8fL+XVaPsL8oLUSbbGDFwr3pT8TvYbPbr6+Ub53E= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823201703-762cc19c1437/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823210057-8e80fa88beeb h1:7/GQRm485qUHpuJnW1QayD0jk4RTmf5PAOqM0xBwM7E= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823210057-8e80fa88beeb/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826074207-144e7f85062d h1:4x29d4HwFmrjRaAJhF+TBSinQwSDh5vNAzEFK+4p4t8= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826074207-144e7f85062d/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826082633-7c44365f527c h1:qo27sWEWWPeVyeShE+fUkAL6Ia0ToYj2aUbrP8MHhWo= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826082633-7c44365f527c/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826085916-d0e1474f8f34 h1:40XQgwR9HxXSnouY+ZqE/xYCM4qa+U+RLA5GA5JSNyQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240826085916-d0e1474f8f34/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= 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= @@ -643,6 +703,8 @@ golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/main.go b/main.go index d282132..e79f2f3 100644 --- a/main.go +++ b/main.go @@ -1,15 +1,19 @@ package main import ( + "fmt" _ "oc-workflow/routers" + "os" oclib "cloud.o-forge.io/core/oc-lib" "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" "github.com/goraz/onion" + "golang.org/x/mod/modfile" ) -const defaultConfigFile = "/etc/oc/workflow.json" +const hostname = "oc-workflow" +const defaultConfigFile = "/etc/oc/conf.json" func main() { configFile := "" @@ -29,8 +33,10 @@ func main() { o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), o.GetStringDefault("NATS_URL", "nats://localhost:4222"), ) - oclib.Init("oc-workflow") + fmt.Println("Config file:", o.GetStringDefault("HOSTNAME", "localhost")) + oclib.Init(hostname, o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8088")) oclib.AddPath(oclib.LibDataEnum(oclib.BOOKING), o.GetStringDefault("BOOKING_URL", ":8092")) + oclib.AddPath(oclib.LibDataEnum(oclib.PEER), o.GetStringDefault("PEER_URL", ":8093")) // Normal beego init //if beego.BConfig.RunMode == "dev" { beego.BConfig.WebConfig.DirectoryIndex = true @@ -38,3 +44,15 @@ func main() { //} beego.Run() } + +func GetModuleName() string { + goModBytes, err := os.ReadFile("go.mod") + if err != nil { + return "prrr" + } + + modName := modfile.ModulePath(goModBytes) + fmt.Fprintf(os.Stdout, "modName=%+v\n", modName) + + return modName +} diff --git a/oc-workflow b/oc-workflow index 5e4f646..ff582dd 100755 Binary files a/oc-workflow and b/oc-workflow differ diff --git a/routers/commentsRouter.go b/routers/commentsRouter.go index 919ef32..a17f19d 100644 --- a/routers/commentsRouter.go +++ b/routers/commentsRouter.go @@ -73,7 +73,7 @@ func init() { beego.GlobalControllerRouter["oc-workflow/controllers:WorkflowController"] = append(beego.GlobalControllerRouter["oc-workflow/controllers:WorkflowController"], beego.ControllerComments{ Method: "Check", - Router: `/check/:start_date/:end_date`, + Router: `/check/:id/:start_date/:end_date`, AllowHTTPMethods: []string{"get"}, MethodParams: param.Make(), Filters: nil, diff --git a/swagger/swagger.json b/swagger/swagger.json index 36a628f..21566be 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -83,7 +83,7 @@ } } }, - "/workflow/check/{start_date}/{end_date}": { + "/workflow/check/{id}/{start_date}/{end_date}": { "get": { "tags": [ "workflow" @@ -91,12 +91,17 @@ "description": "check booking\n\u003cbr\u003e", "operationId": "WorkflowController.Check", "parameters": [ + { + "in": "path", + "name": "id", + "description": "the booking workflow id", + "type": "string" + }, { "in": "path", "name": "start_date", - "description": "2006-01-02T15:04:05", - "type": "string", - "default": "the booking start date" + "description": "the booking start date format 2006-01-02T15:04:05", + "type": "string" }, { "in": "path", diff --git a/swagger/swagger.yml b/swagger/swagger.yml index 8638f20..9d8f2a8 100644 --- a/swagger/swagger.yml +++ b/swagger/swagger.yml @@ -121,7 +121,7 @@ paths: responses: "200": description: '{string} delete success!' - /workflow/check/{start_date}/{end_date}: + /workflow/check/{id}/{start_date}/{end_date}: get: tags: - workflow @@ -131,10 +131,13 @@ paths: operationId: WorkflowController.Check parameters: - in: path - name: start_date - description: 2006-01-02T15:04:05 + name: id + description: the booking workflow id + type: string + - in: path + name: start_date + description: the booking start date format 2006-01-02T15:04:05 type: string - default: the booking start date - in: path name: end_date description: 2006-01-02T15:04:05