add /api/version

This commit is contained in:
AJ ONeal 2020-10-12 14:20:25 -06:00
parent ff2a9e21b5
commit b740ccc74e
2 changed files with 24 additions and 18 deletions

View File

@ -123,6 +123,8 @@ Authentication: Bearer <token>
Here's the API, in brief:
Base URL looks like `https://example.com/api`.
```txt
# Demo Mode Only
DELETE /public/reset Drop database and re-initialize

12
main.go
View File

@ -33,7 +33,7 @@ var (
)
func usage() {
ver()
fmt.Println(ver())
fmt.Println("")
fmt.Println("Use 'help <command>'")
fmt.Println(" help")
@ -41,8 +41,8 @@ func usage() {
fmt.Println(" run")
}
func ver() {
fmt.Printf("%s v%s %s (%s)\n", name, version, commit[:7], date)
func ver() string {
return fmt.Sprintf("%s v%s %s (%s)\n", name, version, commit[:7], date)
}
var defaultAddr = ":3000"
@ -113,7 +113,7 @@ func main() {
switch args[1] {
case "version":
ver()
fmt.Println(ver())
os.Exit(0)
return
case "init":
@ -186,6 +186,10 @@ func serve() {
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Get("/api/version", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(ver() + "\n"))
})
var pub keypairs.PublicKey = nil
if "" != runOpts.pub {
var err error