Skip to content

Commit

Permalink
Semantic versioning & maintain compatibility with Revel
Browse files Browse the repository at this point in the history
Implements basic semantic versioning (Major/Minor changes) along with support for v0.18.0.
  • Loading branch information
EightB1ts authored Dec 5, 2017
1 parent 45b1281 commit c94efc7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion revel/bugsnagrevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package bugsnagrevel
import (
"strings"
"sync"

"strconv"
"net/http"
"github.com/bugsnag/bugsnag-go"
"github.com/revel/revel"
)
Expand Down Expand Up @@ -37,6 +38,12 @@ func middleware(event *bugsnag.Event, config *bugsnag.Configuration) error {
for _, datum := range event.RawData {
if controller, ok := datum.(*revel.Controller); ok {
// make the request visible to the builtin HttpMiddleware
if version("0.18.0") {
event.RawData = append(event.RawData, controller.Request)
} else {
req := struct{*http.Request}{}
event.RawData = append(event.RawData, req.Request)
}
event.RawData = append(event.RawData, controller.Request)
event.Context = controller.Action
event.MetaData.AddStruct("Session", controller.Session)
Expand Down Expand Up @@ -68,3 +75,18 @@ func init() {
})
})
}

// Very basic semantic versioning.
// Returns true if given version matches or is above revel.Version
func version(reqVersion string) bool{
req := strings.Split(reqVersion, ".")
cur := strings.Split(revel.Version, ".")
for i:=0;i<2;i++{
rV,_ := strconv.Atoi(req[i])
cV,_ := strconv.Atoi(cur[i])
if (rV<cV && i==0) || (rV<cV && i==1){
return true
}
}
return false
}

0 comments on commit c94efc7

Please sign in to comment.