Skip to content

Commit

Permalink
🎨 refactor: update .gitignore and remove redundant closed fields (main)
Browse files Browse the repository at this point in the history
- Added `.vscode/` to .gitignore to ignore Visual Studio Code settings.
- Removed redundant `closed` fields and associated checks in HTTPFetcher and JinaFetcher.
- Updated `BrowserControlUrl` in Config struct to use `envDefault` for default value.
  • Loading branch information
vaayne committed Dec 2, 2024
1 parent ba6659e commit 04072d1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ _testmain.go
# This file includes artifacts of Go build that should not be checked in.
# For files created by specific development environment (e.g. editor),
# use alternative ways to exclude files from git.
# For example, set up .git/info/exclude or use a global .gitignore.
# For example, set up .git/info/exclude or use a global .gitignore.
.vscode/
8 changes: 4 additions & 4 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ type Config struct {
OAuths struct {
Github OAuthConfig `envPrefix:"GITHUB_"`
} `envPrefix:"OAUTH_"`
OpenAI OpenAIConfig `envPrefix:"OPENAI_"`
GoogleSearch GoogleSearchConfig `envPrefix:"GOOGLE_SEARCH_"`
S3 S3Config `envPrefix:"S3_"`
BrowserlessControlUrl string `env:"BROWSERLESS_CONTROL_URL"`
OpenAI OpenAIConfig `envPrefix:"OPENAI_"`
GoogleSearch GoogleSearchConfig `envPrefix:"GOOGLE_SEARCH_"`
S3 S3Config `envPrefix:"S3_"`
BrowserControlUrl string `env:"BROWSER_CONTROL_URL" envDefault:"http://localhost:9222"`
}

func init() {
Expand Down
7 changes: 2 additions & 5 deletions internal/pkg/webreader/fetcher/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import (
"net/http"
"strings"
"time"
"vibrain/internal/pkg/config"
"vibrain/internal/pkg/webreader"

"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/proto"
)

const (
defaultControlURL = "http://localhost:9222"
)

// BrowserConfig extends the base Config with browser-specific options
type BrowserConfig struct {
Timeout int `json:"timeout"` // Timeout in seconds
Expand All @@ -35,7 +32,7 @@ type BrowserFetcher struct {
func NewDefaultBrowserConfig() BrowserConfig {
return BrowserConfig{
Timeout: 30,
ControlURL: defaultControlURL,
ControlURL: config.Settings.BrowserControlUrl,
ScrollToBottom: true,
}
}
Expand Down
10 changes: 0 additions & 10 deletions internal/pkg/webreader/fetcher/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type HTTPOption func(*HTTPConfig)
type HTTPFetcher struct {
client *http.Client
config HTTPConfig
closed bool
}

func DefaultHTTPConfig() HTTPConfig {
Expand Down Expand Up @@ -76,10 +75,6 @@ func NewHTTPFetcher(opts ...HTTPOption) (*HTTPFetcher, error) {

// Fetch implements the Fetcher interface
func (f *HTTPFetcher) Fetch(ctx context.Context, url string) (*webreader.Content, error) {
if f.closed {
return nil, fmt.Errorf("fetcher is closed")
}

var lastErr error
retries := f.config.RetryCount + 1

Expand Down Expand Up @@ -136,11 +131,6 @@ func (f *HTTPFetcher) doFetch(ctx context.Context, url string) (*webreader.Conte

// Close implements the Fetcher interface
func (f *HTTPFetcher) Close() error {
if f.closed {
return nil
}
f.closed = true
f.client.CloseIdleConnections()
return nil
}

Expand Down
10 changes: 0 additions & 10 deletions internal/pkg/webreader/fetcher/jina.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type jinaResponse struct {
type JinaFetcher struct {
client *http.Client
config JinaConfig
closed bool
}

func DefaultJinaConfig() JinaConfig {
Expand Down Expand Up @@ -78,10 +77,6 @@ func NewJinaFetcher(opts ...JinaOption) (*JinaFetcher, error) {

// Fetch implements the Fetcher interface
func (f *JinaFetcher) Fetch(ctx context.Context, url string) (*webreader.Content, error) {
if f.closed {
return nil, fmt.Errorf("fetcher is closed")
}

// Prepare the Jina API URL
jinaURL := fmt.Sprintf("%s/%s", jinaHost, url)

Expand Down Expand Up @@ -129,10 +124,5 @@ func (f *JinaFetcher) Fetch(ctx context.Context, url string) (*webreader.Content

// Close implements the Fetcher interface
func (f *JinaFetcher) Close() error {
if f.closed {
return nil
}
f.closed = true
f.client.CloseIdleConnections()
return nil
}

0 comments on commit 04072d1

Please sign in to comment.