Mounting handlers and basic swagger docs example
This commit is contained in:
parent
f75cb7e9fc
commit
13c12b424a
2 changed files with 28 additions and 0 deletions
|
@ -46,6 +46,17 @@ type GState struct {
|
|||
ButtonCount int
|
||||
}
|
||||
|
||||
// Register is a simple handler that registers a new user
|
||||
//
|
||||
// @Summary Register a new user
|
||||
// @Description Register a new user
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} string "User added"
|
||||
// @Failure 400 {string} string "Bad request"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /api/register [post]
|
||||
func (gs *GState) Register(c *fiber.Ctx) error {
|
||||
u := new(types.User)
|
||||
if err := c.BodyParser(u); err != nil {
|
||||
|
|
|
@ -3,16 +3,31 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
_ "ttime/docs"
|
||||
"ttime/internal/config"
|
||||
"ttime/internal/database"
|
||||
"ttime/internal/handlers"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/swagger"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
jwtware "github.com/gofiber/contrib/jwt"
|
||||
)
|
||||
|
||||
// @title TTime API
|
||||
// @version 0.0.1
|
||||
// @description This is the API for TTime, a time tracking application.
|
||||
|
||||
// @license.name AGPL
|
||||
// @license.url https://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
// @host localhost:8080
|
||||
// @BasePath /api
|
||||
|
||||
// @externalDocs.description OpenAPI
|
||||
// @externalDocs.url https://swagger.io/resources/open-api/
|
||||
|
||||
func main() {
|
||||
conf, err := config.ReadConfigFromFile("config.toml")
|
||||
if err != nil {
|
||||
|
@ -31,6 +46,8 @@ func main() {
|
|||
// Create the server
|
||||
server := fiber.New()
|
||||
|
||||
server.Get("/swagger/*", swagger.HandlerDefault)
|
||||
|
||||
// Mount our static files (Beware of the security implications of this!)
|
||||
// This will likely be replaced by an embedded filesystem in the future
|
||||
server.Static("/", "./static")
|
||||
|
|
Loading…
Add table
Reference in a new issue