Browse Source

add /api/version

master
AJ ONeal 4 years ago
parent
commit
b740ccc74e
  1. 30
      README.md
  2. 12
      main.go

30
README.md

@ -30,9 +30,9 @@ The platform, publish URL, and token file can be changed in `.goreleaser.yml`:
```yml ```yml
env_files: env_files:
gitea_token: ~/.config/goreleaser/gitea_token gitea_token: ~/.config/goreleaser/gitea_token
gitea_urls: gitea_urls:
api: https://try.gitea.io/api/v1/ api: https://try.gitea.io/api/v1/
``` ```
#### Manually #### Manually
@ -67,9 +67,9 @@ GOOS=linux GOARCH=arm64 go build -mod=vendor -o dist/goserv-linux-arm64 .
The example files are located in `./examples` The example files are located in `./examples`
- Caddyfile (web server config) - Caddyfile (web server config)
- .env (environment variables) - .env (environment variables)
- build.sh - build.sh
```bash ```bash
export BASE_URL=https://example.com export BASE_URL=https://example.com
@ -123,6 +123,8 @@ Authentication: Bearer <token>
Here's the API, in brief: Here's the API, in brief:
Base URL looks like `https://example.com/api`.
```txt ```txt
# Demo Mode Only # Demo Mode Only
DELETE /public/reset Drop database and re-initialize DELETE /public/reset Drop database and re-initialize
@ -166,9 +168,9 @@ If the documentation is not public hosted you can view it with GoDoc:
godoc --http :6060 godoc --http :6060
``` ```
- <http://localhost:6060/pkg/git.example.com/example/goserv/> - <http://localhost:6060/pkg/git.example.com/example/goserv/>
- <http://localhost:6060/pkg/git.example.com/example/goserv/internal/api> - <http://localhost:6060/pkg/git.example.com/example/goserv/internal/api>
- <http://localhost:6060/pkg/git.example.com/example/goserv/internal/db> - <http://localhost:6060/pkg/git.example.com/example/goserv/internal/db>
You can see abbreviated documentation with `go`'s built-in `doc`, for example: You can see abbreviated documentation with `go`'s built-in `doc`, for example:
@ -198,10 +200,10 @@ go test -mod=vendor ./...
This setup can be run on a VPS, such as Digital Ocean, OVH, or Scaleway This setup can be run on a VPS, such as Digital Ocean, OVH, or Scaleway
for \$5/month with minimal dependencies: for \$5/month with minimal dependencies:
- VPS - VPS
- Caddy - Caddy
- PostgreSQL - PostgreSQL
- Serviceman - Serviceman
**Mac**, **Linux**: **Mac**, **Linux**:
@ -281,8 +283,8 @@ Copyright 2020 The GoServ Authors. All rights reserved.
### Exceptions ### Exceptions
- `countries.json` LGPL, taken from <https://github.com/stefangabos/world_countries> - `countries.json` LGPL, taken from <https://github.com/stefangabos/world_countries>
- `flags.json` MIT, taken from <https://github.com/matiassingers/emoji-flags> - `flags.json` MIT, taken from <https://github.com/matiassingers/emoji-flags>
These are probably also in the Public Domain. \ These are probably also in the Public Domain. \
(gathering the official data from any source would yield the same dataset) (gathering the official data from any source would yield the same dataset)

12
main.go

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

Loading…
Cancel
Save