Add version api & model
This commit is contained in:
parent
a413b3d182
commit
e458bb1328
File diff suppressed because one or more lines are too long
|
|
@ -1024,6 +1024,26 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/version": {
|
||||||
|
"get": {
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"version"
|
||||||
|
],
|
||||||
|
"summary": "Get version information.",
|
||||||
|
"operationId": "getVersion",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Ok",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/VersionInfo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
|
@ -1144,6 +1164,29 @@
|
||||||
},
|
},
|
||||||
"x-go-name": "UserExternal",
|
"x-go-name": "UserExternal",
|
||||||
"x-go-package": "github.com/gotify/server/model"
|
"x-go-package": "github.com/gotify/server/model"
|
||||||
|
},
|
||||||
|
"VersionInfo": {
|
||||||
|
"description": "VersionInfo Model",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"branch": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Branch"
|
||||||
|
},
|
||||||
|
"buildDate": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "BuildDate"
|
||||||
|
},
|
||||||
|
"commit": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Commit"
|
||||||
|
},
|
||||||
|
"version": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Version"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "github.com/gotify/server/model"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
// VersionInfo Model
|
||||||
|
//
|
||||||
|
// swagger:model VersionInfo
|
||||||
|
type VersionInfo struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
Commit string `json:"commit"`
|
||||||
|
BuildDate string `json:"buildDate"`
|
||||||
|
Branch string `json:"branch"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -14,10 +14,11 @@ import (
|
||||||
|
|
||||||
"github.com/gotify/server/docs"
|
"github.com/gotify/server/docs"
|
||||||
"github.com/gotify/server/stream"
|
"github.com/gotify/server/stream"
|
||||||
|
"github.com/gotify/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create creates the gin engine with all routes.
|
// Create creates the gin engine with all routes.
|
||||||
func Create(db *database.GormDatabase) (*gin.Engine, func()) {
|
func Create(db *database.GormDatabase, vInfo *model.VersionInfo) (*gin.Engine, func()) {
|
||||||
streamHandler := stream.New(200*time.Second, 15*time.Second)
|
streamHandler := stream.New(200*time.Second, 15*time.Second)
|
||||||
authentication := auth.Auth{DB: db}
|
authentication := auth.Auth{DB: db}
|
||||||
messageHandler := api.MessageAPI{Notifier: streamHandler, DB: db}
|
messageHandler := api.MessageAPI{Notifier: streamHandler, DB: db}
|
||||||
|
|
@ -36,6 +37,22 @@ func Create(db *database.GormDatabase) (*gin.Engine, func()) {
|
||||||
ctx.Header("Content-Type", "application/json")
|
ctx.Header("Content-Type", "application/json")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// swagger:operation GET /version version getVersion
|
||||||
|
//
|
||||||
|
// Get version information.
|
||||||
|
//
|
||||||
|
// ---
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// responses:
|
||||||
|
// 200:
|
||||||
|
// description: Ok
|
||||||
|
// schema:
|
||||||
|
// $ref: "#/definitions/VersionInfo"
|
||||||
|
g.GET("version", func(ctx *gin.Context) {
|
||||||
|
ctx.JSON(200, vInfo)
|
||||||
|
})
|
||||||
|
|
||||||
// swagger:operation POST /message message createMessage
|
// swagger:operation POST /message message createMessage
|
||||||
//
|
//
|
||||||
// Create a message.
|
// Create a message.
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func (s *IntegrationSuite) BeforeTest(string, string) {
|
||||||
var err error
|
var err error
|
||||||
s.db, err = database.New("sqlite3", "itest.db", "admin", "pw")
|
s.db, err = database.New("sqlite3", "itest.db", "admin", "pw")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
g, closable := Create(s.db)
|
g, closable := Create(s.db, &model.VersionInfo{Version:"1.0.0", BuildDate:"2018-02-20-17:30:47", Branch:"master", Commit:"asdasds"})
|
||||||
s.closable = closable
|
s.closable = closable
|
||||||
s.server = httptest.NewServer(g)
|
s.server = httptest.NewServer(g)
|
||||||
}
|
}
|
||||||
|
|
@ -50,6 +50,12 @@ func (s *IntegrationSuite) AfterTest(string, string) {
|
||||||
s.server.Close()
|
s.server.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationSuite) TestVersionInfo() {
|
||||||
|
req := s.newRequest("GET", "version", "")
|
||||||
|
|
||||||
|
doRequestAndExpect(s.T(), req, 200, `{"version":"1.0.0", "commit":"asdasds", "buildDate":"2018-02-20-17:30:47", "branch":"master"}`)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *IntegrationSuite) TestSendMessage() {
|
func (s *IntegrationSuite) TestSendMessage() {
|
||||||
req := s.newRequest("POST", "application", `{"name": "backup-server"}`)
|
req := s.newRequest("POST", "application", `{"name": "backup-server"}`)
|
||||||
req.SetBasicAuth("admin", "pw")
|
req.SetBasicAuth("admin", "pw")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue