mirror of
https://github.com/Cernobor/oko-server.git
synced 2025-02-24 08:27:17 +00:00
* API endpoint * dockerfile adds commit hash and build time during build
This commit is contained in:
parent
7deb7e3f39
commit
1cf44e3bfc
@ -38,4 +38,3 @@ go.work
|
||||
oko-server
|
||||
*.sqlite*
|
||||
.vscode
|
||||
.git
|
||||
|
@ -3,9 +3,9 @@ FROM alpine:3.15.0 AS build
|
||||
VOLUME ["/data"]
|
||||
COPY . /oko-server/git
|
||||
|
||||
RUN apk add --no-cache go && \
|
||||
RUN apk add --no-cache go git && \
|
||||
cd /oko-server/git && \
|
||||
go build
|
||||
go build -ldflags "-X \"main.sha1ver=$(git rev-parse HEAD)\" -X \"main.buildTime=$(date -Iseconds)\""
|
||||
|
||||
FROM alpine:3.15.0
|
||||
WORKDIR /oko-server
|
||||
|
13
main.go
13
main.go
@ -7,12 +7,18 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"cernobor.cz/oko-server/models"
|
||||
"cernobor.cz/oko-server/server"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
sha1ver string
|
||||
buildTime string
|
||||
)
|
||||
|
||||
func main() {
|
||||
tilepackFileArg := flag.String("tilepack", "", "File that will be sent to clients when they request a tile pack, also used to serve tiles in online mode. Required.")
|
||||
portArg := flag.Int("port", 8080, "Port where the server will listen to. Default is 8080.")
|
||||
@ -31,7 +37,14 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
t, err := time.Parse(time.RFC3339, buildTime)
|
||||
if err != nil {
|
||||
t = time.Now()
|
||||
}
|
||||
|
||||
s := server.New(server.ServerConfig{
|
||||
VersionHash: sha1ver,
|
||||
BuildTime: &t,
|
||||
Port: *portArg,
|
||||
DbPath: *dbFileArg,
|
||||
TilepackPath: *tilepackFileArg,
|
||||
|
@ -33,6 +33,11 @@ type Feature struct {
|
||||
PhotoIDs []FeaturePhotoID `json:"photo_ids"`
|
||||
}
|
||||
|
||||
type BuildInfo struct {
|
||||
VersionHash string `json:"version_hash"`
|
||||
BuildTime *time.Time `json:"build_time"`
|
||||
}
|
||||
|
||||
// transport objects
|
||||
|
||||
type Coords struct {
|
||||
|
@ -2,6 +2,7 @@ package server
|
||||
|
||||
const (
|
||||
URIPing = "/ping"
|
||||
URIBuildInfo = "/build-info"
|
||||
URIHardFail = "/hard-fail"
|
||||
URISoftFail = "/soft-fail"
|
||||
URIReinit = "/reinit"
|
||||
|
@ -81,6 +81,12 @@ func (s *Server) setupRouter() *gin.Engine {
|
||||
router.GET(URIPing, func(gc *gin.Context) {
|
||||
gc.Status(http.StatusNoContent)
|
||||
})
|
||||
router.GET(URIBuildInfo, func(gc *gin.Context) {
|
||||
gc.JSON(http.StatusOK, models.BuildInfo{
|
||||
VersionHash: s.config.VersionHash,
|
||||
BuildTime: s.config.BuildTime,
|
||||
})
|
||||
})
|
||||
router.GET(URIHardFail, func(gc *gin.Context) {
|
||||
gc.Status(http.StatusNotImplemented)
|
||||
})
|
||||
|
@ -35,6 +35,8 @@ type Server struct {
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
VersionHash string
|
||||
BuildTime *time.Time
|
||||
Port int
|
||||
DbPath string
|
||||
TilepackPath string
|
||||
|
Loading…
Reference in New Issue
Block a user