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 GitCommit string
|
||||
|
||||
func main() {
|
||||
configPath := flag.String("config", "config.toml", "Path to the config file (defaults to config.toml)")
|
||||
flag.Parse()
|
||||
|
@ -40,7 +42,7 @@ func main() {
|
|||
}
|
||||
|
||||
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.Notify(signal_chan,
|
||||
|
|
|
@ -27,6 +27,17 @@
|
|||
</div>
|
||||
|
||||
{{ 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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
17
web/web.go
17
web/web.go
|
@ -2,6 +2,7 @@ package web
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -30,17 +31,18 @@ var (
|
|||
)
|
||||
|
||||
type Web struct {
|
||||
config *config.Config
|
||||
api *osuapi.Osuapi
|
||||
hc *http.Client
|
||||
config *config.Config
|
||||
api *osuapi.Osuapi
|
||||
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{
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
web := Web{config, api, hc}
|
||||
web := Web{config, api, hc, version}
|
||||
web.Run()
|
||||
}
|
||||
|
||||
|
@ -58,6 +60,11 @@ func (web *Web) Run() {
|
|||
Root: "web/templates",
|
||||
Master: "master.html",
|
||||
DisableCache: web.config.Debug,
|
||||
Funcs: template.FuncMap{
|
||||
"GitCommit": func() string {
|
||||
return web.version
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
r.GET("/logout", web.logout)
|
||||
|
|
Loading…
Reference in a new issue