build git commit hash into project
This commit is contained in:
parent
28b9e32f43
commit
5ef2803075
4 changed files with 35 additions and 6 deletions
9
Makefile
Normal file
9
Makefile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
GIT_COMMIT = $(shell git rev-list -1 HEAD)
|
||||||
|
SOURCES = $(shell find . -type f -and -name "*.go" -or -name "*.html")
|
||||||
|
|
||||||
|
all: subscribe-bot
|
||||||
|
|
||||||
|
subscribe-bot: $(SOURCES)
|
||||||
|
go build -o $@ -ldflags "-X main.GitCommit=$(GIT_COMMIT)"
|
||||||
|
|
||||||
|
.PHONY: all
|
4
main.go
4
main.go
|
@ -17,6 +17,8 @@ import (
|
||||||
|
|
||||||
var exit_chan = make(chan int)
|
var exit_chan = make(chan int)
|
||||||
|
|
||||||
|
var GitCommit string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configPath := flag.String("config", "config.toml", "Path to the config file (defaults to config.toml)")
|
configPath := flag.String("config", "config.toml", "Path to the config file (defaults to config.toml)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -40,7 +42,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
go scrape.RunScraper(&config, bot, db, api)
|
go scrape.RunScraper(&config, bot, db, api)
|
||||||
go web.RunWeb(&config, api)
|
go web.RunWeb(&config, api, GitCommit)
|
||||||
|
|
||||||
signal_chan := make(chan os.Signal, 1)
|
signal_chan := make(chan os.Signal, 1)
|
||||||
signal.Notify(signal_chan,
|
signal.Notify(signal_chan,
|
||||||
|
|
|
@ -27,6 +27,17 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ template "content" . }}
|
{{ template "content" . }}
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<hr />
|
||||||
|
<small>
|
||||||
|
Maintained by <a href="https://osu.ppy.sh/u/2688103" target="_blank">IOException</a>
|
||||||
|
·
|
||||||
|
<a href="https://git.mzhang.io/osu/subscribe-bot" target="_blank">Source code</a>
|
||||||
|
·
|
||||||
|
subscribe-bot v{{ GitCommit }}
|
||||||
|
</small>
|
||||||
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
11
web/web.go
11
web/web.go
|
@ -2,6 +2,7 @@ package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -33,14 +34,15 @@ type Web struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
api *osuapi.Osuapi
|
api *osuapi.Osuapi
|
||||||
hc *http.Client
|
hc *http.Client
|
||||||
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunWeb(config *config.Config, api *osuapi.Osuapi) {
|
func RunWeb(config *config.Config, api *osuapi.Osuapi, version string) {
|
||||||
hc := &http.Client{
|
hc := &http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
web := Web{config, api, hc}
|
web := Web{config, api, hc, version}
|
||||||
web.Run()
|
web.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +60,11 @@ func (web *Web) Run() {
|
||||||
Root: "web/templates",
|
Root: "web/templates",
|
||||||
Master: "master.html",
|
Master: "master.html",
|
||||||
DisableCache: web.config.Debug,
|
DisableCache: web.config.Debug,
|
||||||
|
Funcs: template.FuncMap{
|
||||||
|
"GitCommit": func() string {
|
||||||
|
return web.version
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/logout", web.logout)
|
r.GET("/logout", web.logout)
|
||||||
|
|
Loading…
Reference in a new issue