Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaiers committed Aug 27, 2021
2 parents 078d556 + 4e4a61f commit 32efcd0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
redis
datetime
requests
python-dotenv
25 changes: 15 additions & 10 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@ import (
"github.com/joho/godotenv"
)

func init() {
err := godotenv.Load()

if err != nil {
log.Fatal("Error loading .env file")
}
}
var _ = godotenv.Load()

var ctx = context.Background()

var rdb = redis.NewClient(&redis.Options{
var client = redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: os.Getenv("REDIS_PASSWORD"),
DB: 0,
Expand Down Expand Up @@ -51,7 +44,11 @@ func Analyzer(w http.ResponseWriter, r *http.Request) {
return
}

ResponseWriter(w, false, "OK")
key := data.Date
value, _ := json.Marshal(data)
DataWriter(key, string(value))

ResponseWriter(w, false, "ok")
}

func main() {
Expand All @@ -60,3 +57,11 @@ func main() {

log.Fatal(http.ListenAndServe("0.0.0.0:8080", router))
}

func DataWriter(key string, value string) {
err := client.Set(key, value, 0).Err()

if err != nil {
log.Print(err)
}
}
16 changes: 10 additions & 6 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dotenv import load_dotenv
from datetime import datetime

import requests
import redis
Expand All @@ -8,17 +9,20 @@
load_dotenv()

data = {
'date': str(datetime.now()), # 2021-08-28 00:50:11.331569
'url': 'https://google.com/',
'method': 'GET',
'status': 200,
'user': '[email protected]'
'user': '[email protected]',
'headers': '',
'body': '',
'comment': '',
}

request = requests.post('https://analytics.fla.codes/', json=data)
json = request.json()
print(json) # {'error': False, 'data': 'OK'}
print(json) # {'error': False, 'data': 'ok'}

client = redis.Redis(host='localhost', port=6379, password=os.environ.get('REDIS_PASSWORD'))
client.set('data', json.get('data'))
value = client.get('data')
print(value.decode()) # OK
client = redis.Redis(host='localhost', port=6379, db=0, password=os.environ.get('REDIS_PASSWORD'))
value = client.get(data.get('date',))
print(value.decode()) # "date":"2021-08-28 00:50:11.331569","url":"https://google.com/","method":"GET","status":200,"user":"[email protected]","headers":"","body":"","comment":""}

0 comments on commit 32efcd0

Please sign in to comment.