From 35abc2db2029e57e6fbefa16364e57a745fc6b0c Mon Sep 17 00:00:00 2001 From: Pavel Zarubin Date: Mon, 3 Apr 2023 17:12:33 +0300 Subject: [PATCH] Refactoring --- cmd/cli.go | 9 ++++----- cmd/grpc.go | 8 ++++---- config/gpt.go | 8 ++++---- internal/CookieManager/manager.go | 2 +- internal/EdgeGPT/gpt.go | 12 ++++++------ internal/EdgeGPT/hub.go | 4 ++-- internal/EdgeGPT/storage.go | 2 +- internal/GRPC/server.go | 4 ++-- internal/{helpers => Helpers}/helper.go | 2 +- 9 files changed, 25 insertions(+), 26 deletions(-) rename internal/{helpers => Helpers}/helper.go (98%) diff --git a/cmd/cli.go b/cmd/cli.go index 44e12fe..cef36f8 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -1,9 +1,8 @@ package main import ( - "EdgeGPT-Go/config" - "EdgeGPT-Go/internal/EdgeGPT" - "log" + "github.com/pavel-one/EdgeGPT-Go/config" + "github.com/pavel-one/EdgeGPT-Go/internal/EdgeGPT" "time" ) @@ -26,7 +25,7 @@ func main() { go mw.Worker() for _ = range mw.Chan { - log.Println(mw.Answer.GetAnswer()) + log.Infoln(mw.Answer.GetAnswer()) } as, err := gpt.AskSync("Покажи пример сокетов на golang gorilla") @@ -34,7 +33,7 @@ func main() { log.Fatalln(err) } - log.Println(as.Answer.GetAnswer()) + log.Infoln(as.Answer.GetAnswer()) time.Sleep(time.Minute * 5) } diff --git a/cmd/grpc.go b/cmd/grpc.go index eef0773..b2fbe7d 100644 --- a/cmd/grpc.go +++ b/cmd/grpc.go @@ -1,10 +1,10 @@ package main import ( - "EdgeGPT-Go/internal/EdgeGPT" - "EdgeGPT-Go/internal/GRPC" - "EdgeGPT-Go/internal/Logger" - pb "EdgeGPT-Go/pkg/GRPC/GPT" + "github.com/pavel-one/EdgeGPT-Go/internal/EdgeGPT" + "github.com/pavel-one/EdgeGPT-Go/internal/GRPC" + "github.com/pavel-one/EdgeGPT-Go/internal/Logger" + pb "github.com/pavel-one/EdgeGPT-Go/pkg/GRPC/GPT" "google.golang.org/grpc" "google.golang.org/grpc/peer" "net" diff --git a/config/gpt.go b/config/gpt.go index 63f5911..ab40b02 100644 --- a/config/gpt.go +++ b/config/gpt.go @@ -1,9 +1,9 @@ package config import ( - "EdgeGPT-Go/internal/helpers" "fmt" "github.com/google/uuid" + "github.com/pavel-one/EdgeGPT-Go/internal/Helpers" "net/url" "time" ) @@ -33,9 +33,9 @@ func NewGpt() (*GPT, error) { forwared := fmt.Sprintf( "13.%d.%d.%d", - helpers.RandInt(104, 107), - helpers.RandInt(0, 255), - helpers.RandInt(0, 255)) + Helpers.RandInt(104, 107), + Helpers.RandInt(0, 255), + Helpers.RandInt(0, 255)) return &GPT{ ConversationUrl: cu, diff --git a/internal/CookieManager/manager.go b/internal/CookieManager/manager.go index 52b483f..6bfe1b9 100644 --- a/internal/CookieManager/manager.go +++ b/internal/CookieManager/manager.go @@ -1,9 +1,9 @@ package CookieManager import ( - "EdgeGPT-Go/internal/Logger" "encoding/json" "github.com/gabriel-vasile/mimetype" + "github.com/pavel-one/EdgeGPT-Go/internal/Logger" "io" "os" ) diff --git a/internal/EdgeGPT/gpt.go b/internal/EdgeGPT/gpt.go index 7b748e5..9915a1f 100644 --- a/internal/EdgeGPT/gpt.go +++ b/internal/EdgeGPT/gpt.go @@ -1,14 +1,14 @@ package EdgeGPT import ( - "EdgeGPT-Go/config" - "EdgeGPT-Go/internal/CookieManager" - "EdgeGPT-Go/internal/Logger" - "EdgeGPT-Go/internal/helpers" "encoding/json" "errors" "fmt" "github.com/gorilla/websocket" + "github.com/pavel-one/EdgeGPT-Go/config" + "github.com/pavel-one/EdgeGPT-Go/internal/CookieManager" + "github.com/pavel-one/EdgeGPT-Go/internal/Helpers" + "github.com/pavel-one/EdgeGPT-Go/internal/Logger" "io" "net/http" "time" @@ -42,7 +42,7 @@ func NewGPT(conf *config.GPT) (*GPT, error) { gpt := &GPT{ Config: conf, - cookies: helpers.MapToCookies(manager.GetBestCookie()), + cookies: Helpers.MapToCookies(manager.GetBestCookie()), ExpiredAt: time.Now().Add(time.Minute * 120), client: &http.Client{ Timeout: conf.TimeoutRequest, @@ -169,7 +169,7 @@ func (g *GPT) createHub() (*Hub, error) { return nil, errors.New("not set conversation") } - conn, _, err := websocket.DefaultDialer.Dial(g.Config.WssUrl.String(), helpers.GetHeaders(g.Config.Headers)) + conn, _, err := websocket.DefaultDialer.Dial(g.Config.WssUrl.String(), Helpers.GetHeaders(g.Config.Headers)) if err != nil { return nil, err } diff --git a/internal/EdgeGPT/hub.go b/internal/EdgeGPT/hub.go index 65a136f..be4c659 100644 --- a/internal/EdgeGPT/hub.go +++ b/internal/EdgeGPT/hub.go @@ -1,9 +1,9 @@ package EdgeGPT import ( - "EdgeGPT-Go/internal/helpers" "encoding/json" "github.com/gorilla/websocket" + "github.com/pavel-one/EdgeGPT-Go/internal/Helpers" "sync" ) @@ -81,7 +81,7 @@ func (c *Hub) getRequest(message string) map[string]any { "225cricinfo", "224locals0", }, - "traceId": helpers.RandomHex(32), + "traceId": Helpers.RandomHex(32), "isStartOfSession": c.InvocationId == 0, "message": map[string]any{ "author": "user", diff --git a/internal/EdgeGPT/storage.go b/internal/EdgeGPT/storage.go index e864f66..b3e58c3 100644 --- a/internal/EdgeGPT/storage.go +++ b/internal/EdgeGPT/storage.go @@ -1,9 +1,9 @@ package EdgeGPT import ( - "EdgeGPT-Go/config" "errors" "fmt" + "github.com/pavel-one/EdgeGPT-Go/config" "time" ) diff --git a/internal/GRPC/server.go b/internal/GRPC/server.go index 6fa5b73..f8329fe 100644 --- a/internal/GRPC/server.go +++ b/internal/GRPC/server.go @@ -1,8 +1,8 @@ package GRPC import ( - "EdgeGPT-Go/internal/EdgeGPT" - pb "EdgeGPT-Go/pkg/GRPC/GPT" + "github.com/pavel-one/EdgeGPT-Go/internal/EdgeGPT" + pb "github.com/pavel-one/EdgeGPT-Go/pkg/GRPC/GPT" "google.golang.org/grpc/peer" "log" "time" diff --git a/internal/helpers/helper.go b/internal/Helpers/helper.go similarity index 98% rename from internal/helpers/helper.go rename to internal/Helpers/helper.go index cba7734..9e9d43b 100644 --- a/internal/helpers/helper.go +++ b/internal/Helpers/helper.go @@ -1,4 +1,4 @@ -package helpers +package Helpers import ( "crypto/rand"