Skip to content

Commit

Permalink
New methods to get just UA string
Browse files Browse the repository at this point in the history
  • Loading branch information
baditaflorin committed May 7, 2024
1 parent 6cd6e26 commit 9008b89
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ randomUserAgent := commonuseragent.GetRandomUserAgent()

Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub at [https://github.com/baditaflorin/commonuseragent](https://github.com/baditaflorin/commonuseragent).

```bash
git status
# Check the status to see if there are uncommitted changes
git add .
# Add all changes to the staging area
git commit -m "Add changes before tagging"
# Commit your changes with a message
git tag -a v0.1.1 -m "Release v0.1.1 with new features and bug fixes"
# -a specifies an annotated tag
# -m specifies a message for the tag
git push origin v0.1.1
# Pushes the tag 0.1.1 to the remote named 'origin'
git push origin main --tags

If you want to check all the branches and tags that are pushed to remote:

```bash
git branch -r
git ls-remote --tags origin
```

## License

This project is licensed under the MIT License - see the LICENSE file for details.
22 changes: 20 additions & 2 deletions useragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

// Go directive to embed the files in the binary.
//
//go:embed desktop_useragents.json
//go:embed mobile_useragents.json
var content embed.FS
Expand Down Expand Up @@ -45,15 +46,32 @@ func GetAllMobile() []UserAgent {
return mobileAgents
}

// GetRandomDesktop returns a random UserAgent struct from the desktopAgents slice
func GetRandomDesktop() UserAgent {
if len(desktopAgents) == 0 {
return UserAgent{}
}
return desktopAgents[rand.Intn(len(desktopAgents))]
}

// GetRandomMobile returns a random UserAgent struct from the mobileAgents slice
func GetRandomMobile() UserAgent {
if len(mobileAgents) == 0 {
return UserAgent{}
}
return mobileAgents[rand.Intn(len(mobileAgents))]
}

func GetRandomUserAgent() UserAgent {
// GetRandomDesktopUA returns just the UA string of a random desktop user agent
func GetRandomDesktopUA() string {
return GetRandomDesktop().UA
}

// GetRandomMobileUA returns just the UA string of a random mobile user agent
func GetRandomMobileUA() string {
return GetRandomMobile().UA
}
func GetRandomUA() string {
allAgents := append(desktopAgents, mobileAgents...)
return allAgents[rand.Intn(len(allAgents))]
return allAgents[rand.Intn(len(allAgents))].UA
}

0 comments on commit 9008b89

Please sign in to comment.