This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add information on the model of mobile devices
- Loading branch information
1 parent
e13ed2b
commit 746647a
Showing
5 changed files
with
114 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package user_agent | ||
|
||
import ( | ||
"strings" | ||
) | ||
// detectModel some properties of the model from the given section. | ||
func (p *UserAgent) detectModel(s section) { | ||
if !p.mobile { | ||
return | ||
} | ||
if p.platform == "iPhone" || p.platform == "iPad" { | ||
p.model = p.platform | ||
return | ||
} | ||
// Android model | ||
if s.name == "Mozilla" && p.platform == "Linux" && len(s.comment) > 2 { | ||
mostAndroidModel := s.comment[2] | ||
if strings.Contains(mostAndroidModel, "Android") || strings.Contains(mostAndroidModel, "Linux") { | ||
mostAndroidModel = s.comment[len(s.comment) - 1] | ||
} | ||
tmp := strings.Split(mostAndroidModel, "Build") | ||
if len(tmp) > 0 { | ||
p.model = strings.Trim(tmp[0], " ") | ||
return | ||
} | ||
} | ||
// traverse all item | ||
for _, v := range s.comment { | ||
if strings.Contains(v, "Build") { | ||
tmp := strings.Split(v, "Build") | ||
p.model = strings.Trim(tmp[0], " ") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters