[server] Add support for exporting version and sources via HTTP.
This commit is contained in:
parent
1f77fb7a1a
commit
1af656d757
2 changed files with 49 additions and 1 deletions
|
@ -37,6 +37,7 @@ import . "github.com/volution/kawipiko/lib/common"
|
||||||
import . "github.com/volution/kawipiko/lib/server"
|
import . "github.com/volution/kawipiko/lib/server"
|
||||||
|
|
||||||
import "github.com/volution/kawipiko/cmd/version"
|
import "github.com/volution/kawipiko/cmd/version"
|
||||||
|
import "github.com/volution/kawipiko/embedded"
|
||||||
|
|
||||||
import _ "embed"
|
import _ "embed"
|
||||||
|
|
||||||
|
@ -135,6 +136,15 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
} else if bytes.Equal (_path, StringToBytes ("/__/about")) || bytes.Equal (_path, StringToBytes ("/__/about/")) {
|
} else if bytes.Equal (_path, StringToBytes ("/__/about")) || bytes.Equal (_path, StringToBytes ("/__/about/")) {
|
||||||
_server.ServeStatic (_context, http.StatusOK, AboutBannerData, AboutBannerContentType, AboutBannerContentEncoding, true)
|
_server.ServeStatic (_context, http.StatusOK, AboutBannerData, AboutBannerContentType, AboutBannerContentEncoding, true)
|
||||||
return
|
return
|
||||||
|
} else if bytes.Equal (_path, StringToBytes ("/__/version")) || bytes.Equal (_path, StringToBytes ("/__/version/")) {
|
||||||
|
_server.ServeSpecial (_context, "version", true)
|
||||||
|
return
|
||||||
|
} else if bytes.Equal (_path, StringToBytes ("/__/sources.md5")) {
|
||||||
|
_server.ServeSpecial (_context, "sources.md5", true)
|
||||||
|
return
|
||||||
|
} else if bytes.Equal (_path, StringToBytes ("/__/sources.cpio")) {
|
||||||
|
_server.ServeSpecial (_context, "sources.cpio", true)
|
||||||
|
return
|
||||||
} else if bytes.HasPrefix (_path, StringToBytes ("/__/banners/errors/")) {
|
} else if bytes.HasPrefix (_path, StringToBytes ("/__/banners/errors/")) {
|
||||||
_code := _path[len ("/__/banners/errors/") :]
|
_code := _path[len ("/__/banners/errors/") :]
|
||||||
if _code, _error := strconv.Atoi (BytesToString (*NoEscapeBytes (&_code))); _error == nil {
|
if _code, _error := strconv.Atoi (BytesToString (*NoEscapeBytes (&_code))); _error == nil {
|
||||||
|
@ -415,6 +425,7 @@ var _namespaces_b_static = []string {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (_server *server) ServeStatic (_context *fasthttp.RequestCtx, _status uint, _data []byte, _contentType string, _contentEncoding string, _cache bool) () {
|
func (_server *server) ServeStatic (_context *fasthttp.RequestCtx, _status uint, _data []byte, _contentType string, _contentEncoding string, _cache bool) () {
|
||||||
|
|
||||||
_response := (*fasthttp.Response) (NoEscape (unsafe.Pointer (&_context.Response)))
|
_response := (*fasthttp.Response) (NoEscape (unsafe.Pointer (&_context.Response)))
|
||||||
|
@ -488,6 +499,42 @@ func (_server *server) ServeError (_context *fasthttp.RequestCtx, _status uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (_server *server) ServeSpecial (_context *fasthttp.RequestCtx, _special string, _cache bool) () {
|
||||||
|
|
||||||
|
var _data []byte
|
||||||
|
var _contentType string
|
||||||
|
var _contentEncoding string
|
||||||
|
|
||||||
|
switch _special {
|
||||||
|
|
||||||
|
case "version" :
|
||||||
|
_buffer := bytes.NewBuffer (nil)
|
||||||
|
if _error := version.Version ("kawipiko-server", "", _buffer); _error != nil {
|
||||||
|
_server.ServeError (_context, http.StatusInternalServerError, _error, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_data = _buffer.Bytes ()
|
||||||
|
_contentType = MimeTypeText
|
||||||
|
_contentEncoding = "identity"
|
||||||
|
|
||||||
|
case "sources.md5" :
|
||||||
|
_data = StringToBytes (embedded.BuildSourcesMd5)
|
||||||
|
_contentType = MimeTypeText
|
||||||
|
_contentEncoding = "identity"
|
||||||
|
|
||||||
|
case "sources.cpio" :
|
||||||
|
_data = embedded.BuildSourcesCpioGz
|
||||||
|
_contentType = MimeTypeText
|
||||||
|
_contentEncoding = "application/x-cpio"
|
||||||
|
|
||||||
|
default :
|
||||||
|
panic ("[8546f2bd]")
|
||||||
|
}
|
||||||
|
|
||||||
|
_server.ServeStatic (_context, http.StatusOK, _data, _contentType, _contentEncoding, _cache)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (_server *server) ServeDummy (_context *fasthttp.RequestCtx) () {
|
func (_server *server) ServeDummy (_context *fasthttp.RequestCtx) () {
|
||||||
_server.ServeStatic (_context, http.StatusOK, DummyData, DummyContentType, DummyContentEncoding, false)
|
_server.ServeStatic (_context, http.StatusOK, DummyData, DummyContentType, DummyContentEncoding, false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ package version
|
||||||
|
|
||||||
import "bytes"
|
import "bytes"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "io"
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ import . "github.com/volution/kawipiko/embedded"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func Version (_executableName string, _executable string, _stream *os.File) (error) {
|
func Version (_executableName string, _executable string, _stream io.Writer) (error) {
|
||||||
|
|
||||||
if _executable == "<os.Executable>" {
|
if _executable == "<os.Executable>" {
|
||||||
if _executable_0, _error := os.Executable (); _error == nil {
|
if _executable_0, _error := os.Executable (); _error == nil {
|
||||||
|
|
Loading…
Reference in a new issue