first time go in to cloud repo
This commit is contained in:
commit
594788380c
15 files changed
+1133
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"linhdevtran99/rest-api/models"
|
||||
)
|
||||
|
||||
func BuildEmail() string {
|
||||
|
||||
data := models.EmailTemplate{
|
||||
Otp: "11017",
|
||||
AlternativeLink: "https://www.google.com.vn",
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles("./Template/email.html")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Cant achieve file")
|
||||
}
|
||||
|
||||
var result bytes.Buffer
|
||||
_ = tmpl.Execute(&result, data)
|
||||
|
||||
fmt.Println(result.String())
|
||||
return result.String()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
)
|
||||
|
||||
var MongoDB *mongo.Client
|
||||
|
||||
func InitMongoDriver(mongoUri string) *mongo.Client {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoUri))
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = client.Ping(ctx, readpref.Primary())
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
fmt.Println("MongoDB is ready")
|
||||
}
|
||||
|
||||
MongoDB = client
|
||||
|
||||
return client
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
var Redis *redis.Client
|
||||
|
||||
func RedisClientDriver(redisUri string) *redis.Client {
|
||||
ctx := context.Background()
|
||||
opt, err := redis.ParseURL(redisUri)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
redisClient := redis.NewClient(opt)
|
||||
res, err := redisClient.Ping(ctx).Result()
|
||||
|
||||
if err != nil {
|
||||
ctx.Done()
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if res == "PONG" {
|
||||
fmt.Println("Redis is ready")
|
||||
}
|
||||
|
||||
Redis = redisClient
|
||||
return redisClient
|
||||
}
|
||||
Reference in new issue
Block a user