Compare commits

..

No commits in common. "d25c3eed543ba68edf87f586b4d1ac3e1179d25e" and "0fef07cfaea8f964b9a24fba210576e24772eef7" have entirely different histories.

9 changed files with 9 additions and 141 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
# IDE Configuration Files
.idea/
.idea

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -1,37 +0,0 @@
package config
import (
"encoding/json"
"os"
)
type Config struct {
RedisURL string `json:"redisURL"`
MongoDBURL string `json:"mongoDBURL"`
ServiceAddress string `json:"serviceAddress"`
WebServerPort int `json:"webServerPort"`
}
func LoadConfig(file string) (*Config, error) {
// Open the config file
configFile, err := os.Open(file)
if err != nil {
return nil, err
}
defer func(configFile *os.File) {
err := configFile.Close()
if err != nil {
return
}
}(configFile)
// Parse the JSON file into a Config struct
var config Config
decoder := json.NewDecoder(configFile)
err = decoder.Decode(&config)
if err != nil {
return nil, err
}
return &config, nil
}

11
go.mod
View File

@ -7,15 +7,4 @@ require github.com/redis/go-redis/v9 v9.6.1
require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.mongodb.org/mongo-driver v1.17.1 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.17.0 // indirect
)

42
internal/cache/gob.go vendored
View File

@ -1,42 +0,0 @@
package cache
import (
"bytes"
"context"
"encoding/gob"
"github.com/redis/go-redis/v9"
)
func StoreCacheGob[Data any](ctx context.Context, rdb *redis.Client, key string, data Data) error {
var buffer bytes.Buffer
encoder := gob.NewEncoder(&buffer)
// Serialize struct to Gob
err := encoder.Encode(data)
if err != nil {
return err
}
// Store data in Redis
return rdb.Set(ctx, key, buffer.Bytes(), 0).Err()
}
func GetCacheGob[Data any](ctx context.Context, rdb *redis.Client, key string) (Data, error) {
var data Data
binData, err := rdb.Get(ctx, key).Bytes()
if err != nil {
return data, err
}
buffer := bytes.NewBuffer(binData)
decoder := gob.NewDecoder(buffer)
// Deserialize Gob binary back to struct
err = decoder.Decode(&data)
if err != nil {
return data, err
}
return data, nil
}

View File

@ -1,26 +0,0 @@
package cache
import (
"context"
"git.libraryofcode.org/engineering/bces/config"
"github.com/redis/go-redis/v9"
"log"
)
// NewRedisConnection takes a Config parameter and connects to the RedisURL provided in the config. It returns an instance of Redis Client.
// This function will exit the program if it cannot parse the URL properly nor connect successfully, and therefore doesn't return an error.
func NewRedisConnection(config config.Config) *redis.Client {
redisConnectionOptions, err := redis.ParseURL(config.RedisURL)
if err != nil {
log.Fatalf("Redis Connection URL is not valid or cannot parse given Connection URL: %s.\n\n%s", config.RedisURL, err)
}
redisClient := redis.NewClient(redisConnectionOptions)
redisPingResponse, err := redisClient.Ping(context.Background()).Result()
if err != nil {
log.Fatalf("Could not ping Redis.\n\n%s", err)
}
log.Printf("Connected to Redis DB at <%s>: %s", config.RedisURL, redisPingResponse)
return redisClient
}

View File

@ -1,9 +0,0 @@
package cache
import "time"
type CachedReport struct {
ReportID string
UserID string
GeneratedAt time.Time
}

View File

@ -1,7 +0,0 @@
package db
type HardInquiryDB struct {
ID string
UserID string
VendorID string
}

View File

@ -1,8 +0,0 @@
package db
type Vendor struct {
ID string `bson:"vendorID"`
Name string `bson:"name"`
PermissionLevel int `bson:"permissionLevel"`
Key string `bson:"key"`
}