Documentation ¶
Overview ¶
Package server implements blog sever with mongodb and swagger.
Index ¶
- type Config
- type Server
- func (s *Server) DeleteHandle(w http.ResponseWriter, r *http.Request)
- func (s *Server) EditHandle(w http.ResponseWriter, r *http.Request)
- func (s *Server) IndexHadle(w http.ResponseWriter, r *http.Request)
- func (s *Server) NewHandle(w http.ResponseWriter, r *http.Request)
- func (s *Server) PostHandle(w http.ResponseWriter, r *http.Request)
- func (s *Server) PutHandle(w http.ResponseWriter, r *http.Request)
- func (s *Server) SendErr(w http.ResponseWriter, err error, code int, obj ...interface{})
- func (s *Server) SendInternalErr(w http.ResponseWriter, err error, obj ...interface{})
- func (s *Server) Start() *Server
- func (s *Server) Stop() error
- func (s *Server) SwaggerHandle(w http.ResponseWriter, r *http.Request)
- func (s *Server) ViewHandle(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Root string `yaml:"rootdir"` Addr string `yaml:"addr"` TemplatesDir string `yaml:"templatesdir"` DBname string `yaml:"dbname"` SwagURL string `yaml:"swagurl"` SwagJSON string `yaml:"swagpath"` }
Config stands for yaml config struct.
type Server ¶
Server stands for server struct.
func (*Server) DeleteHandle ¶
func (s *Server) DeleteHandle(w http.ResponseWriter, r *http.Request)
DeleteHandle deletes a post. @Summary deletes a post by id @Description deletes a post by id @Accept json @Produce json @Success 200 {string} string @Param id path string true "id" @Param post body models.Post true "id" @Router /api/v1/posts/{id} [delete]
func (*Server) EditHandle ¶
func (s *Server) EditHandle(w http.ResponseWriter, r *http.Request)
EditHandle returns page with edit post form. @Summary serve edit post templated page @Description returns page with edit post form @Param id path string true "id" @Success 200 {string} string @Failure 500 {string} models.ErrorModel @Produce html @Router /edit/{id} [get]
func (*Server) IndexHadle ¶
func (s *Server) IndexHadle(w http.ResponseWriter, r *http.Request)
IndexHadle returns index page with max 20 posts. @Summary serve index templated page @Description returns index page with max 20 posts @Success 200 {string} string @Failure 500 {string} models.ErrorModel @Produce html @Router / [get]
func (*Server) NewHandle ¶
func (s *Server) NewHandle(w http.ResponseWriter, r *http.Request)
NewHandle returns page with new post form. @Summary serve new post templated page @Description returns page with new post form @Success 200 {string} string @Failure 500 {string} models.ErrorModel @Produce html @Router /new [get]
func (*Server) PostHandle ¶
func (s *Server) PostHandle(w http.ResponseWriter, r *http.Request)
PostHandle create new post. @Summary create new post @Description create new post and return json @Success 200 {string} models.Post @Failure 500 {string} models.ErrorModel @Produce json @Param post body models.Post true "title, author, content" @Router /api/v1/posts [post]
func (*Server) PutHandle ¶
func (s *Server) PutHandle(w http.ResponseWriter, r *http.Request)
PutHandle renew post. @Summary renew post by id @Description renew post by id @Accept json @Produce json @Success 200 {string} string @Param id path string true "id" @Param post body models.Post true "title, author, content" @Router /api/v1/posts/{id} [put]
func (*Server) SendErr ¶
func (s *Server) SendErr(w http.ResponseWriter, err error, code int, obj ...interface{})
SendErr sends and log error to user.
func (*Server) SendInternalErr ¶
func (s *Server) SendInternalErr(w http.ResponseWriter, err error, obj ...interface{})
SendInternalErr sends 500 error.
func (*Server) SwaggerHandle ¶
func (s *Server) SwaggerHandle(w http.ResponseWriter, r *http.Request)
SwaggerHandle serve path to json for swagger. @Summary returns json docs @Description Returns swagger's json docs @Produce json @Success 200 {string} string "ok" @Router /api/v1/docs/swagger.json [get]
func (*Server) ViewHandle ¶
func (s *Server) ViewHandle(w http.ResponseWriter, r *http.Request)
ViewHandle returns page with one post by id. @Summary serve view post templated page @Description returns page with one post by id @Param id path string true "id" @Success 200 {string} string @Failure 500 {string} models.ErrorModel @Produce html @Router /view/{id} [get]