server

package
v0.0.0-...-520c8c8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package server implements blog sever with mongodb and swagger.

Index

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

type Server struct {
	Page models.Page
	// contains filtered or unexported fields
}

Server stands for server struct.

func New

func New(ctx context.Context, lg *logrus.Logger, conf *Config, db *mongo.Database) *Server

New creates new server.

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) Start

func (s *Server) Start() *Server

Start starts new server.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the server.

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]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL