From b3e31734f59b7aba81297f13b95d5333c457c94d Mon Sep 17 00:00:00 2001 From: Howl Date: Fri, 17 Jun 2016 10:34:53 +0200 Subject: [PATCH] Release logging to sentry --- app/start.go | 1 + app/v1/meta.go | 2 +- common/conf.go | 4 ++++ main.go | 11 +++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/start.go b/app/start.go index 2ca8dc6..6ea1427 100644 --- a/app/start.go +++ b/app/start.go @@ -23,6 +23,7 @@ func Start(conf common.Conf, dbO *sql.DB) *gin.Engine { if conf.SentryDSN != "" { ravenClient, err := raven.New(conf.SentryDSN) + ravenClient.SetRelease(common.Version) if err != nil { fmt.Println(err) } else { diff --git a/app/v1/meta.go b/app/v1/meta.go index 8976d61..87f0166 100644 --- a/app/v1/meta.go +++ b/app/v1/meta.go @@ -78,7 +78,7 @@ func MetaUpdateGET(md common.MethodData) common.CodeMessager { if !execCommand("go", "get", "-v", "-u", "-d") { return } - if !execCommand("go", "build", "-v", "-o", "api") { + if !execCommand("bash", "-c", "go build -v -ldflags \"-X main.Version=`git rev-parse HEAD`\" -o api") { return } diff --git a/common/conf.go b/common/conf.go index 67d230a..3afbf5d 100644 --- a/common/conf.go +++ b/common/conf.go @@ -6,6 +6,10 @@ import ( "github.com/thehowl/conf" ) +// Version is the git hash of the application. Do not edit. This is +// automatically set using -ldflags during build time. +var Version string + // Conf is the configuration file data for the ripple API. // Conf uses https://github.com/thehowl/conf type Conf struct { diff --git a/main.go b/main.go index 1720cbb..5c92a10 100644 --- a/main.go +++ b/main.go @@ -17,12 +17,23 @@ import ( _ "github.com/go-sql-driver/mysql" ) +// Version is the git hash of the application. Do not edit. This is +// automatically set using -ldflags during build time. +var Version string + func init() { log.SetFlags(log.Ltime) log.SetPrefix(fmt.Sprintf("%d|", syscall.Getpid())) + common.Version = Version } func main() { + fmt.Print("Ripple API") + if Version != "" { + fmt.Print("; git commit hash: ", Version) + } + fmt.Println() + conf, halt := common.Load() if halt { return