1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-20 09:26:23 -07:00

Start using GochanVersion struct

TODO: replace current db update check with config.Version.CompareString()
This commit is contained in:
user.email 2018-11-22 23:47:51 -08:00
parent 6ecfc8e1f1
commit 0d36172570
5 changed files with 47 additions and 15 deletions

View file

@ -20,7 +20,7 @@ func main() {
connectToSQLServer()
parseCommandLine()
printf(0, "Starting gochan v%s.%s, using verbosity level %d\n", config.Version, buildtimeString, config.Verbosity)
printf(0, "Starting gochan v%s.%s, using verbosity level %d\n", config.Version.String(), buildtimeString, config.Verbosity)
println(0, "Loading and parsing templates...")
if err := initTemplates(); err != nil {
handleError(0, customError(err))

View file

@ -127,8 +127,10 @@ var funcMap = template.FuncMap{
return getThumbnailPath("catalog", img)
},
"getThreadID": func(post_i interface{}) (thread int) {
post := post_i.(PostTable)
if post.ParentID == 0 {
post, ok := post_i.(PostTable)
if !ok {
thread = 0
} else if post.ParentID == 0 {
thread = post.ID
} else {
thread = post.ParentID
@ -235,6 +237,11 @@ var funcMap = template.FuncMap{
"isStyleDefault": func(style string) bool {
return style == config.DefaultStyle
},
// Version functions
"formatVersion": func(v GochanVersion) string {
return v.String()
},
}
var (

View file

@ -423,11 +423,11 @@ type GochanConfig struct {
// Verbosity = 0 for no debugging info. Critical errors and general output only
// Verbosity = 1 for non-critical warnings and important info
// Verbosity = 2 for all debugging/benchmarks/warnings
Verbosity int `description:"The level of verbosity to use in error/warning messages. 0 = critical errors/startup messages, 1 = warnings, 2 = benchmarks/notices." default:"0"`
EnableAppeals bool `description:"If checked, allow banned users to appeal their bans.<br />This will likely be removed (permanently allowing appeals) or made board-specific in the future." default:"checked"`
MaxLogDays int `description:"The maximum number of days to keep messages in the moderation/staff log file."`
RandomSeed string `critical:"true"`
Version string `critical:"true"`
Verbosity int `description:"The level of verbosity to use in error/warning messages. 0 = critical errors/startup messages, 1 = warnings, 2 = benchmarks/notices." default:"0"`
EnableAppeals bool `description:"If checked, allow banned users to appeal their bans.<br />This will likely be removed (permanently allowing appeals) or made board-specific in the future." default:"checked"`
MaxLogDays int `description:"The maximum number of days to keep messages in the moderation/staff log file."`
RandomSeed string `critical:"true"`
Version GochanVersion `critical:"true"`
}
func initConfig() {
@ -675,5 +675,5 @@ func initConfig() {
bbcompiler.SetTag("quote", nil)
bbcompiler.SetTag("size", nil)
config.Version = version
config.Version = ParseVersion(version)
}

View file

@ -1,3 +1,5 @@
// used for version parsing, printing, and comparison
package main
import (
@ -5,19 +7,38 @@ import (
)
type GochanVersion struct {
Major uint
Minor uint
Revision uint
Major int
Minor int
Revision int
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)
v.Normalize()
return v
}
func (v *GochanVersion) Normalize() bool {
valid := true
if v.Major < 0 {
v.Major = 0
valid = false
}
if v.Minor < 0 {
v.Minor = 0
valid = false
}
if v.Revision < 0 {
v.Revision = 0
}
return valid
}
func (v *GochanVersion) Compare(v2 GochanVersion) int {
v.Normalize()
v2.Normalize()
if v.Major > v2.Major {
return 1
}
@ -39,11 +60,15 @@ func (v *GochanVersion) Compare(v2 GochanVersion) int {
return 0
}
func (v *GochanVersion) CompareString(v2 string) int {
return v.Compare(ParseVersion(v2))
func (v *GochanVersion) CompareString(v2str string) int {
v.Normalize()
v2 := ParseVersion(v2str)
v2.Normalize()
return v.Compare(v2)
}
func (v *GochanVersion) String() string {
v.Normalize()
str := fmt.Sprintf("%d.%d", v.Major, v.Minor)
if v.Revision > 0 {
str += fmt.Sprintf(".%d", v.Revision)

View file

@ -1,6 +1,6 @@
<div id="footer">
<a href="{{$.config.SiteWebfolder}}">Home</a> | <a href="{{$.config.SiteWebfolder}}#boards">Boards</a> | <a href="{{$.config.SiteWebfolder}}#rules">Rules</a> | <a href="{{$.config.SiteWebfolder}}#faq">FAQ</a><br />
Powered by <a href="http://github.com/eggbertx/gochan/">Gochan {{.config.Version}}</a><br />
Powered by <a href="http://github.com/eggbertx/gochan/">Gochan {{formatVersion .config.Version}}</a><br />
</div>
</body>
</html>