simple_web

package module
v0.0.0-...-af82a32 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 4 Imported by: 0

README

simple-web

非常简单web框架,构建小型web服务很有用。

Documentation

Index

Constants

View Source
const (
	SuccessMessage = "操作成功"
	FailMessage    = "操作失败"
)
View Source
const (
	GET  = "GET"
	POST = "POST"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

type HandleFunc

type HandleFunc func(http.ResponseWriter, *http.Request)

type Map

type Map map[string]any

type R

type R[T any] struct {
	Code    int    `json:"code"`    // Code 状态码
	Data    T      `json:"data"`    // Data 载荷
	Msg     string `json:"msg"`     // Msg 状态消息
	Success bool   `json:"success"` // Success 状态
}

R 统一响应结构

func Data

func Data[T any](data T) *R[T]

Data 传入响应数据

func Fail

func Fail(msg string) *R[Map]

Fail 失败响应 msg 失败信息

func MethodNotAllowed

func MethodNotAllowed() *R[Map]

MethodNotAllowed 不支持的请求方法

func NotFound

func NotFound() *R[Map]

NotFound 404未找到请求

func Status

func Status(status bool) *R[Map]

Status 传入响应状态

func Success

func Success() *R[Map]

Success 成功响应

type Route

type Route struct {
	// contains filtered or unexported fields
}

func New

func New() *Route

func (*Route) GetHandle

func (r *Route) GetHandle(path string, h HandleFunc)

func (*Route) Handle

func (r *Route) Handle(method, path string, h HandleFunc)

func (*Route) PostHandle

func (r *Route) PostHandle(path string, h HandleFunc)

func (*Route) Run

func (r *Route) Run(addr string) error

func (*Route) ServeHTTP

func (r *Route) ServeHTTP(writer http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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