diff --git a/src/gochan.go b/src/gochan.go
index 10c1e60b..56860b28 100755
--- a/src/gochan.go
+++ b/src/gochan.go
@@ -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))
diff --git a/src/template.go b/src/template.go
index 1153d49b..e470297b 100755
--- a/src/template.go
+++ b/src/template.go
@@ -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 (
diff --git a/src/types.go b/src/types.go
index 62766d20..6d78a191 100644
--- a/src/types.go
+++ b/src/types.go
@@ -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.
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.
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)
}
diff --git a/src/version.go b/src/version.go
index d8ac1802..f9ab4cc3 100644
--- a/src/version.go
+++ b/src/version.go
@@ -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)
diff --git a/templates/global_footer.html b/templates/global_footer.html
index ecaa315c..b30d4b98 100644
--- a/templates/global_footer.html
+++ b/templates/global_footer.html
@@ -1,6 +1,6 @@