diff --git a/controllers/version.go b/controllers/version.go index 6fa3e9c..2bf7bc7 100644 --- a/controllers/version.go +++ b/controllers/version.go @@ -1,6 +1,7 @@ package controllers import ( + "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" ) @@ -17,3 +18,29 @@ func (c *VersionController) GetAll() { c.Data["json"] = map[string]string{"version": "1"} c.ServeJSON() } + +// @Title Status +// @Description get status +// @Success 200 +// @router /status [get] +func (c *VersionController) Status() { + errStr := "" + api := tools.API{} + state, code, err := api.GetState() + + if state == tools.ALIVE { + state, _, err = api.CheckRemoteAPIs([]string{}) + } + if err != nil { + errStr = err.Error() + } + c.Data["json"] = map[string]interface{}{ + "data": map[string]interface{}{ + "state": state.String(), + "code": state, + }, + "error": errStr, + "code": code, + } + c.ServeJSON() +} diff --git a/go.mod b/go.mod index a4117d3..ab90244 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( ) require ( - cloud.o-forge.io/core/oc-lib v0.0.0-20240813123326-2d9b4587ac95 // indirect + cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/beego/bee/v2 v2.1.0 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -50,6 +50,9 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/nats-io/nats.go v1.37.0 // indirect + github.com/nats-io/nkeys v0.4.7 // indirect + github.com/nats-io/nuid v1.0.1 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/prometheus/client_golang v1.19.1 // indirect diff --git a/go.sum b/go.sum index fce7fd1..b0f3136 100644 --- a/go.sum +++ b/go.sum @@ -118,6 +118,8 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240813084212-4911e32ec215 h1:Ra1RbFC41IFxJ 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-20240821093044-f64563c9ff06 h1:sYveE1C/0mpSr+ZmOYxuZ3fTWID7mr5hPiq0jQenv3Q= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06/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= @@ -378,6 +380,12 @@ github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +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= +github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/ogier/pflag v0.0.1/go.mod h1:zkFki7tvTa0tafRvTBIZTvzYyAu6kQhPZFnshFFPE+g= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= diff --git a/main.go b/main.go index 45b66fc..95ddde3 100644 --- a/main.go +++ b/main.go @@ -5,39 +5,32 @@ import ( _ "oc-datacenter/routers" 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" ) const defaultConfigFile = "/etc/oc/datacenter.json" -const localConfigFile = "./docker_datacenter.json" func main() { configFile := "" var o *onion.Onion l3 := onion.NewEnvLayerPrefix("_", "OCDATACENTER_") - 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) } fmt.Println("BSLDMqlkd", o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC")) - oclib.SetConfig( + tools.SetConfig( o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), + "", ) oclib.Init("oc-datacenter") // Normal beego init diff --git a/oc-shared b/oc-datacenter similarity index 72% rename from oc-shared rename to oc-datacenter index c89731d..188509b 100755 Binary files a/oc-shared and b/oc-datacenter differ diff --git a/routers/commentsRouter.go b/routers/commentsRouter.go index 237e1e5..f7c198c 100644 --- a/routers/commentsRouter.go +++ b/routers/commentsRouter.go @@ -16,6 +16,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"] = append(beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"], + beego.ControllerComments{ + Method: "Post", + Router: `/`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"] = append(beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"], beego.ControllerComments{ Method: "Get", @@ -52,4 +61,13 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["oc-datacenter/controllers:VersionController"] = append(beego.GlobalControllerRouter["oc-datacenter/controllers:VersionController"], + beego.ControllerComments{ + Method: "Status", + Router: `/status`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + } diff --git a/swagger/swagger.json b/swagger/swagger.json index cb3b3dc..bcae095 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -27,6 +27,33 @@ "description": "{booking} models.booking" } } + }, + "post": { + "tags": [ + "booking" + ], + "description": "create booking\n\u003cbr\u003e", + "operationId": "BookingController.Post", + "parameters": [ + { + "in": "body", + "name": "booking", + "description": "the booking you want to post", + "required": true, + "schema": { + "type": "string" + }, + "type": "string" + } + ], + "responses": { + "200": { + "description": "", + "schema": { + "$ref": "#/definitions/models.object" + } + } + } } }, "/booking/check/{start_date}/{end_date}": { @@ -121,6 +148,20 @@ } } } + }, + "/version/status": { + "get": { + "tags": [ + "version" + ], + "description": "get status\n\u003cbr\u003e", + "operationId": "VersionController.Status", + "responses": { + "200": { + "description": "" + } + } + } } }, "definitions": { diff --git a/swagger/swagger.yml b/swagger/swagger.yml index 1e7f9c6..22fbb75 100644 --- a/swagger/swagger.yml +++ b/swagger/swagger.yml @@ -23,6 +23,26 @@ paths: responses: "200": description: '{booking} models.booking' + post: + tags: + - booking + description: |- + create booking +
+ operationId: BookingController.Post + parameters: + - in: body + name: booking + description: the booking you want to post + required: true + schema: + type: string + type: string + responses: + "200": + description: "" + schema: + $ref: '#/definitions/models.object' /booking/{id}: get: tags: @@ -92,6 +112,17 @@ paths: responses: "200": description: "" + /version/status: + get: + tags: + - version + description: |- + get status +
+ operationId: VersionController.Status + responses: + "200": + description: "" definitions: models.object: title: object