You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
764 B
Go
47 lines
764 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type Store struct {
|
|
Counters map[string]int
|
|
}
|
|
|
|
func (db *Store) GetCounter(username string) int {
|
|
value, ok := db.Counters[username]
|
|
if !ok {
|
|
return 0
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func (db *Store) IncrementCounter(username string) {
|
|
value := db.Counters[username]
|
|
db.Counters[username] = value + 1
|
|
}
|
|
|
|
func (db *Store) DecrementCounter(username string) {
|
|
value := db.Counters[username]
|
|
db.Counters[username] = value - 1
|
|
}
|
|
|
|
func main() {
|
|
app := fiber.New()
|
|
|
|
app.Static("/", "./dist/")
|
|
|
|
app.Get("/api/status", func(ctx *fiber.Ctx) error {
|
|
return ctx.JSON("ok")
|
|
})
|
|
|
|
app.Get("/u/:username", func(ctx *fiber.Ctx) error {
|
|
return ctx.SendFile("./user.html")
|
|
})
|
|
|
|
log.Fatal(app.Listen(":4000"))
|
|
}
|