-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
22 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,66 @@ | ||
package useragent | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type VersionNo struct { | ||
Major int | ||
Minor int | ||
Patch int | ||
} | ||
|
||
func parseVersion(ver string, verno *VersionNo) { | ||
var err error | ||
parts := strings.Split(ver, ".") | ||
if len(parts) > 0 { | ||
if verno.Major, err = strconv.Atoi(parts[0]); err != nil { | ||
return | ||
} | ||
} | ||
if len(parts) > 1 { | ||
if verno.Minor, err = strconv.Atoi(parts[1]); err != nil { | ||
return | ||
} | ||
if len(parts) > 2 { | ||
if verno.Patch, err = strconv.Atoi(parts[2]); err != nil { | ||
return | ||
} | ||
} | ||
} | ||
return | ||
} | ||
|
||
// VersionNoShort return version string in format <Major>.<Minor> | ||
func (ua UserAgent) VersionNoShort() string { | ||
if ua.VersionNo.Major == 0 && ua.VersionNo.Minor == 0 && ua.VersionNo.Patch == 0 { | ||
return "" | ||
} | ||
return fmt.Sprintf("%d.%d", ua.VersionNo.Major, ua.VersionNo.Minor) | ||
} | ||
|
||
// VersionNoFull returns version string in format <Major>.<Minor>.<Patch> | ||
func (ua UserAgent) VersionNoFull() string { | ||
if ua.VersionNo.Major == 0 && ua.VersionNo.Minor == 0 && ua.VersionNo.Patch == 0 { | ||
return "" | ||
} | ||
return fmt.Sprintf("%d.%d.%d", ua.VersionNo.Major, ua.VersionNo.Minor, ua.VersionNo.Patch) | ||
} | ||
|
||
// OSVersionNoShort returns OS version string in format <Major>.<Minor> | ||
func (ua UserAgent) OSVersionNoShort() string { | ||
if ua.OSVersionNo.Major == 0 && ua.OSVersionNo.Minor == 0 && ua.OSVersionNo.Patch == 0 { | ||
return "" | ||
} | ||
return fmt.Sprintf("%d.%d", ua.OSVersionNo.Major, ua.OSVersionNo.Minor) | ||
} | ||
|
||
// OSVersionNoFull returns OS version string in format <Major>.<Minor>.<Patch> | ||
func (ua UserAgent) OSVersionNoFull() string { | ||
if ua.OSVersionNo.Major == 0 && ua.OSVersionNo.Minor == 0 && ua.OSVersionNo.Patch == 0 { | ||
return "" | ||
} | ||
return fmt.Sprintf("%d.%d.%d", ua.OSVersionNo.Major, ua.OSVersionNo.Minor, ua.OSVersionNo.Patch) | ||
} |