diff --git a/src/db/db.go b/src/db/db.go index c4d52a7..c72243f 100644 --- a/src/db/db.go +++ b/src/db/db.go @@ -13,17 +13,29 @@ import ( "go.mongodb.org/mongo-driver/v2/mongo/options" "hms_patient_mgmt_svc/models" + "hms_patient_mgmt_svc/utils" ) // Get mongo collection for 1 minute connection pool func get_db_collection() (*mongo.Collection, *mongo.Client) { _, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() - client, err := mongo.Connect(options.Client().ApplyURI(os.Getenv("APP_DB_URI"))) + var base64_encoded_data = map[string]string{ + "APP_DB_URI": os.Getenv("APP_DB_URI"), + "APP_DB_NAME": os.Getenv("APP_DB_NAME"), + "COLLECTION_NAME": os.Getenv("COLLECTION_NAME"), + } + + base64_decoded_data, base64_err := utils.DecodeBase64(base64_encoded_data) + if base64_err != nil { + // fmt.Println("base64 decode error", base64_err.Error()) + } + + client, err := mongo.Connect(options.Client().ApplyURI(base64_decoded_data["APP_DB_URI"])) if err != nil { panic(err) } - collection := client.Database(os.Getenv("APP_DB_NAME")).Collection(os.Getenv("COLLECTION_NAME")) + collection := client.Database(base64_decoded_data["APP_DB_NAME"]).Collection(base64_decoded_data["COLLECTION_NAME"]) return collection, client } diff --git a/src/main.go b/src/main.go index 435f1f9..4b35eda 100644 --- a/src/main.go +++ b/src/main.go @@ -2,14 +2,13 @@ package main import ( "hms_patient_mgmt_svc/api" - - "github.com/joho/godotenv" + // "github.com/joho/godotenv" ) func main() { - err := godotenv.Load() - if err != nil { - panic(err) - } + // err := godotenv.Load() + // if err != nil { + // panic(err) + // } api.Api() } diff --git a/src/utils/helper.go b/src/utils/helper.go new file mode 100644 index 0000000..112963b --- /dev/null +++ b/src/utils/helper.go @@ -0,0 +1,18 @@ +package utils + +import ( + "encoding/base64" +) + +func DecodeBase64(base64_encode_data map[string]string) (map[string]string, error) { + var decoded_map map[string]string = make(map[string]string) + + for k, v := range base64_encode_data { + data, err := base64.StdEncoding.DecodeString(v) + if err != nil { + return nil, err + } + decoded_map[k] = string(data) + } + return decoded_map, nil +}