web

package
v0.20.10 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: AGPL-3.0, AGPL-3.0-only Imports: 31 Imported by: 0

README

req

请求

res

响应

session

session manager

rate

登录限流

middleware

  • middleware/ua 检查请求 User-Agent
  • middleware/origin 检查请求 Origin
  • middleware/recovery panic-recover

handler

路由应该是 internal/web/handler.Handler 的一个方法。

使用 http.Status* 作为返回码,不要使用 fiber.Status*

使用 res.NewError(code int, message string) error 来返回 http 响应。

如果是意料之外的错误,需要使用 Handler.InternalError(c *fiber.Ctx, err error, message string, logFields ...zap.Field) error {

此方法会打一个 log,并且返回 http 500 响应。

package handler

import (
	"github.com/bangumi/server/internal/logger/log"
	"github.com/bangumi/server/internal/web/res"
)

func (h Handler) GetCurrentUser(c *fiber.Ctx) error {
	u := h.getHTTPAccessor(c)
	if !u.login {
		return res.Unauthorized("need login")
	}

	data, err := h.service.FetchUserData(c.Context(), u.ID)
	if err != nil {
		return h.InternalError(c, err, "failed to get user", log.UserID(u.ID), u.LogRequestID())
	}

	return res.JSON(c, data)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(scope tally.Scope, reporter promreporter.Reporter) *fiber.App

func ResistRouter

func ResistRouter(app *fiber.App, c config.AppConfig, h handler.Handler, scope tally.Scope)

ResistRouter add all router and default 404 Handler to app.

func Start added in v0.17.2

func Start(c config.AppConfig, app *fiber.App) error

Types

This section is empty.

Directories

Path Synopsis
middleware
ua

Jump to

Keyboard shortcuts

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