ok commited

Signed-off-by: Odyssey <odyssey346@disroot.org>
This commit is contained in:
Odyssey 2023-01-07 18:16:35 +01:00
parent 41ecec808c
commit 588804cf62
2 changed files with 23 additions and 1 deletions

10
main.go
View File

@ -8,6 +8,8 @@ import (
"github.com/gofiber/fiber/v2"
log "github.com/sirupsen/logrus"
"runtime"
)
// publapi is a simple API for Project Segfault's public shared server (pubnix).
@ -22,8 +24,14 @@ func main() {
})
app.Get("/online", func(c *fiber.Ctx) error {
if runtime.GOOS == "windows" {
return c.JSON(fiber.Map{
"message": "/online is not supported on Windows",
"status": c.Response().StatusCode(),
})
}
// Get the number of users online
out, err := exec.Command("users | wc -l").Output()
out, err := exec.Command("bash", "-c", "users | wc -l").Output()
if err != nil {
log.Error(err)
return c.SendStatus(fiber.StatusInternalServerError)

14
readme.md Normal file
View File

@ -0,0 +1,14 @@
# Publapi
Publapi is a simple API for Project Segfault's public shared system (pubnix).
## Install
An installation of Go 1.19 or higher is required.
```
git clone https://github.com/ProjectSegfault/publapi
go mod download
go build
./publapi
```
By default it listens to port 3000 on 127.0.0.1. You can change the port with the environment variable PUBLAPI_PORT.