// 2019 Rackspace, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. package tools import ( "os" "strings" "github.com/gin-gonic/gin" "github.rackspace.com/gorax/tools/lagger" "github.rackspace.com/gorax/tools/util" ) // MigrationDB is a constant to be used for calling the migration DB by name // in various packages. const MigrationDB = "migration" // Complete method will write the response data and return func Complete(c *gin.Context, resp interface{}, code int, err error) { logger := c.MustGet("lagger").(*lagger.NSILogger) if err != nil { logger.Error(logger.GinLog(c, err.Error())) c.AbortWithStatusJSON(code, gin.H{"data": resp, "message": err.Error()}) return } data := gin.H{} if resp != nil { data = gin.H{"data": resp, "message": nil} } c.JSON(code, data) } // URL function will return the base url in use by the application, based on the // selected environment func URL() string { if util.IsStaging(os.Getenv("ENVIRONMENT")) { return "https://migration-staging.nsi.rackspace.com" } return "https://migration.nsi.rackspace.com" } // Encode will format the string data so that Mongo can handle the values func Encode(key string) string { return strings.Replace(key, "U+00B7", ".", -1) } // Decode will format the string data so that Mongo can handle the values func Decode(key string) string { return strings.Replace(key, ".", "U+00B7", -1) }