Skip to content

Commit

Permalink
refactor: fixed logger panic err
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Dec 19, 2023
1 parent d9d8281 commit 2a7b51c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 32 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21.5
require (
github.com/gotd/td v0.91.0
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/redis/go-redis/v9 v9.3.1
gopkg.in/telebot.v3 v3.2.1
)
Expand Down
2 changes: 1 addition & 1 deletion kreacher/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kreacher
package main

import (
"log"
Expand Down
2 changes: 1 addition & 1 deletion kreacher/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kreacher
package main

import (
"fmt"
Expand Down
11 changes: 7 additions & 4 deletions kreacher/logger.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package kreacher
package main

import (
"io"
"log"
"os"
)

func NewLogger(name string, path string) (*log.Logger, error) {
var logger *log.Logger
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
return nil, err
}

defer file.Close()

logger.SetOutput(file)
logFile := io.MultiWriter(os.Stdout, file)

logger := log.New(logFile, name+" ", log.Ldate|log.Ltime|log.Lshortfile)
logger.SetOutput(logFile)
logger.SetFlags(0)

return logger, nil
Expand Down
12 changes: 11 additions & 1 deletion kreacher/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package kreacher
package main

import (
"database/sql"
"fmt"
"time"

td "github.com/gotd/td/telegram"
_ "github.com/lib/pq"
redis "github.com/redis/go-redis/v9"
tele "gopkg.in/telebot.v3"
)
Expand All @@ -16,6 +18,14 @@ func main() {
panic(err)
}

postgresDB, err := sql.Open("postgres", "user=username password=password dbname=database sslmode=disable")

if err != nil {
panic(err)
}

defer postgresDB.Close()

redisDB := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", NewConfig().RedisHost, NewConfig().RedisPort),
Password: NewConfig().RedisPassword,
Expand Down
4 changes: 0 additions & 4 deletions requirements-dev.txt

This file was deleted.

20 changes: 0 additions & 20 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.11.6
golang-1.21.5

0 comments on commit 2a7b51c

Please sign in to comment.