web

package
v0.27.7 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: AGPL-3.0, AGPL-3.0-only Imports: 44 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.UserContext(), 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)
}

frontend

前端 Demo https://next.bgm.tv/demo/login

Documentation

Index

Constants

This section is empty.

Variables

Functions

func AddRouters added in v0.23.2

func AddRouters(
	app *fiber.App,
	c config.AppConfig,
	h handler.Handler,
	userHandler user.User,
	personHandler person.Person,
	characterHandler character.Character,
	subjectHandler subject.Subject,
)

AddRouters add all router and default 404 Handler to app.

func New

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

func Start added in v0.17.2

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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