chore: add docs to swagger and add pass handlers
All checks were successful
Backend ci / build (push) Successful in 7m15s
All checks were successful
Backend ci / build (push) Successful in 7m15s
This commit is contained in:
@@ -2,7 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/docs"
|
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/docs"
|
||||||
_ "gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/handlers"
|
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/handlers"
|
||||||
|
|
||||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/logger"
|
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/logger"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
swaggerFiles "github.com/swaggo/files"
|
swaggerFiles "github.com/swaggo/files"
|
||||||
@@ -22,7 +23,7 @@ func main() {
|
|||||||
docs.SwaggerInfo.Host = "d3m0k1d.ru"
|
docs.SwaggerInfo.Host = "d3m0k1d.ru"
|
||||||
docs.SwaggerInfo.Schemes = []string{"https"}
|
docs.SwaggerInfo.Schemes = []string{"https"}
|
||||||
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
handlers.Register(router)
|
||||||
log.Info("Starting server on :8080...")
|
log.Info("Starting server on :8080...")
|
||||||
if err := router.Run(":8080"); err != nil {
|
if err := router.Run(":8080"); err != nil {
|
||||||
log.Error("Error starting server: " + err.Error())
|
log.Error("Error starting server: " + err.Error())
|
||||||
|
|||||||
@@ -14,7 +14,139 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"host": "{{.Host}}",
|
"host": "{{.Host}}",
|
||||||
"basePath": "{{.BasePath}}",
|
"basePath": "{{.BasePath}}",
|
||||||
"paths": {}
|
"paths": {
|
||||||
|
"/api/v1/posts": {
|
||||||
|
"get": {
|
||||||
|
"description": "Get all posts",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Get all posts",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"description": "Create post",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Create post",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/posts/{id}": {
|
||||||
|
"get": {
|
||||||
|
"description": "Get post by id",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Get post by id",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"put": {
|
||||||
|
"description": "Update post",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Update post",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"description": "Delete post",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Delete post",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"storage.Post": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"content": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||||
|
|||||||
@@ -3,5 +3,137 @@
|
|||||||
"info": {
|
"info": {
|
||||||
"contact": {}
|
"contact": {}
|
||||||
},
|
},
|
||||||
"paths": {}
|
"paths": {
|
||||||
|
"/api/v1/posts": {
|
||||||
|
"get": {
|
||||||
|
"description": "Get all posts",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Get all posts",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"description": "Create post",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Create post",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/posts/{id}": {
|
||||||
|
"get": {
|
||||||
|
"description": "Get post by id",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Get post by id",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"put": {
|
||||||
|
"description": "Update post",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Update post",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"description": "Delete post",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"posts"
|
||||||
|
],
|
||||||
|
"summary": "Delete post",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/storage.Post"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"storage.Post": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"content": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,90 @@
|
|||||||
|
definitions:
|
||||||
|
storage.Post:
|
||||||
|
properties:
|
||||||
|
content:
|
||||||
|
type: string
|
||||||
|
createdAt:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
title:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
info:
|
info:
|
||||||
contact: {}
|
contact: {}
|
||||||
paths: {}
|
paths:
|
||||||
|
/api/v1/posts:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Get all posts
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/storage.Post'
|
||||||
|
type: array
|
||||||
|
summary: Get all posts
|
||||||
|
tags:
|
||||||
|
- posts
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Create post
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/storage.Post'
|
||||||
|
summary: Create post
|
||||||
|
tags:
|
||||||
|
- posts
|
||||||
|
/api/v1/posts/{id}:
|
||||||
|
delete:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Delete post
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/storage.Post'
|
||||||
|
summary: Delete post
|
||||||
|
tags:
|
||||||
|
- posts
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Get post by id
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/storage.Post'
|
||||||
|
summary: Get post by id
|
||||||
|
tags:
|
||||||
|
- posts
|
||||||
|
put:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Update post
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/storage.Post'
|
||||||
|
summary: Update post
|
||||||
|
tags:
|
||||||
|
- posts
|
||||||
swagger: "2.0"
|
swagger: "2.0"
|
||||||
|
|||||||
@@ -7,6 +7,62 @@ import (
|
|||||||
|
|
||||||
var log = logger.New(false)
|
var log = logger.New(false)
|
||||||
|
|
||||||
|
// GetPosts godoc
|
||||||
|
// @Summary Get all posts
|
||||||
|
// @Description Get all posts
|
||||||
|
// @Tags posts
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} []storage.Post
|
||||||
|
// @Router /api/v1/posts [get]
|
||||||
func GetPosts(c *gin.Context) {
|
func GetPosts(c *gin.Context) {
|
||||||
log.Info("GetPosts")
|
log.Info("GetPosts")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPost godoc
|
||||||
|
// @Summary Get post by id
|
||||||
|
// @Description Get post by id
|
||||||
|
// @Tags posts
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} storage.Post
|
||||||
|
// @Router /api/v1/posts/{id} [get]
|
||||||
|
func GetPost(c *gin.Context) {
|
||||||
|
log.Info("GetPost")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatePost godoc
|
||||||
|
// @Summary Create post
|
||||||
|
// @Description Create post
|
||||||
|
// @Tags posts
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} storage.Post
|
||||||
|
// @Router /api/v1/posts [post]
|
||||||
|
func CreatePost(c *gin.Context) {
|
||||||
|
log.Info("CreatePost")
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePost godoc
|
||||||
|
// @Summary Update post
|
||||||
|
// @Description Update post
|
||||||
|
// @Tags posts
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} storage.Post
|
||||||
|
// @Router /api/v1/posts/{id} [put]
|
||||||
|
func UpdatePost(c *gin.Context) {
|
||||||
|
log.Info("UpdatePost")
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletePost godoc
|
||||||
|
// @Summary Delete post
|
||||||
|
// @Description Delete post
|
||||||
|
// @Tags posts
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} storage.Post
|
||||||
|
// @Router /api/v1/posts/{id} [delete]
|
||||||
|
func DeletePost(c *gin.Context) {
|
||||||
|
log.Info("DeletePost")
|
||||||
|
}
|
||||||
|
|||||||
17
backend/internal/handlers/registry_handlers.go
Normal file
17
backend/internal/handlers/registry_handlers.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Register(router *gin.Engine) {
|
||||||
|
v1 := router.Group("api/v1")
|
||||||
|
posts := v1.Group("posts")
|
||||||
|
{
|
||||||
|
posts.GET("/", GetPosts)
|
||||||
|
posts.GET("/:id", GetPost)
|
||||||
|
posts.POST("/", CreatePost)
|
||||||
|
posts.PUT("/:id", UpdatePost)
|
||||||
|
posts.DELETE("/:id", DeletePost)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user