-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update posting.go description to reflect changes, add version.go
The GochanVersion struct will be used to compare versions, especially for updating
- Loading branch information
user.email
committed
Nov 22, 2018
1 parent
a865840
commit 6ecfc8e
Showing
3 changed files
with
66 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// functions for post, thread, board, and page building | ||
|
||
package main | ||
|
||
import ( | ||
|
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,55 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type GochanVersion struct { | ||
Major uint | ||
Minor uint | ||
Revision uint | ||
Extra string | ||
} | ||
|
||
func ParseVersion(vStr string) GochanVersion { | ||
var v GochanVersion | ||
fmt.Sscanf(vStr, "%d.%d.%d-%s", &v.Major, &v.Minor, &v.Revision, &v.Extra) | ||
return v | ||
} | ||
|
||
func (v *GochanVersion) Compare(v2 GochanVersion) int { | ||
if v.Major > v2.Major { | ||
return 1 | ||
} | ||
if v.Major < v2.Major { | ||
return -1 | ||
} | ||
if v.Minor > v2.Minor { | ||
return 1 | ||
} | ||
if v.Minor < v2.Minor { | ||
return -1 | ||
} | ||
if v.Revision > v2.Revision { | ||
return 1 | ||
} | ||
if v.Revision < v2.Revision { | ||
return -1 | ||
} | ||
return 0 | ||
} | ||
|
||
func (v *GochanVersion) CompareString(v2 string) int { | ||
return v.Compare(ParseVersion(v2)) | ||
} | ||
|
||
func (v *GochanVersion) String() string { | ||
str := fmt.Sprintf("%d.%d", v.Major, v.Minor) | ||
if v.Revision > 0 { | ||
str += fmt.Sprintf(".%d", v.Revision) | ||
} | ||
if v.Extra != "" { | ||
str += "-" + v.Extra | ||
} | ||
return str | ||
} |