Skip to content

Commit

Permalink
Move Geolocation below
Browse files Browse the repository at this point in the history
The main type here should BrowserContextOptions.
  • Loading branch information
inancgumus committed Nov 7, 2024
1 parent 1255a92 commit 01dcb7f
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions common/browser_context_options.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
package common

import (
"fmt"
)

// Geolocation represents a geolocation.
type Geolocation struct {
Latitude float64 `js:"latitude"`
Longitude float64 `js:"longitude"`
Accuracy float64 `js:"accuracy"`
}

// Validate validates the [Geolocation].
func (g *Geolocation) Validate() error {
if g.Longitude < -180 || g.Longitude > 180 {
return fmt.Errorf(`invalid longitude "%.2f": precondition -180 <= LONGITUDE <= 180 failed`, g.Longitude)
}
if g.Latitude < -90 || g.Latitude > 90 {
return fmt.Errorf(`invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90 failed`, g.Latitude)
}
if g.Accuracy < 0 {
return fmt.Errorf(`invalid accuracy "%.2f": precondition 0 <= ACCURACY failed`, g.Accuracy)
}
return nil
}
import "fmt"

// BrowserContextOptions stores browser context options.
type BrowserContextOptions struct {
Expand Down Expand Up @@ -65,6 +42,27 @@ func DefaultBrowserContextOptions() *BrowserContextOptions {
}
}

// Geolocation represents a geolocation.
type Geolocation struct {
Latitude float64 `js:"latitude"`
Longitude float64 `js:"longitude"`
Accuracy float64 `js:"accuracy"`
}

// Validate validates the [Geolocation].
func (g *Geolocation) Validate() error {
if g.Longitude < -180 || g.Longitude > 180 {
return fmt.Errorf(`invalid longitude "%.2f": precondition -180 <= LONGITUDE <= 180 failed`, g.Longitude)
}
if g.Latitude < -90 || g.Latitude > 90 {
return fmt.Errorf(`invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90 failed`, g.Latitude)
}
if g.Accuracy < 0 {
return fmt.Errorf(`invalid accuracy "%.2f": precondition 0 <= ACCURACY failed`, g.Accuracy)
}
return nil
}

// GrantPermissionsOptions is used by BrowserContext.GrantPermissions.
type GrantPermissionsOptions struct {
Origin string
Expand Down

0 comments on commit 01dcb7f

Please sign in to comment.