added sitemap
This commit is contained in:
56
main.go
56
main.go
@@ -23,11 +23,13 @@ import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
_ "github.com/jackc/pgx/v4/stdlib"
|
||||
"github.com/markus-wa/demoinfocs-golang/v3/pkg/demoinfocs/common"
|
||||
"github.com/sabloger/sitemap-generator/smg"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/wercker/journalhook"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/time/rate"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -1050,6 +1052,59 @@ func getMatch(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, mResponse)
|
||||
}
|
||||
|
||||
func getSiteMap(c *gin.Context) {
|
||||
now := time.Now().UTC()
|
||||
sm := smg.NewSitemap(false)
|
||||
sm.SetLastMod(&now)
|
||||
sm.SetHostname("https://csgow.tf")
|
||||
|
||||
players, err := db.Player.Query().IDs(c)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, tPlayer := range players {
|
||||
err = sm.Add(&smg.SitemapLoc{
|
||||
Loc: fmt.Sprintf("/player/%d", tPlayer),
|
||||
ChangeFreq: smg.Daily,
|
||||
})
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
matches, err := db.Match.Query().IDs(c)
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, tMatch := range matches {
|
||||
err = sm.Add(&smg.SitemapLoc{
|
||||
Loc: fmt.Sprintf("/match/%d", tMatch),
|
||||
ChangeFreq: smg.Weekly,
|
||||
})
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tReader, tWriter := io.Pipe()
|
||||
|
||||
sm.Finalize()
|
||||
go func() {
|
||||
_, err = sm.WriteTo(tWriter)
|
||||
if err != nil {
|
||||
log.Warningf("error writing to pipe: %v", err)
|
||||
}
|
||||
_ = tWriter.Close()
|
||||
}()
|
||||
c.DataFromReader(http.StatusOK, 0, "application/xml", tReader, nil)
|
||||
}
|
||||
|
||||
/*
|
||||
/player/<id> GET player details (last 10 matches)
|
||||
/player/<id>/track POST Track player FORM_DATA: authcode, [sharecode]
|
||||
@@ -1188,6 +1243,7 @@ func main() {
|
||||
r.GET("/match/:id/chat", getMatchChat)
|
||||
r.GET("/matches", getMatches)
|
||||
r.GET("/matches/next/:time", getMatches)
|
||||
r.GET("/sitemap", getSiteMap)
|
||||
|
||||
log.Info("Start listening...")
|
||||
|
||||
|
Reference in New Issue
Block a user