Documentation
¶
Index ¶
- Variables
- func AuthMiddleware() gin.HandlerFunc
- func GenerateJWT(id string) (string, error)
- func GetIDFromHeader(c *gin.Context) string
- func GetIDFromJWT(tokenString string) (string, error)
- func GetIDFromToken(token string) string
- func GetJWTFromHeader(c *gin.Context) string
- func Nullable[T any](row *T, err error) (*T, error)
- func NullableID(row string, err error) (string, error)
- func NullableList[T any](rows []*T, err error) ([]*T, error)
- func TokenValid(c *gin.Context) error
- type Error
- type Server
- func (s *Server) AddComment(c *gin.Context)
- func (s *Server) CreateArticle(c *gin.Context)
- func (s *Server) DeleteArticle(c *gin.Context)
- func (s *Server) DeleteComment(c *gin.Context)
- func (s *Server) FavoriteArticle(c *gin.Context)
- func (s *Server) FeedArticles(c *gin.Context)
- func (s *Server) FollowUser(c *gin.Context)
- func (s *Server) GetArticle(c *gin.Context)
- func (s *Server) GetComments(c *gin.Context)
- func (s *Server) GetCurrentUser(c *gin.Context)
- func (s *Server) GetProfile(c *gin.Context)
- func (s *Server) GetTags(c *gin.Context)
- func (s *Server) ListArticles(c *gin.Context)
- func (s *Server) LoginUser(c *gin.Context)
- func (s *Server) MountHandlers()
- func (s *Server) MountSwaggerHandlers()
- func (s *Server) RegisterUser(c *gin.Context)
- func (s *Server) Router() *gin.Engine
- func (s *Server) SearchArticles(c *gin.Context)
- func (s *Server) Start(addr string) error
- func (s *Server) UnfavoriteArticle(c *gin.Context)
- func (s *Server) UnfollowUser(c *gin.Context)
- func (s *Server) UpdateArticle(c *gin.Context)
- func (s *Server) UpdateUser(c *gin.Context)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware() gin.HandlerFunc
func GenerateJWT ¶
func GetIDFromHeader ¶
func GetIDFromJWT ¶
func GetIDFromToken ¶
func GetJWTFromHeader ¶
func NullableList ¶
func TokenValid ¶
Types ¶
type Error ¶
type Error struct {
Errors map[string]interface{} `json:"errors"`
}
func NewValidationError ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) AddComment ¶
AddComment godoc @Summary Add comment @Description Add comment to article @Tags articles @Accept json @Produce json @Param slug path string true "Article slug" @Param comment body addCommentReq true "Comment" @Success 200 {object} commentResponse @Failure 401 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Security Bearer @Router /articles/{slug}/comments [post]
func (*Server) CreateArticle ¶
CreateArticle godoc @Summary Create article @Description Create Article @Tags articles @Accept json @Produce json @Param article body createArticleReq true "Article" @Success 201 {object} articleResponse @Failure 401 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Security Bearer @Router /articles [post]
func (*Server) DeleteArticle ¶
DeleteArticle godoc @Summary Delete article @Description Delete Article by slug @Tags articles @Accept json @Produce json @Param slug path string true "Article slug" @Success 204 @Failure 401 {object} Error @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer @Router /articles/{slug} [delete]
func (*Server) DeleteComment ¶
DeleteComment godoc @Summary Delete comment @Description Delete comment by id @Tags articles @Accept json @Produce json @Param slug path string true "Article slug" @Param id path string true "Comment id" @Success 200 {object} commentResponse @Failure 401 {object} Error @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer @Router /articles/{slug}/comments/{id} [delete]
func (*Server) FavoriteArticle ¶
FavoriteArticle godoc @Summary Favorite article @Description Favorite article by slug @Tags articles @Accept json @Produce json @Param slug path string true "Article slug" @Success 200 {object} articleResponse @Failure 401 {object} Error @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer @Router /articles/{slug}/favorite [post]
func (*Server) FeedArticles ¶
FeedArticles godoc @Summary Feed articles @Description Feed articles @Tags articles @Accept json @Produce json @Param limit query int false "Limit" @Param offset query int false "Offset" @Success 200 {object} articlesResponse @Failure 500 {object} Error @Security Bearer @Router /articles/feed [get]
func (*Server) FollowUser ¶
FollowUser godoc @Summary Follow user by username @Description Follow user @Tags user @Accept json @Produce json @Param username path string true "Username" @Success 200 {object} profileResponse @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer @Router /profiles/{username}/follow [post]
func (*Server) GetArticle ¶
GetArticle godoc @Summary Get an article @Description Get an article by slug @Tags articles @Accept json @Produce json @Param slug path string true "Article slug" @Success 200 {object} articleResponse @Failure 404 {object} Error @Failure 500 {object} Error @Router /articles/{slug} [get]
func (*Server) GetComments ¶
GetComments godoc @Summary Get comments @Description Get comments by article slug @Tags articles @Accept json @Produce json @Param slug path string true "Article slug" @Success 200 {object} commentsResponse @Failure 401 {object} Error @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer @Router /articles/{slug}/comments [get]
func (*Server) GetCurrentUser ¶
GetCurrentUser godoc @Summary Get current user @Description Get current user @Tags user @Accept json @Produce json @Success 200 {object} userResponse @Failure 401 {object} Error @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer @Router /user [get]
func (*Server) GetProfile ¶
GetProfile godoc @Summary Get profile @Description Get profile of any user by username. Authentification optional @Tags user @Accept json @Produce json @Param username path string true "Username" @Success 200 {object} profileResponse @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer || {} @Router /profiles/{username} [get]
func (*Server) GetTags ¶
GetTags godoc @Summary Get tags @Description Get tags @Tags articles @Accept json @Produce json @Success 200 {object} tagsResponse @Failure 500 {object} Error @Router /tags [get]
func (*Server) ListArticles ¶
ListArticles godoc @Summary List articles @Description List articles @Tags articles @Accept json @Produce json @Param tag query string false "Tag" @Param author query string false "Author" @Param favorited query string false "Favorited" @Param limit query int false "Limit" @Param offset query int false "Offset" @Success 200 {object} map[string]interface{} @Failure 500 {object} Error @Router /articles [get]
func (*Server) LoginUser ¶
LoginUser godoc @Summary Login a user @Description Login a user @Tags auth @Accept json @Produce json @Param user body userLoginReq true "User" @Success 200 {object} userResponse @Failure 403 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error
@Router /users/login [post]
func (*Server) MountHandlers ¶
func (s *Server) MountHandlers()
func (*Server) MountSwaggerHandlers ¶
func (s *Server) MountSwaggerHandlers()
func (*Server) RegisterUser ¶
RegisterUser godoc @Summary Register a new user @Description Register a new user @Tags auth @Accept json @Produce json @Param user body userRegisterReq true "User" @Success 201 {object} userResponse @Failure 422 {object} Error @Failure 500 {object} Error
@Router /users [post]
func (*Server) SearchArticles ¶
SearchArticles godoc @Summary Search for articles @Description Search for articles @Tags articles @Accept json @Param q path string true "query" @Param page path int true "page" @Param per_page path int true "per page" @Produce json @Success 200 {object} search.ArticlesWithCount @Failure 422 {object} Error @Failure 500 {object} Error @Router /articles/search [get]
func (*Server) UnfavoriteArticle ¶
UnfavoriteArticle godoc @Summary Unfavorite article @Description Unfavorite article by slug @Tags articles @Accept json @Produce json @Param slug path string true "Article slug" @Success 200 {object} articleResponse @Failure 401 {object} Error @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer @Router /articles/{slug}/favorite [delete]
func (*Server) UnfollowUser ¶
UnfollowUser godoc @Summary Unfollow user by username @Description Unfollow user @Tags user @Accept json @Produce json @Param username path string true "Username" @Success 200 {object} profileResponse @Failure 404 {object} Error @Failure 500 {object} Error @Security Bearer @Router /profiles/{username}/follow [delete]
func (*Server) UpdateArticle ¶
UpdateArticle godoc @Summary Update article @Description Update Article @Tags articles @Accept json @Produce json @Param slug path string true "Article slug" @Param article body updateArticleReq true "Article" @Success 200 {object} articleResponse @Failure 401 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Security Bearer @Router /articles/{slug} [put]
func (*Server) UpdateUser ¶
UpdateUser godoc @Summary Update user @Description Update user @Tags user @Accept json @Produce json @Param user body updateUserReq true "User" @Success 200 {object} userResponse @Failure 401 {object} Error @Failure 404 {object} Error @Failure 422 {object} Error @Failure 500 {object} Error @Security Bearer @Router /user [put]